@evobug_com/safe-ts-feature-node 0.6.0 → 0.7.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/node-api.json +38 -20
- package/package.json +10 -2
- package/safe/hold.d.ts +55 -0
- package/safe/hold.js +124 -0
- package/safe/lock.d.ts +122 -0
- package/safe/lock.js +268 -0
- package/safe-ts.json +96 -1
package/node-api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$comment": "Every callable Node exposes, by how it fails. Checked against the running Node by test/manifest.test.ts; `node test/inventory.ts` lists what is new or gone. `errors` says what each throws/rejects member fails with, in the notation of packages/pack-kit/notation.ts (also in safe-ts.json's $comment); test/errors.test.ts makes every member it safely can fail on the running Node (test/triggers.ts) and checks the error against it. `extends` (class bases) is written from the running Node by `--write-extends`; `creates` (which class a callable returns) is written by hand. `throws`/`rejects` the checker can see are in safe-ts.json.",
|
|
3
|
-
"node": "26.
|
|
3
|
+
"node": "26.14.0",
|
|
4
4
|
"categories": {
|
|
5
5
|
"throws": "Throws synchronously on runtime conditions: I/O, the environment, or data from outside (a file, a request, user input).",
|
|
6
6
|
"rejects": "The returned promise rejects on runtime conditions.",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"node:crypto": { "*": "Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "argon2Sync": "Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "scryptSync": "RangeError [ERR_CRYPTO_INVALID_SCRYPT_PARAMS]", "createCipheriv": "RangeError [ERR_CRYPTO_INVALID_KEYLEN] | TypeError [ERR_CRYPTO_INVALID_IV]", "createDecipheriv": "RangeError [ERR_CRYPTO_INVALID_KEYLEN] | TypeError [ERR_CRYPTO_INVALID_IV]", "diffieHellman": "Error [ERR_CRYPTO_INCOMPATIBLE_KEY] | Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "setEngine": "Error [ERR_CRYPTO_ENGINE_UNKNOWN]", "setFips": "Error [ERR_CRYPTO_FIPS_FORCED] | TypeError [ERR_WORKER_UNSUPPORTED_OPERATION] | Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "timingSafeEqual": "RangeError [ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH]", "encapsulate": "Error [ERR_CRYPTO_OPERATION_FAILED]", "decapsulate": "Error [ERR_CRYPTO_OPERATION_FAILED]", "createMac": "TypeError [ERR_CRYPTO_INVALID_MAC | ERR_CRYPTO_INVALID_DIGEST] | Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "parsePKCS12": "Error [ERR_CRYPTO_OPERATION_FAILED] | Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "Cipheriv#final": "Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "Decipheriv#final": "Error [ERR_OSSL_*] {library, reason, opensslErrorStack?} | Error", "Decipheriv#setAuthTag": "TypeError [ERR_CRYPTO_INVALID_AUTH_TAG]", "DiffieHellman#computeSecret": "RangeError [ERR_CRYPTO_INVALID_KEYLEN] | Error [ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY]", "DiffieHellmanGroup#computeSecret": "RangeError [ERR_CRYPTO_INVALID_KEYLEN] | Error [ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY]", "ECDH#computeSecret": "Error [ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY | ERR_CRYPTO_OPERATION_FAILED]", "ECDH.convertKey": "Error [ERR_CRYPTO_OPERATION_FAILED]", "ECDH#setPrivateKey": "RangeError [ERR_CRYPTO_INVALID_KEYTYPE] | Error [ERR_CRYPTO_OPERATION_FAILED]" },
|
|
28
28
|
"node:dgram": { "Socket#setMulticastInterface": "Error [E*] {errno, syscall: 'setMulticastInterface'}", "Socket#addMembership": "Error [E*] {errno, syscall: 'addMembership'}", "Socket#dropMembership": "Error [E*] {errno, syscall: 'dropMembership'}", "Socket#addSourceSpecificMembership": "Error [E*] {errno, syscall: 'addSourceSpecificMembership'}", "Socket#dropSourceSpecificMembership": "Error [E*] {errno, syscall: 'dropSourceSpecificMembership'}", "Socket#bindSync": "Error [E*] {errno, syscall: 'bind', address, port?}", "Socket#connectSync": "Error [E*] {errno, syscall: 'bind' | 'connect', address, port?}", "Socket#setRecvBufferSize": "SystemError [ERR_SOCKET_BUFFER_SIZE] {info, errno, syscall: 'uv_recv_buffer_size'}", "Socket#setSendBufferSize": "SystemError [ERR_SOCKET_BUFFER_SIZE] {info, errno, syscall: 'uv_send_buffer_size'}" },
|
|
29
29
|
"node:dns/promises": { "lookup": "Error [ENOTFOUND | EAI_*] {errno, syscall: 'getaddrinfo', hostname}", "lookupService": "Error [ENOTFOUND | EAI_*] {errno, syscall: 'getnameinfo'}", "reverse": "Error [dns.*] {syscall: 'getHostByAddr', hostname} | Error [EINVAL] {errno, syscall: 'getHostByAddr', hostname}", "resolve": "Error [dns.*] {syscall: 'query*', hostname}", "resolveAny": "Error [dns.*] {syscall: 'queryAny', hostname}", "resolve4": "Error [dns.*] {syscall: 'queryA', hostname}", "resolve6": "Error [dns.*] {syscall: 'queryAaaa', hostname}", "resolveCaa": "Error [dns.*] {syscall: 'queryCaa', hostname}", "resolveCname": "Error [dns.*] {syscall: 'queryCname', hostname}", "resolveMx": "Error [dns.*] {syscall: 'queryMx', hostname}", "resolveNs": "Error [dns.*] {syscall: 'queryNs', hostname}", "resolveTlsa": "Error [dns.*] {syscall: 'queryTlsa', hostname}", "resolveTxt": "Error [dns.*] {syscall: 'queryTxt', hostname}", "resolveSrv": "Error [dns.*] {syscall: 'querySrv', hostname}", "resolvePtr": "Error [dns.*] {syscall: 'queryPtr', hostname}", "resolveNaptr": "Error [dns.*] {syscall: 'queryNaptr', hostname}", "resolveSoa": "Error [dns.*] {syscall: 'querySoa', hostname}", "Resolver#reverse": "Error [dns.*] {syscall: 'getHostByAddr', hostname} | Error [EINVAL] {errno, syscall: 'getHostByAddr', hostname}", "Resolver#resolve": "Error [dns.*] {syscall: 'query*', hostname}", "Resolver#resolveAny": "Error [dns.*] {syscall: 'queryAny', hostname}", "Resolver#resolve4": "Error [dns.*] {syscall: 'queryA', hostname}", "Resolver#resolve6": "Error [dns.*] {syscall: 'queryAaaa', hostname}", "Resolver#resolveCaa": "Error [dns.*] {syscall: 'queryCaa', hostname}", "Resolver#resolveCname": "Error [dns.*] {syscall: 'queryCname', hostname}", "Resolver#resolveMx": "Error [dns.*] {syscall: 'queryMx', hostname}", "Resolver#resolveNs": "Error [dns.*] {syscall: 'queryNs', hostname}", "Resolver#resolveTlsa": "Error [dns.*] {syscall: 'queryTlsa', hostname}", "Resolver#resolveTxt": "Error [dns.*] {syscall: 'queryTxt', hostname}", "Resolver#resolveSrv": "Error [dns.*] {syscall: 'querySrv', hostname}", "Resolver#resolvePtr": "Error [dns.*] {syscall: 'queryPtr', hostname}", "Resolver#resolveNaptr": "Error [dns.*] {syscall: 'queryNaptr', hostname}", "Resolver#resolveSoa": "Error [dns.*] {syscall: 'querySoa', hostname}" },
|
|
30
|
-
"node:fs": { "accessSync": "Error [E*] {errno, syscall: 'access', path}", "chmodSync": "Error [E*] {errno, syscall: 'chmod', path}", "chownSync": "Error [E*] {errno, syscall: 'chown', path}", "lchownSync": "Error [E*] {errno, syscall: 'lchown', path}", "lstatSync": "Error [E*] {errno, syscall: 'lstat', path}", "statSync": "Error [E*] {errno, syscall: 'stat', path}", "statfsSync": "Error [E*] {errno, syscall: 'statfs', path}", "utimesSync": "Error [E*] {errno, syscall: 'utime', path}", "lutimesSync": "Error [E*] {errno, syscall: 'lutime', path}", "unlinkSync": "Error [E*] {errno, syscall: 'unlink', path}", "rmdirSync": "Error [E*] {errno, syscall: 'rmdir', path}", "readlinkSync": "Error [E*] {errno, syscall: 'readlink', path}", "readdirSync": "Error [E*] {errno, syscall: 'scandir', path}", "mkdirSync": "Error [E*] {errno, syscall: 'mkdir', path}", "mkdtempSync": "Error [E*] {errno, syscall: 'mkdtemp', path}", "mkdtempDisposableSync": "Error [E*] {errno, syscall: 'mkdtemp', path}", "openSync": "Error [E*] {errno, syscall: 'open', path}", "opendirSync": "Error [E*] {errno, syscall: 'opendir', path?}", "truncateSync": "Error [E*] {errno, syscall: 'open' | 'ftruncate', path?}", "realpathSync": "Error [E*] {errno, syscall: 'lstat' | 'stat' | 'readlink', path}", "realpathSync.native": "Error [E*] {errno, syscall: 'realpath', path}", "watch": "Error [E*] {errno, syscall: 'watch', path, filename}", "copyFileSync": "Error [E*] {errno, syscall: 'copyfile', path, dest}", "linkSync": "Error [E*] {errno, syscall: 'link', path, dest}", "symlinkSync": "Error [E*] {errno, syscall: 'symlink', path, dest}", "renameSync": "Error [E*] {errno, syscall: 'rename', path, dest}", "closeSync": "Error [E*] {errno, syscall: 'close'}", "fchmodSync": "Error [E*] {errno, syscall: 'fchmod'}", "fchownSync": "Error [E*] {errno, syscall: 'fchown'}", "fdatasyncSync": "Error [E*] {errno, syscall: 'fdatasync'}", "fstatSync": "Error [E*] {errno, syscall: 'fstat'}", "fsyncSync": "Error [E*] {errno, syscall: 'fsync'}", "ftruncateSync": "Error [E*] {errno, syscall: 'ftruncate'}", "futimesSync": "Error [E*] {errno, syscall: 'futime'}", "readSync": "Error [E*] {errno, syscall: 'read'}", "readvSync": "Error [E*] {errno, syscall: 'read'}", "writeSync": "Error [E*] {errno, syscall: 'write'}", "writevSync": "Error [E*] {errno, syscall: 'write'}", "readFileSync": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path?}", "writeFileSync": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "appendFileSync": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "openAsBlob": "Error [E*] {errno, syscall: 'stat', path}", "openAsBlobSync": "Error [E*] {errno, syscall: 'stat', path}", "lchmodSync": "Error [E*] {errno, syscall: 'open' | 'fchmod' | 'close', path?}", "rmSync": "Error [E*] {errno, syscall, path} | SystemError [ERR_FS_EISDIR] {info, errno, syscall: 'rm', path}", "cpSync": "Error [E*] {errno, syscall, path?, dest?} | Error [ERR_FS_CP_* | ERR_FS_EISDIR]", "Dir#readSync": "Error [E*] {errno, syscall}", "Dir#read": "Error [E*] {errno, syscall}", "Dir#closeSync": "Error [E*] {errno, syscall}", "Dir#close": "Error [E*] {errno, syscall}", "new Utf8Stream": "Error [E*] {errno, syscall: 'open', path}", "Utf8Stream#flushSync": "Error [E*] {errno, syscall: 'write' | 'fsync'}" },
|
|
31
|
-
"node:fs/promises": { "access": "Error [E*] {errno, syscall: 'access', path}", "chmod": "Error [E*] {errno, syscall: 'chmod', path}", "chown": "Error [E*] {errno, syscall: 'chown', path}", "lchown": "Error [E*] {errno, syscall: 'lchown', path}", "lchmod": "Error [ERR_METHOD_NOT_IMPLEMENTED]", "lstat": "Error [E*] {errno, syscall: 'lstat', path}", "stat": "Error [E*] {errno, syscall: 'stat', path}", "statfs": "Error [E*] {errno, syscall: 'statfs', path}", "utimes": "Error [E*] {errno, syscall: 'utime', path}", "lutimes": "Error [E*] {errno, syscall: 'lutime', path}", "unlink": "Error [E*] {errno, syscall: 'unlink', path}", "rmdir": "Error [E*] {errno, syscall: 'rmdir', path}", "readlink": "Error [E*] {errno, syscall: 'readlink', path}", "readdir": "Error [E*] {errno, syscall: 'scandir', path}", "mkdir": "Error [E*] {errno, syscall: 'mkdir', path}", "mkdtemp": "Error [E*] {errno, syscall: 'mkdtemp', path}", "mkdtempDisposable": "Error [E*] {errno, syscall: 'mkdtemp', path}", "open": "Error [E*] {errno, syscall: 'open', path}", "opendir": "Error [E*] {errno, syscall: 'opendir', path}", "truncate": "Error [E*] {errno, syscall: 'open' | 'ftruncate', path?}", "realpath": "Error [E*] {errno, syscall: 'realpath', path}", "copyFile": "Error [E*] {errno, syscall: 'copyfile', path, dest}", "link": "Error [E*] {errno, syscall: 'link', path, dest}", "symlink": "Error [E*] {errno, syscall: 'symlink', path, dest}", "rename": "Error [E*] {errno, syscall: 'rename', path, dest}", "readFile": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path?}", "writeFile": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "appendFile": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "rm": "Error [E*] {errno, syscall, path} | SystemError [ERR_FS_EISDIR] {info, errno, syscall: 'rm', path}", "cp": "Error [E*] {errno, syscall, path?, dest?} | SystemError [ERR_FS_CP_* | ERR_FS_EISDIR] {info, errno, syscall: 'cp', path}", "FileHandle#appendFile": "Error [E*] {errno, syscall: 'write'}", "FileHandle#writeFile": "Error [E*] {errno, syscall: 'write'}", "FileHandle#write": "Error [E*] {errno, syscall: 'write'}", "FileHandle#writev": "Error [E*] {errno, syscall: 'write'}", "FileHandle#read": "Error [E*] {errno, syscall: 'read'}", "FileHandle#readv": "Error [E*] {errno, syscall: 'read'}", "FileHandle#readFile": "Error [E*] {errno, syscall: 'fstat' | 'read'}", "FileHandle#chmod": "Error [E*] {errno, syscall: 'fchmod'}", "FileHandle#chown": "Error [E*] {errno, syscall: 'fchown'}", "FileHandle#datasync": "Error [E*] {errno, syscall: 'fdatasync'}", "FileHandle#sync": "Error [E*] {errno, syscall: 'fsync'}", "FileHandle#stat": "Error [E*] {errno, syscall: 'fstat'}", "FileHandle#truncate": "Error [E*] {errno, syscall: 'ftruncate'}", "FileHandle#utimes": "Error [E*] {errno, syscall: 'futime'}", "FileHandle#close": "Error [E*] {errno, syscall: 'close'}" },
|
|
30
|
+
"node:fs": { "accessSync": "Error [E*] {errno, syscall: 'access', path}", "chmodSync": "Error [E*] {errno, syscall: 'chmod', path}", "chownSync": "Error [E*] {errno, syscall: 'chown', path}", "lchownSync": "Error [E*] {errno, syscall: 'lchown', path}", "lstatSync": "Error [E*] {errno, syscall: 'lstat', path}", "statSync": "Error [E*] {errno, syscall: 'stat', path}", "statfsSync": "Error [E*] {errno, syscall: 'statfs', path}", "utimesSync": "Error [E*] {errno, syscall: 'utime', path}", "lutimesSync": "Error [E*] {errno, syscall: 'lutime', path}", "unlinkSync": "Error [E*] {errno, syscall: 'unlink', path}", "rmdirSync": "Error [E*] {errno, syscall: 'rmdir', path}", "readlinkSync": "Error [E*] {errno, syscall: 'readlink', path}", "readdirSync": "Error [E*] {errno, syscall: 'scandir', path}", "mkdirSync": "Error [E*] {errno, syscall: 'mkdir', path}", "mkdtempSync": "Error [E*] {errno, syscall: 'mkdtemp', path}", "mkdtempDisposableSync": "Error [E*] {errno, syscall: 'mkdtemp', path}", "mkstempSync": "Error [E*] {errno, syscall: 'mkstemp', path}", "openSync": "Error [E*] {errno, syscall: 'open', path}", "opendirSync": "Error [E*] {errno, syscall: 'opendir', path?}", "truncateSync": "Error [E*] {errno, syscall: 'open' | 'ftruncate', path?}", "realpathSync": "Error [E*] {errno, syscall: 'lstat' | 'stat' | 'readlink', path}", "realpathSync.native": "Error [E*] {errno, syscall: 'realpath', path}", "watch": "Error [E*] {errno, syscall: 'watch', path, filename}", "copyFileSync": "Error [E*] {errno, syscall: 'copyfile', path, dest}", "linkSync": "Error [E*] {errno, syscall: 'link', path, dest}", "symlinkSync": "Error [E*] {errno, syscall: 'symlink', path, dest}", "renameSync": "Error [E*] {errno, syscall: 'rename', path, dest}", "closeSync": "Error [E*] {errno, syscall: 'close'}", "fchmodSync": "Error [E*] {errno, syscall: 'fchmod'}", "fchownSync": "Error [E*] {errno, syscall: 'fchown'}", "fdatasyncSync": "Error [E*] {errno, syscall: 'fdatasync'}", "fstatSync": "Error [E*] {errno, syscall: 'fstat'}", "fsyncSync": "Error [E*] {errno, syscall: 'fsync'}", "ftruncateSync": "Error [E*] {errno, syscall: 'ftruncate'}", "futimesSync": "Error [E*] {errno, syscall: 'futime'}", "readSync": "Error [E*] {errno, syscall: 'read'}", "readvSync": "Error [E*] {errno, syscall: 'read'}", "writeSync": "Error [E*] {errno, syscall: 'write'}", "writevSync": "Error [E*] {errno, syscall: 'write'}", "readFileSync": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path?}", "writeFileSync": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "appendFileSync": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "openAsBlob": "Error [E*] {errno, syscall: 'stat', path}", "openAsBlobSync": "Error [E*] {errno, syscall: 'stat', path}", "lchmodSync": "Error [E*] {errno, syscall: 'open' | 'fchmod' | 'close', path?}", "rmSync": "Error [E*] {errno, syscall, path} | SystemError [ERR_FS_EISDIR] {info, errno, syscall: 'rm', path}", "cpSync": "Error [E*] {errno, syscall, path?, dest?} | Error [ERR_FS_CP_* | ERR_FS_EISDIR]", "Dir#readSync": "Error [E*] {errno, syscall}", "Dir#read": "Error [E*] {errno, syscall}", "Dir#closeSync": "Error [E*] {errno, syscall}", "Dir#close": "Error [E*] {errno, syscall}", "new Utf8Stream": "Error [E*] {errno, syscall: 'open', path}", "Utf8Stream#flushSync": "Error [E*] {errno, syscall: 'write' | 'fsync'}" },
|
|
31
|
+
"node:fs/promises": { "access": "Error [E*] {errno, syscall: 'access', path}", "chmod": "Error [E*] {errno, syscall: 'chmod', path}", "chown": "Error [E*] {errno, syscall: 'chown', path}", "lchown": "Error [E*] {errno, syscall: 'lchown', path}", "lchmod": "Error [ERR_METHOD_NOT_IMPLEMENTED]", "lstat": "Error [E*] {errno, syscall: 'lstat', path}", "stat": "Error [E*] {errno, syscall: 'stat', path}", "statfs": "Error [E*] {errno, syscall: 'statfs', path}", "utimes": "Error [E*] {errno, syscall: 'utime', path}", "lutimes": "Error [E*] {errno, syscall: 'lutime', path}", "unlink": "Error [E*] {errno, syscall: 'unlink', path}", "rmdir": "Error [E*] {errno, syscall: 'rmdir', path}", "readlink": "Error [E*] {errno, syscall: 'readlink', path}", "readdir": "Error [E*] {errno, syscall: 'scandir', path}", "mkdir": "Error [E*] {errno, syscall: 'mkdir', path}", "mkdtemp": "Error [E*] {errno, syscall: 'mkdtemp', path}", "mkdtempDisposable": "Error [E*] {errno, syscall: 'mkdtemp', path}", "mkstemp": "Error [E*] {errno, syscall: 'mkstemp', path}", "open": "Error [E*] {errno, syscall: 'open', path}", "opendir": "Error [E*] {errno, syscall: 'opendir', path}", "truncate": "Error [E*] {errno, syscall: 'open' | 'ftruncate', path?}", "realpath": "Error [E*] {errno, syscall: 'realpath', path}", "copyFile": "Error [E*] {errno, syscall: 'copyfile', path, dest}", "link": "Error [E*] {errno, syscall: 'link', path, dest}", "symlink": "Error [E*] {errno, syscall: 'symlink', path, dest}", "rename": "Error [E*] {errno, syscall: 'rename', path, dest}", "readFile": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path?}", "writeFile": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "appendFile": "Error [E*] {errno, syscall: 'open' | 'write', path?}", "rm": "Error [E*] {errno, syscall, path} | SystemError [ERR_FS_EISDIR] {info, errno, syscall: 'rm', path}", "cp": "Error [E*] {errno, syscall, path?, dest?} | SystemError [ERR_FS_CP_* | ERR_FS_EISDIR] {info, errno, syscall: 'cp', path}", "FileHandle#appendFile": "Error [E*] {errno, syscall: 'write'}", "FileHandle#writeFile": "Error [E*] {errno, syscall: 'write'}", "FileHandle#write": "Error [E*] {errno, syscall: 'write'}", "FileHandle#writev": "Error [E*] {errno, syscall: 'write'}", "FileHandle#read": "Error [E*] {errno, syscall: 'read'}", "FileHandle#readv": "Error [E*] {errno, syscall: 'read'}", "FileHandle#readFile": "Error [E*] {errno, syscall: 'fstat' | 'read'}", "FileHandle#chmod": "Error [E*] {errno, syscall: 'fchmod'}", "FileHandle#chown": "Error [E*] {errno, syscall: 'fchown'}", "FileHandle#datasync": "Error [E*] {errno, syscall: 'fdatasync'}", "FileHandle#sync": "Error [E*] {errno, syscall: 'fsync'}", "FileHandle#stat": "Error [E*] {errno, syscall: 'fstat'}", "FileHandle#truncate": "Error [E*] {errno, syscall: 'ftruncate'}", "FileHandle#utimes": "Error [E*] {errno, syscall: 'futime'}", "FileHandle#close": "Error [E*] {errno, syscall: 'close'}" },
|
|
32
32
|
"node:http": { "*": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_INVALID_CHAR]", "get": "TypeError [ERR_INVALID_URL] {input} | TypeError [ERR_UNESCAPED_CHARACTERS | ERR_INVALID_PROTOCOL]", "request": "TypeError [ERR_INVALID_URL] {input} | TypeError [ERR_UNESCAPED_CHARACTERS | ERR_INVALID_PROTOCOL]", "validateHeaderName": "TypeError [ERR_INVALID_HTTP_TOKEN]", "validateHeaderName.withoutStackTrace": "TypeError [ERR_INVALID_HTTP_TOKEN]", "validateHeaderValue": "TypeError [ERR_HTTP_INVALID_HEADER_VALUE | ERR_INVALID_CHAR]", "validateHeaderValue.withoutStackTrace": "TypeError [ERR_HTTP_INVALID_HEADER_VALUE | ERR_INVALID_CHAR]", "OutgoingMessage#setHeader": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP_INVALID_HEADER_VALUE | ERR_INVALID_CHAR]", "OutgoingMessage#setHeaders": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP_INVALID_HEADER_VALUE | ERR_INVALID_CHAR]", "OutgoingMessage#appendHeader": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP_INVALID_HEADER_VALUE | ERR_INVALID_CHAR]", "ServerResponse#writeHead": "RangeError [ERR_HTTP_INVALID_STATUS_CODE] | TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP_INVALID_HEADER_VALUE | ERR_INVALID_CHAR]", "new WebSocket": "DOMException [SyntaxError]" },
|
|
33
33
|
"node:http2": { "*": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP2_INVALID_HEADER_VALUE | ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED]", "getUnpackedSettings": "RangeError [ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH]", "createSecureServer": "Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}", "Http2ServerResponse#writeHead": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP2_INVALID_HEADER_VALUE | ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED] | RangeError [ERR_HTTP2_STATUS_INVALID]", "ClientHttp2Session#request": "TypeError [ERR_INVALID_HTTP_TOKEN | ERR_HTTP2_INVALID_PSEUDOHEADER | ERR_HTTP2_HEADER_SINGLE_VALUE | ERR_HTTP2_INVALID_CONNECTION_HEADERS]" },
|
|
34
34
|
"node:https": { "*": "TypeError [ERR_INVALID_URL] {input} | TypeError [ERR_UNESCAPED_CHARACTERS | ERR_INVALID_PROTOCOL]", "createServer": "Error [ERR_OSSL_*] {library, reason, opensslErrorStack?}" },
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"node:vm": { "*": "SyntaxError | (what the code throws)", "new Script": "SyntaxError", "createScript": "SyntaxError", "compileFunction": "SyntaxError", "Script#runInThisContext": "(what the code throws)", "Script#runInContext": "(what the code throws)", "Script#runInNewContext": "(what the code throws)" },
|
|
48
48
|
"node:wasi": { "*": "RuntimeError | (what the program's imports throw)" },
|
|
49
49
|
"node:worker_threads": { "*": "DOMException [DataCloneError]", "postMessageToThread": "Error [ERR_WORKER_MESSAGING_FAILED | ERR_WORKER_MESSAGING_TIMEOUT | ERR_WORKER_MESSAGING_ERRORED]", "Worker#getHeapSnapshot": "Error [ERR_WORKER_NOT_RUNNING]", "Worker#getHeapStatistics": "Error [ERR_WORKER_NOT_RUNNING]", "Worker#cpuUsage": "Error [ERR_WORKER_NOT_RUNNING]", "Worker#startCpuProfile": "Error [ERR_WORKER_NOT_RUNNING]", "Worker#startHeapProfile": "Error [ERR_WORKER_NOT_RUNNING]" },
|
|
50
|
-
"node:zlib": { "*": "Error [Z_*] {errno}", "brotliDecompressSync": "Error [ERR__ERROR_* | Z_BUF_ERROR] {errno}", "zstdDecompressSync": "Error [ZSTD_error_* | Z_BUF_ERROR] {errno}", "ZipFile.open": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path} | Error [ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ARCHIVE_TOO_LARGE]", "ZipFile.openSync": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path} | Error [ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ARCHIVE_TOO_LARGE]", "new ZipBuffer": "Error [ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ARCHIVE_TOO_LARGE]", "ZipFile#get": "Error [ERR_ZIP_ENTRY_NOT_FOUND | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | Error [E*] {errno, syscall: 'read'}", "ZipFile#getSync": "Error [ERR_ZIP_ENTRY_NOT_FOUND | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | Error [E*] {errno, syscall: 'read'}", "ZipFile#stream": "Error [ERR_ZIP_ENTRY_NOT_FOUND | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | Error [E*] {errno, syscall: 'read'}", "ZipBuffer#get": "Error [ERR_ZIP_ENTRY_NOT_FOUND]", "ZipFile#addEntry": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#add": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#addEntrySync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#addSync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#delete": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#deleteSync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#compactSync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#close": "Error [E*] {errno, syscall: 'close'}", "ZipFile#closeSync": "Error [E*] {errno, syscall: 'close'}", "ZipEntry#content": "Error [ERR_ZIP_ENTRY_CORRUPT | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [Z_*] {errno} | Error [E*] {errno, syscall: 'read'}", "ZipEntry#contentSync": "Error [ERR_ZIP_ENTRY_CORRUPT | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [Z_*] {errno} | Error [E*] {errno, syscall: 'read'}", "ZipBuffer#toBuffer": "(the entry source's error) | Error [E*] {errno, syscall: 'read'}", "ZipBuffer#toBufferSync": "Error [E*] {errno, syscall: 'read'}" },
|
|
50
|
+
"node:zlib": { "*": "Error [Z_*] {errno}", "brotliDecompressSync": "Error [ERR__ERROR_* | Z_BUF_ERROR] {errno}", "zstdDecompressSync": "Error [ZSTD_error_* | Z_BUF_ERROR] {errno}", "ZipFile.open": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path} | Error [ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ARCHIVE_TOO_LARGE]", "ZipFile.openSync": "Error [E*] {errno, syscall: 'open' | 'fstat' | 'read', path} | Error [ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ARCHIVE_TOO_LARGE]", "new ZipBuffer": "Error [ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ARCHIVE_TOO_LARGE]", "ZipFile#get": "Error [ERR_ZIP_ENTRY_NOT_FOUND | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | Error [E*] {errno, syscall: 'read'}", "ZipFile#getSync": "Error [ERR_ZIP_ENTRY_NOT_FOUND | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | Error [E*] {errno, syscall: 'read'}", "ZipFile#stream": "Error [ERR_ZIP_ENTRY_NOT_FOUND | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | Error [E*] {errno, syscall: 'read'}", "ZipBuffer#get": "Error [ERR_ZIP_ENTRY_NOT_FOUND]", "ZipFile#addEntry": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#add": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#addEntrySync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#addSync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#delete": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#deleteSync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#compactSync": "Error [E*] {errno, syscall: 'read' | 'write' | 'ftruncate' | 'fsync'}", "ZipFile#close": "Error [E*] {errno, syscall: 'close'}", "ZipFile#closeSync": "Error [E*] {errno, syscall: 'close'}", "ZipEntry#content": "Error [ERR_ZIP_ENTRY_CORRUPT | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [Z_*] {errno} | Error [E*] {errno, syscall: 'read'}", "ZipEntry#contentSync": "Error [ERR_ZIP_ENTRY_CORRUPT | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [Z_*] {errno} | Error [E*] {errno, syscall: 'read'}", "ZipEntry#rawContent": "Error [ERR_ZIP_INVALID_ARCHIVE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [E*] {errno, syscall: 'read'}", "ZipEntry#rawContentSync": "Error [ERR_ZIP_INVALID_ARCHIVE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [E*] {errno, syscall: 'read'}", "ZipBuffer#toBuffer": "(the entry source's error) | Error [E*] {errno, syscall: 'read'}", "ZipBuffer#toBufferSync": "Error [E*] {errno, syscall: 'read'}" },
|
|
51
51
|
"node:sqlite": { "*": "Error [ERR_SQLITE_ERROR] {errcode, errstr?}", "Database#loadExtension": "Error [ERR_LOAD_SQLITE_EXTENSION]" },
|
|
52
52
|
"node:ffi": { "*": "Error [ERR_FFI_CALL_FAILED]" },
|
|
53
53
|
"globals": { "structuredClone": "DOMException [DataCloneError]", "AbortSignal#throwIfAborted": "DOMException [AbortError | TimeoutError] | (the signal's reason)", "Headers#append": "TypeError", "Headers#set": "TypeError", "new Request": "TypeError {cause?}", "new Response": "RangeError | TypeError", "Response.json": "TypeError | (what toJSON throws)", "Request#clone": "TypeError", "Response#clone": "TypeError", "Storage#setItem": "DOMException [QuotaExceededError]", "fetch": "TypeError {cause} | DOMException [AbortError | TimeoutError] | (the signal's reason)", "Request#blob": "TypeError", "Request#arrayBuffer": "TypeError", "Request#text": "TypeError", "Request#bytes": "TypeError", "Request#json": "SyntaxError | TypeError", "Request#formData": "TypeError", "Response#blob": "TypeError", "Response#arrayBuffer": "TypeError", "Response#text": "TypeError", "Response#bytes": "TypeError", "Response#json": "SyntaxError | TypeError", "Response#formData": "TypeError", "SubtleCrypto#encrypt": "DOMException [OperationError] {cause?}", "SubtleCrypto#decrypt": "DOMException [OperationError] {cause?}", "SubtleCrypto#deriveKey": "DOMException [InvalidAccessError | OperationError] {cause?}", "SubtleCrypto#deriveBits": "DOMException [InvalidAccessError | OperationError] {cause?}", "SubtleCrypto#importKey": "DOMException [DataError | NotSupportedError]", "SubtleCrypto#wrapKey": "DOMException [InvalidAccessError | OperationError] {cause?}", "SubtleCrypto#unwrapKey": "DOMException [InvalidAccessError | OperationError | DataError] {cause?}", "SubtleCrypto#encapsulateBits": "DOMException [InvalidAccessError | OperationError] {cause?}", "SubtleCrypto#encapsulateKey": "DOMException [InvalidAccessError | OperationError] {cause?}", "SubtleCrypto#decapsulateBits": "DOMException [InvalidAccessError | OperationError] {cause?}", "SubtleCrypto#decapsulateKey": "DOMException [InvalidAccessError | OperationError] {cause?}" }
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"node:stream/web": { "ReadableStream#getReader": "ReadableStreamDefaultReader", "WritableStream#getWriter": "WritableStreamDefaultWriter" },
|
|
105
105
|
"node:url": { "parse": "Url" },
|
|
106
106
|
"node:worker_threads": { "parentPort": "MessagePort" },
|
|
107
|
-
"node:zlib": { "ZipFile.open": "ZipFile", "ZipFile.openSync": "ZipFile", "ZipFile#get": "ZipEntry", "ZipFile#getSync": "ZipEntry", "ZipFile#stream": "node:stream Readable", "ZipBuffer#get": "ZipEntry", "ZipBuffer#toBuffer": "node:buffer Buffer", "ZipBuffer#toBufferSync": "node:buffer Buffer", "ZipEntry.create": "ZipEntry", "ZipEntry.createSync": "ZipEntry", "ZipEntry#content": "node:buffer Buffer", "ZipEntry#contentSync": "node:buffer Buffer", "zipFiles": "node:stream Readable", "createGzip": "Gzip", "createGunzip": "Gunzip", "createDeflate": "Deflate", "createInflate": "Inflate", "createDeflateRaw": "DeflateRaw", "createInflateRaw": "InflateRaw", "createUnzip": "Unzip", "createBrotliCompress": "BrotliCompress", "createBrotliDecompress": "BrotliDecompress", "createZstdCompress": "ZstdCompress", "createZstdDecompress": "ZstdDecompress" },
|
|
107
|
+
"node:zlib": { "ZipFile.open": "ZipFile", "ZipFile.openSync": "ZipFile", "ZipFile#get": "ZipEntry", "ZipFile#getSync": "ZipEntry", "ZipFile#stream": "node:stream Readable", "ZipBuffer#get": "ZipEntry", "ZipBuffer#toBuffer": "node:buffer Buffer", "ZipBuffer#toBufferSync": "node:buffer Buffer", "ZipEntry.create": "ZipEntry", "ZipEntry.createSync": "ZipEntry", "ZipEntry#content": "node:buffer Buffer", "ZipEntry#contentSync": "node:buffer Buffer", "ZipEntry#rawContent": "node:buffer Buffer", "ZipEntry#rawContentSync": "node:buffer Buffer", "zipFiles": "node:stream Readable", "createGzip": "Gzip", "createGunzip": "Gunzip", "createDeflate": "Deflate", "createInflate": "Inflate", "createDeflateRaw": "DeflateRaw", "createInflateRaw": "InflateRaw", "createUnzip": "Unzip", "createBrotliCompress": "BrotliCompress", "createBrotliDecompress": "BrotliDecompress", "createZstdCompress": "ZstdCompress", "createZstdDecompress": "ZstdDecompress" },
|
|
108
108
|
"globals": { "fetch": "Response", "Response.json": "Response", "Response.error": "Response", "Response.redirect": "Response", "Response#clone": "Response", "Request#clone": "Request", "crypto": "Crypto", "Crypto#subtle": "SubtleCrypto", "localStorage": "Storage", "sessionStorage": "Storage" }
|
|
109
109
|
},
|
|
110
110
|
"modules": {
|
|
@@ -223,16 +223,16 @@
|
|
|
223
223
|
"never": ["new Domain", "Domain#enter", "Domain#exit", "Domain#add", "Domain#remove", "createDomain"]
|
|
224
224
|
},
|
|
225
225
|
"node:fs": {
|
|
226
|
-
"throws": ["appendFileSync", "accessSync", "chownSync", "chmodSync", "closeSync", "copyFileSync", "cpSync", "fchownSync", "fchmodSync", "fdatasyncSync", "fstatSync", "fsyncSync", "ftruncateSync", "futimesSync", "lchownSync", "linkSync", "lstatSync", "lutimesSync", "mkdirSync", "mkdtempSync", "mkdtempDisposableSync", "openSync", "openAsBlob", "readdirSync", "readSync", "readvSync", "readFileSync", "readlinkSync", "realpathSync", "realpathSync.native", "renameSync", "rmSync", "rmdirSync", "statSync", "statfsSync", "symlinkSync", "truncateSync", "unlinkSync", "utimesSync", "watch", "writeFileSync", "writeSync", "writevSync", "opendirSync", "Dir#readSync", "Dir#closeSync", "new Utf8Stream", "Utf8Stream#flushSync", "lchmodSync", "openAsBlobSync"],
|
|
226
|
+
"throws": ["appendFileSync", "accessSync", "chownSync", "chmodSync", "closeSync", "copyFileSync", "cpSync", "fchownSync", "fchmodSync", "fdatasyncSync", "fstatSync", "fsyncSync", "ftruncateSync", "futimesSync", "lchownSync", "linkSync", "lstatSync", "lutimesSync", "mkdirSync", "mkdtempSync", "mkdtempDisposableSync", "mkstempSync", "openSync", "openAsBlob", "readdirSync", "readSync", "readvSync", "readFileSync", "readlinkSync", "realpathSync", "realpathSync.native", "renameSync", "rmSync", "rmdirSync", "statSync", "statfsSync", "symlinkSync", "truncateSync", "unlinkSync", "utimesSync", "watch", "writeFileSync", "writeSync", "writevSync", "opendirSync", "Dir#readSync", "Dir#closeSync", "new Utf8Stream", "Utf8Stream#flushSync", "lchmodSync", "openAsBlobSync"],
|
|
227
227
|
"rejects": ["Dir#read", "Dir#close"],
|
|
228
228
|
"iterates": ["Dir#entries"],
|
|
229
|
-
"callback": ["appendFile", "access", "chown", "chmod", "close", "copyFile", "cp", "fchown", "fchmod", "fdatasync", "fstat", "fsync", "ftruncate", "futimes", "glob", "lchown", "link", "lstat", "lutimes", "mkdir", "mkdtemp", "open", "readdir", "read", "readv", "readFile", "readlink", "realpath", "realpath.native", "rename", "rm", "rmdir", "stat", "statfs", "symlink", "truncate", "unlink", "utimes", "writeFile", "write", "writev", "opendir", "lchmod", "ReadStream#close", "WriteStream#close", "Utf8Stream#flush"],
|
|
229
|
+
"callback": ["appendFile", "access", "chown", "chmod", "close", "copyFile", "cp", "fchown", "fchmod", "fdatasync", "fstat", "fsync", "ftruncate", "futimes", "glob", "lchown", "link", "lstat", "lutimes", "mkdir", "mkdtemp", "mkstemp", "open", "readdir", "read", "readv", "readFile", "readlink", "realpath", "realpath.native", "rename", "rm", "rmdir", "stat", "statfs", "symlink", "truncate", "unlink", "utimes", "writeFile", "write", "writev", "opendir", "lchmod", "ReadStream#close", "WriteStream#close", "Utf8Stream#flush"],
|
|
230
230
|
"event": ["createReadStream", "createWriteStream", "Utf8Stream#write", "Utf8Stream#reopen"],
|
|
231
231
|
"args": ["watchFile", "new ReadStream", "new WriteStream", "FSWatcher#start", "StatWatcher#start"],
|
|
232
232
|
"never": ["exists", "existsSync", "globSync", "unwatchFile", "new Dirent", "Dirent#isDirectory", "Dirent#isFile", "Dirent#isBlockDevice", "Dirent#isCharacterDevice", "Dirent#isSymbolicLink", "Dirent#isFIFO", "Dirent#isSocket", "Stats", "WriteStream#destroySoon", "Utf8Stream#end", "Utf8Stream#destroy", "new Dir", "FSWatcher#close", "FSWatcher#ref", "FSWatcher#unref", "StatWatcher#stop", "StatWatcher#ref", "StatWatcher#unref"]
|
|
233
233
|
},
|
|
234
234
|
"node:fs/promises": {
|
|
235
|
-
"rejects": ["access", "copyFile", "cp", "open", "opendir", "rename", "truncate", "rm", "rmdir", "mkdir", "readdir", "readlink", "symlink", "lstat", "stat", "statfs", "link", "unlink", "chmod", "lchmod", "lchown", "chown", "utimes", "lutimes", "realpath", "mkdtemp", "mkdtempDisposable", "writeFile", "appendFile", "readFile", "FileHandle#appendFile", "FileHandle#chmod", "FileHandle#chown", "FileHandle#datasync", "FileHandle#sync", "FileHandle#read", "FileHandle#readv", "FileHandle#readFile", "FileHandle#stat", "FileHandle#truncate", "FileHandle#utimes", "FileHandle#write", "FileHandle#writev", "FileHandle#writeFile", "FileHandle#close"],
|
|
235
|
+
"rejects": ["access", "copyFile", "cp", "open", "opendir", "rename", "truncate", "rm", "rmdir", "mkdir", "readdir", "readlink", "symlink", "lstat", "stat", "statfs", "link", "unlink", "chmod", "lchmod", "lchown", "chown", "utimes", "lutimes", "realpath", "mkdtemp", "mkdtempDisposable", "mkstemp", "writeFile", "appendFile", "readFile", "FileHandle#appendFile", "FileHandle#chmod", "FileHandle#chown", "FileHandle#datasync", "FileHandle#sync", "FileHandle#read", "FileHandle#readv", "FileHandle#readFile", "FileHandle#stat", "FileHandle#truncate", "FileHandle#utimes", "FileHandle#write", "FileHandle#writev", "FileHandle#writeFile", "FileHandle#close"],
|
|
236
236
|
"iterates": ["glob", "watch", "FileHandle#readLines"],
|
|
237
237
|
"event": ["FileHandle#createReadStream", "FileHandle#createWriteStream"],
|
|
238
238
|
"args": ["FileHandle#readableWebStream"],
|
|
@@ -389,13 +389,13 @@
|
|
|
389
389
|
"never": ["MessagePort#start", "MessagePort#ref", "MessagePort#unref", "MessagePort#hasRef", "MessagePort#close", "MessagePort#getMaxListeners", "MessagePort#eventNames", "MessagePort#listenerCount", "MessagePort#off", "MessagePort#removeListener", "MessagePort#removeAllListeners", "MessageChannel", "isMarkedAsUntransferable", "Worker#terminate", "Worker#ref", "Worker#unref", "new BroadcastChannel", "BroadcastChannel#close", "BroadcastChannel#ref", "BroadcastChannel#unref", "getEnvironmentData", "locks.query", "setEnvironmentData"]
|
|
390
390
|
},
|
|
391
391
|
"node:zlib": {
|
|
392
|
-
"throws": ["unzipSync", "inflateSync", "gunzipSync", "inflateRawSync", "brotliDecompressSync", "zstdDecompressSync", "ZipFile.openSync", "ZipFile#getSync", "ZipFile#addEntrySync", "ZipFile#addSync", "ZipFile#deleteSync", "ZipFile#compactSync", "ZipFile#closeSync", "ZipEntry#contentSync", "new ZipBuffer", "ZipBuffer#get", "ZipBuffer#toBufferSync"],
|
|
393
|
-
"rejects": ["ZipFile.open", "ZipFile#get", "ZipFile#stream", "ZipFile#addEntry", "ZipFile#add", "ZipFile#delete", "ZipFile#close", "ZipEntry#content", "ZipBuffer#toBuffer"],
|
|
394
|
-
"iterates": ["ZipEntry.read", "ZipEntry#contentIterator", "createZipArchiveSync"],
|
|
392
|
+
"throws": ["unzipSync", "inflateSync", "gunzipSync", "inflateRawSync", "brotliDecompressSync", "zstdDecompressSync", "ZipFile.openSync", "ZipFile#getSync", "ZipFile#addEntrySync", "ZipFile#addSync", "ZipFile#deleteSync", "ZipFile#compactSync", "ZipFile#closeSync", "ZipEntry#contentSync", "ZipEntry#rawContentSync", "new ZipBuffer", "ZipBuffer#get", "ZipBuffer#toBufferSync"],
|
|
393
|
+
"rejects": ["ZipFile.open", "ZipFile#get", "ZipFile#stream", "ZipFile#addEntry", "ZipFile#add", "ZipFile#delete", "ZipFile#close", "ZipEntry#content", "ZipEntry#rawContent", "ZipBuffer#toBuffer"],
|
|
394
|
+
"iterates": ["ZipEntry.read", "ZipEntry#contentIterator", "ZipEntry#rawContentIterator", "createZipArchiveSync"],
|
|
395
395
|
"callback": ["deflate", "gzip", "deflateRaw", "unzip", "inflate", "gunzip", "inflateRaw", "brotliCompress", "brotliDecompress", "zstdCompress", "zstdDecompress", "ZstdCompress#flush", "ZstdDecompress#flush", "ZstdCompress#close", "ZstdDecompress#close"],
|
|
396
396
|
"event": ["Inflate", "Gunzip", "InflateRaw", "Unzip", "BrotliDecompress", "new ZstdDecompress", "createInflate", "createInflateRaw", "createGunzip", "createUnzip", "createBrotliDecompress", "createZstdDecompress", "ZipFile#compact", "createZipArchive", "zipFiles"],
|
|
397
397
|
"propagates": ["ZipFile#forEach", "ZipFile#forEachSync", "ZipBuffer#forEach"],
|
|
398
|
-
"args": ["crc32", "Deflate", "Gzip", "DeflateRaw", "BrotliCompress", "new ZstdCompress", "deflateSync", "gzipSync", "deflateRawSync", "brotliCompressSync", "zstdCompressSync", "createDeflate", "createDeflateRaw", "createGzip", "createBrotliCompress", "createZstdCompress", "new ZipEntry", "ZipEntry.create", "ZipEntry.createSync", "ZipEntry.createStream", "ZipEntry.createSymlink", "new ZipFile", "ZipFile#has", "ZipFile#keys", "ZipFile#values", "ZipFile#valuesSync", "ZipFile#entries", "ZipFile#entriesSync", "ZipBuffer#add", "ZipBuffer#addSync", "setMaxZipContentSize"],
|
|
398
|
+
"args": ["crc32", "crc32c", "Deflate", "Gzip", "DeflateRaw", "BrotliCompress", "new ZstdCompress", "deflateSync", "gzipSync", "deflateRawSync", "brotliCompressSync", "zstdCompressSync", "createDeflate", "createDeflateRaw", "createGzip", "createBrotliCompress", "createZstdCompress", "new ZipEntry", "ZipEntry.create", "ZipEntry.createSync", "ZipEntry.createStream", "ZipEntry.createSymlink", "new ZipFile", "ZipFile#has", "ZipFile#keys", "ZipFile#values", "ZipFile#valuesSync", "ZipFile#entries", "ZipFile#entriesSync", "ZipBuffer#add", "ZipBuffer#addSync", "setMaxZipContentSize"],
|
|
399
399
|
"never": ["ZstdCompress#reset", "ZstdDecompress#reset", "ZipBuffer#has", "ZipBuffer#addEntry", "ZipBuffer#delete", "ZipBuffer#clear", "ZipBuffer#keys", "ZipBuffer#values", "ZipBuffer#entries", "getMaxZipContentSize"]
|
|
400
400
|
},
|
|
401
401
|
"node:sea": {
|
|
@@ -410,7 +410,7 @@
|
|
|
410
410
|
},
|
|
411
411
|
"node:ffi": {
|
|
412
412
|
"throws": ["new DynamicLibrary", "DynamicLibrary#getFunction", "DynamicLibrary#getFunctions", "DynamicLibrary#getSymbol", "dlopen", "dlsym"],
|
|
413
|
-
"args": ["DynamicLibrary#registerCallback", "DynamicLibrary#unregisterCallback", "DynamicLibrary#refCallback", "DynamicLibrary#unrefCallback", "exportArrayBuffer", "exportArrayBufferView", "exportString", "exportBuffer", "getInt8", "getUint8", "getInt16", "getUint16", "getInt32", "getUint32", "getInt64", "getUint64", "getFloat32", "getFloat64", "getRawPointer", "setInt8", "setUint8", "setInt16", "setUint16", "setInt32", "setUint32", "setInt64", "setUint64", "setFloat32", "setFloat64", "toString", "toArrayBuffer", "toBuffer"],
|
|
413
|
+
"args": ["DynamicLibrary#toFunction", "DynamicLibrary#registerCallback", "DynamicLibrary#unregisterCallback", "DynamicLibrary#refCallback", "DynamicLibrary#unrefCallback", "exportArrayBuffer", "exportArrayBufferView", "exportString", "exportBuffer", "getInt8", "getUint8", "getInt16", "getUint16", "getInt32", "getUint32", "getInt64", "getUint64", "getFloat32", "getFloat64", "getRawPointer", "setInt8", "setUint8", "setInt16", "setUint16", "setInt32", "setUint32", "setInt64", "setUint64", "setFloat32", "setFloat64", "toString", "toArrayBuffer", "toBuffer"],
|
|
414
414
|
"never": ["DynamicLibrary#close", "DynamicLibrary#getSymbols", "dlclose", "getCurrentEventLoop"]
|
|
415
415
|
},
|
|
416
416
|
"node:test": {
|
|
@@ -429,21 +429,21 @@
|
|
|
429
429
|
}
|
|
430
430
|
},
|
|
431
431
|
"acquires": {
|
|
432
|
-
"$comment": "What a function acquires and must release before it ends: read by `unreleased-resource` (docs/rules/unreleased-resource.md; the format is in docs/guide/libraries.md, \"What must be released\"). Each resource is a value an operation hands back (`acquiredBy`: a callable of `modules` named as in `consumes`, `new X`, `await f` for an async one, `Class#method` for a method), that holds something until a release (`releasedBy`: `#method` of the value, or a callable and the argument the value goes in: `clearInterval 0`). A resource with `armedBy` holds nothing until then: `#method` (an observer's `observe`, a server's `listen`) or `.signal to method` (an AbortController whose `signal` is in the options of an `addEventListener`). `what` names it in a message, `means` says what staying acquired does, `release` how to release it. `lifelong`: often meant to live as long as the program (a worker's interval, a server), so reported only in a function that releases it on some path; `dispose`: the declaration that releases it by itself (`await using`). acquires.test.ts acquires each on this engine, shows it held, releases it and shows it released.",
|
|
432
|
+
"$comment": "What a function acquires and must release before it ends: read by `unreleased-resource` and `prefer-using` (docs/rules/unreleased-resource.md, docs/rules/prefer-using.md; the format is in docs/guide/libraries.md, \"What must be released\"). Each resource is a value an operation hands back (`acquiredBy`: a callable of `modules` named as in `consumes`, `new X`, `await f` for an async one, `Class#method` for a method), that holds something until a release (`releasedBy`: `#method` of the value, or a callable and the argument the value goes in: `clearInterval 0`). A resource with `armedBy` holds nothing until then: `#method` (an observer's `observe`, a server's `listen`) or `.signal to method` (an AbortController whose `signal` is in the options of an `addEventListener`). `what` names it in a message, `means` says what staying acquired does, `release` how to release it. `lifelong`: often meant to live as long as the program (a worker's interval, a server), so reported only in a function that releases it on some path; `dispose`: the declaration that releases it by itself (`await using`, `using`); `wrapper`: where the value is not disposable, a helper that hands it back disposable (`call` from the module `from`, takes the same arguments; `value`: the member holding what the platform handed back, if it isn't the value itself; `write`: a declaration with it). acquires.test.ts acquires each on this engine, shows it held, releases it and shows it released.",
|
|
433
433
|
"resources": {
|
|
434
|
-
"interval": {"acquiredBy": ["setInterval"], "releasedBy": ["clearInterval 0"], "lifelong": true, "what": "an interval", "means": "its callback keeps running, and keeps everything it captured alive", "release": "clearInterval(id)"},
|
|
435
|
-
"timeout": {"acquiredBy": ["setTimeout"], "releasedBy": ["clearTimeout 0"], "lifelong": true, "what": "a timeout", "means": "its callback still runs later, after the function meant to cancel it", "release": "clearTimeout(id)"},
|
|
434
|
+
"interval": {"acquiredBy": ["setInterval"], "releasedBy": ["clearInterval 0"], "lifelong": true, "wrapper": {"call": "interval", "from": "@evobug_com/safe-ts-std/disposable", "write": "using timer = interval(tick, ms)"}, "what": "an interval", "means": "its callback keeps running, and keeps everything it captured alive", "release": "clearInterval(id)"},
|
|
435
|
+
"timeout": {"acquiredBy": ["setTimeout"], "releasedBy": ["clearTimeout 0"], "lifelong": true, "wrapper": {"call": "timeout", "from": "@evobug_com/safe-ts-std/disposable", "write": "using deadline = timeout(fire, ms)"}, "what": "a timeout", "means": "its callback still runs later, after the function meant to cancel it", "release": "clearTimeout(id)"},
|
|
436
436
|
"abort controller": {"acquiredBy": ["new AbortController"], "armedBy": [".signal to addEventListener"], "releasedBy": ["#abort"], "lifelong": true, "what": "a controller whose signal removes listeners", "means": "the listeners it was meant to remove stay registered", "release": "controller.abort()"},
|
|
437
437
|
"broadcast channel": {"acquiredBy": ["new BroadcastChannel"], "releasedBy": ["#close"], "lifelong": true, "what": "a broadcast channel", "means": "it keeps receiving messages, and keeps the process alive", "release": "channel.close()"},
|
|
438
|
-
"object URL": {"acquiredBy": ["URL.createObjectURL"], "releasedBy": ["URL.revokeObjectURL 0"], "what": "an object URL", "means": "the blob it points to stays in memory until the page (or process) ends", "release": "URL.revokeObjectURL(url)"},
|
|
438
|
+
"object URL": {"acquiredBy": ["URL.createObjectURL"], "releasedBy": ["URL.revokeObjectURL 0"], "wrapper": {"call": "objectUrl", "from": "@evobug_com/safe-ts-std/disposable", "value": "url", "write": "using image = objectUrl(blob)"}, "what": "an object URL", "means": "the blob it points to stays in memory until the page (or process) ends", "release": "URL.revokeObjectURL(url)"},
|
|
439
439
|
"stream reader": {"acquiredBy": ["ReadableStream#getReader"], "releasedBy": ["#releaseLock", "#cancel"], "what": "a stream reader", "means": "the stream stays locked: nothing else can read or cancel it", "release": "reader.releaseLock()"},
|
|
440
440
|
"WebSocket": {"acquiredBy": ["new WebSocket"], "releasedBy": ["#close"], "lifelong": true, "what": "a WebSocket", "means": "the connection stays open", "release": "socket.close()"},
|
|
441
441
|
"file handle": {"acquiredBy": ["await node:fs/promises open"], "releasedBy": ["#close"], "dispose": "await using", "what": "a file handle", "means": "the file descriptor stays open until the garbage collector closes it (with a warning), and the process can run out of them", "release": "await handle.close()"},
|
|
442
|
-
"temporary directory": {"acquiredBy": ["await node:fs/promises mkdtemp"], "releasedBy": ["node:fs/promises rm 0"], "what": "a temporary directory", "means": "the directory and what is in it stay on disk", "release": "await rm(dir, { recursive: true })"},
|
|
442
|
+
"temporary directory": {"acquiredBy": ["await node:fs/promises mkdtemp"], "releasedBy": ["node:fs/promises rm 0"], "wrapper": {"call": "mkdtempDisposable", "from": "@evobug_com/safe-ts-feature-node/fs/promises", "value": "path", "write": "await using dir = q(await mkdtempDisposable(prefix))"}, "what": "a temporary directory", "means": "the directory and what is in it stay on disk", "release": "await rm(dir, { recursive: true })"},
|
|
443
443
|
"HTTP server": {"acquiredBy": ["node:http createServer", "node:https createServer"], "armedBy": ["#listen"], "releasedBy": ["#close"], "lifelong": true, "what": "a listening server", "means": "it keeps its port and keeps the process alive", "release": "server.close()"},
|
|
444
444
|
"TCP server": {"acquiredBy": ["node:net createServer"], "armedBy": ["#listen"], "releasedBy": ["#close"], "lifelong": true, "what": "a listening server", "means": "it keeps its port and keeps the process alive", "release": "server.close()"},
|
|
445
|
-
"worker thread": {"acquiredBy": ["node:worker_threads new Worker"], "releasedBy": ["#terminate"], "lifelong": true, "what": "a worker thread", "means": "the thread keeps running, and keeps the process alive", "release": "await worker.terminate()"},
|
|
446
|
-
"readline interface": {"acquiredBy": ["node:readline createInterface", "node:readline/promises createInterface"], "releasedBy": ["#close"], "lifelong": true, "what": "a readline interface", "means": "it keeps reading its input, and keeps the process alive", "release": "rl.close()"}
|
|
445
|
+
"worker thread": {"acquiredBy": ["node:worker_threads new Worker"], "releasedBy": ["#terminate"], "lifelong": true, "dispose": "await using", "what": "a worker thread", "means": "the thread keeps running, and keeps the process alive", "release": "await worker.terminate()"},
|
|
446
|
+
"readline interface": {"acquiredBy": ["node:readline createInterface", "node:readline/promises createInterface"], "releasedBy": ["#close"], "lifelong": true, "dispose": "using", "what": "a readline interface", "means": "it keeps reading its input, and keeps the process alive", "release": "rl.close()"}
|
|
447
447
|
}
|
|
448
448
|
},
|
|
449
449
|
"consumes": {
|
|
@@ -896,6 +896,8 @@
|
|
|
896
896
|
"node:fs mkdtemp": {"kind": "path", "takes": "argument 0"},
|
|
897
897
|
"node:fs mkdtempDisposableSync": {"kind": "path", "takes": "argument 0"},
|
|
898
898
|
"node:fs mkdtempSync": {"kind": "path", "takes": "argument 0"},
|
|
899
|
+
"node:fs mkstemp": {"kind": "path", "takes": "argument 0"},
|
|
900
|
+
"node:fs mkstempSync": {"kind": "path", "takes": "argument 0"},
|
|
899
901
|
"node:fs open": {"kind": "path", "takes": "argument 0"},
|
|
900
902
|
"node:fs openAsBlob": {"kind": "path", "takes": "argument 0"},
|
|
901
903
|
"node:fs openSync": {"kind": "path", "takes": "argument 0"},
|
|
@@ -947,6 +949,7 @@
|
|
|
947
949
|
"node:fs/promises mkdir": {"kind": "path", "takes": "argument 0"},
|
|
948
950
|
"node:fs/promises mkdtemp": {"kind": "path", "takes": "argument 0"},
|
|
949
951
|
"node:fs/promises mkdtempDisposable": {"kind": "path", "takes": "argument 0"},
|
|
952
|
+
"node:fs/promises mkstemp": {"kind": "path", "takes": "argument 0"},
|
|
950
953
|
"node:fs/promises open": {"kind": "path", "takes": "argument 0"},
|
|
951
954
|
"node:fs/promises opendir": {"kind": "path", "takes": "argument 0"},
|
|
952
955
|
"node:fs/promises readFile": {"kind": "path", "takes": "argument 0"},
|
|
@@ -1036,6 +1039,21 @@
|
|
|
1036
1039
|
"process.prependOnceListener": {"callback": "argument 1", "on": ["message"]}
|
|
1037
1040
|
}
|
|
1038
1041
|
},
|
|
1042
|
+
"clones": {
|
|
1043
|
+
"$comment": "The members of Node that copy a value with the structured clone algorithm (or v8's serializer, which copies the same way), by the argument that is copied (`field`: only that field of the object given there): what `not-cloneable` reads (crates/safe_ts_core/src/cloneable.rs, docs/rules/not-cloneable.md), copied into safe-ts.json as it is, in the format of `sinks.members` (crates/safe_ts_core/src/sinks.rs, `Table::add_clones`). A function, a symbol or a promise given there throws (a `DataCloneError`, v8's an `Error`); a class instance arrives as a plain object, without its methods. Every member here whose `errors` entry names `DataCloneError` is listed, and so is each `consumes` operation with a transfer list (`use-after-consume`): crates/safe_ts_core/src/sinks.rs, `clones_cover_the_maps`. `anyReceiver`: also matched by name on a value whose class can't be told (a port the code holds through a type of its own). test/sinks.test.ts shows each one on the running Node.",
|
|
1044
|
+
"members": {
|
|
1045
|
+
"BroadcastChannel#postMessage": { "takes": "argument 0" },
|
|
1046
|
+
"MessagePort#postMessage": { "takes": "argument 0" },
|
|
1047
|
+
"node:v8 Serializer#writeValue": { "takes": "argument 0" },
|
|
1048
|
+
"node:v8 serialize": { "takes": "argument 0" },
|
|
1049
|
+
"node:worker_threads BroadcastChannel#postMessage": { "takes": "argument 0" },
|
|
1050
|
+
"node:worker_threads MessagePort#postMessage": { "takes": "argument 0", "anyReceiver": true },
|
|
1051
|
+
"node:worker_threads Worker#postMessage": { "takes": "argument 0" },
|
|
1052
|
+
"node:worker_threads new Worker": { "takes": "argument 1", "field": "workerData" },
|
|
1053
|
+
"node:worker_threads postMessageToThread": { "takes": "argument 1" },
|
|
1054
|
+
"structuredClone": { "takes": "argument 0" }
|
|
1055
|
+
}
|
|
1056
|
+
},
|
|
1039
1057
|
"answers": {
|
|
1040
1058
|
"$comment": "What `unused-answer` reads (docs/rules/unused-answer.md), in the format of ecmascript-api.json's `answers` (a member as `module name`, as in `sinks`): `tells` lists members that do something and answer whether, or how much of, it happened, with what the answer says; a call of one as a statement can't know. Members whose answer is often dropped on purpose aren't listed (each measured: the rule's page says which, and why).",
|
|
1041
1059
|
"tells": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evobug_com/safe-ts-feature-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "SAFE-TS feature pack for Node: which built-in functions throw or reject, with the exact errors, and safe versions of them that return a Result (one module per Node module), with the error types and guards.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"safe-ts",
|
|
@@ -26,6 +26,14 @@
|
|
|
26
26
|
"types": "./safe/errors.d.ts",
|
|
27
27
|
"default": "./safe/errors.js"
|
|
28
28
|
},
|
|
29
|
+
"./hold": {
|
|
30
|
+
"types": "./safe/hold.d.ts",
|
|
31
|
+
"default": "./safe/hold.js"
|
|
32
|
+
},
|
|
33
|
+
"./lock": {
|
|
34
|
+
"types": "./safe/lock.d.ts",
|
|
35
|
+
"default": "./safe/lock.js"
|
|
36
|
+
},
|
|
29
37
|
"./buffer": {
|
|
30
38
|
"types": "./safe/buffer.d.ts",
|
|
31
39
|
"default": "./safe/buffer.js"
|
|
@@ -182,7 +190,7 @@
|
|
|
182
190
|
"LICENSE-APACHE"
|
|
183
191
|
],
|
|
184
192
|
"peerDependencies": {
|
|
185
|
-
"@evobug_com/safe-ts-std": "^0.
|
|
193
|
+
"@evobug_com/safe-ts-std": "^0.7.0"
|
|
186
194
|
},
|
|
187
195
|
"publishConfig": {
|
|
188
196
|
"access": "public"
|
package/safe/hold.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Hold points across processes: a test holds a child process at a point of its code
|
|
2
|
+
// (`await holdPoint(name);` of @evobug_com/safe-ts-std/hold) through marker files in a directory
|
|
3
|
+
// it passes by the env var SAFE_TS_HOLD_DIR. In-process, use std's `holdAt`.
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import type { Hold, HoldOptions } from "@evobug_com/safe-ts-std/hold";
|
|
6
|
+
|
|
7
|
+
export type { Hold } from "@evobug_com/safe-ts-std/hold";
|
|
8
|
+
|
|
9
|
+
/** The env var a child process reads its test's hold directory from. */
|
|
10
|
+
export declare const HOLD_DIR_ENV: "SAFE_TS_HOLD_DIR";
|
|
11
|
+
|
|
12
|
+
/** A directory for one test's holds (`holdDir()`). */
|
|
13
|
+
export interface HoldDir {
|
|
14
|
+
/** The directory. */
|
|
15
|
+
readonly path: string;
|
|
16
|
+
/** What to add to a child process's env: `{ SAFE_TS_HOLD_DIR: path }`. */
|
|
17
|
+
readonly env: { readonly SAFE_TS_HOLD_DIR: string };
|
|
18
|
+
/** Delete the directory and its markers. */
|
|
19
|
+
remove(): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Where to arm a point, and how long `reached` waits (default 10000 ms: a process starts first). */
|
|
23
|
+
export interface ProcessHoldOptions extends HoldOptions {
|
|
24
|
+
readonly dir: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A fresh temporary directory for one test's holds, with the env a child process takes it by.
|
|
29
|
+
* Throws if the temporary directory can't be written: a test helper.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const holds = holdDir();
|
|
33
|
+
* const child = spawn(process.execPath, ["--import", "@evobug_com/safe-ts-transform/register", "cli.ts", "build"], {
|
|
34
|
+
* env: { ...process.env, ...holds.env },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function holdDir(): HoldDir;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Arm the hold point `name` for the processes started with `options.dir` as their
|
|
42
|
+
* SAFE_TS_HOLD_DIR: the first of them to reach `await holdPoint(name);` stops there until
|
|
43
|
+
* `release()`. `reached` settles once one has, and fails after the timeout with the name in the
|
|
44
|
+
* message. One hold per point at a time (arming it again before it is reached or released
|
|
45
|
+
* throws). Released before it was reached, the hold is disarmed and the point is passed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function holdAt(name: string, options: ProcessHoldOptions): Hold;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* In a process a test started, as it starts (its entry module): stop at the points the test
|
|
51
|
+
* arms in the directory SAFE_TS_HOLD_DIR names. Without SAFE_TS_HOLD_DIR it does nothing and
|
|
52
|
+
* returns false. A point checks for its marker with one synchronous `existsSync`, and awaits
|
|
53
|
+
* nothing unless it is armed.
|
|
54
|
+
*/
|
|
55
|
+
export declare function holdPointsFromEnv(env?: Readonly<Record<string, string | undefined>>): boolean;
|
package/safe/hold.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// @safe-ts std
|
|
2
|
+
// Hold points across processes (hold.d.ts): a test holds a child process at a point of its code
|
|
3
|
+
// (`await holdPoint(name);`, std's hold) through marker files in a directory it passes by
|
|
4
|
+
// SAFE_TS_HOLD_DIR. Per point, with its name encoded as a file name:
|
|
5
|
+
// <name>.armed the test armed the point (`holdAt`)
|
|
6
|
+
// <name>.reached a process took the hold: it renamed `armed` to this, so of two processes
|
|
7
|
+
// reaching the point at once exactly one stops
|
|
8
|
+
// <name>.released the test let it go on (`release()`); the process deletes it
|
|
9
|
+
import { existsSync, mkdtempSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
|
|
13
|
+
import { setHoldSource } from "@evobug_com/safe-ts-std/hold";
|
|
14
|
+
|
|
15
|
+
export const HOLD_DIR_ENV = "SAFE_TS_HOLD_DIR";
|
|
16
|
+
|
|
17
|
+
const POLL_MS = 5;
|
|
18
|
+
|
|
19
|
+
/** The marker file of `name` (any text: `/`, `:` and `*` are encoded) with this suffix. */
|
|
20
|
+
function marker(dir, name, suffix) {
|
|
21
|
+
return join(dir, `${encodeURIComponent(name).replaceAll("*", "%2A")}.${suffix}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function removeQuietly(path) {
|
|
25
|
+
rmSync(path, { force: true });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A fresh directory for one test's holds, with the env a child process takes it by. */
|
|
29
|
+
export function holdDir() {
|
|
30
|
+
const path = mkdtempSync(join(tmpdir(), "safe-ts-holds-"));
|
|
31
|
+
return {
|
|
32
|
+
path,
|
|
33
|
+
env: { [HOLD_DIR_ENV]: path },
|
|
34
|
+
remove: () => rmSync(path, { recursive: true, force: true }),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Arm `name` for a child process: its next arrival at the point stops there until `release()`. */
|
|
39
|
+
export function holdAt(name, options) {
|
|
40
|
+
const { dir } = options;
|
|
41
|
+
const timeoutMs = options.timeoutMs ?? 10000;
|
|
42
|
+
const armed = marker(dir, name, "armed");
|
|
43
|
+
const reachedFile = marker(dir, name, "reached");
|
|
44
|
+
const released = marker(dir, name, "released");
|
|
45
|
+
removeQuietly(reachedFile);
|
|
46
|
+
removeQuietly(released);
|
|
47
|
+
// `wx`: one hold per point at a time across processes.
|
|
48
|
+
writeFileSync(armed, "", { flag: "wx" });
|
|
49
|
+
let settled = false;
|
|
50
|
+
let poll;
|
|
51
|
+
let timer;
|
|
52
|
+
const stop = () => {
|
|
53
|
+
settled = true;
|
|
54
|
+
clearTimeout(poll);
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
};
|
|
57
|
+
const reached = new Promise((resolve, reject) => {
|
|
58
|
+
timer = setTimeout(() => {
|
|
59
|
+
stop();
|
|
60
|
+
removeQuietly(armed);
|
|
61
|
+
reject(
|
|
62
|
+
new Error(
|
|
63
|
+
`hold point ${JSON.stringify(name)} was not reached by another process within ${timeoutMs} ms (holds in ${dir}). ` +
|
|
64
|
+
`The process must run with ${HOLD_DIR_ENV} set to that directory (which keeps hold points in the Node loader ` +
|
|
65
|
+
"and in Bun) and call holdPointsFromEnv() from @evobug_com/safe-ts-feature-node/hold as it starts",
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
}, timeoutMs);
|
|
69
|
+
timer.unref?.();
|
|
70
|
+
const look = () => {
|
|
71
|
+
if (settled) return;
|
|
72
|
+
if (existsSync(reachedFile)) {
|
|
73
|
+
stop();
|
|
74
|
+
resolve();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
poll = setTimeout(look, POLL_MS);
|
|
78
|
+
};
|
|
79
|
+
look();
|
|
80
|
+
});
|
|
81
|
+
const release = () => {
|
|
82
|
+
// Not taken yet: disarm it, so the point is passed (and `reached` never settles). Taken: let
|
|
83
|
+
// the process go on.
|
|
84
|
+
try {
|
|
85
|
+
unlinkSync(armed);
|
|
86
|
+
stop();
|
|
87
|
+
return;
|
|
88
|
+
} catch {
|
|
89
|
+
writeFileSync(released, "");
|
|
90
|
+
}
|
|
91
|
+
stop();
|
|
92
|
+
removeQuietly(reachedFile);
|
|
93
|
+
};
|
|
94
|
+
return { reached, release };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** In a process a test started: hold at the points the test arms in `SAFE_TS_HOLD_DIR`. */
|
|
98
|
+
export function holdPointsFromEnv(env = process.env) {
|
|
99
|
+
const dir = env[HOLD_DIR_ENV] ?? "";
|
|
100
|
+
if (dir === "") return false;
|
|
101
|
+
setHoldSource((name) => {
|
|
102
|
+
const armed = marker(dir, name, "armed");
|
|
103
|
+
if (!existsSync(armed)) return undefined;
|
|
104
|
+
try {
|
|
105
|
+
renameSync(armed, marker(dir, name, "reached"));
|
|
106
|
+
} catch {
|
|
107
|
+
// Another process took it first.
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const released = marker(dir, name, "released");
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
const look = () => {
|
|
113
|
+
if (!existsSync(released)) {
|
|
114
|
+
setTimeout(look, POLL_MS);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
removeQuietly(released);
|
|
118
|
+
resolve();
|
|
119
|
+
};
|
|
120
|
+
look();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
return true;
|
|
124
|
+
}
|
package/safe/lock.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Written by hand (not generated; test/safe-api.test.ts lists it): a lock across processes, and
|
|
2
|
+
// a JSON file updated under it. In one process, std's `Lock` (`@evobug_com/safe-ts-std/lock`)
|
|
3
|
+
// is enough; two processes (two CLIs, a CLI and a server) need a lock both can see: a file.
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import type { Enum } from "@evobug_com/safe-ts-std/enum";
|
|
6
|
+
import type { Option, Result } from "@evobug_com/safe-ts-std/result";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Why the lock wasn't taken:
|
|
10
|
+
*
|
|
11
|
+
* - `Busy`: another process held it for the whole `waitMs` (`owner`: its pid, as the lock file
|
|
12
|
+
* says, if it says);
|
|
13
|
+
* - `LockFailed`: the lock file couldn't be made or removed (the folder is missing or read-only).
|
|
14
|
+
*/
|
|
15
|
+
export type FileLockFailure = Enum<{
|
|
16
|
+
Busy: { path: string; owner: Option<number>; waitedMs: number };
|
|
17
|
+
LockFailed: { path: string; error: unknown };
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
/** How long to wait for the lock, and when a held lock counts as abandoned. */
|
|
21
|
+
export type FileLockOptions = {
|
|
22
|
+
/** Give up with `Busy` after this many milliseconds (default 10 000). */
|
|
23
|
+
readonly waitMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* A lock whose owner process is gone is taken over at once; one not touched for this many
|
|
26
|
+
* milliseconds is taken over too (default 30 000). The holder touches it every `staleMs / 3`
|
|
27
|
+
* while it holds it, so only a hung or killed holder's lock gets that old.
|
|
28
|
+
*/
|
|
29
|
+
readonly staleMs?: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** A file lock being held. `release()` removes the lock file (only if it is still this holder's); a second call gives the first one's answer. */
|
|
33
|
+
export type FileHeld = {
|
|
34
|
+
/** The lock file: `<path>.lock`, absolute. */
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly release: () => Promise<Result<void, FileLockFailure>>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Take the lock of `path` across processes: make `<path>.lock` with `O_CREAT | O_EXCL`, the
|
|
41
|
+
* owner's pid written in. Waits (a timer between tries, never a spinning loop) while another
|
|
42
|
+
* process holds it, up to `waitMs`; takes over a lock whose owner is gone or that is older than
|
|
43
|
+
* `staleMs`. Waiters in this process queue first, so they take it in the order they asked.
|
|
44
|
+
*
|
|
45
|
+
* The `FileHeld` must be released on every path: prefer `withFileLock`, `guardedFile` or
|
|
46
|
+
* `updateJsonFile`, which release it themselves. A lock held when the process exits is removed.
|
|
47
|
+
* Same host only: a pid on another machine (a network drive) can't be asked whether it lives.
|
|
48
|
+
*/
|
|
49
|
+
export declare function lockFile(path: string, options?: FileLockOptions): Promise<Result<FileHeld, FileLockFailure>>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Run `work` holding the lock of `path` (`lockFile`), and release it when `work` settles: it
|
|
53
|
+
* returns, returns an `Err`, or throws (the rejection is passed on, after the release).
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const built = await withFileLock(prepareLock(home), () => build(id)); // Result<Built, FileLockFailure | BuildError>
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function withFileLock<T>(path: string, work: () => T | Promise<T>, options?: FileLockOptions): Promise<Result<T, FileLockFailure>>;
|
|
60
|
+
|
|
61
|
+
/** Data reachable only under a file lock: `with` takes it, reads, and hands the value over. */
|
|
62
|
+
export type GuardedFile<T> = {
|
|
63
|
+
readonly path: string;
|
|
64
|
+
/** Take the lock, call `read` under it, run `use` on what it read, release the lock when `use` settles. */
|
|
65
|
+
readonly with: <U>(use: (value: T) => U | Promise<U>) => Promise<Result<U, FileLockFailure>>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* std's `guarded` across processes: what `read` returns is reachable only inside `with`, while
|
|
70
|
+
* this process holds the lock of `path`.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* const record = guardedFile(prepareLock(home), () => liveCheckout(id, repo));
|
|
74
|
+
* const built = await record.with((checkout) => (isErr(checkout) ? checkout : build(checkout)));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function guardedFile<T>(path: string, read: () => T | Promise<T>, options?: FileLockOptions): GuardedFile<T>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Why a JSON file wasn't updated: the lock (`Busy`, `LockFailed`), or
|
|
81
|
+
*
|
|
82
|
+
* - `ReadFailed`: the file is there and couldn't be read;
|
|
83
|
+
* - `NotJson`: its text isn't JSON (`error` is the `SyntaxError`);
|
|
84
|
+
* - `Invalid`: it is JSON that `check` refused (`error` is what `check` returned);
|
|
85
|
+
* - `WriteFailed`: the new text couldn't be written or renamed into place (the file is as it was).
|
|
86
|
+
*/
|
|
87
|
+
export type FileUpdateFailure<E> =
|
|
88
|
+
| FileLockFailure
|
|
89
|
+
| Enum<{
|
|
90
|
+
ReadFailed: { path: string; error: unknown };
|
|
91
|
+
NotJson: { path: string; error: unknown };
|
|
92
|
+
Invalid: { path: string; error: E };
|
|
93
|
+
WriteFailed: { path: string; error: unknown };
|
|
94
|
+
}>;
|
|
95
|
+
|
|
96
|
+
export type JsonFileOptions = FileLockOptions & {
|
|
97
|
+
/** The new file's mode when there is none yet (default `0o666`, less the umask); an existing file keeps its own. */
|
|
98
|
+
readonly mode?: number;
|
|
99
|
+
/** `JSON.stringify`'s indent (default none). The text ends with a newline. */
|
|
100
|
+
readonly indent?: number | string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Read, change and write a JSON file that other processes change too, losing nobody's change:
|
|
105
|
+
* take the file's lock (`lockFile`), read it, check it (`check`: std's `validate<T>`, or any
|
|
106
|
+
* function returning a `Result`), call `update` with what is there (`undefined` when there is
|
|
107
|
+
* no file), write the answer to a new file and rename it over the old one, release the lock.
|
|
108
|
+
* Resolves to what was written.
|
|
109
|
+
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* const saved = await updateJsonFile(agentsFile(home), (v) => validate<Agents>(v), (agents) => ({ ...agents, [key]: agent }));
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* The rename alone keeps the file whole, not the other writer's change: two processes that
|
|
115
|
+
* each read, add their entry and rename lose one entry. `shared-file-update` reports that.
|
|
116
|
+
*/
|
|
117
|
+
export declare function updateJsonFile<T, E>(
|
|
118
|
+
path: string,
|
|
119
|
+
check: (value: unknown) => Result<T, E>,
|
|
120
|
+
update: (old: Option<T>) => T,
|
|
121
|
+
options?: JsonFileOptions,
|
|
122
|
+
): Promise<Result<T, FileUpdateFailure<E>>>;
|
package/safe/lock.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// @safe-ts std
|
|
2
|
+
// Written by hand (not generated; test/safe-api.test.ts lists it): a lock across processes, and
|
|
3
|
+
// a JSON file updated under it (lock.d.ts says what each function does).
|
|
4
|
+
//
|
|
5
|
+
// The lock is a file next to what it guards, `<path>.lock`, made with O_CREAT | O_EXCL (`wx`):
|
|
6
|
+
// creating it is the one step two processes can't both win. It holds the owner's pid and the
|
|
7
|
+
// time it was taken; the owner touches it while it holds the lock. A lock whose owner is gone
|
|
8
|
+
// (no such pid) or that wasn't touched for `staleMs` is stale: a waiter moves it aside (one
|
|
9
|
+
// rename wins) and takes the lock. Waiting is a timer between tries, never a loop that spins;
|
|
10
|
+
// waiters in one process queue on a promise first, so only one of them polls the file.
|
|
11
|
+
import { randomBytes } from "node:crypto";
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import { open, readFile, rename, stat, unlink, utimes, link } from "node:fs/promises";
|
|
14
|
+
import { resolve } from "node:path";
|
|
15
|
+
import { Err } from "@evobug_com/safe-ts-std/result";
|
|
16
|
+
|
|
17
|
+
const STALE_MS = 30_000;
|
|
18
|
+
const WAIT_MS = 10_000;
|
|
19
|
+
const RETRY_MS = 20;
|
|
20
|
+
|
|
21
|
+
/** Lock files this process holds: removed if the process exits while holding them. */
|
|
22
|
+
const heldHere = new Set();
|
|
23
|
+
let exitHook = false;
|
|
24
|
+
|
|
25
|
+
function removeOnExit() {
|
|
26
|
+
for (const lockPath of heldHere) {
|
|
27
|
+
try {
|
|
28
|
+
fs.unlinkSync(lockPath);
|
|
29
|
+
} catch {
|
|
30
|
+
// Gone already, or not ours to remove: nothing to do while exiting.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Per lock file: the end of this process's queue for it, so waiters here take turns. */
|
|
36
|
+
const queues = new Map();
|
|
37
|
+
|
|
38
|
+
function sleep(ms) {
|
|
39
|
+
return new Promise((done) => setTimeout(done, ms));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isCode(error, code) {
|
|
43
|
+
return typeof error === "object" && error !== null && error.code === code;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Does a process with this pid exist (on this host)? EPERM: it does, and isn't ours. */
|
|
47
|
+
function alive(pid) {
|
|
48
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
49
|
+
try {
|
|
50
|
+
process.kill(pid, 0);
|
|
51
|
+
return true;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return isCode(error, "EPERM");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The lock file's text: `<pid> <time taken> <nonce>`. */
|
|
58
|
+
function ownerOf(text) {
|
|
59
|
+
const pid = Number.parseInt(text.split(" ")[0] ?? "", 10);
|
|
60
|
+
return Number.isInteger(pid) && pid > 0 ? pid : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One try: the lock, or `undefined` when it is held (and why it isn't stale), or an `Err`. */
|
|
64
|
+
async function tryCreate(lockPath, mine) {
|
|
65
|
+
let handle;
|
|
66
|
+
try {
|
|
67
|
+
handle = await open(lockPath, "wx", 0o644);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (isCode(error, "EEXIST")) return undefined;
|
|
70
|
+
return new Err({ tag: "LockFailed", path: lockPath, error });
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await handle.writeFile(mine);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
await handle.close().catch(() => {});
|
|
76
|
+
await unlink(lockPath).catch(() => {});
|
|
77
|
+
return new Err({ tag: "LockFailed", path: lockPath, error });
|
|
78
|
+
}
|
|
79
|
+
await handle.close().catch(() => {});
|
|
80
|
+
return mine;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The lock is held by someone: if it is stale, move it aside so the next try can take it.
|
|
85
|
+
* Returns the owner's pid as last read (for `Busy`).
|
|
86
|
+
*/
|
|
87
|
+
async function clearIfStale(lockPath, staleMs) {
|
|
88
|
+
let text;
|
|
89
|
+
let info;
|
|
90
|
+
try {
|
|
91
|
+
text = await readFile(lockPath, "utf8");
|
|
92
|
+
info = await stat(lockPath);
|
|
93
|
+
} catch {
|
|
94
|
+
return undefined; // released in between: try again
|
|
95
|
+
}
|
|
96
|
+
const owner = ownerOf(text);
|
|
97
|
+
const stale = (owner !== undefined && owner !== process.pid && !alive(owner)) || Date.now() - info.mtimeMs > staleMs;
|
|
98
|
+
if (!stale) return owner;
|
|
99
|
+
// One waiter's rename wins; the others find no file and try again.
|
|
100
|
+
const aside = `${lockPath}.stale-${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
101
|
+
try {
|
|
102
|
+
await rename(lockPath, aside);
|
|
103
|
+
} catch {
|
|
104
|
+
return owner;
|
|
105
|
+
}
|
|
106
|
+
// Between the read and the rename another waiter may have cleared it and taken a fresh lock:
|
|
107
|
+
// then what was moved aside is that lock, and it goes back (link fails if a newer one exists).
|
|
108
|
+
const moved = await readFile(aside, "utf8").catch(() => text);
|
|
109
|
+
if (moved !== text) await link(aside, lockPath).catch(() => {});
|
|
110
|
+
await unlink(aside).catch(() => {});
|
|
111
|
+
return owner;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Take the lock file, waiting up to `waitMs`. */
|
|
115
|
+
async function takeFile(lockPath, options) {
|
|
116
|
+
const staleMs = options?.staleMs ?? STALE_MS;
|
|
117
|
+
const waitMs = options?.waitMs ?? WAIT_MS;
|
|
118
|
+
const started = Date.now();
|
|
119
|
+
const mine = `${process.pid} ${started} ${randomBytes(6).toString("hex")}`;
|
|
120
|
+
let owner;
|
|
121
|
+
for (;;) {
|
|
122
|
+
const taken = await tryCreate(lockPath, mine);
|
|
123
|
+
if (taken instanceof Err) return taken;
|
|
124
|
+
if (taken !== undefined) return taken;
|
|
125
|
+
owner = await clearIfStale(lockPath, staleMs);
|
|
126
|
+
const waited = Date.now() - started;
|
|
127
|
+
if (waited >= waitMs) return new Err({ tag: "Busy", path: lockPath, owner, waitedMs: waited });
|
|
128
|
+
await sleep(Math.min(RETRY_MS + Math.floor(Math.random() * RETRY_MS), Math.max(1, waitMs - waited)));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function releaser(lockPath, mine, staleMs, done) {
|
|
133
|
+
// Touch the file while held, so a long holder isn't taken for stale.
|
|
134
|
+
const timer = setInterval(() => {
|
|
135
|
+
const now = new Date();
|
|
136
|
+
utimes(lockPath, now, now).catch(() => {});
|
|
137
|
+
}, Math.max(10, Math.floor(staleMs / 3)));
|
|
138
|
+
timer.unref?.();
|
|
139
|
+
let released;
|
|
140
|
+
return () => {
|
|
141
|
+
if (released !== undefined) return released;
|
|
142
|
+
clearInterval(timer);
|
|
143
|
+
heldHere.delete(lockPath);
|
|
144
|
+
released = (async () => {
|
|
145
|
+
try {
|
|
146
|
+
// Only our own lock: a holder that took ours for stale has its own text in the file.
|
|
147
|
+
const text = await readFile(lockPath, "utf8").catch(() => undefined);
|
|
148
|
+
if (text === mine) {
|
|
149
|
+
try {
|
|
150
|
+
await unlink(lockPath);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (!isCode(error, "ENOENT")) return new Err({ tag: "LockFailed", path: lockPath, error });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
} finally {
|
|
157
|
+
done();
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
return released;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function lockFile(path, options) {
|
|
165
|
+
const lockPath = `${resolve(path)}.lock`;
|
|
166
|
+
// This process's waiters for the same file queue here first.
|
|
167
|
+
let done = () => {};
|
|
168
|
+
const turn = new Promise((go) => {
|
|
169
|
+
done = go;
|
|
170
|
+
});
|
|
171
|
+
const before = queues.get(lockPath) ?? Promise.resolve();
|
|
172
|
+
const tail = before.then(() => turn);
|
|
173
|
+
queues.set(lockPath, tail);
|
|
174
|
+
const finish = () => {
|
|
175
|
+
done();
|
|
176
|
+
if (queues.get(lockPath) === tail) queues.delete(lockPath);
|
|
177
|
+
};
|
|
178
|
+
await before;
|
|
179
|
+
const mine = await takeFile(lockPath, options);
|
|
180
|
+
if (mine instanceof Err) {
|
|
181
|
+
finish();
|
|
182
|
+
return mine;
|
|
183
|
+
}
|
|
184
|
+
heldHere.add(lockPath);
|
|
185
|
+
if (!exitHook) {
|
|
186
|
+
exitHook = true;
|
|
187
|
+
process.once("exit", removeOnExit);
|
|
188
|
+
}
|
|
189
|
+
return { path: lockPath, release: releaser(lockPath, mine, options?.staleMs ?? STALE_MS, finish) };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function withFileLock(path, work, options) {
|
|
193
|
+
const held = await lockFile(path, options);
|
|
194
|
+
if (held instanceof Err) return held;
|
|
195
|
+
try {
|
|
196
|
+
return await work();
|
|
197
|
+
} finally {
|
|
198
|
+
await held.release();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function guardedFile(path, read, options) {
|
|
203
|
+
return {
|
|
204
|
+
path,
|
|
205
|
+
with: (use) => withFileLock(path, async () => use(await read()), options),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The file's JSON, checked: `undefined` when there is no file. */
|
|
210
|
+
async function readJson(path, check) {
|
|
211
|
+
let text;
|
|
212
|
+
try {
|
|
213
|
+
text = await readFile(path, "utf8");
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (isCode(error, "ENOENT")) return undefined;
|
|
216
|
+
return new Err({ tag: "ReadFailed", path, error });
|
|
217
|
+
}
|
|
218
|
+
let value;
|
|
219
|
+
try {
|
|
220
|
+
value = JSON.parse(text);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
return new Err({ tag: "NotJson", path, error });
|
|
223
|
+
}
|
|
224
|
+
const checked = check(value);
|
|
225
|
+
return checked instanceof Err ? new Err({ tag: "Invalid", path, error: checked.error }) : checked;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Write `text` to a new file beside `path`, flush it, and rename it over `path`. */
|
|
229
|
+
async function writeAtomically(path, text, mode) {
|
|
230
|
+
const fresh = `${path}.${process.pid}-${randomBytes(6).toString("hex")}.tmp`;
|
|
231
|
+
let handle;
|
|
232
|
+
try {
|
|
233
|
+
handle = await open(fresh, "wx", mode);
|
|
234
|
+
await handle.writeFile(text);
|
|
235
|
+
await handle.sync();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
await handle?.close().catch(() => {});
|
|
238
|
+
await unlink(fresh).catch(() => {});
|
|
239
|
+
return new Err({ tag: "WriteFailed", path, error });
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
await handle.close();
|
|
243
|
+
await rename(fresh, path);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
await unlink(fresh).catch(() => {});
|
|
246
|
+
return new Err({ tag: "WriteFailed", path, error });
|
|
247
|
+
}
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function updateJsonFile(path, check, update, options) {
|
|
252
|
+
const target = resolve(path);
|
|
253
|
+
const held = await lockFile(target, options);
|
|
254
|
+
if (held instanceof Err) return held;
|
|
255
|
+
try {
|
|
256
|
+
const old = await readJson(target, check);
|
|
257
|
+
if (old instanceof Err) return old;
|
|
258
|
+
const next = update(old);
|
|
259
|
+
const mode = options?.mode ?? (await stat(target).then((s) => s.mode & 0o7777, () => 0o666));
|
|
260
|
+
const text = `${JSON.stringify(next, null, options?.indent)}\n`;
|
|
261
|
+
const written = await writeAtomically(target, text, mode);
|
|
262
|
+
return written instanceof Err ? written : next;
|
|
263
|
+
} finally {
|
|
264
|
+
const released = await held.release();
|
|
265
|
+
// A lock file we couldn't remove makes the next update wait for `staleMs`: not this update's failure.
|
|
266
|
+
void released;
|
|
267
|
+
}
|
|
268
|
+
}
|
package/safe-ts.json
CHANGED
|
@@ -1140,6 +1140,10 @@
|
|
|
1140
1140
|
"error": "Error [E*] {errno, syscall: 'mkdtemp', path}",
|
|
1141
1141
|
"safe": "@evobug_com/safe-ts-feature-node/fs mkdtempDisposableSync"
|
|
1142
1142
|
},
|
|
1143
|
+
"mkstempSync": {
|
|
1144
|
+
"fails": "throws",
|
|
1145
|
+
"error": "Error [E*] {errno, syscall: 'mkstemp', path}"
|
|
1146
|
+
},
|
|
1143
1147
|
"openSync": {
|
|
1144
1148
|
"fails": "throws",
|
|
1145
1149
|
"error": "Error [E*] {errno, syscall: 'open', path}",
|
|
@@ -1331,6 +1335,10 @@
|
|
|
1331
1335
|
"error": "Error [E*] {errno, syscall: 'mkdtemp', path}",
|
|
1332
1336
|
"safe": "@evobug_com/safe-ts-feature-node/fs/promises mkdtempDisposable"
|
|
1333
1337
|
},
|
|
1338
|
+
"mkstemp": {
|
|
1339
|
+
"fails": "rejects",
|
|
1340
|
+
"error": "Error [E*] {errno, syscall: 'mkstemp', path}"
|
|
1341
|
+
},
|
|
1334
1342
|
"open": {
|
|
1335
1343
|
"fails": "rejects",
|
|
1336
1344
|
"error": "Error [E*] {errno, syscall: 'open', path}",
|
|
@@ -1601,6 +1609,10 @@
|
|
|
1601
1609
|
"error": "Error [E*] {errno, syscall: 'mkdtemp', path}",
|
|
1602
1610
|
"safe": "@evobug_com/safe-ts-feature-node/fs/promises mkdtempDisposable"
|
|
1603
1611
|
},
|
|
1612
|
+
"mkstemp": {
|
|
1613
|
+
"fails": "rejects",
|
|
1614
|
+
"error": "Error [E*] {errno, syscall: 'mkstemp', path}"
|
|
1615
|
+
},
|
|
1604
1616
|
"writeFile": {
|
|
1605
1617
|
"fails": "rejects",
|
|
1606
1618
|
"error": "Error [E*] {errno, syscall: 'open' | 'write', path?}",
|
|
@@ -2691,6 +2703,14 @@
|
|
|
2691
2703
|
"fails": "throws",
|
|
2692
2704
|
"error": "Error [ERR_ZIP_ENTRY_CORRUPT | ERR_ZIP_INVALID_ARCHIVE | ERR_ZIP_UNSUPPORTED_FEATURE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [Z_*] {errno} | Error [E*] {errno, syscall: 'read'}",
|
|
2693
2705
|
"safe": "@evobug_com/safe-ts-feature-node/zlib contentSync"
|
|
2706
|
+
},
|
|
2707
|
+
"rawContent": {
|
|
2708
|
+
"fails": "rejects",
|
|
2709
|
+
"error": "Error [ERR_ZIP_INVALID_ARCHIVE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [E*] {errno, syscall: 'read'}"
|
|
2710
|
+
},
|
|
2711
|
+
"rawContentSync": {
|
|
2712
|
+
"fails": "throws",
|
|
2713
|
+
"error": "Error [ERR_ZIP_INVALID_ARCHIVE] | RangeError [ERR_ZIP_ENTRY_TOO_LARGE] | Error [E*] {errno, syscall: 'read'}"
|
|
2694
2714
|
}
|
|
2695
2715
|
}
|
|
2696
2716
|
},
|
|
@@ -2790,6 +2810,8 @@
|
|
|
2790
2810
|
"ZipEntry.createSync": "node:zlib ZipEntry",
|
|
2791
2811
|
"ZipEntry#content": "node:buffer Buffer",
|
|
2792
2812
|
"ZipEntry#contentSync": "node:buffer Buffer",
|
|
2813
|
+
"ZipEntry#rawContent": "node:buffer Buffer",
|
|
2814
|
+
"ZipEntry#rawContentSync": "node:buffer Buffer",
|
|
2793
2815
|
"zipFiles": "node:stream Readable",
|
|
2794
2816
|
"createGzip": "node:zlib Gzip",
|
|
2795
2817
|
"createGunzip": "node:zlib Gunzip",
|
|
@@ -4871,6 +4893,14 @@
|
|
|
4871
4893
|
"kind": "path",
|
|
4872
4894
|
"takes": "argument 0"
|
|
4873
4895
|
},
|
|
4896
|
+
"node:fs mkstemp": {
|
|
4897
|
+
"kind": "path",
|
|
4898
|
+
"takes": "argument 0"
|
|
4899
|
+
},
|
|
4900
|
+
"node:fs mkstempSync": {
|
|
4901
|
+
"kind": "path",
|
|
4902
|
+
"takes": "argument 0"
|
|
4903
|
+
},
|
|
4874
4904
|
"node:fs open": {
|
|
4875
4905
|
"kind": "path",
|
|
4876
4906
|
"takes": "argument 0"
|
|
@@ -5075,6 +5105,10 @@
|
|
|
5075
5105
|
"kind": "path",
|
|
5076
5106
|
"takes": "argument 0"
|
|
5077
5107
|
},
|
|
5108
|
+
"node:fs/promises mkstemp": {
|
|
5109
|
+
"kind": "path",
|
|
5110
|
+
"takes": "argument 0"
|
|
5111
|
+
},
|
|
5078
5112
|
"node:fs/promises open": {
|
|
5079
5113
|
"kind": "path",
|
|
5080
5114
|
"takes": "argument 0"
|
|
@@ -5475,8 +5509,45 @@
|
|
|
5475
5509
|
}
|
|
5476
5510
|
}
|
|
5477
5511
|
},
|
|
5512
|
+
"clones": {
|
|
5513
|
+
"$comment": "The members of Node that copy a value with the structured clone algorithm (or v8's serializer, which copies the same way), by the argument that is copied (`field`: only that field of the object given there): what `not-cloneable` reads (crates/safe_ts_core/src/cloneable.rs, docs/rules/not-cloneable.md), copied into safe-ts.json as it is, in the format of `sinks.members` (crates/safe_ts_core/src/sinks.rs, `Table::add_clones`). A function, a symbol or a promise given there throws (a `DataCloneError`, v8's an `Error`); a class instance arrives as a plain object, without its methods. Every member here whose `errors` entry names `DataCloneError` is listed, and so is each `consumes` operation with a transfer list (`use-after-consume`): crates/safe_ts_core/src/sinks.rs, `clones_cover_the_maps`. `anyReceiver`: also matched by name on a value whose class can't be told (a port the code holds through a type of its own). test/sinks.test.ts shows each one on the running Node.",
|
|
5514
|
+
"members": {
|
|
5515
|
+
"BroadcastChannel#postMessage": {
|
|
5516
|
+
"takes": "argument 0"
|
|
5517
|
+
},
|
|
5518
|
+
"MessagePort#postMessage": {
|
|
5519
|
+
"takes": "argument 0"
|
|
5520
|
+
},
|
|
5521
|
+
"node:v8 Serializer#writeValue": {
|
|
5522
|
+
"takes": "argument 0"
|
|
5523
|
+
},
|
|
5524
|
+
"node:v8 serialize": {
|
|
5525
|
+
"takes": "argument 0"
|
|
5526
|
+
},
|
|
5527
|
+
"node:worker_threads BroadcastChannel#postMessage": {
|
|
5528
|
+
"takes": "argument 0"
|
|
5529
|
+
},
|
|
5530
|
+
"node:worker_threads MessagePort#postMessage": {
|
|
5531
|
+
"takes": "argument 0",
|
|
5532
|
+
"anyReceiver": true
|
|
5533
|
+
},
|
|
5534
|
+
"node:worker_threads Worker#postMessage": {
|
|
5535
|
+
"takes": "argument 0"
|
|
5536
|
+
},
|
|
5537
|
+
"node:worker_threads new Worker": {
|
|
5538
|
+
"takes": "argument 1",
|
|
5539
|
+
"field": "workerData"
|
|
5540
|
+
},
|
|
5541
|
+
"node:worker_threads postMessageToThread": {
|
|
5542
|
+
"takes": "argument 1"
|
|
5543
|
+
},
|
|
5544
|
+
"structuredClone": {
|
|
5545
|
+
"takes": "argument 0"
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
},
|
|
5478
5549
|
"acquires": {
|
|
5479
|
-
"$comment": "What a function acquires and must release before it ends: read by `unreleased-resource` (docs/rules/unreleased-resource.md; the format is in docs/guide/libraries.md, \"What must be released\"). Each resource is a value an operation hands back (`acquiredBy`: a callable of `modules` named as in `consumes`, `new X`, `await f` for an async one, `Class#method` for a method), that holds something until a release (`releasedBy`: `#method` of the value, or a callable and the argument the value goes in: `clearInterval 0`). A resource with `armedBy` holds nothing until then: `#method` (an observer's `observe`, a server's `listen`) or `.signal to method` (an AbortController whose `signal` is in the options of an `addEventListener`). `what` names it in a message, `means` says what staying acquired does, `release` how to release it. `lifelong`: often meant to live as long as the program (a worker's interval, a server), so reported only in a function that releases it on some path; `dispose`: the declaration that releases it by itself (`await using`). acquires.test.ts acquires each on this engine, shows it held, releases it and shows it released.",
|
|
5550
|
+
"$comment": "What a function acquires and must release before it ends: read by `unreleased-resource` and `prefer-using` (docs/rules/unreleased-resource.md, docs/rules/prefer-using.md; the format is in docs/guide/libraries.md, \"What must be released\"). Each resource is a value an operation hands back (`acquiredBy`: a callable of `modules` named as in `consumes`, `new X`, `await f` for an async one, `Class#method` for a method), that holds something until a release (`releasedBy`: `#method` of the value, or a callable and the argument the value goes in: `clearInterval 0`). A resource with `armedBy` holds nothing until then: `#method` (an observer's `observe`, a server's `listen`) or `.signal to method` (an AbortController whose `signal` is in the options of an `addEventListener`). `what` names it in a message, `means` says what staying acquired does, `release` how to release it. `lifelong`: often meant to live as long as the program (a worker's interval, a server), so reported only in a function that releases it on some path; `dispose`: the declaration that releases it by itself (`await using`, `using`); `wrapper`: where the value is not disposable, a helper that hands it back disposable (`call` from the module `from`, takes the same arguments; `value`: the member holding what the platform handed back, if it isn't the value itself; `write`: a declaration with it). acquires.test.ts acquires each on this engine, shows it held, releases it and shows it released.",
|
|
5480
5551
|
"resources": {
|
|
5481
5552
|
"interval": {
|
|
5482
5553
|
"acquiredBy": [
|
|
@@ -5486,6 +5557,11 @@
|
|
|
5486
5557
|
"clearInterval 0"
|
|
5487
5558
|
],
|
|
5488
5559
|
"lifelong": true,
|
|
5560
|
+
"wrapper": {
|
|
5561
|
+
"call": "interval",
|
|
5562
|
+
"from": "@evobug_com/safe-ts-std/disposable",
|
|
5563
|
+
"write": "using timer = interval(tick, ms)"
|
|
5564
|
+
},
|
|
5489
5565
|
"what": "an interval",
|
|
5490
5566
|
"means": "its callback keeps running, and keeps everything it captured alive",
|
|
5491
5567
|
"release": "clearInterval(id)"
|
|
@@ -5498,6 +5574,11 @@
|
|
|
5498
5574
|
"clearTimeout 0"
|
|
5499
5575
|
],
|
|
5500
5576
|
"lifelong": true,
|
|
5577
|
+
"wrapper": {
|
|
5578
|
+
"call": "timeout",
|
|
5579
|
+
"from": "@evobug_com/safe-ts-std/disposable",
|
|
5580
|
+
"write": "using deadline = timeout(fire, ms)"
|
|
5581
|
+
},
|
|
5501
5582
|
"what": "a timeout",
|
|
5502
5583
|
"means": "its callback still runs later, after the function meant to cancel it",
|
|
5503
5584
|
"release": "clearTimeout(id)"
|
|
@@ -5536,6 +5617,12 @@
|
|
|
5536
5617
|
"releasedBy": [
|
|
5537
5618
|
"URL.revokeObjectURL 0"
|
|
5538
5619
|
],
|
|
5620
|
+
"wrapper": {
|
|
5621
|
+
"call": "objectUrl",
|
|
5622
|
+
"from": "@evobug_com/safe-ts-std/disposable",
|
|
5623
|
+
"value": "url",
|
|
5624
|
+
"write": "using image = objectUrl(blob)"
|
|
5625
|
+
},
|
|
5539
5626
|
"what": "an object URL",
|
|
5540
5627
|
"means": "the blob it points to stays in memory until the page (or process) ends",
|
|
5541
5628
|
"release": "URL.revokeObjectURL(url)"
|
|
@@ -5583,6 +5670,12 @@
|
|
|
5583
5670
|
"releasedBy": [
|
|
5584
5671
|
"node:fs/promises rm 0"
|
|
5585
5672
|
],
|
|
5673
|
+
"wrapper": {
|
|
5674
|
+
"call": "mkdtempDisposable",
|
|
5675
|
+
"from": "@evobug_com/safe-ts-feature-node/fs/promises",
|
|
5676
|
+
"value": "path",
|
|
5677
|
+
"write": "await using dir = q(await mkdtempDisposable(prefix))"
|
|
5678
|
+
},
|
|
5586
5679
|
"what": "a temporary directory",
|
|
5587
5680
|
"means": "the directory and what is in it stay on disk",
|
|
5588
5681
|
"release": "await rm(dir, { recursive: true })"
|
|
@@ -5626,6 +5719,7 @@
|
|
|
5626
5719
|
"#terminate"
|
|
5627
5720
|
],
|
|
5628
5721
|
"lifelong": true,
|
|
5722
|
+
"dispose": "await using",
|
|
5629
5723
|
"what": "a worker thread",
|
|
5630
5724
|
"means": "the thread keeps running, and keeps the process alive",
|
|
5631
5725
|
"release": "await worker.terminate()"
|
|
@@ -5639,6 +5733,7 @@
|
|
|
5639
5733
|
"#close"
|
|
5640
5734
|
],
|
|
5641
5735
|
"lifelong": true,
|
|
5736
|
+
"dispose": "using",
|
|
5642
5737
|
"what": "a readline interface",
|
|
5643
5738
|
"means": "it keeps reading its input, and keeps the process alive",
|
|
5644
5739
|
"release": "rl.close()"
|