├── .github ├── .keep └── workflows │ ├── nightly.yml │ └── test.yml ├── .gitignore ├── .vscode └── settings.json ├── carbon.png ├── examples ├── default │ └── index.mts ├── filesystem │ └── index.mts ├── http │ └── index.mts └── net │ └── index.mts ├── hammer.mjs ├── license ├── package-lock.json ├── package.json ├── readme.md ├── setup.md ├── src ├── ansi │ ├── color.mts │ ├── cursor.mts │ ├── font.mts │ ├── index.mts │ ├── misc.mts │ └── reset.mts ├── assert │ ├── assert.mts │ ├── equal.mts │ ├── guard.mts │ └── index.mts ├── async │ ├── barrier.mts │ ├── debounce.mts │ ├── deferred.mts │ ├── delay.mts │ ├── index.mts │ ├── lock.mts │ ├── mutex.mts │ ├── retry.mts │ ├── semaphore.mts │ └── timeout.mts ├── benchmark │ ├── async.mts │ ├── index.mts │ ├── stopwatch.mts │ └── sync.mts ├── buffer │ ├── buffer.mts │ └── index.mts ├── channel │ ├── channel.mts │ ├── index.mts │ ├── queue.mts │ ├── receiver.mts │ ├── select.mts │ ├── sender.mts │ └── transform.mts ├── config │ ├── config.mts │ └── index.mts ├── crypto │ ├── browser │ │ ├── crypto.mts │ │ └── index.mts │ ├── bun │ │ ├── crypto.mts │ │ └── index.mts │ ├── core │ │ ├── crypto.mts │ │ └── index.mts │ ├── deno │ │ ├── crypto.mts │ │ └── index.mts │ ├── index.mts │ └── node │ │ ├── crypto.mts │ │ └── index.mts ├── dispose │ ├── dispose.mts │ └── index.mts ├── encoding │ ├── encoding.mts │ ├── index.mts │ ├── json │ │ ├── encoding.mts │ │ └── index.mts │ └── msgpack │ │ ├── encoding.mts │ │ └── index.mts ├── events │ ├── event.mts │ ├── events.mts │ ├── handler.mts │ ├── index.mts │ └── listener.mts ├── filesystem │ ├── browser │ │ ├── filesystem.mts │ │ ├── fs.mts │ │ ├── index.mts │ │ └── indexeddb │ │ │ ├── cursor.mts │ │ │ ├── database.mts │ │ │ ├── factory.mts │ │ │ ├── index.mts │ │ │ ├── indexed.mts │ │ │ ├── object-store.mts │ │ │ ├── request.mts │ │ │ └── transaction.mts │ ├── bun │ │ ├── filesystem.mts │ │ ├── fs.mts │ │ └── index.mts │ ├── core │ │ ├── filesystem.mts │ │ ├── fs.mts │ │ ├── index.mts │ │ ├── stat.mts │ │ └── util.mts │ ├── deno │ │ ├── filesystem.mts │ │ ├── fs.mts │ │ └── index.mts │ ├── index.mts │ └── node │ │ ├── filesystem.mts │ │ ├── fs.mts │ │ └── index.mts ├── http │ ├── browser │ │ ├── http.mts │ │ ├── index.mts │ │ ├── listener.mts │ │ └── websocket │ │ │ ├── client.mts │ │ │ ├── index.mts │ │ │ └── server.mts │ ├── bun │ │ ├── http.mts │ │ ├── index.mts │ │ ├── listener.mts │ │ └── websocket │ │ │ ├── client.mts │ │ │ ├── index.mts │ │ │ └── server.mts │ ├── core │ │ ├── http.mts │ │ ├── index.mts │ │ ├── listener.mts │ │ └── websocket │ │ │ ├── client.mts │ │ │ ├── index.mts │ │ │ └── server.mts │ ├── deno │ │ ├── http.mts │ │ ├── index.mts │ │ ├── listener.mts │ │ └── websocket │ │ │ ├── client.mts │ │ │ └── server.mts │ ├── index.mts │ └── node │ │ ├── http.mts │ │ ├── index.mts │ │ ├── listener.mts │ │ ├── request.mts │ │ ├── upgrade.mts │ │ └── websocket │ │ ├── client.mts │ │ ├── index.mts │ │ └── server.mts ├── index.mts ├── net │ ├── browser │ │ ├── index.mts │ │ ├── listener.mts │ │ ├── net.mts │ │ └── socket.mts │ ├── bun │ │ ├── index.mts │ │ ├── listener.mts │ │ ├── net.mts │ │ └── socket.mts │ ├── core │ │ ├── index.mts │ │ ├── listener.mts │ │ ├── net.mts │ │ └── socket.mts │ ├── deno │ │ ├── index.mts │ │ ├── listener.mts │ │ ├── net.mts │ │ └── socket.mts │ ├── index.mts │ └── node │ │ ├── index.mts │ │ ├── listener.mts │ │ ├── net.mts │ │ └── socket.mts ├── os │ ├── index.mts │ └── os.mts ├── path │ ├── common │ │ ├── cwd.mts │ │ ├── env.mts │ │ ├── index.mts │ │ └── util.mts │ ├── core │ │ ├── index.mts │ │ └── path.mts │ ├── index.mts │ ├── posix │ │ ├── index.mts │ │ └── path.mts │ └── windows │ │ ├── index.mts │ │ └── path.mts ├── performance │ ├── browser │ │ ├── index.mts │ │ └── performance.mts │ ├── bun │ │ ├── index.mts │ │ └── performance.mts │ ├── core │ │ ├── index.mts │ │ └── performance.mts │ ├── deno │ │ ├── index.mts │ │ └── performance.mts │ ├── index.mts │ └── node │ │ ├── index.mts │ │ └── performance.mts ├── process │ ├── browser │ │ ├── index.mts │ │ ├── memory.mts │ │ ├── process.mts │ │ ├── stdio.mts │ │ └── tty.mts │ ├── bun │ │ ├── index.mts │ │ ├── memory.mts │ │ ├── process.mts │ │ ├── stdio.mts │ │ └── tty.mts │ ├── core │ │ ├── index.mts │ │ ├── memory.mts │ │ ├── process.mts │ │ ├── stdio.mts │ │ └── tty.mts │ ├── deno │ │ ├── index.mts │ │ ├── memory.mts │ │ ├── process.mts │ │ ├── stdio.mts │ │ └── tty.mts │ ├── index.mts │ └── node │ │ ├── index.mts │ │ ├── memory.mts │ │ ├── process.mts │ │ ├── stdio.mts │ │ └── tty.mts ├── qs │ ├── index.mts │ ├── parse.mts │ └── stringify.mts ├── runtime │ ├── exception.mts │ ├── index.mts │ └── runtime.mts ├── stream │ ├── close.mts │ ├── frame │ │ ├── duplex.mts │ │ ├── index.mts │ │ ├── reader.mts │ │ └── writer.mts │ ├── index.mts │ ├── read.mts │ └── write.mts ├── test │ ├── describe.mts │ ├── failed.mts │ ├── formatter.mts │ ├── index.mts │ ├── it.mts │ ├── options.mts │ ├── reporter.mts │ ├── result.mts │ └── test.mts ├── tsconfig.json ├── type │ ├── compiler │ │ └── index.mts │ └── index.mts ├── types │ ├── bun.d.ts │ ├── deno.d.ts │ └── index.d.ts ├── url │ ├── index.mts │ ├── parse.mts │ └── url.mts └── value │ └── index.mts ├── test ├── async │ ├── barrier.mts │ ├── debounce.mts │ ├── delay.mts │ ├── index.mts │ ├── mutex.mts │ ├── semaphore.mts │ └── timeout.mts ├── buffer │ ├── buffer.mts │ └── index.mts ├── channel │ ├── channel.mts │ ├── index.mts │ └── select.mts ├── crypto │ ├── crypto.mts │ └── index.mts ├── encoding │ ├── index.mts │ ├── json.mts │ └── msgpack.mts ├── events │ ├── event.mts │ ├── events.mts │ └── index.mts ├── filesystem │ ├── filesystem.mts │ └── index.mts ├── http │ ├── index.mts │ ├── listener │ │ ├── index.mts │ │ └── listener.mts │ ├── request │ │ ├── index.mts │ │ ├── info.mts │ │ ├── properties.mts │ │ └── readable.mts │ ├── response │ │ ├── arraybuffer.mts │ │ ├── index.mts │ │ ├── json.mts │ │ ├── properties.mts │ │ └── text.mts │ └── websocket │ │ ├── client │ │ ├── index.mts │ │ ├── message-event.mts │ │ └── properties.mts │ │ ├── index.mts │ │ └── server │ │ ├── index.mts │ │ ├── message-event.mts │ │ └── properties.mts ├── index.mts ├── net │ ├── index.mts │ └── listener.mts ├── os │ ├── index.mts │ └── os.mts ├── performance │ ├── index.mts │ └── performance.mts └── tsconfig.json └── tsconfig.json /.github/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinclairzx81/carbon/edfbce13ffea6846eaa0006747e141a936dcaa04/.github/.keep -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | target 3 | filedata -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "node_modules": true, 4 | "package-lock.json": true 5 | }, 6 | "typescript.tsdk": "node_modules/typescript/lib" 7 | } -------------------------------------------------------------------------------- /carbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinclairzx81/carbon/edfbce13ffea6846eaa0006747e141a936dcaa04/carbon.png -------------------------------------------------------------------------------- /examples/default/index.mts: -------------------------------------------------------------------------------- 1 | // todo: scripting here 2 | 3 | console.log('hello world') 4 | -------------------------------------------------------------------------------- /examples/filesystem/index.mts: -------------------------------------------------------------------------------- 1 | import { FileSystem, Buffer } from '@sinclair/carbon' 2 | 3 | // open directory as file system root 4 | const fs = await FileSystem.open('filedata') 5 | 6 | // write a file to the root 7 | await fs.write('hello/world.txt', Buffer.encode('hello world')) 8 | 9 | // read a file from the root 10 | console.log(Buffer.decode(await fs.read('hello/world.txt'))) 11 | 12 | // delete the file 13 | await fs.delete('hello/world.txt') 14 | 15 | // close the file system 16 | await fs.close() 17 | -------------------------------------------------------------------------------- /examples/http/index.mts: -------------------------------------------------------------------------------- 1 | import { Http } from '@sinclair/carbon' 2 | 3 | // listen on the given port 4 | const listener = await Http.listen({ port: 5000 }, (request) => { 5 | return new Response('hello world') 6 | }) 7 | 8 | // fetch 9 | const message = await Http.fetch(`http://localhost:5000`).then((res) => res.text()) 10 | 11 | console.log(message) 12 | 13 | // dispose of the listener 14 | await listener.dispose() 15 | -------------------------------------------------------------------------------- /examples/net/index.mts: -------------------------------------------------------------------------------- 1 | import { Buffer, Net } from '@sinclair/carbon' 2 | 3 | // start listener on port 5002 4 | const listener = await Net.listen({ port: 5002 }, (socket) => { 5 | socket.write(Buffer.encode('hello 1\n')) 6 | socket.write(Buffer.encode('hello 2\n')) 7 | socket.write(Buffer.encode('hello 3\n')) 8 | socket.close() 9 | }) 10 | 11 | // connect to listener and receive data. 12 | const socket = await Net.connect({ port: 5002 }) 13 | for await (const buffer of socket) { 14 | console.log(Buffer.decode(buffer)) 15 | } 16 | console.log('done') 17 | 18 | await listener.dispose() 19 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | @sinclair/carbon 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2024 Haydn Paterson (sinclair) 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. -------------------------------------------------------------------------------- /setup.md: -------------------------------------------------------------------------------- 1 | # Carbon Development Setup 2 | 3 | Carbon was developed on Ubuntu 22.04.2 LTS running on WSL2, however any Linux distribution should be fine. This projects package.json is configured to run the various example scripts across each runtime which is how new functionality is tested interactively. It is also configured to run unit tests across each runtime. Before running any of these, you will need to install the following. 4 | 5 | ## Chrome 6 | 7 | The following installs Chrome 8 | 9 | ```bash 10 | $ sudo apt-get install libxss1 libappindicator1 libindicator7 11 | $ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 12 | $ sudo apt install ./google-chrome*.deb -y 13 | ``` 14 | 15 | ## Node 16 | 17 | The following installs Node 18 | 19 | ```bash 20 | $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash 21 | $ nvm install --lts 22 | 23 | ``` 24 | ## Bun 25 | 26 | The following installs Bun 27 | 28 | ```bash 29 | $ curl -fsSL https://bun.sh/install | bash 30 | ``` 31 | 32 | ## Deno 33 | 34 | The following installs Deno 35 | 36 | ```bash 37 | curl -fsSL https://deno.land/x/install/install.sh | sh 38 | ``` -------------------------------------------------------------------------------- /src/ansi/cursor.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export namespace cursor { 30 | const csi = '\x1b[' 31 | export const up = (n: number = 1) => `${csi}${n}A` 32 | export const down = (n: number = 1) => `${csi}${n}B` 33 | export const forward = (n: number = 1) => `${csi}${n}C` 34 | export const backward = (n: number = 1) => `${csi}${n}D` 35 | export const nextLine = (n: number = 1) => `${csi}${n}E` 36 | export const previousLine = (n: number = 1) => `${csi}${n}F` 37 | export const horizontalAbsolute = (n: number) => `${csi}${n}G` 38 | export const position = (n: number) => `${csi}${n}H` 39 | export const hide = `${csi}?25l` 40 | export const show = `${csi}?25h` 41 | } 42 | -------------------------------------------------------------------------------- /src/ansi/font.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export namespace font { 30 | export const bold = '\x1b[1m' 31 | export const italic = '\x1b[3m' 32 | export const underline = '\x1b[4m' 33 | export const font1 = '\x1b[10m' 34 | export const font2 = '\x1b[11m' 35 | export const font3 = '\x1b[12m' 36 | export const font4 = '\x1b[13m' 37 | export const font5 = '\x1b[14m' 38 | export const font6 = '\x1b[15m' 39 | } 40 | -------------------------------------------------------------------------------- /src/ansi/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './color.mjs' 30 | export * from './cursor.mjs' 31 | export * from './font.mjs' 32 | export * from './misc.mjs' 33 | export * from './reset.mjs' 34 | -------------------------------------------------------------------------------- /src/ansi/misc.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export namespace misc { 30 | export const imageNegative = '\x1b[7m' 31 | export const imagePositive = '\x1b[27m' 32 | } 33 | -------------------------------------------------------------------------------- /src/ansi/reset.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export const reset = '\x1b[0m' 30 | -------------------------------------------------------------------------------- /src/assert/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './assert.mjs' 30 | -------------------------------------------------------------------------------- /src/async/delay.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /** Returns a promise that resolves after the given milliseconds have elapsed. */ 30 | export function delay(timeout: number) { 31 | return new Promise((resolve) => setTimeout(resolve, timeout)) 32 | } 33 | -------------------------------------------------------------------------------- /src/async/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './barrier.mjs' 30 | export * from './debounce.mjs' 31 | export * from './deferred.mjs' 32 | export * from './delay.mjs' 33 | export * from './lock.mjs' 34 | export * from './mutex.mjs' 35 | export * from './semaphore.mjs' 36 | export * from './timeout.mjs' 37 | export * from './retry.mjs' 38 | -------------------------------------------------------------------------------- /src/async/lock.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /** A lock to some resource */ 30 | export class Lock { 31 | #resolve: Function 32 | constructor(resolve: Function) { 33 | this.#resolve = resolve 34 | } 35 | [Symbol.dispose]() { 36 | this.dispose() 37 | } 38 | /** Disposes of this lock */ 39 | public dispose() { 40 | this.#resolve() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/benchmark/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './async.mjs' 30 | export * from './stopwatch.mjs' 31 | export * from './sync.mjs' 32 | -------------------------------------------------------------------------------- /src/benchmark/stopwatch.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Performance from '../performance/index.mjs' 30 | 31 | /** A stopwatch to measure the elapsed time from the last reset */ 32 | export class Stopwatch { 33 | #started: number 34 | constructor() { 35 | this.#started = Performance.now() 36 | } 37 | /** Resets the stopwatch to now */ 38 | public reset(): void { 39 | this.#started = Performance.now() 40 | } 41 | /** Returns the elapsed time since creation or reset */ 42 | public elapsed(): number { 43 | return Performance.now() - this.#started 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/buffer/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './buffer.mjs' 30 | -------------------------------------------------------------------------------- /src/channel/channel.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import { TransformChannel } from './transform.mjs' 30 | 31 | /** An multi-sender, single receiver channel that supports sending and receiving values asynchronously */ 32 | export class Channel extends TransformChannel { 33 | constructor() { 34 | super((value) => value) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/channel/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './channel.mjs' 30 | export * from './receiver.mjs' 31 | export * from './select.mjs' 32 | export * from './sender.mjs' 33 | export * from './transform.mjs' 34 | -------------------------------------------------------------------------------- /src/channel/receiver.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface Receiver { 30 | /** Async iterator for this receiver */ 31 | [Symbol.asyncIterator](): AsyncGenerator 32 | /** Returns the next value from this channel or null if EOF. */ 33 | receive(): Promise 34 | } 35 | -------------------------------------------------------------------------------- /src/channel/sender.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface Sender { 30 | /** Sends the given value to this channel. If channel has ended no action. */ 31 | send(value: T): void 32 | /** Sends the given error to this channel causing the receiver to throw on next(). If channel has ended no action. */ 33 | error(error: Error): void 34 | /** Ends this channel. */ 35 | end(): void 36 | } 37 | -------------------------------------------------------------------------------- /src/config/config.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /** 30 | * A delay before resolving calls to close() on network listeners. This setting 31 | * helps to ensure that ports are released by the operating system. It's noted 32 | * that runtimes cannot guarantee when the operating has freed a port, increase 33 | * this value if observing "port in use" errors. 34 | * 35 | * Default is 50 ms 36 | */ 37 | export let listenerCloseDelay = 50 38 | -------------------------------------------------------------------------------- /src/config/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './config.mjs' 30 | -------------------------------------------------------------------------------- /src/crypto/browser/crypto.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export function getRandomValues(array: T): T { 30 | return globalThis.crypto.getRandomValues(array) 31 | } 32 | export function randomUUID(): string { 33 | return globalThis.crypto.randomUUID() 34 | } 35 | 36 | export const subtle = globalThis.crypto.subtle 37 | -------------------------------------------------------------------------------- /src/crypto/browser/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './crypto.mjs' 30 | -------------------------------------------------------------------------------- /src/crypto/bun/crypto.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export function getRandomValues(array: T): T { 30 | return globalThis.crypto.getRandomValues(array) 31 | } 32 | 33 | export function randomUUID(): string { 34 | return globalThis.crypto.randomUUID() 35 | } 36 | 37 | export const subtle = globalThis.crypto.subtle 38 | -------------------------------------------------------------------------------- /src/crypto/bun/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './crypto.mjs' 30 | -------------------------------------------------------------------------------- /src/crypto/core/crypto.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export declare function getRandomValues(array: T): T 30 | 31 | export declare function randomUUID(): string 32 | 33 | export declare const subtle: SubtleCrypto 34 | -------------------------------------------------------------------------------- /src/crypto/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './crypto.mjs' 30 | -------------------------------------------------------------------------------- /src/crypto/deno/crypto.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export function getRandomValues(array: T): T { 30 | return globalThis.crypto.getRandomValues(array) 31 | } 32 | export function randomUUID(): string { 33 | return globalThis.crypto.randomUUID() 34 | } 35 | export const subtle = globalThis.crypto.subtle 36 | -------------------------------------------------------------------------------- /src/crypto/deno/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './crypto.mjs' 30 | -------------------------------------------------------------------------------- /src/crypto/node/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './crypto.mjs' 30 | -------------------------------------------------------------------------------- /src/dispose/dispose.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface Dispose { 30 | [Symbol.asyncDispose](): Promise 31 | dispose(): Promise 32 | } 33 | -------------------------------------------------------------------------------- /src/dispose/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './dispose.mjs' 30 | -------------------------------------------------------------------------------- /src/encoding/encoding.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface Encoding { 30 | decode(value: Uint8Array): unknown 31 | encode(value: unknown): Uint8Array 32 | } 33 | -------------------------------------------------------------------------------- /src/encoding/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './json/index.mjs' 30 | export * from './msgpack/index.mjs' 31 | export * from './encoding.mjs' 32 | -------------------------------------------------------------------------------- /src/encoding/json/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './encoding.mjs' 30 | -------------------------------------------------------------------------------- /src/encoding/msgpack/encoding.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import { encode, decode } from '@msgpack/msgpack' 30 | import { Encoding } from '../encoding.mjs' 31 | 32 | export class MsgPackEncoding implements Encoding { 33 | public decode(value: Uint8Array): unknown { 34 | return decode(value) 35 | } 36 | public encode(value: unknown): Uint8Array { 37 | return encode(value) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/encoding/msgpack/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './encoding.mjs' 30 | -------------------------------------------------------------------------------- /src/events/handler.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export type EventHandler = (value: T) => any 30 | -------------------------------------------------------------------------------- /src/events/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './event.mjs' 30 | export * from './events.mjs' 31 | export * from './handler.mjs' 32 | export * from './listener.mjs' 33 | -------------------------------------------------------------------------------- /src/events/listener.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export class EventListener { 30 | readonly #callback: () => any 31 | constructor(callback: () => any) { 32 | this.#callback = callback 33 | } 34 | /** Disposes of this event listener */ 35 | public dispose() { 36 | this.#callback() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/filesystem/browser/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './filesystem.mjs' 30 | export * from './fs.mjs' 31 | -------------------------------------------------------------------------------- /src/filesystem/browser/indexeddb/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './cursor.mjs' 30 | export * from './database.mjs' 31 | export * from './factory.mjs' 32 | export * from './indexed.mjs' 33 | export * from './object-store.mjs' 34 | export * from './request.mjs' 35 | export * from './transaction.mjs' 36 | -------------------------------------------------------------------------------- /src/filesystem/browser/indexeddb/request.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export type Result = T extends IDBRequest ? U : never 30 | 31 | /** Remaps a IDB Request into a Promise */ 32 | export function Request>(request: T): Promise> { 33 | return new Promise((resolve, reject) => { 34 | request.addEventListener('success', () => resolve(request.result)) 35 | request.addEventListener('error', (event) => reject(event)) 36 | }) 37 | } 38 | -------------------------------------------------------------------------------- /src/filesystem/bun/fs.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | import { FileSystem } from './filesystem.mjs' 31 | 32 | const Fs = await Runtime.dynamicImport('node:fs') 33 | 34 | export async function remove(path: string): Promise { 35 | const stat = await Fs.promises.stat(path).catch(() => null) 36 | if (stat === null || !stat.isDirectory()) return 37 | await Fs.promises.rm(path, { recursive: true, force: true }) 38 | } 39 | 40 | /** Creates a file system root at the given path */ 41 | export async function open(path: string): Promise { 42 | return new FileSystem(path) 43 | } 44 | -------------------------------------------------------------------------------- /src/filesystem/bun/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './filesystem.mjs' 30 | export * from './fs.mjs' 31 | -------------------------------------------------------------------------------- /src/filesystem/core/fs.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import { FileSystem } from './filesystem.mjs' 30 | 31 | /** 32 | * Deletes a FileSystem. This function will delete the directory at the given path. 33 | */ 34 | export declare function remove(path: string): Promise 35 | 36 | /** 37 | * Opens a directory or database as a FileSystem root. 38 | */ 39 | export declare function open(path: string): Promise 40 | -------------------------------------------------------------------------------- /src/filesystem/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './filesystem.mjs' 30 | export * from './fs.mjs' 31 | export * from './stat.mjs' 32 | -------------------------------------------------------------------------------- /src/filesystem/core/stat.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface DirectoryStat { 30 | type: 'directory' 31 | path: string 32 | } 33 | export interface FileStat { 34 | type: 'file' 35 | path: string 36 | created: number 37 | size: number 38 | } 39 | 40 | export type Stat = DirectoryStat | FileStat 41 | -------------------------------------------------------------------------------- /src/filesystem/deno/fs.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import { FileSystem } from './filesystem.mjs' 30 | 31 | export async function remove(path: string): Promise { 32 | const stat = await Deno.stat(path).catch(() => null) 33 | if (stat === null || !stat.isDirectory) return 34 | await Deno.remove(path, { recursive: true }) 35 | } 36 | export async function open(path: string): Promise { 37 | return new FileSystem(path) 38 | } 39 | -------------------------------------------------------------------------------- /src/filesystem/deno/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './filesystem.mjs' 30 | export * from './fs.mjs' 31 | -------------------------------------------------------------------------------- /src/filesystem/node/fs.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | import { FileSystem } from './filesystem.mjs' 31 | 32 | const Fs = await Runtime.dynamicImport('node:fs') 33 | 34 | export async function remove(path: string): Promise { 35 | const stat = await Fs.promises.stat(path).catch(() => null) 36 | if (stat === null || !stat.isDirectory()) return 37 | await Fs.promises.rm(path, { recursive: true, force: true }) 38 | } 39 | export async function open(path: string): Promise { 40 | return new FileSystem(path) 41 | } 42 | -------------------------------------------------------------------------------- /src/filesystem/node/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './filesystem.mjs' 30 | export * from './fs.mjs' 31 | -------------------------------------------------------------------------------- /src/http/browser/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './websocket/server.mjs' 30 | export * from './websocket/client.mjs' 31 | export * from './http.mjs' 32 | export * from './listener.mjs' 33 | -------------------------------------------------------------------------------- /src/http/browser/listener.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | import * as Dispose from '../../dispose/index.mjs' 31 | 32 | export class Listener implements Dispose.Dispose { 33 | public [Symbol.dispose]() { 34 | throw new Runtime.RuntimeNotSupportedException('Http') 35 | } 36 | public async [Symbol.asyncDispose]() { 37 | throw new Runtime.RuntimeNotSupportedException('Http') 38 | } 39 | public async dispose(): Promise { 40 | throw new Runtime.RuntimeNotSupportedException('Http') 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/http/browser/websocket/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './client.mjs' 30 | export * from './server.mjs' 31 | -------------------------------------------------------------------------------- /src/http/bun/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /// 30 | 31 | export * from './websocket/client.mjs' 32 | export * from './websocket/server.mjs' 33 | export * from './http.mjs' 34 | export * from './listener.mjs' 35 | -------------------------------------------------------------------------------- /src/http/bun/websocket/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './client.mjs' 30 | export * from './server.mjs' 31 | -------------------------------------------------------------------------------- /src/http/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './websocket/index.mjs' 30 | export * from './http.mjs' 31 | export * from './listener.mjs' 32 | -------------------------------------------------------------------------------- /src/http/core/listener.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Dispose from '../../dispose/index.mjs' 30 | 31 | export interface ListenOptions { 32 | port: number 33 | hostname?: string 34 | } 35 | export interface Address { 36 | address: string 37 | port: number 38 | } 39 | export interface RequestInfo { 40 | local: Address 41 | remote: Address 42 | } 43 | export type ListenCallback = (request: Request, info: RequestInfo) => Response | Promise 44 | 45 | export declare class Listener implements Dispose.Dispose { 46 | constructor(...args: never[]) 47 | [Symbol.asyncDispose](): Promise 48 | dispose(): Promise 49 | } 50 | -------------------------------------------------------------------------------- /src/http/core/websocket/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './client.mjs' 30 | export * from './server.mjs' 31 | -------------------------------------------------------------------------------- /src/http/deno/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './websocket/server.mjs' 30 | export * from './websocket/client.mjs' 31 | export * from './http.mjs' 32 | export * from './listener.mjs' 33 | -------------------------------------------------------------------------------- /src/http/node/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './websocket/client.mjs' 30 | export * from './websocket/server.mjs' 31 | export * from './http.mjs' 32 | export * from './listener.mjs' 33 | -------------------------------------------------------------------------------- /src/http/node/upgrade.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import type { IncomingMessage } from 'node:http' 30 | import type { WebSocketServer } from 'ws' 31 | import type { Duplex } from 'node:stream' 32 | 33 | export interface UpgradeRequestMapData { 34 | wsserver: WebSocketServer 35 | incomingMessage: IncomingMessage 36 | socket: Duplex 37 | head: Buffer 38 | } 39 | 40 | /** Associates a Request object with a UpgradeRequestData */ 41 | export const UpgradeMap = new WeakMap() 42 | -------------------------------------------------------------------------------- /src/http/node/websocket/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './client.mjs' 30 | export * from './server.mjs' 31 | -------------------------------------------------------------------------------- /src/net/browser/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './listener.mjs' 30 | export * from './net.mjs' 31 | export * from './socket.mjs' 32 | -------------------------------------------------------------------------------- /src/net/browser/listener.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | import * as Dispose from '../../dispose/index.mjs' 31 | 32 | export class Listener implements Dispose.Dispose { 33 | public async [Symbol.asyncDispose]() { 34 | throw new Runtime.RuntimeNotSupportedException('Net') 35 | } 36 | public async dispose() { 37 | throw new Runtime.RuntimeNotSupportedException('Net') 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/net/bun/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './listener.mjs' 30 | export * from './net.mjs' 31 | export * from './socket.mjs' 32 | -------------------------------------------------------------------------------- /src/net/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './listener.mjs' 30 | export * from './socket.mjs' 31 | export * from './net.mjs' 32 | -------------------------------------------------------------------------------- /src/net/core/listener.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Dispose from '../../dispose/index.mjs' 30 | import { Socket } from './socket.mjs' 31 | 32 | export interface ListenOptions { 33 | hostname?: string 34 | port: number 35 | } 36 | export type ListenCallback = (socket: Socket) => unknown 37 | 38 | export declare class Listener implements Dispose.Dispose { 39 | constructor(...args: never[]) 40 | [Symbol.asyncDispose](): Promise 41 | dispose(): Promise 42 | } 43 | -------------------------------------------------------------------------------- /src/net/core/socket.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Stream from '../../stream/index.mjs' 30 | 31 | export interface ConnectOptions { 32 | hostname?: string 33 | port: number 34 | } 35 | export interface Address { 36 | address: string 37 | port: number 38 | } 39 | export declare class Socket implements Stream.Read, Stream.Write { 40 | constructor(...args: never[]) 41 | public get local(): Address 42 | public get remote(): Address 43 | public [Symbol.asyncIterator](): AsyncIterableIterator 44 | public read(): Promise 45 | public write(value: Uint8Array): Promise 46 | public close(): Promise 47 | } 48 | -------------------------------------------------------------------------------- /src/net/deno/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './listener.mjs' 30 | export * from './net.mjs' 31 | export * from './socket.mjs' 32 | -------------------------------------------------------------------------------- /src/net/node/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './listener.mjs' 30 | export * from './net.mjs' 31 | export * from './socket.mjs' 32 | -------------------------------------------------------------------------------- /src/os/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './os.mjs' 30 | -------------------------------------------------------------------------------- /src/path/common/cwd.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | 31 | const runtime = Runtime.name() 32 | // note: required to prevent cyclic referencing between process and path 33 | // prettier-ignore 34 | export const cwd: string = ( 35 | runtime === 'bun' ? process.cwd() : 36 | runtime === 'deno' ? globalThis['Deno'].cwd() as any : 37 | runtime === 'node' ? process.cwd() : 38 | '' 39 | ) 40 | -------------------------------------------------------------------------------- /src/path/common/env.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | 31 | const runtime = Runtime.name() 32 | // note: required to prevent cyclic referencing between process and path 33 | // prettier-ignore 34 | export const env: Map = ( 35 | runtime === 'bun' ? new Map(Object.entries(process.env)) : 36 | runtime === 'deno' ? globalThis['Deno'].env as any : 37 | runtime === 'node' ? new Map(Object.entries(process.env)) : 38 | new Map() 39 | ) 40 | -------------------------------------------------------------------------------- /src/path/common/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './cwd.mjs' 30 | export * from './env.mjs' 31 | export * from './util.mjs' 32 | -------------------------------------------------------------------------------- /src/path/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './path.mjs' 30 | -------------------------------------------------------------------------------- /src/path/posix/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './path.mjs' 30 | -------------------------------------------------------------------------------- /src/path/windows/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './path.mjs' 30 | -------------------------------------------------------------------------------- /src/performance/browser/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './performance.mjs' 30 | -------------------------------------------------------------------------------- /src/performance/browser/performance.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export function now(): number { 30 | return Date.now() 31 | } 32 | -------------------------------------------------------------------------------- /src/performance/bun/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './performance.mjs' 30 | -------------------------------------------------------------------------------- /src/performance/bun/performance.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export function now(): number { 30 | return performance.now() 31 | } 32 | -------------------------------------------------------------------------------- /src/performance/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './performance.mjs' 30 | -------------------------------------------------------------------------------- /src/performance/core/performance.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /** Returns the current high resolution millisecond timestamp */ 30 | export declare function now(): number 31 | -------------------------------------------------------------------------------- /src/performance/deno/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './performance.mjs' 30 | -------------------------------------------------------------------------------- /src/performance/deno/performance.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export function now(): number { 30 | return performance.now() 31 | } 32 | -------------------------------------------------------------------------------- /src/performance/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../runtime/index.mjs' 30 | 31 | async function Resolve(): Promise { 32 | switch (Runtime.name()) { 33 | case 'browser': 34 | return await import('./browser/index.mjs') 35 | case 'bun': 36 | return await import('./bun/index.mjs') 37 | case 'deno': 38 | return await import('./deno/index.mjs') 39 | case 'node': 40 | return await import('./node/index.mjs') 41 | default: 42 | throw new Runtime.RuntimeNotSupportedException('Performance') 43 | } 44 | } 45 | const Core = await Resolve() 46 | export const now = Core.now 47 | -------------------------------------------------------------------------------- /src/performance/node/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './performance.mjs' 30 | -------------------------------------------------------------------------------- /src/performance/node/performance.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | const PerfHooks = await Runtime.dynamicImport('node:perf_hooks') 31 | 32 | export function now(): number { 33 | return PerfHooks.performance.now() 34 | } 35 | -------------------------------------------------------------------------------- /src/process/browser/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './memory.mjs' 30 | export * from './process.mjs' 31 | export * from './stdio.mjs' 32 | export * from './tty.mjs' 33 | -------------------------------------------------------------------------------- /src/process/browser/memory.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface MemoryUsage { 30 | external: number 31 | heapTotal: number 32 | heapUsed: number 33 | rss: number 34 | } 35 | 36 | /** Returns current memory usage statistics */ 37 | export function memoryUsage(): MemoryUsage { 38 | return { external: 0, heapTotal: 0, heapUsed: 0, rss: 0 } 39 | } 40 | -------------------------------------------------------------------------------- /src/process/bun/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './process.mjs' 30 | export * from './memory.mjs' 31 | export * from './stdio.mjs' 32 | export * from './tty.mjs' 33 | -------------------------------------------------------------------------------- /src/process/bun/memory.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Core from '../core/index.mjs' 30 | 31 | export function memoryUsage(): Core.MemoryUsage { 32 | const { external, heapTotal, heapUsed, rss } = process.memoryUsage() 33 | return { external, heapTotal, heapUsed, rss } 34 | } 35 | -------------------------------------------------------------------------------- /src/process/bun/process.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | const WorkerThreads = await Runtime.dynamicImport('node:worker_threads') 31 | 32 | export function cwd(): string { 33 | return process.cwd() 34 | } 35 | export function exit(exitcode: number): never { 36 | return process.exit(exitcode) 37 | } 38 | 39 | export const isMainThread = WorkerThreads.isMainThread 40 | export const mainModule = process.argv[1] 41 | export const args = process.argv.slice(2) 42 | export const env = new Map(Object.entries(process.env as Record)) 43 | -------------------------------------------------------------------------------- /src/process/core/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './memory.mjs' 30 | export * from './process.mjs' 31 | export * from './stdio.mjs' 32 | export * from './tty.mjs' 33 | -------------------------------------------------------------------------------- /src/process/core/memory.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface MemoryUsage { 30 | external: number 31 | heapTotal: number 32 | heapUsed: number 33 | rss: number 34 | } 35 | 36 | /** Returns current memory usage statistics */ 37 | export declare function memoryUsage(): MemoryUsage 38 | -------------------------------------------------------------------------------- /src/process/core/stdio.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /** Standard In */ 30 | export declare const stdin: globalThis.ReadableStream 31 | /** Standard Out */ 32 | export declare const stdout: globalThis.WritableStream 33 | /** Standard Err */ 34 | export declare const stderr: globalThis.WritableStream 35 | -------------------------------------------------------------------------------- /src/process/deno/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /// 30 | 31 | export * from './memory.mjs' 32 | export * from './process.mjs' 33 | export * from './stdio.mjs' 34 | export * from './tty.mjs' 35 | -------------------------------------------------------------------------------- /src/process/deno/memory.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Core from '../core/index.mjs' 30 | 31 | export function memoryUsage(): Core.MemoryUsage { 32 | const { external, heapTotal, heapUsed, rss } = Deno.memoryUsage() 33 | return { external, heapTotal, heapUsed, rss } 34 | } 35 | -------------------------------------------------------------------------------- /src/process/deno/stdio.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export const stdin = Deno.stdin.readable 30 | export const stdout = Deno.stdout.writable 31 | export const stderr = Deno.stderr.writable 32 | -------------------------------------------------------------------------------- /src/process/node/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './process.mjs' 30 | export * from './memory.mjs' 31 | export * from './stdio.mjs' 32 | export * from './tty.mjs' 33 | -------------------------------------------------------------------------------- /src/process/node/memory.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Core from '../core/index.mjs' 30 | 31 | export function memoryUsage(): Core.MemoryUsage { 32 | const { external, heapTotal, heapUsed, rss } = process.memoryUsage() 33 | return { external, heapTotal, heapUsed, rss } 34 | } 35 | -------------------------------------------------------------------------------- /src/process/node/process.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import * as Runtime from '../../runtime/index.mjs' 30 | const WorkerThreads = await Runtime.dynamicImport('node:worker_threads') 31 | 32 | export function cwd(): string { 33 | return process.cwd() 34 | } 35 | export function exit(exitcode: number): never { 36 | return process.exit(exitcode) 37 | } 38 | 39 | export const isMainThread = WorkerThreads.isMainThread 40 | export const mainModule = process.argv[1] 41 | export const args = process.argv.slice(2) 42 | export const env = new Map(Object.entries(process.env as Record)) 43 | -------------------------------------------------------------------------------- /src/qs/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './parse.mjs' 30 | export * from './stringify.mjs' 31 | -------------------------------------------------------------------------------- /src/qs/stringify.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | function isEncodable(value: unknown): value is number | string | boolean { 30 | // prettier-ignore 31 | return ( 32 | typeof value === 'string' || 33 | typeof value === 'number' || 34 | typeof value === 'boolean' 35 | ) 36 | } 37 | /** Encodes an object into a querystring searchParams */ 38 | export function stringify(value: Record): string { 39 | const buffer: string[] = [] 40 | for (const [key, val] of Object.entries(value)) { 41 | if (!isEncodable(val)) continue 42 | buffer.push(`${key}=${encodeURIComponent(val)}`) 43 | } 44 | return buffer.join('&') 45 | } 46 | -------------------------------------------------------------------------------- /src/runtime/exception.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /** Exception raised on runtime not supported functionality */ 30 | export class RuntimeNotSupportedException extends Error { 31 | constructor(context: string = 'Runtime not supported') { 32 | super(`${context} is not supported on this runtime`) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/runtime/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './exception.mjs' 30 | export * from './runtime.mjs' 31 | -------------------------------------------------------------------------------- /src/stream/close.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface Close { 30 | close(): Promise 31 | } 32 | -------------------------------------------------------------------------------- /src/stream/frame/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './reader.mjs' 30 | export * from './duplex.mjs' 31 | export * from './writer.mjs' 32 | -------------------------------------------------------------------------------- /src/stream/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './frame/index.mjs' 30 | export * from './close.mjs' 31 | export * from './read.mjs' 32 | export * from './write.mjs' 33 | -------------------------------------------------------------------------------- /src/stream/read.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import { Close } from './close.mjs' 30 | 31 | export interface Read extends Close { 32 | [Symbol.asyncIterator](): AsyncIterableIterator 33 | read(): Promise 34 | } 35 | -------------------------------------------------------------------------------- /src/stream/write.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import { Close } from './close.mjs' 30 | 31 | export interface Write extends Close { 32 | write(value: T): Promise 33 | close(): Promise 34 | } 35 | -------------------------------------------------------------------------------- /src/test/failed.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export interface Failed { 30 | context: string 31 | unit: string 32 | error: Error 33 | } 34 | -------------------------------------------------------------------------------- /src/test/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './options.mjs' 30 | export * from './result.mjs' 31 | export * from './test.mjs' 32 | -------------------------------------------------------------------------------- /src/test/options.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import type { Reporter } from './reporter.mjs' 30 | 31 | export interface Options { 32 | reporter: Reporter 33 | filter: string 34 | } 35 | -------------------------------------------------------------------------------- /src/test/result.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | import type { Failed } from './failed.mjs' 30 | 31 | export interface Result { 32 | success: boolean 33 | elapsed: number 34 | passCount: number 35 | failCount: number 36 | failures: Failed[] 37 | } 38 | -------------------------------------------------------------------------------- /src/type/compiler/index.mts: -------------------------------------------------------------------------------- 1 | export * from '@sinclair/typebox/compiler' 2 | -------------------------------------------------------------------------------- /src/type/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from '@sinclair/typebox' 30 | -------------------------------------------------------------------------------- /src/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | /// 30 | /// 31 | -------------------------------------------------------------------------------- /src/url/index.mts: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------------- 2 | 3 | @sinclair/carbon 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2024 Haydn Paterson (sinclair) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ---------------------------------------------------------------------------*/ 28 | 29 | export * from './parse.mjs' 30 | export * from './url.mjs' 31 | -------------------------------------------------------------------------------- /src/value/index.mts: -------------------------------------------------------------------------------- 1 | export * from '@sinclair/typebox/value' 2 | -------------------------------------------------------------------------------- /test/async/barrier.mts: -------------------------------------------------------------------------------- 1 | import { Async, Test, Assert } from '@sinclair/carbon' 2 | 3 | Test.describe('Async:Barrier', () => { 4 | Test.it('It should start in a paused state', async () => { 5 | const barrier = new Async.Barrier({ paused: true }) 6 | await Assert.shouldTimeout(async () => await barrier.wait(), { timeout: 100 }) 7 | }) 8 | Test.it('It should start in a resumed state', async () => { 9 | const barrier = new Async.Barrier({ paused: false }) 10 | await barrier.wait() 11 | }) 12 | Test.it('It should start in a paused state and resume', async () => { 13 | const barrier = new Async.Barrier({ paused: true }) 14 | setTimeout(() => barrier.resume(), 10) 15 | await barrier.wait() 16 | }) 17 | Test.it('It should start in a resume state and pause', async () => { 18 | const barrier = new Async.Barrier({ paused: false }) 19 | barrier.pause() 20 | await Assert.shouldTimeout(async () => await barrier.wait(), { timeout: 100 }) 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /test/async/delay.mts: -------------------------------------------------------------------------------- 1 | import { Async, Test, Assert } from '@sinclair/carbon' 2 | 3 | Test.describe('Async:delay', () => { 4 | Test.it('Should delay', async () => { 5 | const start = Date.now() 6 | await Async.delay(10) 7 | const delta = Date.now() - start 8 | Assert.isTrue(delta >= 5) // window of error 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/async/index.mts: -------------------------------------------------------------------------------- 1 | import './barrier.mjs' 2 | import './debounce.mjs' 3 | import './delay.mjs' 4 | import './mutex.mjs' 5 | import './semaphore.mjs' 6 | import './timeout.mjs' 7 | -------------------------------------------------------------------------------- /test/async/mutex.mts: -------------------------------------------------------------------------------- 1 | import { Async, Test, Assert } from '@sinclair/carbon' 2 | 3 | export const range = (length: number) => Array.from({ length }) 4 | 5 | Test.describe('Async:Mutex', () => { 6 | // ---------------------------------------------------------------- 7 | // Concurrency 8 | // ---------------------------------------------------------------- 9 | async function concurrencyTest(iterations: number) { 10 | const mutex = new Async.Mutex() 11 | const expect = range(iterations).map((_, i) => i) 12 | const result = [] as number[] 13 | const tasks = range(iterations).map(async (_, index) => { 14 | const lock = await mutex.lock() 15 | result.push(index) 16 | await Async.delay(Math.floor(Math.random() * 10)) 17 | lock.dispose() 18 | }) 19 | await Promise.all(tasks) 20 | Assert.isEqual(result, expect) 21 | } 22 | Test.it('It run with a concurrency of 1', async () => { 23 | await concurrencyTest(32) 24 | }) 25 | Test.it('It run with a concurrency of 16', async () => { 26 | await concurrencyTest(32) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /test/async/semaphore.mts: -------------------------------------------------------------------------------- 1 | import { Async, Test, Assert } from '@sinclair/carbon' 2 | 3 | export const Range = (length: number) => Array.from({ length }) 4 | 5 | Test.describe('Async:Semaphore', () => { 6 | // ---------------------------------------------------------------- 7 | // Concurrency 8 | // ---------------------------------------------------------------- 9 | async function concurrencyTest(iterations: number, concurrency: number) { 10 | let [count, observedMax] = [0, false] 11 | const semaphore = new Async.Semaphore({ concurrency }) 12 | const tasks = Range(iterations).map(async () => { 13 | const lock = await semaphore.lock() 14 | if (!(count < concurrency)) throw Error('Exceeded max concurrency') 15 | count += 1 16 | if (count === concurrency) observedMax = true 17 | await Async.delay(5) 18 | count -= 1 19 | lock.dispose() 20 | }) 21 | await Promise.all(tasks) 22 | Assert.isTrue(observedMax) 23 | } 24 | Test.it('It run with a concurrency of 1', async () => { 25 | await concurrencyTest(32, 1) 26 | }) 27 | Test.it('It run with a concurrency of 16', async () => { 28 | await concurrencyTest(32, 16) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /test/async/timeout.mts: -------------------------------------------------------------------------------- 1 | import { Async, Test, Assert } from '@sinclair/carbon' 2 | 3 | Test.describe('Async:timeout', () => { 4 | Test.it('Should timeout after 10 milliseconds', async () => { 5 | await Assert.shouldThrowAsync(async () => { 6 | await Async.timeout(Async.delay(20), { timeout: 10 }) 7 | }) 8 | }) 9 | Test.it('Should timeout after 10 milliseconds and yield error', async () => { 10 | class SpecializedError extends Error {} 11 | await Assert.shouldThrowAsync(async () => { 12 | await Async.timeout(Async.delay(1000), { timeout: 10, error: new SpecializedError() }) 13 | }, SpecializedError) 14 | }) 15 | Test.it('Should return a result if resolve before timeout', async () => { 16 | const R = await Async.timeout( 17 | (async () => { 18 | await Async.delay(20) 19 | return 12345 20 | })(), 21 | { timeout: 1000 }, 22 | ) 23 | Assert.isEqual(R, 12345) 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /test/buffer/buffer.mts: -------------------------------------------------------------------------------- 1 | import { Buffer, Assert, Test } from '@sinclair/carbon' 2 | 3 | Test.describe('Buffer', () => { 4 | Test.it('Should alloc a new zero buffer', () => { 5 | const buffer = Buffer.alloc(128) 6 | Assert.isEqual(buffer.length, 128) 7 | for (let i = 0; i < buffer.length; i++) { 8 | Assert.isEqual(buffer[i], 0) 9 | } 10 | }) 11 | Test.it('Should alloc random buffer', () => { 12 | const buffer = Buffer.random(128) 13 | Assert.isEqual(buffer.length, 128) 14 | }) 15 | Test.it('Should encode and decode a string', () => { 16 | const source = 'hello world' 17 | const buffer = Buffer.encode(source) 18 | const target = Buffer.decode(buffer) 19 | Assert.isEqual(source, target) 20 | }) 21 | Test.it('Should compare buffers with equals', () => { 22 | const A = new Uint8Array([0, 1, 2, 3]) 23 | const B = new Uint8Array([0, 1, 2, 3]) 24 | const C = new Uint8Array([0, 1, 2, 4]) 25 | const D = new Uint8Array([0, 1, 2]) 26 | Assert.isEqual(Buffer.equals(A, B), true) 27 | Assert.isEqual(Buffer.equals(A, C), false) 28 | Assert.isEqual(Buffer.equals(A, D), false) 29 | }) 30 | Test.it('Should concat buffers', () => { 31 | const A = new Uint8Array([0, 1, 2, 3]) 32 | const B = new Uint8Array([4, 5, 6, 7]) 33 | const C = new Uint8Array([8, 9, 10, 11]) 34 | const D = new Uint8Array([12, 13, 14]) 35 | const E = Buffer.concat([A, B, C, D]) 36 | Assert.isEqual(E, new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])) 37 | }) 38 | Test.it('Should iterate buffers 1', () => { 39 | const buffers: number[][] = [] 40 | for (const buffer of Buffer.iterator(new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), 4)) { 41 | buffers.push(Array.from(buffer)) 42 | } 43 | Assert.isEqual(buffers[0], [0, 1, 2, 3]) 44 | Assert.isEqual(buffers[1], [4, 5, 6, 7]) 45 | Assert.isEqual(buffers[2], [8, 9, 10, 11]) 46 | Assert.isEqual(buffers[3], [12, 13, 14, 15]) 47 | }) 48 | }) 49 | -------------------------------------------------------------------------------- /test/buffer/index.mts: -------------------------------------------------------------------------------- 1 | import './buffer.mjs' 2 | -------------------------------------------------------------------------------- /test/channel/index.mts: -------------------------------------------------------------------------------- 1 | import './channel.mjs' 2 | import './select.mjs' 3 | -------------------------------------------------------------------------------- /test/crypto/crypto.mts: -------------------------------------------------------------------------------- 1 | import { Crypto, Assert, Test } from '@sinclair/carbon' 2 | 3 | Test.describe('Crypto', () => { 4 | Test.it('Should generate randomUUID', () => { 5 | const uuid = Crypto.randomUUID() 6 | Assert.isTypeOf(uuid, 'string') 7 | }) 8 | }) 9 | -------------------------------------------------------------------------------- /test/crypto/index.mts: -------------------------------------------------------------------------------- 1 | import './crypto.mjs' 2 | -------------------------------------------------------------------------------- /test/encoding/index.mts: -------------------------------------------------------------------------------- 1 | import './json.mjs' 2 | import './msgpack.mjs' 3 | -------------------------------------------------------------------------------- /test/events/index.mts: -------------------------------------------------------------------------------- 1 | import './event.mjs' 2 | import './events.mjs' 3 | -------------------------------------------------------------------------------- /test/filesystem/index.mts: -------------------------------------------------------------------------------- 1 | import './filesystem.mjs' 2 | -------------------------------------------------------------------------------- /test/http/index.mts: -------------------------------------------------------------------------------- 1 | import './listener/index.mjs' 2 | import './request/index.mjs' 3 | import './response/index.mjs' 4 | import './websocket/index.mjs' 5 | -------------------------------------------------------------------------------- /test/http/listener/index.mts: -------------------------------------------------------------------------------- 1 | import './listener.mjs' 2 | -------------------------------------------------------------------------------- /test/http/listener/listener.mts: -------------------------------------------------------------------------------- 1 | import { Test, Http, Assert, Runtime } from '@sinclair/carbon' 2 | 3 | // -------------------------------------------------------------------------- 4 | // Fixtures 5 | // -------------------------------------------------------------------------- 6 | async function assertedFetch() { 7 | const result = await Http.fetch(`http://localhost:5000/`).then((res) => res.text()) 8 | Assert.isEqual(result, 'hello') 9 | } 10 | // -------------------------------------------------------------------------- 11 | // Test 12 | // -------------------------------------------------------------------------- 13 | Test.describe('Http:Listener', () => { 14 | Test.exclude(() => Runtime.isBrowser()) 15 | 16 | Test.it('Should listen then close', async () => { 17 | const listener = await Http.listen({ port: 5000 }, () => new Response('hello')) 18 | await listener.dispose() 19 | }) 20 | Test.it('Should listen then close x 16', async () => { 21 | for (let i = 0; i < 16; i++) { 22 | const listener = await Http.listen({ port: 5000 }, () => new Response('hello')) 23 | await listener.dispose() 24 | } 25 | }) 26 | Test.it('Should listen fetch then close', async () => { 27 | const listener = await Http.listen({ port: 5000 }, () => new Response('hello')) 28 | await assertedFetch() 29 | await listener.dispose() 30 | }) 31 | Test.it('Should listen fetch then close (sequential x 64)', async () => { 32 | const listener = await Http.listen({ port: 5000 }, () => new Response('hello')) 33 | for (let i = 0; i < 64; i++) await assertedFetch() 34 | await listener.dispose() 35 | }) 36 | // todo 37 | // Test.it('Should listen fetch then close (parallel x 64)', async () => { 38 | // const listener = Http.listen({ port: 5000 }, () => new Response('hello')) 39 | // const tasks = Array.from({ length: 64 }).map((_, i) => assertedFetch()) 40 | // await Promise.all(tasks) 41 | // await listener.dispose() 42 | // }) 43 | }) 44 | -------------------------------------------------------------------------------- /test/http/request/index.mts: -------------------------------------------------------------------------------- 1 | import './info.mjs' 2 | import './properties.mjs' 3 | import './readable.mjs' 4 | -------------------------------------------------------------------------------- /test/http/response/index.mts: -------------------------------------------------------------------------------- 1 | import './arraybuffer.mjs' 2 | import './json.mjs' 3 | import './properties.mjs' 4 | import './text.mjs' 5 | -------------------------------------------------------------------------------- /test/http/response/json.mts: -------------------------------------------------------------------------------- 1 | import { Http, Test, Assert, Runtime } from '@sinclair/carbon' 2 | 3 | // ------------------------------------------------------------------ 4 | // Fixtures 5 | // ------------------------------------------------------------------ 6 | async function echo(inputs: any[]): Promise { 7 | const listener = await Http.listen({ port: 5000 }, async (request) => new Response(request.body)) 8 | const [endpoint, method, headers] = [`http://localhost:5000/`, 'post', { 'Content-Type': 'application/json' }] 9 | const buffers = await Promise.all(inputs.map((input) => JSON.stringify(input)).map((body) => Http.fetch(endpoint, { headers, method, body }).then((res) => res.json()))) 10 | await listener.dispose() 11 | return buffers 12 | } 13 | // ------------------------------------------------------------------ 14 | // Test 15 | // ------------------------------------------------------------------ 16 | Test.describe('Http:Response:Json', () => { 17 | Test.exclude(() => Runtime.isBrowser()) 18 | 19 | Test.it('Should send receive parallel x1', async () => { 20 | const inputs = [{ x: 1 }] 21 | const outputs = await echo(inputs) 22 | Assert.isEqual(inputs, outputs) 23 | }) 24 | Test.it('Should send receive parallel x2', async () => { 25 | const inputs = [{ x: 1 }, { x: 2 }] 26 | const outputs = await echo(inputs) 27 | Assert.isEqual(inputs, outputs) 28 | }) 29 | Test.it('Should send receive parallel buffer x4', async () => { 30 | const inputs = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }] 31 | const outputs = await echo(inputs) 32 | Assert.isEqual(inputs, outputs) 33 | }) 34 | Test.it('Should send receive parallel buffer x8', async () => { 35 | const inputs = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }, { x: 5 }, { x: 6 }, { x: 7 }, { x: 9 }] 36 | const outputs = await echo(inputs) 37 | Assert.isEqual(inputs, outputs) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /test/http/response/text.mts: -------------------------------------------------------------------------------- 1 | import { Http, Test, Assert, Runtime } from '@sinclair/carbon' 2 | 3 | // ------------------------------------------------------------------ 4 | // Fixtures 5 | // ------------------------------------------------------------------ 6 | async function echo(inputs: string[]): Promise { 7 | const listener = await Http.listen({ port: 5000 }, async (request) => new Response(request.body)) 8 | const [endpoint, method, headers] = [`http://localhost:5000/`, 'post', { 'Content-Type': 'application/json' }] 9 | const buffers = await Promise.all(inputs.map((body) => Http.fetch(endpoint, { headers, method, body }).then((res) => res.text()))) 10 | await listener.dispose() 11 | return buffers 12 | } 13 | // ------------------------------------------------------------------ 14 | // Test 15 | // ------------------------------------------------------------------ 16 | Test.describe('Http:Response:Text', () => { 17 | Test.exclude(() => Runtime.isBrowser()) 18 | 19 | Test.it('Should send receive parallel x1', async () => { 20 | const inputs = ['S1'] 21 | const outputs = await echo(inputs) 22 | Assert.isEqual(inputs, outputs) 23 | }) 24 | Test.it('Should send receive parallel x2', async () => { 25 | const inputs = ['S1', 'S2'] 26 | const outputs = await echo(inputs) 27 | Assert.isEqual(inputs, outputs) 28 | }) 29 | Test.it('Should send receive parallel buffer x4', async () => { 30 | const inputs = ['S1', 'S2', 'S3', 'S4'] 31 | const outputs = await echo(inputs) 32 | Assert.isEqual(inputs, outputs) 33 | }) 34 | Test.it('Should send receive parallel buffer x8', async () => { 35 | const inputs = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8'] 36 | const outputs = await echo(inputs) 37 | Assert.isEqual(inputs, outputs) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /test/http/websocket/client/index.mts: -------------------------------------------------------------------------------- 1 | import './message-event.mjs' 2 | import './properties.mjs' 3 | -------------------------------------------------------------------------------- /test/http/websocket/client/properties.mts: -------------------------------------------------------------------------------- 1 | import { Test, Assert, Http, Runtime } from '@sinclair/carbon' 2 | 3 | async function request(callback: (socket: Http.WebSocket) => any) { 4 | let error: Error | undefined = undefined 5 | const listener = await Http.listen({ port: 5000 }, async (request) => { 6 | return await Http.upgrade(request, async (socket) => socket.close()) 7 | }) 8 | const socket = new Http.WebSocket(`ws://localhost:5000`) 9 | await new Promise((resolve, reject) => { 10 | socket.on('open', () => {}) 11 | socket.on('error', (error) => reject(error)) 12 | socket.on('close', () => resolve()) 13 | }) 14 | try { 15 | await callback(socket) 16 | } catch (err: any) { 17 | error = err 18 | } 19 | await listener.dispose() 20 | if (error) throw error 21 | } 22 | Test.describe('Http:WebSocket:Properties', () => { 23 | Test.exclude(() => Runtime.isBrowser()) 24 | // ---------------------------------------------------------------- 25 | // Cached 26 | // ---------------------------------------------------------------- 27 | let socket: Http.WebSocket 28 | Test.before( 29 | async () => 30 | await request((_socket) => { 31 | socket = _socket 32 | }), 33 | ) 34 | // ---------------------------------------------------------------- 35 | // Properties 36 | // ---------------------------------------------------------------- 37 | Test.it('Should have binaryType 1', async () => { 38 | Assert.isTypeOf(socket.binaryType, 'string') 39 | }) 40 | Test.it('Should have binaryType 2', async () => { 41 | Assert.isEqual(socket.binaryType, 'arraybuffer') 42 | }) 43 | Test.it('Should have close', async () => { 44 | Assert.isTypeOf(socket.close, 'function') 45 | }) 46 | Test.it('Should have on', async () => { 47 | Assert.isTypeOf(socket.on, 'function') 48 | }) 49 | Test.it('Should have send', async () => { 50 | Assert.isTypeOf(socket.send, 'function') 51 | }) 52 | }) 53 | -------------------------------------------------------------------------------- /test/http/websocket/index.mts: -------------------------------------------------------------------------------- 1 | import './client/index.mjs' 2 | import './server/index.mjs' 3 | -------------------------------------------------------------------------------- /test/http/websocket/server/index.mts: -------------------------------------------------------------------------------- 1 | import './message-event.mjs' 2 | import './properties.mjs' 3 | -------------------------------------------------------------------------------- /test/index.mts: -------------------------------------------------------------------------------- 1 | import { Test, Process, Runtime } from '@sinclair/carbon' 2 | import './async/index.mjs' 3 | import './buffer/index.mjs' 4 | import './channel/index.mjs' 5 | import './crypto/index.mjs' 6 | import './encoding/index.mjs' 7 | import './events/index.mjs' 8 | import './filesystem/index.mjs' 9 | import './http/index.mjs' 10 | import './net/index.mjs' 11 | import './os/index.mjs' 12 | import './performance/index.mjs' 13 | 14 | // ------------------------------------------------------------------ 15 | // Run 16 | // ------------------------------------------------------------------ 17 | declare const Drift: any 18 | function filter() { 19 | return Runtime.isBrowser() ? Drift.args[0] : Process.args[0] 20 | } 21 | function terminate(code: number) { 22 | return Runtime.isBrowser() ? Drift.close(code) : Process.exit(code) 23 | } 24 | Test.run({ filter: filter() }).then((result) => { 25 | return result.success ? terminate(0) : terminate(1) 26 | }) 27 | -------------------------------------------------------------------------------- /test/net/index.mts: -------------------------------------------------------------------------------- 1 | import './listener.mjs' 2 | -------------------------------------------------------------------------------- /test/os/index.mts: -------------------------------------------------------------------------------- 1 | import './os.mjs' 2 | -------------------------------------------------------------------------------- /test/os/os.mts: -------------------------------------------------------------------------------- 1 | import { Test, Assert, Os } from '@sinclair/carbon' 2 | 3 | Test.describe('Os:resolve', () => { 4 | Test.it('Should return operating system string', async () => { 5 | const result = Os.type() 6 | Assert.isTrue(result === 'win32' || result === 'darwin' || result === 'linux') 7 | }) 8 | }) 9 | -------------------------------------------------------------------------------- /test/performance/index.mts: -------------------------------------------------------------------------------- 1 | import './performance.mjs' 2 | -------------------------------------------------------------------------------- /test/performance/performance.mts: -------------------------------------------------------------------------------- 1 | import { Performance, Test, Assert } from '@sinclair/carbon' 2 | 3 | Test.describe('Performance:now', () => { 4 | Test.it('Should return a number', () => { 5 | const result = Performance.now() 6 | Assert.isTypeOf(result, 'number') 7 | }) 8 | }) 9 | -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "files": ["index.mts"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "target": "ESNext", 5 | "module": "NodeNext", 6 | "moduleResolution": "NodeNext", 7 | "baseUrl": ".", 8 | "paths": { 9 | "@sinclair/carbon/ansi": ["src/ansi/index.mts"], 10 | "@sinclair/carbon/assert": ["src/assert/index.mts"], 11 | "@sinclair/carbon/async": ["src/async/index.mts"], 12 | "@sinclair/carbon/benchmark": ["src/benchmark/index.mts"], 13 | "@sinclair/carbon/buffer": ["src/buffer/index.mts"], 14 | "@sinclair/carbon/channel": ["src/channel/index.mts"], 15 | "@sinclair/carbon/config": ["src/config/index.mts"], 16 | "@sinclair/carbon/crypto": ["src/crypto/index.mts"], 17 | "@sinclair/carbon/dispose": ["src/dispose/index.mts"], 18 | "@sinclair/carbon/events": ["src/events/index.mts"], 19 | "@sinclair/carbon/exception": ["src/exception/index.mts"], 20 | "@sinclair/carbon/filesystem": ["src/filesystem/index.mts"], 21 | "@sinclair/carbon/http": ["src/http/index.mts"], 22 | "@sinclair/carbon/net": ["src/net/index.mts"], 23 | "@sinclair/carbon/os": ["src/os/index.mts"], 24 | "@sinclair/carbon/path": ["src/path/index.mts"], 25 | "@sinclair/carbon/performance": ["src/performance/index.mts"], 26 | "@sinclair/carbon/process": ["src/process/index.mts"], 27 | "@sinclair/carbon/qs": ["src/qs/index.mts"], 28 | "@sinclair/carbon/runtime": ["src/runtime/index.mts"], 29 | "@sinclair/carbon/stream": ["src/stream/index.mts"], 30 | "@sinclair/carbon/test": ["src/test/index.mts"], 31 | "@sinclair/carbon/type": ["src/type/index.mts"], 32 | "@sinclair/carbon/type/compiler": ["src/type/compiler/index.mts"], 33 | "@sinclair/carbon/url": ["src/url/index.mts"], 34 | "@sinclair/carbon/value": ["src/value/index.mts"], 35 | "@sinclair/carbon": ["src/index.mts"], 36 | } 37 | } 38 | } --------------------------------------------------------------------------------