Compare commits
No commits in common. 'master' and 'developpement' have entirely different histories.
master
...
developpem
2221 changed files with 450215 additions and 234 deletions
@ -1,232 +0,0 @@ |
|||||
GNU GENERAL PUBLIC LICENSE |
|
||||
Version 3, 29 June 2007 |
|
||||
|
|
||||
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/> |
|
||||
|
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. |
|
||||
|
|
||||
Preamble |
|
||||
|
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works. |
|
||||
|
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. |
|
||||
|
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. |
|
||||
|
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. |
|
||||
|
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. |
|
||||
|
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. |
|
||||
|
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. |
|
||||
|
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. |
|
||||
|
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. |
|
||||
|
|
||||
The precise terms and conditions for copying, distribution and modification follow. |
|
||||
|
|
||||
TERMS AND CONDITIONS |
|
||||
|
|
||||
0. Definitions. |
|
||||
|
|
||||
“This License” refers to version 3 of the GNU General Public License. |
|
||||
|
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. |
|
||||
|
|
||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. |
|
||||
|
|
||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. |
|
||||
|
|
||||
A “covered work” means either the unmodified Program or a work based on the Program. |
|
||||
|
|
||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. |
|
||||
|
|
||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. |
|
||||
|
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. |
|
||||
|
|
||||
1. Source Code. |
|
||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. |
|
||||
|
|
||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. |
|
||||
|
|
||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. |
|
||||
|
|
||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. |
|
||||
|
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. |
|
||||
|
|
||||
The Corresponding Source for a work in source code form is that same work. |
|
||||
|
|
||||
2. Basic Permissions. |
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. |
|
||||
|
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. |
|
||||
|
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. |
|
||||
|
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. |
|
||||
|
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. |
|
||||
|
|
||||
4. Conveying Verbatim Copies. |
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. |
|
||||
|
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. |
|
||||
|
|
||||
5. Conveying Modified Source Versions. |
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: |
|
||||
|
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date. |
|
||||
|
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. |
|
||||
|
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. |
|
||||
|
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. |
|
||||
|
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. |
|
||||
|
|
||||
6. Conveying Non-Source Forms. |
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: |
|
||||
|
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. |
|
||||
|
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. |
|
||||
|
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. |
|
||||
|
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. |
|
||||
|
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. |
|
||||
|
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. |
|
||||
|
|
||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. |
|
||||
|
|
||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. |
|
||||
|
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). |
|
||||
|
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. |
|
||||
|
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. |
|
||||
|
|
||||
7. Additional Terms. |
|
||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. |
|
||||
|
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. |
|
||||
|
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: |
|
||||
|
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or |
|
||||
|
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or |
|
||||
|
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or |
|
||||
|
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or |
|
||||
|
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or |
|
||||
|
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. |
|
||||
|
|
||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. |
|
||||
|
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. |
|
||||
|
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. |
|
||||
|
|
||||
8. Termination. |
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). |
|
||||
|
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. |
|
||||
|
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. |
|
||||
|
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. |
|
||||
|
|
||||
9. Acceptance Not Required for Having Copies. |
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. |
|
||||
|
|
||||
10. Automatic Licensing of Downstream Recipients. |
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. |
|
||||
|
|
||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. |
|
||||
|
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. |
|
||||
|
|
||||
11. Patents. |
|
||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. |
|
||||
|
|
||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. |
|
||||
|
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. |
|
||||
|
|
||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. |
|
||||
|
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. |
|
||||
|
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. |
|
||||
|
|
||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. |
|
||||
|
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. |
|
||||
|
|
||||
12. No Surrender of Others' Freedom. |
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. |
|
||||
|
|
||||
13. Use with the GNU Affero General Public License. |
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. |
|
||||
|
|
||||
14. Revised Versions of this License. |
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. |
|
||||
|
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. |
|
||||
|
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. |
|
||||
|
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. |
|
||||
|
|
||||
15. Disclaimer of Warranty. |
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|
||||
|
|
||||
16. Limitation of Liability. |
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
|
||||
|
|
||||
17. Interpretation of Sections 15 and 16. |
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. |
|
||||
|
|
||||
END OF TERMS AND CONDITIONS |
|
||||
|
|
||||
How to Apply These Terms to Your New Programs |
|
||||
|
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. |
|
||||
|
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. |
|
||||
|
|
||||
<one line to give the program's name and a brief idea of what it does.> |
|
||||
Copyright (C) <year> <name of author> |
|
||||
|
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. |
|
||||
|
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|
||||
|
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
|
|
||||
Also add information on how to contact you by electronic and paper mail. |
|
||||
|
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: |
|
||||
|
|
||||
<program> Copyright (C) <year> <name of author> |
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. |
|
||||
|
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. |
|
||||
|
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>. |
|
||||
|
|
||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>. |
|
||||
@ -1,2 +0,0 @@ |
|||||
# laintify |
|
||||
|
|
||||
@ -0,0 +1,14 @@ |
|||||
|
services: |
||||
|
mongo-db: |
||||
|
image: mongo:latest |
||||
|
container_name: mongo-db |
||||
|
ports: |
||||
|
- "27017:27017" |
||||
|
environment: |
||||
|
MONGO_INITDB_ROOT_USERNAME: root |
||||
|
MONGO_INITDB_ROOT_PASSWORD: toor |
||||
|
volumes: |
||||
|
- mongo-data:/data/db |
||||
|
|
||||
|
volumes: |
||||
|
mongo-data: |
||||
@ -0,0 +1 @@ |
|||||
|
../mkdirp/bin/cmd.js |
||||
@ -0,0 +1 @@ |
|||||
|
../node-gyp-build/bin.js |
||||
@ -0,0 +1 @@ |
|||||
|
../node-gyp-build/optional.js |
||||
@ -0,0 +1 @@ |
|||||
|
../node-gyp-build/build-test.js |
||||
@ -0,0 +1 @@ |
|||||
|
../nodemon/bin/nodemon.js |
||||
@ -0,0 +1 @@ |
|||||
|
../touch/bin/nodetouch.js |
||||
@ -0,0 +1 @@ |
|||||
|
../prettier/bin/prettier.cjs |
||||
@ -0,0 +1 @@ |
|||||
|
../semver/bin/semver.js |
||||
File diff suppressed because it is too large
@ -0,0 +1,22 @@ |
|||||
|
Copyright (c) 2014 Dmitry Tsvettsikh |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person |
||||
|
obtaining a copy of this software and associated documentation |
||||
|
files (the "Software"), to deal in the Software without |
||||
|
restriction, including without limitation the rights to use, |
||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the |
||||
|
Software is furnished to do so, subject to the following |
||||
|
conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be |
||||
|
included in all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||||
|
OTHER DEALINGS IN THE SOFTWARE. |
||||
@ -0,0 +1,4 @@ |
|||||
|
import mod from "./node.js"; |
||||
|
|
||||
|
export default mod; |
||||
|
export const saslprep = mod.saslprep; |
||||
@ -0,0 +1,5 @@ |
|||||
|
declare const saslprep: (input: string, opts?: { |
||||
|
allowUnassigned?: boolean; |
||||
|
} | undefined) => string; |
||||
|
export = saslprep; |
||||
|
//# sourceMappingURL=browser.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,QAAQ;;wBAAmC,CAAC;AAIlD,SAAS,QAAQ,CAAC"} |
||||
@ -0,0 +1,12 @@ |
|||||
|
"use strict"; |
||||
|
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
|
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
|
}; |
||||
|
const index_1 = __importDefault(require("./index")); |
||||
|
const memory_code_points_1 = require("./memory-code-points"); |
||||
|
const code_points_data_browser_1 = __importDefault(require("./code-points-data-browser")); |
||||
|
const codePoints = (0, memory_code_points_1.createMemoryCodePoints)(code_points_data_browser_1.default); |
||||
|
const saslprep = index_1.default.bind(null, codePoints); |
||||
|
Object.assign(saslprep, { saslprep, default: saslprep }); |
||||
|
module.exports = saslprep; |
||||
|
//# sourceMappingURL=browser.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";;;;AAAA,oDAAgC;AAChC,6DAA8D;AAC9D,0FAA8C;AAE9C,MAAM,UAAU,GAAG,IAAA,2CAAsB,EAAC,kCAAI,CAAC,CAAC;AAEhD,MAAM,QAAQ,GAAG,eAAS,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEzD,iBAAS,QAAQ,CAAC"} |
||||
@ -0,0 +1,3 @@ |
|||||
|
declare const data: Buffer<ArrayBuffer>; |
||||
|
export default data; |
||||
|
//# sourceMappingURL=code-points-data-browser.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"code-points-data-browser.d.ts","sourceRoot":"","sources":["../src/code-points-data-browser.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,IAAI,qBAGT,CAAC;AACF,eAAe,IAAI,CAAC"} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"code-points-data-browser.js","sourceRoot":"","sources":["../src/code-points-data-browser.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,8sliBAA8sliB,EAC9sliB,QAAQ,CACT,CAAC;AACF,kBAAe,IAAI,CAAC"} |
||||
@ -0,0 +1,3 @@ |
|||||
|
declare const _default: Buffer<ArrayBufferLike>; |
||||
|
export default _default; |
||||
|
//# sourceMappingURL=code-points-data.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"code-points-data.d.ts","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";AAEA,wBAKE"} |
||||
@ -0,0 +1,5 @@ |
|||||
|
"use strict"; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const zlib_1 = require("zlib"); |
||||
|
exports.default = (0, zlib_1.gunzipSync)(Buffer.from('H4sIAAAAAAACA+3dTYgcaRkA4LemO9Mhxm0FITnE9Cwr4jHgwgZ22B6YywqCJ0HQg5CL4sGTuOjCtGSF4CkHEW856MlTQHD3EJnWkU0Owh5VxE3LHlYQdNxd2U6mU59UV/d09fw4M2EySSXPAzNdP1/9fX/99bzVNZEN4jisRDulVFnQmLxm1aXF9Id/2/xMxNJ4XZlg576yuYlGt9gupV6xoFf8jhu9YvulVrFlp5XSx+lfvYhORGPXvqIRWSxERKtIm8bKFd10WNfKDS5Fo9jJWrq2+M2IlW+8uHgl/+BsROfPF4v5L7148Ur68Sha6dqZpYiVVy8tvLCWXo80Sf/lS89dGX2wHGvpzoXVn75/YWH5wmqe8uika82ViJXTy83Ve2k5Urozm38wm4/ls6t5uT6yfsTSJ7J3T0VKt8c5ExEXI8aFkH729c3eT+7EC6ca8cVULZUiYacX0R5PNWNxlh9L1y90q5kyzrpyy+9WcvOV6URntqw7La9sNVstXyczWVaWYbaaTYqzOHpr7pyiNT3/YzKuT63Z/FqKZlFTiuXtFM2vVOtIq7jiyKJbWZaOWD0euz0yoV2Z7kY0xq2x0YhfzVpmM5px9nTEH7JZ0ot5u39p0ma75Z472/s/H+2yr2inYyuq7fMvJivH2rM72N/Z3lyL31F2b1ya1P0zn816k2KP6JU9UzseucdQH5YqVeH/lFajSN2udg+TLJ9rksNxlvV2lki19rXKI43TPLejFu4ov7k3nMbhyhfY3Xb37f8BAGCf0eMTOH5szf154KmnNgKcnLb+Fzi2AfXktbN7fJelwTAiO/W5uQ2KINXRYu+znqo/WTAdLadURHmy3qciazd3bra4T3w16/f7t7Ms9U5gfJu10955sx1r3vmhBAAAAAAAgId20J1iZbDowNvIjuH427Gr5l/eiC+8OplZON8sVjx/qr9y+Pj+YRItT+NqAM+kkZs3AAAAAID6yfx1FwCAI97/dCh1/ub6SA0AAAAAAAAAgNoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hutp5SiQpYAAAAAAAAAQO2MIpZiT804flnAE2fhwjOeAZXr76kOAAAAAAAA8FjNf4N/l0NE3U/vuVQskLpSd4/Yh2xu9xTu0tFeeNYsLI2f/VMdNxTzj6Je9E/+6pp6Nn3awW3A54goe4Bss6v+PGsjQGMAAAAAAOBp5XEgwH6e7J7rwEQHRb/XvAMAAAAAAAA8yzoDeQDwVGjIAgAAAAAAAACoPfF/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqL/GSkSkClkCAAAAAAAAALXTSAAAAAAAAABA3Y1kAQAAAAAAAADUX8RSXZ9dsHC9+M8Fg2Ex/em1lAZpEBGttcrVjZqLEa+k0XpKw9mG4zWx4ukPUMhkAQAAAAAAABzBqbSe3//rXOS9HxGdo4TqR2XkutCdBu+LaPZw/lBbO7cbHnh2C7N7AIo4evEznllqLqWUp/LnYOtpM2bnOH66wI1+9GO4sOuISwv/TOlumu56FDv3NZhc4mR9v7zYIrafr40j/Cccvj9Xns3t3mu99E7qxUv3bqS0/ouNH/08++RGemfQ+nsx/5uNXsQPGulynPvv3ZTW37zd+1ovrqaYpP/122X6Xpx779Z3zr/3YOPKW1lkaRDf31pPaf3j/msRsVGkL+d/f+/m4sJsPm1cfSsr16e8m9Ldj/KsnyIuR3nXw83Is3EhxLd/2V773ks3m/cj/THKUummdP9qKhIOImuOU0Xjwb3y+oqt735rpTetVbF9n8R4x9crRfO77TKqVOZpDclv5bfK18lMnk+q0K18UpxF/RrGXE0Zxtqx3tWSj+vxbL4XaasfKb0dRbtLW73JsfPGg177H+OmGKlfvS1msllt7JEJm9XOJqXR+Fkfo1H66uy5H1v3Xx5+uJmGLw9jro2u7Loj4PnuR6+f+e3d261+eazNhzrL7X83MohoHpS4PddV8ki1it61//pw1g7z6p1U/26Nm2llST57B5rUvuG0XqSU/rPd7jYrqWcbd+beJQ77BgPMDwn37/8BAGCf0eMTOH4cPlufv9VGgJOzqf8Fjm1APXkd7B7f5dF57GPMaWy/MTvjvNvtXj6h8W2+GXvnzXaseeeHEgAAAAAAAB7aQXeKlcGiadBoEOeLb2dtpGOL2MyOtf391a3P/zD96c3JzIP3t4oV797vrh8+vn+YRL5bBuj/AQAAAABqJvfHXQAAHkX82zfXAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACeAgkAAAAAAAAAqLuRLAAAAAAAAACA2hv9D1iu/VAYaAYA', 'base64')); |
||||
|
//# sourceMappingURL=code-points-data.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"code-points-data.js","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";;AAAA,+BAAkC;AAElC,kBAAe,IAAA,iBAAU,EACvB,MAAM,CAAC,IAAI,CACT,knFAAknF,EAClnF,QAAQ,CACT,CACF,CAAC"} |
||||
@ -0,0 +1,7 @@ |
|||||
|
export declare const unassigned_code_points: Set<number>; |
||||
|
export declare const commonly_mapped_to_nothing: Set<number>; |
||||
|
export declare const non_ASCII_space_characters: Set<number>; |
||||
|
export declare const prohibited_characters: Set<number>; |
||||
|
export declare const bidirectional_r_al: Set<number>; |
||||
|
export declare const bidirectional_l: Set<number>; |
||||
|
//# sourceMappingURL=code-points-src.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"code-points-src.d.ts","sourceRoot":"","sources":["../src/code-points-src.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,aA6YjC,CAAC;AAMH,eAAO,MAAM,0BAA0B,aAIrC,CAAC;AAMH,eAAO,MAAM,0BAA0B,aASrC,CAAC;AAMH,eAAO,MAAM,qBAAqB,aA6GhC,CAAC;AAMH,eAAO,MAAM,kBAAkB,aAmC7B,CAAC;AAMH,eAAO,MAAM,eAAe,aAyW1B,CAAC"} |
||||
@ -0,0 +1,881 @@ |
|||||
|
"use strict"; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
exports.bidirectional_l = exports.bidirectional_r_al = exports.prohibited_characters = exports.non_ASCII_space_characters = exports.commonly_mapped_to_nothing = exports.unassigned_code_points = void 0; |
||||
|
const util_1 = require("./util"); |
||||
|
exports.unassigned_code_points = new Set([ |
||||
|
0x0221, |
||||
|
...(0, util_1.range)(0x0234, 0x024f), |
||||
|
...(0, util_1.range)(0x02ae, 0x02af), |
||||
|
...(0, util_1.range)(0x02ef, 0x02ff), |
||||
|
...(0, util_1.range)(0x0350, 0x035f), |
||||
|
...(0, util_1.range)(0x0370, 0x0373), |
||||
|
...(0, util_1.range)(0x0376, 0x0379), |
||||
|
...(0, util_1.range)(0x037b, 0x037d), |
||||
|
...(0, util_1.range)(0x037f, 0x0383), |
||||
|
0x038b, |
||||
|
0x038d, |
||||
|
0x03a2, |
||||
|
0x03cf, |
||||
|
...(0, util_1.range)(0x03f7, 0x03ff), |
||||
|
0x0487, |
||||
|
0x04cf, |
||||
|
...(0, util_1.range)(0x04f6, 0x04f7), |
||||
|
...(0, util_1.range)(0x04fa, 0x04ff), |
||||
|
...(0, util_1.range)(0x0510, 0x0530), |
||||
|
...(0, util_1.range)(0x0557, 0x0558), |
||||
|
0x0560, |
||||
|
0x0588, |
||||
|
...(0, util_1.range)(0x058b, 0x0590), |
||||
|
0x05a2, |
||||
|
0x05ba, |
||||
|
...(0, util_1.range)(0x05c5, 0x05cf), |
||||
|
...(0, util_1.range)(0x05eb, 0x05ef), |
||||
|
...(0, util_1.range)(0x05f5, 0x060b), |
||||
|
...(0, util_1.range)(0x060d, 0x061a), |
||||
|
...(0, util_1.range)(0x061c, 0x061e), |
||||
|
0x0620, |
||||
|
...(0, util_1.range)(0x063b, 0x063f), |
||||
|
...(0, util_1.range)(0x0656, 0x065f), |
||||
|
...(0, util_1.range)(0x06ee, 0x06ef), |
||||
|
0x06ff, |
||||
|
0x070e, |
||||
|
...(0, util_1.range)(0x072d, 0x072f), |
||||
|
...(0, util_1.range)(0x074b, 0x077f), |
||||
|
...(0, util_1.range)(0x07b2, 0x0900), |
||||
|
0x0904, |
||||
|
...(0, util_1.range)(0x093a, 0x093b), |
||||
|
...(0, util_1.range)(0x094e, 0x094f), |
||||
|
...(0, util_1.range)(0x0955, 0x0957), |
||||
|
...(0, util_1.range)(0x0971, 0x0980), |
||||
|
0x0984, |
||||
|
...(0, util_1.range)(0x098d, 0x098e), |
||||
|
...(0, util_1.range)(0x0991, 0x0992), |
||||
|
0x09a9, |
||||
|
0x09b1, |
||||
|
...(0, util_1.range)(0x09b3, 0x09b5), |
||||
|
...(0, util_1.range)(0x09ba, 0x09bb), |
||||
|
0x09bd, |
||||
|
...(0, util_1.range)(0x09c5, 0x09c6), |
||||
|
...(0, util_1.range)(0x09c9, 0x09ca), |
||||
|
...(0, util_1.range)(0x09ce, 0x09d6), |
||||
|
...(0, util_1.range)(0x09d8, 0x09db), |
||||
|
0x09de, |
||||
|
...(0, util_1.range)(0x09e4, 0x09e5), |
||||
|
...(0, util_1.range)(0x09fb, 0x0a01), |
||||
|
...(0, util_1.range)(0x0a03, 0x0a04), |
||||
|
...(0, util_1.range)(0x0a0b, 0x0a0e), |
||||
|
...(0, util_1.range)(0x0a11, 0x0a12), |
||||
|
0x0a29, |
||||
|
0x0a31, |
||||
|
0x0a34, |
||||
|
0x0a37, |
||||
|
...(0, util_1.range)(0x0a3a, 0x0a3b), |
||||
|
0x0a3d, |
||||
|
...(0, util_1.range)(0x0a43, 0x0a46), |
||||
|
...(0, util_1.range)(0x0a49, 0x0a4a), |
||||
|
...(0, util_1.range)(0x0a4e, 0x0a58), |
||||
|
0x0a5d, |
||||
|
...(0, util_1.range)(0x0a5f, 0x0a65), |
||||
|
...(0, util_1.range)(0x0a75, 0x0a80), |
||||
|
0x0a84, |
||||
|
0x0a8c, |
||||
|
0x0a8e, |
||||
|
0x0a92, |
||||
|
0x0aa9, |
||||
|
0x0ab1, |
||||
|
0x0ab4, |
||||
|
...(0, util_1.range)(0x0aba, 0x0abb), |
||||
|
0x0ac6, |
||||
|
0x0aca, |
||||
|
...(0, util_1.range)(0x0ace, 0x0acf), |
||||
|
...(0, util_1.range)(0x0ad1, 0x0adf), |
||||
|
...(0, util_1.range)(0x0ae1, 0x0ae5), |
||||
|
...(0, util_1.range)(0x0af0, 0x0b00), |
||||
|
0x0b04, |
||||
|
...(0, util_1.range)(0x0b0d, 0x0b0e), |
||||
|
...(0, util_1.range)(0x0b11, 0x0b12), |
||||
|
0x0b29, |
||||
|
0x0b31, |
||||
|
...(0, util_1.range)(0x0b34, 0x0b35), |
||||
|
...(0, util_1.range)(0x0b3a, 0x0b3b), |
||||
|
...(0, util_1.range)(0x0b44, 0x0b46), |
||||
|
...(0, util_1.range)(0x0b49, 0x0b4a), |
||||
|
...(0, util_1.range)(0x0b4e, 0x0b55), |
||||
|
...(0, util_1.range)(0x0b58, 0x0b5b), |
||||
|
0x0b5e, |
||||
|
...(0, util_1.range)(0x0b62, 0x0b65), |
||||
|
...(0, util_1.range)(0x0b71, 0x0b81), |
||||
|
0x0b84, |
||||
|
...(0, util_1.range)(0x0b8b, 0x0b8d), |
||||
|
0x0b91, |
||||
|
...(0, util_1.range)(0x0b96, 0x0b98), |
||||
|
0x0b9b, |
||||
|
0x0b9d, |
||||
|
...(0, util_1.range)(0x0ba0, 0x0ba2), |
||||
|
...(0, util_1.range)(0x0ba5, 0x0ba7), |
||||
|
...(0, util_1.range)(0x0bab, 0x0bad), |
||||
|
0x0bb6, |
||||
|
...(0, util_1.range)(0x0bba, 0x0bbd), |
||||
|
...(0, util_1.range)(0x0bc3, 0x0bc5), |
||||
|
0x0bc9, |
||||
|
...(0, util_1.range)(0x0bce, 0x0bd6), |
||||
|
...(0, util_1.range)(0x0bd8, 0x0be6), |
||||
|
...(0, util_1.range)(0x0bf3, 0x0c00), |
||||
|
0x0c04, |
||||
|
0x0c0d, |
||||
|
0x0c11, |
||||
|
0x0c29, |
||||
|
0x0c34, |
||||
|
...(0, util_1.range)(0x0c3a, 0x0c3d), |
||||
|
0x0c45, |
||||
|
0x0c49, |
||||
|
...(0, util_1.range)(0x0c4e, 0x0c54), |
||||
|
...(0, util_1.range)(0x0c57, 0x0c5f), |
||||
|
...(0, util_1.range)(0x0c62, 0x0c65), |
||||
|
...(0, util_1.range)(0x0c70, 0x0c81), |
||||
|
0x0c84, |
||||
|
0x0c8d, |
||||
|
0x0c91, |
||||
|
0x0ca9, |
||||
|
0x0cb4, |
||||
|
...(0, util_1.range)(0x0cba, 0x0cbd), |
||||
|
0x0cc5, |
||||
|
0x0cc9, |
||||
|
...(0, util_1.range)(0x0cce, 0x0cd4), |
||||
|
...(0, util_1.range)(0x0cd7, 0x0cdd), |
||||
|
0x0cdf, |
||||
|
...(0, util_1.range)(0x0ce2, 0x0ce5), |
||||
|
...(0, util_1.range)(0x0cf0, 0x0d01), |
||||
|
0x0d04, |
||||
|
0x0d0d, |
||||
|
0x0d11, |
||||
|
0x0d29, |
||||
|
...(0, util_1.range)(0x0d3a, 0x0d3d), |
||||
|
...(0, util_1.range)(0x0d44, 0x0d45), |
||||
|
0x0d49, |
||||
|
...(0, util_1.range)(0x0d4e, 0x0d56), |
||||
|
...(0, util_1.range)(0x0d58, 0x0d5f), |
||||
|
...(0, util_1.range)(0x0d62, 0x0d65), |
||||
|
...(0, util_1.range)(0x0d70, 0x0d81), |
||||
|
0x0d84, |
||||
|
...(0, util_1.range)(0x0d97, 0x0d99), |
||||
|
0x0db2, |
||||
|
0x0dbc, |
||||
|
...(0, util_1.range)(0x0dbe, 0x0dbf), |
||||
|
...(0, util_1.range)(0x0dc7, 0x0dc9), |
||||
|
...(0, util_1.range)(0x0dcb, 0x0dce), |
||||
|
0x0dd5, |
||||
|
0x0dd7, |
||||
|
...(0, util_1.range)(0x0de0, 0x0df1), |
||||
|
...(0, util_1.range)(0x0df5, 0x0e00), |
||||
|
...(0, util_1.range)(0x0e3b, 0x0e3e), |
||||
|
...(0, util_1.range)(0x0e5c, 0x0e80), |
||||
|
0x0e83, |
||||
|
...(0, util_1.range)(0x0e85, 0x0e86), |
||||
|
0x0e89, |
||||
|
...(0, util_1.range)(0x0e8b, 0x0e8c), |
||||
|
...(0, util_1.range)(0x0e8e, 0x0e93), |
||||
|
0x0e98, |
||||
|
0x0ea0, |
||||
|
0x0ea4, |
||||
|
0x0ea6, |
||||
|
...(0, util_1.range)(0x0ea8, 0x0ea9), |
||||
|
0x0eac, |
||||
|
0x0eba, |
||||
|
...(0, util_1.range)(0x0ebe, 0x0ebf), |
||||
|
0x0ec5, |
||||
|
0x0ec7, |
||||
|
...(0, util_1.range)(0x0ece, 0x0ecf), |
||||
|
...(0, util_1.range)(0x0eda, 0x0edb), |
||||
|
...(0, util_1.range)(0x0ede, 0x0eff), |
||||
|
0x0f48, |
||||
|
...(0, util_1.range)(0x0f6b, 0x0f70), |
||||
|
...(0, util_1.range)(0x0f8c, 0x0f8f), |
||||
|
0x0f98, |
||||
|
0x0fbd, |
||||
|
...(0, util_1.range)(0x0fcd, 0x0fce), |
||||
|
...(0, util_1.range)(0x0fd0, 0x0fff), |
||||
|
0x1022, |
||||
|
0x1028, |
||||
|
0x102b, |
||||
|
...(0, util_1.range)(0x1033, 0x1035), |
||||
|
...(0, util_1.range)(0x103a, 0x103f), |
||||
|
...(0, util_1.range)(0x105a, 0x109f), |
||||
|
...(0, util_1.range)(0x10c6, 0x10cf), |
||||
|
...(0, util_1.range)(0x10f9, 0x10fa), |
||||
|
...(0, util_1.range)(0x10fc, 0x10ff), |
||||
|
...(0, util_1.range)(0x115a, 0x115e), |
||||
|
...(0, util_1.range)(0x11a3, 0x11a7), |
||||
|
...(0, util_1.range)(0x11fa, 0x11ff), |
||||
|
0x1207, |
||||
|
0x1247, |
||||
|
0x1249, |
||||
|
...(0, util_1.range)(0x124e, 0x124f), |
||||
|
0x1257, |
||||
|
0x1259, |
||||
|
...(0, util_1.range)(0x125e, 0x125f), |
||||
|
0x1287, |
||||
|
0x1289, |
||||
|
...(0, util_1.range)(0x128e, 0x128f), |
||||
|
0x12af, |
||||
|
0x12b1, |
||||
|
...(0, util_1.range)(0x12b6, 0x12b7), |
||||
|
0x12bf, |
||||
|
0x12c1, |
||||
|
...(0, util_1.range)(0x12c6, 0x12c7), |
||||
|
0x12cf, |
||||
|
0x12d7, |
||||
|
0x12ef, |
||||
|
0x130f, |
||||
|
0x1311, |
||||
|
...(0, util_1.range)(0x1316, 0x1317), |
||||
|
0x131f, |
||||
|
0x1347, |
||||
|
...(0, util_1.range)(0x135b, 0x1360), |
||||
|
...(0, util_1.range)(0x137d, 0x139f), |
||||
|
...(0, util_1.range)(0x13f5, 0x1400), |
||||
|
...(0, util_1.range)(0x1677, 0x167f), |
||||
|
...(0, util_1.range)(0x169d, 0x169f), |
||||
|
...(0, util_1.range)(0x16f1, 0x16ff), |
||||
|
0x170d, |
||||
|
...(0, util_1.range)(0x1715, 0x171f), |
||||
|
...(0, util_1.range)(0x1737, 0x173f), |
||||
|
...(0, util_1.range)(0x1754, 0x175f), |
||||
|
0x176d, |
||||
|
0x1771, |
||||
|
...(0, util_1.range)(0x1774, 0x177f), |
||||
|
...(0, util_1.range)(0x17dd, 0x17df), |
||||
|
...(0, util_1.range)(0x17ea, 0x17ff), |
||||
|
0x180f, |
||||
|
...(0, util_1.range)(0x181a, 0x181f), |
||||
|
...(0, util_1.range)(0x1878, 0x187f), |
||||
|
...(0, util_1.range)(0x18aa, 0x1dff), |
||||
|
...(0, util_1.range)(0x1e9c, 0x1e9f), |
||||
|
...(0, util_1.range)(0x1efa, 0x1eff), |
||||
|
...(0, util_1.range)(0x1f16, 0x1f17), |
||||
|
...(0, util_1.range)(0x1f1e, 0x1f1f), |
||||
|
...(0, util_1.range)(0x1f46, 0x1f47), |
||||
|
...(0, util_1.range)(0x1f4e, 0x1f4f), |
||||
|
0x1f58, |
||||
|
0x1f5a, |
||||
|
0x1f5c, |
||||
|
0x1f5e, |
||||
|
...(0, util_1.range)(0x1f7e, 0x1f7f), |
||||
|
0x1fb5, |
||||
|
0x1fc5, |
||||
|
...(0, util_1.range)(0x1fd4, 0x1fd5), |
||||
|
0x1fdc, |
||||
|
...(0, util_1.range)(0x1ff0, 0x1ff1), |
||||
|
0x1ff5, |
||||
|
0x1fff, |
||||
|
...(0, util_1.range)(0x2053, 0x2056), |
||||
|
...(0, util_1.range)(0x2058, 0x205e), |
||||
|
...(0, util_1.range)(0x2064, 0x2069), |
||||
|
...(0, util_1.range)(0x2072, 0x2073), |
||||
|
...(0, util_1.range)(0x208f, 0x209f), |
||||
|
...(0, util_1.range)(0x20b2, 0x20cf), |
||||
|
...(0, util_1.range)(0x20eb, 0x20ff), |
||||
|
...(0, util_1.range)(0x213b, 0x213c), |
||||
|
...(0, util_1.range)(0x214c, 0x2152), |
||||
|
...(0, util_1.range)(0x2184, 0x218f), |
||||
|
...(0, util_1.range)(0x23cf, 0x23ff), |
||||
|
...(0, util_1.range)(0x2427, 0x243f), |
||||
|
...(0, util_1.range)(0x244b, 0x245f), |
||||
|
0x24ff, |
||||
|
...(0, util_1.range)(0x2614, 0x2615), |
||||
|
0x2618, |
||||
|
...(0, util_1.range)(0x267e, 0x267f), |
||||
|
...(0, util_1.range)(0x268a, 0x2700), |
||||
|
0x2705, |
||||
|
...(0, util_1.range)(0x270a, 0x270b), |
||||
|
0x2728, |
||||
|
0x274c, |
||||
|
0x274e, |
||||
|
...(0, util_1.range)(0x2753, 0x2755), |
||||
|
0x2757, |
||||
|
...(0, util_1.range)(0x275f, 0x2760), |
||||
|
...(0, util_1.range)(0x2795, 0x2797), |
||||
|
0x27b0, |
||||
|
...(0, util_1.range)(0x27bf, 0x27cf), |
||||
|
...(0, util_1.range)(0x27ec, 0x27ef), |
||||
|
...(0, util_1.range)(0x2b00, 0x2e7f), |
||||
|
0x2e9a, |
||||
|
...(0, util_1.range)(0x2ef4, 0x2eff), |
||||
|
...(0, util_1.range)(0x2fd6, 0x2fef), |
||||
|
...(0, util_1.range)(0x2ffc, 0x2fff), |
||||
|
0x3040, |
||||
|
...(0, util_1.range)(0x3097, 0x3098), |
||||
|
...(0, util_1.range)(0x3100, 0x3104), |
||||
|
...(0, util_1.range)(0x312d, 0x3130), |
||||
|
0x318f, |
||||
|
...(0, util_1.range)(0x31b8, 0x31ef), |
||||
|
...(0, util_1.range)(0x321d, 0x321f), |
||||
|
...(0, util_1.range)(0x3244, 0x3250), |
||||
|
...(0, util_1.range)(0x327c, 0x327e), |
||||
|
...(0, util_1.range)(0x32cc, 0x32cf), |
||||
|
0x32ff, |
||||
|
...(0, util_1.range)(0x3377, 0x337a), |
||||
|
...(0, util_1.range)(0x33de, 0x33df), |
||||
|
0x33ff, |
||||
|
...(0, util_1.range)(0x4db6, 0x4dff), |
||||
|
...(0, util_1.range)(0x9fa6, 0x9fff), |
||||
|
...(0, util_1.range)(0xa48d, 0xa48f), |
||||
|
...(0, util_1.range)(0xa4c7, 0xabff), |
||||
|
...(0, util_1.range)(0xd7a4, 0xd7ff), |
||||
|
...(0, util_1.range)(0xfa2e, 0xfa2f), |
||||
|
...(0, util_1.range)(0xfa6b, 0xfaff), |
||||
|
...(0, util_1.range)(0xfb07, 0xfb12), |
||||
|
...(0, util_1.range)(0xfb18, 0xfb1c), |
||||
|
0xfb37, |
||||
|
0xfb3d, |
||||
|
0xfb3f, |
||||
|
0xfb42, |
||||
|
0xfb45, |
||||
|
...(0, util_1.range)(0xfbb2, 0xfbd2), |
||||
|
...(0, util_1.range)(0xfd40, 0xfd4f), |
||||
|
...(0, util_1.range)(0xfd90, 0xfd91), |
||||
|
...(0, util_1.range)(0xfdc8, 0xfdcf), |
||||
|
...(0, util_1.range)(0xfdfd, 0xfdff), |
||||
|
...(0, util_1.range)(0xfe10, 0xfe1f), |
||||
|
...(0, util_1.range)(0xfe24, 0xfe2f), |
||||
|
...(0, util_1.range)(0xfe47, 0xfe48), |
||||
|
0xfe53, |
||||
|
0xfe67, |
||||
|
...(0, util_1.range)(0xfe6c, 0xfe6f), |
||||
|
0xfe75, |
||||
|
...(0, util_1.range)(0xfefd, 0xfefe), |
||||
|
0xff00, |
||||
|
...(0, util_1.range)(0xffbf, 0xffc1), |
||||
|
...(0, util_1.range)(0xffc8, 0xffc9), |
||||
|
...(0, util_1.range)(0xffd0, 0xffd1), |
||||
|
...(0, util_1.range)(0xffd8, 0xffd9), |
||||
|
...(0, util_1.range)(0xffdd, 0xffdf), |
||||
|
0xffe7, |
||||
|
...(0, util_1.range)(0xffef, 0xfff8), |
||||
|
...(0, util_1.range)(0x10000, 0x102ff), |
||||
|
0x1031f, |
||||
|
...(0, util_1.range)(0x10324, 0x1032f), |
||||
|
...(0, util_1.range)(0x1034b, 0x103ff), |
||||
|
...(0, util_1.range)(0x10426, 0x10427), |
||||
|
...(0, util_1.range)(0x1044e, 0x1cfff), |
||||
|
...(0, util_1.range)(0x1d0f6, 0x1d0ff), |
||||
|
...(0, util_1.range)(0x1d127, 0x1d129), |
||||
|
...(0, util_1.range)(0x1d1de, 0x1d3ff), |
||||
|
0x1d455, |
||||
|
0x1d49d, |
||||
|
...(0, util_1.range)(0x1d4a0, 0x1d4a1), |
||||
|
...(0, util_1.range)(0x1d4a3, 0x1d4a4), |
||||
|
...(0, util_1.range)(0x1d4a7, 0x1d4a8), |
||||
|
0x1d4ad, |
||||
|
0x1d4ba, |
||||
|
0x1d4bc, |
||||
|
0x1d4c1, |
||||
|
0x1d4c4, |
||||
|
0x1d506, |
||||
|
...(0, util_1.range)(0x1d50b, 0x1d50c), |
||||
|
0x1d515, |
||||
|
0x1d51d, |
||||
|
0x1d53a, |
||||
|
0x1d53f, |
||||
|
0x1d545, |
||||
|
...(0, util_1.range)(0x1d547, 0x1d549), |
||||
|
0x1d551, |
||||
|
...(0, util_1.range)(0x1d6a4, 0x1d6a7), |
||||
|
...(0, util_1.range)(0x1d7ca, 0x1d7cd), |
||||
|
...(0, util_1.range)(0x1d800, 0x1fffd), |
||||
|
...(0, util_1.range)(0x2a6d7, 0x2f7ff), |
||||
|
...(0, util_1.range)(0x2fa1e, 0x2fffd), |
||||
|
...(0, util_1.range)(0x30000, 0x3fffd), |
||||
|
...(0, util_1.range)(0x40000, 0x4fffd), |
||||
|
...(0, util_1.range)(0x50000, 0x5fffd), |
||||
|
...(0, util_1.range)(0x60000, 0x6fffd), |
||||
|
...(0, util_1.range)(0x70000, 0x7fffd), |
||||
|
...(0, util_1.range)(0x80000, 0x8fffd), |
||||
|
...(0, util_1.range)(0x90000, 0x9fffd), |
||||
|
...(0, util_1.range)(0xa0000, 0xafffd), |
||||
|
...(0, util_1.range)(0xb0000, 0xbfffd), |
||||
|
...(0, util_1.range)(0xc0000, 0xcfffd), |
||||
|
...(0, util_1.range)(0xd0000, 0xdfffd), |
||||
|
0xe0000, |
||||
|
...(0, util_1.range)(0xe0002, 0xe001f), |
||||
|
...(0, util_1.range)(0xe0080, 0xefffd), |
||||
|
]); |
||||
|
exports.commonly_mapped_to_nothing = new Set([ |
||||
|
0x00ad, 0x034f, 0x1806, 0x180b, 0x180c, 0x180d, 0x200b, 0x200c, 0x200d, |
||||
|
0x2060, 0xfe00, 0xfe01, 0xfe02, 0xfe03, 0xfe04, 0xfe05, 0xfe06, 0xfe07, |
||||
|
0xfe08, 0xfe09, 0xfe0a, 0xfe0b, 0xfe0c, 0xfe0d, 0xfe0e, 0xfe0f, 0xfeff, |
||||
|
]); |
||||
|
exports.non_ASCII_space_characters = new Set([ |
||||
|
0x00a0, 0x1680, |
||||
|
0x2000, 0x2001, 0x2002, |
||||
|
0x2003, 0x2004, |
||||
|
0x2005, 0x2006, |
||||
|
0x2007, 0x2008, |
||||
|
0x2009, 0x200a, |
||||
|
0x200b, 0x202f, |
||||
|
0x205f, 0x3000, |
||||
|
]); |
||||
|
exports.prohibited_characters = new Set([ |
||||
|
...exports.non_ASCII_space_characters, |
||||
|
...(0, util_1.range)(0, 0x001f), |
||||
|
0x007f, |
||||
|
...(0, util_1.range)(0x0080, 0x009f), |
||||
|
0x06dd, |
||||
|
0x070f, |
||||
|
0x180e, |
||||
|
0x200c, |
||||
|
0x200d, |
||||
|
0x2028, |
||||
|
0x2029, |
||||
|
0x2060, |
||||
|
0x2061, |
||||
|
0x2062, |
||||
|
0x2063, |
||||
|
...(0, util_1.range)(0x206a, 0x206f), |
||||
|
0xfeff, |
||||
|
...(0, util_1.range)(0xfff9, 0xfffc), |
||||
|
...(0, util_1.range)(0x1d173, 0x1d17a), |
||||
|
...(0, util_1.range)(0xe000, 0xf8ff), |
||||
|
...(0, util_1.range)(0xf0000, 0xffffd), |
||||
|
...(0, util_1.range)(0x100000, 0x10fffd), |
||||
|
...(0, util_1.range)(0xfdd0, 0xfdef), |
||||
|
...(0, util_1.range)(0xfffe, 0xffff), |
||||
|
...(0, util_1.range)(0x1fffe, 0x1ffff), |
||||
|
...(0, util_1.range)(0x2fffe, 0x2ffff), |
||||
|
...(0, util_1.range)(0x3fffe, 0x3ffff), |
||||
|
...(0, util_1.range)(0x4fffe, 0x4ffff), |
||||
|
...(0, util_1.range)(0x5fffe, 0x5ffff), |
||||
|
...(0, util_1.range)(0x6fffe, 0x6ffff), |
||||
|
...(0, util_1.range)(0x7fffe, 0x7ffff), |
||||
|
...(0, util_1.range)(0x8fffe, 0x8ffff), |
||||
|
...(0, util_1.range)(0x9fffe, 0x9ffff), |
||||
|
...(0, util_1.range)(0xafffe, 0xaffff), |
||||
|
...(0, util_1.range)(0xbfffe, 0xbffff), |
||||
|
...(0, util_1.range)(0xcfffe, 0xcffff), |
||||
|
...(0, util_1.range)(0xdfffe, 0xdffff), |
||||
|
...(0, util_1.range)(0xefffe, 0xeffff), |
||||
|
...(0, util_1.range)(0x10fffe, 0x10ffff), |
||||
|
...(0, util_1.range)(0xd800, 0xdfff), |
||||
|
0xfff9, |
||||
|
0xfffa, |
||||
|
0xfffb, |
||||
|
0xfffc, |
||||
|
0xfffd, |
||||
|
...(0, util_1.range)(0x2ff0, 0x2ffb), |
||||
|
0x0340, |
||||
|
0x0341, |
||||
|
0x200e, |
||||
|
0x200f, |
||||
|
0x202a, |
||||
|
0x202b, |
||||
|
0x202c, |
||||
|
0x202d, |
||||
|
0x202e, |
||||
|
0x206a, |
||||
|
0x206b, |
||||
|
0x206c, |
||||
|
0x206d, |
||||
|
0x206e, |
||||
|
0x206f, |
||||
|
0xe0001, |
||||
|
...(0, util_1.range)(0xe0020, 0xe007f), |
||||
|
]); |
||||
|
exports.bidirectional_r_al = new Set([ |
||||
|
0x05be, |
||||
|
0x05c0, |
||||
|
0x05c3, |
||||
|
...(0, util_1.range)(0x05d0, 0x05ea), |
||||
|
...(0, util_1.range)(0x05f0, 0x05f4), |
||||
|
0x061b, |
||||
|
0x061f, |
||||
|
...(0, util_1.range)(0x0621, 0x063a), |
||||
|
...(0, util_1.range)(0x0640, 0x064a), |
||||
|
...(0, util_1.range)(0x066d, 0x066f), |
||||
|
...(0, util_1.range)(0x0671, 0x06d5), |
||||
|
0x06dd, |
||||
|
...(0, util_1.range)(0x06e5, 0x06e6), |
||||
|
...(0, util_1.range)(0x06fa, 0x06fe), |
||||
|
...(0, util_1.range)(0x0700, 0x070d), |
||||
|
0x0710, |
||||
|
...(0, util_1.range)(0x0712, 0x072c), |
||||
|
...(0, util_1.range)(0x0780, 0x07a5), |
||||
|
0x07b1, |
||||
|
0x200f, |
||||
|
0xfb1d, |
||||
|
...(0, util_1.range)(0xfb1f, 0xfb28), |
||||
|
...(0, util_1.range)(0xfb2a, 0xfb36), |
||||
|
...(0, util_1.range)(0xfb38, 0xfb3c), |
||||
|
0xfb3e, |
||||
|
...(0, util_1.range)(0xfb40, 0xfb41), |
||||
|
...(0, util_1.range)(0xfb43, 0xfb44), |
||||
|
...(0, util_1.range)(0xfb46, 0xfbb1), |
||||
|
...(0, util_1.range)(0xfbd3, 0xfd3d), |
||||
|
...(0, util_1.range)(0xfd50, 0xfd8f), |
||||
|
...(0, util_1.range)(0xfd92, 0xfdc7), |
||||
|
...(0, util_1.range)(0xfdf0, 0xfdfc), |
||||
|
...(0, util_1.range)(0xfe70, 0xfe74), |
||||
|
...(0, util_1.range)(0xfe76, 0xfefc), |
||||
|
]); |
||||
|
exports.bidirectional_l = new Set([ |
||||
|
...(0, util_1.range)(0x0041, 0x005a), |
||||
|
...(0, util_1.range)(0x0061, 0x007a), |
||||
|
0x00aa, |
||||
|
0x00b5, |
||||
|
0x00ba, |
||||
|
...(0, util_1.range)(0x00c0, 0x00d6), |
||||
|
...(0, util_1.range)(0x00d8, 0x00f6), |
||||
|
...(0, util_1.range)(0x00f8, 0x0220), |
||||
|
...(0, util_1.range)(0x0222, 0x0233), |
||||
|
...(0, util_1.range)(0x0250, 0x02ad), |
||||
|
...(0, util_1.range)(0x02b0, 0x02b8), |
||||
|
...(0, util_1.range)(0x02bb, 0x02c1), |
||||
|
...(0, util_1.range)(0x02d0, 0x02d1), |
||||
|
...(0, util_1.range)(0x02e0, 0x02e4), |
||||
|
0x02ee, |
||||
|
0x037a, |
||||
|
0x0386, |
||||
|
...(0, util_1.range)(0x0388, 0x038a), |
||||
|
0x038c, |
||||
|
...(0, util_1.range)(0x038e, 0x03a1), |
||||
|
...(0, util_1.range)(0x03a3, 0x03ce), |
||||
|
...(0, util_1.range)(0x03d0, 0x03f5), |
||||
|
...(0, util_1.range)(0x0400, 0x0482), |
||||
|
...(0, util_1.range)(0x048a, 0x04ce), |
||||
|
...(0, util_1.range)(0x04d0, 0x04f5), |
||||
|
...(0, util_1.range)(0x04f8, 0x04f9), |
||||
|
...(0, util_1.range)(0x0500, 0x050f), |
||||
|
...(0, util_1.range)(0x0531, 0x0556), |
||||
|
...(0, util_1.range)(0x0559, 0x055f), |
||||
|
...(0, util_1.range)(0x0561, 0x0587), |
||||
|
0x0589, |
||||
|
0x0903, |
||||
|
...(0, util_1.range)(0x0905, 0x0939), |
||||
|
...(0, util_1.range)(0x093d, 0x0940), |
||||
|
...(0, util_1.range)(0x0949, 0x094c), |
||||
|
0x0950, |
||||
|
...(0, util_1.range)(0x0958, 0x0961), |
||||
|
...(0, util_1.range)(0x0964, 0x0970), |
||||
|
...(0, util_1.range)(0x0982, 0x0983), |
||||
|
...(0, util_1.range)(0x0985, 0x098c), |
||||
|
...(0, util_1.range)(0x098f, 0x0990), |
||||
|
...(0, util_1.range)(0x0993, 0x09a8), |
||||
|
...(0, util_1.range)(0x09aa, 0x09b0), |
||||
|
0x09b2, |
||||
|
...(0, util_1.range)(0x09b6, 0x09b9), |
||||
|
...(0, util_1.range)(0x09be, 0x09c0), |
||||
|
...(0, util_1.range)(0x09c7, 0x09c8), |
||||
|
...(0, util_1.range)(0x09cb, 0x09cc), |
||||
|
0x09d7, |
||||
|
...(0, util_1.range)(0x09dc, 0x09dd), |
||||
|
...(0, util_1.range)(0x09df, 0x09e1), |
||||
|
...(0, util_1.range)(0x09e6, 0x09f1), |
||||
|
...(0, util_1.range)(0x09f4, 0x09fa), |
||||
|
...(0, util_1.range)(0x0a05, 0x0a0a), |
||||
|
...(0, util_1.range)(0x0a0f, 0x0a10), |
||||
|
...(0, util_1.range)(0x0a13, 0x0a28), |
||||
|
...(0, util_1.range)(0x0a2a, 0x0a30), |
||||
|
...(0, util_1.range)(0x0a32, 0x0a33), |
||||
|
...(0, util_1.range)(0x0a35, 0x0a36), |
||||
|
...(0, util_1.range)(0x0a38, 0x0a39), |
||||
|
...(0, util_1.range)(0x0a3e, 0x0a40), |
||||
|
...(0, util_1.range)(0x0a59, 0x0a5c), |
||||
|
0x0a5e, |
||||
|
...(0, util_1.range)(0x0a66, 0x0a6f), |
||||
|
...(0, util_1.range)(0x0a72, 0x0a74), |
||||
|
0x0a83, |
||||
|
...(0, util_1.range)(0x0a85, 0x0a8b), |
||||
|
0x0a8d, |
||||
|
...(0, util_1.range)(0x0a8f, 0x0a91), |
||||
|
...(0, util_1.range)(0x0a93, 0x0aa8), |
||||
|
...(0, util_1.range)(0x0aaa, 0x0ab0), |
||||
|
...(0, util_1.range)(0x0ab2, 0x0ab3), |
||||
|
...(0, util_1.range)(0x0ab5, 0x0ab9), |
||||
|
...(0, util_1.range)(0x0abd, 0x0ac0), |
||||
|
0x0ac9, |
||||
|
...(0, util_1.range)(0x0acb, 0x0acc), |
||||
|
0x0ad0, |
||||
|
0x0ae0, |
||||
|
...(0, util_1.range)(0x0ae6, 0x0aef), |
||||
|
...(0, util_1.range)(0x0b02, 0x0b03), |
||||
|
...(0, util_1.range)(0x0b05, 0x0b0c), |
||||
|
...(0, util_1.range)(0x0b0f, 0x0b10), |
||||
|
...(0, util_1.range)(0x0b13, 0x0b28), |
||||
|
...(0, util_1.range)(0x0b2a, 0x0b30), |
||||
|
...(0, util_1.range)(0x0b32, 0x0b33), |
||||
|
...(0, util_1.range)(0x0b36, 0x0b39), |
||||
|
...(0, util_1.range)(0x0b3d, 0x0b3e), |
||||
|
0x0b40, |
||||
|
...(0, util_1.range)(0x0b47, 0x0b48), |
||||
|
...(0, util_1.range)(0x0b4b, 0x0b4c), |
||||
|
0x0b57, |
||||
|
...(0, util_1.range)(0x0b5c, 0x0b5d), |
||||
|
...(0, util_1.range)(0x0b5f, 0x0b61), |
||||
|
...(0, util_1.range)(0x0b66, 0x0b70), |
||||
|
0x0b83, |
||||
|
...(0, util_1.range)(0x0b85, 0x0b8a), |
||||
|
...(0, util_1.range)(0x0b8e, 0x0b90), |
||||
|
...(0, util_1.range)(0x0b92, 0x0b95), |
||||
|
...(0, util_1.range)(0x0b99, 0x0b9a), |
||||
|
0x0b9c, |
||||
|
...(0, util_1.range)(0x0b9e, 0x0b9f), |
||||
|
...(0, util_1.range)(0x0ba3, 0x0ba4), |
||||
|
...(0, util_1.range)(0x0ba8, 0x0baa), |
||||
|
...(0, util_1.range)(0x0bae, 0x0bb5), |
||||
|
...(0, util_1.range)(0x0bb7, 0x0bb9), |
||||
|
...(0, util_1.range)(0x0bbe, 0x0bbf), |
||||
|
...(0, util_1.range)(0x0bc1, 0x0bc2), |
||||
|
...(0, util_1.range)(0x0bc6, 0x0bc8), |
||||
|
...(0, util_1.range)(0x0bca, 0x0bcc), |
||||
|
0x0bd7, |
||||
|
...(0, util_1.range)(0x0be7, 0x0bf2), |
||||
|
...(0, util_1.range)(0x0c01, 0x0c03), |
||||
|
...(0, util_1.range)(0x0c05, 0x0c0c), |
||||
|
...(0, util_1.range)(0x0c0e, 0x0c10), |
||||
|
...(0, util_1.range)(0x0c12, 0x0c28), |
||||
|
...(0, util_1.range)(0x0c2a, 0x0c33), |
||||
|
...(0, util_1.range)(0x0c35, 0x0c39), |
||||
|
...(0, util_1.range)(0x0c41, 0x0c44), |
||||
|
...(0, util_1.range)(0x0c60, 0x0c61), |
||||
|
...(0, util_1.range)(0x0c66, 0x0c6f), |
||||
|
...(0, util_1.range)(0x0c82, 0x0c83), |
||||
|
...(0, util_1.range)(0x0c85, 0x0c8c), |
||||
|
...(0, util_1.range)(0x0c8e, 0x0c90), |
||||
|
...(0, util_1.range)(0x0c92, 0x0ca8), |
||||
|
...(0, util_1.range)(0x0caa, 0x0cb3), |
||||
|
...(0, util_1.range)(0x0cb5, 0x0cb9), |
||||
|
0x0cbe, |
||||
|
...(0, util_1.range)(0x0cc0, 0x0cc4), |
||||
|
...(0, util_1.range)(0x0cc7, 0x0cc8), |
||||
|
...(0, util_1.range)(0x0cca, 0x0ccb), |
||||
|
...(0, util_1.range)(0x0cd5, 0x0cd6), |
||||
|
0x0cde, |
||||
|
...(0, util_1.range)(0x0ce0, 0x0ce1), |
||||
|
...(0, util_1.range)(0x0ce6, 0x0cef), |
||||
|
...(0, util_1.range)(0x0d02, 0x0d03), |
||||
|
...(0, util_1.range)(0x0d05, 0x0d0c), |
||||
|
...(0, util_1.range)(0x0d0e, 0x0d10), |
||||
|
...(0, util_1.range)(0x0d12, 0x0d28), |
||||
|
...(0, util_1.range)(0x0d2a, 0x0d39), |
||||
|
...(0, util_1.range)(0x0d3e, 0x0d40), |
||||
|
...(0, util_1.range)(0x0d46, 0x0d48), |
||||
|
...(0, util_1.range)(0x0d4a, 0x0d4c), |
||||
|
0x0d57, |
||||
|
...(0, util_1.range)(0x0d60, 0x0d61), |
||||
|
...(0, util_1.range)(0x0d66, 0x0d6f), |
||||
|
...(0, util_1.range)(0x0d82, 0x0d83), |
||||
|
...(0, util_1.range)(0x0d85, 0x0d96), |
||||
|
...(0, util_1.range)(0x0d9a, 0x0db1), |
||||
|
...(0, util_1.range)(0x0db3, 0x0dbb), |
||||
|
0x0dbd, |
||||
|
...(0, util_1.range)(0x0dc0, 0x0dc6), |
||||
|
...(0, util_1.range)(0x0dcf, 0x0dd1), |
||||
|
...(0, util_1.range)(0x0dd8, 0x0ddf), |
||||
|
...(0, util_1.range)(0x0df2, 0x0df4), |
||||
|
...(0, util_1.range)(0x0e01, 0x0e30), |
||||
|
...(0, util_1.range)(0x0e32, 0x0e33), |
||||
|
...(0, util_1.range)(0x0e40, 0x0e46), |
||||
|
...(0, util_1.range)(0x0e4f, 0x0e5b), |
||||
|
...(0, util_1.range)(0x0e81, 0x0e82), |
||||
|
0x0e84, |
||||
|
...(0, util_1.range)(0x0e87, 0x0e88), |
||||
|
0x0e8a, |
||||
|
0x0e8d, |
||||
|
...(0, util_1.range)(0x0e94, 0x0e97), |
||||
|
...(0, util_1.range)(0x0e99, 0x0e9f), |
||||
|
...(0, util_1.range)(0x0ea1, 0x0ea3), |
||||
|
0x0ea5, |
||||
|
0x0ea7, |
||||
|
...(0, util_1.range)(0x0eaa, 0x0eab), |
||||
|
...(0, util_1.range)(0x0ead, 0x0eb0), |
||||
|
...(0, util_1.range)(0x0eb2, 0x0eb3), |
||||
|
0x0ebd, |
||||
|
...(0, util_1.range)(0x0ec0, 0x0ec4), |
||||
|
0x0ec6, |
||||
|
...(0, util_1.range)(0x0ed0, 0x0ed9), |
||||
|
...(0, util_1.range)(0x0edc, 0x0edd), |
||||
|
...(0, util_1.range)(0x0f00, 0x0f17), |
||||
|
...(0, util_1.range)(0x0f1a, 0x0f34), |
||||
|
0x0f36, |
||||
|
0x0f38, |
||||
|
...(0, util_1.range)(0x0f3e, 0x0f47), |
||||
|
...(0, util_1.range)(0x0f49, 0x0f6a), |
||||
|
0x0f7f, |
||||
|
0x0f85, |
||||
|
...(0, util_1.range)(0x0f88, 0x0f8b), |
||||
|
...(0, util_1.range)(0x0fbe, 0x0fc5), |
||||
|
...(0, util_1.range)(0x0fc7, 0x0fcc), |
||||
|
0x0fcf, |
||||
|
...(0, util_1.range)(0x1000, 0x1021), |
||||
|
...(0, util_1.range)(0x1023, 0x1027), |
||||
|
...(0, util_1.range)(0x1029, 0x102a), |
||||
|
0x102c, |
||||
|
0x1031, |
||||
|
0x1038, |
||||
|
...(0, util_1.range)(0x1040, 0x1057), |
||||
|
...(0, util_1.range)(0x10a0, 0x10c5), |
||||
|
...(0, util_1.range)(0x10d0, 0x10f8), |
||||
|
0x10fb, |
||||
|
...(0, util_1.range)(0x1100, 0x1159), |
||||
|
...(0, util_1.range)(0x115f, 0x11a2), |
||||
|
...(0, util_1.range)(0x11a8, 0x11f9), |
||||
|
...(0, util_1.range)(0x1200, 0x1206), |
||||
|
...(0, util_1.range)(0x1208, 0x1246), |
||||
|
0x1248, |
||||
|
...(0, util_1.range)(0x124a, 0x124d), |
||||
|
...(0, util_1.range)(0x1250, 0x1256), |
||||
|
0x1258, |
||||
|
...(0, util_1.range)(0x125a, 0x125d), |
||||
|
...(0, util_1.range)(0x1260, 0x1286), |
||||
|
0x1288, |
||||
|
...(0, util_1.range)(0x128a, 0x128d), |
||||
|
...(0, util_1.range)(0x1290, 0x12ae), |
||||
|
0x12b0, |
||||
|
...(0, util_1.range)(0x12b2, 0x12b5), |
||||
|
...(0, util_1.range)(0x12b8, 0x12be), |
||||
|
0x12c0, |
||||
|
...(0, util_1.range)(0x12c2, 0x12c5), |
||||
|
...(0, util_1.range)(0x12c8, 0x12ce), |
||||
|
...(0, util_1.range)(0x12d0, 0x12d6), |
||||
|
...(0, util_1.range)(0x12d8, 0x12ee), |
||||
|
...(0, util_1.range)(0x12f0, 0x130e), |
||||
|
0x1310, |
||||
|
...(0, util_1.range)(0x1312, 0x1315), |
||||
|
...(0, util_1.range)(0x1318, 0x131e), |
||||
|
...(0, util_1.range)(0x1320, 0x1346), |
||||
|
...(0, util_1.range)(0x1348, 0x135a), |
||||
|
...(0, util_1.range)(0x1361, 0x137c), |
||||
|
...(0, util_1.range)(0x13a0, 0x13f4), |
||||
|
...(0, util_1.range)(0x1401, 0x1676), |
||||
|
...(0, util_1.range)(0x1681, 0x169a), |
||||
|
...(0, util_1.range)(0x16a0, 0x16f0), |
||||
|
...(0, util_1.range)(0x1700, 0x170c), |
||||
|
...(0, util_1.range)(0x170e, 0x1711), |
||||
|
...(0, util_1.range)(0x1720, 0x1731), |
||||
|
...(0, util_1.range)(0x1735, 0x1736), |
||||
|
...(0, util_1.range)(0x1740, 0x1751), |
||||
|
...(0, util_1.range)(0x1760, 0x176c), |
||||
|
...(0, util_1.range)(0x176e, 0x1770), |
||||
|
...(0, util_1.range)(0x1780, 0x17b6), |
||||
|
...(0, util_1.range)(0x17be, 0x17c5), |
||||
|
...(0, util_1.range)(0x17c7, 0x17c8), |
||||
|
...(0, util_1.range)(0x17d4, 0x17da), |
||||
|
0x17dc, |
||||
|
...(0, util_1.range)(0x17e0, 0x17e9), |
||||
|
...(0, util_1.range)(0x1810, 0x1819), |
||||
|
...(0, util_1.range)(0x1820, 0x1877), |
||||
|
...(0, util_1.range)(0x1880, 0x18a8), |
||||
|
...(0, util_1.range)(0x1e00, 0x1e9b), |
||||
|
...(0, util_1.range)(0x1ea0, 0x1ef9), |
||||
|
...(0, util_1.range)(0x1f00, 0x1f15), |
||||
|
...(0, util_1.range)(0x1f18, 0x1f1d), |
||||
|
...(0, util_1.range)(0x1f20, 0x1f45), |
||||
|
...(0, util_1.range)(0x1f48, 0x1f4d), |
||||
|
...(0, util_1.range)(0x1f50, 0x1f57), |
||||
|
0x1f59, |
||||
|
0x1f5b, |
||||
|
0x1f5d, |
||||
|
...(0, util_1.range)(0x1f5f, 0x1f7d), |
||||
|
...(0, util_1.range)(0x1f80, 0x1fb4), |
||||
|
...(0, util_1.range)(0x1fb6, 0x1fbc), |
||||
|
0x1fbe, |
||||
|
...(0, util_1.range)(0x1fc2, 0x1fc4), |
||||
|
...(0, util_1.range)(0x1fc6, 0x1fcc), |
||||
|
...(0, util_1.range)(0x1fd0, 0x1fd3), |
||||
|
...(0, util_1.range)(0x1fd6, 0x1fdb), |
||||
|
...(0, util_1.range)(0x1fe0, 0x1fec), |
||||
|
...(0, util_1.range)(0x1ff2, 0x1ff4), |
||||
|
...(0, util_1.range)(0x1ff6, 0x1ffc), |
||||
|
0x200e, |
||||
|
0x2071, |
||||
|
0x207f, |
||||
|
0x2102, |
||||
|
0x2107, |
||||
|
...(0, util_1.range)(0x210a, 0x2113), |
||||
|
0x2115, |
||||
|
...(0, util_1.range)(0x2119, 0x211d), |
||||
|
0x2124, |
||||
|
0x2126, |
||||
|
0x2128, |
||||
|
...(0, util_1.range)(0x212a, 0x212d), |
||||
|
...(0, util_1.range)(0x212f, 0x2131), |
||||
|
...(0, util_1.range)(0x2133, 0x2139), |
||||
|
...(0, util_1.range)(0x213d, 0x213f), |
||||
|
...(0, util_1.range)(0x2145, 0x2149), |
||||
|
...(0, util_1.range)(0x2160, 0x2183), |
||||
|
...(0, util_1.range)(0x2336, 0x237a), |
||||
|
0x2395, |
||||
|
...(0, util_1.range)(0x249c, 0x24e9), |
||||
|
...(0, util_1.range)(0x3005, 0x3007), |
||||
|
...(0, util_1.range)(0x3021, 0x3029), |
||||
|
...(0, util_1.range)(0x3031, 0x3035), |
||||
|
...(0, util_1.range)(0x3038, 0x303c), |
||||
|
...(0, util_1.range)(0x3041, 0x3096), |
||||
|
...(0, util_1.range)(0x309d, 0x309f), |
||||
|
...(0, util_1.range)(0x30a1, 0x30fa), |
||||
|
...(0, util_1.range)(0x30fc, 0x30ff), |
||||
|
...(0, util_1.range)(0x3105, 0x312c), |
||||
|
...(0, util_1.range)(0x3131, 0x318e), |
||||
|
...(0, util_1.range)(0x3190, 0x31b7), |
||||
|
...(0, util_1.range)(0x31f0, 0x321c), |
||||
|
...(0, util_1.range)(0x3220, 0x3243), |
||||
|
...(0, util_1.range)(0x3260, 0x327b), |
||||
|
...(0, util_1.range)(0x327f, 0x32b0), |
||||
|
...(0, util_1.range)(0x32c0, 0x32cb), |
||||
|
...(0, util_1.range)(0x32d0, 0x32fe), |
||||
|
...(0, util_1.range)(0x3300, 0x3376), |
||||
|
...(0, util_1.range)(0x337b, 0x33dd), |
||||
|
...(0, util_1.range)(0x33e0, 0x33fe), |
||||
|
...(0, util_1.range)(0x3400, 0x4db5), |
||||
|
...(0, util_1.range)(0x4e00, 0x9fa5), |
||||
|
...(0, util_1.range)(0xa000, 0xa48c), |
||||
|
...(0, util_1.range)(0xac00, 0xd7a3), |
||||
|
...(0, util_1.range)(0xd800, 0xfa2d), |
||||
|
...(0, util_1.range)(0xfa30, 0xfa6a), |
||||
|
...(0, util_1.range)(0xfb00, 0xfb06), |
||||
|
...(0, util_1.range)(0xfb13, 0xfb17), |
||||
|
...(0, util_1.range)(0xff21, 0xff3a), |
||||
|
...(0, util_1.range)(0xff41, 0xff5a), |
||||
|
...(0, util_1.range)(0xff66, 0xffbe), |
||||
|
...(0, util_1.range)(0xffc2, 0xffc7), |
||||
|
...(0, util_1.range)(0xffca, 0xffcf), |
||||
|
...(0, util_1.range)(0xffd2, 0xffd7), |
||||
|
...(0, util_1.range)(0xffda, 0xffdc), |
||||
|
...(0, util_1.range)(0x10300, 0x1031e), |
||||
|
...(0, util_1.range)(0x10320, 0x10323), |
||||
|
...(0, util_1.range)(0x10330, 0x1034a), |
||||
|
...(0, util_1.range)(0x10400, 0x10425), |
||||
|
...(0, util_1.range)(0x10428, 0x1044d), |
||||
|
...(0, util_1.range)(0x1d000, 0x1d0f5), |
||||
|
...(0, util_1.range)(0x1d100, 0x1d126), |
||||
|
...(0, util_1.range)(0x1d12a, 0x1d166), |
||||
|
...(0, util_1.range)(0x1d16a, 0x1d172), |
||||
|
...(0, util_1.range)(0x1d183, 0x1d184), |
||||
|
...(0, util_1.range)(0x1d18c, 0x1d1a9), |
||||
|
...(0, util_1.range)(0x1d1ae, 0x1d1dd), |
||||
|
...(0, util_1.range)(0x1d400, 0x1d454), |
||||
|
...(0, util_1.range)(0x1d456, 0x1d49c), |
||||
|
...(0, util_1.range)(0x1d49e, 0x1d49f), |
||||
|
0x1d4a2, |
||||
|
...(0, util_1.range)(0x1d4a5, 0x1d4a6), |
||||
|
...(0, util_1.range)(0x1d4a9, 0x1d4ac), |
||||
|
...(0, util_1.range)(0x1d4ae, 0x1d4b9), |
||||
|
0x1d4bb, |
||||
|
...(0, util_1.range)(0x1d4bd, 0x1d4c0), |
||||
|
...(0, util_1.range)(0x1d4c2, 0x1d4c3), |
||||
|
...(0, util_1.range)(0x1d4c5, 0x1d505), |
||||
|
...(0, util_1.range)(0x1d507, 0x1d50a), |
||||
|
...(0, util_1.range)(0x1d50d, 0x1d514), |
||||
|
...(0, util_1.range)(0x1d516, 0x1d51c), |
||||
|
...(0, util_1.range)(0x1d51e, 0x1d539), |
||||
|
...(0, util_1.range)(0x1d53b, 0x1d53e), |
||||
|
...(0, util_1.range)(0x1d540, 0x1d544), |
||||
|
0x1d546, |
||||
|
...(0, util_1.range)(0x1d54a, 0x1d550), |
||||
|
...(0, util_1.range)(0x1d552, 0x1d6a3), |
||||
|
...(0, util_1.range)(0x1d6a8, 0x1d7c9), |
||||
|
...(0, util_1.range)(0x20000, 0x2a6d6), |
||||
|
...(0, util_1.range)(0x2f800, 0x2fa1d), |
||||
|
...(0, util_1.range)(0xf0000, 0xffffd), |
||||
|
...(0, util_1.range)(0x100000, 0x10fffd), |
||||
|
]); |
||||
|
//# sourceMappingURL=code-points-src.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,2 @@ |
|||||
|
export {}; |
||||
|
//# sourceMappingURL=generate-code-points.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"generate-code-points.d.ts","sourceRoot":"","sources":["../src/generate-code-points.ts"],"names":[],"mappings":""} |
||||
@ -0,0 +1,83 @@ |
|||||
|
"use strict"; |
||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
||||
|
if (k2 === undefined) k2 = k; |
||||
|
var desc = Object.getOwnPropertyDescriptor(m, k); |
||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
||||
|
desc = { enumerable: true, get: function() { return m[k]; } }; |
||||
|
} |
||||
|
Object.defineProperty(o, k2, desc); |
||||
|
}) : (function(o, m, k, k2) { |
||||
|
if (k2 === undefined) k2 = k; |
||||
|
o[k2] = m[k]; |
||||
|
})); |
||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v }); |
||||
|
}) : function(o, v) { |
||||
|
o["default"] = v; |
||||
|
}); |
||||
|
var __importStar = (this && this.__importStar) || (function () { |
||||
|
var ownKeys = function(o) { |
||||
|
ownKeys = Object.getOwnPropertyNames || function (o) { |
||||
|
var ar = []; |
||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; |
||||
|
return ar; |
||||
|
}; |
||||
|
return ownKeys(o); |
||||
|
}; |
||||
|
return function (mod) { |
||||
|
if (mod && mod.__esModule) return mod; |
||||
|
var result = {}; |
||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); |
||||
|
__setModuleDefault(result, mod); |
||||
|
return result; |
||||
|
}; |
||||
|
})(); |
||||
|
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
|
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
const zlib_1 = require("zlib"); |
||||
|
const sparse_bitfield_1 = __importDefault(require("sparse-bitfield")); |
||||
|
const codePoints = __importStar(require("./code-points-src")); |
||||
|
const fs_1 = require("fs"); |
||||
|
const prettier = __importStar(require("prettier")); |
||||
|
const unassigned_code_points = (0, sparse_bitfield_1.default)(); |
||||
|
const commonly_mapped_to_nothing = (0, sparse_bitfield_1.default)(); |
||||
|
const non_ascii_space_characters = (0, sparse_bitfield_1.default)(); |
||||
|
const prohibited_characters = (0, sparse_bitfield_1.default)(); |
||||
|
const bidirectional_r_al = (0, sparse_bitfield_1.default)(); |
||||
|
const bidirectional_l = (0, sparse_bitfield_1.default)(); |
||||
|
function traverse(bits, src) { |
||||
|
for (const code of src.keys()) { |
||||
|
bits.set(code, true); |
||||
|
} |
||||
|
const buffer = bits.toBuffer(); |
||||
|
return Buffer.concat([createSize(buffer), buffer]); |
||||
|
} |
||||
|
function createSize(buffer) { |
||||
|
const buf = Buffer.alloc(4); |
||||
|
buf.writeUInt32BE(buffer.length); |
||||
|
return buf; |
||||
|
} |
||||
|
const memory = []; |
||||
|
memory.push(traverse(unassigned_code_points, codePoints.unassigned_code_points), traverse(commonly_mapped_to_nothing, codePoints.commonly_mapped_to_nothing), traverse(non_ascii_space_characters, codePoints.non_ASCII_space_characters), traverse(prohibited_characters, codePoints.prohibited_characters), traverse(bidirectional_r_al, codePoints.bidirectional_r_al), traverse(bidirectional_l, codePoints.bidirectional_l)); |
||||
|
async function writeCodepoints() { |
||||
|
const config = await prettier.resolveConfig(__dirname); |
||||
|
const formatOptions = { ...config, parser: 'typescript' }; |
||||
|
function write(stream, chunk) { |
||||
|
return new Promise((resolve) => stream.write(chunk, () => resolve())); |
||||
|
} |
||||
|
await write((0, fs_1.createWriteStream)(process.argv[2]), await prettier.format(`import { gunzipSync } from 'zlib';
|
||||
|
|
||||
|
export default gunzipSync( |
||||
|
Buffer.from( |
||||
|
'${(0, zlib_1.gzipSync)(Buffer.concat(memory), { level: 9 }).toString('base64')}', |
||||
|
'base64' |
||||
|
) |
||||
|
); |
||||
|
`, formatOptions));
|
||||
|
const fsStreamUncompressedData = (0, fs_1.createWriteStream)(process.argv[3]); |
||||
|
await write(fsStreamUncompressedData, await prettier.format(`const data = Buffer.from('${Buffer.concat(memory).toString('base64')}', 'base64');\nexport default data;\n`, formatOptions)); |
||||
|
} |
||||
|
writeCodepoints().catch((error) => console.error('error occurred generating saslprep codepoint data', { error })); |
||||
|
//# sourceMappingURL=generate-code-points.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"generate-code-points.js","sourceRoot":"","sources":["../src/generate-code-points.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAgC;AAChC,sEAAuC;AACvC,8DAAgD;AAChD,2BAAuC;AACvC,mDAAqC;AAGrC,MAAM,sBAAsB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC1C,MAAM,0BAA0B,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC9C,MAAM,0BAA0B,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC9C,MAAM,qBAAqB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AACzC,MAAM,kBAAkB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AACtC,MAAM,eAAe,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAMnC,SAAS,QAAQ,CAAC,IAA+B,EAAE,GAAgB;IACjE,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,MAAM,GAAa,EAAE,CAAC;AAE5B,MAAM,CAAC,IAAI,CACT,QAAQ,CAAC,sBAAsB,EAAE,UAAU,CAAC,sBAAsB,CAAC,EACnE,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,CAAC,EAC3E,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,CAAC,EAC3E,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,qBAAqB,CAAC,EACjE,QAAQ,CAAC,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAC3D,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,CACtD,CAAC;AAEF,KAAK,UAAU,eAAe;IAC5B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAE1D,SAAS,KAAK,CAAC,MAAgB,EAAE,KAAa;QAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,KAAK,CACT,IAAA,sBAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAClC,MAAM,QAAQ,CAAC,MAAM,CACnB;;;;SAIG,IAAA,eAAQ,EAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;;;;GAItE,EACG,aAAa,CACd,CACF,CAAC;IAEF,MAAM,wBAAwB,GAAG,IAAA,sBAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpE,MAAM,KAAK,CACT,wBAAwB,EACxB,MAAM,QAAQ,CAAC,MAAM,CACnB,6BAA6B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CACzD,QAAQ,CACT,uCAAuC,EACxC,aAAa,CACd,CACF,CAAC;AACJ,CAAC;AAED,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAEhC,OAAO,CAAC,KAAK,CAAC,mDAAmD,EAAE,EAAE,KAAK,EAAE,CAAC,CAC9E,CAAC"} |
||||
@ -0,0 +1,11 @@ |
|||||
|
import type { createMemoryCodePoints } from './memory-code-points'; |
||||
|
declare function saslprep({ unassigned_code_points, commonly_mapped_to_nothing, non_ASCII_space_characters, prohibited_characters, bidirectional_r_al, bidirectional_l, }: ReturnType<typeof createMemoryCodePoints>, input: string, opts?: { |
||||
|
allowUnassigned?: boolean; |
||||
|
}): string; |
||||
|
declare namespace saslprep { |
||||
|
export var saslprep: typeof import("."); |
||||
|
var _a: typeof import("."); |
||||
|
export { _a as default }; |
||||
|
} |
||||
|
export = saslprep; |
||||
|
//# sourceMappingURL=index.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAsCnE,iBAAS,QAAQ,CACf,EACE,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAChB,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,EAC5C,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GACvC,MAAM,CAqGR;kBAhHQ,QAAQ;;;;;AAoHjB,SAAS,QAAQ,CAAC"} |
||||
@ -0,0 +1,65 @@ |
|||||
|
"use strict"; |
||||
|
const getCodePoint = (character) => character.codePointAt(0); |
||||
|
const first = (x) => x[0]; |
||||
|
const last = (x) => x[x.length - 1]; |
||||
|
function toCodePoints(input) { |
||||
|
const codepoints = []; |
||||
|
const size = input.length; |
||||
|
for (let i = 0; i < size; i += 1) { |
||||
|
const before = input.charCodeAt(i); |
||||
|
if (before >= 0xd800 && before <= 0xdbff && size > i + 1) { |
||||
|
const next = input.charCodeAt(i + 1); |
||||
|
if (next >= 0xdc00 && next <= 0xdfff) { |
||||
|
codepoints.push((before - 0xd800) * 0x400 + next - 0xdc00 + 0x10000); |
||||
|
i += 1; |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
codepoints.push(before); |
||||
|
} |
||||
|
return codepoints; |
||||
|
} |
||||
|
function saslprep({ unassigned_code_points, commonly_mapped_to_nothing, non_ASCII_space_characters, prohibited_characters, bidirectional_r_al, bidirectional_l, }, input, opts = {}) { |
||||
|
const mapping2space = non_ASCII_space_characters; |
||||
|
const mapping2nothing = commonly_mapped_to_nothing; |
||||
|
if (typeof input !== 'string') { |
||||
|
throw new TypeError('Expected string.'); |
||||
|
} |
||||
|
if (input.length === 0) { |
||||
|
return ''; |
||||
|
} |
||||
|
const mapped_input = toCodePoints(input) |
||||
|
.map((character) => (mapping2space.get(character) ? 0x20 : character)) |
||||
|
.filter((character) => !mapping2nothing.get(character)); |
||||
|
const normalized_input = String.fromCodePoint |
||||
|
.apply(null, mapped_input) |
||||
|
.normalize('NFKC'); |
||||
|
const normalized_map = toCodePoints(normalized_input); |
||||
|
const hasProhibited = normalized_map.some((character) => prohibited_characters.get(character)); |
||||
|
if (hasProhibited) { |
||||
|
throw new Error('Prohibited character, see https://tools.ietf.org/html/rfc4013#section-2.3'); |
||||
|
} |
||||
|
if (opts.allowUnassigned !== true) { |
||||
|
const hasUnassigned = normalized_map.some((character) => unassigned_code_points.get(character)); |
||||
|
if (hasUnassigned) { |
||||
|
throw new Error('Unassigned code point, see https://tools.ietf.org/html/rfc4013#section-2.5'); |
||||
|
} |
||||
|
} |
||||
|
const hasBidiRAL = normalized_map.some((character) => bidirectional_r_al.get(character)); |
||||
|
const hasBidiL = normalized_map.some((character) => bidirectional_l.get(character)); |
||||
|
if (hasBidiRAL && hasBidiL) { |
||||
|
throw new Error('String must not contain RandALCat and LCat at the same time,' + |
||||
|
' see https://tools.ietf.org/html/rfc3454#section-6'); |
||||
|
} |
||||
|
const isFirstBidiRAL = bidirectional_r_al.get(getCodePoint(first(normalized_input))); |
||||
|
const isLastBidiRAL = bidirectional_r_al.get(getCodePoint(last(normalized_input))); |
||||
|
if (hasBidiRAL && !(isFirstBidiRAL && isLastBidiRAL)) { |
||||
|
throw new Error('Bidirectional RandALCat character must be the first and the last' + |
||||
|
' character of the string, see https://tools.ietf.org/html/rfc3454#section-6'); |
||||
|
} |
||||
|
return normalized_input; |
||||
|
} |
||||
|
saslprep.saslprep = saslprep; |
||||
|
saslprep.default = saslprep; |
||||
|
module.exports = saslprep; |
||||
|
//# sourceMappingURL=index.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,KAAK,GAAG,CAA2B,CAAI,EAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,IAAI,GAAG,CAA2B,CAAI,EAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAO5E,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEnC,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAErC,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACrC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;gBACrE,CAAC,IAAI,CAAC,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAKD,SAAS,QAAQ,CACf,EACE,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAC2B,EAC5C,KAAa,EACb,OAAsC,EAAE;IAQxC,MAAM,aAAa,GAAG,0BAA0B,CAAC;IAMjD,MAAM,eAAe,GAAG,0BAA0B,CAAC;IAEnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAGD,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC;SAErC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;SAErE,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAG1D,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa;SAC1C,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC;SACzB,SAAS,CAAC,MAAM,CAAC,CAAC;IAErB,MAAM,cAAc,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAGtD,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACtD,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CACrC,CAAC;IAEF,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IAGD,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI,EAAE,CAAC;QAClC,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACtD,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,CACtC,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;QACJ,CAAC;IACH,CAAC;IAID,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACnD,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAClC,CAAC;IAEF,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACjD,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAC/B,CAAC;IAIF,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,8DAA8D;YAC5D,oDAAoD,CACvD,CAAC;IACJ,CAAC;IAQD,MAAM,cAAc,GAAG,kBAAkB,CAAC,GAAG,CAC3C,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAE,CACvC,CAAC;IACF,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAC1C,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAE,CACtC,CAAC;IAEF,IAAI,UAAU,IAAI,CAAC,CAAC,cAAc,IAAI,aAAa,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,kEAAkE;YAChE,6EAA6E,CAChF,CAAC;IACJ,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;AAC5B,iBAAS,QAAQ,CAAC"} |
||||
@ -0,0 +1,10 @@ |
|||||
|
import bitfield from 'sparse-bitfield'; |
||||
|
export declare function createMemoryCodePoints(data: Buffer): { |
||||
|
unassigned_code_points: bitfield.BitFieldInstance; |
||||
|
commonly_mapped_to_nothing: bitfield.BitFieldInstance; |
||||
|
non_ASCII_space_characters: bitfield.BitFieldInstance; |
||||
|
prohibited_characters: bitfield.BitFieldInstance; |
||||
|
bidirectional_r_al: bitfield.BitFieldInstance; |
||||
|
bidirectional_l: bitfield.BitFieldInstance; |
||||
|
}; |
||||
|
//# sourceMappingURL=memory-code-points.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"memory-code-points.d.ts","sourceRoot":"","sources":["../src/memory-code-points.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM;;;;;;;EA+BlD"} |
||||
@ -0,0 +1,32 @@ |
|||||
|
"use strict"; |
||||
|
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
|
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
|
}; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
exports.createMemoryCodePoints = createMemoryCodePoints; |
||||
|
const sparse_bitfield_1 = __importDefault(require("sparse-bitfield")); |
||||
|
function createMemoryCodePoints(data) { |
||||
|
let offset = 0; |
||||
|
function read() { |
||||
|
const size = data.readUInt32BE(offset); |
||||
|
offset += 4; |
||||
|
const codepoints = data.slice(offset, offset + size); |
||||
|
offset += size; |
||||
|
return (0, sparse_bitfield_1.default)({ buffer: codepoints }); |
||||
|
} |
||||
|
const unassigned_code_points = read(); |
||||
|
const commonly_mapped_to_nothing = read(); |
||||
|
const non_ASCII_space_characters = read(); |
||||
|
const prohibited_characters = read(); |
||||
|
const bidirectional_r_al = read(); |
||||
|
const bidirectional_l = read(); |
||||
|
return { |
||||
|
unassigned_code_points, |
||||
|
commonly_mapped_to_nothing, |
||||
|
non_ASCII_space_characters, |
||||
|
prohibited_characters, |
||||
|
bidirectional_r_al, |
||||
|
bidirectional_l, |
||||
|
}; |
||||
|
} |
||||
|
//# sourceMappingURL=memory-code-points.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"memory-code-points.js","sourceRoot":"","sources":["../src/memory-code-points.ts"],"names":[],"mappings":";;;;;AAEA,wDA+BC;AAjCD,sEAAuC;AAEvC,SAAgB,sBAAsB,CAAC,IAAY;IACjD,IAAI,MAAM,GAAG,CAAC,CAAC;IAKf,SAAS,IAAI;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,IAAI,CAAC,CAAC;QAEZ,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;QACrD,MAAM,IAAI,IAAI,CAAC;QAEf,OAAO,IAAA,yBAAQ,EAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,sBAAsB,GAAG,IAAI,EAAE,CAAC;IACtC,MAAM,0BAA0B,GAAG,IAAI,EAAE,CAAC;IAC1C,MAAM,0BAA0B,GAAG,IAAI,EAAE,CAAC;IAC1C,MAAM,qBAAqB,GAAG,IAAI,EAAE,CAAC;IACrC,MAAM,kBAAkB,GAAG,IAAI,EAAE,CAAC;IAClC,MAAM,eAAe,GAAG,IAAI,EAAE,CAAC;IAE/B,OAAO;QACL,sBAAsB;QACtB,0BAA0B;QAC1B,0BAA0B;QAC1B,qBAAqB;QACrB,kBAAkB;QAClB,eAAe;KAChB,CAAC;AACJ,CAAC"} |
||||
@ -0,0 +1,10 @@ |
|||||
|
declare function saslprep(input: string, opts?: { |
||||
|
allowUnassigned?: boolean; |
||||
|
}): string; |
||||
|
declare namespace saslprep { |
||||
|
export var saslprep: typeof import("./node"); |
||||
|
var _a: typeof import("./node"); |
||||
|
export { _a as default }; |
||||
|
} |
||||
|
export = saslprep; |
||||
|
//# sourceMappingURL=node.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAMA,iBAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAE7E;kBAFQ,QAAQ;;;;;AAOjB,SAAS,QAAQ,CAAC"} |
||||
@ -0,0 +1,15 @@ |
|||||
|
"use strict"; |
||||
|
var __importDefault = (this && this.__importDefault) || function (mod) { |
||||
|
return (mod && mod.__esModule) ? mod : { "default": mod }; |
||||
|
}; |
||||
|
const index_1 = __importDefault(require("./index")); |
||||
|
const memory_code_points_1 = require("./memory-code-points"); |
||||
|
const code_points_data_1 = __importDefault(require("./code-points-data")); |
||||
|
const codePoints = (0, memory_code_points_1.createMemoryCodePoints)(code_points_data_1.default); |
||||
|
function saslprep(input, opts) { |
||||
|
return (0, index_1.default)(codePoints, input, opts); |
||||
|
} |
||||
|
saslprep.saslprep = saslprep; |
||||
|
saslprep.default = saslprep; |
||||
|
module.exports = saslprep; |
||||
|
//# sourceMappingURL=node.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;AAAA,oDAAgC;AAChC,6DAA8D;AAC9D,0EAAsC;AAEtC,MAAM,UAAU,GAAG,IAAA,2CAAsB,EAAC,0BAAI,CAAC,CAAC;AAEhD,SAAS,QAAQ,CAAC,KAAa,EAAE,IAAoC;IACnE,OAAO,IAAA,eAAS,EAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;AAE5B,iBAAS,QAAQ,CAAC"} |
||||
@ -0,0 +1,2 @@ |
|||||
|
export declare function range(from: number, to: number): number[]; |
||||
|
//# sourceMappingURL=util.d.ts.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxD"} |
||||
@ -0,0 +1,11 @@ |
|||||
|
"use strict"; |
||||
|
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
|
exports.range = range; |
||||
|
function range(from, to) { |
||||
|
const list = new Array(to - from + 1); |
||||
|
for (let i = 0; i < list.length; i += 1) { |
||||
|
list[i] = from + i; |
||||
|
} |
||||
|
return list; |
||||
|
} |
||||
|
//# sourceMappingURL=util.js.map
|
||||
@ -0,0 +1 @@ |
|||||
|
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAGA,sBAQC;AARD,SAAgB,KAAK,CAAC,IAAY,EAAE,EAAU;IAE5C,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"} |
||||
@ -0,0 +1,87 @@ |
|||||
|
{ |
||||
|
"name": "@mongodb-js/saslprep", |
||||
|
"description": "SASLprep: Stringprep Profile for User Names and Passwords, rfc4013", |
||||
|
"keywords": [ |
||||
|
"sasl", |
||||
|
"saslprep", |
||||
|
"stringprep", |
||||
|
"rfc4013", |
||||
|
"4013" |
||||
|
], |
||||
|
"author": "Dmitry Tsvettsikh <me@reklatsmasters.com>", |
||||
|
"publishConfig": { |
||||
|
"access": "public" |
||||
|
}, |
||||
|
"main": "dist/node.js", |
||||
|
"bugs": { |
||||
|
"url": "https://jira.mongodb.org/projects/COMPASS/issues", |
||||
|
"email": "compass@mongodb.com" |
||||
|
}, |
||||
|
"homepage": "https://github.com/mongodb-js/devtools-shared/tree/main/packages/saslprep", |
||||
|
"version": "1.3.0", |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/mongodb-js/devtools-shared.git" |
||||
|
}, |
||||
|
"files": [ |
||||
|
"dist" |
||||
|
], |
||||
|
"license": "MIT", |
||||
|
"exports": { |
||||
|
"browser": { |
||||
|
"types": "./dist/browser.d.ts", |
||||
|
"default": "./dist/browser.js" |
||||
|
}, |
||||
|
"import": { |
||||
|
"types": "./dist/node.d.ts", |
||||
|
"default": "./dist/.esm-wrapper.mjs" |
||||
|
}, |
||||
|
"require": { |
||||
|
"types": "./dist/node.d.ts", |
||||
|
"default": "./dist/node.js" |
||||
|
} |
||||
|
}, |
||||
|
"types": "./dist/node.d.ts", |
||||
|
"scripts": { |
||||
|
"gen-code-points": "ts-node src/generate-code-points.ts src/code-points-data.ts src/code-points-data-browser.ts", |
||||
|
"bootstrap": "npm run compile", |
||||
|
"prepublishOnly": "npm run compile", |
||||
|
"compile": "npm run gen-code-points && tsc -p tsconfig.json && gen-esm-wrapper . ./dist/.esm-wrapper.mjs", |
||||
|
"typecheck": "tsc --noEmit", |
||||
|
"eslint": "eslint", |
||||
|
"prettier": "prettier", |
||||
|
"lint": "npm run eslint . && npm run prettier -- --check .", |
||||
|
"depcheck": "depcheck", |
||||
|
"check": "npm run typecheck && npm run lint && npm run depcheck", |
||||
|
"check-ci": "npm run check", |
||||
|
"test": "mocha", |
||||
|
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test", |
||||
|
"test-watch": "npm run test -- --watch", |
||||
|
"test-ci": "npm run test-cov", |
||||
|
"reformat": "npm run prettier -- --write ." |
||||
|
}, |
||||
|
"dependencies": { |
||||
|
"sparse-bitfield": "^3.0.3" |
||||
|
}, |
||||
|
"devDependencies": { |
||||
|
"@mongodb-js/eslint-config-devtools": "0.9.11", |
||||
|
"@mongodb-js/mocha-config-devtools": "^1.0.5", |
||||
|
"@mongodb-js/prettier-config-devtools": "^1.0.2", |
||||
|
"@mongodb-js/tsconfig-devtools": "^1.0.3", |
||||
|
"@types/chai": "^4.2.21", |
||||
|
"@types/mocha": "^9.1.1", |
||||
|
"@types/node": "^22.15.30", |
||||
|
"@types/sinon-chai": "^3.2.5", |
||||
|
"@types/sparse-bitfield": "^3.0.1", |
||||
|
"chai": "^4.5.0", |
||||
|
"depcheck": "^1.4.7", |
||||
|
"eslint": "^7.25.0", |
||||
|
"gen-esm-wrapper": "^1.1.3", |
||||
|
"mocha": "^8.4.0", |
||||
|
"nyc": "^15.1.0", |
||||
|
"prettier": "^3.5.3", |
||||
|
"sinon": "^9.2.3", |
||||
|
"typescript": "^5.0.4" |
||||
|
}, |
||||
|
"gitHead": "005f6263e3a329d916f6936c9adcf35db47cfe9f" |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
# saslprep |
||||
|
|
||||
|
_Note: This is a fork of the original [`saslprep`](https://www.npmjs.com/package/saslprep) npm package |
||||
|
and provides equivalent functionality._ |
||||
|
|
||||
|
Stringprep Profile for User Names and Passwords, [rfc4013](https://tools.ietf.org/html/rfc4013) |
||||
|
|
||||
|
### Usage |
||||
|
|
||||
|
```js |
||||
|
const saslprep = require('@mongodb-js/saslprep'); |
||||
|
|
||||
|
saslprep('password\u00AD'); // password |
||||
|
saslprep('password\u0007'); // Error: prohibited character |
||||
|
``` |
||||
|
|
||||
|
### API |
||||
|
|
||||
|
##### `saslprep(input: String, opts: Options): String` |
||||
|
|
||||
|
Normalize user name or password. |
||||
|
|
||||
|
##### `Options.allowUnassigned: bool` |
||||
|
|
||||
|
A special behavior for unassigned code points, see https://tools.ietf.org/html/rfc4013#section-2.5. Disabled by default. |
||||
|
|
||||
|
## License |
||||
|
|
||||
|
MIT, 2017-2019 (c) Dmitriy Tsvettsikh |
||||
@ -0,0 +1,24 @@ |
|||||
|
(The MIT License) |
||||
|
|
||||
|
Copyright (c) 2014 Component contributors <dev@component.io> |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person |
||||
|
obtaining a copy of this software and associated documentation |
||||
|
files (the "Software"), to deal in the Software without |
||||
|
restriction, including without limitation the rights to use, |
||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the |
||||
|
Software is furnished to do so, subject to the following |
||||
|
conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be |
||||
|
included in all copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||||
|
OTHER DEALINGS IN THE SOFTWARE. |
||||
@ -0,0 +1,79 @@ |
|||||
|
# `@socket.io/component-emitter` |
||||
|
|
||||
|
Event emitter component. |
||||
|
|
||||
|
This project is a fork of the [`component-emitter`](https://github.com/sindresorhus/component-emitter) project, with [Socket.IO](https://socket.io/)-specific TypeScript typings. |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
``` |
||||
|
$ npm i @socket.io/component-emitter |
||||
|
``` |
||||
|
|
||||
|
## API |
||||
|
|
||||
|
### Emitter(obj) |
||||
|
|
||||
|
The `Emitter` may also be used as a mixin. For example |
||||
|
a "plain" object may become an emitter, or you may |
||||
|
extend an existing prototype. |
||||
|
|
||||
|
As an `Emitter` instance: |
||||
|
|
||||
|
```js |
||||
|
import { Emitter } from '@socket.io/component-emitter'; |
||||
|
|
||||
|
var emitter = new Emitter; |
||||
|
emitter.emit('something'); |
||||
|
``` |
||||
|
|
||||
|
As a mixin: |
||||
|
|
||||
|
```js |
||||
|
import { Emitter } from '@socket.io/component-emitter'; |
||||
|
|
||||
|
var user = { name: 'tobi' }; |
||||
|
Emitter(user); |
||||
|
|
||||
|
user.emit('im a user'); |
||||
|
``` |
||||
|
|
||||
|
As a prototype mixin: |
||||
|
|
||||
|
```js |
||||
|
import { Emitter } from '@socket.io/component-emitter'; |
||||
|
|
||||
|
Emitter(User.prototype); |
||||
|
``` |
||||
|
|
||||
|
### Emitter#on(event, fn) |
||||
|
|
||||
|
Register an `event` handler `fn`. |
||||
|
|
||||
|
### Emitter#once(event, fn) |
||||
|
|
||||
|
Register a single-shot `event` handler `fn`, |
||||
|
removed immediately after it is invoked the |
||||
|
first time. |
||||
|
|
||||
|
### Emitter#off(event, fn) |
||||
|
|
||||
|
* Pass `event` and `fn` to remove a listener. |
||||
|
* Pass `event` to remove all listeners on that event. |
||||
|
* Pass nothing to remove all listeners on all events. |
||||
|
|
||||
|
### Emitter#emit(event, ...) |
||||
|
|
||||
|
Emit an `event` with variable option args. |
||||
|
|
||||
|
### Emitter#listeners(event) |
||||
|
|
||||
|
Return an array of callbacks, or an empty array. |
||||
|
|
||||
|
### Emitter#hasListeners(event) |
||||
|
|
||||
|
Check if this emitter has `event` handlers. |
||||
|
|
||||
|
## License |
||||
|
|
||||
|
MIT |
||||
@ -0,0 +1,179 @@ |
|||||
|
/** |
||||
|
* An events map is an interface that maps event names to their value, which |
||||
|
* represents the type of the `on` listener. |
||||
|
*/ |
||||
|
export interface EventsMap { |
||||
|
[event: string]: any; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The default events map, used if no EventsMap is given. Using this EventsMap |
||||
|
* is equivalent to accepting all event names, and any data. |
||||
|
*/ |
||||
|
export interface DefaultEventsMap { |
||||
|
[event: string]: (...args: any[]) => void; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns a union type containing all the keys of an event map. |
||||
|
*/ |
||||
|
export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol); |
||||
|
|
||||
|
/** The tuple type representing the parameters of an event listener */ |
||||
|
export type EventParams< |
||||
|
Map extends EventsMap, |
||||
|
Ev extends EventNames<Map> |
||||
|
> = Parameters<Map[Ev]>; |
||||
|
|
||||
|
/** |
||||
|
* The event names that are either in ReservedEvents or in UserEvents |
||||
|
*/ |
||||
|
export type ReservedOrUserEventNames< |
||||
|
ReservedEventsMap extends EventsMap, |
||||
|
UserEvents extends EventsMap |
||||
|
> = EventNames<ReservedEventsMap> | EventNames<UserEvents>; |
||||
|
|
||||
|
/** |
||||
|
* Type of a listener of a user event or a reserved event. If `Ev` is in |
||||
|
* `ReservedEvents`, the reserved event listener is returned. |
||||
|
*/ |
||||
|
export type ReservedOrUserListener< |
||||
|
ReservedEvents extends EventsMap, |
||||
|
UserEvents extends EventsMap, |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, UserEvents> |
||||
|
> = FallbackToUntypedListener< |
||||
|
Ev extends EventNames<ReservedEvents> |
||||
|
? ReservedEvents[Ev] |
||||
|
: Ev extends EventNames<UserEvents> |
||||
|
? UserEvents[Ev] |
||||
|
: never |
||||
|
>; |
||||
|
|
||||
|
/** |
||||
|
* Returns an untyped listener type if `T` is `never`; otherwise, returns `T`. |
||||
|
* |
||||
|
* This is a hack to mitigate https://github.com/socketio/socket.io/issues/3833.
|
||||
|
* Needed because of https://github.com/microsoft/TypeScript/issues/41778
|
||||
|
*/ |
||||
|
type FallbackToUntypedListener<T> = [T] extends [never] |
||||
|
? (...args: any[]) => void | Promise<void> |
||||
|
: T; |
||||
|
|
||||
|
/** |
||||
|
* Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type |
||||
|
* parameters for mappings of event names to event data types, and strictly |
||||
|
* types method calls to the `EventEmitter` according to these event maps. |
||||
|
* |
||||
|
* @typeParam ListenEvents - `EventsMap` of user-defined events that can be |
||||
|
* listened to with `on` or `once` |
||||
|
* @typeParam EmitEvents - `EventsMap` of user-defined events that can be |
||||
|
* emitted with `emit` |
||||
|
* @typeParam ReservedEvents - `EventsMap` of reserved events, that can be |
||||
|
* emitted by socket.io with `emitReserved`, and can be listened to with |
||||
|
* `listen`. |
||||
|
*/ |
||||
|
export class Emitter< |
||||
|
ListenEvents extends EventsMap, |
||||
|
EmitEvents extends EventsMap, |
||||
|
ReservedEvents extends EventsMap = {} |
||||
|
> { |
||||
|
/** |
||||
|
* Adds the `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
ev: Ev, |
||||
|
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Adds a one-time `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
once<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
ev: Ev, |
||||
|
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Removes the `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
ev?: Ev, |
||||
|
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Emits an event. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param args Values to send to listeners of this event |
||||
|
*/ |
||||
|
emit<Ev extends EventNames<EmitEvents>>( |
||||
|
ev: Ev, |
||||
|
...args: EventParams<EmitEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Emits a reserved event. |
||||
|
* |
||||
|
* This method is `protected`, so that only a class extending |
||||
|
* `StrictEventEmitter` can emit its own reserved events. |
||||
|
* |
||||
|
* @param ev Reserved event name |
||||
|
* @param args Arguments to emit along with the event |
||||
|
*/ |
||||
|
protected emitReserved<Ev extends EventNames<ReservedEvents>>( |
||||
|
ev: Ev, |
||||
|
...args: EventParams<ReservedEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Returns the listeners listening to an event. |
||||
|
* |
||||
|
* @param event Event name |
||||
|
* @returns Array of listeners subscribed to `event` |
||||
|
*/ |
||||
|
listeners<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
event: Ev |
||||
|
): ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>[]; |
||||
|
|
||||
|
/** |
||||
|
* Returns true if there is a listener for this event. |
||||
|
* |
||||
|
* @param event Event name |
||||
|
* @returns boolean |
||||
|
*/ |
||||
|
hasListeners< |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents> |
||||
|
>(event: Ev): boolean; |
||||
|
|
||||
|
/** |
||||
|
* Removes the `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
removeListener< |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents> |
||||
|
>( |
||||
|
ev?: Ev, |
||||
|
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Removes all `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
*/ |
||||
|
removeAllListeners< |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents> |
||||
|
>(ev?: Ev): this; |
||||
|
} |
||||
@ -0,0 +1,176 @@ |
|||||
|
|
||||
|
/** |
||||
|
* Expose `Emitter`. |
||||
|
*/ |
||||
|
|
||||
|
exports.Emitter = Emitter; |
||||
|
|
||||
|
/** |
||||
|
* Initialize a new `Emitter`. |
||||
|
* |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
function Emitter(obj) { |
||||
|
if (obj) return mixin(obj); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Mixin the emitter properties. |
||||
|
* |
||||
|
* @param {Object} obj |
||||
|
* @return {Object} |
||||
|
* @api private |
||||
|
*/ |
||||
|
|
||||
|
function mixin(obj) { |
||||
|
for (var key in Emitter.prototype) { |
||||
|
obj[key] = Emitter.prototype[key]; |
||||
|
} |
||||
|
return obj; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Listen on the given `event` with `fn`. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Function} fn |
||||
|
* @return {Emitter} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.on = |
||||
|
Emitter.prototype.addEventListener = function(event, fn){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
(this._callbacks['$' + event] = this._callbacks['$' + event] || []) |
||||
|
.push(fn); |
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Adds an `event` listener that will be invoked a single |
||||
|
* time then automatically removed. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Function} fn |
||||
|
* @return {Emitter} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.once = function(event, fn){ |
||||
|
function on() { |
||||
|
this.off(event, on); |
||||
|
fn.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
on.fn = fn; |
||||
|
this.on(event, on); |
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Remove the given callback for `event` or all |
||||
|
* registered callbacks. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Function} fn |
||||
|
* @return {Emitter} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.off = |
||||
|
Emitter.prototype.removeListener = |
||||
|
Emitter.prototype.removeAllListeners = |
||||
|
Emitter.prototype.removeEventListener = function(event, fn){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
|
||||
|
// all
|
||||
|
if (0 == arguments.length) { |
||||
|
this._callbacks = {}; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
// specific event
|
||||
|
var callbacks = this._callbacks['$' + event]; |
||||
|
if (!callbacks) return this; |
||||
|
|
||||
|
// remove all handlers
|
||||
|
if (1 == arguments.length) { |
||||
|
delete this._callbacks['$' + event]; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
// remove specific handler
|
||||
|
var cb; |
||||
|
for (var i = 0; i < callbacks.length; i++) { |
||||
|
cb = callbacks[i]; |
||||
|
if (cb === fn || cb.fn === fn) { |
||||
|
callbacks.splice(i, 1); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Remove event specific arrays for event types that no
|
||||
|
// one is subscribed for to avoid memory leak.
|
||||
|
if (callbacks.length === 0) { |
||||
|
delete this._callbacks['$' + event]; |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Emit `event` with the given args. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Mixed} ... |
||||
|
* @return {Emitter} |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.emit = function(event){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
|
||||
|
var args = new Array(arguments.length - 1) |
||||
|
, callbacks = this._callbacks['$' + event]; |
||||
|
|
||||
|
for (var i = 1; i < arguments.length; i++) { |
||||
|
args[i - 1] = arguments[i]; |
||||
|
} |
||||
|
|
||||
|
if (callbacks) { |
||||
|
callbacks = callbacks.slice(0); |
||||
|
for (var i = 0, len = callbacks.length; i < len; ++i) { |
||||
|
callbacks[i].apply(this, args); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
// alias used for reserved events (protected method)
|
||||
|
Emitter.prototype.emitReserved = Emitter.prototype.emit; |
||||
|
|
||||
|
/** |
||||
|
* Return array of callbacks for `event`. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @return {Array} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.listeners = function(event){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
return this._callbacks['$' + event] || []; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Check if this emitter has `event` handlers. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @return {Boolean} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.hasListeners = function(event){ |
||||
|
return !! this.listeners(event).length; |
||||
|
}; |
||||
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
"name": "@socket.io/component-emitter", |
||||
|
"type": "commonjs" |
||||
|
} |
||||
@ -0,0 +1,179 @@ |
|||||
|
/** |
||||
|
* An events map is an interface that maps event names to their value, which |
||||
|
* represents the type of the `on` listener. |
||||
|
*/ |
||||
|
export interface EventsMap { |
||||
|
[event: string]: any; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The default events map, used if no EventsMap is given. Using this EventsMap |
||||
|
* is equivalent to accepting all event names, and any data. |
||||
|
*/ |
||||
|
export interface DefaultEventsMap { |
||||
|
[event: string]: (...args: any[]) => void; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns a union type containing all the keys of an event map. |
||||
|
*/ |
||||
|
export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol); |
||||
|
|
||||
|
/** The tuple type representing the parameters of an event listener */ |
||||
|
export type EventParams< |
||||
|
Map extends EventsMap, |
||||
|
Ev extends EventNames<Map> |
||||
|
> = Parameters<Map[Ev]>; |
||||
|
|
||||
|
/** |
||||
|
* The event names that are either in ReservedEvents or in UserEvents |
||||
|
*/ |
||||
|
export type ReservedOrUserEventNames< |
||||
|
ReservedEventsMap extends EventsMap, |
||||
|
UserEvents extends EventsMap |
||||
|
> = EventNames<ReservedEventsMap> | EventNames<UserEvents>; |
||||
|
|
||||
|
/** |
||||
|
* Type of a listener of a user event or a reserved event. If `Ev` is in |
||||
|
* `ReservedEvents`, the reserved event listener is returned. |
||||
|
*/ |
||||
|
export type ReservedOrUserListener< |
||||
|
ReservedEvents extends EventsMap, |
||||
|
UserEvents extends EventsMap, |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, UserEvents> |
||||
|
> = FallbackToUntypedListener< |
||||
|
Ev extends EventNames<ReservedEvents> |
||||
|
? ReservedEvents[Ev] |
||||
|
: Ev extends EventNames<UserEvents> |
||||
|
? UserEvents[Ev] |
||||
|
: never |
||||
|
>; |
||||
|
|
||||
|
/** |
||||
|
* Returns an untyped listener type if `T` is `never`; otherwise, returns `T`. |
||||
|
* |
||||
|
* This is a hack to mitigate https://github.com/socketio/socket.io/issues/3833.
|
||||
|
* Needed because of https://github.com/microsoft/TypeScript/issues/41778
|
||||
|
*/ |
||||
|
type FallbackToUntypedListener<T> = [T] extends [never] |
||||
|
? (...args: any[]) => void | Promise<void> |
||||
|
: T; |
||||
|
|
||||
|
/** |
||||
|
* Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type |
||||
|
* parameters for mappings of event names to event data types, and strictly |
||||
|
* types method calls to the `EventEmitter` according to these event maps. |
||||
|
* |
||||
|
* @typeParam ListenEvents - `EventsMap` of user-defined events that can be |
||||
|
* listened to with `on` or `once` |
||||
|
* @typeParam EmitEvents - `EventsMap` of user-defined events that can be |
||||
|
* emitted with `emit` |
||||
|
* @typeParam ReservedEvents - `EventsMap` of reserved events, that can be |
||||
|
* emitted by socket.io with `emitReserved`, and can be listened to with |
||||
|
* `listen`. |
||||
|
*/ |
||||
|
export class Emitter< |
||||
|
ListenEvents extends EventsMap, |
||||
|
EmitEvents extends EventsMap, |
||||
|
ReservedEvents extends EventsMap = {} |
||||
|
> { |
||||
|
/** |
||||
|
* Adds the `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
ev: Ev, |
||||
|
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Adds a one-time `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
once<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
ev: Ev, |
||||
|
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Removes the `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
ev?: Ev, |
||||
|
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Emits an event. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param args Values to send to listeners of this event |
||||
|
*/ |
||||
|
emit<Ev extends EventNames<EmitEvents>>( |
||||
|
ev: Ev, |
||||
|
...args: EventParams<EmitEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Emits a reserved event. |
||||
|
* |
||||
|
* This method is `protected`, so that only a class extending |
||||
|
* `StrictEventEmitter` can emit its own reserved events. |
||||
|
* |
||||
|
* @param ev Reserved event name |
||||
|
* @param args Arguments to emit along with the event |
||||
|
*/ |
||||
|
protected emitReserved<Ev extends EventNames<ReservedEvents>>( |
||||
|
ev: Ev, |
||||
|
...args: EventParams<ReservedEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Returns the listeners listening to an event. |
||||
|
* |
||||
|
* @param event Event name |
||||
|
* @returns Array of listeners subscribed to `event` |
||||
|
*/ |
||||
|
listeners<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( |
||||
|
event: Ev |
||||
|
): ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>[]; |
||||
|
|
||||
|
/** |
||||
|
* Returns true if there is a listener for this event. |
||||
|
* |
||||
|
* @param event Event name |
||||
|
* @returns boolean |
||||
|
*/ |
||||
|
hasListeners< |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents> |
||||
|
>(event: Ev): boolean; |
||||
|
|
||||
|
/** |
||||
|
* Removes the `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
* @param listener Callback function |
||||
|
*/ |
||||
|
removeListener< |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents> |
||||
|
>( |
||||
|
ev?: Ev, |
||||
|
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev> |
||||
|
): this; |
||||
|
|
||||
|
/** |
||||
|
* Removes all `listener` function as an event listener for `ev`. |
||||
|
* |
||||
|
* @param ev Name of the event |
||||
|
*/ |
||||
|
removeAllListeners< |
||||
|
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents> |
||||
|
>(ev?: Ev): this; |
||||
|
} |
||||
@ -0,0 +1,169 @@ |
|||||
|
/** |
||||
|
* Initialize a new `Emitter`. |
||||
|
* |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
export function Emitter(obj) { |
||||
|
if (obj) return mixin(obj); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Mixin the emitter properties. |
||||
|
* |
||||
|
* @param {Object} obj |
||||
|
* @return {Object} |
||||
|
* @api private |
||||
|
*/ |
||||
|
|
||||
|
function mixin(obj) { |
||||
|
for (var key in Emitter.prototype) { |
||||
|
obj[key] = Emitter.prototype[key]; |
||||
|
} |
||||
|
return obj; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Listen on the given `event` with `fn`. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Function} fn |
||||
|
* @return {Emitter} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.on = |
||||
|
Emitter.prototype.addEventListener = function(event, fn){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
(this._callbacks['$' + event] = this._callbacks['$' + event] || []) |
||||
|
.push(fn); |
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Adds an `event` listener that will be invoked a single |
||||
|
* time then automatically removed. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Function} fn |
||||
|
* @return {Emitter} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.once = function(event, fn){ |
||||
|
function on() { |
||||
|
this.off(event, on); |
||||
|
fn.apply(this, arguments); |
||||
|
} |
||||
|
|
||||
|
on.fn = fn; |
||||
|
this.on(event, on); |
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Remove the given callback for `event` or all |
||||
|
* registered callbacks. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Function} fn |
||||
|
* @return {Emitter} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.off = |
||||
|
Emitter.prototype.removeListener = |
||||
|
Emitter.prototype.removeAllListeners = |
||||
|
Emitter.prototype.removeEventListener = function(event, fn){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
|
||||
|
// all
|
||||
|
if (0 == arguments.length) { |
||||
|
this._callbacks = {}; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
// specific event
|
||||
|
var callbacks = this._callbacks['$' + event]; |
||||
|
if (!callbacks) return this; |
||||
|
|
||||
|
// remove all handlers
|
||||
|
if (1 == arguments.length) { |
||||
|
delete this._callbacks['$' + event]; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
// remove specific handler
|
||||
|
var cb; |
||||
|
for (var i = 0; i < callbacks.length; i++) { |
||||
|
cb = callbacks[i]; |
||||
|
if (cb === fn || cb.fn === fn) { |
||||
|
callbacks.splice(i, 1); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Remove event specific arrays for event types that no
|
||||
|
// one is subscribed for to avoid memory leak.
|
||||
|
if (callbacks.length === 0) { |
||||
|
delete this._callbacks['$' + event]; |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Emit `event` with the given args. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @param {Mixed} ... |
||||
|
* @return {Emitter} |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.emit = function(event){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
|
||||
|
var args = new Array(arguments.length - 1) |
||||
|
, callbacks = this._callbacks['$' + event]; |
||||
|
|
||||
|
for (var i = 1; i < arguments.length; i++) { |
||||
|
args[i - 1] = arguments[i]; |
||||
|
} |
||||
|
|
||||
|
if (callbacks) { |
||||
|
callbacks = callbacks.slice(0); |
||||
|
for (var i = 0, len = callbacks.length; i < len; ++i) { |
||||
|
callbacks[i].apply(this, args); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return this; |
||||
|
}; |
||||
|
|
||||
|
// alias used for reserved events (protected method)
|
||||
|
Emitter.prototype.emitReserved = Emitter.prototype.emit; |
||||
|
|
||||
|
/** |
||||
|
* Return array of callbacks for `event`. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @return {Array} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.listeners = function(event){ |
||||
|
this._callbacks = this._callbacks || {}; |
||||
|
return this._callbacks['$' + event] || []; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Check if this emitter has `event` handlers. |
||||
|
* |
||||
|
* @param {String} event |
||||
|
* @return {Boolean} |
||||
|
* @api public |
||||
|
*/ |
||||
|
|
||||
|
Emitter.prototype.hasListeners = function(event){ |
||||
|
return !! this.listeners(event).length; |
||||
|
}; |
||||
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
"name": "@socket.io/component-emitter", |
||||
|
"type": "module" |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"name": "@socket.io/component-emitter", |
||||
|
"description": "Event emitter", |
||||
|
"version": "3.1.2", |
||||
|
"license": "MIT", |
||||
|
"devDependencies": { |
||||
|
"mocha": "*", |
||||
|
"should": "*" |
||||
|
}, |
||||
|
"component": { |
||||
|
"scripts": { |
||||
|
"emitter/index.js": "index.js" |
||||
|
} |
||||
|
}, |
||||
|
"main": "./lib/cjs/index.js", |
||||
|
"module": "./lib/esm/index.js", |
||||
|
"types": "./lib/cjs/index.d.ts", |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/socketio/emitter.git" |
||||
|
}, |
||||
|
"scripts": { |
||||
|
"test": "make test" |
||||
|
}, |
||||
|
"files": [ |
||||
|
"lib/" |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
MIT License |
||||
|
|
||||
|
Copyright (c) Microsoft Corporation. |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE |
||||
@ -0,0 +1,75 @@ |
|||||
|
# Installation |
||||
|
> `npm install --save @types/cors` |
||||
|
|
||||
|
# Summary |
||||
|
This package contains type definitions for cors (https://github.com/expressjs/cors/). |
||||
|
|
||||
|
# Details |
||||
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors. |
||||
|
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors/index.d.ts) |
||||
|
````ts |
||||
|
/// <reference types="node" /> |
||||
|
|
||||
|
import { IncomingHttpHeaders } from "http"; |
||||
|
|
||||
|
type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>; |
||||
|
|
||||
|
type CustomOrigin = ( |
||||
|
requestOrigin: string | undefined, |
||||
|
callback: (err: Error | null, origin?: StaticOrigin) => void, |
||||
|
) => void; |
||||
|
|
||||
|
declare namespace e { |
||||
|
interface CorsRequest { |
||||
|
method?: string | undefined; |
||||
|
headers: IncomingHttpHeaders; |
||||
|
} |
||||
|
interface CorsOptions { |
||||
|
/** |
||||
|
* @default '*' |
||||
|
*/ |
||||
|
origin?: StaticOrigin | CustomOrigin | undefined; |
||||
|
/** |
||||
|
* @default 'GET,HEAD,PUT,PATCH,POST,DELETE' |
||||
|
*/ |
||||
|
methods?: string | string[] | undefined; |
||||
|
allowedHeaders?: string | string[] | undefined; |
||||
|
exposedHeaders?: string | string[] | undefined; |
||||
|
credentials?: boolean | undefined; |
||||
|
maxAge?: number | undefined; |
||||
|
/** |
||||
|
* @default false |
||||
|
*/ |
||||
|
preflightContinue?: boolean | undefined; |
||||
|
/** |
||||
|
* @default 204 |
||||
|
*/ |
||||
|
optionsSuccessStatus?: number | undefined; |
||||
|
} |
||||
|
type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = ( |
||||
|
req: T, |
||||
|
callback: (err: Error | null, options?: CorsOptions) => void, |
||||
|
) => void; |
||||
|
} |
||||
|
|
||||
|
declare function e<T extends e.CorsRequest = e.CorsRequest>( |
||||
|
options?: e.CorsOptions | e.CorsOptionsDelegate<T>, |
||||
|
): ( |
||||
|
req: T, |
||||
|
res: { |
||||
|
statusCode?: number | undefined; |
||||
|
setHeader(key: string, value: string): any; |
||||
|
end(): any; |
||||
|
}, |
||||
|
next: (err?: any) => any, |
||||
|
) => void; |
||||
|
export = e; |
||||
|
|
||||
|
```` |
||||
|
|
||||
|
### Additional Details |
||||
|
* Last updated: Sat, 07 Jun 2025 02:15:25 GMT |
||||
|
* Dependencies: [@types/node](https://npmjs.com/package/@types/node) |
||||
|
|
||||
|
# Credits |
||||
|
These definitions were written by [Alan Plum](https://github.com/pluma), [Gaurav Sharma](https://github.com/gtpan77), and [Sebastian Beltran](https://github.com/bjohansebas). |
||||
@ -0,0 +1,56 @@ |
|||||
|
/// <reference types="node" />
|
||||
|
|
||||
|
import { IncomingHttpHeaders } from "http"; |
||||
|
|
||||
|
type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>; |
||||
|
|
||||
|
type CustomOrigin = ( |
||||
|
requestOrigin: string | undefined, |
||||
|
callback: (err: Error | null, origin?: StaticOrigin) => void, |
||||
|
) => void; |
||||
|
|
||||
|
declare namespace e { |
||||
|
interface CorsRequest { |
||||
|
method?: string | undefined; |
||||
|
headers: IncomingHttpHeaders; |
||||
|
} |
||||
|
interface CorsOptions { |
||||
|
/** |
||||
|
* @default '*' |
||||
|
*/ |
||||
|
origin?: StaticOrigin | CustomOrigin | undefined; |
||||
|
/** |
||||
|
* @default 'GET,HEAD,PUT,PATCH,POST,DELETE' |
||||
|
*/ |
||||
|
methods?: string | string[] | undefined; |
||||
|
allowedHeaders?: string | string[] | undefined; |
||||
|
exposedHeaders?: string | string[] | undefined; |
||||
|
credentials?: boolean | undefined; |
||||
|
maxAge?: number | undefined; |
||||
|
/** |
||||
|
* @default false |
||||
|
*/ |
||||
|
preflightContinue?: boolean | undefined; |
||||
|
/** |
||||
|
* @default 204 |
||||
|
*/ |
||||
|
optionsSuccessStatus?: number | undefined; |
||||
|
} |
||||
|
type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = ( |
||||
|
req: T, |
||||
|
callback: (err: Error | null, options?: CorsOptions) => void, |
||||
|
) => void; |
||||
|
} |
||||
|
|
||||
|
declare function e<T extends e.CorsRequest = e.CorsRequest>( |
||||
|
options?: e.CorsOptions | e.CorsOptionsDelegate<T>, |
||||
|
): ( |
||||
|
req: T, |
||||
|
res: { |
||||
|
statusCode?: number | undefined; |
||||
|
setHeader(key: string, value: string): any; |
||||
|
end(): any; |
||||
|
}, |
||||
|
next: (err?: any) => any, |
||||
|
) => void; |
||||
|
export = e; |
||||
@ -0,0 +1,38 @@ |
|||||
|
{ |
||||
|
"name": "@types/cors", |
||||
|
"version": "2.8.19", |
||||
|
"description": "TypeScript definitions for cors", |
||||
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors", |
||||
|
"license": "MIT", |
||||
|
"contributors": [ |
||||
|
{ |
||||
|
"name": "Alan Plum", |
||||
|
"githubUsername": "pluma", |
||||
|
"url": "https://github.com/pluma" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Gaurav Sharma", |
||||
|
"githubUsername": "gtpan77", |
||||
|
"url": "https://github.com/gtpan77" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Sebastian Beltran", |
||||
|
"githubUsername": "bjohansebas", |
||||
|
"url": "https://github.com/bjohansebas" |
||||
|
} |
||||
|
], |
||||
|
"main": "", |
||||
|
"types": "index.d.ts", |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git", |
||||
|
"directory": "types/cors" |
||||
|
}, |
||||
|
"scripts": {}, |
||||
|
"dependencies": { |
||||
|
"@types/node": "*" |
||||
|
}, |
||||
|
"peerDependencies": {}, |
||||
|
"typesPublisherContentHash": "a090e558c5f443573318c2955deecddc840bd8dfaac7cdedf31c7f6ede8d0b47", |
||||
|
"typeScriptVersion": "5.1" |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
MIT License |
||||
|
|
||||
|
Copyright (c) Microsoft Corporation. |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE |
||||
@ -0,0 +1,15 @@ |
|||||
|
# Installation |
||||
|
> `npm install --save @types/node` |
||||
|
|
||||
|
# Summary |
||||
|
This package contains type definitions for node (https://nodejs.org/). |
||||
|
|
||||
|
# Details |
||||
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node. |
||||
|
|
||||
|
### Additional Details |
||||
|
* Last updated: Fri, 15 Aug 2025 08:39:32 GMT |
||||
|
* Dependencies: [undici-types](https://npmjs.com/package/undici-types) |
||||
|
|
||||
|
# Credits |
||||
|
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [Alberto Schiabel](https://github.com/jkomyno), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [David Junger](https://github.com/touffy), [Mohsen Azimi](https://github.com/mohsen1), [Nikita Galkin](https://github.com/galkin), [Sebastian Silbermann](https://github.com/eps1lon), [Wilco Bakker](https://github.com/WilcoBakker), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), [Dmitry Semigradsky](https://github.com/Semigradsky), [René](https://github.com/Renegade334), and [Yagiz Nizipli](https://github.com/anonrig). |
||||
File diff suppressed because it is too large
@ -0,0 +1,8 @@ |
|||||
|
declare module "assert/strict" { |
||||
|
import { strict } from "node:assert"; |
||||
|
export = strict; |
||||
|
} |
||||
|
declare module "node:assert/strict" { |
||||
|
import { strict } from "node:assert"; |
||||
|
export = strict; |
||||
|
} |
||||
@ -0,0 +1,623 @@ |
|||||
|
/** |
||||
|
* We strongly discourage the use of the `async_hooks` API. |
||||
|
* Other APIs that can cover most of its use cases include: |
||||
|
* |
||||
|
* * [`AsyncLocalStorage`](https://nodejs.org/docs/latest-v24.x/api/async_context.html#class-asynclocalstorage) tracks async context
|
||||
|
* * [`process.getActiveResourcesInfo()`](https://nodejs.org/docs/latest-v24.x/api/process.html#processgetactiveresourcesinfo) tracks active resources
|
||||
|
* |
||||
|
* The `node:async_hooks` module provides an API to track asynchronous resources. |
||||
|
* It can be accessed using: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import async_hooks from 'node:async_hooks'; |
||||
|
* ``` |
||||
|
* @experimental |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/async_hooks.js)
|
||||
|
*/ |
||||
|
declare module "async_hooks" { |
||||
|
/** |
||||
|
* ```js
|
||||
|
* import { executionAsyncId } from 'node:async_hooks'; |
||||
|
* import fs from 'node:fs'; |
||||
|
* |
||||
|
* console.log(executionAsyncId()); // 1 - bootstrap
|
||||
|
* const path = '.'; |
||||
|
* fs.open(path, 'r', (err, fd) => { |
||||
|
* console.log(executionAsyncId()); // 6 - open()
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* The ID returned from `executionAsyncId()` is related to execution timing, not |
||||
|
* causality (which is covered by `triggerAsyncId()`): |
||||
|
* |
||||
|
* ```js
|
||||
|
* const server = net.createServer((conn) => { |
||||
|
* // Returns the ID of the server, not of the new connection, because the
|
||||
|
* // callback runs in the execution scope of the server's MakeCallback().
|
||||
|
* async_hooks.executionAsyncId(); |
||||
|
* |
||||
|
* }).listen(port, () => { |
||||
|
* // Returns the ID of a TickObject (process.nextTick()) because all
|
||||
|
* // callbacks passed to .listen() are wrapped in a nextTick().
|
||||
|
* async_hooks.executionAsyncId(); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Promise contexts may not get precise `executionAsyncIds` by default. |
||||
|
* See the section on [promise execution tracking](https://nodejs.org/docs/latest-v24.x/api/async_hooks.html#promise-execution-tracking).
|
||||
|
* @since v8.1.0 |
||||
|
* @return The `asyncId` of the current execution context. Useful to track when something calls. |
||||
|
*/ |
||||
|
function executionAsyncId(): number; |
||||
|
/** |
||||
|
* Resource objects returned by `executionAsyncResource()` are most often internal |
||||
|
* Node.js handle objects with undocumented APIs. Using any functions or properties |
||||
|
* on the object is likely to crash your application and should be avoided. |
||||
|
* |
||||
|
* Using `executionAsyncResource()` in the top-level execution context will |
||||
|
* return an empty object as there is no handle or request object to use, |
||||
|
* but having an object representing the top-level can be helpful. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { open } from 'node:fs'; |
||||
|
* import { executionAsyncId, executionAsyncResource } from 'node:async_hooks'; |
||||
|
* |
||||
|
* console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
|
||||
|
* open(new URL(import.meta.url), 'r', (err, fd) => { |
||||
|
* console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* This can be used to implement continuation local storage without the |
||||
|
* use of a tracking `Map` to store the metadata: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { createServer } from 'node:http'; |
||||
|
* import { |
||||
|
* executionAsyncId, |
||||
|
* executionAsyncResource, |
||||
|
* createHook, |
||||
|
* } from 'node:async_hooks'; |
||||
|
* const sym = Symbol('state'); // Private symbol to avoid pollution
|
||||
|
* |
||||
|
* createHook({ |
||||
|
* init(asyncId, type, triggerAsyncId, resource) { |
||||
|
* const cr = executionAsyncResource(); |
||||
|
* if (cr) { |
||||
|
* resource[sym] = cr[sym]; |
||||
|
* } |
||||
|
* }, |
||||
|
* }).enable(); |
||||
|
* |
||||
|
* const server = createServer((req, res) => { |
||||
|
* executionAsyncResource()[sym] = { state: req.url }; |
||||
|
* setTimeout(function() { |
||||
|
* res.end(JSON.stringify(executionAsyncResource()[sym])); |
||||
|
* }, 100); |
||||
|
* }).listen(3000); |
||||
|
* ``` |
||||
|
* @since v13.9.0, v12.17.0 |
||||
|
* @return The resource representing the current execution. Useful to store data within the resource. |
||||
|
*/ |
||||
|
function executionAsyncResource(): object; |
||||
|
/** |
||||
|
* ```js
|
||||
|
* const server = net.createServer((conn) => { |
||||
|
* // The resource that caused (or triggered) this callback to be called
|
||||
|
* // was that of the new connection. Thus the return value of triggerAsyncId()
|
||||
|
* // is the asyncId of "conn".
|
||||
|
* async_hooks.triggerAsyncId(); |
||||
|
* |
||||
|
* }).listen(port, () => { |
||||
|
* // Even though all callbacks passed to .listen() are wrapped in a nextTick()
|
||||
|
* // the callback itself exists because the call to the server's .listen()
|
||||
|
* // was made. So the return value would be the ID of the server.
|
||||
|
* async_hooks.triggerAsyncId(); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Promise contexts may not get valid `triggerAsyncId`s by default. See |
||||
|
* the section on [promise execution tracking](https://nodejs.org/docs/latest-v24.x/api/async_hooks.html#promise-execution-tracking).
|
||||
|
* @return The ID of the resource responsible for calling the callback that is currently being executed. |
||||
|
*/ |
||||
|
function triggerAsyncId(): number; |
||||
|
interface HookCallbacks { |
||||
|
/** |
||||
|
* Called when a class is constructed that has the possibility to emit an asynchronous event. |
||||
|
* @param asyncId A unique ID for the async resource |
||||
|
* @param type The type of the async resource |
||||
|
* @param triggerAsyncId The unique ID of the async resource in whose execution context this async resource was created |
||||
|
* @param resource Reference to the resource representing the async operation, needs to be released during destroy |
||||
|
*/ |
||||
|
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void; |
||||
|
/** |
||||
|
* When an asynchronous operation is initiated or completes a callback is called to notify the user. |
||||
|
* The before callback is called just before said callback is executed. |
||||
|
* @param asyncId the unique identifier assigned to the resource about to execute the callback. |
||||
|
*/ |
||||
|
before?(asyncId: number): void; |
||||
|
/** |
||||
|
* Called immediately after the callback specified in `before` is completed. |
||||
|
* |
||||
|
* If an uncaught exception occurs during execution of the callback, then `after` will run after the `'uncaughtException'` event is emitted or a `domain`'s handler runs. |
||||
|
* @param asyncId the unique identifier assigned to the resource which has executed the callback. |
||||
|
*/ |
||||
|
after?(asyncId: number): void; |
||||
|
/** |
||||
|
* Called when a promise has resolve() called. This may not be in the same execution id |
||||
|
* as the promise itself. |
||||
|
* @param asyncId the unique id for the promise that was resolve()d. |
||||
|
*/ |
||||
|
promiseResolve?(asyncId: number): void; |
||||
|
/** |
||||
|
* Called after the resource corresponding to asyncId is destroyed |
||||
|
* @param asyncId a unique ID for the async resource |
||||
|
*/ |
||||
|
destroy?(asyncId: number): void; |
||||
|
} |
||||
|
interface AsyncHook { |
||||
|
/** |
||||
|
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop. |
||||
|
*/ |
||||
|
enable(): this; |
||||
|
/** |
||||
|
* Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled. |
||||
|
*/ |
||||
|
disable(): this; |
||||
|
} |
||||
|
/** |
||||
|
* Registers functions to be called for different lifetime events of each async |
||||
|
* operation. |
||||
|
* |
||||
|
* The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the |
||||
|
* respective asynchronous event during a resource's lifetime. |
||||
|
* |
||||
|
* All callbacks are optional. For example, if only resource cleanup needs to |
||||
|
* be tracked, then only the `destroy` callback needs to be passed. The |
||||
|
* specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { createHook } from 'node:async_hooks'; |
||||
|
* |
||||
|
* const asyncHook = createHook({ |
||||
|
* init(asyncId, type, triggerAsyncId, resource) { }, |
||||
|
* destroy(asyncId) { }, |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* The callbacks will be inherited via the prototype chain: |
||||
|
* |
||||
|
* ```js
|
||||
|
* class MyAsyncCallbacks { |
||||
|
* init(asyncId, type, triggerAsyncId, resource) { } |
||||
|
* destroy(asyncId) {} |
||||
|
* } |
||||
|
* |
||||
|
* class MyAddedCallbacks extends MyAsyncCallbacks { |
||||
|
* before(asyncId) { } |
||||
|
* after(asyncId) { } |
||||
|
* } |
||||
|
* |
||||
|
* const asyncHook = async_hooks.createHook(new MyAddedCallbacks()); |
||||
|
* ``` |
||||
|
* |
||||
|
* Because promises are asynchronous resources whose lifecycle is tracked |
||||
|
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises. |
||||
|
* @since v8.1.0 |
||||
|
* @param callbacks The `Hook Callbacks` to register |
||||
|
* @return Instance used for disabling and enabling hooks |
||||
|
*/ |
||||
|
function createHook(callbacks: HookCallbacks): AsyncHook; |
||||
|
interface AsyncResourceOptions { |
||||
|
/** |
||||
|
* The ID of the execution context that created this async event. |
||||
|
* @default executionAsyncId() |
||||
|
*/ |
||||
|
triggerAsyncId?: number | undefined; |
||||
|
/** |
||||
|
* Disables automatic `emitDestroy` when the object is garbage collected. |
||||
|
* This usually does not need to be set (even if `emitDestroy` is called |
||||
|
* manually), unless the resource's `asyncId` is retrieved and the |
||||
|
* sensitive API's `emitDestroy` is called with it. |
||||
|
* @default false |
||||
|
*/ |
||||
|
requireManualDestroy?: boolean | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* The class `AsyncResource` is designed to be extended by the embedder's async |
||||
|
* resources. Using this, users can easily trigger the lifetime events of their |
||||
|
* own resources. |
||||
|
* |
||||
|
* The `init` hook will trigger when an `AsyncResource` is instantiated. |
||||
|
* |
||||
|
* The following is an overview of the `AsyncResource` API. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { AsyncResource, executionAsyncId } from 'node:async_hooks'; |
||||
|
* |
||||
|
* // AsyncResource() is meant to be extended. Instantiating a
|
||||
|
* // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
||||
|
* // async_hook.executionAsyncId() is used.
|
||||
|
* const asyncResource = new AsyncResource( |
||||
|
* type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false }, |
||||
|
* ); |
||||
|
* |
||||
|
* // Run a function in the execution context of the resource. This will
|
||||
|
* // * establish the context of the resource
|
||||
|
* // * trigger the AsyncHooks before callbacks
|
||||
|
* // * call the provided function `fn` with the supplied arguments
|
||||
|
* // * trigger the AsyncHooks after callbacks
|
||||
|
* // * restore the original execution context
|
||||
|
* asyncResource.runInAsyncScope(fn, thisArg, ...args); |
||||
|
* |
||||
|
* // Call AsyncHooks destroy callbacks.
|
||||
|
* asyncResource.emitDestroy(); |
||||
|
* |
||||
|
* // Return the unique ID assigned to the AsyncResource instance.
|
||||
|
* asyncResource.asyncId(); |
||||
|
* |
||||
|
* // Return the trigger ID for the AsyncResource instance.
|
||||
|
* asyncResource.triggerAsyncId(); |
||||
|
* ``` |
||||
|
*/ |
||||
|
class AsyncResource { |
||||
|
/** |
||||
|
* AsyncResource() is meant to be extended. Instantiating a |
||||
|
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then |
||||
|
* async_hook.executionAsyncId() is used. |
||||
|
* @param type The type of async event. |
||||
|
* @param triggerAsyncId The ID of the execution context that created |
||||
|
* this async event (default: `executionAsyncId()`), or an |
||||
|
* AsyncResourceOptions object (since v9.3.0) |
||||
|
*/ |
||||
|
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions); |
||||
|
/** |
||||
|
* Binds the given function to the current execution context. |
||||
|
* @since v14.8.0, v12.19.0 |
||||
|
* @param fn The function to bind to the current execution context. |
||||
|
* @param type An optional name to associate with the underlying `AsyncResource`. |
||||
|
*/ |
||||
|
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>( |
||||
|
fn: Func, |
||||
|
type?: string, |
||||
|
thisArg?: ThisArg, |
||||
|
): Func; |
||||
|
/** |
||||
|
* Binds the given function to execute to this `AsyncResource`'s scope. |
||||
|
* @since v14.8.0, v12.19.0 |
||||
|
* @param fn The function to bind to the current `AsyncResource`. |
||||
|
*/ |
||||
|
bind<Func extends (...args: any[]) => any>(fn: Func): Func; |
||||
|
/** |
||||
|
* Call the provided function with the provided arguments in the execution context |
||||
|
* of the async resource. This will establish the context, trigger the AsyncHooks |
||||
|
* before callbacks, call the function, trigger the AsyncHooks after callbacks, and |
||||
|
* then restore the original execution context. |
||||
|
* @since v9.6.0 |
||||
|
* @param fn The function to call in the execution context of this async resource. |
||||
|
* @param thisArg The receiver to be used for the function call. |
||||
|
* @param args Optional arguments to pass to the function. |
||||
|
*/ |
||||
|
runInAsyncScope<This, Result>( |
||||
|
fn: (this: This, ...args: any[]) => Result, |
||||
|
thisArg?: This, |
||||
|
...args: any[] |
||||
|
): Result; |
||||
|
/** |
||||
|
* Call all `destroy` hooks. This should only ever be called once. An error will |
||||
|
* be thrown if it is called more than once. This **must** be manually called. If |
||||
|
* the resource is left to be collected by the GC then the `destroy` hooks will |
||||
|
* never be called. |
||||
|
* @return A reference to `asyncResource`. |
||||
|
*/ |
||||
|
emitDestroy(): this; |
||||
|
/** |
||||
|
* @return The unique `asyncId` assigned to the resource. |
||||
|
*/ |
||||
|
asyncId(): number; |
||||
|
/** |
||||
|
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor. |
||||
|
*/ |
||||
|
triggerAsyncId(): number; |
||||
|
} |
||||
|
interface AsyncLocalStorageOptions { |
||||
|
/** |
||||
|
* The default value to be used when no store is provided. |
||||
|
*/ |
||||
|
defaultValue?: any; |
||||
|
/** |
||||
|
* A name for the `AsyncLocalStorage` value. |
||||
|
*/ |
||||
|
name?: string | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* This class creates stores that stay coherent through asynchronous operations. |
||||
|
* |
||||
|
* While you can create your own implementation on top of the `node:async_hooks` module, `AsyncLocalStorage` should be preferred as it is a performant and memory |
||||
|
* safe implementation that involves significant optimizations that are non-obvious |
||||
|
* to implement. |
||||
|
* |
||||
|
* The following example uses `AsyncLocalStorage` to build a simple logger |
||||
|
* that assigns IDs to incoming HTTP requests and includes them in messages |
||||
|
* logged within each request. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import http from 'node:http'; |
||||
|
* import { AsyncLocalStorage } from 'node:async_hooks'; |
||||
|
* |
||||
|
* const asyncLocalStorage = new AsyncLocalStorage(); |
||||
|
* |
||||
|
* function logWithId(msg) { |
||||
|
* const id = asyncLocalStorage.getStore(); |
||||
|
* console.log(`${id !== undefined ? id : '-'}:`, msg); |
||||
|
* } |
||||
|
* |
||||
|
* let idSeq = 0; |
||||
|
* http.createServer((req, res) => { |
||||
|
* asyncLocalStorage.run(idSeq++, () => { |
||||
|
* logWithId('start'); |
||||
|
* // Imagine any chain of async operations here
|
||||
|
* setImmediate(() => { |
||||
|
* logWithId('finish'); |
||||
|
* res.end(); |
||||
|
* }); |
||||
|
* }); |
||||
|
* }).listen(8080); |
||||
|
* |
||||
|
* http.get('http://localhost:8080'); |
||||
|
* http.get('http://localhost:8080'); |
||||
|
* // Prints:
|
||||
|
* // 0: start
|
||||
|
* // 0: finish
|
||||
|
* // 1: start
|
||||
|
* // 1: finish
|
||||
|
* ``` |
||||
|
* |
||||
|
* Each instance of `AsyncLocalStorage` maintains an independent storage context. |
||||
|
* Multiple instances can safely exist simultaneously without risk of interfering |
||||
|
* with each other's data. |
||||
|
* @since v13.10.0, v12.17.0 |
||||
|
*/ |
||||
|
class AsyncLocalStorage<T> { |
||||
|
/** |
||||
|
* Creates a new instance of `AsyncLocalStorage`. Store is only provided within a |
||||
|
* `run()` call or after an `enterWith()` call. |
||||
|
*/ |
||||
|
constructor(options?: AsyncLocalStorageOptions); |
||||
|
/** |
||||
|
* Binds the given function to the current execution context. |
||||
|
* @since v19.8.0 |
||||
|
* @param fn The function to bind to the current execution context. |
||||
|
* @return A new function that calls `fn` within the captured execution context. |
||||
|
*/ |
||||
|
static bind<Func extends (...args: any[]) => any>(fn: Func): Func; |
||||
|
/** |
||||
|
* Captures the current execution context and returns a function that accepts a |
||||
|
* function as an argument. Whenever the returned function is called, it |
||||
|
* calls the function passed to it within the captured context. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const asyncLocalStorage = new AsyncLocalStorage(); |
||||
|
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot()); |
||||
|
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore())); |
||||
|
* console.log(result); // returns 123
|
||||
|
* ``` |
||||
|
* |
||||
|
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple |
||||
|
* async context tracking purposes, for example: |
||||
|
* |
||||
|
* ```js
|
||||
|
* class Foo { |
||||
|
* #runInAsyncScope = AsyncLocalStorage.snapshot(); |
||||
|
* |
||||
|
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); } |
||||
|
* } |
||||
|
* |
||||
|
* const foo = asyncLocalStorage.run(123, () => new Foo()); |
||||
|
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
||||
|
* ``` |
||||
|
* @since v19.8.0 |
||||
|
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`. |
||||
|
*/ |
||||
|
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R; |
||||
|
/** |
||||
|
* Disables the instance of `AsyncLocalStorage`. All subsequent calls |
||||
|
* to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. |
||||
|
* |
||||
|
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the |
||||
|
* instance will be exited. |
||||
|
* |
||||
|
* Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not apply to stores |
||||
|
* provided by the `asyncLocalStorage`, as those objects are garbage collected |
||||
|
* along with the corresponding async resources. |
||||
|
* |
||||
|
* Use this method when the `asyncLocalStorage` is not in use anymore |
||||
|
* in the current process. |
||||
|
* @since v13.10.0, v12.17.0 |
||||
|
* @experimental |
||||
|
*/ |
||||
|
disable(): void; |
||||
|
/** |
||||
|
* Returns the current store. |
||||
|
* If called outside of an asynchronous context initialized by |
||||
|
* calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it |
||||
|
* returns `undefined`. |
||||
|
* @since v13.10.0, v12.17.0 |
||||
|
*/ |
||||
|
getStore(): T | undefined; |
||||
|
/** |
||||
|
* The name of the `AsyncLocalStorage` instance if provided. |
||||
|
* @since v24.0.0 |
||||
|
*/ |
||||
|
readonly name: string; |
||||
|
/** |
||||
|
* Runs a function synchronously within a context and returns its |
||||
|
* return value. The store is not accessible outside of the callback function. |
||||
|
* The store is accessible to any asynchronous operations created within the |
||||
|
* callback. |
||||
|
* |
||||
|
* The optional `args` are passed to the callback function. |
||||
|
* |
||||
|
* If the callback function throws an error, the error is thrown by `run()` too. |
||||
|
* The stacktrace is not impacted by this call and the context is exited. |
||||
|
* |
||||
|
* Example: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const store = { id: 2 }; |
||||
|
* try { |
||||
|
* asyncLocalStorage.run(store, () => { |
||||
|
* asyncLocalStorage.getStore(); // Returns the store object
|
||||
|
* setTimeout(() => { |
||||
|
* asyncLocalStorage.getStore(); // Returns the store object
|
||||
|
* }, 200); |
||||
|
* throw new Error(); |
||||
|
* }); |
||||
|
* } catch (e) { |
||||
|
* asyncLocalStorage.getStore(); // Returns undefined
|
||||
|
* // The error will be caught here
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v13.10.0, v12.17.0 |
||||
|
*/ |
||||
|
run<R>(store: T, callback: () => R): R; |
||||
|
run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R; |
||||
|
/** |
||||
|
* Runs a function synchronously outside of a context and returns its |
||||
|
* return value. The store is not accessible within the callback function or |
||||
|
* the asynchronous operations created within the callback. Any `getStore()` call done within the callback function will always return `undefined`. |
||||
|
* |
||||
|
* The optional `args` are passed to the callback function. |
||||
|
* |
||||
|
* If the callback function throws an error, the error is thrown by `exit()` too. |
||||
|
* The stacktrace is not impacted by this call and the context is re-entered. |
||||
|
* |
||||
|
* Example: |
||||
|
* |
||||
|
* ```js
|
||||
|
* // Within a call to run
|
||||
|
* try { |
||||
|
* asyncLocalStorage.getStore(); // Returns the store object or value
|
||||
|
* asyncLocalStorage.exit(() => { |
||||
|
* asyncLocalStorage.getStore(); // Returns undefined
|
||||
|
* throw new Error(); |
||||
|
* }); |
||||
|
* } catch (e) { |
||||
|
* asyncLocalStorage.getStore(); // Returns the same object or value
|
||||
|
* // The error will be caught here
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v13.10.0, v12.17.0 |
||||
|
* @experimental |
||||
|
*/ |
||||
|
exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R; |
||||
|
/** |
||||
|
* Transitions into the context for the remainder of the current |
||||
|
* synchronous execution and then persists the store through any following |
||||
|
* asynchronous calls. |
||||
|
* |
||||
|
* Example: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const store = { id: 1 }; |
||||
|
* // Replaces previous store with the given store object
|
||||
|
* asyncLocalStorage.enterWith(store); |
||||
|
* asyncLocalStorage.getStore(); // Returns the store object
|
||||
|
* someAsyncOperation(() => { |
||||
|
* asyncLocalStorage.getStore(); // Returns the same object
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* This transition will continue for the _entire_ synchronous execution. |
||||
|
* This means that if, for example, the context is entered within an event |
||||
|
* handler subsequent event handlers will also run within that context unless |
||||
|
* specifically bound to another context with an `AsyncResource`. That is why `run()` should be preferred over `enterWith()` unless there are strong reasons |
||||
|
* to use the latter method. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const store = { id: 1 }; |
||||
|
* |
||||
|
* emitter.on('my-event', () => { |
||||
|
* asyncLocalStorage.enterWith(store); |
||||
|
* }); |
||||
|
* emitter.on('my-event', () => { |
||||
|
* asyncLocalStorage.getStore(); // Returns the same object
|
||||
|
* }); |
||||
|
* |
||||
|
* asyncLocalStorage.getStore(); // Returns undefined
|
||||
|
* emitter.emit('my-event'); |
||||
|
* asyncLocalStorage.getStore(); // Returns the same object
|
||||
|
* ``` |
||||
|
* @since v13.11.0, v12.17.0 |
||||
|
* @experimental |
||||
|
*/ |
||||
|
enterWith(store: T): void; |
||||
|
} |
||||
|
/** |
||||
|
* @since v17.2.0, v16.14.0 |
||||
|
* @return A map of provider types to the corresponding numeric id. |
||||
|
* This map contains all the event types that might be emitted by the `async_hooks.init()` event. |
||||
|
*/ |
||||
|
namespace asyncWrapProviders { |
||||
|
const NONE: number; |
||||
|
const DIRHANDLE: number; |
||||
|
const DNSCHANNEL: number; |
||||
|
const ELDHISTOGRAM: number; |
||||
|
const FILEHANDLE: number; |
||||
|
const FILEHANDLECLOSEREQ: number; |
||||
|
const FIXEDSIZEBLOBCOPY: number; |
||||
|
const FSEVENTWRAP: number; |
||||
|
const FSREQCALLBACK: number; |
||||
|
const FSREQPROMISE: number; |
||||
|
const GETADDRINFOREQWRAP: number; |
||||
|
const GETNAMEINFOREQWRAP: number; |
||||
|
const HEAPSNAPSHOT: number; |
||||
|
const HTTP2SESSION: number; |
||||
|
const HTTP2STREAM: number; |
||||
|
const HTTP2PING: number; |
||||
|
const HTTP2SETTINGS: number; |
||||
|
const HTTPINCOMINGMESSAGE: number; |
||||
|
const HTTPCLIENTREQUEST: number; |
||||
|
const JSSTREAM: number; |
||||
|
const JSUDPWRAP: number; |
||||
|
const MESSAGEPORT: number; |
||||
|
const PIPECONNECTWRAP: number; |
||||
|
const PIPESERVERWRAP: number; |
||||
|
const PIPEWRAP: number; |
||||
|
const PROCESSWRAP: number; |
||||
|
const PROMISE: number; |
||||
|
const QUERYWRAP: number; |
||||
|
const SHUTDOWNWRAP: number; |
||||
|
const SIGNALWRAP: number; |
||||
|
const STATWATCHER: number; |
||||
|
const STREAMPIPE: number; |
||||
|
const TCPCONNECTWRAP: number; |
||||
|
const TCPSERVERWRAP: number; |
||||
|
const TCPWRAP: number; |
||||
|
const TTYWRAP: number; |
||||
|
const UDPSENDWRAP: number; |
||||
|
const UDPWRAP: number; |
||||
|
const SIGINTWATCHDOG: number; |
||||
|
const WORKER: number; |
||||
|
const WORKERHEAPSNAPSHOT: number; |
||||
|
const WRITEWRAP: number; |
||||
|
const ZLIB: number; |
||||
|
const CHECKPRIMEREQUEST: number; |
||||
|
const PBKDF2REQUEST: number; |
||||
|
const KEYPAIRGENREQUEST: number; |
||||
|
const KEYGENREQUEST: number; |
||||
|
const KEYEXPORTREQUEST: number; |
||||
|
const CIPHERREQUEST: number; |
||||
|
const DERIVEBITSREQUEST: number; |
||||
|
const HASHREQUEST: number; |
||||
|
const RANDOMBYTESREQUEST: number; |
||||
|
const RANDOMPRIMEREQUEST: number; |
||||
|
const SCRYPTREQUEST: number; |
||||
|
const SIGNREQUEST: number; |
||||
|
const TLSWRAP: number; |
||||
|
const VERIFYREQUEST: number; |
||||
|
} |
||||
|
} |
||||
|
declare module "node:async_hooks" { |
||||
|
export * from "async_hooks"; |
||||
|
} |
||||
@ -0,0 +1,463 @@ |
|||||
|
declare module "buffer" { |
||||
|
type ImplicitArrayBuffer<T extends WithImplicitCoercion<ArrayBufferLike>> = T extends |
||||
|
{ valueOf(): infer V extends ArrayBufferLike } ? V : T; |
||||
|
global { |
||||
|
interface BufferConstructor { |
||||
|
// see buffer.d.ts for implementation shared with all TypeScript versions
|
||||
|
|
||||
|
/** |
||||
|
* Allocates a new buffer containing the given {str}. |
||||
|
* |
||||
|
* @param str String to store in buffer. |
||||
|
* @param encoding encoding to use, optional. Default is 'utf8' |
||||
|
* @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead. |
||||
|
*/ |
||||
|
new(str: string, encoding?: BufferEncoding): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Allocates a new buffer of {size} octets. |
||||
|
* |
||||
|
* @param size count of octets to allocate. |
||||
|
* @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`). |
||||
|
*/ |
||||
|
new(size: number): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Allocates a new buffer containing the given {array} of octets. |
||||
|
* |
||||
|
* @param array The octets to store. |
||||
|
* @deprecated since v10.0.0 - Use `Buffer.from(array)` instead. |
||||
|
*/ |
||||
|
new(array: ArrayLike<number>): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Produces a Buffer backed by the same allocated memory as |
||||
|
* the given {ArrayBuffer}/{SharedArrayBuffer}. |
||||
|
* |
||||
|
* @param arrayBuffer The ArrayBuffer with which to share memory. |
||||
|
* @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. |
||||
|
*/ |
||||
|
new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>; |
||||
|
/** |
||||
|
* Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`. |
||||
|
* Array entries outside that range will be truncated to fit into it. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
|
||||
|
* const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); |
||||
|
* ``` |
||||
|
* |
||||
|
* If `array` is an `Array`-like object (that is, one with a `length` property of |
||||
|
* type `number`), it is treated as if it is an array, unless it is a `Buffer` or |
||||
|
* a `Uint8Array`. This means all other `TypedArray` variants get treated as an |
||||
|
* `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use |
||||
|
* `Buffer.copyBytesFrom()`. |
||||
|
* |
||||
|
* A `TypeError` will be thrown if `array` is not an `Array` or another type |
||||
|
* appropriate for `Buffer.from()` variants. |
||||
|
* |
||||
|
* `Buffer.from(array)` and `Buffer.from(string)` may also use the internal |
||||
|
* `Buffer` pool like `Buffer.allocUnsafe()` does. |
||||
|
* @since v5.10.0 |
||||
|
*/ |
||||
|
from(array: WithImplicitCoercion<ArrayLike<number>>): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* This creates a view of the `ArrayBuffer` without copying the underlying |
||||
|
* memory. For example, when passed a reference to the `.buffer` property of a |
||||
|
* `TypedArray` instance, the newly created `Buffer` will share the same |
||||
|
* allocated memory as the `TypedArray`'s underlying `ArrayBuffer`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const arr = new Uint16Array(2); |
||||
|
* |
||||
|
* arr[0] = 5000; |
||||
|
* arr[1] = 4000; |
||||
|
* |
||||
|
* // Shares memory with `arr`.
|
||||
|
* const buf = Buffer.from(arr.buffer); |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 88 13 a0 0f>
|
||||
|
* |
||||
|
* // Changing the original Uint16Array changes the Buffer also.
|
||||
|
* arr[1] = 6000; |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 88 13 70 17>
|
||||
|
* ``` |
||||
|
* |
||||
|
* The optional `byteOffset` and `length` arguments specify a memory range within |
||||
|
* the `arrayBuffer` that will be shared by the `Buffer`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const ab = new ArrayBuffer(10); |
||||
|
* const buf = Buffer.from(ab, 0, 2); |
||||
|
* |
||||
|
* console.log(buf.length); |
||||
|
* // Prints: 2
|
||||
|
* ``` |
||||
|
* |
||||
|
* A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer` or a |
||||
|
* `SharedArrayBuffer` or another type appropriate for `Buffer.from()` |
||||
|
* variants. |
||||
|
* |
||||
|
* It is important to remember that a backing `ArrayBuffer` can cover a range |
||||
|
* of memory that extends beyond the bounds of a `TypedArray` view. A new |
||||
|
* `Buffer` created using the `buffer` property of a `TypedArray` may extend |
||||
|
* beyond the range of the `TypedArray`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements
|
||||
|
* const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements
|
||||
|
* console.log(arrA.buffer === arrB.buffer); // true
|
||||
|
* |
||||
|
* const buf = Buffer.from(arrB.buffer); |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 63 64 65 66>
|
||||
|
* ``` |
||||
|
* @since v5.10.0 |
||||
|
* @param arrayBuffer An `ArrayBuffer`, `SharedArrayBuffer`, for example the |
||||
|
* `.buffer` property of a `TypedArray`. |
||||
|
* @param byteOffset Index of first byte to expose. **Default:** `0`. |
||||
|
* @param length Number of bytes to expose. **Default:** |
||||
|
* `arrayBuffer.byteLength - byteOffset`. |
||||
|
*/ |
||||
|
from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>( |
||||
|
arrayBuffer: TArrayBuffer, |
||||
|
byteOffset?: number, |
||||
|
length?: number, |
||||
|
): Buffer<ImplicitArrayBuffer<TArrayBuffer>>; |
||||
|
/** |
||||
|
* Creates a new `Buffer` containing `string`. The `encoding` parameter identifies |
||||
|
* the character encoding to be used when converting `string` into bytes. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf1 = Buffer.from('this is a tést'); |
||||
|
* const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex'); |
||||
|
* |
||||
|
* console.log(buf1.toString()); |
||||
|
* // Prints: this is a tést
|
||||
|
* console.log(buf2.toString()); |
||||
|
* // Prints: this is a tést
|
||||
|
* console.log(buf1.toString('latin1')); |
||||
|
* // Prints: this is a tést
|
||||
|
* ``` |
||||
|
* |
||||
|
* A `TypeError` will be thrown if `string` is not a string or another type |
||||
|
* appropriate for `Buffer.from()` variants. |
||||
|
* |
||||
|
* `Buffer.from(string)` may also use the internal `Buffer` pool like |
||||
|
* `Buffer.allocUnsafe()` does. |
||||
|
* @since v5.10.0 |
||||
|
* @param string A string to encode. |
||||
|
* @param encoding The encoding of `string`. **Default:** `'utf8'`. |
||||
|
*/ |
||||
|
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>; |
||||
|
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Creates a new Buffer using the passed {data} |
||||
|
* @param values to create a new Buffer |
||||
|
*/ |
||||
|
of(...items: number[]): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together. |
||||
|
* |
||||
|
* If the list has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned. |
||||
|
* |
||||
|
* If `totalLength` is not provided, it is calculated from the `Buffer` instances |
||||
|
* in `list` by adding their lengths. |
||||
|
* |
||||
|
* If `totalLength` is provided, it is coerced to an unsigned integer. If the |
||||
|
* combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is |
||||
|
* truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is |
||||
|
* less than `totalLength`, the remaining space is filled with zeros. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* // Create a single `Buffer` from a list of three `Buffer` instances.
|
||||
|
* |
||||
|
* const buf1 = Buffer.alloc(10); |
||||
|
* const buf2 = Buffer.alloc(14); |
||||
|
* const buf3 = Buffer.alloc(18); |
||||
|
* const totalLength = buf1.length + buf2.length + buf3.length; |
||||
|
* |
||||
|
* console.log(totalLength); |
||||
|
* // Prints: 42
|
||||
|
* |
||||
|
* const bufA = Buffer.concat([buf1, buf2, buf3], totalLength); |
||||
|
* |
||||
|
* console.log(bufA); |
||||
|
* // Prints: <Buffer 00 00 00 00 ...>
|
||||
|
* console.log(bufA.length); |
||||
|
* // Prints: 42
|
||||
|
* ``` |
||||
|
* |
||||
|
* `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does. |
||||
|
* @since v0.7.11 |
||||
|
* @param list List of `Buffer` or {@link Uint8Array} instances to concatenate. |
||||
|
* @param totalLength Total length of the `Buffer` instances in `list` when concatenated. |
||||
|
*/ |
||||
|
concat(list: readonly Uint8Array[], totalLength?: number): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Copies the underlying memory of `view` into a new `Buffer`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const u16 = new Uint16Array([0, 0xffff]); |
||||
|
* const buf = Buffer.copyBytesFrom(u16, 1, 1); |
||||
|
* u16[1] = 0; |
||||
|
* console.log(buf.length); // 2
|
||||
|
* console.log(buf[0]); // 255
|
||||
|
* console.log(buf[1]); // 255
|
||||
|
* ``` |
||||
|
* @since v19.8.0 |
||||
|
* @param view The {TypedArray} to copy. |
||||
|
* @param [offset=0] The starting offset within `view`. |
||||
|
* @param [length=view.length - offset] The number of elements from `view` to copy. |
||||
|
*/ |
||||
|
copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf = Buffer.alloc(5); |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 00 00 00 00 00>
|
||||
|
* ``` |
||||
|
* |
||||
|
* If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. |
||||
|
* |
||||
|
* If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf = Buffer.alloc(5, 'a'); |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 61 61 61 61 61>
|
||||
|
* ``` |
||||
|
* |
||||
|
* If both `fill` and `encoding` are specified, the allocated `Buffer` will be |
||||
|
* initialized by calling `buf.fill(fill, encoding)`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64'); |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
||||
|
* ``` |
||||
|
* |
||||
|
* Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance |
||||
|
* contents will never contain sensitive data from previous allocations, including |
||||
|
* data that might not have been allocated for `Buffer`s. |
||||
|
* |
||||
|
* A `TypeError` will be thrown if `size` is not a number. |
||||
|
* @since v5.10.0 |
||||
|
* @param size The desired length of the new `Buffer`. |
||||
|
* @param [fill=0] A value to pre-fill the new `Buffer` with. |
||||
|
* @param [encoding='utf8'] If `fill` is a string, this is its encoding. |
||||
|
*/ |
||||
|
alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. |
||||
|
* |
||||
|
* The underlying memory for `Buffer` instances created in this way is _not_ |
||||
|
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf = Buffer.allocUnsafe(10); |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
|
||||
|
* |
||||
|
* buf.fill(0); |
||||
|
* |
||||
|
* console.log(buf); |
||||
|
* // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
||||
|
* ``` |
||||
|
* |
||||
|
* A `TypeError` will be thrown if `size` is not a number. |
||||
|
* |
||||
|
* The `Buffer` module pre-allocates an internal `Buffer` instance of |
||||
|
* size `Buffer.poolSize` that is used as a pool for the fast allocation of new `Buffer` instances created using `Buffer.allocUnsafe()`, `Buffer.from(array)`, |
||||
|
* and `Buffer.concat()` only when `size` is less than `Buffer.poolSize >>> 1` (floor of `Buffer.poolSize` divided by two). |
||||
|
* |
||||
|
* Use of this pre-allocated internal memory pool is a key difference between |
||||
|
* calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`. |
||||
|
* Specifically, `Buffer.alloc(size, fill)` will _never_ use the internal `Buffer`pool, while `Buffer.allocUnsafe(size).fill(fill)`_will_ use the internal`Buffer` pool if `size` is less |
||||
|
* than or equal to half `Buffer.poolSize`. The |
||||
|
* difference is subtle but can be important when an application requires the |
||||
|
* additional performance that `Buffer.allocUnsafe()` provides. |
||||
|
* @since v5.10.0 |
||||
|
* @param size The desired length of the new `Buffer`. |
||||
|
*/ |
||||
|
allocUnsafe(size: number): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. A zero-length `Buffer` is created if |
||||
|
* `size` is 0. |
||||
|
* |
||||
|
* The underlying memory for `Buffer` instances created in this way is _not_ |
||||
|
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize |
||||
|
* such `Buffer` instances with zeroes. |
||||
|
* |
||||
|
* When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances, |
||||
|
* allocations under 4 KiB are sliced from a single pre-allocated `Buffer`. This |
||||
|
* allows applications to avoid the garbage collection overhead of creating many |
||||
|
* individually allocated `Buffer` instances. This approach improves both |
||||
|
* performance and memory usage by eliminating the need to track and clean up as |
||||
|
* many individual `ArrayBuffer` objects. |
||||
|
* |
||||
|
* However, in the case where a developer may need to retain a small chunk of |
||||
|
* memory from a pool for an indeterminate amount of time, it may be appropriate |
||||
|
* to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and |
||||
|
* then copying out the relevant bits. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* // Need to keep around a few small chunks of memory.
|
||||
|
* const store = []; |
||||
|
* |
||||
|
* socket.on('readable', () => { |
||||
|
* let data; |
||||
|
* while (null !== (data = readable.read())) { |
||||
|
* // Allocate for retained data.
|
||||
|
* const sb = Buffer.allocUnsafeSlow(10); |
||||
|
* |
||||
|
* // Copy the data into the new allocation.
|
||||
|
* data.copy(sb, 0, 0, 10); |
||||
|
* |
||||
|
* store.push(sb); |
||||
|
* } |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* A `TypeError` will be thrown if `size` is not a number. |
||||
|
* @since v5.12.0 |
||||
|
* @param size The desired length of the new `Buffer`. |
||||
|
*/ |
||||
|
allocUnsafeSlow(size: number): Buffer<ArrayBuffer>; |
||||
|
} |
||||
|
interface Buffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> extends Uint8Array<TArrayBuffer> { |
||||
|
// see buffer.d.ts for implementation shared with all TypeScript versions
|
||||
|
|
||||
|
/** |
||||
|
* Returns a new `Buffer` that references the same memory as the original, but |
||||
|
* offset and cropped by the `start` and `end` indices. |
||||
|
* |
||||
|
* This method is not compatible with the `Uint8Array.prototype.slice()`, |
||||
|
* which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf = Buffer.from('buffer'); |
||||
|
* |
||||
|
* const copiedBuf = Uint8Array.prototype.slice.call(buf); |
||||
|
* copiedBuf[0]++; |
||||
|
* console.log(copiedBuf.toString()); |
||||
|
* // Prints: cuffer
|
||||
|
* |
||||
|
* console.log(buf.toString()); |
||||
|
* // Prints: buffer
|
||||
|
* |
||||
|
* // With buf.slice(), the original buffer is modified.
|
||||
|
* const notReallyCopiedBuf = buf.slice(); |
||||
|
* notReallyCopiedBuf[0]++; |
||||
|
* console.log(notReallyCopiedBuf.toString()); |
||||
|
* // Prints: cuffer
|
||||
|
* console.log(buf.toString()); |
||||
|
* // Also prints: cuffer (!)
|
||||
|
* ``` |
||||
|
* @since v0.3.0 |
||||
|
* @deprecated Use `subarray` instead. |
||||
|
* @param [start=0] Where the new `Buffer` will start. |
||||
|
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive). |
||||
|
*/ |
||||
|
slice(start?: number, end?: number): Buffer<ArrayBuffer>; |
||||
|
/** |
||||
|
* Returns a new `Buffer` that references the same memory as the original, but |
||||
|
* offset and cropped by the `start` and `end` indices. |
||||
|
* |
||||
|
* Specifying `end` greater than `buf.length` will return the same result as |
||||
|
* that of `end` equal to `buf.length`. |
||||
|
* |
||||
|
* This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
|
||||
|
* |
||||
|
* Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
|
||||
|
* // from the original `Buffer`.
|
||||
|
* |
||||
|
* const buf1 = Buffer.allocUnsafe(26); |
||||
|
* |
||||
|
* for (let i = 0; i < 26; i++) { |
||||
|
* // 97 is the decimal ASCII value for 'a'.
|
||||
|
* buf1[i] = i + 97; |
||||
|
* } |
||||
|
* |
||||
|
* const buf2 = buf1.subarray(0, 3); |
||||
|
* |
||||
|
* console.log(buf2.toString('ascii', 0, buf2.length)); |
||||
|
* // Prints: abc
|
||||
|
* |
||||
|
* buf1[0] = 33; |
||||
|
* |
||||
|
* console.log(buf2.toString('ascii', 0, buf2.length)); |
||||
|
* // Prints: !bc
|
||||
|
* ``` |
||||
|
* |
||||
|
* Specifying negative indexes causes the slice to be generated relative to the |
||||
|
* end of `buf` rather than the beginning. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf = Buffer.from('buffer'); |
||||
|
* |
||||
|
* console.log(buf.subarray(-6, -1).toString()); |
||||
|
* // Prints: buffe
|
||||
|
* // (Equivalent to buf.subarray(0, 5).)
|
||||
|
* |
||||
|
* console.log(buf.subarray(-6, -2).toString()); |
||||
|
* // Prints: buff
|
||||
|
* // (Equivalent to buf.subarray(0, 4).)
|
||||
|
* |
||||
|
* console.log(buf.subarray(-5, -2).toString()); |
||||
|
* // Prints: uff
|
||||
|
* // (Equivalent to buf.subarray(1, 4).)
|
||||
|
* ``` |
||||
|
* @since v3.0.0 |
||||
|
* @param [start=0] Where the new `Buffer` will start. |
||||
|
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive). |
||||
|
*/ |
||||
|
subarray(start?: number, end?: number): Buffer<TArrayBuffer>; |
||||
|
} |
||||
|
type NonSharedBuffer = Buffer<ArrayBuffer>; |
||||
|
type AllowSharedBuffer = Buffer<ArrayBufferLike>; |
||||
|
} |
||||
|
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ |
||||
|
var SlowBuffer: { |
||||
|
/** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */ |
||||
|
new(size: number): Buffer<ArrayBuffer>; |
||||
|
prototype: Buffer; |
||||
|
}; |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,579 @@ |
|||||
|
/** |
||||
|
* Clusters of Node.js processes can be used to run multiple instances of Node.js |
||||
|
* that can distribute workloads among their application threads. When process isolation |
||||
|
* is not needed, use the [`worker_threads`](https://nodejs.org/docs/latest-v24.x/api/worker_threads.html)
|
||||
|
* module instead, which allows running multiple application threads within a single Node.js instance. |
||||
|
* |
||||
|
* The cluster module allows easy creation of child processes that all share |
||||
|
* server ports. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import cluster from 'node:cluster'; |
||||
|
* import http from 'node:http'; |
||||
|
* import { availableParallelism } from 'node:os'; |
||||
|
* import process from 'node:process'; |
||||
|
* |
||||
|
* const numCPUs = availableParallelism(); |
||||
|
* |
||||
|
* if (cluster.isPrimary) { |
||||
|
* console.log(`Primary ${process.pid} is running`); |
||||
|
* |
||||
|
* // Fork workers.
|
||||
|
* for (let i = 0; i < numCPUs; i++) { |
||||
|
* cluster.fork(); |
||||
|
* } |
||||
|
* |
||||
|
* cluster.on('exit', (worker, code, signal) => { |
||||
|
* console.log(`worker ${worker.process.pid} died`); |
||||
|
* }); |
||||
|
* } else { |
||||
|
* // Workers can share any TCP connection
|
||||
|
* // In this case it is an HTTP server
|
||||
|
* http.createServer((req, res) => { |
||||
|
* res.writeHead(200); |
||||
|
* res.end('hello world\n'); |
||||
|
* }).listen(8000); |
||||
|
* |
||||
|
* console.log(`Worker ${process.pid} started`); |
||||
|
* } |
||||
|
* ``` |
||||
|
* |
||||
|
* Running Node.js will now share port 8000 between the workers: |
||||
|
* |
||||
|
* ```console
|
||||
|
* $ node server.js |
||||
|
* Primary 3596 is running |
||||
|
* Worker 4324 started |
||||
|
* Worker 4520 started |
||||
|
* Worker 6056 started |
||||
|
* Worker 5644 started |
||||
|
* ``` |
||||
|
* |
||||
|
* On Windows, it is not yet possible to set up a named pipe server in a worker. |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/cluster.js)
|
||||
|
*/ |
||||
|
declare module "cluster" { |
||||
|
import * as child from "node:child_process"; |
||||
|
import EventEmitter = require("node:events"); |
||||
|
import * as net from "node:net"; |
||||
|
type SerializationType = "json" | "advanced"; |
||||
|
export interface ClusterSettings { |
||||
|
/** |
||||
|
* List of string arguments passed to the Node.js executable. |
||||
|
* @default process.execArgv |
||||
|
*/ |
||||
|
execArgv?: string[] | undefined; |
||||
|
/** |
||||
|
* File path to worker file. |
||||
|
* @default process.argv[1] |
||||
|
*/ |
||||
|
exec?: string | undefined; |
||||
|
/** |
||||
|
* String arguments passed to worker. |
||||
|
* @default process.argv.slice(2) |
||||
|
*/ |
||||
|
args?: string[] | undefined; |
||||
|
/** |
||||
|
* Whether or not to send output to parent's stdio. |
||||
|
* @default false |
||||
|
*/ |
||||
|
silent?: boolean | undefined; |
||||
|
/** |
||||
|
* Configures the stdio of forked processes. Because the cluster module relies on IPC to function, this configuration must |
||||
|
* contain an `'ipc'` entry. When this option is provided, it overrides `silent`. See [`child_prcess.spawn()`](https://nodejs.org/docs/latest-v24.x/api/child_process.html#child_processspawncommand-args-options)'s
|
||||
|
* [`stdio`](https://nodejs.org/docs/latest-v24.x/api/child_process.html#optionsstdio).
|
||||
|
*/ |
||||
|
stdio?: any[] | undefined; |
||||
|
/** |
||||
|
* Sets the user identity of the process. (See [`setuid(2)`](https://man7.org/linux/man-pages/man2/setuid.2.html).)
|
||||
|
*/ |
||||
|
uid?: number | undefined; |
||||
|
/** |
||||
|
* Sets the group identity of the process. (See [`setgid(2)`](https://man7.org/linux/man-pages/man2/setgid.2.html).)
|
||||
|
*/ |
||||
|
gid?: number | undefined; |
||||
|
/** |
||||
|
* Sets inspector port of worker. This can be a number, or a function that takes no arguments and returns a number. |
||||
|
* By default each worker gets its own port, incremented from the primary's `process.debugPort`. |
||||
|
*/ |
||||
|
inspectPort?: number | (() => number) | undefined; |
||||
|
/** |
||||
|
* Specify the kind of serialization used for sending messages between processes. Possible values are `'json'` and `'advanced'`. |
||||
|
* See [Advanced serialization for `child_process`](https://nodejs.org/docs/latest-v24.x/api/child_process.html#advanced-serialization) for more details.
|
||||
|
* @default false |
||||
|
*/ |
||||
|
serialization?: SerializationType | undefined; |
||||
|
/** |
||||
|
* Current working directory of the worker process. |
||||
|
* @default undefined (inherits from parent process) |
||||
|
*/ |
||||
|
cwd?: string | undefined; |
||||
|
/** |
||||
|
* Hide the forked processes console window that would normally be created on Windows systems. |
||||
|
* @default false |
||||
|
*/ |
||||
|
windowsHide?: boolean | undefined; |
||||
|
} |
||||
|
export interface Address { |
||||
|
address: string; |
||||
|
port: number; |
||||
|
/** |
||||
|
* The `addressType` is one of: |
||||
|
* |
||||
|
* * `4` (TCPv4) |
||||
|
* * `6` (TCPv6) |
||||
|
* * `-1` (Unix domain socket) |
||||
|
* * `'udp4'` or `'udp6'` (UDPv4 or UDPv6) |
||||
|
*/ |
||||
|
addressType: 4 | 6 | -1 | "udp4" | "udp6"; |
||||
|
} |
||||
|
/** |
||||
|
* A `Worker` object contains all public information and method about a worker. |
||||
|
* In the primary it can be obtained using `cluster.workers`. In a worker |
||||
|
* it can be obtained using `cluster.worker`. |
||||
|
* @since v0.7.0 |
||||
|
*/ |
||||
|
export class Worker extends EventEmitter { |
||||
|
/** |
||||
|
* Each new worker is given its own unique id, this id is stored in the `id`. |
||||
|
* |
||||
|
* While a worker is alive, this is the key that indexes it in `cluster.workers`. |
||||
|
* @since v0.8.0 |
||||
|
*/ |
||||
|
id: number; |
||||
|
/** |
||||
|
* All workers are created using [`child_process.fork()`](https://nodejs.org/docs/latest-v24.x/api/child_process.html#child_processforkmodulepath-args-options), the returned object
|
||||
|
* from this function is stored as `.process`. In a worker, the global `process` is stored. |
||||
|
* |
||||
|
* See: [Child Process module](https://nodejs.org/docs/latest-v24.x/api/child_process.html#child_processforkmodulepath-args-options).
|
||||
|
* |
||||
|
* Workers will call `process.exit(0)` if the `'disconnect'` event occurs |
||||
|
* on `process` and `.exitedAfterDisconnect` is not `true`. This protects against |
||||
|
* accidental disconnection. |
||||
|
* @since v0.7.0 |
||||
|
*/ |
||||
|
process: child.ChildProcess; |
||||
|
/** |
||||
|
* Send a message to a worker or primary, optionally with a handle. |
||||
|
* |
||||
|
* In the primary, this sends a message to a specific worker. It is identical to [`ChildProcess.send()`](https://nodejs.org/docs/latest-v24.x/api/child_process.html#subprocesssendmessage-sendhandle-options-callback).
|
||||
|
* |
||||
|
* In a worker, this sends a message to the primary. It is identical to `process.send()`. |
||||
|
* |
||||
|
* This example will echo back all messages from the primary: |
||||
|
* |
||||
|
* ```js
|
||||
|
* if (cluster.isPrimary) { |
||||
|
* const worker = cluster.fork(); |
||||
|
* worker.send('hi there'); |
||||
|
* |
||||
|
* } else if (cluster.isWorker) { |
||||
|
* process.on('message', (msg) => { |
||||
|
* process.send(msg); |
||||
|
* }); |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.7.0 |
||||
|
* @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles. |
||||
|
*/ |
||||
|
send(message: child.Serializable, callback?: (error: Error | null) => void): boolean; |
||||
|
send( |
||||
|
message: child.Serializable, |
||||
|
sendHandle: child.SendHandle, |
||||
|
callback?: (error: Error | null) => void, |
||||
|
): boolean; |
||||
|
send( |
||||
|
message: child.Serializable, |
||||
|
sendHandle: child.SendHandle, |
||||
|
options?: child.MessageOptions, |
||||
|
callback?: (error: Error | null) => void, |
||||
|
): boolean; |
||||
|
/** |
||||
|
* This function will kill the worker. In the primary worker, it does this by |
||||
|
* disconnecting the `worker.process`, and once disconnected, killing with `signal`. In the worker, it does it by killing the process with `signal`. |
||||
|
* |
||||
|
* The `kill()` function kills the worker process without waiting for a graceful |
||||
|
* disconnect, it has the same behavior as `worker.process.kill()`. |
||||
|
* |
||||
|
* This method is aliased as `worker.destroy()` for backwards compatibility. |
||||
|
* |
||||
|
* In a worker, `process.kill()` exists, but it is not this function; |
||||
|
* it is [`kill()`](https://nodejs.org/docs/latest-v24.x/api/process.html#processkillpid-signal).
|
||||
|
* @since v0.9.12 |
||||
|
* @param [signal='SIGTERM'] Name of the kill signal to send to the worker process. |
||||
|
*/ |
||||
|
kill(signal?: string): void; |
||||
|
destroy(signal?: string): void; |
||||
|
/** |
||||
|
* In a worker, this function will close all servers, wait for the `'close'` event |
||||
|
* on those servers, and then disconnect the IPC channel. |
||||
|
* |
||||
|
* In the primary, an internal message is sent to the worker causing it to call `.disconnect()` on itself. |
||||
|
* |
||||
|
* Causes `.exitedAfterDisconnect` to be set. |
||||
|
* |
||||
|
* After a server is closed, it will no longer accept new connections, |
||||
|
* but connections may be accepted by any other listening worker. Existing |
||||
|
* connections will be allowed to close as usual. When no more connections exist, |
||||
|
* see `server.close()`, the IPC channel to the worker will close allowing it |
||||
|
* to die gracefully. |
||||
|
* |
||||
|
* The above applies _only_ to server connections, client connections are not |
||||
|
* automatically closed by workers, and disconnect does not wait for them to close |
||||
|
* before exiting. |
||||
|
* |
||||
|
* In a worker, `process.disconnect` exists, but it is not this function; |
||||
|
* it is `disconnect()`. |
||||
|
* |
||||
|
* Because long living server connections may block workers from disconnecting, it |
||||
|
* may be useful to send a message, so application specific actions may be taken to |
||||
|
* close them. It also may be useful to implement a timeout, killing a worker if |
||||
|
* the `'disconnect'` event has not been emitted after some time. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import net from 'node:net'; |
||||
|
* |
||||
|
* if (cluster.isPrimary) { |
||||
|
* const worker = cluster.fork(); |
||||
|
* let timeout; |
||||
|
* |
||||
|
* worker.on('listening', (address) => { |
||||
|
* worker.send('shutdown'); |
||||
|
* worker.disconnect(); |
||||
|
* timeout = setTimeout(() => { |
||||
|
* worker.kill(); |
||||
|
* }, 2000); |
||||
|
* }); |
||||
|
* |
||||
|
* worker.on('disconnect', () => { |
||||
|
* clearTimeout(timeout); |
||||
|
* }); |
||||
|
* |
||||
|
* } else if (cluster.isWorker) { |
||||
|
* const server = net.createServer((socket) => { |
||||
|
* // Connections never end
|
||||
|
* }); |
||||
|
* |
||||
|
* server.listen(8000); |
||||
|
* |
||||
|
* process.on('message', (msg) => { |
||||
|
* if (msg === 'shutdown') { |
||||
|
* // Initiate graceful close of any connections to server
|
||||
|
* } |
||||
|
* }); |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.7.7 |
||||
|
* @return A reference to `worker`. |
||||
|
*/ |
||||
|
disconnect(): this; |
||||
|
/** |
||||
|
* This function returns `true` if the worker is connected to its primary via its |
||||
|
* IPC channel, `false` otherwise. A worker is connected to its primary after it |
||||
|
* has been created. It is disconnected after the `'disconnect'` event is emitted. |
||||
|
* @since v0.11.14 |
||||
|
*/ |
||||
|
isConnected(): boolean; |
||||
|
/** |
||||
|
* This function returns `true` if the worker's process has terminated (either |
||||
|
* because of exiting or being signaled). Otherwise, it returns `false`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import cluster from 'node:cluster'; |
||||
|
* import http from 'node:http'; |
||||
|
* import { availableParallelism } from 'node:os'; |
||||
|
* import process from 'node:process'; |
||||
|
* |
||||
|
* const numCPUs = availableParallelism(); |
||||
|
* |
||||
|
* if (cluster.isPrimary) { |
||||
|
* console.log(`Primary ${process.pid} is running`); |
||||
|
* |
||||
|
* // Fork workers.
|
||||
|
* for (let i = 0; i < numCPUs; i++) { |
||||
|
* cluster.fork(); |
||||
|
* } |
||||
|
* |
||||
|
* cluster.on('fork', (worker) => { |
||||
|
* console.log('worker is dead:', worker.isDead()); |
||||
|
* }); |
||||
|
* |
||||
|
* cluster.on('exit', (worker, code, signal) => { |
||||
|
* console.log('worker is dead:', worker.isDead()); |
||||
|
* }); |
||||
|
* } else { |
||||
|
* // Workers can share any TCP connection. In this case, it is an HTTP server.
|
||||
|
* http.createServer((req, res) => { |
||||
|
* res.writeHead(200); |
||||
|
* res.end(`Current process\n ${process.pid}`); |
||||
|
* process.kill(process.pid); |
||||
|
* }).listen(8000); |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.11.14 |
||||
|
*/ |
||||
|
isDead(): boolean; |
||||
|
/** |
||||
|
* This property is `true` if the worker exited due to `.disconnect()`. |
||||
|
* If the worker exited any other way, it is `false`. If the |
||||
|
* worker has not exited, it is `undefined`. |
||||
|
* |
||||
|
* The boolean `worker.exitedAfterDisconnect` allows distinguishing between |
||||
|
* voluntary and accidental exit, the primary may choose not to respawn a worker |
||||
|
* based on this value. |
||||
|
* |
||||
|
* ```js
|
||||
|
* cluster.on('exit', (worker, code, signal) => { |
||||
|
* if (worker.exitedAfterDisconnect === true) { |
||||
|
* console.log('Oh, it was just voluntary – no need to worry'); |
||||
|
* } |
||||
|
* }); |
||||
|
* |
||||
|
* // kill worker
|
||||
|
* worker.kill(); |
||||
|
* ``` |
||||
|
* @since v6.0.0 |
||||
|
*/ |
||||
|
exitedAfterDisconnect: boolean; |
||||
|
/** |
||||
|
* events.EventEmitter |
||||
|
* 1. disconnect |
||||
|
* 2. error |
||||
|
* 3. exit |
||||
|
* 4. listening |
||||
|
* 5. message |
||||
|
* 6. online |
||||
|
*/ |
||||
|
addListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
addListener(event: "disconnect", listener: () => void): this; |
||||
|
addListener(event: "error", listener: (error: Error) => void): this; |
||||
|
addListener(event: "exit", listener: (code: number, signal: string) => void): this; |
||||
|
addListener(event: "listening", listener: (address: Address) => void): this; |
||||
|
addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
addListener(event: "online", listener: () => void): this; |
||||
|
emit(event: string | symbol, ...args: any[]): boolean; |
||||
|
emit(event: "disconnect"): boolean; |
||||
|
emit(event: "error", error: Error): boolean; |
||||
|
emit(event: "exit", code: number, signal: string): boolean; |
||||
|
emit(event: "listening", address: Address): boolean; |
||||
|
emit(event: "message", message: any, handle: net.Socket | net.Server): boolean; |
||||
|
emit(event: "online"): boolean; |
||||
|
on(event: string, listener: (...args: any[]) => void): this; |
||||
|
on(event: "disconnect", listener: () => void): this; |
||||
|
on(event: "error", listener: (error: Error) => void): this; |
||||
|
on(event: "exit", listener: (code: number, signal: string) => void): this; |
||||
|
on(event: "listening", listener: (address: Address) => void): this; |
||||
|
on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
on(event: "online", listener: () => void): this; |
||||
|
once(event: string, listener: (...args: any[]) => void): this; |
||||
|
once(event: "disconnect", listener: () => void): this; |
||||
|
once(event: "error", listener: (error: Error) => void): this; |
||||
|
once(event: "exit", listener: (code: number, signal: string) => void): this; |
||||
|
once(event: "listening", listener: (address: Address) => void): this; |
||||
|
once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
once(event: "online", listener: () => void): this; |
||||
|
prependListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependListener(event: "disconnect", listener: () => void): this; |
||||
|
prependListener(event: "error", listener: (error: Error) => void): this; |
||||
|
prependListener(event: "exit", listener: (code: number, signal: string) => void): this; |
||||
|
prependListener(event: "listening", listener: (address: Address) => void): this; |
||||
|
prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
prependListener(event: "online", listener: () => void): this; |
||||
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependOnceListener(event: "disconnect", listener: () => void): this; |
||||
|
prependOnceListener(event: "error", listener: (error: Error) => void): this; |
||||
|
prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this; |
||||
|
prependOnceListener(event: "listening", listener: (address: Address) => void): this; |
||||
|
prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
prependOnceListener(event: "online", listener: () => void): this; |
||||
|
} |
||||
|
export interface Cluster extends EventEmitter { |
||||
|
disconnect(callback?: () => void): void; |
||||
|
/** |
||||
|
* Spawn a new worker process. |
||||
|
* |
||||
|
* This can only be called from the primary process. |
||||
|
* @param env Key/value pairs to add to worker process environment. |
||||
|
* @since v0.6.0 |
||||
|
*/ |
||||
|
fork(env?: any): Worker; |
||||
|
/** @deprecated since v16.0.0 - use isPrimary. */ |
||||
|
readonly isMaster: boolean; |
||||
|
/** |
||||
|
* True if the process is a primary. This is determined by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID` |
||||
|
* is undefined, then `isPrimary` is `true`. |
||||
|
* @since v16.0.0 |
||||
|
*/ |
||||
|
readonly isPrimary: boolean; |
||||
|
/** |
||||
|
* True if the process is not a primary (it is the negation of `cluster.isPrimary`). |
||||
|
* @since v0.6.0 |
||||
|
*/ |
||||
|
readonly isWorker: boolean; |
||||
|
/** |
||||
|
* The scheduling policy, either `cluster.SCHED_RR` for round-robin or `cluster.SCHED_NONE` to leave it to the operating system. This is a |
||||
|
* global setting and effectively frozen once either the first worker is spawned, or [`.setupPrimary()`](https://nodejs.org/docs/latest-v24.x/api/cluster.html#clustersetupprimarysettings)
|
||||
|
* is called, whichever comes first. |
||||
|
* |
||||
|
* `SCHED_RR` is the default on all operating systems except Windows. Windows will change to `SCHED_RR` once libuv is able to effectively distribute |
||||
|
* IOCP handles without incurring a large performance hit. |
||||
|
* |
||||
|
* `cluster.schedulingPolicy` can also be set through the `NODE_CLUSTER_SCHED_POLICY` environment variable. Valid values are `'rr'` and `'none'`. |
||||
|
* @since v0.11.2 |
||||
|
*/ |
||||
|
schedulingPolicy: number; |
||||
|
/** |
||||
|
* After calling [`.setupPrimary()`](https://nodejs.org/docs/latest-v24.x/api/cluster.html#clustersetupprimarysettings)
|
||||
|
* (or [`.fork()`](https://nodejs.org/docs/latest-v24.x/api/cluster.html#clusterforkenv)) this settings object will contain
|
||||
|
* the settings, including the default values. |
||||
|
* |
||||
|
* This object is not intended to be changed or set manually. |
||||
|
* @since v0.7.1 |
||||
|
*/ |
||||
|
readonly settings: ClusterSettings; |
||||
|
/** @deprecated since v16.0.0 - use [`.setupPrimary()`](https://nodejs.org/docs/latest-v24.x/api/cluster.html#clustersetupprimarysettings) instead. */ |
||||
|
setupMaster(settings?: ClusterSettings): void; |
||||
|
/** |
||||
|
* `setupPrimary` is used to change the default 'fork' behavior. Once called, the settings will be present in `cluster.settings`. |
||||
|
* |
||||
|
* Any settings changes only affect future calls to [`.fork()`](https://nodejs.org/docs/latest-v24.x/api/cluster.html#clusterforkenv)
|
||||
|
* and have no effect on workers that are already running. |
||||
|
* |
||||
|
* The only attribute of a worker that cannot be set via `.setupPrimary()` is the `env` passed to |
||||
|
* [`.fork()`](https://nodejs.org/docs/latest-v24.x/api/cluster.html#clusterforkenv).
|
||||
|
* |
||||
|
* The defaults above apply to the first call only; the defaults for later calls are the current values at the time of |
||||
|
* `cluster.setupPrimary()` is called. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import cluster from 'node:cluster'; |
||||
|
* |
||||
|
* cluster.setupPrimary({ |
||||
|
* exec: 'worker.js', |
||||
|
* args: ['--use', 'https'], |
||||
|
* silent: true, |
||||
|
* }); |
||||
|
* cluster.fork(); // https worker
|
||||
|
* cluster.setupPrimary({ |
||||
|
* exec: 'worker.js', |
||||
|
* args: ['--use', 'http'], |
||||
|
* }); |
||||
|
* cluster.fork(); // http worker
|
||||
|
* ``` |
||||
|
* |
||||
|
* This can only be called from the primary process. |
||||
|
* @since v16.0.0 |
||||
|
*/ |
||||
|
setupPrimary(settings?: ClusterSettings): void; |
||||
|
/** |
||||
|
* A reference to the current worker object. Not available in the primary process. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import cluster from 'node:cluster'; |
||||
|
* |
||||
|
* if (cluster.isPrimary) { |
||||
|
* console.log('I am primary'); |
||||
|
* cluster.fork(); |
||||
|
* cluster.fork(); |
||||
|
* } else if (cluster.isWorker) { |
||||
|
* console.log(`I am worker #${cluster.worker.id}`); |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.7.0 |
||||
|
*/ |
||||
|
readonly worker?: Worker | undefined; |
||||
|
/** |
||||
|
* A hash that stores the active worker objects, keyed by `id` field. This makes it easy to loop through all the workers. It is only available in the primary process. |
||||
|
* |
||||
|
* A worker is removed from `cluster.workers` after the worker has disconnected _and_ exited. The order between these two events cannot be determined in advance. However, it |
||||
|
* is guaranteed that the removal from the `cluster.workers` list happens before the last `'disconnect'` or `'exit'` event is emitted. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import cluster from 'node:cluster'; |
||||
|
* |
||||
|
* for (const worker of Object.values(cluster.workers)) { |
||||
|
* worker.send('big announcement to all workers'); |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.7.0 |
||||
|
*/ |
||||
|
readonly workers?: NodeJS.Dict<Worker> | undefined; |
||||
|
readonly SCHED_NONE: number; |
||||
|
readonly SCHED_RR: number; |
||||
|
/** |
||||
|
* events.EventEmitter |
||||
|
* 1. disconnect |
||||
|
* 2. exit |
||||
|
* 3. fork |
||||
|
* 4. listening |
||||
|
* 5. message |
||||
|
* 6. online |
||||
|
* 7. setup |
||||
|
*/ |
||||
|
addListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
addListener(event: "disconnect", listener: (worker: Worker) => void): this; |
||||
|
addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; |
||||
|
addListener(event: "fork", listener: (worker: Worker) => void): this; |
||||
|
addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; |
||||
|
addListener( |
||||
|
event: "message", |
||||
|
listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void, |
||||
|
): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
addListener(event: "online", listener: (worker: Worker) => void): this; |
||||
|
addListener(event: "setup", listener: (settings: ClusterSettings) => void): this; |
||||
|
emit(event: string | symbol, ...args: any[]): boolean; |
||||
|
emit(event: "disconnect", worker: Worker): boolean; |
||||
|
emit(event: "exit", worker: Worker, code: number, signal: string): boolean; |
||||
|
emit(event: "fork", worker: Worker): boolean; |
||||
|
emit(event: "listening", worker: Worker, address: Address): boolean; |
||||
|
emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean; |
||||
|
emit(event: "online", worker: Worker): boolean; |
||||
|
emit(event: "setup", settings: ClusterSettings): boolean; |
||||
|
on(event: string, listener: (...args: any[]) => void): this; |
||||
|
on(event: "disconnect", listener: (worker: Worker) => void): this; |
||||
|
on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; |
||||
|
on(event: "fork", listener: (worker: Worker) => void): this; |
||||
|
on(event: "listening", listener: (worker: Worker, address: Address) => void): this; |
||||
|
on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
on(event: "online", listener: (worker: Worker) => void): this; |
||||
|
on(event: "setup", listener: (settings: ClusterSettings) => void): this; |
||||
|
once(event: string, listener: (...args: any[]) => void): this; |
||||
|
once(event: "disconnect", listener: (worker: Worker) => void): this; |
||||
|
once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; |
||||
|
once(event: "fork", listener: (worker: Worker) => void): this; |
||||
|
once(event: "listening", listener: (worker: Worker, address: Address) => void): this; |
||||
|
once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
once(event: "online", listener: (worker: Worker) => void): this; |
||||
|
once(event: "setup", listener: (settings: ClusterSettings) => void): this; |
||||
|
prependListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependListener(event: "disconnect", listener: (worker: Worker) => void): this; |
||||
|
prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; |
||||
|
prependListener(event: "fork", listener: (worker: Worker) => void): this; |
||||
|
prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; |
||||
|
// the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
prependListener( |
||||
|
event: "message", |
||||
|
listener: (worker: Worker, message: any, handle?: net.Socket | net.Server) => void, |
||||
|
): this; |
||||
|
prependListener(event: "online", listener: (worker: Worker) => void): this; |
||||
|
prependListener(event: "setup", listener: (settings: ClusterSettings) => void): this; |
||||
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this; |
||||
|
prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; |
||||
|
prependOnceListener(event: "fork", listener: (worker: Worker) => void): this; |
||||
|
prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; |
||||
|
// the handle is a net.Socket or net.Server object, or undefined.
|
||||
|
prependOnceListener( |
||||
|
event: "message", |
||||
|
listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void, |
||||
|
): this; |
||||
|
prependOnceListener(event: "online", listener: (worker: Worker) => void): this; |
||||
|
prependOnceListener(event: "setup", listener: (settings: ClusterSettings) => void): this; |
||||
|
} |
||||
|
const cluster: Cluster; |
||||
|
export default cluster; |
||||
|
} |
||||
|
declare module "node:cluster" { |
||||
|
export * from "cluster"; |
||||
|
export { default as default } from "cluster"; |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
// Backwards-compatible iterator interfaces, augmented with iterator helper methods by lib.esnext.iterator in TypeScript 5.6.
|
||||
|
// The IterableIterator interface does not contain these methods, which creates assignability issues in places where IteratorObjects
|
||||
|
// are expected (eg. DOM-compatible APIs) if lib.esnext.iterator is loaded.
|
||||
|
// Also ensures that iterators returned by the Node API, which inherit from Iterator.prototype, correctly expose the iterator helper methods
|
||||
|
// if lib.esnext.iterator is loaded.
|
||||
|
// TODO: remove once this package no longer supports TS 5.5, and replace NodeJS.BuiltinIteratorReturn with BuiltinIteratorReturn.
|
||||
|
|
||||
|
// Placeholders for TS <5.6
|
||||
|
interface IteratorObject<T, TReturn, TNext> {} |
||||
|
interface AsyncIteratorObject<T, TReturn, TNext> {} |
||||
|
|
||||
|
declare namespace NodeJS { |
||||
|
// Populate iterator methods for TS <5.6
|
||||
|
interface Iterator<T, TReturn, TNext> extends globalThis.Iterator<T, TReturn, TNext> {} |
||||
|
interface AsyncIterator<T, TReturn, TNext> extends globalThis.AsyncIterator<T, TReturn, TNext> {} |
||||
|
|
||||
|
// Polyfill for TS 5.6's instrinsic BuiltinIteratorReturn type, required for DOM-compatible iterators
|
||||
|
type BuiltinIteratorReturn = ReturnType<any[][typeof Symbol.iterator]> extends |
||||
|
globalThis.Iterator<any, infer TReturn> ? TReturn |
||||
|
: any; |
||||
|
} |
||||
@ -0,0 +1,452 @@ |
|||||
|
/** |
||||
|
* The `node:console` module provides a simple debugging console that is similar to |
||||
|
* the JavaScript console mechanism provided by web browsers. |
||||
|
* |
||||
|
* The module exports two specific components: |
||||
|
* |
||||
|
* * A `Console` class with methods such as `console.log()`, `console.error()`, and `console.warn()` that can be used to write to any Node.js stream. |
||||
|
* * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
|
||||
|
* [`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
|
||||
|
* |
||||
|
* _**Warning**_: The global console object's methods are neither consistently |
||||
|
* synchronous like the browser APIs they resemble, nor are they consistently |
||||
|
* asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
|
||||
|
* more information. |
||||
|
* |
||||
|
* Example using the global `console`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* console.log('hello world'); |
||||
|
* // Prints: hello world, to stdout
|
||||
|
* console.log('hello %s', 'world'); |
||||
|
* // Prints: hello world, to stdout
|
||||
|
* console.error(new Error('Whoops, something bad happened')); |
||||
|
* // Prints error message and stack trace to stderr:
|
||||
|
* // Error: Whoops, something bad happened
|
||||
|
* // at [eval]:5:15
|
||||
|
* // at Script.runInThisContext (node:vm:132:18)
|
||||
|
* // at Object.runInThisContext (node:vm:309:38)
|
||||
|
* // at node:internal/process/execution:77:19
|
||||
|
* // at [eval]-wrapper:6:22
|
||||
|
* // at evalScript (node:internal/process/execution:76:60)
|
||||
|
* // at node:internal/main/eval_string:23:3
|
||||
|
* |
||||
|
* const name = 'Will Robinson'; |
||||
|
* console.warn(`Danger ${name}! Danger!`); |
||||
|
* // Prints: Danger Will Robinson! Danger!, to stderr
|
||||
|
* ``` |
||||
|
* |
||||
|
* Example using the `Console` class: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const out = getStreamSomehow(); |
||||
|
* const err = getStreamSomehow(); |
||||
|
* const myConsole = new console.Console(out, err); |
||||
|
* |
||||
|
* myConsole.log('hello world'); |
||||
|
* // Prints: hello world, to out
|
||||
|
* myConsole.log('hello %s', 'world'); |
||||
|
* // Prints: hello world, to out
|
||||
|
* myConsole.error(new Error('Whoops, something bad happened')); |
||||
|
* // Prints: [Error: Whoops, something bad happened], to err
|
||||
|
* |
||||
|
* const name = 'Will Robinson'; |
||||
|
* myConsole.warn(`Danger ${name}! Danger!`); |
||||
|
* // Prints: Danger Will Robinson! Danger!, to err
|
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/console.js)
|
||||
|
*/ |
||||
|
declare module "console" { |
||||
|
import console = require("node:console"); |
||||
|
export = console; |
||||
|
} |
||||
|
declare module "node:console" { |
||||
|
import { InspectOptions } from "node:util"; |
||||
|
global { |
||||
|
// This needs to be global to avoid TS2403 in case lib.dom.d.ts is present in the same build
|
||||
|
interface Console { |
||||
|
Console: console.ConsoleConstructor; |
||||
|
/** |
||||
|
* `console.assert()` writes a message if `value` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) or omitted. It only
|
||||
|
* writes a message and does not otherwise affect execution. The output always |
||||
|
* starts with `"Assertion failed"`. If provided, `message` is formatted using |
||||
|
* [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args).
|
||||
|
* |
||||
|
* If `value` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), nothing happens.
|
||||
|
* |
||||
|
* ```js
|
||||
|
* console.assert(true, 'does nothing'); |
||||
|
* |
||||
|
* console.assert(false, 'Whoops %s work', 'didn\'t'); |
||||
|
* // Assertion failed: Whoops didn't work
|
||||
|
* |
||||
|
* console.assert(); |
||||
|
* // Assertion failed
|
||||
|
* ``` |
||||
|
* @since v0.1.101 |
||||
|
* @param value The value tested for being truthy. |
||||
|
* @param message All arguments besides `value` are used as error message. |
||||
|
*/ |
||||
|
assert(value: any, message?: string, ...optionalParams: any[]): void; |
||||
|
/** |
||||
|
* When `stdout` is a TTY, calling `console.clear()` will attempt to clear the |
||||
|
* TTY. When `stdout` is not a TTY, this method does nothing. |
||||
|
* |
||||
|
* The specific operation of `console.clear()` can vary across operating systems |
||||
|
* and terminal types. For most Linux operating systems, `console.clear()` operates similarly to the `clear` shell command. On Windows, `console.clear()` will clear only the output in the |
||||
|
* current terminal viewport for the Node.js |
||||
|
* binary. |
||||
|
* @since v8.3.0 |
||||
|
*/ |
||||
|
clear(): void; |
||||
|
/** |
||||
|
* Maintains an internal counter specific to `label` and outputs to `stdout` the |
||||
|
* number of times `console.count()` has been called with the given `label`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* > console.count() |
||||
|
* default: 1 |
||||
|
* undefined |
||||
|
* > console.count('default') |
||||
|
* default: 2 |
||||
|
* undefined |
||||
|
* > console.count('abc') |
||||
|
* abc: 1 |
||||
|
* undefined |
||||
|
* > console.count('xyz') |
||||
|
* xyz: 1 |
||||
|
* undefined |
||||
|
* > console.count('abc') |
||||
|
* abc: 2 |
||||
|
* undefined |
||||
|
* > console.count() |
||||
|
* default: 3 |
||||
|
* undefined |
||||
|
* > |
||||
|
* ``` |
||||
|
* @since v8.3.0 |
||||
|
* @param [label='default'] The display label for the counter. |
||||
|
*/ |
||||
|
count(label?: string): void; |
||||
|
/** |
||||
|
* Resets the internal counter specific to `label`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* > console.count('abc'); |
||||
|
* abc: 1 |
||||
|
* undefined |
||||
|
* > console.countReset('abc'); |
||||
|
* undefined |
||||
|
* > console.count('abc'); |
||||
|
* abc: 1 |
||||
|
* undefined |
||||
|
* > |
||||
|
* ``` |
||||
|
* @since v8.3.0 |
||||
|
* @param [label='default'] The display label for the counter. |
||||
|
*/ |
||||
|
countReset(label?: string): void; |
||||
|
/** |
||||
|
* The `console.debug()` function is an alias for {@link log}. |
||||
|
* @since v8.0.0 |
||||
|
*/ |
||||
|
debug(message?: any, ...optionalParams: any[]): void; |
||||
|
/** |
||||
|
* Uses [`util.inspect()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilinspectobject-options) on `obj` and prints the resulting string to `stdout`.
|
||||
|
* This function bypasses any custom `inspect()` function defined on `obj`. |
||||
|
* @since v0.1.101 |
||||
|
*/ |
||||
|
dir(obj: any, options?: InspectOptions): void; |
||||
|
/** |
||||
|
* This method calls `console.log()` passing it the arguments received. |
||||
|
* This method does not produce any XML formatting. |
||||
|
* @since v8.0.0 |
||||
|
*/ |
||||
|
dirxml(...data: any[]): void; |
||||
|
/** |
||||
|
* Prints to `stderr` with newline. Multiple arguments can be passed, with the |
||||
|
* first used as the primary message and all additional used as substitution |
||||
|
* values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
|
||||
|
* (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
|
||||
|
* |
||||
|
* ```js
|
||||
|
* const code = 5; |
||||
|
* console.error('error #%d', code); |
||||
|
* // Prints: error #5, to stderr
|
||||
|
* console.error('error', code); |
||||
|
* // Prints: error 5, to stderr
|
||||
|
* ``` |
||||
|
* |
||||
|
* If formatting elements (e.g. `%d`) are not found in the first string then |
||||
|
* [`util.inspect()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilinspectobject-options) is called on each argument and the
|
||||
|
* resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)
|
||||
|
* for more information. |
||||
|
* @since v0.1.100 |
||||
|
*/ |
||||
|
error(message?: any, ...optionalParams: any[]): void; |
||||
|
/** |
||||
|
* Increases indentation of subsequent lines by spaces for `groupIndentation` length. |
||||
|
* |
||||
|
* If one or more `label`s are provided, those are printed first without the |
||||
|
* additional indentation. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
group(...label: any[]): void; |
||||
|
/** |
||||
|
* An alias for {@link group}. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
groupCollapsed(...label: any[]): void; |
||||
|
/** |
||||
|
* Decreases indentation of subsequent lines by spaces for `groupIndentation` length. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
groupEnd(): void; |
||||
|
/** |
||||
|
* The `console.info()` function is an alias for {@link log}. |
||||
|
* @since v0.1.100 |
||||
|
*/ |
||||
|
info(message?: any, ...optionalParams: any[]): void; |
||||
|
/** |
||||
|
* Prints to `stdout` with newline. Multiple arguments can be passed, with the |
||||
|
* first used as the primary message and all additional used as substitution |
||||
|
* values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
|
||||
|
* (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
|
||||
|
* |
||||
|
* ```js
|
||||
|
* const count = 5; |
||||
|
* console.log('count: %d', count); |
||||
|
* // Prints: count: 5, to stdout
|
||||
|
* console.log('count:', count); |
||||
|
* // Prints: count: 5, to stdout
|
||||
|
* ``` |
||||
|
* |
||||
|
* See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.
|
||||
|
* @since v0.1.100 |
||||
|
*/ |
||||
|
log(message?: any, ...optionalParams: any[]): void; |
||||
|
/** |
||||
|
* Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and rows of `tabularData` and log it. Falls back to just |
||||
|
* logging the argument if it can't be parsed as tabular. |
||||
|
* |
||||
|
* ```js
|
||||
|
* // These can't be parsed as tabular data
|
||||
|
* console.table(Symbol()); |
||||
|
* // Symbol()
|
||||
|
* |
||||
|
* console.table(undefined); |
||||
|
* // undefined
|
||||
|
* |
||||
|
* console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]); |
||||
|
* // ┌─────────┬─────┬─────┐
|
||||
|
* // │ (index) │ a │ b │
|
||||
|
* // ├─────────┼─────┼─────┤
|
||||
|
* // │ 0 │ 1 │ 'Y' │
|
||||
|
* // │ 1 │ 'Z' │ 2 │
|
||||
|
* // └─────────┴─────┴─────┘
|
||||
|
* |
||||
|
* console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['a']); |
||||
|
* // ┌─────────┬─────┐
|
||||
|
* // │ (index) │ a │
|
||||
|
* // ├─────────┼─────┤
|
||||
|
* // │ 0 │ 1 │
|
||||
|
* // │ 1 │ 'Z' │
|
||||
|
* // └─────────┴─────┘
|
||||
|
* ``` |
||||
|
* @since v10.0.0 |
||||
|
* @param properties Alternate properties for constructing the table. |
||||
|
*/ |
||||
|
table(tabularData: any, properties?: readonly string[]): void; |
||||
|
/** |
||||
|
* Starts a timer that can be used to compute the duration of an operation. Timers |
||||
|
* are identified by a unique `label`. Use the same `label` when calling {@link timeEnd} to stop the timer and output the elapsed time in |
||||
|
* suitable time units to `stdout`. For example, if the elapsed |
||||
|
* time is 3869ms, `console.timeEnd()` displays "3.869s". |
||||
|
* @since v0.1.104 |
||||
|
* @param [label='default'] |
||||
|
*/ |
||||
|
time(label?: string): void; |
||||
|
/** |
||||
|
* Stops a timer that was previously started by calling {@link time} and |
||||
|
* prints the result to `stdout`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* console.time('bunch-of-stuff'); |
||||
|
* // Do a bunch of stuff.
|
||||
|
* console.timeEnd('bunch-of-stuff'); |
||||
|
* // Prints: bunch-of-stuff: 225.438ms
|
||||
|
* ``` |
||||
|
* @since v0.1.104 |
||||
|
* @param [label='default'] |
||||
|
*/ |
||||
|
timeEnd(label?: string): void; |
||||
|
/** |
||||
|
* For a timer that was previously started by calling {@link time}, prints |
||||
|
* the elapsed time and other `data` arguments to `stdout`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* console.time('process'); |
||||
|
* const value = expensiveProcess1(); // Returns 42
|
||||
|
* console.timeLog('process', value); |
||||
|
* // Prints "process: 365.227ms 42".
|
||||
|
* doExpensiveProcess2(value); |
||||
|
* console.timeEnd('process'); |
||||
|
* ``` |
||||
|
* @since v10.7.0 |
||||
|
* @param [label='default'] |
||||
|
*/ |
||||
|
timeLog(label?: string, ...data: any[]): void; |
||||
|
/** |
||||
|
* Prints to `stderr` the string `'Trace: '`, followed by the [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)
|
||||
|
* formatted message and stack trace to the current position in the code. |
||||
|
* |
||||
|
* ```js
|
||||
|
* console.trace('Show me'); |
||||
|
* // Prints: (stack trace will vary based on where trace is called)
|
||||
|
* // Trace: Show me
|
||||
|
* // at repl:2:9
|
||||
|
* // at REPLServer.defaultEval (repl.js:248:27)
|
||||
|
* // at bound (domain.js:287:14)
|
||||
|
* // at REPLServer.runBound [as eval] (domain.js:300:12)
|
||||
|
* // at REPLServer.<anonymous> (repl.js:412:12)
|
||||
|
* // at emitOne (events.js:82:20)
|
||||
|
* // at REPLServer.emit (events.js:169:7)
|
||||
|
* // at REPLServer.Interface._onLine (readline.js:210:10)
|
||||
|
* // at REPLServer.Interface._line (readline.js:549:8)
|
||||
|
* // at REPLServer.Interface._ttyWrite (readline.js:826:14)
|
||||
|
* ``` |
||||
|
* @since v0.1.104 |
||||
|
*/ |
||||
|
trace(message?: any, ...optionalParams: any[]): void; |
||||
|
/** |
||||
|
* The `console.warn()` function is an alias for {@link error}. |
||||
|
* @since v0.1.100 |
||||
|
*/ |
||||
|
warn(message?: any, ...optionalParams: any[]): void; |
||||
|
// --- Inspector mode only ---
|
||||
|
/** |
||||
|
* This method does not display anything unless used in the inspector. The `console.profile()` |
||||
|
* method starts a JavaScript CPU profile with an optional label until {@link profileEnd} |
||||
|
* is called. The profile is then added to the Profile panel of the inspector. |
||||
|
* |
||||
|
* ```js
|
||||
|
* console.profile('MyLabel'); |
||||
|
* // Some code
|
||||
|
* console.profileEnd('MyLabel'); |
||||
|
* // Adds the profile 'MyLabel' to the Profiles panel of the inspector.
|
||||
|
* ``` |
||||
|
* @since v8.0.0 |
||||
|
*/ |
||||
|
profile(label?: string): void; |
||||
|
/** |
||||
|
* This method does not display anything unless used in the inspector. Stops the current |
||||
|
* JavaScript CPU profiling session if one has been started and prints the report to the |
||||
|
* Profiles panel of the inspector. See {@link profile} for an example. |
||||
|
* |
||||
|
* If this method is called without a label, the most recently started profile is stopped. |
||||
|
* @since v8.0.0 |
||||
|
*/ |
||||
|
profileEnd(label?: string): void; |
||||
|
/** |
||||
|
* This method does not display anything unless used in the inspector. The `console.timeStamp()` |
||||
|
* method adds an event with the label `'label'` to the Timeline panel of the inspector. |
||||
|
* @since v8.0.0 |
||||
|
*/ |
||||
|
timeStamp(label?: string): void; |
||||
|
} |
||||
|
/** |
||||
|
* The `console` module provides a simple debugging console that is similar to the |
||||
|
* JavaScript console mechanism provided by web browsers. |
||||
|
* |
||||
|
* The module exports two specific components: |
||||
|
* |
||||
|
* * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. |
||||
|
* * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) and
|
||||
|
* [`process.stderr`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
|
||||
|
* |
||||
|
* _**Warning**_: The global console object's methods are neither consistently |
||||
|
* synchronous like the browser APIs they resemble, nor are they consistently |
||||
|
* asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v24.x/api/process.html#a-note-on-process-io) for
|
||||
|
* more information. |
||||
|
* |
||||
|
* Example using the global `console`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* console.log('hello world'); |
||||
|
* // Prints: hello world, to stdout
|
||||
|
* console.log('hello %s', 'world'); |
||||
|
* // Prints: hello world, to stdout
|
||||
|
* console.error(new Error('Whoops, something bad happened')); |
||||
|
* // Prints error message and stack trace to stderr:
|
||||
|
* // Error: Whoops, something bad happened
|
||||
|
* // at [eval]:5:15
|
||||
|
* // at Script.runInThisContext (node:vm:132:18)
|
||||
|
* // at Object.runInThisContext (node:vm:309:38)
|
||||
|
* // at node:internal/process/execution:77:19
|
||||
|
* // at [eval]-wrapper:6:22
|
||||
|
* // at evalScript (node:internal/process/execution:76:60)
|
||||
|
* // at node:internal/main/eval_string:23:3
|
||||
|
* |
||||
|
* const name = 'Will Robinson'; |
||||
|
* console.warn(`Danger ${name}! Danger!`); |
||||
|
* // Prints: Danger Will Robinson! Danger!, to stderr
|
||||
|
* ``` |
||||
|
* |
||||
|
* Example using the `Console` class: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const out = getStreamSomehow(); |
||||
|
* const err = getStreamSomehow(); |
||||
|
* const myConsole = new console.Console(out, err); |
||||
|
* |
||||
|
* myConsole.log('hello world'); |
||||
|
* // Prints: hello world, to out
|
||||
|
* myConsole.log('hello %s', 'world'); |
||||
|
* // Prints: hello world, to out
|
||||
|
* myConsole.error(new Error('Whoops, something bad happened')); |
||||
|
* // Prints: [Error: Whoops, something bad happened], to err
|
||||
|
* |
||||
|
* const name = 'Will Robinson'; |
||||
|
* myConsole.warn(`Danger ${name}! Danger!`); |
||||
|
* // Prints: Danger Will Robinson! Danger!, to err
|
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/console.js)
|
||||
|
*/ |
||||
|
namespace console { |
||||
|
interface ConsoleConstructorOptions { |
||||
|
stdout: NodeJS.WritableStream; |
||||
|
stderr?: NodeJS.WritableStream | undefined; |
||||
|
/** |
||||
|
* Ignore errors when writing to the underlying streams. |
||||
|
* @default true |
||||
|
*/ |
||||
|
ignoreErrors?: boolean | undefined; |
||||
|
/** |
||||
|
* Set color support for this `Console` instance. Setting to true enables coloring while inspecting |
||||
|
* values. Setting to `false` disables coloring while inspecting values. Setting to `'auto'` makes color |
||||
|
* support depend on the value of the `isTTY` property and the value returned by `getColorDepth()` on the |
||||
|
* respective stream. This option can not be used, if `inspectOptions.colors` is set as well. |
||||
|
* @default auto |
||||
|
*/ |
||||
|
colorMode?: boolean | "auto" | undefined; |
||||
|
/** |
||||
|
* Specifies options that are passed along to |
||||
|
* [`util.inspect()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilinspectobject-options).
|
||||
|
*/ |
||||
|
inspectOptions?: InspectOptions | undefined; |
||||
|
/** |
||||
|
* Set group indentation. |
||||
|
* @default 2 |
||||
|
*/ |
||||
|
groupIndentation?: number | undefined; |
||||
|
} |
||||
|
interface ConsoleConstructor { |
||||
|
prototype: Console; |
||||
|
new(stdout: NodeJS.WritableStream, stderr?: NodeJS.WritableStream, ignoreErrors?: boolean): Console; |
||||
|
new(options: ConsoleConstructorOptions): Console; |
||||
|
} |
||||
|
} |
||||
|
var console: Console; |
||||
|
} |
||||
|
export = globalThis.console; |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
/** |
||||
|
* @deprecated The `node:constants` module is deprecated. When requiring access to constants |
||||
|
* relevant to specific Node.js builtin modules, developers should instead refer |
||||
|
* to the `constants` property exposed by the relevant module. For instance, |
||||
|
* `require('node:fs').constants` and `require('node:os').constants`. |
||||
|
*/ |
||||
|
declare module "constants" { |
||||
|
const constants: |
||||
|
& typeof import("node:os").constants.dlopen |
||||
|
& typeof import("node:os").constants.errno |
||||
|
& typeof import("node:os").constants.priority |
||||
|
& typeof import("node:os").constants.signals |
||||
|
& typeof import("node:fs").constants |
||||
|
& typeof import("node:crypto").constants; |
||||
|
export = constants; |
||||
|
} |
||||
|
|
||||
|
declare module "node:constants" { |
||||
|
import constants = require("constants"); |
||||
|
export = constants; |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,599 @@ |
|||||
|
/** |
||||
|
* The `node:dgram` module provides an implementation of UDP datagram sockets. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dgram from 'node:dgram'; |
||||
|
* |
||||
|
* const server = dgram.createSocket('udp4'); |
||||
|
* |
||||
|
* server.on('error', (err) => { |
||||
|
* console.error(`server error:\n${err.stack}`); |
||||
|
* server.close(); |
||||
|
* }); |
||||
|
* |
||||
|
* server.on('message', (msg, rinfo) => { |
||||
|
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); |
||||
|
* }); |
||||
|
* |
||||
|
* server.on('listening', () => { |
||||
|
* const address = server.address(); |
||||
|
* console.log(`server listening ${address.address}:${address.port}`); |
||||
|
* }); |
||||
|
* |
||||
|
* server.bind(41234); |
||||
|
* // Prints: server listening 0.0.0.0:41234
|
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/dgram.js)
|
||||
|
*/ |
||||
|
declare module "dgram" { |
||||
|
import { AddressInfo, BlockList } from "node:net"; |
||||
|
import * as dns from "node:dns"; |
||||
|
import { Abortable, EventEmitter } from "node:events"; |
||||
|
interface RemoteInfo { |
||||
|
address: string; |
||||
|
family: "IPv4" | "IPv6"; |
||||
|
port: number; |
||||
|
size: number; |
||||
|
} |
||||
|
interface BindOptions { |
||||
|
port?: number | undefined; |
||||
|
address?: string | undefined; |
||||
|
exclusive?: boolean | undefined; |
||||
|
fd?: number | undefined; |
||||
|
} |
||||
|
type SocketType = "udp4" | "udp6"; |
||||
|
interface SocketOptions extends Abortable { |
||||
|
type: SocketType; |
||||
|
reuseAddr?: boolean | undefined; |
||||
|
reusePort?: boolean | undefined; |
||||
|
/** |
||||
|
* @default false |
||||
|
*/ |
||||
|
ipv6Only?: boolean | undefined; |
||||
|
recvBufferSize?: number | undefined; |
||||
|
sendBufferSize?: number | undefined; |
||||
|
lookup?: |
||||
|
| (( |
||||
|
hostname: string, |
||||
|
options: dns.LookupOneOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void, |
||||
|
) => void) |
||||
|
| undefined; |
||||
|
receiveBlockList?: BlockList | undefined; |
||||
|
sendBlockList?: BlockList | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* Creates a `dgram.Socket` object. Once the socket is created, calling `socket.bind()` will instruct the socket to begin listening for datagram |
||||
|
* messages. When `address` and `port` are not passed to `socket.bind()` the |
||||
|
* method will bind the socket to the "all interfaces" address on a random port |
||||
|
* (it does the right thing for both `udp4` and `udp6` sockets). The bound address |
||||
|
* and port can be retrieved using `socket.address().address` and `socket.address().port`. |
||||
|
* |
||||
|
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.close()` on the socket: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const controller = new AbortController(); |
||||
|
* const { signal } = controller; |
||||
|
* const server = dgram.createSocket({ type: 'udp4', signal }); |
||||
|
* server.on('message', (msg, rinfo) => { |
||||
|
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); |
||||
|
* }); |
||||
|
* // Later, when you want to close the server.
|
||||
|
* controller.abort(); |
||||
|
* ``` |
||||
|
* @since v0.11.13 |
||||
|
* @param options Available options are: |
||||
|
* @param callback Attached as a listener for `'message'` events. Optional. |
||||
|
*/ |
||||
|
function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; |
||||
|
function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; |
||||
|
/** |
||||
|
* Encapsulates the datagram functionality. |
||||
|
* |
||||
|
* New instances of `dgram.Socket` are created using {@link createSocket}. |
||||
|
* The `new` keyword is not to be used to create `dgram.Socket` instances. |
||||
|
* @since v0.1.99 |
||||
|
*/ |
||||
|
class Socket extends EventEmitter { |
||||
|
/** |
||||
|
* Tells the kernel to join a multicast group at the given `multicastAddress` and `multicastInterface` using the `IP_ADD_MEMBERSHIP` socket option. If the `multicastInterface` argument is not |
||||
|
* specified, the operating system will choose |
||||
|
* one interface and will add membership to it. To add membership to every |
||||
|
* available interface, call `addMembership` multiple times, once per interface. |
||||
|
* |
||||
|
* When called on an unbound socket, this method will implicitly bind to a random |
||||
|
* port, listening on all interfaces. |
||||
|
* |
||||
|
* When sharing a UDP socket across multiple `cluster` workers, the`socket.addMembership()` function must be called only once or an`EADDRINUSE` error will occur: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import cluster from 'node:cluster'; |
||||
|
* import dgram from 'node:dgram'; |
||||
|
* |
||||
|
* if (cluster.isPrimary) { |
||||
|
* cluster.fork(); // Works ok.
|
||||
|
* cluster.fork(); // Fails with EADDRINUSE.
|
||||
|
* } else { |
||||
|
* const s = dgram.createSocket('udp4'); |
||||
|
* s.bind(1234, () => { |
||||
|
* s.addMembership('224.0.0.114'); |
||||
|
* }); |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.6.9 |
||||
|
*/ |
||||
|
addMembership(multicastAddress: string, multicastInterface?: string): void; |
||||
|
/** |
||||
|
* Returns an object containing the address information for a socket. |
||||
|
* For UDP sockets, this object will contain `address`, `family`, and `port` properties. |
||||
|
* |
||||
|
* This method throws `EBADF` if called on an unbound socket. |
||||
|
* @since v0.1.99 |
||||
|
*/ |
||||
|
address(): AddressInfo; |
||||
|
/** |
||||
|
* For UDP sockets, causes the `dgram.Socket` to listen for datagram |
||||
|
* messages on a named `port` and optional `address`. If `port` is not |
||||
|
* specified or is `0`, the operating system will attempt to bind to a |
||||
|
* random port. If `address` is not specified, the operating system will |
||||
|
* attempt to listen on all addresses. Once binding is complete, a `'listening'` event is emitted and the optional `callback` function is |
||||
|
* called. |
||||
|
* |
||||
|
* Specifying both a `'listening'` event listener and passing a `callback` to the `socket.bind()` method is not harmful but not very |
||||
|
* useful. |
||||
|
* |
||||
|
* A bound datagram socket keeps the Node.js process running to receive |
||||
|
* datagram messages. |
||||
|
* |
||||
|
* If binding fails, an `'error'` event is generated. In rare case (e.g. |
||||
|
* attempting to bind with a closed socket), an `Error` may be thrown. |
||||
|
* |
||||
|
* Example of a UDP server listening on port 41234: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dgram from 'node:dgram'; |
||||
|
* |
||||
|
* const server = dgram.createSocket('udp4'); |
||||
|
* |
||||
|
* server.on('error', (err) => { |
||||
|
* console.error(`server error:\n${err.stack}`); |
||||
|
* server.close(); |
||||
|
* }); |
||||
|
* |
||||
|
* server.on('message', (msg, rinfo) => { |
||||
|
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); |
||||
|
* }); |
||||
|
* |
||||
|
* server.on('listening', () => { |
||||
|
* const address = server.address(); |
||||
|
* console.log(`server listening ${address.address}:${address.port}`); |
||||
|
* }); |
||||
|
* |
||||
|
* server.bind(41234); |
||||
|
* // Prints: server listening 0.0.0.0:41234
|
||||
|
* ``` |
||||
|
* @since v0.1.99 |
||||
|
* @param callback with no parameters. Called when binding is complete. |
||||
|
*/ |
||||
|
bind(port?: number, address?: string, callback?: () => void): this; |
||||
|
bind(port?: number, callback?: () => void): this; |
||||
|
bind(callback?: () => void): this; |
||||
|
bind(options: BindOptions, callback?: () => void): this; |
||||
|
/** |
||||
|
* Close the underlying socket and stop listening for data on it. If a callback is |
||||
|
* provided, it is added as a listener for the `'close'` event. |
||||
|
* @since v0.1.99 |
||||
|
* @param callback Called when the socket has been closed. |
||||
|
*/ |
||||
|
close(callback?: () => void): this; |
||||
|
/** |
||||
|
* Associates the `dgram.Socket` to a remote address and port. Every |
||||
|
* message sent by this handle is automatically sent to that destination. Also, |
||||
|
* the socket will only receive messages from that remote peer. |
||||
|
* Trying to call `connect()` on an already connected socket will result |
||||
|
* in an `ERR_SOCKET_DGRAM_IS_CONNECTED` exception. If `address` is not |
||||
|
* provided, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets) |
||||
|
* will be used by default. Once the connection is complete, a `'connect'` event |
||||
|
* is emitted and the optional `callback` function is called. In case of failure, |
||||
|
* the `callback` is called or, failing this, an `'error'` event is emitted. |
||||
|
* @since v12.0.0 |
||||
|
* @param callback Called when the connection is completed or on error. |
||||
|
*/ |
||||
|
connect(port: number, address?: string, callback?: () => void): void; |
||||
|
connect(port: number, callback: () => void): void; |
||||
|
/** |
||||
|
* A synchronous function that disassociates a connected `dgram.Socket` from |
||||
|
* its remote address. Trying to call `disconnect()` on an unbound or already |
||||
|
* disconnected socket will result in an `ERR_SOCKET_DGRAM_NOT_CONNECTED` exception. |
||||
|
* @since v12.0.0 |
||||
|
*/ |
||||
|
disconnect(): void; |
||||
|
/** |
||||
|
* Instructs the kernel to leave a multicast group at `multicastAddress` using the `IP_DROP_MEMBERSHIP` socket option. This method is automatically called by the |
||||
|
* kernel when the socket is closed or the process terminates, so most apps will |
||||
|
* never have reason to call this. |
||||
|
* |
||||
|
* If `multicastInterface` is not specified, the operating system will attempt to |
||||
|
* drop membership on all valid interfaces. |
||||
|
* @since v0.6.9 |
||||
|
*/ |
||||
|
dropMembership(multicastAddress: string, multicastInterface?: string): void; |
||||
|
/** |
||||
|
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket. |
||||
|
* @since v8.7.0 |
||||
|
* @return the `SO_RCVBUF` socket receive buffer size in bytes. |
||||
|
*/ |
||||
|
getRecvBufferSize(): number; |
||||
|
/** |
||||
|
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket. |
||||
|
* @since v8.7.0 |
||||
|
* @return the `SO_SNDBUF` socket send buffer size in bytes. |
||||
|
*/ |
||||
|
getSendBufferSize(): number; |
||||
|
/** |
||||
|
* @since v18.8.0, v16.19.0 |
||||
|
* @return Number of bytes queued for sending. |
||||
|
*/ |
||||
|
getSendQueueSize(): number; |
||||
|
/** |
||||
|
* @since v18.8.0, v16.19.0 |
||||
|
* @return Number of send requests currently in the queue awaiting to be processed. |
||||
|
*/ |
||||
|
getSendQueueCount(): number; |
||||
|
/** |
||||
|
* By default, binding a socket will cause it to block the Node.js process from |
||||
|
* exiting as long as the socket is open. The `socket.unref()` method can be used |
||||
|
* to exclude the socket from the reference counting that keeps the Node.js |
||||
|
* process active. The `socket.ref()` method adds the socket back to the reference |
||||
|
* counting and restores the default behavior. |
||||
|
* |
||||
|
* Calling `socket.ref()` multiples times will have no additional effect. |
||||
|
* |
||||
|
* The `socket.ref()` method returns a reference to the socket so calls can be |
||||
|
* chained. |
||||
|
* @since v0.9.1 |
||||
|
*/ |
||||
|
ref(): this; |
||||
|
/** |
||||
|
* Returns an object containing the `address`, `family`, and `port` of the remote |
||||
|
* endpoint. This method throws an `ERR_SOCKET_DGRAM_NOT_CONNECTED` exception |
||||
|
* if the socket is not connected. |
||||
|
* @since v12.0.0 |
||||
|
*/ |
||||
|
remoteAddress(): AddressInfo; |
||||
|
/** |
||||
|
* Broadcasts a datagram on the socket. |
||||
|
* For connectionless sockets, the destination `port` and `address` must be |
||||
|
* specified. Connected sockets, on the other hand, will use their associated |
||||
|
* remote endpoint, so the `port` and `address` arguments must not be set. |
||||
|
* |
||||
|
* The `msg` argument contains the message to be sent. |
||||
|
* Depending on its type, different behavior can apply. If `msg` is a `Buffer`, |
||||
|
* any `TypedArray` or a `DataView`, |
||||
|
* the `offset` and `length` specify the offset within the `Buffer` where the |
||||
|
* message begins and the number of bytes in the message, respectively. |
||||
|
* If `msg` is a `String`, then it is automatically converted to a `Buffer` with `'utf8'` encoding. With messages that |
||||
|
* contain multi-byte characters, `offset` and `length` will be calculated with |
||||
|
* respect to `byte length` and not the character position. |
||||
|
* If `msg` is an array, `offset` and `length` must not be specified. |
||||
|
* |
||||
|
* The `address` argument is a string. If the value of `address` is a host name, |
||||
|
* DNS will be used to resolve the address of the host. If `address` is not |
||||
|
* provided or otherwise nullish, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets) will be used by default. |
||||
|
* |
||||
|
* If the socket has not been previously bound with a call to `bind`, the socket |
||||
|
* is assigned a random port number and is bound to the "all interfaces" address |
||||
|
* (`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.) |
||||
|
* |
||||
|
* An optional `callback` function may be specified to as a way of reporting |
||||
|
* DNS errors or for determining when it is safe to reuse the `buf` object. |
||||
|
* DNS lookups delay the time to send for at least one tick of the |
||||
|
* Node.js event loop. |
||||
|
* |
||||
|
* The only way to know for sure that the datagram has been sent is by using a `callback`. If an error occurs and a `callback` is given, the error will be |
||||
|
* passed as the first argument to the `callback`. If a `callback` is not given, |
||||
|
* the error is emitted as an `'error'` event on the `socket` object. |
||||
|
* |
||||
|
* Offset and length are optional but both _must_ be set if either are used. |
||||
|
* They are supported only when the first argument is a `Buffer`, a `TypedArray`, |
||||
|
* or a `DataView`. |
||||
|
* |
||||
|
* This method throws `ERR_SOCKET_BAD_PORT` if called on an unbound socket. |
||||
|
* |
||||
|
* Example of sending a UDP packet to a port on `localhost`; |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dgram from 'node:dgram'; |
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const message = Buffer.from('Some bytes'); |
||||
|
* const client = dgram.createSocket('udp4'); |
||||
|
* client.send(message, 41234, 'localhost', (err) => { |
||||
|
* client.close(); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Example of sending a UDP packet composed of multiple buffers to a port on`127.0.0.1`; |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dgram from 'node:dgram'; |
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const buf1 = Buffer.from('Some '); |
||||
|
* const buf2 = Buffer.from('bytes'); |
||||
|
* const client = dgram.createSocket('udp4'); |
||||
|
* client.send([buf1, buf2], 41234, (err) => { |
||||
|
* client.close(); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Sending multiple buffers might be faster or slower depending on the |
||||
|
* application and operating system. Run benchmarks to |
||||
|
* determine the optimal strategy on a case-by-case basis. Generally speaking, |
||||
|
* however, sending multiple buffers is faster. |
||||
|
* |
||||
|
* Example of sending a UDP packet using a socket connected to a port on `localhost`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dgram from 'node:dgram'; |
||||
|
* import { Buffer } from 'node:buffer'; |
||||
|
* |
||||
|
* const message = Buffer.from('Some bytes'); |
||||
|
* const client = dgram.createSocket('udp4'); |
||||
|
* client.connect(41234, 'localhost', (err) => { |
||||
|
* client.send(message, (err) => { |
||||
|
* client.close(); |
||||
|
* }); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v0.1.99 |
||||
|
* @param msg Message to be sent. |
||||
|
* @param offset Offset in the buffer where the message starts. |
||||
|
* @param length Number of bytes in the message. |
||||
|
* @param port Destination port. |
||||
|
* @param address Destination host name or IP address. |
||||
|
* @param callback Called when the message has been sent. |
||||
|
*/ |
||||
|
send( |
||||
|
msg: string | NodeJS.ArrayBufferView | readonly any[], |
||||
|
port?: number, |
||||
|
address?: string, |
||||
|
callback?: (error: Error | null, bytes: number) => void, |
||||
|
): void; |
||||
|
send( |
||||
|
msg: string | NodeJS.ArrayBufferView | readonly any[], |
||||
|
port?: number, |
||||
|
callback?: (error: Error | null, bytes: number) => void, |
||||
|
): void; |
||||
|
send( |
||||
|
msg: string | NodeJS.ArrayBufferView | readonly any[], |
||||
|
callback?: (error: Error | null, bytes: number) => void, |
||||
|
): void; |
||||
|
send( |
||||
|
msg: string | NodeJS.ArrayBufferView, |
||||
|
offset: number, |
||||
|
length: number, |
||||
|
port?: number, |
||||
|
address?: string, |
||||
|
callback?: (error: Error | null, bytes: number) => void, |
||||
|
): void; |
||||
|
send( |
||||
|
msg: string | NodeJS.ArrayBufferView, |
||||
|
offset: number, |
||||
|
length: number, |
||||
|
port?: number, |
||||
|
callback?: (error: Error | null, bytes: number) => void, |
||||
|
): void; |
||||
|
send( |
||||
|
msg: string | NodeJS.ArrayBufferView, |
||||
|
offset: number, |
||||
|
length: number, |
||||
|
callback?: (error: Error | null, bytes: number) => void, |
||||
|
): void; |
||||
|
/** |
||||
|
* Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP |
||||
|
* packets may be sent to a local interface's broadcast address. |
||||
|
* |
||||
|
* This method throws `EBADF` if called on an unbound socket. |
||||
|
* @since v0.6.9 |
||||
|
*/ |
||||
|
setBroadcast(flag: boolean): void; |
||||
|
/** |
||||
|
* _All references to scope in this section are referring to [IPv6 Zone Indices](https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses), which are defined by [RFC
|
||||
|
* 4007](https://tools.ietf.org/html/rfc4007). In string form, an IP_
|
||||
|
* _with a scope index is written as `'IP%scope'` where scope is an interface name_ |
||||
|
* _or interface number._ |
||||
|
* |
||||
|
* Sets the default outgoing multicast interface of the socket to a chosen |
||||
|
* interface or back to system interface selection. The `multicastInterface` must |
||||
|
* be a valid string representation of an IP from the socket's family. |
||||
|
* |
||||
|
* For IPv4 sockets, this should be the IP configured for the desired physical |
||||
|
* interface. All packets sent to multicast on the socket will be sent on the |
||||
|
* interface determined by the most recent successful use of this call. |
||||
|
* |
||||
|
* For IPv6 sockets, `multicastInterface` should include a scope to indicate the |
||||
|
* interface as in the examples that follow. In IPv6, individual `send` calls can |
||||
|
* also use explicit scope in addresses, so only packets sent to a multicast |
||||
|
* address without specifying an explicit scope are affected by the most recent |
||||
|
* successful use of this call. |
||||
|
* |
||||
|
* This method throws `EBADF` if called on an unbound socket. |
||||
|
* |
||||
|
* #### Example: IPv6 outgoing multicast interface |
||||
|
* |
||||
|
* On most systems, where scope format uses the interface name: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const socket = dgram.createSocket('udp6'); |
||||
|
* |
||||
|
* socket.bind(1234, () => { |
||||
|
* socket.setMulticastInterface('::%eth1'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* On Windows, where scope format uses an interface number: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const socket = dgram.createSocket('udp6'); |
||||
|
* |
||||
|
* socket.bind(1234, () => { |
||||
|
* socket.setMulticastInterface('::%2'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* #### Example: IPv4 outgoing multicast interface |
||||
|
* |
||||
|
* All systems use an IP of the host on the desired physical interface: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const socket = dgram.createSocket('udp4'); |
||||
|
* |
||||
|
* socket.bind(1234, () => { |
||||
|
* socket.setMulticastInterface('10.0.0.2'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v8.6.0 |
||||
|
*/ |
||||
|
setMulticastInterface(multicastInterface: string): void; |
||||
|
/** |
||||
|
* Sets or clears the `IP_MULTICAST_LOOP` socket option. When set to `true`, |
||||
|
* multicast packets will also be received on the local interface. |
||||
|
* |
||||
|
* This method throws `EBADF` if called on an unbound socket. |
||||
|
* @since v0.3.8 |
||||
|
*/ |
||||
|
setMulticastLoopback(flag: boolean): boolean; |
||||
|
/** |
||||
|
* Sets the `IP_MULTICAST_TTL` socket option. While TTL generally stands for |
||||
|
* "Time to Live", in this context it specifies the number of IP hops that a |
||||
|
* packet is allowed to travel through, specifically for multicast traffic. Each |
||||
|
* router or gateway that forwards a packet decrements the TTL. If the TTL is |
||||
|
* decremented to 0 by a router, it will not be forwarded. |
||||
|
* |
||||
|
* The `ttl` argument may be between 0 and 255\. The default on most systems is `1`. |
||||
|
* |
||||
|
* This method throws `EBADF` if called on an unbound socket. |
||||
|
* @since v0.3.8 |
||||
|
*/ |
||||
|
setMulticastTTL(ttl: number): number; |
||||
|
/** |
||||
|
* Sets the `SO_RCVBUF` socket option. Sets the maximum socket receive buffer |
||||
|
* in bytes. |
||||
|
* |
||||
|
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket. |
||||
|
* @since v8.7.0 |
||||
|
*/ |
||||
|
setRecvBufferSize(size: number): void; |
||||
|
/** |
||||
|
* Sets the `SO_SNDBUF` socket option. Sets the maximum socket send buffer |
||||
|
* in bytes. |
||||
|
* |
||||
|
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket. |
||||
|
* @since v8.7.0 |
||||
|
*/ |
||||
|
setSendBufferSize(size: number): void; |
||||
|
/** |
||||
|
* Sets the `IP_TTL` socket option. While TTL generally stands for "Time to Live", |
||||
|
* in this context it specifies the number of IP hops that a packet is allowed to |
||||
|
* travel through. Each router or gateway that forwards a packet decrements the |
||||
|
* TTL. If the TTL is decremented to 0 by a router, it will not be forwarded. |
||||
|
* Changing TTL values is typically done for network probes or when multicasting. |
||||
|
* |
||||
|
* The `ttl` argument may be between 1 and 255\. The default on most systems |
||||
|
* is 64. |
||||
|
* |
||||
|
* This method throws `EBADF` if called on an unbound socket. |
||||
|
* @since v0.1.101 |
||||
|
*/ |
||||
|
setTTL(ttl: number): number; |
||||
|
/** |
||||
|
* By default, binding a socket will cause it to block the Node.js process from |
||||
|
* exiting as long as the socket is open. The `socket.unref()` method can be used |
||||
|
* to exclude the socket from the reference counting that keeps the Node.js |
||||
|
* process active, allowing the process to exit even if the socket is still |
||||
|
* listening. |
||||
|
* |
||||
|
* Calling `socket.unref()` multiple times will have no additional effect. |
||||
|
* |
||||
|
* The `socket.unref()` method returns a reference to the socket so calls can be |
||||
|
* chained. |
||||
|
* @since v0.9.1 |
||||
|
*/ |
||||
|
unref(): this; |
||||
|
/** |
||||
|
* Tells the kernel to join a source-specific multicast channel at the given `sourceAddress` and `groupAddress`, using the `multicastInterface` with the `IP_ADD_SOURCE_MEMBERSHIP` socket |
||||
|
* option. If the `multicastInterface` argument |
||||
|
* is not specified, the operating system will choose one interface and will add |
||||
|
* membership to it. To add membership to every available interface, call `socket.addSourceSpecificMembership()` multiple times, once per interface. |
||||
|
* |
||||
|
* When called on an unbound socket, this method will implicitly bind to a random |
||||
|
* port, listening on all interfaces. |
||||
|
* @since v13.1.0, v12.16.0 |
||||
|
*/ |
||||
|
addSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void; |
||||
|
/** |
||||
|
* Instructs the kernel to leave a source-specific multicast channel at the given `sourceAddress` and `groupAddress` using the `IP_DROP_SOURCE_MEMBERSHIP` socket option. This method is |
||||
|
* automatically called by the kernel when the |
||||
|
* socket is closed or the process terminates, so most apps will never have |
||||
|
* reason to call this. |
||||
|
* |
||||
|
* If `multicastInterface` is not specified, the operating system will attempt to |
||||
|
* drop membership on all valid interfaces. |
||||
|
* @since v13.1.0, v12.16.0 |
||||
|
*/ |
||||
|
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void; |
||||
|
/** |
||||
|
* events.EventEmitter |
||||
|
* 1. close |
||||
|
* 2. connect |
||||
|
* 3. error |
||||
|
* 4. listening |
||||
|
* 5. message |
||||
|
*/ |
||||
|
addListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
addListener(event: "close", listener: () => void): this; |
||||
|
addListener(event: "connect", listener: () => void): this; |
||||
|
addListener(event: "error", listener: (err: Error) => void): this; |
||||
|
addListener(event: "listening", listener: () => void): this; |
||||
|
addListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; |
||||
|
emit(event: string | symbol, ...args: any[]): boolean; |
||||
|
emit(event: "close"): boolean; |
||||
|
emit(event: "connect"): boolean; |
||||
|
emit(event: "error", err: Error): boolean; |
||||
|
emit(event: "listening"): boolean; |
||||
|
emit(event: "message", msg: Buffer, rinfo: RemoteInfo): boolean; |
||||
|
on(event: string, listener: (...args: any[]) => void): this; |
||||
|
on(event: "close", listener: () => void): this; |
||||
|
on(event: "connect", listener: () => void): this; |
||||
|
on(event: "error", listener: (err: Error) => void): this; |
||||
|
on(event: "listening", listener: () => void): this; |
||||
|
on(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; |
||||
|
once(event: string, listener: (...args: any[]) => void): this; |
||||
|
once(event: "close", listener: () => void): this; |
||||
|
once(event: "connect", listener: () => void): this; |
||||
|
once(event: "error", listener: (err: Error) => void): this; |
||||
|
once(event: "listening", listener: () => void): this; |
||||
|
once(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; |
||||
|
prependListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependListener(event: "close", listener: () => void): this; |
||||
|
prependListener(event: "connect", listener: () => void): this; |
||||
|
prependListener(event: "error", listener: (err: Error) => void): this; |
||||
|
prependListener(event: "listening", listener: () => void): this; |
||||
|
prependListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; |
||||
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependOnceListener(event: "close", listener: () => void): this; |
||||
|
prependOnceListener(event: "connect", listener: () => void): this; |
||||
|
prependOnceListener(event: "error", listener: (err: Error) => void): this; |
||||
|
prependOnceListener(event: "listening", listener: () => void): this; |
||||
|
prependOnceListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this; |
||||
|
/** |
||||
|
* Calls `socket.close()` and returns a promise that fulfills when the socket has closed. |
||||
|
* @since v20.5.0 |
||||
|
*/ |
||||
|
[Symbol.asyncDispose](): Promise<void>; |
||||
|
} |
||||
|
} |
||||
|
declare module "node:dgram" { |
||||
|
export * from "dgram"; |
||||
|
} |
||||
@ -0,0 +1,578 @@ |
|||||
|
/** |
||||
|
* The `node:diagnostics_channel` module provides an API to create named channels |
||||
|
* to report arbitrary message data for diagnostics purposes. |
||||
|
* |
||||
|
* It can be accessed using: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* ``` |
||||
|
* |
||||
|
* It is intended that a module writer wanting to report diagnostics messages |
||||
|
* will create one or many top-level channels to report messages through. |
||||
|
* Channels may also be acquired at runtime but it is not encouraged |
||||
|
* due to the additional overhead of doing so. Channels may be exported for |
||||
|
* convenience, but as long as the name is known it can be acquired anywhere. |
||||
|
* |
||||
|
* If you intend for your module to produce diagnostics data for others to |
||||
|
* consume it is recommended that you include documentation of what named |
||||
|
* channels are used along with the shape of the message data. Channel names |
||||
|
* should generally include the module name to avoid collisions with data from |
||||
|
* other modules. |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/diagnostics_channel.js)
|
||||
|
*/ |
||||
|
declare module "diagnostics_channel" { |
||||
|
import { AsyncLocalStorage } from "node:async_hooks"; |
||||
|
/** |
||||
|
* Check if there are active subscribers to the named channel. This is helpful if |
||||
|
* the message you want to send might be expensive to prepare. |
||||
|
* |
||||
|
* This API is optional but helpful when trying to publish messages from very |
||||
|
* performance-sensitive code. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* if (diagnostics_channel.hasSubscribers('my-channel')) { |
||||
|
* // There are subscribers, prepare and publish message
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @param name The channel name |
||||
|
* @return If there are active subscribers |
||||
|
*/ |
||||
|
function hasSubscribers(name: string | symbol): boolean; |
||||
|
/** |
||||
|
* This is the primary entry-point for anyone wanting to publish to a named |
||||
|
* channel. It produces a channel object which is optimized to reduce overhead at |
||||
|
* publish time as much as possible. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* ``` |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @param name The channel name |
||||
|
* @return The named channel object |
||||
|
*/ |
||||
|
function channel(name: string | symbol): Channel; |
||||
|
type ChannelListener = (message: unknown, name: string | symbol) => void; |
||||
|
/** |
||||
|
* Register a message handler to subscribe to this channel. This message handler |
||||
|
* will be run synchronously whenever a message is published to the channel. Any |
||||
|
* errors thrown in the message handler will trigger an `'uncaughtException'`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* diagnostics_channel.subscribe('my-channel', (message, name) => { |
||||
|
* // Received data
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v18.7.0, v16.17.0 |
||||
|
* @param name The channel name |
||||
|
* @param onMessage The handler to receive channel messages |
||||
|
*/ |
||||
|
function subscribe(name: string | symbol, onMessage: ChannelListener): void; |
||||
|
/** |
||||
|
* Remove a message handler previously registered to this channel with {@link subscribe}. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* function onMessage(message, name) { |
||||
|
* // Received data
|
||||
|
* } |
||||
|
* |
||||
|
* diagnostics_channel.subscribe('my-channel', onMessage); |
||||
|
* |
||||
|
* diagnostics_channel.unsubscribe('my-channel', onMessage); |
||||
|
* ``` |
||||
|
* @since v18.7.0, v16.17.0 |
||||
|
* @param name The channel name |
||||
|
* @param onMessage The previous subscribed handler to remove |
||||
|
* @return `true` if the handler was found, `false` otherwise. |
||||
|
*/ |
||||
|
function unsubscribe(name: string | symbol, onMessage: ChannelListener): boolean; |
||||
|
/** |
||||
|
* Creates a `TracingChannel` wrapper for the given `TracingChannel Channels`. If a name is given, the corresponding tracing |
||||
|
* channels will be created in the form of `tracing:${name}:${eventType}` where `eventType` corresponds to the types of `TracingChannel Channels`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channelsByName = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* // or...
|
||||
|
* |
||||
|
* const channelsByCollection = diagnostics_channel.tracingChannel({ |
||||
|
* start: diagnostics_channel.channel('tracing:my-channel:start'), |
||||
|
* end: diagnostics_channel.channel('tracing:my-channel:end'), |
||||
|
* asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'), |
||||
|
* asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'), |
||||
|
* error: diagnostics_channel.channel('tracing:my-channel:error'), |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param nameOrChannels Channel name or object containing all the `TracingChannel Channels` |
||||
|
* @return Collection of channels to trace with |
||||
|
*/ |
||||
|
function tracingChannel< |
||||
|
StoreType = unknown, |
||||
|
ContextType extends object = StoreType extends object ? StoreType : object, |
||||
|
>( |
||||
|
nameOrChannels: string | TracingChannelCollection<StoreType, ContextType>, |
||||
|
): TracingChannel<StoreType, ContextType>; |
||||
|
/** |
||||
|
* The class `Channel` represents an individual named channel within the data |
||||
|
* pipeline. It is used to track subscribers and to publish messages when there |
||||
|
* are subscribers present. It exists as a separate object to avoid channel |
||||
|
* lookups at publish time, enabling very fast publish speeds and allowing |
||||
|
* for heavy use while incurring very minimal cost. Channels are created with {@link channel}, constructing a channel directly |
||||
|
* with `new Channel(name)` is not supported. |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
*/ |
||||
|
class Channel<StoreType = unknown, ContextType = StoreType> { |
||||
|
readonly name: string | symbol; |
||||
|
/** |
||||
|
* Check if there are active subscribers to this channel. This is helpful if |
||||
|
* the message you want to send might be expensive to prepare. |
||||
|
* |
||||
|
* This API is optional but helpful when trying to publish messages from very |
||||
|
* performance-sensitive code. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* if (channel.hasSubscribers) { |
||||
|
* // There are subscribers, prepare and publish message
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
*/ |
||||
|
readonly hasSubscribers: boolean; |
||||
|
private constructor(name: string | symbol); |
||||
|
/** |
||||
|
* Publish a message to any subscribers to the channel. This will trigger |
||||
|
* message handlers synchronously so they will execute within the same context. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* channel.publish({ |
||||
|
* some: 'message', |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @param message The message to send to the channel subscribers |
||||
|
*/ |
||||
|
publish(message: unknown): void; |
||||
|
/** |
||||
|
* Register a message handler to subscribe to this channel. This message handler |
||||
|
* will be run synchronously whenever a message is published to the channel. Any |
||||
|
* errors thrown in the message handler will trigger an `'uncaughtException'`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* channel.subscribe((message, name) => { |
||||
|
* // Received data
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @deprecated Since v18.7.0,v16.17.0 - Use {@link subscribe(name, onMessage)} |
||||
|
* @param onMessage The handler to receive channel messages |
||||
|
*/ |
||||
|
subscribe(onMessage: ChannelListener): void; |
||||
|
/** |
||||
|
* Remove a message handler previously registered to this channel with `channel.subscribe(onMessage)`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* function onMessage(message, name) { |
||||
|
* // Received data
|
||||
|
* } |
||||
|
* |
||||
|
* channel.subscribe(onMessage); |
||||
|
* |
||||
|
* channel.unsubscribe(onMessage); |
||||
|
* ``` |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @deprecated Since v18.7.0,v16.17.0 - Use {@link unsubscribe(name, onMessage)} |
||||
|
* @param onMessage The previous subscribed handler to remove |
||||
|
* @return `true` if the handler was found, `false` otherwise. |
||||
|
*/ |
||||
|
unsubscribe(onMessage: ChannelListener): void; |
||||
|
/** |
||||
|
* When `channel.runStores(context, ...)` is called, the given context data |
||||
|
* will be applied to any store bound to the channel. If the store has already been |
||||
|
* bound the previous `transform` function will be replaced with the new one. |
||||
|
* The `transform` function may be omitted to set the given context data as the |
||||
|
* context directly. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* import { AsyncLocalStorage } from 'node:async_hooks'; |
||||
|
* |
||||
|
* const store = new AsyncLocalStorage(); |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* channel.bindStore(store, (data) => { |
||||
|
* return { data }; |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param store The store to which to bind the context data |
||||
|
* @param transform Transform context data before setting the store context |
||||
|
*/ |
||||
|
bindStore(store: AsyncLocalStorage<StoreType>, transform?: (context: ContextType) => StoreType): void; |
||||
|
/** |
||||
|
* Remove a message handler previously registered to this channel with `channel.bindStore(store)`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* import { AsyncLocalStorage } from 'node:async_hooks'; |
||||
|
* |
||||
|
* const store = new AsyncLocalStorage(); |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* channel.bindStore(store); |
||||
|
* channel.unbindStore(store); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param store The store to unbind from the channel. |
||||
|
* @return `true` if the store was found, `false` otherwise. |
||||
|
*/ |
||||
|
unbindStore(store: AsyncLocalStorage<StoreType>): boolean; |
||||
|
/** |
||||
|
* Applies the given data to any AsyncLocalStorage instances bound to the channel |
||||
|
* for the duration of the given function, then publishes to the channel within |
||||
|
* the scope of that data is applied to the stores. |
||||
|
* |
||||
|
* If a transform function was given to `channel.bindStore(store)` it will be |
||||
|
* applied to transform the message data before it becomes the context value for |
||||
|
* the store. The prior storage context is accessible from within the transform |
||||
|
* function in cases where context linking is required. |
||||
|
* |
||||
|
* The context applied to the store should be accessible in any async code which |
||||
|
* continues from execution which began during the given function, however |
||||
|
* there are some situations in which `context loss` may occur. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* import { AsyncLocalStorage } from 'node:async_hooks'; |
||||
|
* |
||||
|
* const store = new AsyncLocalStorage(); |
||||
|
* |
||||
|
* const channel = diagnostics_channel.channel('my-channel'); |
||||
|
* |
||||
|
* channel.bindStore(store, (message) => { |
||||
|
* const parent = store.getStore(); |
||||
|
* return new Span(message, parent); |
||||
|
* }); |
||||
|
* channel.runStores({ some: 'message' }, () => { |
||||
|
* store.getStore(); // Span({ some: 'message' })
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param context Message to send to subscribers and bind to stores |
||||
|
* @param fn Handler to run within the entered storage context |
||||
|
* @param thisArg The receiver to be used for the function call. |
||||
|
* @param args Optional arguments to pass to the function. |
||||
|
*/ |
||||
|
runStores<ThisArg = any, Args extends any[] = any[], Result = any>( |
||||
|
context: ContextType, |
||||
|
fn: (this: ThisArg, ...args: Args) => Result, |
||||
|
thisArg?: ThisArg, |
||||
|
...args: Args |
||||
|
): Result; |
||||
|
} |
||||
|
interface TracingChannelSubscribers<ContextType extends object> { |
||||
|
start: (message: ContextType) => void; |
||||
|
end: ( |
||||
|
message: ContextType & { |
||||
|
error?: unknown; |
||||
|
result?: unknown; |
||||
|
}, |
||||
|
) => void; |
||||
|
asyncStart: ( |
||||
|
message: ContextType & { |
||||
|
error?: unknown; |
||||
|
result?: unknown; |
||||
|
}, |
||||
|
) => void; |
||||
|
asyncEnd: ( |
||||
|
message: ContextType & { |
||||
|
error?: unknown; |
||||
|
result?: unknown; |
||||
|
}, |
||||
|
) => void; |
||||
|
error: ( |
||||
|
message: ContextType & { |
||||
|
error: unknown; |
||||
|
}, |
||||
|
) => void; |
||||
|
} |
||||
|
interface TracingChannelCollection<StoreType = unknown, ContextType = StoreType> { |
||||
|
start: Channel<StoreType, ContextType>; |
||||
|
end: Channel<StoreType, ContextType>; |
||||
|
asyncStart: Channel<StoreType, ContextType>; |
||||
|
asyncEnd: Channel<StoreType, ContextType>; |
||||
|
error: Channel<StoreType, ContextType>; |
||||
|
} |
||||
|
/** |
||||
|
* The class `TracingChannel` is a collection of `TracingChannel Channels` which |
||||
|
* together express a single traceable action. It is used to formalize and |
||||
|
* simplify the process of producing events for tracing application flow. {@link tracingChannel} is used to construct a `TracingChannel`. As with `Channel` it is recommended to create and reuse a |
||||
|
* single `TracingChannel` at the top-level of the file rather than creating them |
||||
|
* dynamically. |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
*/ |
||||
|
class TracingChannel<StoreType = unknown, ContextType extends object = {}> implements TracingChannelCollection { |
||||
|
start: Channel<StoreType, ContextType>; |
||||
|
end: Channel<StoreType, ContextType>; |
||||
|
asyncStart: Channel<StoreType, ContextType>; |
||||
|
asyncEnd: Channel<StoreType, ContextType>; |
||||
|
error: Channel<StoreType, ContextType>; |
||||
|
/** |
||||
|
* Helper to subscribe a collection of functions to the corresponding channels. |
||||
|
* This is the same as calling `channel.subscribe(onMessage)` on each channel |
||||
|
* individually. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* channels.subscribe({ |
||||
|
* start(message) { |
||||
|
* // Handle start message
|
||||
|
* }, |
||||
|
* end(message) { |
||||
|
* // Handle end message
|
||||
|
* }, |
||||
|
* asyncStart(message) { |
||||
|
* // Handle asyncStart message
|
||||
|
* }, |
||||
|
* asyncEnd(message) { |
||||
|
* // Handle asyncEnd message
|
||||
|
* }, |
||||
|
* error(message) { |
||||
|
* // Handle error message
|
||||
|
* }, |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param subscribers Set of `TracingChannel Channels` subscribers |
||||
|
*/ |
||||
|
subscribe(subscribers: TracingChannelSubscribers<ContextType>): void; |
||||
|
/** |
||||
|
* Helper to unsubscribe a collection of functions from the corresponding channels. |
||||
|
* This is the same as calling `channel.unsubscribe(onMessage)` on each channel |
||||
|
* individually. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* channels.unsubscribe({ |
||||
|
* start(message) { |
||||
|
* // Handle start message
|
||||
|
* }, |
||||
|
* end(message) { |
||||
|
* // Handle end message
|
||||
|
* }, |
||||
|
* asyncStart(message) { |
||||
|
* // Handle asyncStart message
|
||||
|
* }, |
||||
|
* asyncEnd(message) { |
||||
|
* // Handle asyncEnd message
|
||||
|
* }, |
||||
|
* error(message) { |
||||
|
* // Handle error message
|
||||
|
* }, |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param subscribers Set of `TracingChannel Channels` subscribers |
||||
|
* @return `true` if all handlers were successfully unsubscribed, and `false` otherwise. |
||||
|
*/ |
||||
|
unsubscribe(subscribers: TracingChannelSubscribers<ContextType>): void; |
||||
|
/** |
||||
|
* Trace a synchronous function call. This will always produce a `start event` and `end event` around the execution and may produce an `error event` if the given function throws an error. |
||||
|
* This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all |
||||
|
* events should have any bound stores set to match this trace context. |
||||
|
* |
||||
|
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions |
||||
|
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* channels.traceSync(() => { |
||||
|
* // Do something
|
||||
|
* }, { |
||||
|
* some: 'thing', |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param fn Function to wrap a trace around |
||||
|
* @param context Shared object to correlate events through |
||||
|
* @param thisArg The receiver to be used for the function call |
||||
|
* @param args Optional arguments to pass to the function |
||||
|
* @return The return value of the given function |
||||
|
*/ |
||||
|
traceSync<ThisArg = any, Args extends any[] = any[], Result = any>( |
||||
|
fn: (this: ThisArg, ...args: Args) => Result, |
||||
|
context?: ContextType, |
||||
|
thisArg?: ThisArg, |
||||
|
...args: Args |
||||
|
): Result; |
||||
|
/** |
||||
|
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the |
||||
|
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also |
||||
|
* produce an `error event` if the given function throws an error or the |
||||
|
* returned promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all |
||||
|
* events should have any bound stores set to match this trace context. |
||||
|
* |
||||
|
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions |
||||
|
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* channels.tracePromise(async () => { |
||||
|
* // Do something
|
||||
|
* }, { |
||||
|
* some: 'thing', |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param fn Promise-returning function to wrap a trace around |
||||
|
* @param context Shared object to correlate trace events through |
||||
|
* @param thisArg The receiver to be used for the function call |
||||
|
* @param args Optional arguments to pass to the function |
||||
|
* @return Chained from promise returned by the given function |
||||
|
*/ |
||||
|
tracePromise<ThisArg = any, Args extends any[] = any[], Result = any>( |
||||
|
fn: (this: ThisArg, ...args: Args) => Promise<Result>, |
||||
|
context?: ContextType, |
||||
|
thisArg?: ThisArg, |
||||
|
...args: Args |
||||
|
): Promise<Result>; |
||||
|
/** |
||||
|
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the |
||||
|
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or |
||||
|
* the returned |
||||
|
* promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all |
||||
|
* events should have any bound stores set to match this trace context. |
||||
|
* |
||||
|
* The `position` will be -1 by default to indicate the final argument should |
||||
|
* be used as the callback. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* channels.traceCallback((arg1, callback) => { |
||||
|
* // Do something
|
||||
|
* callback(null, 'result'); |
||||
|
* }, 1, { |
||||
|
* some: 'thing', |
||||
|
* }, thisArg, arg1, callback); |
||||
|
* ``` |
||||
|
* |
||||
|
* The callback will also be run with `channel.runStores(context, ...)` which |
||||
|
* enables context loss recovery in some cases. |
||||
|
* |
||||
|
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions |
||||
|
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import diagnostics_channel from 'node:diagnostics_channel'; |
||||
|
* import { AsyncLocalStorage } from 'node:async_hooks'; |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* const myStore = new AsyncLocalStorage(); |
||||
|
* |
||||
|
* // The start channel sets the initial store data to something
|
||||
|
* // and stores that store data value on the trace context object
|
||||
|
* channels.start.bindStore(myStore, (data) => { |
||||
|
* const span = new Span(data); |
||||
|
* data.span = span; |
||||
|
* return span; |
||||
|
* }); |
||||
|
* |
||||
|
* // Then asyncStart can restore from that data it stored previously
|
||||
|
* channels.asyncStart.bindStore(myStore, (data) => { |
||||
|
* return data.span; |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
* @experimental |
||||
|
* @param fn callback using function to wrap a trace around |
||||
|
* @param position Zero-indexed argument position of expected callback |
||||
|
* @param context Shared object to correlate trace events through |
||||
|
* @param thisArg The receiver to be used for the function call |
||||
|
* @param args Optional arguments to pass to the function |
||||
|
* @return The return value of the given function |
||||
|
*/ |
||||
|
traceCallback<ThisArg = any, Args extends any[] = any[], Result = any>( |
||||
|
fn: (this: ThisArg, ...args: Args) => Result, |
||||
|
position?: number, |
||||
|
context?: ContextType, |
||||
|
thisArg?: ThisArg, |
||||
|
...args: Args |
||||
|
): Result; |
||||
|
/** |
||||
|
* `true` if any of the individual channels has a subscriber, `false` if not. |
||||
|
* |
||||
|
* This is a helper method available on a {@link TracingChannel} instance to check |
||||
|
* if any of the [TracingChannel Channels](https://nodejs.org/api/diagnostics_channel.html#tracingchannel-channels) have subscribers.
|
||||
|
* A `true` is returned if any of them have at least one subscriber, a `false` is returned otherwise. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const diagnostics_channel = require('node:diagnostics_channel'); |
||||
|
* |
||||
|
* const channels = diagnostics_channel.tracingChannel('my-channel'); |
||||
|
* |
||||
|
* if (channels.hasSubscribers) { |
||||
|
* // Do something
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v22.0.0, v20.13.0 |
||||
|
*/ |
||||
|
readonly hasSubscribers: boolean; |
||||
|
} |
||||
|
} |
||||
|
declare module "node:diagnostics_channel" { |
||||
|
export * from "diagnostics_channel"; |
||||
|
} |
||||
@ -0,0 +1,918 @@ |
|||||
|
/** |
||||
|
* The `node:dns` module enables name resolution. For example, use it to look up IP |
||||
|
* addresses of host names. |
||||
|
* |
||||
|
* Although named for the [Domain Name System (DNS)](https://en.wikipedia.org/wiki/Domain_Name_System), it does not always use the
|
||||
|
* DNS protocol for lookups. {@link lookup} uses the operating system |
||||
|
* facilities to perform name resolution. It may not need to perform any network |
||||
|
* communication. To perform name resolution the way other applications on the same |
||||
|
* system do, use {@link lookup}. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dns from 'node:dns'; |
||||
|
* |
||||
|
* dns.lookup('example.org', (err, address, family) => { |
||||
|
* console.log('address: %j family: IPv%s', address, family); |
||||
|
* }); |
||||
|
* // address: "93.184.216.34" family: IPv4
|
||||
|
* ``` |
||||
|
* |
||||
|
* All other functions in the `node:dns` module connect to an actual DNS server to |
||||
|
* perform name resolution. They will always use the network to perform DNS |
||||
|
* queries. These functions do not use the same set of configuration files used by {@link lookup} (e.g. `/etc/hosts`). Use these functions to always perform |
||||
|
* DNS queries, bypassing other name-resolution facilities. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dns from 'node:dns'; |
||||
|
* |
||||
|
* dns.resolve4('archive.org', (err, addresses) => { |
||||
|
* if (err) throw err; |
||||
|
* |
||||
|
* console.log(`addresses: ${JSON.stringify(addresses)}`); |
||||
|
* |
||||
|
* addresses.forEach((a) => { |
||||
|
* dns.reverse(a, (err, hostnames) => { |
||||
|
* if (err) { |
||||
|
* throw err; |
||||
|
* } |
||||
|
* console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`); |
||||
|
* }); |
||||
|
* }); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* See the [Implementation considerations section](https://nodejs.org/docs/latest-v24.x/api/dns.html#implementation-considerations) for more information.
|
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/dns.js)
|
||||
|
*/ |
||||
|
declare module "dns" { |
||||
|
import * as dnsPromises from "node:dns/promises"; |
||||
|
// Supported getaddrinfo flags.
|
||||
|
/** |
||||
|
* Limits returned address types to the types of non-loopback addresses configured on the system. For example, IPv4 addresses are |
||||
|
* only returned if the current system has at least one IPv4 address configured. |
||||
|
*/ |
||||
|
export const ADDRCONFIG: number; |
||||
|
/** |
||||
|
* If the IPv6 family was specified, but no IPv6 addresses were found, then return IPv4 mapped IPv6 addresses. It is not supported |
||||
|
* on some operating systems (e.g. FreeBSD 10.1). |
||||
|
*/ |
||||
|
export const V4MAPPED: number; |
||||
|
/** |
||||
|
* If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as |
||||
|
* well as IPv4 mapped IPv6 addresses. |
||||
|
*/ |
||||
|
export const ALL: number; |
||||
|
export interface LookupOptions { |
||||
|
/** |
||||
|
* The record family. Must be `4`, `6`, or `0`. For backward compatibility reasons, `'IPv4'` and `'IPv6'` are interpreted |
||||
|
* as `4` and `6` respectively. The value 0 indicates that either an IPv4 or IPv6 address is returned. If the value `0` is used |
||||
|
* with `{ all: true } (see below)`, both IPv4 and IPv6 addresses are returned. |
||||
|
* @default 0 |
||||
|
*/ |
||||
|
family?: number | "IPv4" | "IPv6" | undefined; |
||||
|
/** |
||||
|
* One or more [supported `getaddrinfo`](https://nodejs.org/docs/latest-v24.x/api/dns.html#supported-getaddrinfo-flags) flags. Multiple flags may be
|
||||
|
* passed by bitwise `OR`ing their values. |
||||
|
*/ |
||||
|
hints?: number | undefined; |
||||
|
/** |
||||
|
* When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address. |
||||
|
* @default false |
||||
|
*/ |
||||
|
all?: boolean | undefined; |
||||
|
/** |
||||
|
* When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted |
||||
|
* by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6 |
||||
|
* addresses before IPv4 addresses. Default value is configurable using |
||||
|
* {@link setDefaultResultOrder} or [`--dns-result-order`](https://nodejs.org/docs/latest-v24.x/api/cli.html#--dns-result-orderorder).
|
||||
|
* @default `verbatim` (addresses are not reordered) |
||||
|
* @since v22.1.0 |
||||
|
*/ |
||||
|
order?: "ipv4first" | "ipv6first" | "verbatim" | undefined; |
||||
|
/** |
||||
|
* When `true`, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4 |
||||
|
* addresses are placed before IPv6 addresses. This option will be deprecated in favor of `order`. When both are specified, |
||||
|
* `order` has higher precedence. New code should only use `order`. Default value is configurable using {@link setDefaultResultOrder} |
||||
|
* @default true (addresses are not reordered) |
||||
|
* @deprecated Please use `order` option |
||||
|
*/ |
||||
|
verbatim?: boolean | undefined; |
||||
|
} |
||||
|
export interface LookupOneOptions extends LookupOptions { |
||||
|
all?: false | undefined; |
||||
|
} |
||||
|
export interface LookupAllOptions extends LookupOptions { |
||||
|
all: true; |
||||
|
} |
||||
|
export interface LookupAddress { |
||||
|
/** |
||||
|
* A string representation of an IPv4 or IPv6 address. |
||||
|
*/ |
||||
|
address: string; |
||||
|
/** |
||||
|
* `4` or `6`, denoting the family of `address`, or `0` if the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a |
||||
|
* bug in the name resolution service used by the operating system. |
||||
|
*/ |
||||
|
family: number; |
||||
|
} |
||||
|
/** |
||||
|
* Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or |
||||
|
* AAAA (IPv6) record. All `option` properties are optional. If `options` is an |
||||
|
* integer, then it must be `4` or `6` – if `options` is `0` or not provided, then |
||||
|
* IPv4 and IPv6 addresses are both returned if found. |
||||
|
* |
||||
|
* With the `all` option set to `true`, the arguments for `callback` change to `(err, addresses)`, with `addresses` being an array of objects with the |
||||
|
* properties `address` and `family`. |
||||
|
* |
||||
|
* On error, `err` is an `Error` object, where `err.code` is the error code. |
||||
|
* Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when |
||||
|
* the host name does not exist but also when the lookup fails in other ways |
||||
|
* such as no available file descriptors. |
||||
|
* |
||||
|
* `dns.lookup()` does not necessarily have anything to do with the DNS protocol. |
||||
|
* The implementation uses an operating system facility that can associate names |
||||
|
* with addresses and vice versa. This implementation can have subtle but |
||||
|
* important consequences on the behavior of any Node.js program. Please take some |
||||
|
* time to consult the [Implementation considerations section](https://nodejs.org/docs/latest-v24.x/api/dns.html#implementation-considerations)
|
||||
|
* before using `dns.lookup()`. |
||||
|
* |
||||
|
* Example usage: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dns from 'node:dns'; |
||||
|
* const options = { |
||||
|
* family: 6, |
||||
|
* hints: dns.ADDRCONFIG | dns.V4MAPPED, |
||||
|
* }; |
||||
|
* dns.lookup('example.com', options, (err, address, family) => |
||||
|
* console.log('address: %j family: IPv%s', address, family)); |
||||
|
* // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
|
||||
|
* |
||||
|
* // When options.all is true, the result will be an Array.
|
||||
|
* options.all = true; |
||||
|
* dns.lookup('example.com', options, (err, addresses) => |
||||
|
* console.log('addresses: %j', addresses)); |
||||
|
* // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
|
||||
|
* ``` |
||||
|
* |
||||
|
* If this method is invoked as its [util.promisify()](https://nodejs.org/docs/latest-v24.x/api/util.html#utilpromisifyoriginal) ed
|
||||
|
* version, and `all` is not set to `true`, it returns a `Promise` for an `Object` with `address` and `family` properties. |
||||
|
* @since v0.1.90 |
||||
|
*/ |
||||
|
export function lookup( |
||||
|
hostname: string, |
||||
|
family: number, |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void, |
||||
|
): void; |
||||
|
export function lookup( |
||||
|
hostname: string, |
||||
|
options: LookupOneOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void, |
||||
|
): void; |
||||
|
export function lookup( |
||||
|
hostname: string, |
||||
|
options: LookupAllOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void, |
||||
|
): void; |
||||
|
export function lookup( |
||||
|
hostname: string, |
||||
|
options: LookupOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family: number) => void, |
||||
|
): void; |
||||
|
export function lookup( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void, |
||||
|
): void; |
||||
|
export namespace lookup { |
||||
|
function __promisify__(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>; |
||||
|
function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<LookupAddress>; |
||||
|
function __promisify__(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Resolves the given `address` and `port` into a host name and service using |
||||
|
* the operating system's underlying `getnameinfo` implementation. |
||||
|
* |
||||
|
* If `address` is not a valid IP address, a `TypeError` will be thrown. |
||||
|
* The `port` will be coerced to a number. If it is not a legal port, a `TypeError` will be thrown. |
||||
|
* |
||||
|
* On an error, `err` is an [`Error`](https://nodejs.org/docs/latest-v24.x/api/errors.html#class-error) object,
|
||||
|
* where `err.code` is the error code. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dns from 'node:dns'; |
||||
|
* dns.lookupService('127.0.0.1', 22, (err, hostname, service) => { |
||||
|
* console.log(hostname, service); |
||||
|
* // Prints: localhost ssh
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* If this method is invoked as its [util.promisify()](https://nodejs.org/docs/latest-v24.x/api/util.html#utilpromisifyoriginal) ed
|
||||
|
* version, it returns a `Promise` for an `Object` with `hostname` and `service` properties. |
||||
|
* @since v0.11.14 |
||||
|
*/ |
||||
|
export function lookupService( |
||||
|
address: string, |
||||
|
port: number, |
||||
|
callback: (err: NodeJS.ErrnoException | null, hostname: string, service: string) => void, |
||||
|
): void; |
||||
|
export namespace lookupService { |
||||
|
function __promisify__( |
||||
|
address: string, |
||||
|
port: number, |
||||
|
): Promise<{ |
||||
|
hostname: string; |
||||
|
service: string; |
||||
|
}>; |
||||
|
} |
||||
|
export interface ResolveOptions { |
||||
|
ttl: boolean; |
||||
|
} |
||||
|
export interface ResolveWithTtlOptions extends ResolveOptions { |
||||
|
ttl: true; |
||||
|
} |
||||
|
export interface RecordWithTtl { |
||||
|
address: string; |
||||
|
ttl: number; |
||||
|
} |
||||
|
/** @deprecated Use `AnyARecord` or `AnyAaaaRecord` instead. */ |
||||
|
export type AnyRecordWithTtl = AnyARecord | AnyAaaaRecord; |
||||
|
export interface AnyARecord extends RecordWithTtl { |
||||
|
type: "A"; |
||||
|
} |
||||
|
export interface AnyAaaaRecord extends RecordWithTtl { |
||||
|
type: "AAAA"; |
||||
|
} |
||||
|
export interface CaaRecord { |
||||
|
critical: number; |
||||
|
issue?: string | undefined; |
||||
|
issuewild?: string | undefined; |
||||
|
iodef?: string | undefined; |
||||
|
contactemail?: string | undefined; |
||||
|
contactphone?: string | undefined; |
||||
|
} |
||||
|
export interface AnyCaaRecord extends CaaRecord { |
||||
|
type: "CAA"; |
||||
|
} |
||||
|
export interface MxRecord { |
||||
|
priority: number; |
||||
|
exchange: string; |
||||
|
} |
||||
|
export interface AnyMxRecord extends MxRecord { |
||||
|
type: "MX"; |
||||
|
} |
||||
|
export interface NaptrRecord { |
||||
|
flags: string; |
||||
|
service: string; |
||||
|
regexp: string; |
||||
|
replacement: string; |
||||
|
order: number; |
||||
|
preference: number; |
||||
|
} |
||||
|
export interface AnyNaptrRecord extends NaptrRecord { |
||||
|
type: "NAPTR"; |
||||
|
} |
||||
|
export interface SoaRecord { |
||||
|
nsname: string; |
||||
|
hostmaster: string; |
||||
|
serial: number; |
||||
|
refresh: number; |
||||
|
retry: number; |
||||
|
expire: number; |
||||
|
minttl: number; |
||||
|
} |
||||
|
export interface AnySoaRecord extends SoaRecord { |
||||
|
type: "SOA"; |
||||
|
} |
||||
|
export interface SrvRecord { |
||||
|
priority: number; |
||||
|
weight: number; |
||||
|
port: number; |
||||
|
name: string; |
||||
|
} |
||||
|
export interface AnySrvRecord extends SrvRecord { |
||||
|
type: "SRV"; |
||||
|
} |
||||
|
export interface TlsaRecord { |
||||
|
certUsage: number; |
||||
|
selector: number; |
||||
|
match: number; |
||||
|
data: ArrayBuffer; |
||||
|
} |
||||
|
export interface AnyTlsaRecord extends TlsaRecord { |
||||
|
type: "TLSA"; |
||||
|
} |
||||
|
export interface AnyTxtRecord { |
||||
|
type: "TXT"; |
||||
|
entries: string[]; |
||||
|
} |
||||
|
export interface AnyNsRecord { |
||||
|
type: "NS"; |
||||
|
value: string; |
||||
|
} |
||||
|
export interface AnyPtrRecord { |
||||
|
type: "PTR"; |
||||
|
value: string; |
||||
|
} |
||||
|
export interface AnyCnameRecord { |
||||
|
type: "CNAME"; |
||||
|
value: string; |
||||
|
} |
||||
|
export type AnyRecord = |
||||
|
| AnyARecord |
||||
|
| AnyAaaaRecord |
||||
|
| AnyCaaRecord |
||||
|
| AnyCnameRecord |
||||
|
| AnyMxRecord |
||||
|
| AnyNaptrRecord |
||||
|
| AnyNsRecord |
||||
|
| AnyPtrRecord |
||||
|
| AnySoaRecord |
||||
|
| AnySrvRecord |
||||
|
| AnyTlsaRecord |
||||
|
| AnyTxtRecord; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array |
||||
|
* of the resource records. The `callback` function has arguments `(err, records)`. When successful, `records` will be an array of resource |
||||
|
* records. The type and structure of individual results varies based on `rrtype`: |
||||
|
* |
||||
|
* <omitted> |
||||
|
* |
||||
|
* On error, `err` is an [`Error`](https://nodejs.org/docs/latest-v24.x/api/errors.html#class-error) object,
|
||||
|
* where `err.code` is one of the `DNS error codes`. |
||||
|
* @since v0.1.27 |
||||
|
* @param hostname Host name to resolve. |
||||
|
* @param [rrtype='A'] Resource record type. |
||||
|
*/ |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "A" | "AAAA" | "CNAME" | "NS" | "PTR", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "ANY", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "CAA", |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: CaaRecord[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "MX", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "NAPTR", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "SOA", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: SoaRecord) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "SRV", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "TLSA", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: TlsaRecord[]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: "TXT", |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void, |
||||
|
): void; |
||||
|
export function resolve( |
||||
|
hostname: string, |
||||
|
rrtype: string, |
||||
|
callback: ( |
||||
|
err: NodeJS.ErrnoException | null, |
||||
|
addresses: |
||||
|
| string[] |
||||
|
| CaaRecord[] |
||||
|
| MxRecord[] |
||||
|
| NaptrRecord[] |
||||
|
| SoaRecord |
||||
|
| SrvRecord[] |
||||
|
| TlsaRecord[] |
||||
|
| string[][] |
||||
|
| AnyRecord[], |
||||
|
) => void, |
||||
|
): void; |
||||
|
export namespace resolve { |
||||
|
function __promisify__(hostname: string, rrtype?: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "MX"): Promise<MxRecord[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "SOA"): Promise<SoaRecord>; |
||||
|
function __promisify__(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "TLSA"): Promise<TlsaRecord[]>; |
||||
|
function __promisify__(hostname: string, rrtype: "TXT"): Promise<string[][]>; |
||||
|
function __promisify__( |
||||
|
hostname: string, |
||||
|
rrtype: string, |
||||
|
): Promise< |
||||
|
| string[] |
||||
|
| CaaRecord[] |
||||
|
| MxRecord[] |
||||
|
| NaptrRecord[] |
||||
|
| SoaRecord |
||||
|
| SrvRecord[] |
||||
|
| TlsaRecord[] |
||||
|
| string[][] |
||||
|
| AnyRecord[] |
||||
|
>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the `hostname`. The `addresses` argument passed to the `callback` function |
||||
|
* will contain an array of IPv4 addresses (e.g.`['74.125.79.104', '74.125.79.105', '74.125.79.106']`). |
||||
|
* @since v0.1.16 |
||||
|
* @param hostname Host name to resolve. |
||||
|
*/ |
||||
|
export function resolve4( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export function resolve4( |
||||
|
hostname: string, |
||||
|
options: ResolveWithTtlOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void, |
||||
|
): void; |
||||
|
export function resolve4( |
||||
|
hostname: string, |
||||
|
options: ResolveOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void, |
||||
|
): void; |
||||
|
export namespace resolve4 { |
||||
|
function __promisify__(hostname: string): Promise<string[]>; |
||||
|
function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>; |
||||
|
function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the `hostname`. The `addresses` argument passed to the `callback` function |
||||
|
* will contain an array of IPv6 addresses. |
||||
|
* @since v0.1.16 |
||||
|
* @param hostname Host name to resolve. |
||||
|
*/ |
||||
|
export function resolve6( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export function resolve6( |
||||
|
hostname: string, |
||||
|
options: ResolveWithTtlOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void, |
||||
|
): void; |
||||
|
export function resolve6( |
||||
|
hostname: string, |
||||
|
options: ResolveOptions, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void, |
||||
|
): void; |
||||
|
export namespace resolve6 { |
||||
|
function __promisify__(hostname: string): Promise<string[]>; |
||||
|
function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>; |
||||
|
function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The `addresses` argument passed to the `callback` function |
||||
|
* will contain an array of canonical name records available for the `hostname` (e.g. `['bar.example.com']`). |
||||
|
* @since v0.3.2 |
||||
|
*/ |
||||
|
export function resolveCname( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveCname { |
||||
|
function __promisify__(hostname: string): Promise<string[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve `CAA` records for the `hostname`. The `addresses` argument passed to the `callback` function |
||||
|
* will contain an array of certification authority authorization records |
||||
|
* available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]`). |
||||
|
* @since v15.0.0, v14.17.0 |
||||
|
*/ |
||||
|
export function resolveCaa( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, records: CaaRecord[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveCaa { |
||||
|
function __promisify__(hostname: string): Promise<CaaRecord[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve mail exchange records (`MX` records) for the `hostname`. The `addresses` argument passed to the `callback` function will |
||||
|
* contain an array of objects containing both a `priority` and `exchange` property (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`). |
||||
|
* @since v0.1.27 |
||||
|
*/ |
||||
|
export function resolveMx( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveMx { |
||||
|
function __promisify__(hostname: string): Promise<MxRecord[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve regular expression-based records (`NAPTR` records) for the `hostname`. The `addresses` argument passed to the `callback` function will contain an array of |
||||
|
* objects with the following properties: |
||||
|
* |
||||
|
* * `flags` |
||||
|
* * `service` |
||||
|
* * `regexp` |
||||
|
* * `replacement` |
||||
|
* * `order` |
||||
|
* * `preference` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* flags: 's', |
||||
|
* service: 'SIP+D2U', |
||||
|
* regexp: '', |
||||
|
* replacement: '_sip._udp.example.com', |
||||
|
* order: 30, |
||||
|
* preference: 100 |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.9.12 |
||||
|
*/ |
||||
|
export function resolveNaptr( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveNaptr { |
||||
|
function __promisify__(hostname: string): Promise<NaptrRecord[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve name server records (`NS` records) for the `hostname`. The `addresses` argument passed to the `callback` function will |
||||
|
* contain an array of name server records available for `hostname` (e.g. `['ns1.example.com', 'ns2.example.com']`). |
||||
|
* @since v0.1.90 |
||||
|
*/ |
||||
|
export function resolveNs( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveNs { |
||||
|
function __promisify__(hostname: string): Promise<string[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve pointer records (`PTR` records) for the `hostname`. The `addresses` argument passed to the `callback` function will |
||||
|
* be an array of strings containing the reply records. |
||||
|
* @since v6.0.0 |
||||
|
*/ |
||||
|
export function resolvePtr( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void, |
||||
|
): void; |
||||
|
export namespace resolvePtr { |
||||
|
function __promisify__(hostname: string): Promise<string[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve a start of authority record (`SOA` record) for |
||||
|
* the `hostname`. The `address` argument passed to the `callback` function will |
||||
|
* be an object with the following properties: |
||||
|
* |
||||
|
* * `nsname` |
||||
|
* * `hostmaster` |
||||
|
* * `serial` |
||||
|
* * `refresh` |
||||
|
* * `retry` |
||||
|
* * `expire` |
||||
|
* * `minttl` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* nsname: 'ns.example.com', |
||||
|
* hostmaster: 'root.example.com', |
||||
|
* serial: 2013101809, |
||||
|
* refresh: 10000, |
||||
|
* retry: 2400, |
||||
|
* expire: 604800, |
||||
|
* minttl: 3600 |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.11.10 |
||||
|
*/ |
||||
|
export function resolveSoa( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, address: SoaRecord) => void, |
||||
|
): void; |
||||
|
export namespace resolveSoa { |
||||
|
function __promisify__(hostname: string): Promise<SoaRecord>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve service records (`SRV` records) for the `hostname`. The `addresses` argument passed to the `callback` function will |
||||
|
* be an array of objects with the following properties: |
||||
|
* |
||||
|
* * `priority` |
||||
|
* * `weight` |
||||
|
* * `port` |
||||
|
* * `name` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* priority: 10, |
||||
|
* weight: 5, |
||||
|
* port: 21223, |
||||
|
* name: 'service.example.com' |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.1.27 |
||||
|
*/ |
||||
|
export function resolveSrv( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveSrv { |
||||
|
function __promisify__(hostname: string): Promise<SrvRecord[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve certificate associations (`TLSA` records) for |
||||
|
* the `hostname`. The `records` argument passed to the `callback` function is an |
||||
|
* array of objects with these properties: |
||||
|
* |
||||
|
* * `certUsage` |
||||
|
* * `selector` |
||||
|
* * `match` |
||||
|
* * `data` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* certUsage: 3, |
||||
|
* selector: 1, |
||||
|
* match: 1, |
||||
|
* data: [ArrayBuffer] |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v23.9.0, v22.15.0 |
||||
|
*/ |
||||
|
export function resolveTlsa( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: TlsaRecord[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveTlsa { |
||||
|
function __promisify__(hostname: string): Promise<TlsaRecord[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve text queries (`TXT` records) for the `hostname`. The `records` argument passed to the `callback` function is a |
||||
|
* two-dimensional array of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of |
||||
|
* one record. Depending on the use case, these could be either joined together or |
||||
|
* treated separately. |
||||
|
* @since v0.1.27 |
||||
|
*/ |
||||
|
export function resolveTxt( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void, |
||||
|
): void; |
||||
|
export namespace resolveTxt { |
||||
|
function __promisify__(hostname: string): Promise<string[][]>; |
||||
|
} |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query). |
||||
|
* The `ret` argument passed to the `callback` function will be an array containing |
||||
|
* various types of records. Each object has a property `type` that indicates the |
||||
|
* type of the current record. And depending on the `type`, additional properties |
||||
|
* will be present on the object: |
||||
|
* |
||||
|
* <omitted> |
||||
|
* |
||||
|
* Here is an example of the `ret` object passed to the callback: |
||||
|
* |
||||
|
* ```js
|
||||
|
* [ { type: 'A', address: '127.0.0.1', ttl: 299 }, |
||||
|
* { type: 'CNAME', value: 'example.com' }, |
||||
|
* { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 }, |
||||
|
* { type: 'NS', value: 'ns1.example.com' }, |
||||
|
* { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] }, |
||||
|
* { type: 'SOA', |
||||
|
* nsname: 'ns1.example.com', |
||||
|
* hostmaster: 'admin.example.com', |
||||
|
* serial: 156696742, |
||||
|
* refresh: 900, |
||||
|
* retry: 900, |
||||
|
* expire: 1800, |
||||
|
* minttl: 60 } ] |
||||
|
* ``` |
||||
|
* |
||||
|
* DNS server operators may choose not to respond to `ANY` queries. It may be better to call individual methods like {@link resolve4}, {@link resolveMx}, and so on. For more details, see |
||||
|
* [RFC 8482](https://tools.ietf.org/html/rfc8482).
|
||||
|
*/ |
||||
|
export function resolveAny( |
||||
|
hostname: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void, |
||||
|
): void; |
||||
|
export namespace resolveAny { |
||||
|
function __promisify__(hostname: string): Promise<AnyRecord[]>; |
||||
|
} |
||||
|
/** |
||||
|
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an |
||||
|
* array of host names. |
||||
|
* |
||||
|
* On error, `err` is an [`Error`](https://nodejs.org/docs/latest-v24.x/api/errors.html#class-error) object, where `err.code` is
|
||||
|
* one of the [DNS error codes](https://nodejs.org/docs/latest-v24.x/api/dns.html#error-codes).
|
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
export function reverse( |
||||
|
ip: string, |
||||
|
callback: (err: NodeJS.ErrnoException | null, hostnames: string[]) => void, |
||||
|
): void; |
||||
|
/** |
||||
|
* Get the default value for `order` in {@link lookup} and [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v24.x/api/dns.html#dnspromiseslookuphostname-options).
|
||||
|
* The value could be: |
||||
|
* |
||||
|
* * `ipv4first`: for `order` defaulting to `ipv4first`. |
||||
|
* * `ipv6first`: for `order` defaulting to `ipv6first`. |
||||
|
* * `verbatim`: for `order` defaulting to `verbatim`. |
||||
|
* @since v18.17.0 |
||||
|
*/ |
||||
|
export function getDefaultResultOrder(): "ipv4first" | "ipv6first" | "verbatim"; |
||||
|
/** |
||||
|
* Sets the IP address and port of servers to be used when performing DNS |
||||
|
* resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
|
||||
|
* addresses. If the port is the IANA default DNS port (53) it can be omitted. |
||||
|
* |
||||
|
* ```js
|
||||
|
* dns.setServers([ |
||||
|
* '4.4.4.4', |
||||
|
* '[2001:4860:4860::8888]', |
||||
|
* '4.4.4.4:1053', |
||||
|
* '[2001:4860:4860::8888]:1053', |
||||
|
* ]); |
||||
|
* ``` |
||||
|
* |
||||
|
* An error will be thrown if an invalid address is provided. |
||||
|
* |
||||
|
* The `dns.setServers()` method must not be called while a DNS query is in |
||||
|
* progress. |
||||
|
* |
||||
|
* The {@link setServers} method affects only {@link resolve}, `dns.resolve*()` and {@link reverse} (and specifically _not_ {@link lookup}). |
||||
|
* |
||||
|
* This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
|
||||
|
* That is, if attempting to resolve with the first server provided results in a `NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with |
||||
|
* subsequent servers provided. Fallback DNS servers will only be used if the |
||||
|
* earlier ones time out or result in some other error. |
||||
|
* @since v0.11.3 |
||||
|
* @param servers array of [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952#section-6) formatted addresses
|
||||
|
*/ |
||||
|
export function setServers(servers: readonly string[]): void; |
||||
|
/** |
||||
|
* Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
|
||||
|
* that are currently configured for DNS resolution. A string will include a port |
||||
|
* section if a custom port is used. |
||||
|
* |
||||
|
* ```js
|
||||
|
* [ |
||||
|
* '4.4.4.4', |
||||
|
* '2001:4860:4860::8888', |
||||
|
* '4.4.4.4:1053', |
||||
|
* '[2001:4860:4860::8888]:1053', |
||||
|
* ] |
||||
|
* ``` |
||||
|
* @since v0.11.3 |
||||
|
*/ |
||||
|
export function getServers(): string[]; |
||||
|
/** |
||||
|
* Set the default value of `order` in {@link lookup} and [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v24.x/api/dns.html#dnspromiseslookuphostname-options).
|
||||
|
* The value could be: |
||||
|
* |
||||
|
* * `ipv4first`: sets default `order` to `ipv4first`. |
||||
|
* * `ipv6first`: sets default `order` to `ipv6first`. |
||||
|
* * `verbatim`: sets default `order` to `verbatim`. |
||||
|
* |
||||
|
* The default is `verbatim` and {@link setDefaultResultOrder} have higher |
||||
|
* priority than [`--dns-result-order`](https://nodejs.org/docs/latest-v24.x/api/cli.html#--dns-result-orderorder). When using
|
||||
|
* [worker threads](https://nodejs.org/docs/latest-v24.x/api/worker_threads.html), {@link setDefaultResultOrder} from the main
|
||||
|
* thread won't affect the default dns orders in workers. |
||||
|
* @since v16.4.0, v14.18.0 |
||||
|
* @param order must be `'ipv4first'`, `'ipv6first'` or `'verbatim'`. |
||||
|
*/ |
||||
|
export function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void; |
||||
|
// Error codes
|
||||
|
export const NODATA: "ENODATA"; |
||||
|
export const FORMERR: "EFORMERR"; |
||||
|
export const SERVFAIL: "ESERVFAIL"; |
||||
|
export const NOTFOUND: "ENOTFOUND"; |
||||
|
export const NOTIMP: "ENOTIMP"; |
||||
|
export const REFUSED: "EREFUSED"; |
||||
|
export const BADQUERY: "EBADQUERY"; |
||||
|
export const BADNAME: "EBADNAME"; |
||||
|
export const BADFAMILY: "EBADFAMILY"; |
||||
|
export const BADRESP: "EBADRESP"; |
||||
|
export const CONNREFUSED: "ECONNREFUSED"; |
||||
|
export const TIMEOUT: "ETIMEOUT"; |
||||
|
export const EOF: "EOF"; |
||||
|
export const FILE: "EFILE"; |
||||
|
export const NOMEM: "ENOMEM"; |
||||
|
export const DESTRUCTION: "EDESTRUCTION"; |
||||
|
export const BADSTR: "EBADSTR"; |
||||
|
export const BADFLAGS: "EBADFLAGS"; |
||||
|
export const NONAME: "ENONAME"; |
||||
|
export const BADHINTS: "EBADHINTS"; |
||||
|
export const NOTINITIALIZED: "ENOTINITIALIZED"; |
||||
|
export const LOADIPHLPAPI: "ELOADIPHLPAPI"; |
||||
|
export const ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS"; |
||||
|
export const CANCELLED: "ECANCELLED"; |
||||
|
export interface ResolverOptions { |
||||
|
/** |
||||
|
* Query timeout in milliseconds, or `-1` to use the default timeout. |
||||
|
*/ |
||||
|
timeout?: number | undefined; |
||||
|
/** |
||||
|
* The number of tries the resolver will try contacting each name server before giving up. |
||||
|
* @default 4 |
||||
|
*/ |
||||
|
tries?: number; |
||||
|
} |
||||
|
/** |
||||
|
* An independent resolver for DNS requests. |
||||
|
* |
||||
|
* Creating a new resolver uses the default server settings. Setting |
||||
|
* the servers used for a resolver using [`resolver.setServers()`](https://nodejs.org/docs/latest-v24.x/api/dns.html#dnssetserversservers) does not affect
|
||||
|
* other resolvers: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { Resolver } from 'node:dns'; |
||||
|
* const resolver = new Resolver(); |
||||
|
* resolver.setServers(['4.4.4.4']); |
||||
|
* |
||||
|
* // This request will use the server at 4.4.4.4, independent of global settings.
|
||||
|
* resolver.resolve4('example.org', (err, addresses) => { |
||||
|
* // ...
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* The following methods from the `node:dns` module are available: |
||||
|
* |
||||
|
* * `resolver.getServers()` |
||||
|
* * `resolver.resolve()` |
||||
|
* * `resolver.resolve4()` |
||||
|
* * `resolver.resolve6()` |
||||
|
* * `resolver.resolveAny()` |
||||
|
* * `resolver.resolveCaa()` |
||||
|
* * `resolver.resolveCname()` |
||||
|
* * `resolver.resolveMx()` |
||||
|
* * `resolver.resolveNaptr()` |
||||
|
* * `resolver.resolveNs()` |
||||
|
* * `resolver.resolvePtr()` |
||||
|
* * `resolver.resolveSoa()` |
||||
|
* * `resolver.resolveSrv()` |
||||
|
* * `resolver.resolveTxt()` |
||||
|
* * `resolver.reverse()` |
||||
|
* * `resolver.setServers()` |
||||
|
* @since v8.3.0 |
||||
|
*/ |
||||
|
export class Resolver { |
||||
|
constructor(options?: ResolverOptions); |
||||
|
/** |
||||
|
* Cancel all outstanding DNS queries made by this resolver. The corresponding |
||||
|
* callbacks will be called with an error with code `ECANCELLED`. |
||||
|
* @since v8.3.0 |
||||
|
*/ |
||||
|
cancel(): void; |
||||
|
getServers: typeof getServers; |
||||
|
resolve: typeof resolve; |
||||
|
resolve4: typeof resolve4; |
||||
|
resolve6: typeof resolve6; |
||||
|
resolveAny: typeof resolveAny; |
||||
|
resolveCaa: typeof resolveCaa; |
||||
|
resolveCname: typeof resolveCname; |
||||
|
resolveMx: typeof resolveMx; |
||||
|
resolveNaptr: typeof resolveNaptr; |
||||
|
resolveNs: typeof resolveNs; |
||||
|
resolvePtr: typeof resolvePtr; |
||||
|
resolveSoa: typeof resolveSoa; |
||||
|
resolveSrv: typeof resolveSrv; |
||||
|
resolveTlsa: typeof resolveTlsa; |
||||
|
resolveTxt: typeof resolveTxt; |
||||
|
reverse: typeof reverse; |
||||
|
/** |
||||
|
* The resolver instance will send its requests from the specified IP address. |
||||
|
* This allows programs to specify outbound interfaces when used on multi-homed |
||||
|
* systems. |
||||
|
* |
||||
|
* If a v4 or v6 address is not specified, it is set to the default and the |
||||
|
* operating system will choose a local address automatically. |
||||
|
* |
||||
|
* The resolver will use the v4 local address when making requests to IPv4 DNS |
||||
|
* servers, and the v6 local address when making requests to IPv6 DNS servers. |
||||
|
* The `rrtype` of resolution requests has no impact on the local address used. |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @param [ipv4='0.0.0.0'] A string representation of an IPv4 address. |
||||
|
* @param [ipv6='::0'] A string representation of an IPv6 address. |
||||
|
*/ |
||||
|
setLocalAddress(ipv4?: string, ipv6?: string): void; |
||||
|
setServers: typeof setServers; |
||||
|
} |
||||
|
export { dnsPromises as promises }; |
||||
|
} |
||||
|
declare module "node:dns" { |
||||
|
export * from "dns"; |
||||
|
} |
||||
@ -0,0 +1,503 @@ |
|||||
|
/** |
||||
|
* The `dns.promises` API provides an alternative set of asynchronous DNS methods |
||||
|
* that return `Promise` objects rather than using callbacks. The API is accessible |
||||
|
* via `import { promises as dnsPromises } from 'node:dns'` or `import dnsPromises from 'node:dns/promises'`. |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
declare module "dns/promises" { |
||||
|
import { |
||||
|
AnyRecord, |
||||
|
CaaRecord, |
||||
|
LookupAddress, |
||||
|
LookupAllOptions, |
||||
|
LookupOneOptions, |
||||
|
LookupOptions, |
||||
|
MxRecord, |
||||
|
NaptrRecord, |
||||
|
RecordWithTtl, |
||||
|
ResolveOptions, |
||||
|
ResolverOptions, |
||||
|
ResolveWithTtlOptions, |
||||
|
SoaRecord, |
||||
|
SrvRecord, |
||||
|
TlsaRecord, |
||||
|
} from "node:dns"; |
||||
|
/** |
||||
|
* Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
|
||||
|
* that are currently configured for DNS resolution. A string will include a port |
||||
|
* section if a custom port is used. |
||||
|
* |
||||
|
* ```js
|
||||
|
* [ |
||||
|
* '4.4.4.4', |
||||
|
* '2001:4860:4860::8888', |
||||
|
* '4.4.4.4:1053', |
||||
|
* '[2001:4860:4860::8888]:1053', |
||||
|
* ] |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function getServers(): string[]; |
||||
|
/** |
||||
|
* Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or |
||||
|
* AAAA (IPv6) record. All `option` properties are optional. If `options` is an |
||||
|
* integer, then it must be `4` or `6` – if `options` is not provided, then IPv4 |
||||
|
* and IPv6 addresses are both returned if found. |
||||
|
* |
||||
|
* With the `all` option set to `true`, the `Promise` is resolved with `addresses` being an array of objects with the properties `address` and `family`. |
||||
|
* |
||||
|
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code` is the error code.
|
||||
|
* Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when |
||||
|
* the host name does not exist but also when the lookup fails in other ways |
||||
|
* such as no available file descriptors. |
||||
|
* |
||||
|
* [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromiseslookuphostname-options) does not necessarily have anything to do with the DNS
|
||||
|
* protocol. The implementation uses an operating system facility that can |
||||
|
* associate names with addresses and vice versa. This implementation can have |
||||
|
* subtle but important consequences on the behavior of any Node.js program. Please |
||||
|
* take some time to consult the [Implementation considerations section](https://nodejs.org/docs/latest-v20.x/api/dns.html#implementation-considerations) before
|
||||
|
* using `dnsPromises.lookup()`. |
||||
|
* |
||||
|
* Example usage: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import dns from 'node:dns'; |
||||
|
* const dnsPromises = dns.promises; |
||||
|
* const options = { |
||||
|
* family: 6, |
||||
|
* hints: dns.ADDRCONFIG | dns.V4MAPPED, |
||||
|
* }; |
||||
|
* |
||||
|
* dnsPromises.lookup('example.com', options).then((result) => { |
||||
|
* console.log('address: %j family: IPv%s', result.address, result.family); |
||||
|
* // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
|
||||
|
* }); |
||||
|
* |
||||
|
* // When options.all is true, the result will be an Array.
|
||||
|
* options.all = true; |
||||
|
* dnsPromises.lookup('example.com', options).then((result) => { |
||||
|
* console.log('addresses: %j', result); |
||||
|
* // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function lookup(hostname: string, family: number): Promise<LookupAddress>; |
||||
|
function lookup(hostname: string, options: LookupOneOptions): Promise<LookupAddress>; |
||||
|
function lookup(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>; |
||||
|
function lookup(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>; |
||||
|
function lookup(hostname: string): Promise<LookupAddress>; |
||||
|
/** |
||||
|
* Resolves the given `address` and `port` into a host name and service using |
||||
|
* the operating system's underlying `getnameinfo` implementation. |
||||
|
* |
||||
|
* If `address` is not a valid IP address, a `TypeError` will be thrown. |
||||
|
* The `port` will be coerced to a number. If it is not a legal port, a `TypeError` will be thrown. |
||||
|
* |
||||
|
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code` is the error code.
|
||||
|
* |
||||
|
* ```js
|
||||
|
* import dnsPromises from 'node:dns'; |
||||
|
* dnsPromises.lookupService('127.0.0.1', 22).then((result) => { |
||||
|
* console.log(result.hostname, result.service); |
||||
|
* // Prints: localhost ssh
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function lookupService( |
||||
|
address: string, |
||||
|
port: number, |
||||
|
): Promise<{ |
||||
|
hostname: string; |
||||
|
service: string; |
||||
|
}>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array |
||||
|
* of the resource records. When successful, the `Promise` is resolved with an |
||||
|
* array of resource records. The type and structure of individual results vary |
||||
|
* based on `rrtype`: |
||||
|
* |
||||
|
* <omitted> |
||||
|
* |
||||
|
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code`
|
||||
|
* is one of the [DNS error codes](https://nodejs.org/docs/latest-v20.x/api/dns.html#error-codes).
|
||||
|
* @since v10.6.0 |
||||
|
* @param hostname Host name to resolve. |
||||
|
* @param [rrtype='A'] Resource record type. |
||||
|
*/ |
||||
|
function resolve(hostname: string): Promise<string[]>; |
||||
|
function resolve(hostname: string, rrtype: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>; |
||||
|
function resolve(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>; |
||||
|
function resolve(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>; |
||||
|
function resolve(hostname: string, rrtype: "MX"): Promise<MxRecord[]>; |
||||
|
function resolve(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>; |
||||
|
function resolve(hostname: string, rrtype: "SOA"): Promise<SoaRecord>; |
||||
|
function resolve(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>; |
||||
|
function resolve(hostname: string, rrtype: "TLSA"): Promise<TlsaRecord[]>; |
||||
|
function resolve(hostname: string, rrtype: "TXT"): Promise<string[][]>; |
||||
|
function resolve(hostname: string, rrtype: string): Promise< |
||||
|
| string[] |
||||
|
| CaaRecord[] |
||||
|
| MxRecord[] |
||||
|
| NaptrRecord[] |
||||
|
| SoaRecord |
||||
|
| SrvRecord[] |
||||
|
| TlsaRecord[] |
||||
|
| string[][] |
||||
|
| AnyRecord[] |
||||
|
>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve IPv4 addresses (`A` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv4 |
||||
|
* addresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`). |
||||
|
* @since v10.6.0 |
||||
|
* @param hostname Host name to resolve. |
||||
|
*/ |
||||
|
function resolve4(hostname: string): Promise<string[]>; |
||||
|
function resolve4(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>; |
||||
|
function resolve4(hostname: string, options: ResolveOptions): Promise<string[] | RecordWithTtl[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv6 |
||||
|
* addresses. |
||||
|
* @since v10.6.0 |
||||
|
* @param hostname Host name to resolve. |
||||
|
*/ |
||||
|
function resolve6(hostname: string): Promise<string[]>; |
||||
|
function resolve6(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>; |
||||
|
function resolve6(hostname: string, options: ResolveOptions): Promise<string[] | RecordWithTtl[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query). |
||||
|
* On success, the `Promise` is resolved with an array containing various types of |
||||
|
* records. Each object has a property `type` that indicates the type of the |
||||
|
* current record. And depending on the `type`, additional properties will be |
||||
|
* present on the object: |
||||
|
* |
||||
|
* <omitted> |
||||
|
* |
||||
|
* Here is an example of the result object: |
||||
|
* |
||||
|
* ```js
|
||||
|
* [ { type: 'A', address: '127.0.0.1', ttl: 299 }, |
||||
|
* { type: 'CNAME', value: 'example.com' }, |
||||
|
* { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 }, |
||||
|
* { type: 'NS', value: 'ns1.example.com' }, |
||||
|
* { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] }, |
||||
|
* { type: 'SOA', |
||||
|
* nsname: 'ns1.example.com', |
||||
|
* hostmaster: 'admin.example.com', |
||||
|
* serial: 156696742, |
||||
|
* refresh: 900, |
||||
|
* retry: 900, |
||||
|
* expire: 1800, |
||||
|
* minttl: 60 } ] |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveAny(hostname: string): Promise<AnyRecord[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve `CAA` records for the `hostname`. On success, |
||||
|
* the `Promise` is resolved with an array of objects containing available |
||||
|
* certification authority authorization records available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]`). |
||||
|
* @since v15.0.0, v14.17.0 |
||||
|
*/ |
||||
|
function resolveCaa(hostname: string): Promise<CaaRecord[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve `CNAME` records for the `hostname`. On success, |
||||
|
* the `Promise` is resolved with an array of canonical name records available for |
||||
|
* the `hostname` (e.g. `['bar.example.com']`). |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveCname(hostname: string): Promise<string[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve mail exchange records (`MX` records) for the `hostname`. On success, the `Promise` is resolved with an array of objects |
||||
|
* containing both a `priority` and `exchange` property (e.g.`[{priority: 10, exchange: 'mx.example.com'}, ...]`). |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveMx(hostname: string): Promise<MxRecord[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve regular expression-based records (`NAPTR` records) for the `hostname`. On success, the `Promise` is resolved with an array |
||||
|
* of objects with the following properties: |
||||
|
* |
||||
|
* * `flags` |
||||
|
* * `service` |
||||
|
* * `regexp` |
||||
|
* * `replacement` |
||||
|
* * `order` |
||||
|
* * `preference` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* flags: 's', |
||||
|
* service: 'SIP+D2U', |
||||
|
* regexp: '', |
||||
|
* replacement: '_sip._udp.example.com', |
||||
|
* order: 30, |
||||
|
* preference: 100 |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveNaptr(hostname: string): Promise<NaptrRecord[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve name server records (`NS` records) for the `hostname`. On success, the `Promise` is resolved with an array of name server |
||||
|
* records available for `hostname` (e.g.`['ns1.example.com', 'ns2.example.com']`). |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveNs(hostname: string): Promise<string[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve pointer records (`PTR` records) for the `hostname`. On success, the `Promise` is resolved with an array of strings |
||||
|
* containing the reply records. |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolvePtr(hostname: string): Promise<string[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve a start of authority record (`SOA` record) for |
||||
|
* the `hostname`. On success, the `Promise` is resolved with an object with the |
||||
|
* following properties: |
||||
|
* |
||||
|
* * `nsname` |
||||
|
* * `hostmaster` |
||||
|
* * `serial` |
||||
|
* * `refresh` |
||||
|
* * `retry` |
||||
|
* * `expire` |
||||
|
* * `minttl` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* nsname: 'ns.example.com', |
||||
|
* hostmaster: 'root.example.com', |
||||
|
* serial: 2013101809, |
||||
|
* refresh: 10000, |
||||
|
* retry: 2400, |
||||
|
* expire: 604800, |
||||
|
* minttl: 3600 |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveSoa(hostname: string): Promise<SoaRecord>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve service records (`SRV` records) for the `hostname`. On success, the `Promise` is resolved with an array of objects with |
||||
|
* the following properties: |
||||
|
* |
||||
|
* * `priority` |
||||
|
* * `weight` |
||||
|
* * `port` |
||||
|
* * `name` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* priority: 10, |
||||
|
* weight: 5, |
||||
|
* port: 21223, |
||||
|
* name: 'service.example.com' |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveSrv(hostname: string): Promise<SrvRecord[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve certificate associations (`TLSA` records) for |
||||
|
* the `hostname`. On success, the `Promise` is resolved with an array of objectsAdd commentMore actions |
||||
|
* with these properties: |
||||
|
* |
||||
|
* * `certUsage` |
||||
|
* * `selector` |
||||
|
* * `match` |
||||
|
* * `data` |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* certUsage: 3, |
||||
|
* selector: 1, |
||||
|
* match: 1, |
||||
|
* data: [ArrayBuffer] |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v23.9.0, v22.15.0 |
||||
|
*/ |
||||
|
function resolveTlsa(hostname: string): Promise<TlsaRecord[]>; |
||||
|
/** |
||||
|
* Uses the DNS protocol to resolve text queries (`TXT` records) for the `hostname`. On success, the `Promise` is resolved with a two-dimensional array |
||||
|
* of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of |
||||
|
* one record. Depending on the use case, these could be either joined together or |
||||
|
* treated separately. |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function resolveTxt(hostname: string): Promise<string[][]>; |
||||
|
/** |
||||
|
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an |
||||
|
* array of host names. |
||||
|
* |
||||
|
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code`
|
||||
|
* is one of the [DNS error codes](https://nodejs.org/docs/latest-v20.x/api/dns.html#error-codes).
|
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
function reverse(ip: string): Promise<string[]>; |
||||
|
/** |
||||
|
* Get the default value for `verbatim` in {@link lookup} and [dnsPromises.lookup()](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromiseslookuphostname-options).
|
||||
|
* The value could be: |
||||
|
* |
||||
|
* * `ipv4first`: for `verbatim` defaulting to `false`. |
||||
|
* * `verbatim`: for `verbatim` defaulting to `true`. |
||||
|
* @since v20.1.0 |
||||
|
*/ |
||||
|
function getDefaultResultOrder(): "ipv4first" | "verbatim"; |
||||
|
/** |
||||
|
* Sets the IP address and port of servers to be used when performing DNS |
||||
|
* resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
|
||||
|
* addresses. If the port is the IANA default DNS port (53) it can be omitted. |
||||
|
* |
||||
|
* ```js
|
||||
|
* dnsPromises.setServers([ |
||||
|
* '4.4.4.4', |
||||
|
* '[2001:4860:4860::8888]', |
||||
|
* '4.4.4.4:1053', |
||||
|
* '[2001:4860:4860::8888]:1053', |
||||
|
* ]); |
||||
|
* ``` |
||||
|
* |
||||
|
* An error will be thrown if an invalid address is provided. |
||||
|
* |
||||
|
* The `dnsPromises.setServers()` method must not be called while a DNS query is in |
||||
|
* progress. |
||||
|
* |
||||
|
* This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
|
||||
|
* That is, if attempting to resolve with the first server provided results in a `NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with |
||||
|
* subsequent servers provided. Fallback DNS servers will only be used if the |
||||
|
* earlier ones time out or result in some other error. |
||||
|
* @since v10.6.0 |
||||
|
* @param servers array of `RFC 5952` formatted addresses |
||||
|
*/ |
||||
|
function setServers(servers: readonly string[]): void; |
||||
|
/** |
||||
|
* Set the default value of `order` in `dns.lookup()` and `{@link lookup}`. The value could be: |
||||
|
* |
||||
|
* * `ipv4first`: sets default `order` to `ipv4first`. |
||||
|
* * `ipv6first`: sets default `order` to `ipv6first`. |
||||
|
* * `verbatim`: sets default `order` to `verbatim`. |
||||
|
* |
||||
|
* The default is `verbatim` and [dnsPromises.setDefaultResultOrder()](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetdefaultresultorderorder)
|
||||
|
* have higher priority than [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder).
|
||||
|
* When using [worker threads](https://nodejs.org/docs/latest-v20.x/api/worker_threads.html), [`dnsPromises.setDefaultResultOrder()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetdefaultresultorderorder)
|
||||
|
* from the main thread won't affect the default dns orders in workers. |
||||
|
* @since v16.4.0, v14.18.0 |
||||
|
* @param order must be `'ipv4first'`, `'ipv6first'` or `'verbatim'`. |
||||
|
*/ |
||||
|
function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void; |
||||
|
// Error codes
|
||||
|
const NODATA: "ENODATA"; |
||||
|
const FORMERR: "EFORMERR"; |
||||
|
const SERVFAIL: "ESERVFAIL"; |
||||
|
const NOTFOUND: "ENOTFOUND"; |
||||
|
const NOTIMP: "ENOTIMP"; |
||||
|
const REFUSED: "EREFUSED"; |
||||
|
const BADQUERY: "EBADQUERY"; |
||||
|
const BADNAME: "EBADNAME"; |
||||
|
const BADFAMILY: "EBADFAMILY"; |
||||
|
const BADRESP: "EBADRESP"; |
||||
|
const CONNREFUSED: "ECONNREFUSED"; |
||||
|
const TIMEOUT: "ETIMEOUT"; |
||||
|
const EOF: "EOF"; |
||||
|
const FILE: "EFILE"; |
||||
|
const NOMEM: "ENOMEM"; |
||||
|
const DESTRUCTION: "EDESTRUCTION"; |
||||
|
const BADSTR: "EBADSTR"; |
||||
|
const BADFLAGS: "EBADFLAGS"; |
||||
|
const NONAME: "ENONAME"; |
||||
|
const BADHINTS: "EBADHINTS"; |
||||
|
const NOTINITIALIZED: "ENOTINITIALIZED"; |
||||
|
const LOADIPHLPAPI: "ELOADIPHLPAPI"; |
||||
|
const ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS"; |
||||
|
const CANCELLED: "ECANCELLED"; |
||||
|
|
||||
|
/** |
||||
|
* An independent resolver for DNS requests. |
||||
|
* |
||||
|
* Creating a new resolver uses the default server settings. Setting |
||||
|
* the servers used for a resolver using [`resolver.setServers()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetserversservers) does not affect
|
||||
|
* other resolvers: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { promises } from 'node:dns'; |
||||
|
* const resolver = new promises.Resolver(); |
||||
|
* resolver.setServers(['4.4.4.4']); |
||||
|
* |
||||
|
* // This request will use the server at 4.4.4.4, independent of global settings.
|
||||
|
* resolver.resolve4('example.org').then((addresses) => { |
||||
|
* // ...
|
||||
|
* }); |
||||
|
* |
||||
|
* // Alternatively, the same code can be written using async-await style.
|
||||
|
* (async function() { |
||||
|
* const addresses = await resolver.resolve4('example.org'); |
||||
|
* })(); |
||||
|
* ``` |
||||
|
* |
||||
|
* The following methods from the `dnsPromises` API are available: |
||||
|
* |
||||
|
* * `resolver.getServers()` |
||||
|
* * `resolver.resolve()` |
||||
|
* * `resolver.resolve4()` |
||||
|
* * `resolver.resolve6()` |
||||
|
* * `resolver.resolveAny()` |
||||
|
* * `resolver.resolveCaa()` |
||||
|
* * `resolver.resolveCname()` |
||||
|
* * `resolver.resolveMx()` |
||||
|
* * `resolver.resolveNaptr()` |
||||
|
* * `resolver.resolveNs()` |
||||
|
* * `resolver.resolvePtr()` |
||||
|
* * `resolver.resolveSoa()` |
||||
|
* * `resolver.resolveSrv()` |
||||
|
* * `resolver.resolveTxt()` |
||||
|
* * `resolver.reverse()` |
||||
|
* * `resolver.setServers()` |
||||
|
* @since v10.6.0 |
||||
|
*/ |
||||
|
class Resolver { |
||||
|
constructor(options?: ResolverOptions); |
||||
|
/** |
||||
|
* Cancel all outstanding DNS queries made by this resolver. The corresponding |
||||
|
* callbacks will be called with an error with code `ECANCELLED`. |
||||
|
* @since v8.3.0 |
||||
|
*/ |
||||
|
cancel(): void; |
||||
|
getServers: typeof getServers; |
||||
|
resolve: typeof resolve; |
||||
|
resolve4: typeof resolve4; |
||||
|
resolve6: typeof resolve6; |
||||
|
resolveAny: typeof resolveAny; |
||||
|
resolveCaa: typeof resolveCaa; |
||||
|
resolveCname: typeof resolveCname; |
||||
|
resolveMx: typeof resolveMx; |
||||
|
resolveNaptr: typeof resolveNaptr; |
||||
|
resolveNs: typeof resolveNs; |
||||
|
resolvePtr: typeof resolvePtr; |
||||
|
resolveSoa: typeof resolveSoa; |
||||
|
resolveSrv: typeof resolveSrv; |
||||
|
resolveTlsa: typeof resolveTlsa; |
||||
|
resolveTxt: typeof resolveTxt; |
||||
|
reverse: typeof reverse; |
||||
|
/** |
||||
|
* The resolver instance will send its requests from the specified IP address. |
||||
|
* This allows programs to specify outbound interfaces when used on multi-homed |
||||
|
* systems. |
||||
|
* |
||||
|
* If a v4 or v6 address is not specified, it is set to the default and the |
||||
|
* operating system will choose a local address automatically. |
||||
|
* |
||||
|
* The resolver will use the v4 local address when making requests to IPv4 DNS |
||||
|
* servers, and the v6 local address when making requests to IPv6 DNS servers. |
||||
|
* The `rrtype` of resolution requests has no impact on the local address used. |
||||
|
* @since v15.1.0, v14.17.0 |
||||
|
* @param [ipv4='0.0.0.0'] A string representation of an IPv4 address. |
||||
|
* @param [ipv6='::0'] A string representation of an IPv6 address. |
||||
|
*/ |
||||
|
setLocalAddress(ipv4?: string, ipv6?: string): void; |
||||
|
setServers: typeof setServers; |
||||
|
} |
||||
|
} |
||||
|
declare module "node:dns/promises" { |
||||
|
export * from "dns/promises"; |
||||
|
} |
||||
@ -0,0 +1,99 @@ |
|||||
|
// Make this a module
|
||||
|
export {}; |
||||
|
|
||||
|
// Conditional type aliases, which are later merged into the global scope.
|
||||
|
// Will either be empty if the relevant web library is already present, or the @types/node definition otherwise.
|
||||
|
|
||||
|
type __Event = typeof globalThis extends { onmessage: any } ? {} : Event; |
||||
|
interface Event { |
||||
|
readonly bubbles: boolean; |
||||
|
cancelBubble: boolean; |
||||
|
readonly cancelable: boolean; |
||||
|
readonly composed: boolean; |
||||
|
composedPath(): [EventTarget?]; |
||||
|
readonly currentTarget: EventTarget | null; |
||||
|
readonly defaultPrevented: boolean; |
||||
|
readonly eventPhase: 0 | 2; |
||||
|
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void; |
||||
|
readonly isTrusted: boolean; |
||||
|
preventDefault(): void; |
||||
|
readonly returnValue: boolean; |
||||
|
readonly srcElement: EventTarget | null; |
||||
|
stopImmediatePropagation(): void; |
||||
|
stopPropagation(): void; |
||||
|
readonly target: EventTarget | null; |
||||
|
readonly timeStamp: number; |
||||
|
readonly type: string; |
||||
|
} |
||||
|
|
||||
|
type __CustomEvent<T = any> = typeof globalThis extends { onmessage: any } ? {} : CustomEvent<T>; |
||||
|
interface CustomEvent<T = any> extends Event { |
||||
|
readonly detail: T; |
||||
|
} |
||||
|
|
||||
|
type __EventTarget = typeof globalThis extends { onmessage: any } ? {} : EventTarget; |
||||
|
interface EventTarget { |
||||
|
addEventListener( |
||||
|
type: string, |
||||
|
listener: EventListener | EventListenerObject, |
||||
|
options?: AddEventListenerOptions | boolean, |
||||
|
): void; |
||||
|
dispatchEvent(event: Event): boolean; |
||||
|
removeEventListener( |
||||
|
type: string, |
||||
|
listener: EventListener | EventListenerObject, |
||||
|
options?: EventListenerOptions | boolean, |
||||
|
): void; |
||||
|
} |
||||
|
|
||||
|
interface EventInit { |
||||
|
bubbles?: boolean; |
||||
|
cancelable?: boolean; |
||||
|
composed?: boolean; |
||||
|
} |
||||
|
|
||||
|
interface CustomEventInit<T = any> extends EventInit { |
||||
|
detail?: T; |
||||
|
} |
||||
|
|
||||
|
interface EventListenerOptions { |
||||
|
capture?: boolean; |
||||
|
} |
||||
|
|
||||
|
interface AddEventListenerOptions extends EventListenerOptions { |
||||
|
once?: boolean; |
||||
|
passive?: boolean; |
||||
|
signal?: AbortSignal; |
||||
|
} |
||||
|
|
||||
|
interface EventListener { |
||||
|
(evt: Event): void; |
||||
|
} |
||||
|
|
||||
|
interface EventListenerObject { |
||||
|
handleEvent(object: Event): void; |
||||
|
} |
||||
|
|
||||
|
// Merge conditional interfaces into global scope, and conditionally declare global constructors.
|
||||
|
declare global { |
||||
|
interface Event extends __Event {} |
||||
|
var Event: typeof globalThis extends { onmessage: any; Event: infer T } ? T |
||||
|
: { |
||||
|
prototype: Event; |
||||
|
new(type: string, eventInitDict?: EventInit): Event; |
||||
|
}; |
||||
|
|
||||
|
interface CustomEvent<T = any> extends __CustomEvent<T> {} |
||||
|
var CustomEvent: typeof globalThis extends { onmessage: any; CustomEvent: infer T } ? T |
||||
|
: { |
||||
|
prototype: CustomEvent; |
||||
|
new<T>(type: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>; |
||||
|
}; |
||||
|
|
||||
|
interface EventTarget extends __EventTarget {} |
||||
|
var EventTarget: typeof globalThis extends { onmessage: any; EventTarget: infer T } ? T |
||||
|
: { |
||||
|
prototype: EventTarget; |
||||
|
new(): EventTarget; |
||||
|
}; |
||||
|
} |
||||
@ -0,0 +1,170 @@ |
|||||
|
/** |
||||
|
* **This module is pending deprecation.** Once a replacement API has been |
||||
|
* finalized, this module will be fully deprecated. Most developers should |
||||
|
* **not** have cause to use this module. Users who absolutely must have |
||||
|
* the functionality that domains provide may rely on it for the time being |
||||
|
* but should expect to have to migrate to a different solution |
||||
|
* in the future. |
||||
|
* |
||||
|
* Domains provide a way to handle multiple different IO operations as a |
||||
|
* single group. If any of the event emitters or callbacks registered to a |
||||
|
* domain emit an `'error'` event, or throw an error, then the domain object |
||||
|
* will be notified, rather than losing the context of the error in the `process.on('uncaughtException')` handler, or causing the program to |
||||
|
* exit immediately with an error code. |
||||
|
* @deprecated Since v1.4.2 - Deprecated |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/domain.js)
|
||||
|
*/ |
||||
|
declare module "domain" { |
||||
|
import EventEmitter = require("node:events"); |
||||
|
/** |
||||
|
* The `Domain` class encapsulates the functionality of routing errors and |
||||
|
* uncaught exceptions to the active `Domain` object. |
||||
|
* |
||||
|
* To handle the errors that it catches, listen to its `'error'` event. |
||||
|
*/ |
||||
|
class Domain extends EventEmitter { |
||||
|
/** |
||||
|
* An array of timers and event emitters that have been explicitly added |
||||
|
* to the domain. |
||||
|
*/ |
||||
|
members: Array<EventEmitter | NodeJS.Timer>; |
||||
|
/** |
||||
|
* The `enter()` method is plumbing used by the `run()`, `bind()`, and `intercept()` methods to set the active domain. It sets `domain.active` and `process.domain` to the domain, and implicitly |
||||
|
* pushes the domain onto the domain |
||||
|
* stack managed by the domain module (see {@link exit} for details on the |
||||
|
* domain stack). The call to `enter()` delimits the beginning of a chain of |
||||
|
* asynchronous calls and I/O operations bound to a domain. |
||||
|
* |
||||
|
* Calling `enter()` changes only the active domain, and does not alter the domain |
||||
|
* itself. `enter()` and `exit()` can be called an arbitrary number of times on a |
||||
|
* single domain. |
||||
|
*/ |
||||
|
enter(): void; |
||||
|
/** |
||||
|
* The `exit()` method exits the current domain, popping it off the domain stack. |
||||
|
* Any time execution is going to switch to the context of a different chain of |
||||
|
* asynchronous calls, it's important to ensure that the current domain is exited. |
||||
|
* The call to `exit()` delimits either the end of or an interruption to the chain |
||||
|
* of asynchronous calls and I/O operations bound to a domain. |
||||
|
* |
||||
|
* If there are multiple, nested domains bound to the current execution context, `exit()` will exit any domains nested within this domain. |
||||
|
* |
||||
|
* Calling `exit()` changes only the active domain, and does not alter the domain |
||||
|
* itself. `enter()` and `exit()` can be called an arbitrary number of times on a |
||||
|
* single domain. |
||||
|
*/ |
||||
|
exit(): void; |
||||
|
/** |
||||
|
* Run the supplied function in the context of the domain, implicitly |
||||
|
* binding all event emitters, timers, and low-level requests that are |
||||
|
* created in that context. Optionally, arguments can be passed to |
||||
|
* the function. |
||||
|
* |
||||
|
* This is the most basic way to use a domain. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import domain from 'node:domain'; |
||||
|
* import fs from 'node:fs'; |
||||
|
* const d = domain.create(); |
||||
|
* d.on('error', (er) => { |
||||
|
* console.error('Caught error!', er); |
||||
|
* }); |
||||
|
* d.run(() => { |
||||
|
* process.nextTick(() => { |
||||
|
* setTimeout(() => { // Simulating some various async stuff
|
||||
|
* fs.open('non-existent file', 'r', (er, fd) => { |
||||
|
* if (er) throw er; |
||||
|
* // proceed...
|
||||
|
* }); |
||||
|
* }, 100); |
||||
|
* }); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* In this example, the `d.on('error')` handler will be triggered, rather |
||||
|
* than crashing the program. |
||||
|
*/ |
||||
|
run<T>(fn: (...args: any[]) => T, ...args: any[]): T; |
||||
|
/** |
||||
|
* Explicitly adds an emitter to the domain. If any event handlers called by |
||||
|
* the emitter throw an error, or if the emitter emits an `'error'` event, it |
||||
|
* will be routed to the domain's `'error'` event, just like with implicit
|
||||
|
* binding. |
||||
|
* |
||||
|
* This also works with timers that are returned from `setInterval()` and `setTimeout()`. If their callback function throws, it will be caught by |
||||
|
* the domain `'error'` handler. |
||||
|
* |
||||
|
* If the Timer or `EventEmitter` was already bound to a domain, it is removed |
||||
|
* from that one, and bound to this one instead. |
||||
|
* @param emitter emitter or timer to be added to the domain |
||||
|
*/ |
||||
|
add(emitter: EventEmitter | NodeJS.Timer): void; |
||||
|
/** |
||||
|
* The opposite of {@link add}. Removes domain handling from the |
||||
|
* specified emitter. |
||||
|
* @param emitter emitter or timer to be removed from the domain |
||||
|
*/ |
||||
|
remove(emitter: EventEmitter | NodeJS.Timer): void; |
||||
|
/** |
||||
|
* The returned function will be a wrapper around the supplied callback |
||||
|
* function. When the returned function is called, any errors that are |
||||
|
* thrown will be routed to the domain's `'error'` event.
|
||||
|
* |
||||
|
* ```js
|
||||
|
* const d = domain.create(); |
||||
|
* |
||||
|
* function readSomeFile(filename, cb) { |
||||
|
* fs.readFile(filename, 'utf8', d.bind((er, data) => { |
||||
|
* // If this throws, it will also be passed to the domain.
|
||||
|
* return cb(er, data ? JSON.parse(data) : null); |
||||
|
* })); |
||||
|
* } |
||||
|
* |
||||
|
* d.on('error', (er) => { |
||||
|
* // An error occurred somewhere. If we throw it now, it will crash the program
|
||||
|
* // with the normal line number and stack message.
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @param callback The callback function |
||||
|
* @return The bound function |
||||
|
*/ |
||||
|
bind<T extends Function>(callback: T): T; |
||||
|
/** |
||||
|
* This method is almost identical to {@link bind}. However, in |
||||
|
* addition to catching thrown errors, it will also intercept `Error` objects sent as the first argument to the function. |
||||
|
* |
||||
|
* In this way, the common `if (err) return callback(err);` pattern can be replaced |
||||
|
* with a single error handler in a single place. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const d = domain.create(); |
||||
|
* |
||||
|
* function readSomeFile(filename, cb) { |
||||
|
* fs.readFile(filename, 'utf8', d.intercept((data) => { |
||||
|
* // Note, the first argument is never passed to the
|
||||
|
* // callback since it is assumed to be the 'Error' argument
|
||||
|
* // and thus intercepted by the domain.
|
||||
|
* |
||||
|
* // If this throws, it will also be passed to the domain
|
||||
|
* // so the error-handling logic can be moved to the 'error'
|
||||
|
* // event on the domain instead of being repeated throughout
|
||||
|
* // the program.
|
||||
|
* return cb(null, JSON.parse(data)); |
||||
|
* })); |
||||
|
* } |
||||
|
* |
||||
|
* d.on('error', (er) => { |
||||
|
* // An error occurred somewhere. If we throw it now, it will crash the program
|
||||
|
* // with the normal line number and stack message.
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* @param callback The callback function |
||||
|
* @return The intercepted function |
||||
|
*/ |
||||
|
intercept<T extends Function>(callback: T): T; |
||||
|
} |
||||
|
function create(): Domain; |
||||
|
} |
||||
|
declare module "node:domain" { |
||||
|
export * from "domain"; |
||||
|
} |
||||
@ -0,0 +1,930 @@ |
|||||
|
/** |
||||
|
* Much of the Node.js core API is built around an idiomatic asynchronous |
||||
|
* event-driven architecture in which certain kinds of objects (called "emitters") |
||||
|
* emit named events that cause `Function` objects ("listeners") to be called. |
||||
|
* |
||||
|
* For instance: a `net.Server` object emits an event each time a peer |
||||
|
* connects to it; a `fs.ReadStream` emits an event when the file is opened; |
||||
|
* a `stream` emits an event whenever data is available to be read. |
||||
|
* |
||||
|
* All objects that emit events are instances of the `EventEmitter` class. These |
||||
|
* objects expose an `eventEmitter.on()` function that allows one or more |
||||
|
* functions to be attached to named events emitted by the object. Typically, |
||||
|
* event names are camel-cased strings but any valid JavaScript property key |
||||
|
* can be used. |
||||
|
* |
||||
|
* When the `EventEmitter` object emits an event, all of the functions attached |
||||
|
* to that specific event are called _synchronously_. Any values returned by the |
||||
|
* called listeners are _ignored_ and discarded. |
||||
|
* |
||||
|
* The following example shows a simple `EventEmitter` instance with a single |
||||
|
* listener. The `eventEmitter.on()` method is used to register listeners, while |
||||
|
* the `eventEmitter.emit()` method is used to trigger the event. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* |
||||
|
* class MyEmitter extends EventEmitter {} |
||||
|
* |
||||
|
* const myEmitter = new MyEmitter(); |
||||
|
* myEmitter.on('event', () => { |
||||
|
* console.log('an event occurred!'); |
||||
|
* }); |
||||
|
* myEmitter.emit('event'); |
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/events.js)
|
||||
|
*/ |
||||
|
declare module "events" { |
||||
|
import { AsyncResource, AsyncResourceOptions } from "node:async_hooks"; |
||||
|
// NOTE: This class is in the docs but is **not actually exported** by Node.
|
||||
|
// If https://github.com/nodejs/node/issues/39903 gets resolved and Node
|
||||
|
// actually starts exporting the class, uncomment below.
|
||||
|
// import { EventListener, EventListenerObject } from '__dom-events';
|
||||
|
// /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
|
||||
|
// interface NodeEventTarget extends EventTarget {
|
||||
|
// /**
|
||||
|
// * Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API.
|
||||
|
// * The only difference between `addListener()` and `addEventListener()` is that addListener() will return a reference to the EventTarget.
|
||||
|
// */
|
||||
|
// addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
|
||||
|
// /** Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered. */
|
||||
|
// eventNames(): string[];
|
||||
|
// /** Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`. */
|
||||
|
// listenerCount(type: string): number;
|
||||
|
// /** Node.js-specific alias for `eventTarget.removeListener()`. */
|
||||
|
// off(type: string, listener: EventListener | EventListenerObject): this;
|
||||
|
// /** Node.js-specific alias for `eventTarget.addListener()`. */
|
||||
|
// on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
|
||||
|
// /** Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`. */
|
||||
|
// once(type: string, listener: EventListener | EventListenerObject): this;
|
||||
|
// /**
|
||||
|
// * Node.js-specific extension to the `EventTarget` class.
|
||||
|
// * If `type` is specified, removes all registered listeners for `type`,
|
||||
|
// * otherwise removes all registered listeners.
|
||||
|
// */
|
||||
|
// removeAllListeners(type: string): this;
|
||||
|
// /**
|
||||
|
// * Node.js-specific extension to the `EventTarget` class that removes the listener for the given `type`.
|
||||
|
// * The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`.
|
||||
|
// */
|
||||
|
// removeListener(type: string, listener: EventListener | EventListenerObject): this;
|
||||
|
// }
|
||||
|
interface EventEmitterOptions { |
||||
|
/** |
||||
|
* Enables automatic capturing of promise rejection. |
||||
|
*/ |
||||
|
captureRejections?: boolean | undefined; |
||||
|
} |
||||
|
interface StaticEventEmitterOptions { |
||||
|
/** |
||||
|
* Can be used to cancel awaiting events. |
||||
|
*/ |
||||
|
signal?: AbortSignal | undefined; |
||||
|
} |
||||
|
interface StaticEventEmitterIteratorOptions extends StaticEventEmitterOptions { |
||||
|
/** |
||||
|
* Names of events that will end the iteration. |
||||
|
*/ |
||||
|
close?: string[] | undefined; |
||||
|
/** |
||||
|
* The high watermark. The emitter is paused every time the size of events being buffered is higher than it. |
||||
|
* Supported only on emitters implementing `pause()` and `resume()` methods. |
||||
|
* @default Number.MAX_SAFE_INTEGER |
||||
|
*/ |
||||
|
highWaterMark?: number | undefined; |
||||
|
/** |
||||
|
* The low watermark. The emitter is resumed every time the size of events being buffered is lower than it. |
||||
|
* Supported only on emitters implementing `pause()` and `resume()` methods. |
||||
|
* @default 1 |
||||
|
*/ |
||||
|
lowWaterMark?: number | undefined; |
||||
|
} |
||||
|
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {} |
||||
|
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap; |
||||
|
type DefaultEventMap = [never]; |
||||
|
type AnyRest = [...args: any[]]; |
||||
|
type Args<K, T> = T extends DefaultEventMap ? AnyRest : ( |
||||
|
K extends keyof T ? T[K] : never |
||||
|
); |
||||
|
type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T; |
||||
|
type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T; |
||||
|
type Listener<K, T, F> = T extends DefaultEventMap ? F : ( |
||||
|
K extends keyof T ? ( |
||||
|
T[K] extends unknown[] ? (...args: T[K]) => void : never |
||||
|
) |
||||
|
: never |
||||
|
); |
||||
|
type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>; |
||||
|
type Listener2<K, T> = Listener<K, T, Function>; |
||||
|
|
||||
|
/** |
||||
|
* The `EventEmitter` class is defined and exposed by the `node:events` module: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* ``` |
||||
|
* |
||||
|
* All `EventEmitter`s emit the event `'newListener'` when new listeners are |
||||
|
* added and `'removeListener'` when existing listeners are removed. |
||||
|
* |
||||
|
* It supports the following option: |
||||
|
* @since v0.1.26 |
||||
|
*/ |
||||
|
class EventEmitter<T extends EventMap<T> = DefaultEventMap> { |
||||
|
constructor(options?: EventEmitterOptions); |
||||
|
|
||||
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void; |
||||
|
|
||||
|
/** |
||||
|
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given |
||||
|
* event or that is rejected if the `EventEmitter` emits `'error'` while waiting. |
||||
|
* The `Promise` will resolve with an array of all the arguments emitted to the |
||||
|
* given event. |
||||
|
* |
||||
|
* This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event
|
||||
|
* semantics and does not listen to the `'error'` event. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { once, EventEmitter } from 'node:events'; |
||||
|
* import process from 'node:process'; |
||||
|
* |
||||
|
* const ee = new EventEmitter(); |
||||
|
* |
||||
|
* process.nextTick(() => { |
||||
|
* ee.emit('myevent', 42); |
||||
|
* }); |
||||
|
* |
||||
|
* const [value] = await once(ee, 'myevent'); |
||||
|
* console.log(value); |
||||
|
* |
||||
|
* const err = new Error('kaboom'); |
||||
|
* process.nextTick(() => { |
||||
|
* ee.emit('error', err); |
||||
|
* }); |
||||
|
* |
||||
|
* try { |
||||
|
* await once(ee, 'myevent'); |
||||
|
* } catch (err) { |
||||
|
* console.error('error happened', err); |
||||
|
* } |
||||
|
* ``` |
||||
|
* |
||||
|
* The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the |
||||
|
* '`error'` event itself, then it is treated as any other kind of event without
|
||||
|
* special handling: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter, once } from 'node:events'; |
||||
|
* |
||||
|
* const ee = new EventEmitter(); |
||||
|
* |
||||
|
* once(ee, 'error') |
||||
|
* .then(([err]) => console.log('ok', err.message)) |
||||
|
* .catch((err) => console.error('error', err.message)); |
||||
|
* |
||||
|
* ee.emit('error', new Error('boom')); |
||||
|
* |
||||
|
* // Prints: ok boom
|
||||
|
* ``` |
||||
|
* |
||||
|
* An `AbortSignal` can be used to cancel waiting for the event: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter, once } from 'node:events'; |
||||
|
* |
||||
|
* const ee = new EventEmitter(); |
||||
|
* const ac = new AbortController(); |
||||
|
* |
||||
|
* async function foo(emitter, event, signal) { |
||||
|
* try { |
||||
|
* await once(emitter, event, { signal }); |
||||
|
* console.log('event emitted!'); |
||||
|
* } catch (error) { |
||||
|
* if (error.name === 'AbortError') { |
||||
|
* console.error('Waiting for the event was canceled!'); |
||||
|
* } else { |
||||
|
* console.error('There was an error', error.message); |
||||
|
* } |
||||
|
* } |
||||
|
* } |
||||
|
* |
||||
|
* foo(ee, 'foo', ac.signal); |
||||
|
* ac.abort(); // Abort waiting for the event
|
||||
|
* ee.emit('foo'); // Prints: Waiting for the event was canceled!
|
||||
|
* ``` |
||||
|
* @since v11.13.0, v10.16.0 |
||||
|
*/ |
||||
|
static once( |
||||
|
emitter: NodeJS.EventEmitter, |
||||
|
eventName: string | symbol, |
||||
|
options?: StaticEventEmitterOptions, |
||||
|
): Promise<any[]>; |
||||
|
static once(emitter: EventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>; |
||||
|
/** |
||||
|
* ```js
|
||||
|
* import { on, EventEmitter } from 'node:events'; |
||||
|
* import process from 'node:process'; |
||||
|
* |
||||
|
* const ee = new EventEmitter(); |
||||
|
* |
||||
|
* // Emit later on
|
||||
|
* process.nextTick(() => { |
||||
|
* ee.emit('foo', 'bar'); |
||||
|
* ee.emit('foo', 42); |
||||
|
* }); |
||||
|
* |
||||
|
* for await (const event of on(ee, 'foo')) { |
||||
|
* // The execution of this inner block is synchronous and it
|
||||
|
* // processes one event at a time (even with await). Do not use
|
||||
|
* // if concurrent execution is required.
|
||||
|
* console.log(event); // prints ['bar'] [42]
|
||||
|
* } |
||||
|
* // Unreachable here
|
||||
|
* ``` |
||||
|
* |
||||
|
* Returns an `AsyncIterator` that iterates `eventName` events. It will throw |
||||
|
* if the `EventEmitter` emits `'error'`. It removes all listeners when |
||||
|
* exiting the loop. The `value` returned by each iteration is an array |
||||
|
* composed of the emitted event arguments. |
||||
|
* |
||||
|
* An `AbortSignal` can be used to cancel waiting on events: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { on, EventEmitter } from 'node:events'; |
||||
|
* import process from 'node:process'; |
||||
|
* |
||||
|
* const ac = new AbortController(); |
||||
|
* |
||||
|
* (async () => { |
||||
|
* const ee = new EventEmitter(); |
||||
|
* |
||||
|
* // Emit later on
|
||||
|
* process.nextTick(() => { |
||||
|
* ee.emit('foo', 'bar'); |
||||
|
* ee.emit('foo', 42); |
||||
|
* }); |
||||
|
* |
||||
|
* for await (const event of on(ee, 'foo', { signal: ac.signal })) { |
||||
|
* // The execution of this inner block is synchronous and it
|
||||
|
* // processes one event at a time (even with await). Do not use
|
||||
|
* // if concurrent execution is required.
|
||||
|
* console.log(event); // prints ['bar'] [42]
|
||||
|
* } |
||||
|
* // Unreachable here
|
||||
|
* })(); |
||||
|
* |
||||
|
* process.nextTick(() => ac.abort()); |
||||
|
* ``` |
||||
|
* |
||||
|
* Use the `close` option to specify an array of event names that will end the iteration: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { on, EventEmitter } from 'node:events'; |
||||
|
* import process from 'node:process'; |
||||
|
* |
||||
|
* const ee = new EventEmitter(); |
||||
|
* |
||||
|
* // Emit later on
|
||||
|
* process.nextTick(() => { |
||||
|
* ee.emit('foo', 'bar'); |
||||
|
* ee.emit('foo', 42); |
||||
|
* ee.emit('close'); |
||||
|
* }); |
||||
|
* |
||||
|
* for await (const event of on(ee, 'foo', { close: ['close'] })) { |
||||
|
* console.log(event); // prints ['bar'] [42]
|
||||
|
* } |
||||
|
* // the loop will exit after 'close' is emitted
|
||||
|
* console.log('done'); // prints 'done'
|
||||
|
* ``` |
||||
|
* @since v13.6.0, v12.16.0 |
||||
|
* @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter` |
||||
|
*/ |
||||
|
static on( |
||||
|
emitter: NodeJS.EventEmitter, |
||||
|
eventName: string | symbol, |
||||
|
options?: StaticEventEmitterIteratorOptions, |
||||
|
): NodeJS.AsyncIterator<any[]>; |
||||
|
static on( |
||||
|
emitter: EventTarget, |
||||
|
eventName: string, |
||||
|
options?: StaticEventEmitterIteratorOptions, |
||||
|
): NodeJS.AsyncIterator<any[]>; |
||||
|
/** |
||||
|
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter, listenerCount } from 'node:events'; |
||||
|
* |
||||
|
* const myEmitter = new EventEmitter(); |
||||
|
* myEmitter.on('event', () => {}); |
||||
|
* myEmitter.on('event', () => {}); |
||||
|
* console.log(listenerCount(myEmitter, 'event')); |
||||
|
* // Prints: 2
|
||||
|
* ``` |
||||
|
* @since v0.9.12 |
||||
|
* @deprecated Since v3.2.0 - Use `listenerCount` instead. |
||||
|
* @param emitter The emitter to query |
||||
|
* @param eventName The event name |
||||
|
*/ |
||||
|
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number; |
||||
|
/** |
||||
|
* Returns a copy of the array of listeners for the event named `eventName`. |
||||
|
* |
||||
|
* For `EventEmitter`s this behaves exactly the same as calling `.listeners` on |
||||
|
* the emitter. |
||||
|
* |
||||
|
* For `EventTarget`s this is the only way to get the event listeners for the |
||||
|
* event target. This is useful for debugging and diagnostic purposes. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { getEventListeners, EventEmitter } from 'node:events'; |
||||
|
* |
||||
|
* { |
||||
|
* const ee = new EventEmitter(); |
||||
|
* const listener = () => console.log('Events are fun'); |
||||
|
* ee.on('foo', listener); |
||||
|
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
|
||||
|
* } |
||||
|
* { |
||||
|
* const et = new EventTarget(); |
||||
|
* const listener = () => console.log('Events are fun'); |
||||
|
* et.addEventListener('foo', listener); |
||||
|
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v15.2.0, v14.17.0 |
||||
|
*/ |
||||
|
static getEventListeners(emitter: EventTarget | NodeJS.EventEmitter, name: string | symbol): Function[]; |
||||
|
/** |
||||
|
* Returns the currently set max amount of listeners. |
||||
|
* |
||||
|
* For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on |
||||
|
* the emitter. |
||||
|
* |
||||
|
* For `EventTarget`s this is the only way to get the max event listeners for the |
||||
|
* event target. If the number of event handlers on a single EventTarget exceeds |
||||
|
* the max set, the EventTarget will print a warning. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events'; |
||||
|
* |
||||
|
* { |
||||
|
* const ee = new EventEmitter(); |
||||
|
* console.log(getMaxListeners(ee)); // 10
|
||||
|
* setMaxListeners(11, ee); |
||||
|
* console.log(getMaxListeners(ee)); // 11
|
||||
|
* } |
||||
|
* { |
||||
|
* const et = new EventTarget(); |
||||
|
* console.log(getMaxListeners(et)); // 10
|
||||
|
* setMaxListeners(11, et); |
||||
|
* console.log(getMaxListeners(et)); // 11
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v19.9.0 |
||||
|
*/ |
||||
|
static getMaxListeners(emitter: EventTarget | NodeJS.EventEmitter): number; |
||||
|
/** |
||||
|
* ```js
|
||||
|
* import { setMaxListeners, EventEmitter } from 'node:events'; |
||||
|
* |
||||
|
* const target = new EventTarget(); |
||||
|
* const emitter = new EventEmitter(); |
||||
|
* |
||||
|
* setMaxListeners(5, target, emitter); |
||||
|
* ``` |
||||
|
* @since v15.4.0 |
||||
|
* @param n A non-negative number. The maximum number of listeners per `EventTarget` event. |
||||
|
* @param eventTargets Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter} |
||||
|
* objects. |
||||
|
*/ |
||||
|
static setMaxListeners(n?: number, ...eventTargets: Array<EventTarget | NodeJS.EventEmitter>): void; |
||||
|
/** |
||||
|
* Listens once to the `abort` event on the provided `signal`. |
||||
|
* |
||||
|
* Listening to the `abort` event on abort signals is unsafe and may |
||||
|
* lead to resource leaks since another third party with the signal can |
||||
|
* call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change |
||||
|
* this since it would violate the web standard. Additionally, the original |
||||
|
* API makes it easy to forget to remove listeners. |
||||
|
* |
||||
|
* This API allows safely using `AbortSignal`s in Node.js APIs by solving these |
||||
|
* two issues by listening to the event such that `stopImmediatePropagation` does |
||||
|
* not prevent the listener from running. |
||||
|
* |
||||
|
* Returns a disposable so that it may be unsubscribed from more easily. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { addAbortListener } from 'node:events'; |
||||
|
* |
||||
|
* function example(signal) { |
||||
|
* let disposable; |
||||
|
* try { |
||||
|
* signal.addEventListener('abort', (e) => e.stopImmediatePropagation()); |
||||
|
* disposable = addAbortListener(signal, (e) => { |
||||
|
* // Do something when signal is aborted.
|
||||
|
* }); |
||||
|
* } finally { |
||||
|
* disposable?.[Symbol.dispose](); |
||||
|
* } |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v20.5.0 |
||||
|
* @return Disposable that removes the `abort` listener. |
||||
|
*/ |
||||
|
static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable; |
||||
|
/** |
||||
|
* This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called. |
||||
|
* |
||||
|
* Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no |
||||
|
* regular `'error'` listener is installed. |
||||
|
* @since v13.6.0, v12.17.0 |
||||
|
*/ |
||||
|
static readonly errorMonitor: unique symbol; |
||||
|
/** |
||||
|
* Value: `Symbol.for('nodejs.rejection')` |
||||
|
* |
||||
|
* See how to write a custom `rejection handler`. |
||||
|
* @since v13.4.0, v12.16.0 |
||||
|
*/ |
||||
|
static readonly captureRejectionSymbol: unique symbol; |
||||
|
/** |
||||
|
* Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
|
||||
|
* |
||||
|
* Change the default `captureRejections` option on all new `EventEmitter` objects. |
||||
|
* @since v13.4.0, v12.16.0 |
||||
|
*/ |
||||
|
static captureRejections: boolean; |
||||
|
/** |
||||
|
* By default, a maximum of `10` listeners can be registered for any single |
||||
|
* event. This limit can be changed for individual `EventEmitter` instances |
||||
|
* using the `emitter.setMaxListeners(n)` method. To change the default |
||||
|
* for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property |
||||
|
* can be used. If this value is not a positive number, a `RangeError` is thrown. |
||||
|
* |
||||
|
* Take caution when setting the `events.defaultMaxListeners` because the |
||||
|
* change affects _all_ `EventEmitter` instances, including those created before |
||||
|
* the change is made. However, calling `emitter.setMaxListeners(n)` still has |
||||
|
* precedence over `events.defaultMaxListeners`. |
||||
|
* |
||||
|
* This is not a hard limit. The `EventEmitter` instance will allow |
||||
|
* more listeners to be added but will output a trace warning to stderr indicating |
||||
|
* that a "possible EventEmitter memory leak" has been detected. For any single |
||||
|
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to |
||||
|
* temporarily avoid this warning: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* const emitter = new EventEmitter(); |
||||
|
* emitter.setMaxListeners(emitter.getMaxListeners() + 1); |
||||
|
* emitter.once('event', () => { |
||||
|
* // do stuff
|
||||
|
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0)); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* The `--trace-warnings` command-line flag can be used to display the |
||||
|
* stack trace for such warnings. |
||||
|
* |
||||
|
* The emitted warning can be inspected with `process.on('warning')` and will |
||||
|
* have the additional `emitter`, `type`, and `count` properties, referring to |
||||
|
* the event emitter instance, the event's name and the number of attached |
||||
|
* listeners, respectively. |
||||
|
* Its `name` property is set to `'MaxListenersExceededWarning'`. |
||||
|
* @since v0.11.2 |
||||
|
*/ |
||||
|
static defaultMaxListeners: number; |
||||
|
} |
||||
|
import internal = require("node:events"); |
||||
|
namespace EventEmitter { |
||||
|
// Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
|
||||
|
export { internal as EventEmitter }; |
||||
|
export interface Abortable { |
||||
|
/** |
||||
|
* When provided the corresponding `AbortController` can be used to cancel an asynchronous action. |
||||
|
*/ |
||||
|
signal?: AbortSignal | undefined; |
||||
|
} |
||||
|
|
||||
|
export interface EventEmitterReferencingAsyncResource extends AsyncResource { |
||||
|
readonly eventEmitter: EventEmitterAsyncResource; |
||||
|
} |
||||
|
|
||||
|
export interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions { |
||||
|
/** |
||||
|
* The type of async event, this is required when instantiating `EventEmitterAsyncResource` |
||||
|
* directly rather than as a child class. |
||||
|
* @default new.target.name if instantiated as a child class. |
||||
|
*/ |
||||
|
name?: string; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that |
||||
|
* require manual async tracking. Specifically, all events emitted by instances |
||||
|
* of `events.EventEmitterAsyncResource` will run within its `async context`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitterAsyncResource, EventEmitter } from 'node:events'; |
||||
|
* import { notStrictEqual, strictEqual } from 'node:assert'; |
||||
|
* import { executionAsyncId, triggerAsyncId } from 'node:async_hooks'; |
||||
|
* |
||||
|
* // Async tracking tooling will identify this as 'Q'.
|
||||
|
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' }); |
||||
|
* |
||||
|
* // 'foo' listeners will run in the EventEmitters async context.
|
||||
|
* ee1.on('foo', () => { |
||||
|
* strictEqual(executionAsyncId(), ee1.asyncId); |
||||
|
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId); |
||||
|
* }); |
||||
|
* |
||||
|
* const ee2 = new EventEmitter(); |
||||
|
* |
||||
|
* // 'foo' listeners on ordinary EventEmitters that do not track async
|
||||
|
* // context, however, run in the same async context as the emit().
|
||||
|
* ee2.on('foo', () => { |
||||
|
* notStrictEqual(executionAsyncId(), ee2.asyncId); |
||||
|
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId); |
||||
|
* }); |
||||
|
* |
||||
|
* Promise.resolve().then(() => { |
||||
|
* ee1.emit('foo'); |
||||
|
* ee2.emit('foo'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* The `EventEmitterAsyncResource` class has the same methods and takes the |
||||
|
* same options as `EventEmitter` and `AsyncResource` themselves. |
||||
|
* @since v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
export class EventEmitterAsyncResource extends EventEmitter { |
||||
|
/** |
||||
|
* @param options Only optional in child class. |
||||
|
*/ |
||||
|
constructor(options?: EventEmitterAsyncResourceOptions); |
||||
|
/** |
||||
|
* Call all `destroy` hooks. This should only ever be called once. An error will |
||||
|
* be thrown if it is called more than once. This **must** be manually called. If |
||||
|
* the resource is left to be collected by the GC then the `destroy` hooks will |
||||
|
* never be called. |
||||
|
*/ |
||||
|
emitDestroy(): void; |
||||
|
/** |
||||
|
* The unique `asyncId` assigned to the resource. |
||||
|
*/ |
||||
|
readonly asyncId: number; |
||||
|
/** |
||||
|
* The same triggerAsyncId that is passed to the AsyncResource constructor. |
||||
|
*/ |
||||
|
readonly triggerAsyncId: number; |
||||
|
/** |
||||
|
* The returned `AsyncResource` object has an additional `eventEmitter` property |
||||
|
* that provides a reference to this `EventEmitterAsyncResource`. |
||||
|
*/ |
||||
|
readonly asyncResource: EventEmitterReferencingAsyncResource; |
||||
|
} |
||||
|
} |
||||
|
global { |
||||
|
namespace NodeJS { |
||||
|
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> { |
||||
|
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void; |
||||
|
/** |
||||
|
* Alias for `emitter.on(eventName, listener)`. |
||||
|
* @since v0.1.26 |
||||
|
*/ |
||||
|
addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Adds the `listener` function to the end of the listeners array for the event |
||||
|
* named `eventName`. No checks are made to see if the `listener` has already |
||||
|
* been added. Multiple calls passing the same combination of `eventName` and |
||||
|
* `listener` will result in the `listener` being added, and called, multiple times. |
||||
|
* |
||||
|
* ```js
|
||||
|
* server.on('connection', (stream) => { |
||||
|
* console.log('someone connected!'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* |
||||
|
* By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the |
||||
|
* event listener to the beginning of the listeners array. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* const myEE = new EventEmitter(); |
||||
|
* myEE.on('foo', () => console.log('a')); |
||||
|
* myEE.prependListener('foo', () => console.log('b')); |
||||
|
* myEE.emit('foo'); |
||||
|
* // Prints:
|
||||
|
* // b
|
||||
|
* // a
|
||||
|
* ``` |
||||
|
* @since v0.1.101 |
||||
|
* @param eventName The name of the event. |
||||
|
* @param listener The callback function |
||||
|
*/ |
||||
|
on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Adds a **one-time** `listener` function for the event named `eventName`. The |
||||
|
* next time `eventName` is triggered, this listener is removed and then invoked. |
||||
|
* |
||||
|
* ```js
|
||||
|
* server.once('connection', (stream) => { |
||||
|
* console.log('Ah, we have our first user!'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* |
||||
|
* By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the |
||||
|
* event listener to the beginning of the listeners array. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* const myEE = new EventEmitter(); |
||||
|
* myEE.once('foo', () => console.log('a')); |
||||
|
* myEE.prependOnceListener('foo', () => console.log('b')); |
||||
|
* myEE.emit('foo'); |
||||
|
* // Prints:
|
||||
|
* // b
|
||||
|
* // a
|
||||
|
* ``` |
||||
|
* @since v0.3.0 |
||||
|
* @param eventName The name of the event. |
||||
|
* @param listener The callback function |
||||
|
*/ |
||||
|
once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Removes the specified `listener` from the listener array for the event named `eventName`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const callback = (stream) => { |
||||
|
* console.log('someone connected!'); |
||||
|
* }; |
||||
|
* server.on('connection', callback); |
||||
|
* // ...
|
||||
|
* server.removeListener('connection', callback); |
||||
|
* ``` |
||||
|
* |
||||
|
* `removeListener()` will remove, at most, one instance of a listener from the |
||||
|
* listener array. If any single listener has been added multiple times to the |
||||
|
* listener array for the specified `eventName`, then `removeListener()` must be |
||||
|
* called multiple times to remove each instance. |
||||
|
* |
||||
|
* Once an event is emitted, all listeners attached to it at the |
||||
|
* time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution |
||||
|
* will not remove them from`emit()` in progress. Subsequent events behave as expected. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* class MyEmitter extends EventEmitter {} |
||||
|
* const myEmitter = new MyEmitter(); |
||||
|
* |
||||
|
* const callbackA = () => { |
||||
|
* console.log('A'); |
||||
|
* myEmitter.removeListener('event', callbackB); |
||||
|
* }; |
||||
|
* |
||||
|
* const callbackB = () => { |
||||
|
* console.log('B'); |
||||
|
* }; |
||||
|
* |
||||
|
* myEmitter.on('event', callbackA); |
||||
|
* |
||||
|
* myEmitter.on('event', callbackB); |
||||
|
* |
||||
|
* // callbackA removes listener callbackB but it will still be called.
|
||||
|
* // Internal listener array at time of emit [callbackA, callbackB]
|
||||
|
* myEmitter.emit('event'); |
||||
|
* // Prints:
|
||||
|
* // A
|
||||
|
* // B
|
||||
|
* |
||||
|
* // callbackB is now removed.
|
||||
|
* // Internal listener array [callbackA]
|
||||
|
* myEmitter.emit('event'); |
||||
|
* // Prints:
|
||||
|
* // A
|
||||
|
* ``` |
||||
|
* |
||||
|
* Because listeners are managed using an internal array, calling this will |
||||
|
* change the position indices of any listener registered _after_ the listener |
||||
|
* being removed. This will not impact the order in which listeners are called, |
||||
|
* but it means that any copies of the listener array as returned by |
||||
|
* the `emitter.listeners()` method will need to be recreated. |
||||
|
* |
||||
|
* When a single function has been added as a handler multiple times for a single |
||||
|
* event (as in the example below), `removeListener()` will remove the most |
||||
|
* recently added instance. In the example the `once('ping')` listener is removed: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* const ee = new EventEmitter(); |
||||
|
* |
||||
|
* function pong() { |
||||
|
* console.log('pong'); |
||||
|
* } |
||||
|
* |
||||
|
* ee.on('ping', pong); |
||||
|
* ee.once('ping', pong); |
||||
|
* ee.removeListener('ping', pong); |
||||
|
* |
||||
|
* ee.emit('ping'); |
||||
|
* ee.emit('ping'); |
||||
|
* ``` |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* @since v0.1.26 |
||||
|
*/ |
||||
|
removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Alias for `emitter.removeListener()`. |
||||
|
* @since v10.0.0 |
||||
|
*/ |
||||
|
off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Removes all listeners, or those of the specified `eventName`. |
||||
|
* |
||||
|
* It is bad practice to remove listeners added elsewhere in the code, |
||||
|
* particularly when the `EventEmitter` instance was created by some other |
||||
|
* component or module (e.g. sockets or file streams). |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* @since v0.1.26 |
||||
|
*/ |
||||
|
removeAllListeners(eventName?: Key<unknown, T>): this; |
||||
|
/** |
||||
|
* By default `EventEmitter`s will print a warning if more than `10` listeners are |
||||
|
* added for a particular event. This is a useful default that helps finding |
||||
|
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be |
||||
|
* modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners. |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* @since v0.3.5 |
||||
|
*/ |
||||
|
setMaxListeners(n: number): this; |
||||
|
/** |
||||
|
* Returns the current max listener value for the `EventEmitter` which is either |
||||
|
* set by `emitter.setMaxListeners(n)` or defaults to {@link EventEmitter.defaultMaxListeners}. |
||||
|
* @since v1.0.0 |
||||
|
*/ |
||||
|
getMaxListeners(): number; |
||||
|
/** |
||||
|
* Returns a copy of the array of listeners for the event named `eventName`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* server.on('connection', (stream) => { |
||||
|
* console.log('someone connected!'); |
||||
|
* }); |
||||
|
* console.log(util.inspect(server.listeners('connection'))); |
||||
|
* // Prints: [ [Function] ]
|
||||
|
* ``` |
||||
|
* @since v0.1.26 |
||||
|
*/ |
||||
|
listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>; |
||||
|
/** |
||||
|
* Returns a copy of the array of listeners for the event named `eventName`, |
||||
|
* including any wrappers (such as those created by `.once()`). |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* const emitter = new EventEmitter(); |
||||
|
* emitter.once('log', () => console.log('log once')); |
||||
|
* |
||||
|
* // Returns a new Array with a function `onceWrapper` which has a property
|
||||
|
* // `listener` which contains the original listener bound above
|
||||
|
* const listeners = emitter.rawListeners('log'); |
||||
|
* const logFnWrapper = listeners[0]; |
||||
|
* |
||||
|
* // Logs "log once" to the console and does not unbind the `once` event
|
||||
|
* logFnWrapper.listener(); |
||||
|
* |
||||
|
* // Logs "log once" to the console and removes the listener
|
||||
|
* logFnWrapper(); |
||||
|
* |
||||
|
* emitter.on('log', () => console.log('log persistently')); |
||||
|
* // Will return a new Array with a single function bound by `.on()` above
|
||||
|
* const newListeners = emitter.rawListeners('log'); |
||||
|
* |
||||
|
* // Logs "log persistently" twice
|
||||
|
* newListeners[0](); |
||||
|
* emitter.emit('log'); |
||||
|
* ``` |
||||
|
* @since v9.4.0 |
||||
|
*/ |
||||
|
rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>; |
||||
|
/** |
||||
|
* Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments |
||||
|
* to each. |
||||
|
* |
||||
|
* Returns `true` if the event had listeners, `false` otherwise. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* const myEmitter = new EventEmitter(); |
||||
|
* |
||||
|
* // First listener
|
||||
|
* myEmitter.on('event', function firstListener() { |
||||
|
* console.log('Helloooo! first listener'); |
||||
|
* }); |
||||
|
* // Second listener
|
||||
|
* myEmitter.on('event', function secondListener(arg1, arg2) { |
||||
|
* console.log(`event with parameters ${arg1}, ${arg2} in second listener`); |
||||
|
* }); |
||||
|
* // Third listener
|
||||
|
* myEmitter.on('event', function thirdListener(...args) { |
||||
|
* const parameters = args.join(', '); |
||||
|
* console.log(`event with parameters ${parameters} in third listener`); |
||||
|
* }); |
||||
|
* |
||||
|
* console.log(myEmitter.listeners('event')); |
||||
|
* |
||||
|
* myEmitter.emit('event', 1, 2, 3, 4, 5); |
||||
|
* |
||||
|
* // Prints:
|
||||
|
* // [
|
||||
|
* // [Function: firstListener],
|
||||
|
* // [Function: secondListener],
|
||||
|
* // [Function: thirdListener]
|
||||
|
* // ]
|
||||
|
* // Helloooo! first listener
|
||||
|
* // event with parameters 1, 2 in second listener
|
||||
|
* // event with parameters 1, 2, 3, 4, 5 in third listener
|
||||
|
* ``` |
||||
|
* @since v0.1.26 |
||||
|
*/ |
||||
|
emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean; |
||||
|
/** |
||||
|
* Returns the number of listeners listening for the event named `eventName`. |
||||
|
* If `listener` is provided, it will return how many times the listener is found |
||||
|
* in the list of the listeners of the event. |
||||
|
* @since v3.2.0 |
||||
|
* @param eventName The name of the event being listened for |
||||
|
* @param listener The event handler function |
||||
|
*/ |
||||
|
listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number; |
||||
|
/** |
||||
|
* Adds the `listener` function to the _beginning_ of the listeners array for the |
||||
|
* event named `eventName`. No checks are made to see if the `listener` has |
||||
|
* already been added. Multiple calls passing the same combination of `eventName` |
||||
|
* and `listener` will result in the `listener` being added, and called, multiple times. |
||||
|
* |
||||
|
* ```js
|
||||
|
* server.prependListener('connection', (stream) => { |
||||
|
* console.log('someone connected!'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* @since v6.0.0 |
||||
|
* @param eventName The name of the event. |
||||
|
* @param listener The callback function |
||||
|
*/ |
||||
|
prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this |
||||
|
* listener is removed, and then invoked. |
||||
|
* |
||||
|
* ```js
|
||||
|
* server.prependOnceListener('connection', (stream) => { |
||||
|
* console.log('Ah, we have our first user!'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Returns a reference to the `EventEmitter`, so that calls can be chained. |
||||
|
* @since v6.0.0 |
||||
|
* @param eventName The name of the event. |
||||
|
* @param listener The callback function |
||||
|
*/ |
||||
|
prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this; |
||||
|
/** |
||||
|
* Returns an array listing the events for which the emitter has registered |
||||
|
* listeners. The values in the array are strings or `Symbol`s. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { EventEmitter } from 'node:events'; |
||||
|
* |
||||
|
* const myEE = new EventEmitter(); |
||||
|
* myEE.on('foo', () => {}); |
||||
|
* myEE.on('bar', () => {}); |
||||
|
* |
||||
|
* const sym = Symbol('symbol'); |
||||
|
* myEE.on(sym, () => {}); |
||||
|
* |
||||
|
* console.log(myEE.eventNames()); |
||||
|
* // Prints: [ 'foo', 'bar', Symbol(symbol) ]
|
||||
|
* ``` |
||||
|
* @since v6.0.0 |
||||
|
*/ |
||||
|
eventNames(): Array<(string | symbol) & Key2<unknown, T>>; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
export = EventEmitter; |
||||
|
} |
||||
|
declare module "node:events" { |
||||
|
import events = require("events"); |
||||
|
export = events; |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,367 @@ |
|||||
|
export {}; // Make this a module
|
||||
|
|
||||
|
// #region Fetch and friends
|
||||
|
// Conditional type aliases, used at the end of this file.
|
||||
|
// Will either be empty if lib.dom (or lib.webworker) is included, or the undici version otherwise.
|
||||
|
type _Request = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Request; |
||||
|
type _Response = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Response; |
||||
|
type _FormData = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").FormData; |
||||
|
type _Headers = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Headers; |
||||
|
type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").MessageEvent; |
||||
|
type _RequestInit = typeof globalThis extends { onmessage: any } ? {} |
||||
|
: import("undici-types").RequestInit; |
||||
|
type _ResponseInit = typeof globalThis extends { onmessage: any } ? {} |
||||
|
: import("undici-types").ResponseInit; |
||||
|
type _WebSocket = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").WebSocket; |
||||
|
type _EventSource = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").EventSource; |
||||
|
type _CloseEvent = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").CloseEvent; |
||||
|
// #endregion Fetch and friends
|
||||
|
|
||||
|
// Conditional type definitions for webstorage interface, which conflicts with lib.dom otherwise.
|
||||
|
type _Storage = typeof globalThis extends { onabort: any } ? {} : { |
||||
|
readonly length: number; |
||||
|
clear(): void; |
||||
|
getItem(key: string): string | null; |
||||
|
key(index: number): string | null; |
||||
|
removeItem(key: string): void; |
||||
|
setItem(key: string, value: string): void; |
||||
|
[key: string]: any; |
||||
|
}; |
||||
|
|
||||
|
// #region DOMException
|
||||
|
type _DOMException = typeof globalThis extends { onmessage: any } ? {} : NodeDOMException; |
||||
|
interface NodeDOMException extends Error { |
||||
|
readonly code: number; |
||||
|
readonly message: string; |
||||
|
readonly name: string; |
||||
|
readonly INDEX_SIZE_ERR: 1; |
||||
|
readonly DOMSTRING_SIZE_ERR: 2; |
||||
|
readonly HIERARCHY_REQUEST_ERR: 3; |
||||
|
readonly WRONG_DOCUMENT_ERR: 4; |
||||
|
readonly INVALID_CHARACTER_ERR: 5; |
||||
|
readonly NO_DATA_ALLOWED_ERR: 6; |
||||
|
readonly NO_MODIFICATION_ALLOWED_ERR: 7; |
||||
|
readonly NOT_FOUND_ERR: 8; |
||||
|
readonly NOT_SUPPORTED_ERR: 9; |
||||
|
readonly INUSE_ATTRIBUTE_ERR: 10; |
||||
|
readonly INVALID_STATE_ERR: 11; |
||||
|
readonly SYNTAX_ERR: 12; |
||||
|
readonly INVALID_MODIFICATION_ERR: 13; |
||||
|
readonly NAMESPACE_ERR: 14; |
||||
|
readonly INVALID_ACCESS_ERR: 15; |
||||
|
readonly VALIDATION_ERR: 16; |
||||
|
readonly TYPE_MISMATCH_ERR: 17; |
||||
|
readonly SECURITY_ERR: 18; |
||||
|
readonly NETWORK_ERR: 19; |
||||
|
readonly ABORT_ERR: 20; |
||||
|
readonly URL_MISMATCH_ERR: 21; |
||||
|
readonly QUOTA_EXCEEDED_ERR: 22; |
||||
|
readonly TIMEOUT_ERR: 23; |
||||
|
readonly INVALID_NODE_TYPE_ERR: 24; |
||||
|
readonly DATA_CLONE_ERR: 25; |
||||
|
} |
||||
|
interface NodeDOMExceptionConstructor { |
||||
|
prototype: DOMException; |
||||
|
new(message?: string, nameOrOptions?: string | { name?: string; cause?: unknown }): DOMException; |
||||
|
readonly INDEX_SIZE_ERR: 1; |
||||
|
readonly DOMSTRING_SIZE_ERR: 2; |
||||
|
readonly HIERARCHY_REQUEST_ERR: 3; |
||||
|
readonly WRONG_DOCUMENT_ERR: 4; |
||||
|
readonly INVALID_CHARACTER_ERR: 5; |
||||
|
readonly NO_DATA_ALLOWED_ERR: 6; |
||||
|
readonly NO_MODIFICATION_ALLOWED_ERR: 7; |
||||
|
readonly NOT_FOUND_ERR: 8; |
||||
|
readonly NOT_SUPPORTED_ERR: 9; |
||||
|
readonly INUSE_ATTRIBUTE_ERR: 10; |
||||
|
readonly INVALID_STATE_ERR: 11; |
||||
|
readonly SYNTAX_ERR: 12; |
||||
|
readonly INVALID_MODIFICATION_ERR: 13; |
||||
|
readonly NAMESPACE_ERR: 14; |
||||
|
readonly INVALID_ACCESS_ERR: 15; |
||||
|
readonly VALIDATION_ERR: 16; |
||||
|
readonly TYPE_MISMATCH_ERR: 17; |
||||
|
readonly SECURITY_ERR: 18; |
||||
|
readonly NETWORK_ERR: 19; |
||||
|
readonly ABORT_ERR: 20; |
||||
|
readonly URL_MISMATCH_ERR: 21; |
||||
|
readonly QUOTA_EXCEEDED_ERR: 22; |
||||
|
readonly TIMEOUT_ERR: 23; |
||||
|
readonly INVALID_NODE_TYPE_ERR: 24; |
||||
|
readonly DATA_CLONE_ERR: 25; |
||||
|
} |
||||
|
// #endregion DOMException
|
||||
|
|
||||
|
declare global { |
||||
|
var global: typeof globalThis; |
||||
|
|
||||
|
var process: NodeJS.Process; |
||||
|
var console: Console; |
||||
|
|
||||
|
interface ErrorConstructor { |
||||
|
/** |
||||
|
* Creates a `.stack` property on `targetObject`, which when accessed returns |
||||
|
* a string representing the location in the code at which |
||||
|
* `Error.captureStackTrace()` was called. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const myObject = {}; |
||||
|
* Error.captureStackTrace(myObject); |
||||
|
* myObject.stack; // Similar to `new Error().stack`
|
||||
|
* ``` |
||||
|
* |
||||
|
* The first line of the trace will be prefixed with |
||||
|
* `${myObject.name}: ${myObject.message}`. |
||||
|
* |
||||
|
* The optional `constructorOpt` argument accepts a function. If given, all frames |
||||
|
* above `constructorOpt`, including `constructorOpt`, will be omitted from the |
||||
|
* generated stack trace. |
||||
|
* |
||||
|
* The `constructorOpt` argument is useful for hiding implementation |
||||
|
* details of error generation from the user. For instance: |
||||
|
* |
||||
|
* ```js
|
||||
|
* function a() { |
||||
|
* b(); |
||||
|
* } |
||||
|
* |
||||
|
* function b() { |
||||
|
* c(); |
||||
|
* } |
||||
|
* |
||||
|
* function c() { |
||||
|
* // Create an error without stack trace to avoid calculating the stack trace twice.
|
||||
|
* const { stackTraceLimit } = Error; |
||||
|
* Error.stackTraceLimit = 0; |
||||
|
* const error = new Error(); |
||||
|
* Error.stackTraceLimit = stackTraceLimit; |
||||
|
* |
||||
|
* // Capture the stack trace above function b
|
||||
|
* Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
|
||||
|
* throw error; |
||||
|
* } |
||||
|
* |
||||
|
* a(); |
||||
|
* ``` |
||||
|
*/ |
||||
|
captureStackTrace(targetObject: object, constructorOpt?: Function): void; |
||||
|
/** |
||||
|
* @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
||||
|
*/ |
||||
|
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any; |
||||
|
/** |
||||
|
* The `Error.stackTraceLimit` property specifies the number of stack frames |
||||
|
* collected by a stack trace (whether generated by `new Error().stack` or |
||||
|
* `Error.captureStackTrace(obj)`). |
||||
|
* |
||||
|
* The default value is `10` but may be set to any valid JavaScript number. Changes |
||||
|
* will affect any stack trace captured _after_ the value has been changed. |
||||
|
* |
||||
|
* If set to a non-number value, or set to a negative number, stack traces will |
||||
|
* not capture any frames. |
||||
|
*/ |
||||
|
stackTraceLimit: number; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Enable this API with the `--expose-gc` CLI flag. |
||||
|
*/ |
||||
|
var gc: NodeJS.GCFunction | undefined; |
||||
|
|
||||
|
namespace NodeJS { |
||||
|
interface CallSite { |
||||
|
getColumnNumber(): number | null; |
||||
|
getEnclosingColumnNumber(): number | null; |
||||
|
getEnclosingLineNumber(): number | null; |
||||
|
getEvalOrigin(): string | undefined; |
||||
|
getFileName(): string | null; |
||||
|
getFunction(): Function | undefined; |
||||
|
getFunctionName(): string | null; |
||||
|
getLineNumber(): number | null; |
||||
|
getMethodName(): string | null; |
||||
|
getPosition(): number; |
||||
|
getPromiseIndex(): number | null; |
||||
|
getScriptHash(): string; |
||||
|
getScriptNameOrSourceURL(): string | null; |
||||
|
getThis(): unknown; |
||||
|
getTypeName(): string | null; |
||||
|
isAsync(): boolean; |
||||
|
isConstructor(): boolean; |
||||
|
isEval(): boolean; |
||||
|
isNative(): boolean; |
||||
|
isPromiseAll(): boolean; |
||||
|
isToplevel(): boolean; |
||||
|
} |
||||
|
|
||||
|
interface ErrnoException extends Error { |
||||
|
errno?: number | undefined; |
||||
|
code?: string | undefined; |
||||
|
path?: string | undefined; |
||||
|
syscall?: string | undefined; |
||||
|
} |
||||
|
|
||||
|
interface ReadableStream extends EventEmitter { |
||||
|
readable: boolean; |
||||
|
read(size?: number): string | Buffer; |
||||
|
setEncoding(encoding: BufferEncoding): this; |
||||
|
pause(): this; |
||||
|
resume(): this; |
||||
|
isPaused(): boolean; |
||||
|
pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined }): T; |
||||
|
unpipe(destination?: WritableStream): this; |
||||
|
unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void; |
||||
|
wrap(oldStream: ReadableStream): this; |
||||
|
[Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>; |
||||
|
} |
||||
|
|
||||
|
interface WritableStream extends EventEmitter { |
||||
|
writable: boolean; |
||||
|
write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean; |
||||
|
write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean; |
||||
|
end(cb?: () => void): this; |
||||
|
end(data: string | Uint8Array, cb?: () => void): this; |
||||
|
end(str: string, encoding?: BufferEncoding, cb?: () => void): this; |
||||
|
} |
||||
|
|
||||
|
interface ReadWriteStream extends ReadableStream, WritableStream {} |
||||
|
|
||||
|
interface RefCounted { |
||||
|
ref(): this; |
||||
|
unref(): this; |
||||
|
} |
||||
|
|
||||
|
interface Dict<T> { |
||||
|
[key: string]: T | undefined; |
||||
|
} |
||||
|
|
||||
|
interface ReadOnlyDict<T> { |
||||
|
readonly [key: string]: T | undefined; |
||||
|
} |
||||
|
|
||||
|
interface GCFunction { |
||||
|
(minor?: boolean): void; |
||||
|
(options: NodeJS.GCOptions & { execution: "async" }): Promise<void>; |
||||
|
(options: NodeJS.GCOptions): void; |
||||
|
} |
||||
|
|
||||
|
interface GCOptions { |
||||
|
execution?: "sync" | "async" | undefined; |
||||
|
flavor?: "regular" | "last-resort" | undefined; |
||||
|
type?: "major-snapshot" | "major" | "minor" | undefined; |
||||
|
filename?: string | undefined; |
||||
|
} |
||||
|
|
||||
|
/** An iterable iterator returned by the Node.js API. */ |
||||
|
interface Iterator<T, TReturn = undefined, TNext = any> extends IteratorObject<T, TReturn, TNext> { |
||||
|
[Symbol.iterator](): NodeJS.Iterator<T, TReturn, TNext>; |
||||
|
} |
||||
|
|
||||
|
/** An async iterable iterator returned by the Node.js API. */ |
||||
|
interface AsyncIterator<T, TReturn = undefined, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> { |
||||
|
[Symbol.asyncIterator](): NodeJS.AsyncIterator<T, TReturn, TNext>; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Global DOM types
|
||||
|
|
||||
|
interface DOMException extends _DOMException {} |
||||
|
var DOMException: typeof globalThis extends { onmessage: any; DOMException: infer T } ? T |
||||
|
: NodeDOMExceptionConstructor; |
||||
|
|
||||
|
// #region AbortController
|
||||
|
interface AbortController { |
||||
|
readonly signal: AbortSignal; |
||||
|
abort(reason?: any): void; |
||||
|
} |
||||
|
var AbortController: typeof globalThis extends { onmessage: any; AbortController: infer T } ? T |
||||
|
: { |
||||
|
prototype: AbortController; |
||||
|
new(): AbortController; |
||||
|
}; |
||||
|
|
||||
|
interface AbortSignal extends EventTarget { |
||||
|
readonly aborted: boolean; |
||||
|
onabort: ((this: AbortSignal, ev: Event) => any) | null; |
||||
|
readonly reason: any; |
||||
|
throwIfAborted(): void; |
||||
|
} |
||||
|
var AbortSignal: typeof globalThis extends { onmessage: any; AbortSignal: infer T } ? T |
||||
|
: { |
||||
|
prototype: AbortSignal; |
||||
|
new(): AbortSignal; |
||||
|
abort(reason?: any): AbortSignal; |
||||
|
any(signals: AbortSignal[]): AbortSignal; |
||||
|
timeout(milliseconds: number): AbortSignal; |
||||
|
}; |
||||
|
// #endregion AbortController
|
||||
|
|
||||
|
// #region Storage
|
||||
|
interface Storage extends _Storage {} |
||||
|
// Conditional on `onabort` rather than `onmessage`, in order to exclude lib.webworker
|
||||
|
var Storage: typeof globalThis extends { onabort: any; Storage: infer T } ? T |
||||
|
: { |
||||
|
prototype: Storage; |
||||
|
new(): Storage; |
||||
|
}; |
||||
|
|
||||
|
var localStorage: Storage; |
||||
|
var sessionStorage: Storage; |
||||
|
// #endregion Storage
|
||||
|
|
||||
|
// #region fetch
|
||||
|
interface RequestInit extends _RequestInit {} |
||||
|
|
||||
|
function fetch( |
||||
|
input: string | URL | globalThis.Request, |
||||
|
init?: RequestInit, |
||||
|
): Promise<Response>; |
||||
|
|
||||
|
interface Request extends _Request {} |
||||
|
var Request: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
Request: infer T; |
||||
|
} ? T |
||||
|
: typeof import("undici-types").Request; |
||||
|
|
||||
|
interface ResponseInit extends _ResponseInit {} |
||||
|
|
||||
|
interface Response extends _Response {} |
||||
|
var Response: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
Response: infer T; |
||||
|
} ? T |
||||
|
: typeof import("undici-types").Response; |
||||
|
|
||||
|
interface FormData extends _FormData {} |
||||
|
var FormData: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
FormData: infer T; |
||||
|
} ? T |
||||
|
: typeof import("undici-types").FormData; |
||||
|
|
||||
|
interface Headers extends _Headers {} |
||||
|
var Headers: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
Headers: infer T; |
||||
|
} ? T |
||||
|
: typeof import("undici-types").Headers; |
||||
|
|
||||
|
interface MessageEvent extends _MessageEvent {} |
||||
|
var MessageEvent: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
MessageEvent: infer T; |
||||
|
} ? T |
||||
|
: typeof import("undici-types").MessageEvent; |
||||
|
|
||||
|
interface WebSocket extends _WebSocket {} |
||||
|
var WebSocket: typeof globalThis extends { onmessage: any; WebSocket: infer T } ? T |
||||
|
: typeof import("undici-types").WebSocket; |
||||
|
|
||||
|
interface EventSource extends _EventSource {} |
||||
|
var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T |
||||
|
: typeof import("undici-types").EventSource; |
||||
|
|
||||
|
interface CloseEvent extends _CloseEvent {} |
||||
|
var CloseEvent: typeof globalThis extends { onmessage: any; CloseEvent: infer T } ? T |
||||
|
: typeof import("undici-types").CloseEvent; |
||||
|
// #endregion fetch
|
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
export {}; // Make this a module
|
||||
|
|
||||
|
declare global { |
||||
|
namespace NodeJS { |
||||
|
type TypedArray<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> = |
||||
|
| Uint8Array<TArrayBuffer> |
||||
|
| Uint8ClampedArray<TArrayBuffer> |
||||
|
| Uint16Array<TArrayBuffer> |
||||
|
| Uint32Array<TArrayBuffer> |
||||
|
| Int8Array<TArrayBuffer> |
||||
|
| Int16Array<TArrayBuffer> |
||||
|
| Int32Array<TArrayBuffer> |
||||
|
| BigUint64Array<TArrayBuffer> |
||||
|
| BigInt64Array<TArrayBuffer> |
||||
|
| Float16Array<TArrayBuffer> |
||||
|
| Float32Array<TArrayBuffer> |
||||
|
| Float64Array<TArrayBuffer>; |
||||
|
type ArrayBufferView<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> = |
||||
|
| TypedArray<TArrayBuffer> |
||||
|
| DataView<TArrayBuffer>; |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,545 @@ |
|||||
|
/** |
||||
|
* HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a |
||||
|
* separate module. |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/https.js)
|
||||
|
*/ |
||||
|
declare module "https" { |
||||
|
import { Duplex } from "node:stream"; |
||||
|
import * as tls from "node:tls"; |
||||
|
import * as http from "node:http"; |
||||
|
import { URL } from "node:url"; |
||||
|
type ServerOptions< |
||||
|
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage, |
||||
|
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse, |
||||
|
> = tls.SecureContextOptions & tls.TlsOptions & http.ServerOptions<Request, Response>; |
||||
|
type RequestOptions = |
||||
|
& http.RequestOptions |
||||
|
& tls.SecureContextOptions |
||||
|
& { |
||||
|
checkServerIdentity?: |
||||
|
| ((hostname: string, cert: tls.DetailedPeerCertificate) => Error | undefined) |
||||
|
| undefined; |
||||
|
rejectUnauthorized?: boolean | undefined; // Defaults to true
|
||||
|
servername?: string | undefined; // SNI TLS Extension
|
||||
|
}; |
||||
|
interface AgentOptions extends http.AgentOptions, tls.ConnectionOptions { |
||||
|
maxCachedSessions?: number | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* An `Agent` object for HTTPS similar to `http.Agent`. See {@link request} for more information. |
||||
|
* @since v0.4.5 |
||||
|
*/ |
||||
|
class Agent extends http.Agent { |
||||
|
constructor(options?: AgentOptions); |
||||
|
options: AgentOptions; |
||||
|
} |
||||
|
interface Server< |
||||
|
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage, |
||||
|
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse, |
||||
|
> extends http.Server<Request, Response> {} |
||||
|
/** |
||||
|
* See `http.Server` for more information. |
||||
|
* @since v0.3.4 |
||||
|
*/ |
||||
|
class Server< |
||||
|
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage, |
||||
|
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse, |
||||
|
> extends tls.Server { |
||||
|
constructor(requestListener?: http.RequestListener<Request, Response>); |
||||
|
constructor( |
||||
|
options: ServerOptions<Request, Response>, |
||||
|
requestListener?: http.RequestListener<Request, Response>, |
||||
|
); |
||||
|
/** |
||||
|
* Closes all connections connected to this server. |
||||
|
* @since v18.2.0 |
||||
|
*/ |
||||
|
closeAllConnections(): void; |
||||
|
/** |
||||
|
* Closes all connections connected to this server which are not sending a request or waiting for a response. |
||||
|
* @since v18.2.0 |
||||
|
*/ |
||||
|
closeIdleConnections(): void; |
||||
|
addListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
addListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
addListener( |
||||
|
event: "newSession", |
||||
|
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, |
||||
|
): this; |
||||
|
addListener( |
||||
|
event: "OCSPRequest", |
||||
|
listener: ( |
||||
|
certificate: Buffer, |
||||
|
issuer: Buffer, |
||||
|
callback: (err: Error | null, resp: Buffer) => void, |
||||
|
) => void, |
||||
|
): this; |
||||
|
addListener( |
||||
|
event: "resumeSession", |
||||
|
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, |
||||
|
): this; |
||||
|
addListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; |
||||
|
addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
addListener(event: "close", listener: () => void): this; |
||||
|
addListener(event: "connection", listener: (socket: Duplex) => void): this; |
||||
|
addListener(event: "error", listener: (err: Error) => void): this; |
||||
|
addListener(event: "listening", listener: () => void): this; |
||||
|
addListener(event: "checkContinue", listener: http.RequestListener<Request, Response>): this; |
||||
|
addListener(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this; |
||||
|
addListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; |
||||
|
addListener( |
||||
|
event: "connect", |
||||
|
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void, |
||||
|
): this; |
||||
|
addListener(event: "request", listener: http.RequestListener<Request, Response>): this; |
||||
|
addListener( |
||||
|
event: "upgrade", |
||||
|
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void, |
||||
|
): this; |
||||
|
emit(event: string, ...args: any[]): boolean; |
||||
|
emit(event: "keylog", line: Buffer, tlsSocket: tls.TLSSocket): boolean; |
||||
|
emit( |
||||
|
event: "newSession", |
||||
|
sessionId: Buffer, |
||||
|
sessionData: Buffer, |
||||
|
callback: (err: Error, resp: Buffer) => void, |
||||
|
): boolean; |
||||
|
emit( |
||||
|
event: "OCSPRequest", |
||||
|
certificate: Buffer, |
||||
|
issuer: Buffer, |
||||
|
callback: (err: Error | null, resp: Buffer) => void, |
||||
|
): boolean; |
||||
|
emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean; |
||||
|
emit(event: "secureConnection", tlsSocket: tls.TLSSocket): boolean; |
||||
|
emit(event: "tlsClientError", err: Error, tlsSocket: tls.TLSSocket): boolean; |
||||
|
emit(event: "close"): boolean; |
||||
|
emit(event: "connection", socket: Duplex): boolean; |
||||
|
emit(event: "error", err: Error): boolean; |
||||
|
emit(event: "listening"): boolean; |
||||
|
emit( |
||||
|
event: "checkContinue", |
||||
|
req: InstanceType<Request>, |
||||
|
res: InstanceType<Response>, |
||||
|
): boolean; |
||||
|
emit( |
||||
|
event: "checkExpectation", |
||||
|
req: InstanceType<Request>, |
||||
|
res: InstanceType<Response>, |
||||
|
): boolean; |
||||
|
emit(event: "clientError", err: Error, socket: Duplex): boolean; |
||||
|
emit(event: "connect", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean; |
||||
|
emit( |
||||
|
event: "request", |
||||
|
req: InstanceType<Request>, |
||||
|
res: InstanceType<Response>, |
||||
|
): boolean; |
||||
|
emit(event: "upgrade", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean; |
||||
|
on(event: string, listener: (...args: any[]) => void): this; |
||||
|
on(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
on( |
||||
|
event: "newSession", |
||||
|
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, |
||||
|
): this; |
||||
|
on( |
||||
|
event: "OCSPRequest", |
||||
|
listener: ( |
||||
|
certificate: Buffer, |
||||
|
issuer: Buffer, |
||||
|
callback: (err: Error | null, resp: Buffer) => void, |
||||
|
) => void, |
||||
|
): this; |
||||
|
on( |
||||
|
event: "resumeSession", |
||||
|
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, |
||||
|
): this; |
||||
|
on(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; |
||||
|
on(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
on(event: "close", listener: () => void): this; |
||||
|
on(event: "connection", listener: (socket: Duplex) => void): this; |
||||
|
on(event: "error", listener: (err: Error) => void): this; |
||||
|
on(event: "listening", listener: () => void): this; |
||||
|
on(event: "checkContinue", listener: http.RequestListener<Request, Response>): this; |
||||
|
on(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this; |
||||
|
on(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; |
||||
|
on(event: "connect", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this; |
||||
|
on(event: "request", listener: http.RequestListener<Request, Response>): this; |
||||
|
on(event: "upgrade", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this; |
||||
|
once(event: string, listener: (...args: any[]) => void): this; |
||||
|
once(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
once( |
||||
|
event: "newSession", |
||||
|
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, |
||||
|
): this; |
||||
|
once( |
||||
|
event: "OCSPRequest", |
||||
|
listener: ( |
||||
|
certificate: Buffer, |
||||
|
issuer: Buffer, |
||||
|
callback: (err: Error | null, resp: Buffer) => void, |
||||
|
) => void, |
||||
|
): this; |
||||
|
once( |
||||
|
event: "resumeSession", |
||||
|
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, |
||||
|
): this; |
||||
|
once(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; |
||||
|
once(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
once(event: "close", listener: () => void): this; |
||||
|
once(event: "connection", listener: (socket: Duplex) => void): this; |
||||
|
once(event: "error", listener: (err: Error) => void): this; |
||||
|
once(event: "listening", listener: () => void): this; |
||||
|
once(event: "checkContinue", listener: http.RequestListener<Request, Response>): this; |
||||
|
once(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this; |
||||
|
once(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; |
||||
|
once(event: "connect", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this; |
||||
|
once(event: "request", listener: http.RequestListener<Request, Response>): this; |
||||
|
once(event: "upgrade", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this; |
||||
|
prependListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
prependListener( |
||||
|
event: "newSession", |
||||
|
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, |
||||
|
): this; |
||||
|
prependListener( |
||||
|
event: "OCSPRequest", |
||||
|
listener: ( |
||||
|
certificate: Buffer, |
||||
|
issuer: Buffer, |
||||
|
callback: (err: Error | null, resp: Buffer) => void, |
||||
|
) => void, |
||||
|
): this; |
||||
|
prependListener( |
||||
|
event: "resumeSession", |
||||
|
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, |
||||
|
): this; |
||||
|
prependListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; |
||||
|
prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
prependListener(event: "close", listener: () => void): this; |
||||
|
prependListener(event: "connection", listener: (socket: Duplex) => void): this; |
||||
|
prependListener(event: "error", listener: (err: Error) => void): this; |
||||
|
prependListener(event: "listening", listener: () => void): this; |
||||
|
prependListener(event: "checkContinue", listener: http.RequestListener<Request, Response>): this; |
||||
|
prependListener(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this; |
||||
|
prependListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; |
||||
|
prependListener( |
||||
|
event: "connect", |
||||
|
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void, |
||||
|
): this; |
||||
|
prependListener(event: "request", listener: http.RequestListener<Request, Response>): this; |
||||
|
prependListener( |
||||
|
event: "upgrade", |
||||
|
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void, |
||||
|
): this; |
||||
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this; |
||||
|
prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
prependOnceListener( |
||||
|
event: "newSession", |
||||
|
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void, |
||||
|
): this; |
||||
|
prependOnceListener( |
||||
|
event: "OCSPRequest", |
||||
|
listener: ( |
||||
|
certificate: Buffer, |
||||
|
issuer: Buffer, |
||||
|
callback: (err: Error | null, resp: Buffer) => void, |
||||
|
) => void, |
||||
|
): this; |
||||
|
prependOnceListener( |
||||
|
event: "resumeSession", |
||||
|
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void, |
||||
|
): this; |
||||
|
prependOnceListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this; |
||||
|
prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this; |
||||
|
prependOnceListener(event: "close", listener: () => void): this; |
||||
|
prependOnceListener(event: "connection", listener: (socket: Duplex) => void): this; |
||||
|
prependOnceListener(event: "error", listener: (err: Error) => void): this; |
||||
|
prependOnceListener(event: "listening", listener: () => void): this; |
||||
|
prependOnceListener(event: "checkContinue", listener: http.RequestListener<Request, Response>): this; |
||||
|
prependOnceListener(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this; |
||||
|
prependOnceListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this; |
||||
|
prependOnceListener( |
||||
|
event: "connect", |
||||
|
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void, |
||||
|
): this; |
||||
|
prependOnceListener(event: "request", listener: http.RequestListener<Request, Response>): this; |
||||
|
prependOnceListener( |
||||
|
event: "upgrade", |
||||
|
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void, |
||||
|
): this; |
||||
|
} |
||||
|
/** |
||||
|
* ```js
|
||||
|
* // curl -k https://localhost:8000/
|
||||
|
* import https from 'node:https'; |
||||
|
* import fs from 'node:fs'; |
||||
|
* |
||||
|
* const options = { |
||||
|
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), |
||||
|
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'), |
||||
|
* }; |
||||
|
* |
||||
|
* https.createServer(options, (req, res) => { |
||||
|
* res.writeHead(200); |
||||
|
* res.end('hello world\n'); |
||||
|
* }).listen(8000); |
||||
|
* ``` |
||||
|
* |
||||
|
* Or |
||||
|
* |
||||
|
* ```js
|
||||
|
* import https from 'node:https'; |
||||
|
* import fs from 'node:fs'; |
||||
|
* |
||||
|
* const options = { |
||||
|
* pfx: fs.readFileSync('test/fixtures/test_cert.pfx'), |
||||
|
* passphrase: 'sample', |
||||
|
* }; |
||||
|
* |
||||
|
* https.createServer(options, (req, res) => { |
||||
|
* res.writeHead(200); |
||||
|
* res.end('hello world\n'); |
||||
|
* }).listen(8000); |
||||
|
* ``` |
||||
|
* @since v0.3.4 |
||||
|
* @param options Accepts `options` from `createServer`, `createSecureContext` and `createServer`. |
||||
|
* @param requestListener A listener to be added to the `'request'` event. |
||||
|
*/ |
||||
|
function createServer< |
||||
|
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage, |
||||
|
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse, |
||||
|
>(requestListener?: http.RequestListener<Request, Response>): Server<Request, Response>; |
||||
|
function createServer< |
||||
|
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage, |
||||
|
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse, |
||||
|
>( |
||||
|
options: ServerOptions<Request, Response>, |
||||
|
requestListener?: http.RequestListener<Request, Response>, |
||||
|
): Server<Request, Response>; |
||||
|
/** |
||||
|
* Makes a request to a secure web server. |
||||
|
* |
||||
|
* The following additional `options` from `tls.connect()` are also accepted: `ca`, `cert`, `ciphers`, `clientCertEngine`, `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`, `key`, `passphrase`, |
||||
|
* `pfx`, `rejectUnauthorized`, `secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`. |
||||
|
* |
||||
|
* `options` can be an object, a string, or a `URL` object. If `options` is a |
||||
|
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object. |
||||
|
* |
||||
|
* `https.request()` returns an instance of the `http.ClientRequest` class. The `ClientRequest` instance is a writable stream. If one needs to |
||||
|
* upload a file with a POST request, then write to the `ClientRequest` object. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import https from 'node:https'; |
||||
|
* |
||||
|
* const options = { |
||||
|
* hostname: 'encrypted.google.com', |
||||
|
* port: 443, |
||||
|
* path: '/', |
||||
|
* method: 'GET', |
||||
|
* }; |
||||
|
* |
||||
|
* const req = https.request(options, (res) => { |
||||
|
* console.log('statusCode:', res.statusCode); |
||||
|
* console.log('headers:', res.headers); |
||||
|
* |
||||
|
* res.on('data', (d) => { |
||||
|
* process.stdout.write(d); |
||||
|
* }); |
||||
|
* }); |
||||
|
* |
||||
|
* req.on('error', (e) => { |
||||
|
* console.error(e); |
||||
|
* }); |
||||
|
* req.end(); |
||||
|
* ``` |
||||
|
* |
||||
|
* Example using options from `tls.connect()`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const options = { |
||||
|
* hostname: 'encrypted.google.com', |
||||
|
* port: 443, |
||||
|
* path: '/', |
||||
|
* method: 'GET', |
||||
|
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), |
||||
|
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'), |
||||
|
* }; |
||||
|
* options.agent = new https.Agent(options); |
||||
|
* |
||||
|
* const req = https.request(options, (res) => { |
||||
|
* // ...
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Alternatively, opt out of connection pooling by not using an `Agent`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const options = { |
||||
|
* hostname: 'encrypted.google.com', |
||||
|
* port: 443, |
||||
|
* path: '/', |
||||
|
* method: 'GET', |
||||
|
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), |
||||
|
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'), |
||||
|
* agent: false, |
||||
|
* }; |
||||
|
* |
||||
|
* const req = https.request(options, (res) => { |
||||
|
* // ...
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Example using a `URL` as `options`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* const options = new URL('https://abc:xyz@example.com'); |
||||
|
* |
||||
|
* const req = https.request(options, (res) => { |
||||
|
* // ...
|
||||
|
* }); |
||||
|
* ``` |
||||
|
* |
||||
|
* Example pinning on certificate fingerprint, or the public key (similar to`pin-sha256`): |
||||
|
* |
||||
|
* ```js
|
||||
|
* import tls from 'node:tls'; |
||||
|
* import https from 'node:https'; |
||||
|
* import crypto from 'node:crypto'; |
||||
|
* |
||||
|
* function sha256(s) { |
||||
|
* return crypto.createHash('sha256').update(s).digest('base64'); |
||||
|
* } |
||||
|
* const options = { |
||||
|
* hostname: 'github.com', |
||||
|
* port: 443, |
||||
|
* path: '/', |
||||
|
* method: 'GET', |
||||
|
* checkServerIdentity: function(host, cert) { |
||||
|
* // Make sure the certificate is issued to the host we are connected to
|
||||
|
* const err = tls.checkServerIdentity(host, cert); |
||||
|
* if (err) { |
||||
|
* return err; |
||||
|
* } |
||||
|
* |
||||
|
* // Pin the public key, similar to HPKP pin-sha256 pinning
|
||||
|
* const pubkey256 = 'pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU='; |
||||
|
* if (sha256(cert.pubkey) !== pubkey256) { |
||||
|
* const msg = 'Certificate verification error: ' + |
||||
|
* `The public key of '${cert.subject.CN}' ` + |
||||
|
* 'does not match our pinned fingerprint'; |
||||
|
* return new Error(msg); |
||||
|
* } |
||||
|
* |
||||
|
* // Pin the exact certificate, rather than the pub key
|
||||
|
* const cert256 = '25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:' + |
||||
|
* 'D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16'; |
||||
|
* if (cert.fingerprint256 !== cert256) { |
||||
|
* const msg = 'Certificate verification error: ' + |
||||
|
* `The certificate of '${cert.subject.CN}' ` + |
||||
|
* 'does not match our pinned fingerprint'; |
||||
|
* return new Error(msg); |
||||
|
* } |
||||
|
* |
||||
|
* // This loop is informational only.
|
||||
|
* // Print the certificate and public key fingerprints of all certs in the
|
||||
|
* // chain. Its common to pin the public key of the issuer on the public
|
||||
|
* // internet, while pinning the public key of the service in sensitive
|
||||
|
* // environments.
|
||||
|
* do { |
||||
|
* console.log('Subject Common Name:', cert.subject.CN); |
||||
|
* console.log(' Certificate SHA256 fingerprint:', cert.fingerprint256); |
||||
|
* |
||||
|
* hash = crypto.createHash('sha256'); |
||||
|
* console.log(' Public key ping-sha256:', sha256(cert.pubkey)); |
||||
|
* |
||||
|
* lastprint256 = cert.fingerprint256; |
||||
|
* cert = cert.issuerCertificate; |
||||
|
* } while (cert.fingerprint256 !== lastprint256); |
||||
|
* |
||||
|
* }, |
||||
|
* }; |
||||
|
* |
||||
|
* options.agent = new https.Agent(options); |
||||
|
* const req = https.request(options, (res) => { |
||||
|
* console.log('All OK. Server matched our pinned cert or public key'); |
||||
|
* console.log('statusCode:', res.statusCode); |
||||
|
* // Print the HPKP values
|
||||
|
* console.log('headers:', res.headers['public-key-pins']); |
||||
|
* |
||||
|
* res.on('data', (d) => {}); |
||||
|
* }); |
||||
|
* |
||||
|
* req.on('error', (e) => { |
||||
|
* console.error(e.message); |
||||
|
* }); |
||||
|
* req.end(); |
||||
|
* ``` |
||||
|
* |
||||
|
* Outputs for example: |
||||
|
* |
||||
|
* ```text
|
||||
|
* Subject Common Name: github.com |
||||
|
* Certificate SHA256 fingerprint: 25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16 |
||||
|
* Public key ping-sha256: pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU= |
||||
|
* Subject Common Name: DigiCert SHA2 Extended Validation Server CA |
||||
|
* Certificate SHA256 fingerprint: 40:3E:06:2A:26:53:05:91:13:28:5B:AF:80:A0:D4:AE:42:2C:84:8C:9F:78:FA:D0:1F:C9:4B:C5:B8:7F:EF:1A |
||||
|
* Public key ping-sha256: RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho= |
||||
|
* Subject Common Name: DigiCert High Assurance EV Root CA |
||||
|
* Certificate SHA256 fingerprint: 74:31:E5:F4:C3:C1:CE:46:90:77:4F:0B:61:E0:54:40:88:3B:A9:A0:1E:D0:0B:A6:AB:D7:80:6E:D3:B1:18:CF |
||||
|
* Public key ping-sha256: WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18= |
||||
|
* All OK. Server matched our pinned cert or public key |
||||
|
* statusCode: 200 |
||||
|
* headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho="; |
||||
|
* pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4="; |
||||
|
* pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains |
||||
|
* ``` |
||||
|
* @since v0.3.6 |
||||
|
* @param options Accepts all `options` from `request`, with some differences in default values: |
||||
|
*/ |
||||
|
function request( |
||||
|
options: RequestOptions | string | URL, |
||||
|
callback?: (res: http.IncomingMessage) => void, |
||||
|
): http.ClientRequest; |
||||
|
function request( |
||||
|
url: string | URL, |
||||
|
options: RequestOptions, |
||||
|
callback?: (res: http.IncomingMessage) => void, |
||||
|
): http.ClientRequest; |
||||
|
/** |
||||
|
* Like `http.get()` but for HTTPS. |
||||
|
* |
||||
|
* `options` can be an object, a string, or a `URL` object. If `options` is a |
||||
|
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import https from 'node:https'; |
||||
|
* |
||||
|
* https.get('https://encrypted.google.com/', (res) => { |
||||
|
* console.log('statusCode:', res.statusCode); |
||||
|
* console.log('headers:', res.headers); |
||||
|
* |
||||
|
* res.on('data', (d) => { |
||||
|
* process.stdout.write(d); |
||||
|
* }); |
||||
|
* |
||||
|
* }).on('error', (e) => { |
||||
|
* console.error(e); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v0.3.6 |
||||
|
* @param options Accepts the same `options` as {@link request}, with the `method` always set to `GET`. |
||||
|
*/ |
||||
|
function get( |
||||
|
options: RequestOptions | string | URL, |
||||
|
callback?: (res: http.IncomingMessage) => void, |
||||
|
): http.ClientRequest; |
||||
|
function get( |
||||
|
url: string | URL, |
||||
|
options: RequestOptions, |
||||
|
callback?: (res: http.IncomingMessage) => void, |
||||
|
): http.ClientRequest; |
||||
|
let globalAgent: Agent; |
||||
|
} |
||||
|
declare module "node:https" { |
||||
|
export * from "https"; |
||||
|
} |
||||
@ -0,0 +1,94 @@ |
|||||
|
/** |
||||
|
* License for programmatically and manually incorporated |
||||
|
* documentation aka. `JSDoc` from https://github.com/nodejs/node/tree/master/doc
|
||||
|
* |
||||
|
* Copyright Node.js contributors. All rights reserved. |
||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
* of this software and associated documentation files (the "Software"), to |
||||
|
* deal in the Software without restriction, including without limitation the |
||||
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
||||
|
* sell copies of the Software, and to permit persons to whom the Software is |
||||
|
* furnished to do so, subject to the following conditions: |
||||
|
* |
||||
|
* The above copyright notice and this permission notice shall be included in |
||||
|
* all copies or substantial portions of the Software. |
||||
|
* |
||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
||||
|
* IN THE SOFTWARE. |
||||
|
*/ |
||||
|
|
||||
|
// NOTE: These definitions support Node.js and TypeScript 5.8+.
|
||||
|
|
||||
|
// Reference required TypeScript libraries:
|
||||
|
/// <reference lib="es2020" />
|
||||
|
/// <reference lib="esnext.disposable" />
|
||||
|
/// <reference lib="esnext.float16" />
|
||||
|
|
||||
|
// Iterator definitions required for compatibility with TypeScript <5.6:
|
||||
|
/// <reference path="compatibility/iterators.d.ts" />
|
||||
|
|
||||
|
// Definitions for Node.js modules specific to TypeScript 5.7+:
|
||||
|
/// <reference path="globals.typedarray.d.ts" />
|
||||
|
/// <reference path="buffer.buffer.d.ts" />
|
||||
|
|
||||
|
// Definitions for Node.js modules that are not specific to any version of TypeScript:
|
||||
|
/// <reference path="globals.d.ts" />
|
||||
|
/// <reference path="assert.d.ts" />
|
||||
|
/// <reference path="assert/strict.d.ts" />
|
||||
|
/// <reference path="async_hooks.d.ts" />
|
||||
|
/// <reference path="buffer.d.ts" />
|
||||
|
/// <reference path="child_process.d.ts" />
|
||||
|
/// <reference path="cluster.d.ts" />
|
||||
|
/// <reference path="console.d.ts" />
|
||||
|
/// <reference path="constants.d.ts" />
|
||||
|
/// <reference path="crypto.d.ts" />
|
||||
|
/// <reference path="dgram.d.ts" />
|
||||
|
/// <reference path="diagnostics_channel.d.ts" />
|
||||
|
/// <reference path="dns.d.ts" />
|
||||
|
/// <reference path="dns/promises.d.ts" />
|
||||
|
/// <reference path="dns/promises.d.ts" />
|
||||
|
/// <reference path="domain.d.ts" />
|
||||
|
/// <reference path="dom-events.d.ts" />
|
||||
|
/// <reference path="events.d.ts" />
|
||||
|
/// <reference path="fs.d.ts" />
|
||||
|
/// <reference path="fs/promises.d.ts" />
|
||||
|
/// <reference path="http.d.ts" />
|
||||
|
/// <reference path="http2.d.ts" />
|
||||
|
/// <reference path="https.d.ts" />
|
||||
|
/// <reference path="inspector.d.ts" />
|
||||
|
/// <reference path="module.d.ts" />
|
||||
|
/// <reference path="net.d.ts" />
|
||||
|
/// <reference path="os.d.ts" />
|
||||
|
/// <reference path="path.d.ts" />
|
||||
|
/// <reference path="perf_hooks.d.ts" />
|
||||
|
/// <reference path="process.d.ts" />
|
||||
|
/// <reference path="punycode.d.ts" />
|
||||
|
/// <reference path="querystring.d.ts" />
|
||||
|
/// <reference path="readline.d.ts" />
|
||||
|
/// <reference path="readline/promises.d.ts" />
|
||||
|
/// <reference path="repl.d.ts" />
|
||||
|
/// <reference path="sea.d.ts" />
|
||||
|
/// <reference path="sqlite.d.ts" />
|
||||
|
/// <reference path="stream.d.ts" />
|
||||
|
/// <reference path="stream/promises.d.ts" />
|
||||
|
/// <reference path="stream/consumers.d.ts" />
|
||||
|
/// <reference path="stream/web.d.ts" />
|
||||
|
/// <reference path="string_decoder.d.ts" />
|
||||
|
/// <reference path="test.d.ts" />
|
||||
|
/// <reference path="timers.d.ts" />
|
||||
|
/// <reference path="timers/promises.d.ts" />
|
||||
|
/// <reference path="tls.d.ts" />
|
||||
|
/// <reference path="trace_events.d.ts" />
|
||||
|
/// <reference path="tty.d.ts" />
|
||||
|
/// <reference path="url.d.ts" />
|
||||
|
/// <reference path="util.d.ts" />
|
||||
|
/// <reference path="v8.d.ts" />
|
||||
|
/// <reference path="vm.d.ts" />
|
||||
|
/// <reference path="wasi.d.ts" />
|
||||
|
/// <reference path="worker_threads.d.ts" />
|
||||
|
/// <reference path="zlib.d.ts" />
|
||||
File diff suppressed because it is too large
@ -0,0 +1,893 @@ |
|||||
|
/** |
||||
|
* @since v0.3.7 |
||||
|
*/ |
||||
|
declare module "module" { |
||||
|
import { URL } from "node:url"; |
||||
|
class Module { |
||||
|
constructor(id: string, parent?: Module); |
||||
|
} |
||||
|
interface Module extends NodeJS.Module {} |
||||
|
namespace Module { |
||||
|
export { Module }; |
||||
|
} |
||||
|
namespace Module { |
||||
|
/** |
||||
|
* A list of the names of all modules provided by Node.js. Can be used to verify |
||||
|
* if a module is maintained by a third party or not. |
||||
|
* |
||||
|
* Note: the list doesn't contain prefix-only modules like `node:test`. |
||||
|
* @since v9.3.0, v8.10.0, v6.13.0 |
||||
|
*/ |
||||
|
const builtinModules: readonly string[]; |
||||
|
/** |
||||
|
* @since v12.2.0 |
||||
|
* @param path Filename to be used to construct the require |
||||
|
* function. Must be a file URL object, file URL string, or absolute path |
||||
|
* string. |
||||
|
*/ |
||||
|
function createRequire(path: string | URL): NodeJS.Require; |
||||
|
namespace constants { |
||||
|
/** |
||||
|
* The following constants are returned as the `status` field in the object returned by |
||||
|
* {@link enableCompileCache} to indicate the result of the attempt to enable the |
||||
|
* [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache).
|
||||
|
* @since v22.8.0 |
||||
|
*/ |
||||
|
namespace compileCacheStatus { |
||||
|
/** |
||||
|
* Node.js has enabled the compile cache successfully. The directory used to store the |
||||
|
* compile cache will be returned in the `directory` field in the |
||||
|
* returned object. |
||||
|
*/ |
||||
|
const ENABLED: number; |
||||
|
/** |
||||
|
* The compile cache has already been enabled before, either by a previous call to |
||||
|
* {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir` |
||||
|
* environment variable. The directory used to store the |
||||
|
* compile cache will be returned in the `directory` field in the |
||||
|
* returned object. |
||||
|
*/ |
||||
|
const ALREADY_ENABLED: number; |
||||
|
/** |
||||
|
* Node.js fails to enable the compile cache. This can be caused by the lack of |
||||
|
* permission to use the specified directory, or various kinds of file system errors. |
||||
|
* The detail of the failure will be returned in the `message` field in the |
||||
|
* returned object. |
||||
|
*/ |
||||
|
const FAILED: number; |
||||
|
/** |
||||
|
* Node.js cannot enable the compile cache because the environment variable |
||||
|
* `NODE_DISABLE_COMPILE_CACHE=1` has been set. |
||||
|
*/ |
||||
|
const DISABLED: number; |
||||
|
} |
||||
|
} |
||||
|
interface EnableCompileCacheResult { |
||||
|
/** |
||||
|
* One of the {@link constants.compileCacheStatus} |
||||
|
*/ |
||||
|
status: number; |
||||
|
/** |
||||
|
* If Node.js cannot enable the compile cache, this contains |
||||
|
* the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`. |
||||
|
*/ |
||||
|
message?: string; |
||||
|
/** |
||||
|
* If the compile cache is enabled, this contains the directory |
||||
|
* where the compile cache is stored. Only set if `status` is |
||||
|
* `module.constants.compileCacheStatus.ENABLED` or |
||||
|
* `module.constants.compileCacheStatus.ALREADY_ENABLED`. |
||||
|
*/ |
||||
|
directory?: string; |
||||
|
} |
||||
|
/** |
||||
|
* Enable [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
|
||||
|
* in the current Node.js instance. |
||||
|
* |
||||
|
* If `cacheDir` is not specified, Node.js will either use the directory specified by the |
||||
|
* `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use |
||||
|
* `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's |
||||
|
* recommended to call `module.enableCompileCache()` without specifying the `cacheDir`, |
||||
|
* so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment |
||||
|
* variable when necessary. |
||||
|
* |
||||
|
* Since compile cache is supposed to be a quiet optimization that is not required for the |
||||
|
* application to be functional, this method is designed to not throw any exception when the |
||||
|
* compile cache cannot be enabled. Instead, it will return an object containing an error |
||||
|
* message in the `message` field to aid debugging. |
||||
|
* If compile cache is enabled successfully, the `directory` field in the returned object |
||||
|
* contains the path to the directory where the compile cache is stored. The `status` |
||||
|
* field in the returned object would be one of the `module.constants.compileCacheStatus` |
||||
|
* values to indicate the result of the attempt to enable the |
||||
|
* [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache).
|
||||
|
* |
||||
|
* This method only affects the current Node.js instance. To enable it in child worker threads, |
||||
|
* either call this method in child worker threads too, or set the |
||||
|
* `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can |
||||
|
* be inherited into the child workers. The directory can be obtained either from the |
||||
|
* `directory` field returned by this method, or with {@link getCompileCacheDir}. |
||||
|
* @since v22.8.0 |
||||
|
* @param cacheDir Optional path to specify the directory where the compile cache |
||||
|
* will be stored/retrieved. |
||||
|
*/ |
||||
|
function enableCompileCache(cacheDir?: string): EnableCompileCacheResult; |
||||
|
/** |
||||
|
* Flush the [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
|
||||
|
* accumulated from modules already loaded |
||||
|
* in the current Node.js instance to disk. This returns after all the flushing |
||||
|
* file system operations come to an end, no matter they succeed or not. If there |
||||
|
* are any errors, this will fail silently, since compile cache misses should not |
||||
|
* interfere with the actual operation of the application. |
||||
|
* @since v22.10.0 |
||||
|
*/ |
||||
|
function flushCompileCache(): void; |
||||
|
/** |
||||
|
* @since v22.8.0 |
||||
|
* @return Path to the [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
|
||||
|
* directory if it is enabled, or `undefined` otherwise. |
||||
|
*/ |
||||
|
function getCompileCacheDir(): string | undefined; |
||||
|
/** |
||||
|
* ```text
|
||||
|
* /path/to/project |
||||
|
* ├ packages/ |
||||
|
* ├ bar/ |
||||
|
* ├ bar.js |
||||
|
* └ package.json // name = '@foo/bar'
|
||||
|
* └ qux/ |
||||
|
* ├ node_modules/ |
||||
|
* └ some-package/ |
||||
|
* └ package.json // name = 'some-package'
|
||||
|
* ├ qux.js |
||||
|
* └ package.json // name = '@foo/qux'
|
||||
|
* ├ main.js |
||||
|
* └ package.json // name = '@foo'
|
||||
|
* ``` |
||||
|
* ```js
|
||||
|
* // /path/to/project/packages/bar/bar.js
|
||||
|
* import { findPackageJSON } from 'node:module'; |
||||
|
* |
||||
|
* findPackageJSON('..', import.meta.url); |
||||
|
* // '/path/to/project/package.json'
|
||||
|
* // Same result when passing an absolute specifier instead:
|
||||
|
* findPackageJSON(new URL('../', import.meta.url)); |
||||
|
* findPackageJSON(import.meta.resolve('../')); |
||||
|
* |
||||
|
* findPackageJSON('some-package', import.meta.url); |
||||
|
* // '/path/to/project/packages/bar/node_modules/some-package/package.json'
|
||||
|
* // When passing an absolute specifier, you might get a different result if the
|
||||
|
* // resolved module is inside a subfolder that has nested `package.json`.
|
||||
|
* findPackageJSON(import.meta.resolve('some-package')); |
||||
|
* // '/path/to/project/packages/bar/node_modules/some-package/some-subfolder/package.json'
|
||||
|
* |
||||
|
* findPackageJSON('@foo/qux', import.meta.url); |
||||
|
* // '/path/to/project/packages/qux/package.json'
|
||||
|
* ``` |
||||
|
* @since v22.14.0 |
||||
|
* @param specifier The specifier for the module whose `package.json` to |
||||
|
* retrieve. When passing a _bare specifier_, the `package.json` at the root of |
||||
|
* the package is returned. When passing a _relative specifier_ or an _absolute specifier_, |
||||
|
* the closest parent `package.json` is returned. |
||||
|
* @param base The absolute location (`file:` URL string or FS path) of the |
||||
|
* containing module. For CJS, use `__filename` (not `__dirname`!); for ESM, use |
||||
|
* `import.meta.url`. You do not need to pass it if `specifier` is an _absolute specifier_. |
||||
|
* @returns A path if the `package.json` is found. When `startLocation` |
||||
|
* is a package, the package's root `package.json`; when a relative or unresolved, the closest |
||||
|
* `package.json` to the `startLocation`. |
||||
|
*/ |
||||
|
function findPackageJSON(specifier: string | URL, base?: string | URL): string | undefined; |
||||
|
/** |
||||
|
* @since v18.6.0, v16.17.0 |
||||
|
*/ |
||||
|
function isBuiltin(moduleName: string): boolean; |
||||
|
interface RegisterOptions<Data> { |
||||
|
/** |
||||
|
* If you want to resolve `specifier` relative to a |
||||
|
* base URL, such as `import.meta.url`, you can pass that URL here. This |
||||
|
* property is ignored if the `parentURL` is supplied as the second argument. |
||||
|
* @default 'data:' |
||||
|
*/ |
||||
|
parentURL?: string | URL | undefined; |
||||
|
/** |
||||
|
* Any arbitrary, cloneable JavaScript value to pass into the |
||||
|
* {@link initialize} hook. |
||||
|
*/ |
||||
|
data?: Data | undefined; |
||||
|
/** |
||||
|
* [Transferable objects](https://nodejs.org/docs/latest-v24.x/api/worker_threads.html#portpostmessagevalue-transferlist)
|
||||
|
* to be passed into the `initialize` hook. |
||||
|
*/ |
||||
|
transferList?: any[] | undefined; |
||||
|
} |
||||
|
/* eslint-disable @definitelytyped/no-unnecessary-generics */ |
||||
|
/** |
||||
|
* Register a module that exports hooks that customize Node.js module |
||||
|
* resolution and loading behavior. See |
||||
|
* [Customization hooks](https://nodejs.org/docs/latest-v24.x/api/module.html#customization-hooks).
|
||||
|
* |
||||
|
* This feature requires `--allow-worker` if used with the |
||||
|
* [Permission Model](https://nodejs.org/docs/latest-v24.x/api/permissions.html#permission-model).
|
||||
|
* @since v20.6.0, v18.19.0 |
||||
|
* @param specifier Customization hooks to be registered; this should be |
||||
|
* the same string that would be passed to `import()`, except that if it is |
||||
|
* relative, it is resolved relative to `parentURL`. |
||||
|
* @param parentURL f you want to resolve `specifier` relative to a base |
||||
|
* URL, such as `import.meta.url`, you can pass that URL here. |
||||
|
*/ |
||||
|
function register<Data = any>( |
||||
|
specifier: string | URL, |
||||
|
parentURL?: string | URL, |
||||
|
options?: RegisterOptions<Data>, |
||||
|
): void; |
||||
|
function register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void; |
||||
|
interface RegisterHooksOptions { |
||||
|
/** |
||||
|
* See [load hook](https://nodejs.org/docs/latest-v24.x/api/module.html#loadurl-context-nextload).
|
||||
|
* @default undefined |
||||
|
*/ |
||||
|
load?: LoadHookSync | undefined; |
||||
|
/** |
||||
|
* See [resolve hook](https://nodejs.org/docs/latest-v24.x/api/module.html#resolvespecifier-context-nextresolve).
|
||||
|
* @default undefined |
||||
|
*/ |
||||
|
resolve?: ResolveHookSync | undefined; |
||||
|
} |
||||
|
interface ModuleHooks { |
||||
|
/** |
||||
|
* Deregister the hook instance. |
||||
|
*/ |
||||
|
deregister(): void; |
||||
|
} |
||||
|
/** |
||||
|
* Register [hooks](https://nodejs.org/docs/latest-v24.x/api/module.html#customization-hooks)
|
||||
|
* that customize Node.js module resolution and loading behavior. |
||||
|
* @since v22.15.0 |
||||
|
* @experimental |
||||
|
*/ |
||||
|
function registerHooks(options: RegisterHooksOptions): ModuleHooks; |
||||
|
interface StripTypeScriptTypesOptions { |
||||
|
/** |
||||
|
* Possible values are: |
||||
|
* * `'strip'` Only strip type annotations without performing the transformation of TypeScript features. |
||||
|
* * `'transform'` Strip type annotations and transform TypeScript features to JavaScript. |
||||
|
* @default 'strip' |
||||
|
*/ |
||||
|
mode?: "strip" | "transform" | undefined; |
||||
|
/** |
||||
|
* Only when `mode` is `'transform'`, if `true`, a source map |
||||
|
* will be generated for the transformed code. |
||||
|
* @default false |
||||
|
*/ |
||||
|
sourceMap?: boolean | undefined; |
||||
|
/** |
||||
|
* Specifies the source url used in the source map. |
||||
|
*/ |
||||
|
sourceUrl?: string | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It |
||||
|
* can be used to strip type annotations from TypeScript code before running it |
||||
|
* with `vm.runInContext()` or `vm.compileFunction()`. |
||||
|
* By default, it will throw an error if the code contains TypeScript features |
||||
|
* that require transformation such as `Enums`, |
||||
|
* see [type-stripping](https://nodejs.org/docs/latest-v24.x/api/typescript.md#type-stripping) for more information.
|
||||
|
* When mode is `'transform'`, it also transforms TypeScript features to JavaScript, |
||||
|
* see [transform TypeScript features](https://nodejs.org/docs/latest-v24.x/api/typescript.md#typescript-features) for more information.
|
||||
|
* When mode is `'strip'`, source maps are not generated, because locations are preserved. |
||||
|
* If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown. |
||||
|
* |
||||
|
* _WARNING_: The output of this function should not be considered stable across Node.js versions, |
||||
|
* due to changes in the TypeScript parser. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { stripTypeScriptTypes } from 'node:module'; |
||||
|
* const code = 'const a: number = 1;'; |
||||
|
* const strippedCode = stripTypeScriptTypes(code); |
||||
|
* console.log(strippedCode); |
||||
|
* // Prints: const a = 1;
|
||||
|
* ``` |
||||
|
* |
||||
|
* If `sourceUrl` is provided, it will be used appended as a comment at the end of the output: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { stripTypeScriptTypes } from 'node:module'; |
||||
|
* const code = 'const a: number = 1;'; |
||||
|
* const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' }); |
||||
|
* console.log(strippedCode); |
||||
|
* // Prints: const a = 1\n\n//# sourceURL=source.ts;
|
||||
|
* ``` |
||||
|
* |
||||
|
* When `mode` is `'transform'`, the code is transformed to JavaScript: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { stripTypeScriptTypes } from 'node:module'; |
||||
|
* const code = ` |
||||
|
* namespace MathUtil { |
||||
|
* export const add = (a: number, b: number) => a + b; |
||||
|
* }`;
|
||||
|
* const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true }); |
||||
|
* console.log(strippedCode); |
||||
|
* // Prints:
|
||||
|
* // var MathUtil;
|
||||
|
* // (function(MathUtil) {
|
||||
|
* // MathUtil.add = (a, b)=>a + b;
|
||||
|
* // })(MathUtil || (MathUtil = {}));
|
||||
|
* // # sourceMappingURL=data:application/json;base64, ...
|
||||
|
* ``` |
||||
|
* @since v22.13.0 |
||||
|
* @param code The code to strip type annotations from. |
||||
|
* @returns The code with type annotations stripped. |
||||
|
*/ |
||||
|
function stripTypeScriptTypes(code: string, options?: StripTypeScriptTypesOptions): string; |
||||
|
/* eslint-enable @definitelytyped/no-unnecessary-generics */ |
||||
|
/** |
||||
|
* The `module.syncBuiltinESMExports()` method updates all the live bindings for |
||||
|
* builtin `ES Modules` to match the properties of the `CommonJS` exports. It |
||||
|
* does not add or remove exported names from the `ES Modules`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import fs from 'node:fs'; |
||||
|
* import assert from 'node:assert'; |
||||
|
* import { syncBuiltinESMExports } from 'node:module'; |
||||
|
* |
||||
|
* fs.readFile = newAPI; |
||||
|
* |
||||
|
* delete fs.readFileSync; |
||||
|
* |
||||
|
* function newAPI() { |
||||
|
* // ...
|
||||
|
* } |
||||
|
* |
||||
|
* fs.newAPI = newAPI; |
||||
|
* |
||||
|
* syncBuiltinESMExports(); |
||||
|
* |
||||
|
* import('node:fs').then((esmFS) => { |
||||
|
* // It syncs the existing readFile property with the new value
|
||||
|
* assert.strictEqual(esmFS.readFile, newAPI); |
||||
|
* // readFileSync has been deleted from the required fs
|
||||
|
* assert.strictEqual('readFileSync' in fs, false); |
||||
|
* // syncBuiltinESMExports() does not remove readFileSync from esmFS
|
||||
|
* assert.strictEqual('readFileSync' in esmFS, true); |
||||
|
* // syncBuiltinESMExports() does not add names
|
||||
|
* assert.strictEqual(esmFS.newAPI, undefined); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @since v12.12.0 |
||||
|
*/ |
||||
|
function syncBuiltinESMExports(): void; |
||||
|
interface ImportAttributes extends NodeJS.Dict<string> { |
||||
|
type?: string | undefined; |
||||
|
} |
||||
|
type ModuleFormat = |
||||
|
| "addon" |
||||
|
| "builtin" |
||||
|
| "commonjs" |
||||
|
| "commonjs-typescript" |
||||
|
| "json" |
||||
|
| "module" |
||||
|
| "module-typescript" |
||||
|
| "wasm"; |
||||
|
type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray; |
||||
|
/** |
||||
|
* The `initialize` hook provides a way to define a custom function that runs in |
||||
|
* the hooks thread when the hooks module is initialized. Initialization happens |
||||
|
* when the hooks module is registered via {@link register}. |
||||
|
* |
||||
|
* This hook can receive data from a {@link register} invocation, including |
||||
|
* ports and other transferable objects. The return value of `initialize` can be a |
||||
|
* `Promise`, in which case it will be awaited before the main application thread |
||||
|
* execution resumes. |
||||
|
*/ |
||||
|
type InitializeHook<Data = any> = (data: Data) => void | Promise<void>; |
||||
|
interface ResolveHookContext { |
||||
|
/** |
||||
|
* Export conditions of the relevant `package.json` |
||||
|
*/ |
||||
|
conditions: string[]; |
||||
|
/** |
||||
|
* An object whose key-value pairs represent the assertions for the module to import |
||||
|
*/ |
||||
|
importAttributes: ImportAttributes; |
||||
|
/** |
||||
|
* The module importing this one, or undefined if this is the Node.js entry point |
||||
|
*/ |
||||
|
parentURL: string | undefined; |
||||
|
} |
||||
|
interface ResolveFnOutput { |
||||
|
/** |
||||
|
* A hint to the load hook (it might be ignored); can be an intermediary value. |
||||
|
*/ |
||||
|
format?: string | null | undefined; |
||||
|
/** |
||||
|
* The import attributes to use when caching the module (optional; if excluded the input will be used) |
||||
|
*/ |
||||
|
importAttributes?: ImportAttributes | undefined; |
||||
|
/** |
||||
|
* A signal that this hook intends to terminate the chain of `resolve` hooks. |
||||
|
* @default false |
||||
|
*/ |
||||
|
shortCircuit?: boolean | undefined; |
||||
|
/** |
||||
|
* The absolute URL to which this input resolves |
||||
|
*/ |
||||
|
url: string; |
||||
|
} |
||||
|
/** |
||||
|
* The `resolve` hook chain is responsible for telling Node.js where to find and |
||||
|
* how to cache a given `import` statement or expression, or `require` call. It can |
||||
|
* optionally return a format (such as `'module'`) as a hint to the `load` hook. If |
||||
|
* a format is specified, the `load` hook is ultimately responsible for providing |
||||
|
* the final `format` value (and it is free to ignore the hint provided by |
||||
|
* `resolve`); if `resolve` provides a `format`, a custom `load` hook is required |
||||
|
* even if only to pass the value to the Node.js default `load` hook. |
||||
|
*/ |
||||
|
type ResolveHook = ( |
||||
|
specifier: string, |
||||
|
context: ResolveHookContext, |
||||
|
nextResolve: ( |
||||
|
specifier: string, |
||||
|
context?: Partial<ResolveHookContext>, |
||||
|
) => ResolveFnOutput | Promise<ResolveFnOutput>, |
||||
|
) => ResolveFnOutput | Promise<ResolveFnOutput>; |
||||
|
type ResolveHookSync = ( |
||||
|
specifier: string, |
||||
|
context: ResolveHookContext, |
||||
|
nextResolve: ( |
||||
|
specifier: string, |
||||
|
context?: Partial<ResolveHookContext>, |
||||
|
) => ResolveFnOutput, |
||||
|
) => ResolveFnOutput; |
||||
|
interface LoadHookContext { |
||||
|
/** |
||||
|
* Export conditions of the relevant `package.json` |
||||
|
*/ |
||||
|
conditions: string[]; |
||||
|
/** |
||||
|
* The format optionally supplied by the `resolve` hook chain (can be an intermediary value). |
||||
|
*/ |
||||
|
format: string | null | undefined; |
||||
|
/** |
||||
|
* An object whose key-value pairs represent the assertions for the module to import |
||||
|
*/ |
||||
|
importAttributes: ImportAttributes; |
||||
|
} |
||||
|
interface LoadFnOutput { |
||||
|
format: string | null | undefined; |
||||
|
/** |
||||
|
* A signal that this hook intends to terminate the chain of `resolve` hooks. |
||||
|
* @default false |
||||
|
*/ |
||||
|
shortCircuit?: boolean | undefined; |
||||
|
/** |
||||
|
* The source for Node.js to evaluate |
||||
|
*/ |
||||
|
source?: ModuleSource | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* The `load` hook provides a way to define a custom method of determining how a |
||||
|
* URL should be interpreted, retrieved, and parsed. It is also in charge of |
||||
|
* validating the import attributes. |
||||
|
*/ |
||||
|
type LoadHook = ( |
||||
|
url: string, |
||||
|
context: LoadHookContext, |
||||
|
nextLoad: ( |
||||
|
url: string, |
||||
|
context?: Partial<LoadHookContext>, |
||||
|
) => LoadFnOutput | Promise<LoadFnOutput>, |
||||
|
) => LoadFnOutput | Promise<LoadFnOutput>; |
||||
|
type LoadHookSync = ( |
||||
|
url: string, |
||||
|
context: LoadHookContext, |
||||
|
nextLoad: ( |
||||
|
url: string, |
||||
|
context?: Partial<LoadHookContext>, |
||||
|
) => LoadFnOutput, |
||||
|
) => LoadFnOutput; |
||||
|
interface SourceMapsSupport { |
||||
|
/** |
||||
|
* If the source maps support is enabled |
||||
|
*/ |
||||
|
enabled: boolean; |
||||
|
/** |
||||
|
* If the support is enabled for files in `node_modules`. |
||||
|
*/ |
||||
|
nodeModules: boolean; |
||||
|
/** |
||||
|
* If the support is enabled for generated code from `eval` or `new Function`. |
||||
|
*/ |
||||
|
generatedCode: boolean; |
||||
|
} |
||||
|
/** |
||||
|
* This method returns whether the [Source Map v3](https://tc39.es/ecma426/) support for stack
|
||||
|
* traces is enabled. |
||||
|
* @since v23.7.0, v22.14.0 |
||||
|
*/ |
||||
|
function getSourceMapsSupport(): SourceMapsSupport; |
||||
|
/** |
||||
|
* `path` is the resolved path for the file for which a corresponding source map |
||||
|
* should be fetched. |
||||
|
* @since v13.7.0, v12.17.0 |
||||
|
* @return Returns `module.SourceMap` if a source map is found, `undefined` otherwise. |
||||
|
*/ |
||||
|
function findSourceMap(path: string): SourceMap | undefined; |
||||
|
interface SetSourceMapsSupportOptions { |
||||
|
/** |
||||
|
* If enabling the support for files in `node_modules`. |
||||
|
* @default false |
||||
|
*/ |
||||
|
nodeModules?: boolean | undefined; |
||||
|
/** |
||||
|
* If enabling the support for generated code from `eval` or `new Function`. |
||||
|
* @default false |
||||
|
*/ |
||||
|
generatedCode?: boolean | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* This function enables or disables the [Source Map v3](https://tc39.es/ecma426/) support for
|
||||
|
* stack traces. |
||||
|
* |
||||
|
* It provides same features as launching Node.js process with commandline options |
||||
|
* `--enable-source-maps`, with additional options to alter the support for files |
||||
|
* in `node_modules` or generated codes. |
||||
|
* |
||||
|
* Only source maps in JavaScript files that are loaded after source maps has been |
||||
|
* enabled will be parsed and loaded. Preferably, use the commandline options |
||||
|
* `--enable-source-maps` to avoid losing track of source maps of modules loaded |
||||
|
* before this API call. |
||||
|
* @since v23.7.0, v22.14.0 |
||||
|
*/ |
||||
|
function setSourceMapsSupport(enabled: boolean, options?: SetSourceMapsSupportOptions): void; |
||||
|
interface SourceMapConstructorOptions { |
||||
|
/** |
||||
|
* @since v21.0.0, v20.5.0 |
||||
|
*/ |
||||
|
lineLengths?: readonly number[] | undefined; |
||||
|
} |
||||
|
interface SourceMapPayload { |
||||
|
file: string; |
||||
|
version: number; |
||||
|
sources: string[]; |
||||
|
sourcesContent: string[]; |
||||
|
names: string[]; |
||||
|
mappings: string; |
||||
|
sourceRoot: string; |
||||
|
} |
||||
|
interface SourceMapping { |
||||
|
generatedLine: number; |
||||
|
generatedColumn: number; |
||||
|
originalSource: string; |
||||
|
originalLine: number; |
||||
|
originalColumn: number; |
||||
|
} |
||||
|
interface SourceOrigin { |
||||
|
/** |
||||
|
* The name of the range in the source map, if one was provided |
||||
|
*/ |
||||
|
name: string | undefined; |
||||
|
/** |
||||
|
* The file name of the original source, as reported in the SourceMap |
||||
|
*/ |
||||
|
fileName: string; |
||||
|
/** |
||||
|
* The 1-indexed lineNumber of the corresponding call site in the original source |
||||
|
*/ |
||||
|
lineNumber: number; |
||||
|
/** |
||||
|
* The 1-indexed columnNumber of the corresponding call site in the original source |
||||
|
*/ |
||||
|
columnNumber: number; |
||||
|
} |
||||
|
/** |
||||
|
* @since v13.7.0, v12.17.0 |
||||
|
*/ |
||||
|
class SourceMap { |
||||
|
constructor(payload: SourceMapPayload, options?: SourceMapConstructorOptions); |
||||
|
/** |
||||
|
* Getter for the payload used to construct the `SourceMap` instance. |
||||
|
*/ |
||||
|
readonly payload: SourceMapPayload; |
||||
|
/** |
||||
|
* Given a line offset and column offset in the generated source |
||||
|
* file, returns an object representing the SourceMap range in the |
||||
|
* original file if found, or an empty object if not. |
||||
|
* |
||||
|
* The object returned contains the following keys: |
||||
|
* |
||||
|
* The returned value represents the raw range as it appears in the |
||||
|
* SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and |
||||
|
* column numbers as they appear in Error messages and CallSite |
||||
|
* objects. |
||||
|
* |
||||
|
* To get the corresponding 1-indexed line and column numbers from a |
||||
|
* lineNumber and columnNumber as they are reported by Error stacks |
||||
|
* and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)` |
||||
|
* @param lineOffset The zero-indexed line number offset in the generated source |
||||
|
* @param columnOffset The zero-indexed column number offset in the generated source |
||||
|
*/ |
||||
|
findEntry(lineOffset: number, columnOffset: number): SourceMapping | {}; |
||||
|
/** |
||||
|
* Given a 1-indexed `lineNumber` and `columnNumber` from a call site in the generated source, |
||||
|
* find the corresponding call site location in the original source. |
||||
|
* |
||||
|
* If the `lineNumber` and `columnNumber` provided are not found in any source map, |
||||
|
* then an empty object is returned. |
||||
|
* @param lineNumber The 1-indexed line number of the call site in the generated source |
||||
|
* @param columnNumber The 1-indexed column number of the call site in the generated source |
||||
|
*/ |
||||
|
findOrigin(lineNumber: number, columnNumber: number): SourceOrigin | {}; |
||||
|
} |
||||
|
function runMain(main?: string): void; |
||||
|
function wrap(script: string): string; |
||||
|
} |
||||
|
global { |
||||
|
interface ImportMeta { |
||||
|
/** |
||||
|
* The directory name of the current module. |
||||
|
* |
||||
|
* This is the same as the `path.dirname()` of the `import.meta.filename`. |
||||
|
* |
||||
|
* > **Caveat**: only present on `file:` modules. |
||||
|
* @since v21.2.0, v20.11.0 |
||||
|
*/ |
||||
|
dirname: string; |
||||
|
/** |
||||
|
* The full absolute path and filename of the current module, with |
||||
|
* symlinks resolved. |
||||
|
* |
||||
|
* This is the same as the `url.fileURLToPath()` of the `import.meta.url`. |
||||
|
* |
||||
|
* > **Caveat** only local modules support this property. Modules not using the |
||||
|
* > `file:` protocol will not provide it. |
||||
|
* @since v21.2.0, v20.11.0 |
||||
|
*/ |
||||
|
filename: string; |
||||
|
/** |
||||
|
* The absolute `file:` URL of the module. |
||||
|
* |
||||
|
* This is defined exactly the same as it is in browsers providing the URL of the |
||||
|
* current module file. |
||||
|
* |
||||
|
* This enables useful patterns such as relative file loading: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { readFileSync } from 'node:fs'; |
||||
|
* const buffer = readFileSync(new URL('./data.proto', import.meta.url)); |
||||
|
* ``` |
||||
|
*/ |
||||
|
url: string; |
||||
|
/** |
||||
|
* `import.meta.resolve` is a module-relative resolution function scoped to |
||||
|
* each module, returning the URL string. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const dependencyAsset = import.meta.resolve('component-lib/asset.css'); |
||||
|
* // file:///app/node_modules/component-lib/asset.css
|
||||
|
* import.meta.resolve('./dep.js'); |
||||
|
* // file:///app/dep.js
|
||||
|
* ``` |
||||
|
* |
||||
|
* All features of the Node.js module resolution are supported. Dependency |
||||
|
* resolutions are subject to the permitted exports resolutions within the package. |
||||
|
* |
||||
|
* **Caveats**: |
||||
|
* |
||||
|
* * This can result in synchronous file-system operations, which |
||||
|
* can impact performance similarly to `require.resolve`. |
||||
|
* * This feature is not available within custom loaders (it would |
||||
|
* create a deadlock). |
||||
|
* @since v13.9.0, v12.16.0 |
||||
|
* @param specifier The module specifier to resolve relative to the |
||||
|
* current module. |
||||
|
* @param parent An optional absolute parent module URL to resolve from. |
||||
|
* **Default:** `import.meta.url` |
||||
|
* @returns The absolute URL string that the specifier would resolve to. |
||||
|
*/ |
||||
|
resolve(specifier: string, parent?: string | URL): string; |
||||
|
/** |
||||
|
* `true` when the current module is the entry point of the current process; `false` otherwise. |
||||
|
* |
||||
|
* Equivalent to `require.main === module` in CommonJS. |
||||
|
* |
||||
|
* Analogous to Python's `__name__ == "__main__"`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* export function foo() { |
||||
|
* return 'Hello, world'; |
||||
|
* } |
||||
|
* |
||||
|
* function main() { |
||||
|
* const message = foo(); |
||||
|
* console.log(message); |
||||
|
* } |
||||
|
* |
||||
|
* if (import.meta.main) main(); |
||||
|
* // `foo` can be imported from another module without possible side-effects from `main`
|
||||
|
* ``` |
||||
|
* @since v24.2.0 |
||||
|
* @experimental |
||||
|
*/ |
||||
|
main: boolean; |
||||
|
} |
||||
|
namespace NodeJS { |
||||
|
interface Module { |
||||
|
/** |
||||
|
* The module objects required for the first time by this one. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
children: Module[]; |
||||
|
/** |
||||
|
* The `module.exports` object is created by the `Module` system. Sometimes this is |
||||
|
* not acceptable; many want their module to be an instance of some class. To do |
||||
|
* this, assign the desired export object to `module.exports`. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
exports: any; |
||||
|
/** |
||||
|
* The fully resolved filename of the module. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
filename: string; |
||||
|
/** |
||||
|
* The identifier for the module. Typically this is the fully resolved |
||||
|
* filename. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
id: string; |
||||
|
/** |
||||
|
* `true` if the module is running during the Node.js preload |
||||
|
* phase. |
||||
|
* @since v15.4.0, v14.17.0 |
||||
|
*/ |
||||
|
isPreloading: boolean; |
||||
|
/** |
||||
|
* Whether or not the module is done loading, or is in the process of |
||||
|
* loading. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
loaded: boolean; |
||||
|
/** |
||||
|
* The module that first required this one, or `null` if the current module is the |
||||
|
* entry point of the current process, or `undefined` if the module was loaded by |
||||
|
* something that is not a CommonJS module (e.g. REPL or `import`). |
||||
|
* @since v0.1.16 |
||||
|
* @deprecated Please use `require.main` and `module.children` instead. |
||||
|
*/ |
||||
|
parent: Module | null | undefined; |
||||
|
/** |
||||
|
* The directory name of the module. This is usually the same as the |
||||
|
* `path.dirname()` of the `module.id`. |
||||
|
* @since v11.14.0 |
||||
|
*/ |
||||
|
path: string; |
||||
|
/** |
||||
|
* The search paths for the module. |
||||
|
* @since v0.4.0 |
||||
|
*/ |
||||
|
paths: string[]; |
||||
|
/** |
||||
|
* The `module.require()` method provides a way to load a module as if |
||||
|
* `require()` was called from the original module. |
||||
|
* @since v0.5.1 |
||||
|
*/ |
||||
|
require(id: string): any; |
||||
|
} |
||||
|
interface Require { |
||||
|
/** |
||||
|
* Used to import modules, `JSON`, and local files. |
||||
|
* @since v0.1.13 |
||||
|
*/ |
||||
|
(id: string): any; |
||||
|
/** |
||||
|
* Modules are cached in this object when they are required. By deleting a key |
||||
|
* value from this object, the next `require` will reload the module. |
||||
|
* This does not apply to |
||||
|
* [native addons](https://nodejs.org/docs/latest-v24.x/api/addons.html),
|
||||
|
* for which reloading will result in an error. |
||||
|
* @since v0.3.0 |
||||
|
*/ |
||||
|
cache: Dict<Module>; |
||||
|
/** |
||||
|
* Instruct `require` on how to handle certain file extensions. |
||||
|
* @since v0.3.0 |
||||
|
* @deprecated |
||||
|
*/ |
||||
|
extensions: RequireExtensions; |
||||
|
/** |
||||
|
* The `Module` object representing the entry script loaded when the Node.js |
||||
|
* process launched, or `undefined` if the entry point of the program is not a |
||||
|
* CommonJS module. |
||||
|
* @since v0.1.17 |
||||
|
*/ |
||||
|
main: Module | undefined; |
||||
|
/** |
||||
|
* @since v0.3.0 |
||||
|
*/ |
||||
|
resolve: RequireResolve; |
||||
|
} |
||||
|
/** @deprecated */ |
||||
|
interface RequireExtensions extends Dict<(module: Module, filename: string) => any> { |
||||
|
".js": (module: Module, filename: string) => any; |
||||
|
".json": (module: Module, filename: string) => any; |
||||
|
".node": (module: Module, filename: string) => any; |
||||
|
} |
||||
|
interface RequireResolveOptions { |
||||
|
/** |
||||
|
* Paths to resolve module location from. If present, these |
||||
|
* paths are used instead of the default resolution paths, with the exception |
||||
|
* of |
||||
|
* [GLOBAL\_FOLDERS](https://nodejs.org/docs/latest-v24.x/api/modules.html#loading-from-the-global-folders)
|
||||
|
* like `$HOME/.node_modules`, which are |
||||
|
* always included. Each of these paths is used as a starting point for |
||||
|
* the module resolution algorithm, meaning that the `node_modules` hierarchy |
||||
|
* is checked from this location. |
||||
|
* @since v8.9.0 |
||||
|
*/ |
||||
|
paths?: string[] | undefined; |
||||
|
} |
||||
|
interface RequireResolve { |
||||
|
/** |
||||
|
* Use the internal `require()` machinery to look up the location of a module, |
||||
|
* but rather than loading the module, just return the resolved filename. |
||||
|
* |
||||
|
* If the module can not be found, a `MODULE_NOT_FOUND` error is thrown. |
||||
|
* @since v0.3.0 |
||||
|
* @param request The module path to resolve. |
||||
|
*/ |
||||
|
(request: string, options?: RequireResolveOptions): string; |
||||
|
/** |
||||
|
* Returns an array containing the paths searched during resolution of `request` or |
||||
|
* `null` if the `request` string references a core module, for example `http` or |
||||
|
* `fs`. |
||||
|
* @since v8.9.0 |
||||
|
* @param request The module path whose lookup paths are being retrieved. |
||||
|
*/ |
||||
|
paths(request: string): string[] | null; |
||||
|
} |
||||
|
} |
||||
|
/** |
||||
|
* The directory name of the current module. This is the same as the |
||||
|
* `path.dirname()` of the `__filename`. |
||||
|
* @since v0.1.27 |
||||
|
*/ |
||||
|
var __dirname: string; |
||||
|
/** |
||||
|
* The file name of the current module. This is the current module file's absolute |
||||
|
* path with symlinks resolved. |
||||
|
* |
||||
|
* For a main program this is not necessarily the same as the file name used in the |
||||
|
* command line. |
||||
|
* @since v0.0.1 |
||||
|
*/ |
||||
|
var __filename: string; |
||||
|
/** |
||||
|
* The `exports` variable is available within a module's file-level scope, and is |
||||
|
* assigned the value of `module.exports` before the module is evaluated. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
var exports: NodeJS.Module["exports"]; |
||||
|
/** |
||||
|
* A reference to the current module. |
||||
|
* @since v0.1.16 |
||||
|
*/ |
||||
|
var module: NodeJS.Module; |
||||
|
/** |
||||
|
* @since v0.1.13 |
||||
|
*/ |
||||
|
var require: NodeJS.Require; |
||||
|
// Global-scope aliases for backwards compatibility with @types/node <13.0.x
|
||||
|
// TODO: consider removing in a future major version update
|
||||
|
/** @deprecated Use `NodeJS.Module` instead. */ |
||||
|
interface NodeModule extends NodeJS.Module {} |
||||
|
/** @deprecated Use `NodeJS.Require` instead. */ |
||||
|
interface NodeRequire extends NodeJS.Require {} |
||||
|
/** @deprecated Use `NodeJS.RequireResolve` instead. */ |
||||
|
interface RequireResolve extends NodeJS.RequireResolve {} |
||||
|
} |
||||
|
export = Module; |
||||
|
} |
||||
|
declare module "node:module" { |
||||
|
import module = require("module"); |
||||
|
export = module; |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,496 @@ |
|||||
|
/** |
||||
|
* The `node:os` module provides operating system-related utility methods and |
||||
|
* properties. It can be accessed using: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import os from 'node:os'; |
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/os.js)
|
||||
|
*/ |
||||
|
declare module "os" { |
||||
|
interface CpuInfo { |
||||
|
model: string; |
||||
|
speed: number; |
||||
|
times: { |
||||
|
/** The number of milliseconds the CPU has spent in user mode. */ |
||||
|
user: number; |
||||
|
/** The number of milliseconds the CPU has spent in nice mode. */ |
||||
|
nice: number; |
||||
|
/** The number of milliseconds the CPU has spent in sys mode. */ |
||||
|
sys: number; |
||||
|
/** The number of milliseconds the CPU has spent in idle mode. */ |
||||
|
idle: number; |
||||
|
/** The number of milliseconds the CPU has spent in irq mode. */ |
||||
|
irq: number; |
||||
|
}; |
||||
|
} |
||||
|
interface NetworkInterfaceBase { |
||||
|
address: string; |
||||
|
netmask: string; |
||||
|
mac: string; |
||||
|
internal: boolean; |
||||
|
cidr: string | null; |
||||
|
} |
||||
|
interface NetworkInterfaceInfoIPv4 extends NetworkInterfaceBase { |
||||
|
family: "IPv4"; |
||||
|
scopeid?: undefined; |
||||
|
} |
||||
|
interface NetworkInterfaceInfoIPv6 extends NetworkInterfaceBase { |
||||
|
family: "IPv6"; |
||||
|
scopeid: number; |
||||
|
} |
||||
|
interface UserInfo<T> { |
||||
|
username: T; |
||||
|
uid: number; |
||||
|
gid: number; |
||||
|
shell: T | null; |
||||
|
homedir: T; |
||||
|
} |
||||
|
type NetworkInterfaceInfo = NetworkInterfaceInfoIPv4 | NetworkInterfaceInfoIPv6; |
||||
|
/** |
||||
|
* Returns the host name of the operating system as a string. |
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function hostname(): string; |
||||
|
/** |
||||
|
* Returns an array containing the 1, 5, and 15 minute load averages. |
||||
|
* |
||||
|
* The load average is a measure of system activity calculated by the operating |
||||
|
* system and expressed as a fractional number. |
||||
|
* |
||||
|
* The load average is a Unix-specific concept. On Windows, the return value is |
||||
|
* always `[0, 0, 0]`. |
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function loadavg(): number[]; |
||||
|
/** |
||||
|
* Returns the system uptime in number of seconds. |
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function uptime(): number; |
||||
|
/** |
||||
|
* Returns the amount of free system memory in bytes as an integer. |
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function freemem(): number; |
||||
|
/** |
||||
|
* Returns the total amount of system memory in bytes as an integer. |
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function totalmem(): number; |
||||
|
/** |
||||
|
* Returns an array of objects containing information about each logical CPU core. |
||||
|
* The array will be empty if no CPU information is available, such as if the `/proc` file system is unavailable. |
||||
|
* |
||||
|
* The properties included on each object include: |
||||
|
* |
||||
|
* ```js
|
||||
|
* [ |
||||
|
* { |
||||
|
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', |
||||
|
* speed: 2926, |
||||
|
* times: { |
||||
|
* user: 252020, |
||||
|
* nice: 0, |
||||
|
* sys: 30340, |
||||
|
* idle: 1070356870, |
||||
|
* irq: 0, |
||||
|
* }, |
||||
|
* }, |
||||
|
* { |
||||
|
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', |
||||
|
* speed: 2926, |
||||
|
* times: { |
||||
|
* user: 306960, |
||||
|
* nice: 0, |
||||
|
* sys: 26980, |
||||
|
* idle: 1071569080, |
||||
|
* irq: 0, |
||||
|
* }, |
||||
|
* }, |
||||
|
* { |
||||
|
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', |
||||
|
* speed: 2926, |
||||
|
* times: { |
||||
|
* user: 248450, |
||||
|
* nice: 0, |
||||
|
* sys: 21750, |
||||
|
* idle: 1070919370, |
||||
|
* irq: 0, |
||||
|
* }, |
||||
|
* }, |
||||
|
* { |
||||
|
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz', |
||||
|
* speed: 2926, |
||||
|
* times: { |
||||
|
* user: 256880, |
||||
|
* nice: 0, |
||||
|
* sys: 19430, |
||||
|
* idle: 1070905480, |
||||
|
* irq: 20, |
||||
|
* }, |
||||
|
* }, |
||||
|
* ] |
||||
|
* ``` |
||||
|
* |
||||
|
* `nice` values are POSIX-only. On Windows, the `nice` values of all processors |
||||
|
* are always 0. |
||||
|
* |
||||
|
* `os.cpus().length` should not be used to calculate the amount of parallelism |
||||
|
* available to an application. Use {@link availableParallelism} for this purpose. |
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function cpus(): CpuInfo[]; |
||||
|
/** |
||||
|
* Returns an estimate of the default amount of parallelism a program should use. |
||||
|
* Always returns a value greater than zero. |
||||
|
* |
||||
|
* This function is a small wrapper about libuv's [`uv_available_parallelism()`](https://docs.libuv.org/en/v1.x/misc.html#c.uv_available_parallelism).
|
||||
|
* @since v19.4.0, v18.14.0 |
||||
|
*/ |
||||
|
function availableParallelism(): number; |
||||
|
/** |
||||
|
* Returns the operating system name as returned by [`uname(3)`](https://linux.die.net/man/3/uname). For example, it
|
||||
|
* returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows. |
||||
|
* |
||||
|
* See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for additional information
|
||||
|
* about the output of running [`uname(3)`](https://linux.die.net/man/3/uname) on various operating systems.
|
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function type(): string; |
||||
|
/** |
||||
|
* Returns the operating system as a string. |
||||
|
* |
||||
|
* On POSIX systems, the operating system release is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `GetVersionExW()` is used. See
|
||||
|
* [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
||||
|
* @since v0.3.3 |
||||
|
*/ |
||||
|
function release(): string; |
||||
|
/** |
||||
|
* Returns an object containing network interfaces that have been assigned a |
||||
|
* network address. |
||||
|
* |
||||
|
* Each key on the returned object identifies a network interface. The associated |
||||
|
* value is an array of objects that each describe an assigned network address. |
||||
|
* |
||||
|
* The properties available on the assigned network address object include: |
||||
|
* |
||||
|
* ```js
|
||||
|
* { |
||||
|
* lo: [ |
||||
|
* { |
||||
|
* address: '127.0.0.1', |
||||
|
* netmask: '255.0.0.0', |
||||
|
* family: 'IPv4', |
||||
|
* mac: '00:00:00:00:00:00', |
||||
|
* internal: true, |
||||
|
* cidr: '127.0.0.1/8' |
||||
|
* }, |
||||
|
* { |
||||
|
* address: '::1', |
||||
|
* netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', |
||||
|
* family: 'IPv6', |
||||
|
* mac: '00:00:00:00:00:00', |
||||
|
* scopeid: 0, |
||||
|
* internal: true, |
||||
|
* cidr: '::1/128' |
||||
|
* } |
||||
|
* ], |
||||
|
* eth0: [ |
||||
|
* { |
||||
|
* address: '192.168.1.108', |
||||
|
* netmask: '255.255.255.0', |
||||
|
* family: 'IPv4', |
||||
|
* mac: '01:02:03:0a:0b:0c', |
||||
|
* internal: false, |
||||
|
* cidr: '192.168.1.108/24' |
||||
|
* }, |
||||
|
* { |
||||
|
* address: 'fe80::a00:27ff:fe4e:66a1', |
||||
|
* netmask: 'ffff:ffff:ffff:ffff::', |
||||
|
* family: 'IPv6', |
||||
|
* mac: '01:02:03:0a:0b:0c', |
||||
|
* scopeid: 1, |
||||
|
* internal: false, |
||||
|
* cidr: 'fe80::a00:27ff:fe4e:66a1/64' |
||||
|
* } |
||||
|
* ] |
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v0.6.0 |
||||
|
*/ |
||||
|
function networkInterfaces(): NodeJS.Dict<NetworkInterfaceInfo[]>; |
||||
|
/** |
||||
|
* Returns the string path of the current user's home directory. |
||||
|
* |
||||
|
* On POSIX, it uses the `$HOME` environment variable if defined. Otherwise it |
||||
|
* uses the [effective UID](https://en.wikipedia.org/wiki/User_identifier#Effective_user_ID) to look up the user's home directory.
|
||||
|
* |
||||
|
* On Windows, it uses the `USERPROFILE` environment variable if defined. |
||||
|
* Otherwise it uses the path to the profile directory of the current user. |
||||
|
* @since v2.3.0 |
||||
|
*/ |
||||
|
function homedir(): string; |
||||
|
/** |
||||
|
* Returns information about the currently effective user. On POSIX platforms, |
||||
|
* this is typically a subset of the password file. The returned object includes |
||||
|
* the `username`, `uid`, `gid`, `shell`, and `homedir`. On Windows, the `uid` and `gid` fields are `-1`, and `shell` is `null`. |
||||
|
* |
||||
|
* The value of `homedir` returned by `os.userInfo()` is provided by the operating |
||||
|
* system. This differs from the result of `os.homedir()`, which queries |
||||
|
* environment variables for the home directory before falling back to the |
||||
|
* operating system response. |
||||
|
* |
||||
|
* Throws a [`SystemError`](https://nodejs.org/docs/latest-v24.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`.
|
||||
|
* @since v6.0.0 |
||||
|
*/ |
||||
|
function userInfo(options: { encoding: "buffer" }): UserInfo<Buffer>; |
||||
|
function userInfo(options?: { encoding: BufferEncoding }): UserInfo<string>; |
||||
|
type SignalConstants = { |
||||
|
[key in NodeJS.Signals]: number; |
||||
|
}; |
||||
|
namespace constants { |
||||
|
const UV_UDP_REUSEADDR: number; |
||||
|
namespace signals {} |
||||
|
const signals: SignalConstants; |
||||
|
namespace errno { |
||||
|
const E2BIG: number; |
||||
|
const EACCES: number; |
||||
|
const EADDRINUSE: number; |
||||
|
const EADDRNOTAVAIL: number; |
||||
|
const EAFNOSUPPORT: number; |
||||
|
const EAGAIN: number; |
||||
|
const EALREADY: number; |
||||
|
const EBADF: number; |
||||
|
const EBADMSG: number; |
||||
|
const EBUSY: number; |
||||
|
const ECANCELED: number; |
||||
|
const ECHILD: number; |
||||
|
const ECONNABORTED: number; |
||||
|
const ECONNREFUSED: number; |
||||
|
const ECONNRESET: number; |
||||
|
const EDEADLK: number; |
||||
|
const EDESTADDRREQ: number; |
||||
|
const EDOM: number; |
||||
|
const EDQUOT: number; |
||||
|
const EEXIST: number; |
||||
|
const EFAULT: number; |
||||
|
const EFBIG: number; |
||||
|
const EHOSTUNREACH: number; |
||||
|
const EIDRM: number; |
||||
|
const EILSEQ: number; |
||||
|
const EINPROGRESS: number; |
||||
|
const EINTR: number; |
||||
|
const EINVAL: number; |
||||
|
const EIO: number; |
||||
|
const EISCONN: number; |
||||
|
const EISDIR: number; |
||||
|
const ELOOP: number; |
||||
|
const EMFILE: number; |
||||
|
const EMLINK: number; |
||||
|
const EMSGSIZE: number; |
||||
|
const EMULTIHOP: number; |
||||
|
const ENAMETOOLONG: number; |
||||
|
const ENETDOWN: number; |
||||
|
const ENETRESET: number; |
||||
|
const ENETUNREACH: number; |
||||
|
const ENFILE: number; |
||||
|
const ENOBUFS: number; |
||||
|
const ENODATA: number; |
||||
|
const ENODEV: number; |
||||
|
const ENOENT: number; |
||||
|
const ENOEXEC: number; |
||||
|
const ENOLCK: number; |
||||
|
const ENOLINK: number; |
||||
|
const ENOMEM: number; |
||||
|
const ENOMSG: number; |
||||
|
const ENOPROTOOPT: number; |
||||
|
const ENOSPC: number; |
||||
|
const ENOSR: number; |
||||
|
const ENOSTR: number; |
||||
|
const ENOSYS: number; |
||||
|
const ENOTCONN: number; |
||||
|
const ENOTDIR: number; |
||||
|
const ENOTEMPTY: number; |
||||
|
const ENOTSOCK: number; |
||||
|
const ENOTSUP: number; |
||||
|
const ENOTTY: number; |
||||
|
const ENXIO: number; |
||||
|
const EOPNOTSUPP: number; |
||||
|
const EOVERFLOW: number; |
||||
|
const EPERM: number; |
||||
|
const EPIPE: number; |
||||
|
const EPROTO: number; |
||||
|
const EPROTONOSUPPORT: number; |
||||
|
const EPROTOTYPE: number; |
||||
|
const ERANGE: number; |
||||
|
const EROFS: number; |
||||
|
const ESPIPE: number; |
||||
|
const ESRCH: number; |
||||
|
const ESTALE: number; |
||||
|
const ETIME: number; |
||||
|
const ETIMEDOUT: number; |
||||
|
const ETXTBSY: number; |
||||
|
const EWOULDBLOCK: number; |
||||
|
const EXDEV: number; |
||||
|
const WSAEINTR: number; |
||||
|
const WSAEBADF: number; |
||||
|
const WSAEACCES: number; |
||||
|
const WSAEFAULT: number; |
||||
|
const WSAEINVAL: number; |
||||
|
const WSAEMFILE: number; |
||||
|
const WSAEWOULDBLOCK: number; |
||||
|
const WSAEINPROGRESS: number; |
||||
|
const WSAEALREADY: number; |
||||
|
const WSAENOTSOCK: number; |
||||
|
const WSAEDESTADDRREQ: number; |
||||
|
const WSAEMSGSIZE: number; |
||||
|
const WSAEPROTOTYPE: number; |
||||
|
const WSAENOPROTOOPT: number; |
||||
|
const WSAEPROTONOSUPPORT: number; |
||||
|
const WSAESOCKTNOSUPPORT: number; |
||||
|
const WSAEOPNOTSUPP: number; |
||||
|
const WSAEPFNOSUPPORT: number; |
||||
|
const WSAEAFNOSUPPORT: number; |
||||
|
const WSAEADDRINUSE: number; |
||||
|
const WSAEADDRNOTAVAIL: number; |
||||
|
const WSAENETDOWN: number; |
||||
|
const WSAENETUNREACH: number; |
||||
|
const WSAENETRESET: number; |
||||
|
const WSAECONNABORTED: number; |
||||
|
const WSAECONNRESET: number; |
||||
|
const WSAENOBUFS: number; |
||||
|
const WSAEISCONN: number; |
||||
|
const WSAENOTCONN: number; |
||||
|
const WSAESHUTDOWN: number; |
||||
|
const WSAETOOMANYREFS: number; |
||||
|
const WSAETIMEDOUT: number; |
||||
|
const WSAECONNREFUSED: number; |
||||
|
const WSAELOOP: number; |
||||
|
const WSAENAMETOOLONG: number; |
||||
|
const WSAEHOSTDOWN: number; |
||||
|
const WSAEHOSTUNREACH: number; |
||||
|
const WSAENOTEMPTY: number; |
||||
|
const WSAEPROCLIM: number; |
||||
|
const WSAEUSERS: number; |
||||
|
const WSAEDQUOT: number; |
||||
|
const WSAESTALE: number; |
||||
|
const WSAEREMOTE: number; |
||||
|
const WSASYSNOTREADY: number; |
||||
|
const WSAVERNOTSUPPORTED: number; |
||||
|
const WSANOTINITIALISED: number; |
||||
|
const WSAEDISCON: number; |
||||
|
const WSAENOMORE: number; |
||||
|
const WSAECANCELLED: number; |
||||
|
const WSAEINVALIDPROCTABLE: number; |
||||
|
const WSAEINVALIDPROVIDER: number; |
||||
|
const WSAEPROVIDERFAILEDINIT: number; |
||||
|
const WSASYSCALLFAILURE: number; |
||||
|
const WSASERVICE_NOT_FOUND: number; |
||||
|
const WSATYPE_NOT_FOUND: number; |
||||
|
const WSA_E_NO_MORE: number; |
||||
|
const WSA_E_CANCELLED: number; |
||||
|
const WSAEREFUSED: number; |
||||
|
} |
||||
|
namespace dlopen { |
||||
|
const RTLD_LAZY: number; |
||||
|
const RTLD_NOW: number; |
||||
|
const RTLD_GLOBAL: number; |
||||
|
const RTLD_LOCAL: number; |
||||
|
const RTLD_DEEPBIND: number; |
||||
|
} |
||||
|
namespace priority { |
||||
|
const PRIORITY_LOW: number; |
||||
|
const PRIORITY_BELOW_NORMAL: number; |
||||
|
const PRIORITY_NORMAL: number; |
||||
|
const PRIORITY_ABOVE_NORMAL: number; |
||||
|
const PRIORITY_HIGH: number; |
||||
|
const PRIORITY_HIGHEST: number; |
||||
|
} |
||||
|
} |
||||
|
const devNull: string; |
||||
|
/** |
||||
|
* The operating system-specific end-of-line marker. |
||||
|
* * `\n` on POSIX |
||||
|
* * `\r\n` on Windows |
||||
|
*/ |
||||
|
const EOL: string; |
||||
|
/** |
||||
|
* Returns the operating system CPU architecture for which the Node.js binary was |
||||
|
* compiled. Possible values are `'arm'`, `'arm64'`, `'ia32'`, `'loong64'`, |
||||
|
* `'mips'`, `'mipsel'`, `'ppc64'`, `'riscv64'`, `'s390x'`, and `'x64'`. |
||||
|
* |
||||
|
* The return value is equivalent to [process.arch](https://nodejs.org/docs/latest-v24.x/api/process.html#processarch).
|
||||
|
* @since v0.5.0 |
||||
|
*/ |
||||
|
function arch(): NodeJS.Architecture; |
||||
|
/** |
||||
|
* Returns a string identifying the kernel version. |
||||
|
* |
||||
|
* On POSIX systems, the operating system release is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `RtlGetVersion()` is used, and if it is not
|
||||
|
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
||||
|
* @since v13.11.0, v12.17.0 |
||||
|
*/ |
||||
|
function version(): string; |
||||
|
/** |
||||
|
* Returns a string identifying the operating system platform for which |
||||
|
* the Node.js binary was compiled. The value is set at compile time. |
||||
|
* Possible values are `'aix'`, `'darwin'`, `'freebsd'`, `'linux'`, `'openbsd'`, `'sunos'`, and `'win32'`. |
||||
|
* |
||||
|
* The return value is equivalent to `process.platform`. |
||||
|
* |
||||
|
* The value `'android'` may also be returned if Node.js is built on the Android |
||||
|
* operating system. [Android support is experimental](https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os).
|
||||
|
* @since v0.5.0 |
||||
|
*/ |
||||
|
function platform(): NodeJS.Platform; |
||||
|
/** |
||||
|
* Returns the machine type as a string, such as `arm`, `arm64`, `aarch64`, |
||||
|
* `mips`, `mips64`, `ppc64`, `ppc64le`, `s390x`, `i386`, `i686`, `x86_64`. |
||||
|
* |
||||
|
* On POSIX systems, the machine type is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `RtlGetVersion()` is used, and if it is not
|
||||
|
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
||||
|
* @since v18.9.0, v16.18.0 |
||||
|
*/ |
||||
|
function machine(): string; |
||||
|
/** |
||||
|
* Returns the operating system's default directory for temporary files as a |
||||
|
* string. |
||||
|
* @since v0.9.9 |
||||
|
*/ |
||||
|
function tmpdir(): string; |
||||
|
/** |
||||
|
* Returns a string identifying the endianness of the CPU for which the Node.js |
||||
|
* binary was compiled. |
||||
|
* |
||||
|
* Possible values are `'BE'` for big endian and `'LE'` for little endian. |
||||
|
* @since v0.9.4 |
||||
|
*/ |
||||
|
function endianness(): "BE" | "LE"; |
||||
|
/** |
||||
|
* Returns the scheduling priority for the process specified by `pid`. If `pid` is |
||||
|
* not provided or is `0`, the priority of the current process is returned. |
||||
|
* @since v10.10.0 |
||||
|
* @param [pid=0] The process ID to retrieve scheduling priority for. |
||||
|
*/ |
||||
|
function getPriority(pid?: number): number; |
||||
|
/** |
||||
|
* Attempts to set the scheduling priority for the process specified by `pid`. If `pid` is not provided or is `0`, the process ID of the current process is used. |
||||
|
* |
||||
|
* The `priority` input must be an integer between `-20` (high priority) and `19` (low priority). Due to differences between Unix priority levels and Windows |
||||
|
* priority classes, `priority` is mapped to one of six priority constants in `os.constants.priority`. When retrieving a process priority level, this range |
||||
|
* mapping may cause the return value to be slightly different on Windows. To avoid |
||||
|
* confusion, set `priority` to one of the priority constants. |
||||
|
* |
||||
|
* On Windows, setting priority to `PRIORITY_HIGHEST` requires elevated user |
||||
|
* privileges. Otherwise the set priority will be silently reduced to `PRIORITY_HIGH`. |
||||
|
* @since v10.10.0 |
||||
|
* @param [pid=0] The process ID to set scheduling priority for. |
||||
|
* @param priority The scheduling priority to assign to the process. |
||||
|
*/ |
||||
|
function setPriority(priority: number): void; |
||||
|
function setPriority(pid: number, priority: number): void; |
||||
|
} |
||||
|
declare module "node:os" { |
||||
|
export * from "os"; |
||||
|
} |
||||
@ -0,0 +1,155 @@ |
|||||
|
{ |
||||
|
"name": "@types/node", |
||||
|
"version": "24.3.0", |
||||
|
"description": "TypeScript definitions for node", |
||||
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node", |
||||
|
"license": "MIT", |
||||
|
"contributors": [ |
||||
|
{ |
||||
|
"name": "Microsoft TypeScript", |
||||
|
"githubUsername": "Microsoft", |
||||
|
"url": "https://github.com/Microsoft" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Alberto Schiabel", |
||||
|
"githubUsername": "jkomyno", |
||||
|
"url": "https://github.com/jkomyno" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Andrew Makarov", |
||||
|
"githubUsername": "r3nya", |
||||
|
"url": "https://github.com/r3nya" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Benjamin Toueg", |
||||
|
"githubUsername": "btoueg", |
||||
|
"url": "https://github.com/btoueg" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "David Junger", |
||||
|
"githubUsername": "touffy", |
||||
|
"url": "https://github.com/touffy" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Mohsen Azimi", |
||||
|
"githubUsername": "mohsen1", |
||||
|
"url": "https://github.com/mohsen1" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Nikita Galkin", |
||||
|
"githubUsername": "galkin", |
||||
|
"url": "https://github.com/galkin" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Sebastian Silbermann", |
||||
|
"githubUsername": "eps1lon", |
||||
|
"url": "https://github.com/eps1lon" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Wilco Bakker", |
||||
|
"githubUsername": "WilcoBakker", |
||||
|
"url": "https://github.com/WilcoBakker" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Marcin Kopacz", |
||||
|
"githubUsername": "chyzwar", |
||||
|
"url": "https://github.com/chyzwar" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Trivikram Kamat", |
||||
|
"githubUsername": "trivikr", |
||||
|
"url": "https://github.com/trivikr" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Junxiao Shi", |
||||
|
"githubUsername": "yoursunny", |
||||
|
"url": "https://github.com/yoursunny" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Ilia Baryshnikov", |
||||
|
"githubUsername": "qwelias", |
||||
|
"url": "https://github.com/qwelias" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "ExE Boss", |
||||
|
"githubUsername": "ExE-Boss", |
||||
|
"url": "https://github.com/ExE-Boss" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Piotr Błażejewicz", |
||||
|
"githubUsername": "peterblazejewicz", |
||||
|
"url": "https://github.com/peterblazejewicz" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Anna Henningsen", |
||||
|
"githubUsername": "addaleax", |
||||
|
"url": "https://github.com/addaleax" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Victor Perin", |
||||
|
"githubUsername": "victorperin", |
||||
|
"url": "https://github.com/victorperin" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "NodeJS Contributors", |
||||
|
"githubUsername": "NodeJS", |
||||
|
"url": "https://github.com/NodeJS" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Linus Unnebäck", |
||||
|
"githubUsername": "LinusU", |
||||
|
"url": "https://github.com/LinusU" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "wafuwafu13", |
||||
|
"githubUsername": "wafuwafu13", |
||||
|
"url": "https://github.com/wafuwafu13" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Matteo Collina", |
||||
|
"githubUsername": "mcollina", |
||||
|
"url": "https://github.com/mcollina" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Dmitry Semigradsky", |
||||
|
"githubUsername": "Semigradsky", |
||||
|
"url": "https://github.com/Semigradsky" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "René", |
||||
|
"githubUsername": "Renegade334", |
||||
|
"url": "https://github.com/Renegade334" |
||||
|
}, |
||||
|
{ |
||||
|
"name": "Yagiz Nizipli", |
||||
|
"githubUsername": "anonrig", |
||||
|
"url": "https://github.com/anonrig" |
||||
|
} |
||||
|
], |
||||
|
"main": "", |
||||
|
"types": "index.d.ts", |
||||
|
"typesVersions": { |
||||
|
"<=5.6": { |
||||
|
"*": [ |
||||
|
"ts5.6/*" |
||||
|
] |
||||
|
}, |
||||
|
"<=5.7": { |
||||
|
"*": [ |
||||
|
"ts5.7/*" |
||||
|
] |
||||
|
} |
||||
|
}, |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git", |
||||
|
"directory": "types/node" |
||||
|
}, |
||||
|
"scripts": {}, |
||||
|
"dependencies": { |
||||
|
"undici-types": "~7.10.0" |
||||
|
}, |
||||
|
"peerDependencies": {}, |
||||
|
"typesPublisherContentHash": "1db0510763ba3afd8e54c0591e60a100a7b90926f5d7da28ae32d8f845d725da", |
||||
|
"typeScriptVersion": "5.2" |
||||
|
} |
||||
@ -0,0 +1,200 @@ |
|||||
|
declare module "path/posix" { |
||||
|
import path = require("path"); |
||||
|
export = path; |
||||
|
} |
||||
|
declare module "path/win32" { |
||||
|
import path = require("path"); |
||||
|
export = path; |
||||
|
} |
||||
|
/** |
||||
|
* The `node:path` module provides utilities for working with file and directory |
||||
|
* paths. It can be accessed using: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import path from 'node:path'; |
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/path.js)
|
||||
|
*/ |
||||
|
declare module "path" { |
||||
|
namespace path { |
||||
|
/** |
||||
|
* A parsed path object generated by path.parse() or consumed by path.format(). |
||||
|
*/ |
||||
|
interface ParsedPath { |
||||
|
/** |
||||
|
* The root of the path such as '/' or 'c:\' |
||||
|
*/ |
||||
|
root: string; |
||||
|
/** |
||||
|
* The full directory path such as '/home/user/dir' or 'c:\path\dir' |
||||
|
*/ |
||||
|
dir: string; |
||||
|
/** |
||||
|
* The file name including extension (if any) such as 'index.html' |
||||
|
*/ |
||||
|
base: string; |
||||
|
/** |
||||
|
* The file extension (if any) such as '.html' |
||||
|
*/ |
||||
|
ext: string; |
||||
|
/** |
||||
|
* The file name without extension (if any) such as 'index' |
||||
|
*/ |
||||
|
name: string; |
||||
|
} |
||||
|
interface FormatInputPathObject { |
||||
|
/** |
||||
|
* The root of the path such as '/' or 'c:\' |
||||
|
*/ |
||||
|
root?: string | undefined; |
||||
|
/** |
||||
|
* The full directory path such as '/home/user/dir' or 'c:\path\dir' |
||||
|
*/ |
||||
|
dir?: string | undefined; |
||||
|
/** |
||||
|
* The file name including extension (if any) such as 'index.html' |
||||
|
*/ |
||||
|
base?: string | undefined; |
||||
|
/** |
||||
|
* The file extension (if any) such as '.html' |
||||
|
*/ |
||||
|
ext?: string | undefined; |
||||
|
/** |
||||
|
* The file name without extension (if any) such as 'index' |
||||
|
*/ |
||||
|
name?: string | undefined; |
||||
|
} |
||||
|
interface PlatformPath { |
||||
|
/** |
||||
|
* Normalize a string path, reducing '..' and '.' parts. |
||||
|
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. |
||||
|
* |
||||
|
* @param path string path to normalize. |
||||
|
* @throws {TypeError} if `path` is not a string. |
||||
|
*/ |
||||
|
normalize(path: string): string; |
||||
|
/** |
||||
|
* Join all arguments together and normalize the resulting path. |
||||
|
* |
||||
|
* @param paths paths to join. |
||||
|
* @throws {TypeError} if any of the path segments is not a string. |
||||
|
*/ |
||||
|
join(...paths: string[]): string; |
||||
|
/** |
||||
|
* The right-most parameter is considered {to}. Other parameters are considered an array of {from}. |
||||
|
* |
||||
|
* Starting from leftmost {from} parameter, resolves {to} to an absolute path. |
||||
|
* |
||||
|
* If {to} isn't already absolute, {from} arguments are prepended in right to left order, |
||||
|
* until an absolute path is found. If after using all {from} paths still no absolute path is found, |
||||
|
* the current working directory is used as well. The resulting path is normalized, |
||||
|
* and trailing slashes are removed unless the path gets resolved to the root directory. |
||||
|
* |
||||
|
* @param paths A sequence of paths or path segments. |
||||
|
* @throws {TypeError} if any of the arguments is not a string. |
||||
|
*/ |
||||
|
resolve(...paths: string[]): string; |
||||
|
/** |
||||
|
* The `path.matchesGlob()` method determines if `path` matches the `pattern`. |
||||
|
* @param path The path to glob-match against. |
||||
|
* @param pattern The glob to check the path against. |
||||
|
* @returns Whether or not the `path` matched the `pattern`. |
||||
|
* @throws {TypeError} if `path` or `pattern` are not strings. |
||||
|
* @since v22.5.0 |
||||
|
*/ |
||||
|
matchesGlob(path: string, pattern: string): boolean; |
||||
|
/** |
||||
|
* Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. |
||||
|
* |
||||
|
* If the given {path} is a zero-length string, `false` will be returned. |
||||
|
* |
||||
|
* @param path path to test. |
||||
|
* @throws {TypeError} if `path` is not a string. |
||||
|
*/ |
||||
|
isAbsolute(path: string): boolean; |
||||
|
/** |
||||
|
* Solve the relative path from {from} to {to} based on the current working directory. |
||||
|
* At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve. |
||||
|
* |
||||
|
* @throws {TypeError} if either `from` or `to` is not a string. |
||||
|
*/ |
||||
|
relative(from: string, to: string): string; |
||||
|
/** |
||||
|
* Return the directory name of a path. Similar to the Unix dirname command. |
||||
|
* |
||||
|
* @param path the path to evaluate. |
||||
|
* @throws {TypeError} if `path` is not a string. |
||||
|
*/ |
||||
|
dirname(path: string): string; |
||||
|
/** |
||||
|
* Return the last portion of a path. Similar to the Unix basename command. |
||||
|
* Often used to extract the file name from a fully qualified path. |
||||
|
* |
||||
|
* @param path the path to evaluate. |
||||
|
* @param suffix optionally, an extension to remove from the result. |
||||
|
* @throws {TypeError} if `path` is not a string or if `ext` is given and is not a string. |
||||
|
*/ |
||||
|
basename(path: string, suffix?: string): string; |
||||
|
/** |
||||
|
* Return the extension of the path, from the last '.' to end of string in the last portion of the path. |
||||
|
* If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string. |
||||
|
* |
||||
|
* @param path the path to evaluate. |
||||
|
* @throws {TypeError} if `path` is not a string. |
||||
|
*/ |
||||
|
extname(path: string): string; |
||||
|
/** |
||||
|
* The platform-specific file separator. '\\' or '/'. |
||||
|
*/ |
||||
|
readonly sep: "\\" | "/"; |
||||
|
/** |
||||
|
* The platform-specific file delimiter. ';' or ':'. |
||||
|
*/ |
||||
|
readonly delimiter: ";" | ":"; |
||||
|
/** |
||||
|
* Returns an object from a path string - the opposite of format(). |
||||
|
* |
||||
|
* @param path path to evaluate. |
||||
|
* @throws {TypeError} if `path` is not a string. |
||||
|
*/ |
||||
|
parse(path: string): ParsedPath; |
||||
|
/** |
||||
|
* Returns a path string from an object - the opposite of parse(). |
||||
|
* |
||||
|
* @param pathObject path to evaluate. |
||||
|
*/ |
||||
|
format(pathObject: FormatInputPathObject): string; |
||||
|
/** |
||||
|
* On Windows systems only, returns an equivalent namespace-prefixed path for the given path. |
||||
|
* If path is not a string, path will be returned without modifications. |
||||
|
* This method is meaningful only on Windows system. |
||||
|
* On POSIX systems, the method is non-operational and always returns path without modifications. |
||||
|
*/ |
||||
|
toNamespacedPath(path: string): string; |
||||
|
/** |
||||
|
* Posix specific pathing. |
||||
|
* Same as parent object on posix. |
||||
|
*/ |
||||
|
readonly posix: PlatformPath; |
||||
|
/** |
||||
|
* Windows specific pathing. |
||||
|
* Same as parent object on windows |
||||
|
*/ |
||||
|
readonly win32: PlatformPath; |
||||
|
} |
||||
|
} |
||||
|
const path: path.PlatformPath; |
||||
|
export = path; |
||||
|
} |
||||
|
declare module "node:path" { |
||||
|
import path = require("path"); |
||||
|
export = path; |
||||
|
} |
||||
|
declare module "node:path/posix" { |
||||
|
import path = require("path/posix"); |
||||
|
export = path; |
||||
|
} |
||||
|
declare module "node:path/win32" { |
||||
|
import path = require("path/win32"); |
||||
|
export = path; |
||||
|
} |
||||
@ -0,0 +1,984 @@ |
|||||
|
/** |
||||
|
* This module provides an implementation of a subset of the W3C [Web Performance APIs](https://w3c.github.io/perf-timing-primer/) as well as additional APIs for
|
||||
|
* Node.js-specific performance measurements. |
||||
|
* |
||||
|
* Node.js supports the following [Web Performance APIs](https://w3c.github.io/perf-timing-primer/):
|
||||
|
* |
||||
|
* * [High Resolution Time](https://www.w3.org/TR/hr-time-2)
|
||||
|
* * [Performance Timeline](https://w3c.github.io/performance-timeline/)
|
||||
|
* * [User Timing](https://www.w3.org/TR/user-timing/)
|
||||
|
* * [Resource Timing](https://www.w3.org/TR/resource-timing-2/)
|
||||
|
* |
||||
|
* ```js
|
||||
|
* import { PerformanceObserver, performance } from 'node:perf_hooks'; |
||||
|
* |
||||
|
* const obs = new PerformanceObserver((items) => { |
||||
|
* console.log(items.getEntries()[0].duration); |
||||
|
* performance.clearMarks(); |
||||
|
* }); |
||||
|
* obs.observe({ type: 'measure' }); |
||||
|
* performance.measure('Start to Now'); |
||||
|
* |
||||
|
* performance.mark('A'); |
||||
|
* doSomeLongRunningProcess(() => { |
||||
|
* performance.measure('A to Now', 'A'); |
||||
|
* |
||||
|
* performance.mark('B'); |
||||
|
* performance.measure('A to B', 'A', 'B'); |
||||
|
* }); |
||||
|
* ``` |
||||
|
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/perf_hooks.js)
|
||||
|
*/ |
||||
|
declare module "perf_hooks" { |
||||
|
import { AsyncResource } from "node:async_hooks"; |
||||
|
type EntryType = |
||||
|
| "dns" // Node.js only
|
||||
|
| "function" // Node.js only
|
||||
|
| "gc" // Node.js only
|
||||
|
| "http2" // Node.js only
|
||||
|
| "http" // Node.js only
|
||||
|
| "mark" // available on the Web
|
||||
|
| "measure" // available on the Web
|
||||
|
| "net" // Node.js only
|
||||
|
| "node" // Node.js only
|
||||
|
| "resource"; // available on the Web
|
||||
|
interface NodeGCPerformanceDetail { |
||||
|
/** |
||||
|
* When `performanceEntry.entryType` is equal to 'gc', the `performance.kind` property identifies |
||||
|
* the type of garbage collection operation that occurred. |
||||
|
* See perf_hooks.constants for valid values. |
||||
|
*/ |
||||
|
readonly kind?: number | undefined; |
||||
|
/** |
||||
|
* When `performanceEntry.entryType` is equal to 'gc', the `performance.flags` |
||||
|
* property contains additional information about garbage collection operation. |
||||
|
* See perf_hooks.constants for valid values. |
||||
|
*/ |
||||
|
readonly flags?: number | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* The constructor of this class is not exposed to users directly. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
class PerformanceEntry { |
||||
|
protected constructor(); |
||||
|
/** |
||||
|
* The total number of milliseconds elapsed for this entry. This value will not |
||||
|
* be meaningful for all Performance Entry types. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly duration: number; |
||||
|
/** |
||||
|
* The name of the performance entry. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly name: string; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp marking the starting time of the |
||||
|
* Performance Entry. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly startTime: number; |
||||
|
/** |
||||
|
* The type of the performance entry. It may be one of: |
||||
|
* |
||||
|
* * `'node'` (Node.js only) |
||||
|
* * `'mark'` (available on the Web) |
||||
|
* * `'measure'` (available on the Web) |
||||
|
* * `'gc'` (Node.js only) |
||||
|
* * `'function'` (Node.js only) |
||||
|
* * `'http2'` (Node.js only) |
||||
|
* * `'http'` (Node.js only) |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly entryType: EntryType; |
||||
|
/** |
||||
|
* Additional detail specific to the `entryType`. |
||||
|
* @since v16.0.0 |
||||
|
*/ |
||||
|
readonly detail?: NodeGCPerformanceDetail | unknown | undefined; // TODO: Narrow this based on entry type.
|
||||
|
toJSON(): any; |
||||
|
} |
||||
|
/** |
||||
|
* Exposes marks created via the `Performance.mark()` method. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
class PerformanceMark extends PerformanceEntry { |
||||
|
readonly duration: 0; |
||||
|
readonly entryType: "mark"; |
||||
|
} |
||||
|
/** |
||||
|
* Exposes measures created via the `Performance.measure()` method. |
||||
|
* |
||||
|
* The constructor of this class is not exposed to users directly. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
class PerformanceMeasure extends PerformanceEntry { |
||||
|
readonly entryType: "measure"; |
||||
|
} |
||||
|
interface UVMetrics { |
||||
|
/** |
||||
|
* Number of event loop iterations. |
||||
|
*/ |
||||
|
readonly loopCount: number; |
||||
|
/** |
||||
|
* Number of events that have been processed by the event handler. |
||||
|
*/ |
||||
|
readonly events: number; |
||||
|
/** |
||||
|
* Number of events that were waiting to be processed when the event provider was called. |
||||
|
*/ |
||||
|
readonly eventsWaiting: number; |
||||
|
} |
||||
|
/** |
||||
|
* _This property is an extension by Node.js. It is not available in Web browsers._ |
||||
|
* |
||||
|
* Provides timing details for Node.js itself. The constructor of this class |
||||
|
* is not exposed to users. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
class PerformanceNodeTiming extends PerformanceEntry { |
||||
|
readonly entryType: "node"; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at which the Node.js process |
||||
|
* completed bootstrapping. If bootstrapping has not yet finished, the property |
||||
|
* has the value of -1. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly bootstrapComplete: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at which the Node.js environment was |
||||
|
* initialized. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly environment: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp of the amount of time the event loop |
||||
|
* has been idle within the event loop's event provider (e.g. `epoll_wait`). This |
||||
|
* does not take CPU usage into consideration. If the event loop has not yet |
||||
|
* started (e.g., in the first tick of the main script), the property has the |
||||
|
* value of 0. |
||||
|
* @since v14.10.0, v12.19.0 |
||||
|
*/ |
||||
|
readonly idleTime: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at which the Node.js event loop |
||||
|
* exited. If the event loop has not yet exited, the property has the value of -1\. |
||||
|
* It can only have a value of not -1 in a handler of the `'exit'` event. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly loopExit: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at which the Node.js event loop |
||||
|
* started. If the event loop has not yet started (e.g., in the first tick of the |
||||
|
* main script), the property has the value of -1. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly loopStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at which the Node.js process was initialized. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly nodeStart: number; |
||||
|
/** |
||||
|
* This is a wrapper to the `uv_metrics_info` function. |
||||
|
* It returns the current set of event loop metrics. |
||||
|
* |
||||
|
* It is recommended to use this property inside a function whose execution was |
||||
|
* scheduled using `setImmediate` to avoid collecting metrics before finishing all |
||||
|
* operations scheduled during the current loop iteration. |
||||
|
* @since v22.8.0, v20.18.0 |
||||
|
*/ |
||||
|
readonly uvMetricsInfo: UVMetrics; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at which the V8 platform was |
||||
|
* initialized. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly v8Start: number; |
||||
|
} |
||||
|
interface EventLoopUtilization { |
||||
|
idle: number; |
||||
|
active: number; |
||||
|
utilization: number; |
||||
|
} |
||||
|
/** |
||||
|
* @param utilization1 The result of a previous call to `eventLoopUtilization()`. |
||||
|
* @param utilization2 The result of a previous call to `eventLoopUtilization()` prior to `utilization1`. |
||||
|
*/ |
||||
|
type EventLoopUtilityFunction = ( |
||||
|
utilization1?: EventLoopUtilization, |
||||
|
utilization2?: EventLoopUtilization, |
||||
|
) => EventLoopUtilization; |
||||
|
interface MarkOptions { |
||||
|
/** |
||||
|
* Additional optional detail to include with the mark. |
||||
|
*/ |
||||
|
detail?: unknown | undefined; |
||||
|
/** |
||||
|
* An optional timestamp to be used as the mark time. |
||||
|
* @default `performance.now()` |
||||
|
*/ |
||||
|
startTime?: number | undefined; |
||||
|
} |
||||
|
interface MeasureOptions { |
||||
|
/** |
||||
|
* Additional optional detail to include with the mark. |
||||
|
*/ |
||||
|
detail?: unknown | undefined; |
||||
|
/** |
||||
|
* Duration between start and end times. |
||||
|
*/ |
||||
|
duration?: number | undefined; |
||||
|
/** |
||||
|
* Timestamp to be used as the end time, or a string identifying a previously recorded mark. |
||||
|
*/ |
||||
|
end?: number | string | undefined; |
||||
|
/** |
||||
|
* Timestamp to be used as the start time, or a string identifying a previously recorded mark. |
||||
|
*/ |
||||
|
start?: number | string | undefined; |
||||
|
} |
||||
|
interface TimerifyOptions { |
||||
|
/** |
||||
|
* A histogram object created using `perf_hooks.createHistogram()` that will record runtime |
||||
|
* durations in nanoseconds. |
||||
|
*/ |
||||
|
histogram?: RecordableHistogram | undefined; |
||||
|
} |
||||
|
interface Performance { |
||||
|
/** |
||||
|
* If `name` is not provided, removes all `PerformanceMark` objects from the Performance Timeline. |
||||
|
* If `name` is provided, removes only the named mark. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
clearMarks(name?: string): void; |
||||
|
/** |
||||
|
* If `name` is not provided, removes all `PerformanceMeasure` objects from the Performance Timeline. |
||||
|
* If `name` is provided, removes only the named measure. |
||||
|
* @since v16.7.0 |
||||
|
*/ |
||||
|
clearMeasures(name?: string): void; |
||||
|
/** |
||||
|
* If `name` is not provided, removes all `PerformanceResourceTiming` objects from the Resource Timeline. |
||||
|
* If `name` is provided, removes only the named resource. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
clearResourceTimings(name?: string): void; |
||||
|
/** |
||||
|
* eventLoopUtilization is similar to CPU utilization except that it is calculated using high precision wall-clock time. |
||||
|
* It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait). |
||||
|
* No other CPU idle time is taken into consideration. |
||||
|
*/ |
||||
|
eventLoopUtilization: EventLoopUtilityFunction; |
||||
|
/** |
||||
|
* Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`. |
||||
|
* If you are only interested in performance entries of certain types or that have certain names, see |
||||
|
* `performance.getEntriesByType()` and `performance.getEntriesByName()`. |
||||
|
* @since v16.7.0 |
||||
|
*/ |
||||
|
getEntries(): PerformanceEntry[]; |
||||
|
/** |
||||
|
* Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime` |
||||
|
* whose `performanceEntry.name` is equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to `type`. |
||||
|
* @param name |
||||
|
* @param type |
||||
|
* @since v16.7.0 |
||||
|
*/ |
||||
|
getEntriesByName(name: string, type?: EntryType): PerformanceEntry[]; |
||||
|
/** |
||||
|
* Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime` |
||||
|
* whose `performanceEntry.entryType` is equal to `type`. |
||||
|
* @param type |
||||
|
* @since v16.7.0 |
||||
|
*/ |
||||
|
getEntriesByType(type: EntryType): PerformanceEntry[]; |
||||
|
/** |
||||
|
* Creates a new `PerformanceMark` entry in the Performance Timeline. |
||||
|
* A `PerformanceMark` is a subclass of `PerformanceEntry` whose `performanceEntry.entryType` is always `'mark'`, |
||||
|
* and whose `performanceEntry.duration` is always `0`. |
||||
|
* Performance marks are used to mark specific significant moments in the Performance Timeline. |
||||
|
* |
||||
|
* The created `PerformanceMark` entry is put in the global Performance Timeline and can be queried with |
||||
|
* `performance.getEntries`, `performance.getEntriesByName`, and `performance.getEntriesByType`. When the observation is |
||||
|
* performed, the entries should be cleared from the global Performance Timeline manually with `performance.clearMarks`. |
||||
|
* @param name |
||||
|
*/ |
||||
|
mark(name: string, options?: MarkOptions): PerformanceMark; |
||||
|
/** |
||||
|
* Creates a new `PerformanceResourceTiming` entry in the Resource Timeline. |
||||
|
* A `PerformanceResourceTiming` is a subclass of `PerformanceEntry` whose `performanceEntry.entryType` is always `'resource'`. |
||||
|
* Performance resources are used to mark moments in the Resource Timeline. |
||||
|
* @param timingInfo [Fetch Timing Info](https://fetch.spec.whatwg.org/#fetch-timing-info)
|
||||
|
* @param requestedUrl The resource url |
||||
|
* @param initiatorType The initiator name, e.g: 'fetch' |
||||
|
* @param global |
||||
|
* @param cacheMode The cache mode must be an empty string ('') or 'local' |
||||
|
* @param bodyInfo [Fetch Response Body Info](https://fetch.spec.whatwg.org/#response-body-info)
|
||||
|
* @param responseStatus The response's status code |
||||
|
* @param deliveryType The delivery type. Default: ''. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
markResourceTiming( |
||||
|
timingInfo: object, |
||||
|
requestedUrl: string, |
||||
|
initiatorType: string, |
||||
|
global: object, |
||||
|
cacheMode: "" | "local", |
||||
|
bodyInfo: object, |
||||
|
responseStatus: number, |
||||
|
deliveryType?: string, |
||||
|
): PerformanceResourceTiming; |
||||
|
/** |
||||
|
* Creates a new PerformanceMeasure entry in the Performance Timeline. |
||||
|
* A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure', |
||||
|
* and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark. |
||||
|
* |
||||
|
* The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify |
||||
|
* any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist, |
||||
|
* then startMark is set to timeOrigin by default. |
||||
|
* |
||||
|
* The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp |
||||
|
* properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown. |
||||
|
* @param name |
||||
|
* @param startMark |
||||
|
* @param endMark |
||||
|
* @return The PerformanceMeasure entry that was created |
||||
|
*/ |
||||
|
measure(name: string, startMark?: string, endMark?: string): PerformanceMeasure; |
||||
|
measure(name: string, options: MeasureOptions): PerformanceMeasure; |
||||
|
/** |
||||
|
* _This property is an extension by Node.js. It is not available in Web browsers._ |
||||
|
* |
||||
|
* An instance of the `PerformanceNodeTiming` class that provides performance metrics for specific Node.js operational milestones. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly nodeTiming: PerformanceNodeTiming; |
||||
|
/** |
||||
|
* Returns the current high resolution millisecond timestamp, where 0 represents the start of the current `node` process. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
now(): number; |
||||
|
/** |
||||
|
* Sets the global performance resource timing buffer size to the specified number of "resource" type performance entry objects. |
||||
|
* |
||||
|
* By default the max buffer size is set to 250. |
||||
|
* @since v18.8.0 |
||||
|
*/ |
||||
|
setResourceTimingBufferSize(maxSize: number): void; |
||||
|
/** |
||||
|
* The [`timeOrigin`](https://w3c.github.io/hr-time/#dom-performance-timeorigin) specifies the high resolution millisecond timestamp
|
||||
|
* at which the current `node` process began, measured in Unix time. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
readonly timeOrigin: number; |
||||
|
/** |
||||
|
* _This property is an extension by Node.js. It is not available in Web browsers._ |
||||
|
* |
||||
|
* Wraps a function within a new function that measures the running time of the wrapped function. |
||||
|
* A `PerformanceObserver` must be subscribed to the `'function'` event type in order for the timing details to be accessed. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { |
||||
|
* performance, |
||||
|
* PerformanceObserver, |
||||
|
* } from 'node:perf_hooks'; |
||||
|
* |
||||
|
* function someFunction() { |
||||
|
* console.log('hello world'); |
||||
|
* } |
||||
|
* |
||||
|
* const wrapped = performance.timerify(someFunction); |
||||
|
* |
||||
|
* const obs = new PerformanceObserver((list) => { |
||||
|
* console.log(list.getEntries()[0].duration); |
||||
|
* |
||||
|
* performance.clearMarks(); |
||||
|
* performance.clearMeasures(); |
||||
|
* obs.disconnect(); |
||||
|
* }); |
||||
|
* obs.observe({ entryTypes: ['function'] }); |
||||
|
* |
||||
|
* // A performance timeline entry will be created
|
||||
|
* wrapped(); |
||||
|
* ``` |
||||
|
* |
||||
|
* If the wrapped function returns a promise, a finally handler will be attached to the promise and the duration will be reported |
||||
|
* once the finally handler is invoked. |
||||
|
* @param fn |
||||
|
*/ |
||||
|
timerify<T extends (...params: any[]) => any>(fn: T, options?: TimerifyOptions): T; |
||||
|
/** |
||||
|
* An object which is JSON representation of the performance object. It is similar to |
||||
|
* [`window.performance.toJSON`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/toJSON) in browsers.
|
||||
|
* @since v16.1.0 |
||||
|
*/ |
||||
|
toJSON(): any; |
||||
|
} |
||||
|
class PerformanceObserverEntryList { |
||||
|
/** |
||||
|
* Returns a list of `PerformanceEntry` objects in chronological order |
||||
|
* with respect to `performanceEntry.startTime`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { |
||||
|
* performance, |
||||
|
* PerformanceObserver, |
||||
|
* } from 'node:perf_hooks'; |
||||
|
* |
||||
|
* const obs = new PerformanceObserver((perfObserverList, observer) => { |
||||
|
* console.log(perfObserverList.getEntries()); |
||||
|
* |
||||
|
* * [ |
||||
|
* * PerformanceEntry { |
||||
|
* * name: 'test', |
||||
|
* * entryType: 'mark', |
||||
|
* * startTime: 81.465639, |
||||
|
* * duration: 0, |
||||
|
* * detail: null |
||||
|
* * }, |
||||
|
* * PerformanceEntry { |
||||
|
* * name: 'meow', |
||||
|
* * entryType: 'mark', |
||||
|
* * startTime: 81.860064, |
||||
|
* * duration: 0, |
||||
|
* * detail: null |
||||
|
* * } |
||||
|
* * ] |
||||
|
* |
||||
|
* performance.clearMarks(); |
||||
|
* performance.clearMeasures(); |
||||
|
* observer.disconnect(); |
||||
|
* }); |
||||
|
* obs.observe({ type: 'mark' }); |
||||
|
* |
||||
|
* performance.mark('test'); |
||||
|
* performance.mark('meow'); |
||||
|
* ``` |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
getEntries(): PerformanceEntry[]; |
||||
|
/** |
||||
|
* Returns a list of `PerformanceEntry` objects in chronological order |
||||
|
* with respect to `performanceEntry.startTime` whose `performanceEntry.name` is |
||||
|
* equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to`type`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { |
||||
|
* performance, |
||||
|
* PerformanceObserver, |
||||
|
* } from 'node:perf_hooks'; |
||||
|
* |
||||
|
* const obs = new PerformanceObserver((perfObserverList, observer) => { |
||||
|
* console.log(perfObserverList.getEntriesByName('meow')); |
||||
|
* |
||||
|
* * [ |
||||
|
* * PerformanceEntry { |
||||
|
* * name: 'meow', |
||||
|
* * entryType: 'mark', |
||||
|
* * startTime: 98.545991, |
||||
|
* * duration: 0, |
||||
|
* * detail: null |
||||
|
* * } |
||||
|
* * ] |
||||
|
* |
||||
|
* console.log(perfObserverList.getEntriesByName('nope')); // []
|
||||
|
* |
||||
|
* console.log(perfObserverList.getEntriesByName('test', 'mark')); |
||||
|
* |
||||
|
* * [ |
||||
|
* * PerformanceEntry { |
||||
|
* * name: 'test', |
||||
|
* * entryType: 'mark', |
||||
|
* * startTime: 63.518931, |
||||
|
* * duration: 0, |
||||
|
* * detail: null |
||||
|
* * } |
||||
|
* * ] |
||||
|
* |
||||
|
* console.log(perfObserverList.getEntriesByName('test', 'measure')); // []
|
||||
|
* |
||||
|
* performance.clearMarks(); |
||||
|
* performance.clearMeasures(); |
||||
|
* observer.disconnect(); |
||||
|
* }); |
||||
|
* obs.observe({ entryTypes: ['mark', 'measure'] }); |
||||
|
* |
||||
|
* performance.mark('test'); |
||||
|
* performance.mark('meow'); |
||||
|
* ``` |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
getEntriesByName(name: string, type?: EntryType): PerformanceEntry[]; |
||||
|
/** |
||||
|
* Returns a list of `PerformanceEntry` objects in chronological order |
||||
|
* with respect to `performanceEntry.startTime` whose `performanceEntry.entryType` is equal to `type`. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { |
||||
|
* performance, |
||||
|
* PerformanceObserver, |
||||
|
* } from 'node:perf_hooks'; |
||||
|
* |
||||
|
* const obs = new PerformanceObserver((perfObserverList, observer) => { |
||||
|
* console.log(perfObserverList.getEntriesByType('mark')); |
||||
|
* |
||||
|
* * [ |
||||
|
* * PerformanceEntry { |
||||
|
* * name: 'test', |
||||
|
* * entryType: 'mark', |
||||
|
* * startTime: 55.897834, |
||||
|
* * duration: 0, |
||||
|
* * detail: null |
||||
|
* * }, |
||||
|
* * PerformanceEntry { |
||||
|
* * name: 'meow', |
||||
|
* * entryType: 'mark', |
||||
|
* * startTime: 56.350146, |
||||
|
* * duration: 0, |
||||
|
* * detail: null |
||||
|
* * } |
||||
|
* * ] |
||||
|
* |
||||
|
* performance.clearMarks(); |
||||
|
* performance.clearMeasures(); |
||||
|
* observer.disconnect(); |
||||
|
* }); |
||||
|
* obs.observe({ type: 'mark' }); |
||||
|
* |
||||
|
* performance.mark('test'); |
||||
|
* performance.mark('meow'); |
||||
|
* ``` |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
getEntriesByType(type: EntryType): PerformanceEntry[]; |
||||
|
} |
||||
|
type PerformanceObserverCallback = (list: PerformanceObserverEntryList, observer: PerformanceObserver) => void; |
||||
|
/** |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
class PerformanceObserver extends AsyncResource { |
||||
|
constructor(callback: PerformanceObserverCallback); |
||||
|
/** |
||||
|
* Disconnects the `PerformanceObserver` instance from all notifications. |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
disconnect(): void; |
||||
|
/** |
||||
|
* Subscribes the `PerformanceObserver` instance to notifications of new `PerformanceEntry` instances identified either by `options.entryTypes` or `options.type`: |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { |
||||
|
* performance, |
||||
|
* PerformanceObserver, |
||||
|
* } from 'node:perf_hooks'; |
||||
|
* |
||||
|
* const obs = new PerformanceObserver((list, observer) => { |
||||
|
* // Called once asynchronously. `list` contains three items.
|
||||
|
* }); |
||||
|
* obs.observe({ type: 'mark' }); |
||||
|
* |
||||
|
* for (let n = 0; n < 3; n++) |
||||
|
* performance.mark(`test${n}`); |
||||
|
* ``` |
||||
|
* @since v8.5.0 |
||||
|
*/ |
||||
|
observe( |
||||
|
options: |
||||
|
| { |
||||
|
entryTypes: readonly EntryType[]; |
||||
|
buffered?: boolean | undefined; |
||||
|
} |
||||
|
| { |
||||
|
type: EntryType; |
||||
|
buffered?: boolean | undefined; |
||||
|
}, |
||||
|
): void; |
||||
|
/** |
||||
|
* @since v16.0.0 |
||||
|
* @returns Current list of entries stored in the performance observer, emptying it out. |
||||
|
*/ |
||||
|
takeRecords(): PerformanceEntry[]; |
||||
|
} |
||||
|
/** |
||||
|
* Provides detailed network timing data regarding the loading of an application's resources. |
||||
|
* |
||||
|
* The constructor of this class is not exposed to users directly. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
class PerformanceResourceTiming extends PerformanceEntry { |
||||
|
readonly entryType: "resource"; |
||||
|
protected constructor(); |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp at immediately before dispatching the `fetch` |
||||
|
* request. If the resource is not intercepted by a worker the property will always return 0. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly workerStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp that represents the start time of the fetch which |
||||
|
* initiates the redirect. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly redirectStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp that will be created immediately after receiving |
||||
|
* the last byte of the response of the last redirect. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly redirectEnd: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp immediately before the Node.js starts to fetch the resource. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly fetchStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp immediately before the Node.js starts the domain name lookup |
||||
|
* for the resource. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly domainLookupStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp representing the time immediately after the Node.js finished |
||||
|
* the domain name lookup for the resource. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly domainLookupEnd: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp representing the time immediately before Node.js starts to |
||||
|
* establish the connection to the server to retrieve the resource. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly connectStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp representing the time immediately after Node.js finishes |
||||
|
* establishing the connection to the server to retrieve the resource. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly connectEnd: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp representing the time immediately before Node.js starts the |
||||
|
* handshake process to secure the current connection. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly secureConnectionStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp representing the time immediately before Node.js receives the |
||||
|
* first byte of the response from the server. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly requestStart: number; |
||||
|
/** |
||||
|
* The high resolution millisecond timestamp representing the time immediately after Node.js receives the |
||||
|
* last byte of the resource or immediately before the transport connection is closed, whichever comes first. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly responseEnd: number; |
||||
|
/** |
||||
|
* A number representing the size (in octets) of the fetched resource. The size includes the response header |
||||
|
* fields plus the response payload body. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly transferSize: number; |
||||
|
/** |
||||
|
* A number representing the size (in octets) received from the fetch (HTTP or cache), of the payload body, before |
||||
|
* removing any applied content-codings. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly encodedBodySize: number; |
||||
|
/** |
||||
|
* A number representing the size (in octets) received from the fetch (HTTP or cache), of the message body, after |
||||
|
* removing any applied content-codings. |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
readonly decodedBodySize: number; |
||||
|
/** |
||||
|
* Returns a `object` that is the JSON representation of the `PerformanceResourceTiming` object |
||||
|
* @since v18.2.0, v16.17.0 |
||||
|
*/ |
||||
|
toJSON(): any; |
||||
|
} |
||||
|
namespace constants { |
||||
|
const NODE_PERFORMANCE_GC_MAJOR: number; |
||||
|
const NODE_PERFORMANCE_GC_MINOR: number; |
||||
|
const NODE_PERFORMANCE_GC_INCREMENTAL: number; |
||||
|
const NODE_PERFORMANCE_GC_WEAKCB: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_NO: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_FORCED: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: number; |
||||
|
const NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: number; |
||||
|
} |
||||
|
const performance: Performance; |
||||
|
interface EventLoopMonitorOptions { |
||||
|
/** |
||||
|
* The sampling rate in milliseconds. |
||||
|
* Must be greater than zero. |
||||
|
* @default 10 |
||||
|
*/ |
||||
|
resolution?: number | undefined; |
||||
|
} |
||||
|
interface Histogram { |
||||
|
/** |
||||
|
* The number of samples recorded by the histogram. |
||||
|
* @since v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
readonly count: number; |
||||
|
/** |
||||
|
* The number of samples recorded by the histogram. |
||||
|
* v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
readonly countBigInt: bigint; |
||||
|
/** |
||||
|
* The number of times the event loop delay exceeded the maximum 1 hour event |
||||
|
* loop delay threshold. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
readonly exceeds: number; |
||||
|
/** |
||||
|
* The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold. |
||||
|
* @since v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
readonly exceedsBigInt: bigint; |
||||
|
/** |
||||
|
* The maximum recorded event loop delay. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
readonly max: number; |
||||
|
/** |
||||
|
* The maximum recorded event loop delay. |
||||
|
* v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
readonly maxBigInt: number; |
||||
|
/** |
||||
|
* The mean of the recorded event loop delays. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
readonly mean: number; |
||||
|
/** |
||||
|
* The minimum recorded event loop delay. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
readonly min: number; |
||||
|
/** |
||||
|
* The minimum recorded event loop delay. |
||||
|
* v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
readonly minBigInt: bigint; |
||||
|
/** |
||||
|
* Returns the value at the given percentile. |
||||
|
* @since v11.10.0 |
||||
|
* @param percentile A percentile value in the range (0, 100]. |
||||
|
*/ |
||||
|
percentile(percentile: number): number; |
||||
|
/** |
||||
|
* Returns the value at the given percentile. |
||||
|
* @since v17.4.0, v16.14.0 |
||||
|
* @param percentile A percentile value in the range (0, 100]. |
||||
|
*/ |
||||
|
percentileBigInt(percentile: number): bigint; |
||||
|
/** |
||||
|
* Returns a `Map` object detailing the accumulated percentile distribution. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
readonly percentiles: Map<number, number>; |
||||
|
/** |
||||
|
* Returns a `Map` object detailing the accumulated percentile distribution. |
||||
|
* @since v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
readonly percentilesBigInt: Map<bigint, bigint>; |
||||
|
/** |
||||
|
* Resets the collected histogram data. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
reset(): void; |
||||
|
/** |
||||
|
* The standard deviation of the recorded event loop delays. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
readonly stddev: number; |
||||
|
} |
||||
|
interface IntervalHistogram extends Histogram { |
||||
|
/** |
||||
|
* Enables the update interval timer. Returns `true` if the timer was |
||||
|
* started, `false` if it was already started. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
enable(): boolean; |
||||
|
/** |
||||
|
* Disables the update interval timer. Returns `true` if the timer was |
||||
|
* stopped, `false` if it was already stopped. |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
disable(): boolean; |
||||
|
/** |
||||
|
* Disables the update interval timer when the histogram is disposed. |
||||
|
* |
||||
|
* ```js
|
||||
|
* const { monitorEventLoopDelay } = require('node:perf_hooks'); |
||||
|
* { |
||||
|
* using hist = monitorEventLoopDelay({ resolution: 20 }); |
||||
|
* hist.enable(); |
||||
|
* // The histogram will be disabled when the block is exited.
|
||||
|
* } |
||||
|
* ``` |
||||
|
* @since v24.2.0 |
||||
|
*/ |
||||
|
[Symbol.dispose](): void; |
||||
|
} |
||||
|
interface RecordableHistogram extends Histogram { |
||||
|
/** |
||||
|
* @since v15.9.0, v14.18.0 |
||||
|
* @param val The amount to record in the histogram. |
||||
|
*/ |
||||
|
record(val: number | bigint): void; |
||||
|
/** |
||||
|
* Calculates the amount of time (in nanoseconds) that has passed since the |
||||
|
* previous call to `recordDelta()` and records that amount in the histogram. |
||||
|
* @since v15.9.0, v14.18.0 |
||||
|
*/ |
||||
|
recordDelta(): void; |
||||
|
/** |
||||
|
* Adds the values from `other` to this histogram. |
||||
|
* @since v17.4.0, v16.14.0 |
||||
|
*/ |
||||
|
add(other: RecordableHistogram): void; |
||||
|
} |
||||
|
/** |
||||
|
* _This property is an extension by Node.js. It is not available in Web browsers._ |
||||
|
* |
||||
|
* Creates an `IntervalHistogram` object that samples and reports the event loop |
||||
|
* delay over time. The delays will be reported in nanoseconds. |
||||
|
* |
||||
|
* Using a timer to detect approximate event loop delay works because the |
||||
|
* execution of timers is tied specifically to the lifecycle of the libuv |
||||
|
* event loop. That is, a delay in the loop will cause a delay in the execution |
||||
|
* of the timer, and those delays are specifically what this API is intended to |
||||
|
* detect. |
||||
|
* |
||||
|
* ```js
|
||||
|
* import { monitorEventLoopDelay } from 'node:perf_hooks'; |
||||
|
* const h = monitorEventLoopDelay({ resolution: 20 }); |
||||
|
* h.enable(); |
||||
|
* // Do something.
|
||||
|
* h.disable(); |
||||
|
* console.log(h.min); |
||||
|
* console.log(h.max); |
||||
|
* console.log(h.mean); |
||||
|
* console.log(h.stddev); |
||||
|
* console.log(h.percentiles); |
||||
|
* console.log(h.percentile(50)); |
||||
|
* console.log(h.percentile(99)); |
||||
|
* ``` |
||||
|
* @since v11.10.0 |
||||
|
*/ |
||||
|
function monitorEventLoopDelay(options?: EventLoopMonitorOptions): IntervalHistogram; |
||||
|
interface CreateHistogramOptions { |
||||
|
/** |
||||
|
* The minimum recordable value. Must be an integer value greater than 0. |
||||
|
* @default 1 |
||||
|
*/ |
||||
|
lowest?: number | bigint | undefined; |
||||
|
/** |
||||
|
* The maximum recordable value. Must be an integer value greater than min. |
||||
|
* @default Number.MAX_SAFE_INTEGER |
||||
|
*/ |
||||
|
highest?: number | bigint | undefined; |
||||
|
/** |
||||
|
* The number of accuracy digits. Must be a number between 1 and 5. |
||||
|
* @default 3 |
||||
|
*/ |
||||
|
figures?: number | undefined; |
||||
|
} |
||||
|
/** |
||||
|
* Returns a `RecordableHistogram`. |
||||
|
* @since v15.9.0, v14.18.0 |
||||
|
*/ |
||||
|
function createHistogram(options?: CreateHistogramOptions): RecordableHistogram; |
||||
|
import { |
||||
|
performance as _performance, |
||||
|
PerformanceEntry as _PerformanceEntry, |
||||
|
PerformanceMark as _PerformanceMark, |
||||
|
PerformanceMeasure as _PerformanceMeasure, |
||||
|
PerformanceObserver as _PerformanceObserver, |
||||
|
PerformanceObserverEntryList as _PerformanceObserverEntryList, |
||||
|
PerformanceResourceTiming as _PerformanceResourceTiming, |
||||
|
} from "perf_hooks"; |
||||
|
global { |
||||
|
/** |
||||
|
* `PerformanceEntry` is a global reference for `import { PerformanceEntry } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performanceentry
|
||||
|
* @since v19.0.0 |
||||
|
*/ |
||||
|
var PerformanceEntry: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
PerformanceEntry: infer T; |
||||
|
} ? T |
||||
|
: typeof _PerformanceEntry; |
||||
|
/** |
||||
|
* `PerformanceMark` is a global reference for `import { PerformanceMark } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performancemark
|
||||
|
* @since v19.0.0 |
||||
|
*/ |
||||
|
var PerformanceMark: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
PerformanceMark: infer T; |
||||
|
} ? T |
||||
|
: typeof _PerformanceMark; |
||||
|
/** |
||||
|
* `PerformanceMeasure` is a global reference for `import { PerformanceMeasure } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performancemeasure
|
||||
|
* @since v19.0.0 |
||||
|
*/ |
||||
|
var PerformanceMeasure: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
PerformanceMeasure: infer T; |
||||
|
} ? T |
||||
|
: typeof _PerformanceMeasure; |
||||
|
/** |
||||
|
* `PerformanceObserver` is a global reference for `import { PerformanceObserver } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performanceobserver
|
||||
|
* @since v19.0.0 |
||||
|
*/ |
||||
|
var PerformanceObserver: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
PerformanceObserver: infer T; |
||||
|
} ? T |
||||
|
: typeof _PerformanceObserver; |
||||
|
/** |
||||
|
* `PerformanceObserverEntryList` is a global reference for `import { PerformanceObserverEntryList } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performanceobserverentrylist
|
||||
|
* @since v19.0.0 |
||||
|
*/ |
||||
|
var PerformanceObserverEntryList: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
PerformanceObserverEntryList: infer T; |
||||
|
} ? T |
||||
|
: typeof _PerformanceObserverEntryList; |
||||
|
/** |
||||
|
* `PerformanceResourceTiming` is a global reference for `import { PerformanceResourceTiming } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performanceresourcetiming
|
||||
|
* @since v19.0.0 |
||||
|
*/ |
||||
|
var PerformanceResourceTiming: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
PerformanceResourceTiming: infer T; |
||||
|
} ? T |
||||
|
: typeof _PerformanceResourceTiming; |
||||
|
/** |
||||
|
* `performance` is a global reference for `import { performance } from 'node:perf_hooks'` |
||||
|
* @see https://nodejs.org/docs/latest-v24.x/api/globals.html#performance
|
||||
|
* @since v16.0.0 |
||||
|
*/ |
||||
|
var performance: typeof globalThis extends { |
||||
|
onmessage: any; |
||||
|
performance: infer T; |
||||
|
} ? T |
||||
|
: typeof _performance; |
||||
|
} |
||||
|
} |
||||
|
declare module "node:perf_hooks" { |
||||
|
export * from "perf_hooks"; |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue