@ac-kit/node 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +39 -0
- package/dist/child-process/exec-async.d.ts +24 -0
- package/dist/child-process/exec-async.d.ts.map +1 -0
- package/dist/child-process/exec-async.js +33 -0
- package/dist/child-process/exec-async.js.map +1 -0
- package/dist/error/node-aggregate-error.d.ts +18 -0
- package/dist/error/node-aggregate-error.d.ts.map +1 -0
- package/dist/error/node-aggregate-error.js +13 -0
- package/dist/error/node-aggregate-error.js.map +1 -0
- package/dist/error/node-error.d.ts +26 -0
- package/dist/error/node-error.d.ts.map +1 -0
- package/dist/error/node-error.js +21 -0
- package/dist/error/node-error.js.map +1 -0
- package/dist/error/node-exec-error.d.ts +21 -0
- package/dist/error/node-exec-error.d.ts.map +1 -0
- package/dist/error/node-exec-error.js +17 -0
- package/dist/error/node-exec-error.js.map +1 -0
- package/dist/error/node-system-error.d.ts +46 -0
- package/dist/error/node-system-error.d.ts.map +1 -0
- package/dist/error/node-system-error.js +35 -0
- package/dist/error/node-system-error.js.map +1 -0
- package/dist/error/process-exit-error.d.ts +22 -0
- package/dist/error/process-exit-error.d.ts.map +1 -0
- package/dist/error/process-exit-error.js +46 -0
- package/dist/error/process-exit-error.js.map +1 -0
- package/dist/fs/compress-file.d.ts +42 -0
- package/dist/fs/compress-file.d.ts.map +1 -0
- package/dist/fs/compress-file.js +72 -0
- package/dist/fs/compress-file.js.map +1 -0
- package/dist/fs/create-temp-dir.d.ts +13 -0
- package/dist/fs/create-temp-dir.d.ts.map +1 -0
- package/dist/fs/create-temp-dir.js +18 -0
- package/dist/fs/create-temp-dir.js.map +1 -0
- package/dist/fs/escape-path.d.ts +19 -0
- package/dist/fs/escape-path.d.ts.map +1 -0
- package/dist/fs/escape-path.js +20 -0
- package/dist/fs/escape-path.js.map +1 -0
- package/dist/fs/exists-async.d.ts +9 -0
- package/dist/fs/exists-async.d.ts.map +1 -0
- package/dist/fs/exists-async.js +17 -0
- package/dist/fs/exists-async.js.map +1 -0
- package/dist/fs/file-content-equal.d.ts +18 -0
- package/dist/fs/file-content-equal.d.ts.map +1 -0
- package/dist/fs/file-content-equal.js +50 -0
- package/dist/fs/file-content-equal.js.map +1 -0
- package/dist/fs/is-directory-async.d.ts +11 -0
- package/dist/fs/is-directory-async.d.ts.map +1 -0
- package/dist/fs/is-directory-async.js +18 -0
- package/dist/fs/is-directory-async.js.map +1 -0
- package/dist/fs/types.d.ts +19 -0
- package/dist/fs/types.d.ts.map +1 -0
- package/dist/fs/types.js +23 -0
- package/dist/fs/types.js.map +1 -0
- package/dist/fs/walk-paths.d.ts +108 -0
- package/dist/fs/walk-paths.d.ts.map +1 -0
- package/dist/fs/walk-paths.js +197 -0
- package/dist/fs/walk-paths.js.map +1 -0
- package/dist/fs/write-file-atomic.d.ts +42 -0
- package/dist/fs/write-file-atomic.d.ts.map +1 -0
- package/dist/fs/write-file-atomic.js +126 -0
- package/dist/fs/write-file-atomic.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/module/import-module.d.ts +13 -0
- package/dist/module/import-module.d.ts.map +1 -0
- package/dist/module/import-module.js +18 -0
- package/dist/module/import-module.js.map +1 -0
- package/dist/module/optional-import.d.ts +19 -0
- package/dist/module/optional-import.d.ts.map +1 -0
- package/dist/module/optional-import.js +30 -0
- package/dist/module/optional-import.js.map +1 -0
- package/dist/module/resolve-module.d.ts +13 -0
- package/dist/module/resolve-module.d.ts.map +1 -0
- package/dist/module/resolve-module.js +26 -0
- package/dist/module/resolve-module.js.map +1 -0
- package/dist/net/dgram-socket.d.ts +235 -0
- package/dist/net/dgram-socket.d.ts.map +1 -0
- package/dist/net/dgram-socket.js +341 -0
- package/dist/net/dgram-socket.js.map +1 -0
- package/dist/net/ipc-socket.d.ts +34 -0
- package/dist/net/ipc-socket.d.ts.map +1 -0
- package/dist/net/ipc-socket.js +63 -0
- package/dist/net/ipc-socket.js.map +1 -0
- package/dist/net/stream-socket.d.ts +156 -0
- package/dist/net/stream-socket.d.ts.map +1 -0
- package/dist/net/stream-socket.js +188 -0
- package/dist/net/stream-socket.js.map +1 -0
- package/dist/net/tcp-server.d.ts +110 -0
- package/dist/net/tcp-server.d.ts.map +1 -0
- package/dist/net/tcp-server.js +198 -0
- package/dist/net/tcp-server.js.map +1 -0
- package/dist/net/tcp-socket.d.ts +87 -0
- package/dist/net/tcp-socket.d.ts.map +1 -0
- package/dist/net/tcp-socket.js +153 -0
- package/dist/net/tcp-socket.js.map +1 -0
- package/dist/net/tls-socket.d.ts +45 -0
- package/dist/net/tls-socket.d.ts.map +1 -0
- package/dist/net/tls-socket.js +148 -0
- package/dist/net/tls-socket.js.map +1 -0
- package/dist/process/fork-process.d.ts +63 -0
- package/dist/process/fork-process.d.ts.map +1 -0
- package/dist/process/fork-process.js +98 -0
- package/dist/process/fork-process.js.map +1 -0
- package/dist/process/guarded.d.ts +12 -0
- package/dist/process/guarded.d.ts.map +1 -0
- package/dist/process/guarded.js +25 -0
- package/dist/process/guarded.js.map +1 -0
- package/dist/process/spawn-process.d.ts +37 -0
- package/dist/process/spawn-process.d.ts.map +1 -0
- package/dist/process/spawn-process.js +73 -0
- package/dist/process/spawn-process.js.map +1 -0
- package/dist/process/spawned-process.d.ts +102 -0
- package/dist/process/spawned-process.d.ts.map +1 -0
- package/dist/process/spawned-process.js +226 -0
- package/dist/process/spawned-process.js.map +1 -0
- package/dist/process/start-process.d.ts +54 -0
- package/dist/process/start-process.d.ts.map +1 -0
- package/dist/process/start-process.js +73 -0
- package/dist/process/start-process.js.map +1 -0
- package/dist/shell/escape-command-arg.d.ts +9 -0
- package/dist/shell/escape-command-arg.d.ts.map +1 -0
- package/dist/shell/escape-command-arg.js +13 -0
- package/dist/shell/escape-command-arg.js.map +1 -0
- package/dist/shell/escape-command.d.ts +10 -0
- package/dist/shell/escape-command.d.ts.map +1 -0
- package/dist/shell/escape-command.js +12 -0
- package/dist/shell/escape-command.js.map +1 -0
- package/dist/stream/non-closing-writable-stream.d.ts +14 -0
- package/dist/stream/non-closing-writable-stream.d.ts.map +1 -0
- package/dist/stream/non-closing-writable-stream.js +20 -0
- package/dist/stream/non-closing-writable-stream.js.map +1 -0
- package/dist/stream/write-async.d.ts +12 -0
- package/dist/stream/write-async.d.ts.map +1 -0
- package/dist/stream/write-async.js +22 -0
- package/dist/stream/write-async.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { chmod, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { constants as osConstants } from "node:os";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { defaults } from "@ac-kit/core";
|
|
7
|
+
import { NODE_WRITE_FILE_DEFAULT_OPTIONS, } from "./types.js";
|
|
8
|
+
const PERMISSION_BITS = 0o7777;
|
|
9
|
+
function isAppendFlag(flag) {
|
|
10
|
+
return typeof flag === "string"
|
|
11
|
+
? flag.includes("a")
|
|
12
|
+
: (flag & constants.O_APPEND) === constants.O_APPEND;
|
|
13
|
+
}
|
|
14
|
+
function isExclusiveFlag(flag) {
|
|
15
|
+
return typeof flag === "string"
|
|
16
|
+
? flag.includes("x")
|
|
17
|
+
: (flag & constants.O_EXCL) === constants.O_EXCL;
|
|
18
|
+
}
|
|
19
|
+
function toPermissionBits(mode) {
|
|
20
|
+
return ((typeof mode === "string" ? Number.parseInt(mode, 8) : mode) &
|
|
21
|
+
PERMISSION_BITS);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The temporary file sits beside the destination: `rename` is only atomic
|
|
25
|
+
* within one filesystem, so a system temporary directory would break it.
|
|
26
|
+
*/
|
|
27
|
+
function temporaryPathFor(filePath) {
|
|
28
|
+
const suffix = `.tmp-${randomUUID()}`;
|
|
29
|
+
if (filePath instanceof URL) {
|
|
30
|
+
// `pathname` is percent-encoded; `fileURLToPath` also rejects non-`file:`.
|
|
31
|
+
return fileURLToPath(filePath) + suffix;
|
|
32
|
+
}
|
|
33
|
+
if (Buffer.isBuffer(filePath)) {
|
|
34
|
+
return Buffer.concat([filePath, Buffer.from(suffix)]);
|
|
35
|
+
}
|
|
36
|
+
return filePath + suffix;
|
|
37
|
+
}
|
|
38
|
+
function fileAlreadyExistsError(filePath) {
|
|
39
|
+
const path = filePath instanceof URL ? fileURLToPath(filePath) : filePath;
|
|
40
|
+
const errno = -osConstants.errno.EEXIST;
|
|
41
|
+
return Object.assign(new Error(`EEXIST: file already exists, open '${String(path)}'`), {
|
|
42
|
+
code: "EEXIST",
|
|
43
|
+
errno,
|
|
44
|
+
syscall: "open",
|
|
45
|
+
path,
|
|
46
|
+
info: { errno, syscall: "open", path },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Replaces a file's contents in one step: a reader sees either the previous
|
|
51
|
+
* contents or the new ones, never a partial write.
|
|
52
|
+
*
|
|
53
|
+
* The data goes to a uniquely named temporary file beside the destination,
|
|
54
|
+
* which is then `rename`d over it. `rename` replaces the destination
|
|
55
|
+
* atomically, so no window exists in which the path is missing.
|
|
56
|
+
*
|
|
57
|
+
* Appending is rejected — `flag: "a"` and `O_APPEND` throw. Staging an append
|
|
58
|
+
* means copying the destination into the temporary file and appending there,
|
|
59
|
+
* which silently discards whatever another process wrote in between: the
|
|
60
|
+
* opposite of what an appender expects. Read, concatenate and replace instead,
|
|
61
|
+
* serialising the writers yourself when there is more than one:
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const current = await readFile(path, "utf8").catch(() => "");
|
|
65
|
+
* await writeFileAtomic(path, `${current}${line}\n`);
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* When the destination already exists its permission bits carry over, unless
|
|
69
|
+
* `options.mode` says otherwise. Ownership does not: the replacement belongs to
|
|
70
|
+
* the calling user.
|
|
71
|
+
*
|
|
72
|
+
* Durability is a separate concern from atomicity — pass `flush: true` to fsync
|
|
73
|
+
* the data before the rename. The parent directory is never fsynced, so the
|
|
74
|
+
* rename itself may still be lost to a power failure.
|
|
75
|
+
*
|
|
76
|
+
* @param filePath The path to replace.
|
|
77
|
+
* @param data The contents to write.
|
|
78
|
+
* @param options Encoding, mode, flag, flush and abort signal, as for
|
|
79
|
+
* `fs.writeFile`. `flag` may only select exclusive creation (`"wx"`,
|
|
80
|
+
* `O_EXCL`); appending throws.
|
|
81
|
+
* @returns A promise that resolves once the destination holds the new contents.
|
|
82
|
+
* @throws {TypeError} When `options.flag` requests an append.
|
|
83
|
+
* @throws When the destination exists and `options.flag` is exclusive (`code:
|
|
84
|
+
* "EEXIST"`), or when any underlying syscall fails.
|
|
85
|
+
*/
|
|
86
|
+
export async function writeFileAtomic(filePath, data, options) {
|
|
87
|
+
const flag = options?.flag ?? NODE_WRITE_FILE_DEFAULT_OPTIONS.flag;
|
|
88
|
+
if (isAppendFlag(flag)) {
|
|
89
|
+
throw new TypeError("writeFileAtomic cannot append: staging an append drops concurrent writes. Read the file and write the concatenation instead.");
|
|
90
|
+
}
|
|
91
|
+
let stats;
|
|
92
|
+
try {
|
|
93
|
+
stats = await stat(filePath);
|
|
94
|
+
}
|
|
95
|
+
catch { }
|
|
96
|
+
if (stats && isExclusiveFlag(flag)) {
|
|
97
|
+
throw fileAlreadyExistsError(filePath);
|
|
98
|
+
}
|
|
99
|
+
const effectiveOptions = defaults(options, NODE_WRITE_FILE_DEFAULT_OPTIONS);
|
|
100
|
+
// Left unset, the mode is the caller's umask business, exactly as for a
|
|
101
|
+
// plain `writeFile`; set, it has to survive the umask, hence the `chmod`.
|
|
102
|
+
const requestedMode = options?.mode ?? stats?.mode;
|
|
103
|
+
const mode = toPermissionBits(requestedMode ?? NODE_WRITE_FILE_DEFAULT_OPTIONS.mode);
|
|
104
|
+
const tmpFilePath = temporaryPathFor(filePath);
|
|
105
|
+
try {
|
|
106
|
+
await writeFile(tmpFilePath, data, {
|
|
107
|
+
...effectiveOptions,
|
|
108
|
+
mode,
|
|
109
|
+
// The temporary file is always a fresh create under a name of our own.
|
|
110
|
+
flag: "wx",
|
|
111
|
+
signal: effectiveOptions.signal ?? undefined,
|
|
112
|
+
});
|
|
113
|
+
if (requestedMode !== undefined) {
|
|
114
|
+
await chmod(tmpFilePath, mode);
|
|
115
|
+
}
|
|
116
|
+
await rename(tmpFilePath, filePath);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
try {
|
|
120
|
+
await unlink(tmpFilePath);
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=write-file-atomic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-file-atomic.js","sourceRoot":"","sources":["../../src/fs/write-file-atomic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAwC,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EACN,+BAA+B,GAE/B,MAAM,YAAY,CAAC;AAEpB,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,SAAS,YAAY,CAAC,IAAqB;IAC1C,OAAO,OAAO,IAAI,KAAK,QAAQ;QAC9B,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QACpB,CAAC,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B;YACnB,IAAI;YACJ,uEAAuE;YACvE,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,gBAAgB,CAAC,MAAM,IAAI,SAAS;SAC5C,CAAC,CAAC;QAEH,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC;YACJ,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QAEV,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from "./child-process/exec-async.js";
|
|
2
|
+
export * from "./error/node-aggregate-error.js";
|
|
3
|
+
export * from "./error/node-error.js";
|
|
4
|
+
export * from "./error/node-exec-error.js";
|
|
5
|
+
export * from "./error/node-system-error.js";
|
|
6
|
+
export * from "./error/process-exit-error.js";
|
|
7
|
+
export * from "./fs/compress-file.js";
|
|
8
|
+
export * from "./fs/create-temp-dir.js";
|
|
9
|
+
export * from "./fs/escape-path.js";
|
|
10
|
+
export * from "./fs/exists-async.js";
|
|
11
|
+
export * from "./fs/file-content-equal.js";
|
|
12
|
+
export * from "./fs/is-directory-async.js";
|
|
13
|
+
export * from "./fs/types.js";
|
|
14
|
+
export * from "./fs/walk-paths.js";
|
|
15
|
+
export * from "./fs/write-file-atomic.js";
|
|
16
|
+
export * from "./module/import-module.js";
|
|
17
|
+
export * from "./module/optional-import.js";
|
|
18
|
+
export * from "./module/resolve-module.js";
|
|
19
|
+
export * from "./net/dgram-socket.js";
|
|
20
|
+
export * from "./net/ipc-socket.js";
|
|
21
|
+
export * from "./net/stream-socket.js";
|
|
22
|
+
export * from "./net/tcp-server.js";
|
|
23
|
+
export * from "./net/tcp-socket.js";
|
|
24
|
+
export * from "./net/tls-socket.js";
|
|
25
|
+
export * from "./process/fork-process.js";
|
|
26
|
+
export * from "./process/guarded.js";
|
|
27
|
+
export * from "./process/spawn-process.js";
|
|
28
|
+
export * from "./process/spawned-process.js";
|
|
29
|
+
export * from "./process/start-process.js";
|
|
30
|
+
export * from "./shell/escape-command-arg.js";
|
|
31
|
+
export * from "./shell/escape-command.js";
|
|
32
|
+
export * from "./stream/non-closing-writable-stream.js";
|
|
33
|
+
export * from "./stream/write-async.js";
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * from "./child-process/exec-async.js";
|
|
2
|
+
export * from "./error/node-aggregate-error.js";
|
|
3
|
+
export * from "./error/node-error.js";
|
|
4
|
+
export * from "./error/node-exec-error.js";
|
|
5
|
+
export * from "./error/node-system-error.js";
|
|
6
|
+
export * from "./error/process-exit-error.js";
|
|
7
|
+
export * from "./fs/compress-file.js";
|
|
8
|
+
export * from "./fs/create-temp-dir.js";
|
|
9
|
+
export * from "./fs/escape-path.js";
|
|
10
|
+
export * from "./fs/exists-async.js";
|
|
11
|
+
export * from "./fs/file-content-equal.js";
|
|
12
|
+
export * from "./fs/is-directory-async.js";
|
|
13
|
+
export * from "./fs/types.js";
|
|
14
|
+
export * from "./fs/walk-paths.js";
|
|
15
|
+
export * from "./fs/write-file-atomic.js";
|
|
16
|
+
export * from "./module/import-module.js";
|
|
17
|
+
export * from "./module/optional-import.js";
|
|
18
|
+
export * from "./module/resolve-module.js";
|
|
19
|
+
export * from "./net/dgram-socket.js";
|
|
20
|
+
export * from "./net/ipc-socket.js";
|
|
21
|
+
export * from "./net/stream-socket.js";
|
|
22
|
+
export * from "./net/tcp-server.js";
|
|
23
|
+
export * from "./net/tcp-socket.js";
|
|
24
|
+
export * from "./net/tls-socket.js";
|
|
25
|
+
export * from "./process/fork-process.js";
|
|
26
|
+
export * from "./process/guarded.js";
|
|
27
|
+
export * from "./process/spawn-process.js";
|
|
28
|
+
export * from "./process/spawned-process.js";
|
|
29
|
+
export * from "./process/start-process.js";
|
|
30
|
+
export * from "./shell/escape-command-arg.js";
|
|
31
|
+
export * from "./shell/escape-command.js";
|
|
32
|
+
export * from "./stream/non-closing-writable-stream.js";
|
|
33
|
+
export * from "./stream/write-async.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import module at runtime with custom resolve paths.
|
|
3
|
+
*
|
|
4
|
+
* If used, the resolve paths will be used instead of the default node.js ones,
|
|
5
|
+
* except for the GLOBAL_FOLDERS like $HOME/.node_modules, which are always
|
|
6
|
+
* included.
|
|
7
|
+
*
|
|
8
|
+
* @param id The module to load
|
|
9
|
+
* @param resolvePaths The paths to use to resolve the module
|
|
10
|
+
* @returns The loaded module
|
|
11
|
+
*/
|
|
12
|
+
export declare function importModule<T>(id: string, resolvePaths?: string[]): Promise<T>;
|
|
13
|
+
//# sourceMappingURL=import-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-module.d.ts","sourceRoot":"","sources":["../../src/module/import-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAAC,CAAC,EACnC,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,MAAM,EAAE,GACrB,OAAO,CAAC,CAAC,CAAC,CAMZ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import module at runtime with custom resolve paths.
|
|
3
|
+
*
|
|
4
|
+
* If used, the resolve paths will be used instead of the default node.js ones,
|
|
5
|
+
* except for the GLOBAL_FOLDERS like $HOME/.node_modules, which are always
|
|
6
|
+
* included.
|
|
7
|
+
*
|
|
8
|
+
* @param id The module to load
|
|
9
|
+
* @param resolvePaths The paths to use to resolve the module
|
|
10
|
+
* @returns The loaded module
|
|
11
|
+
*/
|
|
12
|
+
export async function importModule(id, resolvePaths) {
|
|
13
|
+
if (resolvePaths && resolvePaths.length > 0) {
|
|
14
|
+
id = require.resolve(id, { paths: resolvePaths });
|
|
15
|
+
}
|
|
16
|
+
return import(id);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=import-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-module.js","sourceRoot":"","sources":["../../src/module/import-module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,EAAU,EACV,YAAuB;IAEvB,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import a module optionally, returning `null` if the module is not found.
|
|
3
|
+
*
|
|
4
|
+
* This is useful for optional peer dependencies, where a module may or may not
|
|
5
|
+
* be installed.
|
|
6
|
+
*
|
|
7
|
+
* `load` must contain a literal `import("specifier")` expression written in the
|
|
8
|
+
* caller's own module: dynamic import specifiers resolve against the file the
|
|
9
|
+
* expression is written in, not the file that happens to invoke `load` at
|
|
10
|
+
* runtime. Passing a specifier string here instead would resolve it against
|
|
11
|
+
* this module's own dependencies, which fails under strict (non-hoisting)
|
|
12
|
+
* package managers whenever the optional dependency belongs to the caller
|
|
13
|
+
* instead.
|
|
14
|
+
*
|
|
15
|
+
* @param load - A thunk containing the `import("specifier")` expression.
|
|
16
|
+
* @returns The imported module, or `null` if the module cannot be found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function optionalImport<T>(load: () => Promise<T>): Promise<T | null>;
|
|
19
|
+
//# sourceMappingURL=optional-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-import.d.ts","sourceRoot":"","sources":["../../src/module/optional-import.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACrC,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CASnB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isNodeErrorWithCode } from "../error/node-error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Import a module optionally, returning `null` if the module is not found.
|
|
4
|
+
*
|
|
5
|
+
* This is useful for optional peer dependencies, where a module may or may not
|
|
6
|
+
* be installed.
|
|
7
|
+
*
|
|
8
|
+
* `load` must contain a literal `import("specifier")` expression written in the
|
|
9
|
+
* caller's own module: dynamic import specifiers resolve against the file the
|
|
10
|
+
* expression is written in, not the file that happens to invoke `load` at
|
|
11
|
+
* runtime. Passing a specifier string here instead would resolve it against
|
|
12
|
+
* this module's own dependencies, which fails under strict (non-hoisting)
|
|
13
|
+
* package managers whenever the optional dependency belongs to the caller
|
|
14
|
+
* instead.
|
|
15
|
+
*
|
|
16
|
+
* @param load - A thunk containing the `import("specifier")` expression.
|
|
17
|
+
* @returns The imported module, or `null` if the module cannot be found.
|
|
18
|
+
*/
|
|
19
|
+
export async function optionalImport(load) {
|
|
20
|
+
try {
|
|
21
|
+
return await load();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (isNodeErrorWithCode(error, "ERR_MODULE_NOT_FOUND")) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=optional-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-import.js","sourceRoot":"","sources":["../../src/module/optional-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,IAAsB;IAEtB,IAAI,CAAC;QACJ,OAAO,MAAM,IAAI,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,mBAAmB,CAAC,KAAK,EAAE,sBAAsB,CAAC,EAAE,CAAC;YACxD,OAAO,IAAI,CAAC;QACb,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a module id to its full path.
|
|
3
|
+
*
|
|
4
|
+
* If defined, the resolve paths will be used instead of the default node.js
|
|
5
|
+
* ones, except for the GLOBAL_FOLDERS like $HOME/.node_modules, which are
|
|
6
|
+
* always included.
|
|
7
|
+
*
|
|
8
|
+
* @param id Module identifier
|
|
9
|
+
* @param resolvePaths Optional paths to use to resolve the module
|
|
10
|
+
* @returns The resolved module path, or null if it cannot be found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveModule(id: string, resolvePaths?: string[]): string | null;
|
|
13
|
+
//# sourceMappingURL=resolve-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-module.d.ts","sourceRoot":"","sources":["../../src/module/resolve-module.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC5B,EAAE,EAAE,MAAM,EACV,YAAY,CAAC,EAAE,MAAM,EAAE,GACrB,MAAM,GAAG,IAAI,CAcf"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isNodeErrorWithCode } from "../error/node-error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a module id to its full path.
|
|
4
|
+
*
|
|
5
|
+
* If defined, the resolve paths will be used instead of the default node.js
|
|
6
|
+
* ones, except for the GLOBAL_FOLDERS like $HOME/.node_modules, which are
|
|
7
|
+
* always included.
|
|
8
|
+
*
|
|
9
|
+
* @param id Module identifier
|
|
10
|
+
* @param resolvePaths Optional paths to use to resolve the module
|
|
11
|
+
* @returns The resolved module path, or null if it cannot be found.
|
|
12
|
+
*/
|
|
13
|
+
export function resolveModule(id, resolvePaths) {
|
|
14
|
+
let result;
|
|
15
|
+
try {
|
|
16
|
+
result = require.resolve(id, { paths: resolvePaths });
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (!isNodeErrorWithCode(error, "MODULE_NOT_FOUND")) {
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
result = null;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=resolve-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-module.js","sourceRoot":"","sources":["../../src/module/resolve-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAC5B,EAAU,EACV,YAAuB;IAEvB,IAAI,MAAqB,CAAC;IAE1B,IAAI,CAAC;QACJ,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE,CAAC;YACrD,MAAM,KAAK,CAAC;QACb,CAAC;QAED,MAAM,GAAG,IAAI,CAAC;IACf,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import * as dgram from "node:dgram";
|
|
2
|
+
import { EventDispatcherMapBase, IEventDispatcherMap } from "@ac-kit/async";
|
|
3
|
+
import { InetEndpoint, type IError } from "@ac-kit/core";
|
|
4
|
+
import type { Except, TypedArray } from "type-fest";
|
|
5
|
+
/** Event map for DgramSocket socket-specific events. */
|
|
6
|
+
export type DgramSocketEvents = {
|
|
7
|
+
/** Emitted when the socket is closed. */
|
|
8
|
+
close: [];
|
|
9
|
+
/** Emitted after a socket is addressed using `bind()`. */
|
|
10
|
+
connect: [];
|
|
11
|
+
/** Emitted when an error occurs. */
|
|
12
|
+
error: [error: IError];
|
|
13
|
+
/** Emitted when the socket is ready to receive data. */
|
|
14
|
+
listening: [];
|
|
15
|
+
/**
|
|
16
|
+
* Emitted when a new datagram is available on a socket.
|
|
17
|
+
*
|
|
18
|
+
* @param msg - The message buffer received
|
|
19
|
+
* @param msgSize - The size of the message in bytes
|
|
20
|
+
* @param from - The sender's endpoint information (address, port, and family)
|
|
21
|
+
*/
|
|
22
|
+
message: [msg: Buffer, msgSize: number, from: InetEndpoint];
|
|
23
|
+
};
|
|
24
|
+
export interface DgramSocketStat {
|
|
25
|
+
/** The number of datagrams currently queued for sending. */
|
|
26
|
+
sendQueueCount: number;
|
|
27
|
+
/** The total number of bytes currently queued for sending. */
|
|
28
|
+
sendQueueSize: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* High-level wrapper around Node.js
|
|
32
|
+
* {@link dgram.Socket | UDP datagram sockets}.
|
|
33
|
+
*
|
|
34
|
+
* This class delegates almost all behavior to an underlying
|
|
35
|
+
* {@link dgram.Socket} instance while:
|
|
36
|
+
*
|
|
37
|
+
* - Providing strongly-typed events via {@link DgramSocketEvents}.
|
|
38
|
+
* - Using {@link InetEndpoint} instead of Node's `RemoteInfo`.
|
|
39
|
+
* - Exposing promise-based {@link DgramSocket.bind | bind} and
|
|
40
|
+
* {@link DgramSocket.close | close} helpers.
|
|
41
|
+
* - Aggregating send-queue statistics through {@link DgramSocket.getStat}.
|
|
42
|
+
*
|
|
43
|
+
* Unless explicitly documented otherwise, methods have the same semantics as
|
|
44
|
+
* their counterparts on {@link dgram.Socket}.
|
|
45
|
+
*
|
|
46
|
+
* Example usage:
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* const dgramSocket = DgramSocket.from({ type: "udp4" });
|
|
50
|
+
* await dgramSocket.bind(12345, "localhost");
|
|
51
|
+
* dgramSocket.on("message", (msg, msgSize, from) => {
|
|
52
|
+
* console.log(
|
|
53
|
+
* `Received ${msgSize} bytes from ${from.address}:${from.port}`,
|
|
54
|
+
* );
|
|
55
|
+
* });
|
|
56
|
+
* await dgramSocket.send(54321, "localhost", Buffer.from("Hello, UDP!"));
|
|
57
|
+
* await dgramSocket.close();
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare class DgramSocket extends EventDispatcherMapBase<DgramSocketEvents> implements IEventDispatcherMap<DgramSocketEvents> {
|
|
61
|
+
private readonly sock;
|
|
62
|
+
/** Creates a new `DgramSocket` instance with the specified options. */
|
|
63
|
+
static from(options?: dgram.SocketOptions): DgramSocket;
|
|
64
|
+
private readonly handledErrorEvents;
|
|
65
|
+
/**
|
|
66
|
+
* Constructs a new `DgramSocket` instance wrapping the provided
|
|
67
|
+
* `dgram.Socket`.
|
|
68
|
+
*/
|
|
69
|
+
constructor(sock: dgram.Socket);
|
|
70
|
+
/**
|
|
71
|
+
* References the socket, preventing the process from exiting while the socket
|
|
72
|
+
* is active.
|
|
73
|
+
*/
|
|
74
|
+
ref(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Unreferences the socket, allowing the process to exit even if the socket is
|
|
77
|
+
* active.
|
|
78
|
+
*/
|
|
79
|
+
unref(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Enables or disables sending of broadcast datagrams.
|
|
82
|
+
*
|
|
83
|
+
* This is a thin wrapper around {@link dgram.Socket.setBroadcast}, which
|
|
84
|
+
* toggles the `SO_BROADCAST` socket option. When enabled, UDP packets may be
|
|
85
|
+
* sent to broadcast addresses.
|
|
86
|
+
*
|
|
87
|
+
* @param flag Whether broadcast should be enabled.
|
|
88
|
+
*/
|
|
89
|
+
setBroadcast(flag: boolean): void;
|
|
90
|
+
/**
|
|
91
|
+
* Adds this socket to the given multicast group.
|
|
92
|
+
*
|
|
93
|
+
* This is a thin wrapper around {@link dgram.Socket.addMembership}, which
|
|
94
|
+
* configures `IP_ADD_MEMBERSHIP` for the given multicast group.
|
|
95
|
+
*/
|
|
96
|
+
addMembership(multicastAddress: string, multicastInterface?: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Sets the size in bytes of the underlying receive buffer.
|
|
99
|
+
*
|
|
100
|
+
* This is a thin wrapper around {@link dgram.Socket.setRecvBufferSize}, which
|
|
101
|
+
* sets the `SO_RCVBUF` socket option.
|
|
102
|
+
*/
|
|
103
|
+
setRecvBufferSize(size: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the size in bytes of the underlying receive buffer.
|
|
106
|
+
*
|
|
107
|
+
* This is a thin wrapper around {@link dgram.Socket.getRecvBufferSize}, which
|
|
108
|
+
* reads the `SO_RCVBUF` socket option.
|
|
109
|
+
*/
|
|
110
|
+
getRecvBufferSize(): number;
|
|
111
|
+
/**
|
|
112
|
+
* Sets the size in bytes of the underlying send buffer.
|
|
113
|
+
*
|
|
114
|
+
* This is a thin wrapper around {@link dgram.Socket.setSendBufferSize}, which
|
|
115
|
+
* sets the `SO_SNDBUF` socket option.
|
|
116
|
+
*/
|
|
117
|
+
setSendBufferSize(size: number): void;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the size in bytes of the underlying send buffer.
|
|
120
|
+
*
|
|
121
|
+
* This is a thin wrapper around {@link dgram.Socket.getSendBufferSize}, which
|
|
122
|
+
* reads the `SO_SNDBUF` socket option.
|
|
123
|
+
*/
|
|
124
|
+
getSendBufferSize(): number;
|
|
125
|
+
/**
|
|
126
|
+
* Removes this socket from the given multicast group.
|
|
127
|
+
*
|
|
128
|
+
* This is a thin wrapper around {@link dgram.Socket.dropMembership}, which
|
|
129
|
+
* configures `IP_DROP_MEMBERSHIP` for the given multicast group.
|
|
130
|
+
*/
|
|
131
|
+
dropMembership(multicastAddress: string, multicastInterface?: string): void;
|
|
132
|
+
/**
|
|
133
|
+
* Adds this socket to a source-specific multicast group.
|
|
134
|
+
*
|
|
135
|
+
* This is a thin wrapper around
|
|
136
|
+
* {@link dgram.Socket.addSourceSpecificMembership}, configuring
|
|
137
|
+
* source-specific multicast membership for the given source and group.
|
|
138
|
+
*/
|
|
139
|
+
addSourceMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void;
|
|
140
|
+
/**
|
|
141
|
+
* Removes this socket from a source-specific multicast group.
|
|
142
|
+
*
|
|
143
|
+
* This is a thin wrapper around
|
|
144
|
+
* {@link dgram.Socket.dropSourceSpecificMembership}, removing source-specific
|
|
145
|
+
* multicast membership for the given source and group.
|
|
146
|
+
*/
|
|
147
|
+
dropSourceMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void;
|
|
148
|
+
/**
|
|
149
|
+
* Sets the outbound multicast interface.
|
|
150
|
+
*
|
|
151
|
+
* This is a thin wrapper around {@link dgram.Socket.setMulticastInterface},
|
|
152
|
+
* which controls the default outgoing interface for multicast traffic.
|
|
153
|
+
*/
|
|
154
|
+
setMulticastInterface(multicastInterface: string): void;
|
|
155
|
+
/**
|
|
156
|
+
* Enables or disables loopback for multicast packets sent from this socket.
|
|
157
|
+
*
|
|
158
|
+
* This is a thin wrapper around {@link dgram.Socket.setMulticastLoopback},
|
|
159
|
+
* which toggles the `IP_MULTICAST_LOOP` socket option.
|
|
160
|
+
*/
|
|
161
|
+
setMulticastLoop(flag: boolean): void;
|
|
162
|
+
/**
|
|
163
|
+
* Sets the time-to-live (TTL) value for multicast packets.
|
|
164
|
+
*
|
|
165
|
+
* This is a thin wrapper around {@link dgram.Socket.setMulticastTTL}, which
|
|
166
|
+
* configures the `IP_MULTICAST_TTL` socket option.
|
|
167
|
+
*/
|
|
168
|
+
setMulticastTtl(ttl: number): void;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the unicast time-to-live (TTL) value for outgoing packets.
|
|
171
|
+
*
|
|
172
|
+
* This is a thin wrapper around {@link dgram.Socket.setTTL}, which configures
|
|
173
|
+
* the `IP_TTL` socket option.
|
|
174
|
+
*/
|
|
175
|
+
setTtl(ttl: number): void;
|
|
176
|
+
/**
|
|
177
|
+
* Gets the address information of the bound socket.
|
|
178
|
+
*
|
|
179
|
+
* @returns The socket's endpoint information or null if the socket is not
|
|
180
|
+
* bound.
|
|
181
|
+
* @throws {UnsupportedError} If the address type is not an AddressInfo
|
|
182
|
+
* object.
|
|
183
|
+
*/
|
|
184
|
+
address(): InetEndpoint | null;
|
|
185
|
+
/**
|
|
186
|
+
* Binds the UDP socket to the specified address and port.
|
|
187
|
+
*
|
|
188
|
+
* @param port The port to bind to. If not specified, a random available port
|
|
189
|
+
* will be used.
|
|
190
|
+
* @param address The address to bind to. If not specified, the socket will
|
|
191
|
+
* bind to all available interfaces.
|
|
192
|
+
* @param options Binding options.
|
|
193
|
+
* @returns A promise that resolves when the socket is successfully bound.
|
|
194
|
+
*/
|
|
195
|
+
bind(port?: number, address?: string, options?: Except<dgram.BindOptions, "address" | "port">): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Closes the UDP socket.
|
|
198
|
+
*
|
|
199
|
+
* @returns A promise that resolves when the socket is successfully closed.
|
|
200
|
+
*/
|
|
201
|
+
close(): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Returns statistics about the underlying send queue.
|
|
204
|
+
*
|
|
205
|
+
* This wraps {@link dgram.Socket.getSendQueueCount} and
|
|
206
|
+
* {@link dgram.Socket.getSendQueueSize} into a single object.
|
|
207
|
+
*/
|
|
208
|
+
getStat(): DgramSocketStat;
|
|
209
|
+
/**
|
|
210
|
+
* Sends a message to the specified address and port.
|
|
211
|
+
*
|
|
212
|
+
* The msg argument contains the message to be sent. Depending on its type,
|
|
213
|
+
* different behavior can apply. If msg is a Buffer, any TypedArray or a
|
|
214
|
+
* DataView, the offset and length specify the offset within the Buffer where
|
|
215
|
+
* the message begins and the number of bytes in the message, respectively.
|
|
216
|
+
*
|
|
217
|
+
* If msg is a String, then it is automatically converted to a Buffer with
|
|
218
|
+
* 'utf8' encoding.
|
|
219
|
+
*
|
|
220
|
+
* With messages that contain multi-byte characters, offset and length will be
|
|
221
|
+
* calculated with respect to byte length and not the character position. If
|
|
222
|
+
* msg is an array, offset and length must not be specified.
|
|
223
|
+
*
|
|
224
|
+
* @param port The destination port.
|
|
225
|
+
* @param address The destination address.
|
|
226
|
+
* @param msg The message to send. This can be a `Buffer`, `TypedArray`, or
|
|
227
|
+
* `DataView`.
|
|
228
|
+
* @param offset Optional offset in the message buffer to start sending from.
|
|
229
|
+
* @param length Optional number of bytes to send from the message buffer.
|
|
230
|
+
* @returns A promise that resolves with the number of bytes sent.
|
|
231
|
+
*/
|
|
232
|
+
send(port: number, address: string, msg: string | TypedArray | DataView, offset?: number, length?: number): Promise<number>;
|
|
233
|
+
private setupEventForwarding;
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=dgram-socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dgram-socket.d.ts","sourceRoot":"","sources":["../../src/net/dgram-socket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAsB,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAIpD,wDAAwD;AACxD,MAAM,MAAM,iBAAiB,GAAG;IAC/B,yCAAyC;IACzC,KAAK,EAAE,EAAE,CAAC;IAEV,0DAA0D;IAC1D,OAAO,EAAE,EAAE,CAAC;IAEZ,oCAAoC;IACpC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAEvB,wDAAwD;IACxD,SAAS,EAAE,EAAE,CAAC;IAEd;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,WAAW,eAAe;IAC/B,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IAEvB,8DAA8D;IAC9D,aAAa,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,WACZ,SAAQ,sBAAsB,CAAC,iBAAiB,CAChD,YAAW,mBAAmB,CAAC,iBAAiB,CAAC;IAarC,OAAO,CAAC,QAAQ,CAAC,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