knitting 0.1.53 → 0.1.55

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.
Files changed (135) hide show
  1. package/README.md +38 -27
  2. package/knitting.d.ts +797 -5
  3. package/knitting.js +9780 -5
  4. package/map.md +9 -12
  5. package/package.json +14 -13
  6. package/shared-memory.d.ts +155 -0
  7. package/shared-memory.js +1342 -0
  8. package/unsafe.d.ts +71 -1
  9. package/unsafe.js +878 -1
  10. package/utils.d.ts +31 -1
  11. package/utils.js +116 -1
  12. package/process-shared-buffer.d.ts +0 -1
  13. package/process-shared-buffer.js +0 -1
  14. package/src/api.d.ts +0 -69
  15. package/src/api.js +0 -555
  16. package/src/common/envelope.d.ts +0 -17
  17. package/src/common/envelope.js +0 -22
  18. package/src/common/module-url.d.ts +0 -1
  19. package/src/common/module-url.js +0 -24
  20. package/src/common/node-compat.d.ts +0 -20
  21. package/src/common/node-compat.js +0 -24
  22. package/src/common/path-canonical.d.ts +0 -6
  23. package/src/common/path-canonical.js +0 -41
  24. package/src/common/runtime.d.ts +0 -15
  25. package/src/common/runtime.js +0 -91
  26. package/src/common/shared-buffer-region.d.ts +0 -11
  27. package/src/common/shared-buffer-region.js +0 -21
  28. package/src/common/shared-buffer-text.d.ts +0 -16
  29. package/src/common/shared-buffer-text.js +0 -65
  30. package/src/common/task-source.d.ts +0 -3
  31. package/src/common/task-source.js +0 -84
  32. package/src/common/task-symbol.d.ts +0 -1
  33. package/src/common/task-symbol.js +0 -1
  34. package/src/common/with-resolvers.d.ts +0 -9
  35. package/src/common/with-resolvers.js +0 -23
  36. package/src/common/worker-runtime.d.ts +0 -42
  37. package/src/common/worker-runtime.js +0 -61
  38. package/src/connections/buffer-reference-native.d.ts +0 -56
  39. package/src/connections/buffer-reference-native.js +0 -217
  40. package/src/connections/buffer-reference.d.ts +0 -78
  41. package/src/connections/buffer-reference.js +0 -461
  42. package/src/connections/bun.d.ts +0 -22
  43. package/src/connections/bun.js +0 -214
  44. package/src/connections/deno.d.ts +0 -22
  45. package/src/connections/deno.js +0 -205
  46. package/src/connections/file-descriptor.d.ts +0 -39
  47. package/src/connections/file-descriptor.js +0 -161
  48. package/src/connections/index.d.ts +0 -4
  49. package/src/connections/index.js +0 -4
  50. package/src/connections/node-addons.d.ts +0 -5
  51. package/src/connections/node-addons.js +0 -43
  52. package/src/connections/node-buffer-pointer.d.ts +0 -20
  53. package/src/connections/node-buffer-pointer.js +0 -16
  54. package/src/connections/node.d.ts +0 -30
  55. package/src/connections/node.js +0 -62
  56. package/src/connections/posix.d.ts +0 -32
  57. package/src/connections/posix.js +0 -77
  58. package/src/connections/process-shared-buffer.d.ts +0 -75
  59. package/src/connections/process-shared-buffer.js +0 -279
  60. package/src/connections/shared-array-buffer-payload.d.ts +0 -36
  61. package/src/connections/shared-array-buffer-payload.js +0 -235
  62. package/src/connections/types.d.ts +0 -50
  63. package/src/connections/types.js +0 -37
  64. package/src/connections/windows.d.ts +0 -28
  65. package/src/connections/windows.js +0 -224
  66. package/src/debug/env-diff.d.ts +0 -26
  67. package/src/debug/env-diff.js +0 -49
  68. package/src/debug/gate.d.ts +0 -18
  69. package/src/debug/gate.js +0 -69
  70. package/src/debug/handle.d.ts +0 -23
  71. package/src/debug/handle.js +0 -48
  72. package/src/error.d.ts +0 -13
  73. package/src/error.js +0 -49
  74. package/src/ipc/tools/ring-queue.d.ts +0 -33
  75. package/src/ipc/tools/ring-queue.js +0 -159
  76. package/src/ipc/transport/shared-memory.d.ts +0 -23
  77. package/src/ipc/transport/shared-memory.js +0 -35
  78. package/src/memory/byte-carpet.d.ts +0 -73
  79. package/src/memory/byte-carpet.js +0 -157
  80. package/src/memory/lock.d.ts +0 -201
  81. package/src/memory/lock.js +0 -739
  82. package/src/memory/payload-config.d.ts +0 -31
  83. package/src/memory/payload-config.js +0 -67
  84. package/src/memory/payloadCodec.d.ts +0 -46
  85. package/src/memory/payloadCodec.js +0 -1334
  86. package/src/memory/regionRegistry.d.ts +0 -17
  87. package/src/memory/regionRegistry.js +0 -285
  88. package/src/memory/shared-buffer-io.d.ts +0 -55
  89. package/src/memory/shared-buffer-io.js +0 -403
  90. package/src/permission/index.d.ts +0 -2
  91. package/src/permission/index.js +0 -2
  92. package/src/permission/protocol.d.ts +0 -166
  93. package/src/permission/protocol.js +0 -650
  94. package/src/runtime/balancer.d.ts +0 -19
  95. package/src/runtime/balancer.js +0 -149
  96. package/src/runtime/dispatcher.d.ts +0 -34
  97. package/src/runtime/dispatcher.js +0 -142
  98. package/src/runtime/inline-executor.d.ts +0 -10
  99. package/src/runtime/inline-executor.js +0 -282
  100. package/src/runtime/pool.d.ts +0 -30
  101. package/src/runtime/pool.js +0 -391
  102. package/src/runtime/process-worker.d.ts +0 -92
  103. package/src/runtime/process-worker.js +0 -673
  104. package/src/runtime/tx-queue.d.ts +0 -26
  105. package/src/runtime/tx-queue.js +0 -151
  106. package/src/shared/abortSignal.d.ts +0 -23
  107. package/src/shared/abortSignal.js +0 -134
  108. package/src/types.d.ts +0 -346
  109. package/src/types.js +0 -2
  110. package/src/utils/http.d.ts +0 -29
  111. package/src/utils/http.js +0 -100
  112. package/src/worker/bootstrap.d.ts +0 -5
  113. package/src/worker/bootstrap.js +0 -78
  114. package/src/worker/composable-runners.d.ts +0 -12
  115. package/src/worker/composable-runners.js +0 -97
  116. package/src/worker/loop.d.ts +0 -2
  117. package/src/worker/loop.js +0 -382
  118. package/src/worker/process-worker-bootstrap.d.ts +0 -8
  119. package/src/worker/process-worker-bootstrap.js +0 -160
  120. package/src/worker/rx-queue.d.ts +0 -25
  121. package/src/worker/rx-queue.js +0 -173
  122. package/src/worker/safety/index.d.ts +0 -4
  123. package/src/worker/safety/index.js +0 -4
  124. package/src/worker/safety/performance.d.ts +0 -1
  125. package/src/worker/safety/performance.js +0 -17
  126. package/src/worker/safety/process.d.ts +0 -2
  127. package/src/worker/safety/process.js +0 -79
  128. package/src/worker/safety/startup.d.ts +0 -16
  129. package/src/worker/safety/startup.js +0 -30
  130. package/src/worker/safety/worker-data.d.ts +0 -2
  131. package/src/worker/safety/worker-data.js +0 -36
  132. package/src/worker/task-loader.d.ts +0 -27
  133. package/src/worker/task-loader.js +0 -78
  134. package/src/worker/timers.d.ts +0 -18
  135. package/src/worker/timers.js +0 -116
@@ -1,650 +0,0 @@
1
- import { existsSync as existsSyncCompat, realpathSync as realpathSyncCompat, } from "node:fs";
2
- import { isAbsolute as pathIsAbsolute, relative as pathRelative, resolve as pathResolve, } from "node:path";
3
- import { fileURLToPath as fileURLToPathCompat } from "node:url";
4
- import { RUNTIME } from "../common/runtime.js";
5
- import { toCanonicalPath as toSharedCanonicalPath } from "../common/path-canonical.js";
6
- import { getNodeProcess } from "../common/node-compat.js";
7
- const DEFAULT_ENV_FILE = ".env";
8
- const DEFAULT_DENO_LOCK_FILE = "deno.lock";
9
- const NODE_MODULES_DIR = "node_modules";
10
- const DEFAULT_DENY_RELATIVE = [
11
- ".env",
12
- ".git",
13
- ".npmrc",
14
- ".docker",
15
- ".secrets",
16
- ];
17
- const DEFAULT_ALLOW_IMPORT_HOSTS = ["deno.land", "esm.sh", "jsr.io"];
18
- const SUPPORTED_SYS_API_NAMES = [
19
- "hostname",
20
- "osRelease",
21
- "osUptime",
22
- "loadavg",
23
- "networkInterfaces",
24
- "systemMemoryInfo",
25
- "uid",
26
- "gid",
27
- ];
28
- const SUPPORTED_SYS_API_NAME_SET = new Set(SUPPORTED_SYS_API_NAMES);
29
- const L3_KEYS = {
30
- deno: [],
31
- node: [
32
- "denyRead",
33
- "denyWrite",
34
- "net",
35
- "denyNet",
36
- "env.allow",
37
- "env.deny",
38
- "denyRun",
39
- "denyFfi",
40
- "sys",
41
- "denySys",
42
- "allowImport",
43
- ],
44
- };
45
- const cloneL3Keys = () => ({
46
- deno: [...L3_KEYS.deno],
47
- node: [...L3_KEYS.node],
48
- });
49
- const DEFAULT_DENY_HOME = [
50
- ".ssh",
51
- ".gnupg",
52
- ".aws",
53
- ".azure",
54
- ".config/gcloud",
55
- ".kube",
56
- ];
57
- const DEFAULT_DENY_ABSOLUTE_POSIX = [
58
- "/proc",
59
- "/proc/self",
60
- "/proc/self/environ",
61
- "/proc/self/mem",
62
- "/sys",
63
- "/dev",
64
- "/etc",
65
- ];
66
- const normalizeList = (values) => {
67
- const out = [];
68
- const seen = new Set();
69
- for (const value of values) {
70
- if (seen.has(value))
71
- continue;
72
- seen.add(value);
73
- out.push(value);
74
- }
75
- return out;
76
- };
77
- const normalizeStringList = (values) => {
78
- if (!values || values.length === 0)
79
- return [];
80
- const cleaned = [];
81
- for (const value of values) {
82
- if (typeof value !== "string")
83
- continue;
84
- const trimmed = value.trim();
85
- if (trimmed.length === 0)
86
- continue;
87
- cleaned.push(trimmed);
88
- }
89
- return normalizeList(cleaned);
90
- };
91
- const normalizeSysApiList = (values) => {
92
- if (!values || values.length === 0)
93
- return [];
94
- const out = [];
95
- const seen = new Set();
96
- for (const raw of values) {
97
- if (typeof raw !== "string")
98
- continue;
99
- const value = raw.trim();
100
- if (value.length === 0 || seen.has(value))
101
- continue;
102
- if (!SUPPORTED_SYS_API_NAME_SET.has(value))
103
- continue;
104
- seen.add(value);
105
- out.push(value);
106
- }
107
- return out;
108
- };
109
- const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
110
- const normalizeProtocolInput = (input) => !input
111
- ? undefined
112
- : (typeof input === "string" ? { mode: input } : input);
113
- const isWindows = () => {
114
- const nodeProcess = getNodeProcess();
115
- if (typeof nodeProcess?.platform === "string") {
116
- return nodeProcess.platform === "win32";
117
- }
118
- const g = globalThis;
119
- return g.Deno?.build?.os === "windows";
120
- };
121
- const getCwd = () => {
122
- try {
123
- const nodeProcess = getNodeProcess();
124
- if (typeof nodeProcess?.cwd === "function") {
125
- return nodeProcess.cwd();
126
- }
127
- }
128
- catch {
129
- }
130
- const g = globalThis;
131
- try {
132
- if (typeof g.Deno?.cwd === "function")
133
- return g.Deno.cwd();
134
- }
135
- catch {
136
- }
137
- return ".";
138
- };
139
- const getHome = () => {
140
- try {
141
- const nodeProcess = getNodeProcess();
142
- if (typeof nodeProcess?.env === "object") {
143
- const home = nodeProcess.env.HOME ?? nodeProcess.env.USERPROFILE;
144
- if (typeof home === "string" && home.length > 0)
145
- return home;
146
- }
147
- }
148
- catch {
149
- }
150
- const g = globalThis;
151
- try {
152
- const home = g.Deno?.env?.get?.("HOME") ??
153
- g.Deno?.env?.get?.("USERPROFILE");
154
- if (typeof home === "string" && home.length > 0)
155
- return home;
156
- }
157
- catch {
158
- }
159
- return undefined;
160
- };
161
- const expandHomePath = (value, home) => {
162
- if (!home)
163
- return value;
164
- if (value === "~")
165
- return home;
166
- if (value.startsWith("~/") || value.startsWith("~\\")) {
167
- return pathResolve(home, value.slice(2));
168
- }
169
- return value;
170
- };
171
- const toAbsolutePath = (value, cwd, home) => {
172
- if (value instanceof URL) {
173
- if (value.protocol !== "file:")
174
- return undefined;
175
- return pathResolve(fileURLToPathCompat(value));
176
- }
177
- const expanded = expandHomePath(value, home);
178
- if (pathIsAbsolute(expanded)) {
179
- return pathResolve(expanded);
180
- }
181
- try {
182
- const parsed = new URL(expanded);
183
- if (parsed.protocol !== "file:")
184
- return undefined;
185
- return pathResolve(fileURLToPathCompat(parsed));
186
- }
187
- catch {
188
- return pathResolve(cwd, expanded);
189
- }
190
- };
191
- const toPath = (value, cwd, home) => value == null ? undefined : toAbsolutePath(value, cwd, home);
192
- const toPathList = (values, cwd, home) => {
193
- if (!values?.length)
194
- return [];
195
- const out = [];
196
- for (const value of values) {
197
- const resolved = toPath(value, cwd, home);
198
- if (resolved)
199
- out.push(resolved);
200
- }
201
- return out;
202
- };
203
- const toUniquePathList = (values, cwd, home) => normalizeList(toPathList(values, cwd, home));
204
- const toEnvFiles = (input, cwd, home) => {
205
- const values = Array.isArray(input)
206
- ? input
207
- : input
208
- ? [input]
209
- : [DEFAULT_ENV_FILE];
210
- return toUniquePathList(values, cwd, home);
211
- };
212
- const rawRealpathSync = realpathSyncCompat.native ?? realpathSyncCompat;
213
- const toCanonicalPath = (candidate) => {
214
- return toSharedCanonicalPath(candidate, {
215
- existsSync: existsSyncCompat,
216
- realpathSync: rawRealpathSync,
217
- });
218
- };
219
- const isPathWithin = (base, candidate) => {
220
- const canonicalBase = toCanonicalPath(base);
221
- const canonicalCandidate = toCanonicalPath(candidate);
222
- const relative = pathRelative(canonicalBase, canonicalCandidate);
223
- return relative === "" ||
224
- (!relative.startsWith("..") && !pathIsAbsolute(relative));
225
- };
226
- const defaultSensitiveProjectAndHomePaths = (cwd, home) => {
227
- const projectSensitive = DEFAULT_DENY_RELATIVE.map((entry) => pathResolve(cwd, entry));
228
- const homeSensitive = home
229
- ? DEFAULT_DENY_HOME.map((entry) => pathResolve(home, entry))
230
- : [];
231
- return normalizeList([...projectSensitive, ...homeSensitive]);
232
- };
233
- const defaultSensitiveReadDenyPaths = (cwd, home) => {
234
- const projectAndHome = defaultSensitiveProjectAndHomePaths(cwd, home);
235
- const osSensitive = isWindows()
236
- ? []
237
- : DEFAULT_DENY_ABSOLUTE_POSIX.map((entry) => pathResolve(entry));
238
- return normalizeList([...projectAndHome, ...osSensitive]);
239
- };
240
- const collectWritePaths = (cwd, values) => {
241
- const out = normalizeList(values.length > 0 ? values : [cwd]);
242
- if (!out.some((entry) => isPathWithin(entry, cwd) || isPathWithin(cwd, entry))) {
243
- out.unshift(cwd);
244
- }
245
- return normalizeList(out);
246
- };
247
- const collectReadPaths = ({ cwd, read, moduleFiles, envFiles, denoLock, }) => {
248
- const out = [
249
- cwd,
250
- pathResolve(cwd, NODE_MODULES_DIR),
251
- ...read,
252
- ...moduleFiles,
253
- ...envFiles,
254
- ];
255
- if (denoLock)
256
- out.push(denoLock);
257
- return normalizeList(out);
258
- };
259
- const resolveDenoLock = (input, cwd, home) => {
260
- if (input === false)
261
- return undefined;
262
- if (input && input !== true) {
263
- return toPath(input, cwd, home);
264
- }
265
- return pathResolve(cwd, DEFAULT_DENO_LOCK_FILE);
266
- };
267
- const resolveNodePermissionActivationFlag = () => {
268
- try {
269
- const raw = getNodeProcess()?.versions?.node;
270
- const major = Number.parseInt(String(raw).split(".", 1)[0] ?? "", 10);
271
- if (Number.isFinite(major) && major > 0 && major < 22) {
272
- return "--experimental-permission";
273
- }
274
- }
275
- catch {
276
- }
277
- return "--permission";
278
- };
279
- const toNodeFlags = ({ read, readAll, write, writeAll, envFiles, node, }) => {
280
- const modelFlags = [];
281
- if (readAll) {
282
- modelFlags.push("--allow-fs-read=*");
283
- }
284
- else if (read.length > 0) {
285
- modelFlags.push(`--allow-fs-read=${read.join(",")}`);
286
- }
287
- if (writeAll) {
288
- modelFlags.push("--allow-fs-write=*");
289
- }
290
- else if (write.length > 0) {
291
- modelFlags.push(`--allow-fs-write=${write.join(",")}`);
292
- }
293
- if (node.allowWorker)
294
- modelFlags.push("--allow-worker");
295
- if (node.allowChildProcess)
296
- modelFlags.push("--allow-child-process");
297
- if (node.allowAddons)
298
- modelFlags.push("--allow-addons");
299
- if (node.allowWasi)
300
- modelFlags.push("--allow-wasi");
301
- const flags = [];
302
- if (modelFlags.length > 0) {
303
- flags.push(resolveNodePermissionActivationFlag(), ...modelFlags);
304
- }
305
- for (const file of envFiles) {
306
- flags.push(`--env-file-if-exists=${file}`);
307
- }
308
- return flags;
309
- };
310
- const toDenoFlags = ({ read, readAll, write, writeAll, denyRead, denyWrite, net, netAll, denyNet, allowImport, allowImportAll, envAllow, envAllowAll, envDeny, envFiles, run, runAll, denyRun, ffi, ffiAll, denyFfi, sys, sysAll, denySys, denoLock, denoLockEnabled, frozen, }) => {
311
- const flags = [];
312
- if (readAll) {
313
- flags.push("--allow-read");
314
- }
315
- else if (read.length > 0) {
316
- flags.push(`--allow-read=${read.join(",")}`);
317
- }
318
- if (writeAll) {
319
- flags.push("--allow-write");
320
- }
321
- else if (write.length > 0) {
322
- flags.push(`--allow-write=${write.join(",")}`);
323
- }
324
- if (denyRead.length > 0) {
325
- flags.push(`--deny-read=${denyRead.join(",")}`);
326
- }
327
- if (denyWrite.length > 0) {
328
- flags.push(`--deny-write=${denyWrite.join(",")}`);
329
- }
330
- if (netAll) {
331
- flags.push("--allow-net");
332
- }
333
- else if (net.length > 0) {
334
- flags.push(`--allow-net=${net.join(",")}`);
335
- }
336
- if (denyNet.length > 0) {
337
- flags.push(`--deny-net=${denyNet.join(",")}`);
338
- }
339
- if (allowImportAll) {
340
- flags.push("--allow-import");
341
- }
342
- else if (allowImport.length > 0) {
343
- flags.push(`--allow-import=${allowImport.join(",")}`);
344
- }
345
- if (envAllowAll) {
346
- flags.push("--allow-env");
347
- }
348
- else if (envAllow.length > 0) {
349
- flags.push(`--allow-env=${envAllow.join(",")}`);
350
- }
351
- if (envDeny.length > 0) {
352
- flags.push(`--deny-env=${envDeny.join(",")}`);
353
- }
354
- for (const file of envFiles) {
355
- try {
356
- if (!existsSyncCompat(file))
357
- continue;
358
- }
359
- catch {
360
- continue;
361
- }
362
- flags.push(`--env-file=${file}`);
363
- }
364
- if (runAll) {
365
- flags.push("--allow-run");
366
- }
367
- else if (run.length > 0) {
368
- flags.push(`--allow-run=${run.join(",")}`);
369
- }
370
- if (denyRun.length > 0) {
371
- flags.push(`--deny-run=${denyRun.join(",")}`);
372
- }
373
- if (ffiAll) {
374
- flags.push("--allow-ffi");
375
- }
376
- else if (ffi.length > 0) {
377
- flags.push(`--allow-ffi=${ffi.join(",")}`);
378
- }
379
- if (denyFfi.length > 0) {
380
- flags.push(`--deny-ffi=${denyFfi.join(",")}`);
381
- }
382
- if (sysAll) {
383
- flags.push("--allow-sys");
384
- }
385
- else if (sys.length > 0) {
386
- flags.push(`--allow-sys=${sys.join(",")}`);
387
- }
388
- if (denySys.length > 0) {
389
- flags.push(`--deny-sys=${denySys.join(",")}`);
390
- }
391
- if (!denoLockEnabled) {
392
- flags.push("--no-lock");
393
- }
394
- else if (denoLock) {
395
- flags.push(`--lock=${denoLock}`);
396
- if (frozen)
397
- flags.push("--frozen=true");
398
- }
399
- return flags;
400
- };
401
- export const resolvePermissionProtocol = ({ permission, modules, }) => {
402
- const input = normalizeProtocolInput(permission);
403
- if (!input)
404
- return undefined;
405
- const rawMode = input.mode;
406
- const mode = (rawMode === "unsafe" || rawMode === "off")
407
- ? "unsafe"
408
- : (rawMode === "custom" ? "custom" : "strict");
409
- const unsafe = mode === "unsafe";
410
- const allowConsole = input.console ?? unsafe;
411
- const cwd = pathResolve(input.cwd ?? getCwd());
412
- const home = getHome();
413
- const envFiles = toEnvFiles(input.env?.files, cwd, home);
414
- const moduleFiles = toUniquePathList(modules, cwd, home);
415
- const denoLockInput = input.deno?.lock;
416
- const denoLockEnabled = denoLockInput !== false;
417
- const denoLock = resolveDenoLock(denoLockInput, cwd, home);
418
- if (unsafe) {
419
- return {
420
- enabled: true,
421
- mode,
422
- unsafe: true,
423
- allowConsole,
424
- cwd,
425
- read: [],
426
- readAll: true,
427
- write: [],
428
- writeAll: true,
429
- denyRead: [],
430
- denyWrite: [],
431
- net: [],
432
- netAll: true,
433
- denyNet: [],
434
- allowImport: [],
435
- allowImportAll: true,
436
- env: {
437
- allow: [],
438
- allowAll: true,
439
- deny: [],
440
- files: envFiles,
441
- },
442
- envFiles,
443
- run: [],
444
- runAll: true,
445
- denyRun: [],
446
- workers: true,
447
- ffi: [],
448
- ffiAll: true,
449
- denyFfi: [],
450
- sys: [],
451
- sysAll: true,
452
- denySys: [],
453
- wasi: true,
454
- lockFiles: {
455
- deno: denoLock,
456
- },
457
- node: {
458
- allowWorker: true,
459
- allowChildProcess: true,
460
- allowAddons: true,
461
- allowWasi: true,
462
- flags: [],
463
- },
464
- deno: {
465
- frozen: false,
466
- allowRun: true,
467
- flags: [],
468
- },
469
- l3: cloneL3Keys(),
470
- };
471
- }
472
- const nodeModulesPath = pathResolve(cwd, NODE_MODULES_DIR);
473
- const hasExplicitDenyRead = hasOwn(input, "denyRead");
474
- const hasExplicitDenyWrite = hasOwn(input, "denyWrite");
475
- const hasExplicitRead = hasOwn(input, "read");
476
- const hasExplicitWrite = hasOwn(input, "write");
477
- const denyReadDefaults = defaultSensitiveReadDenyPaths(cwd, home);
478
- const denyWriteDefaults = normalizeList([
479
- ...defaultSensitiveProjectAndHomePaths(cwd, home),
480
- nodeModulesPath,
481
- ]);
482
- const denyRead = normalizeList([
483
- ...toPathList(input.denyRead, cwd, home),
484
- ...((mode === "custom" && hasExplicitDenyRead) ? [] : denyReadDefaults),
485
- ]);
486
- const denyWrite = normalizeList([
487
- ...toPathList(input.denyWrite, cwd, home),
488
- ...((mode === "custom" && hasExplicitDenyWrite) ? [] : denyWriteDefaults),
489
- ]);
490
- const readAll = input.read === true;
491
- const writeAll = input.write === true;
492
- const configuredRead = readAll
493
- ? []
494
- : toPathList(Array.isArray(input.read) ? input.read : undefined, cwd, home);
495
- const configuredWrite = writeAll ? [] : toPathList(Array.isArray(input.write) ? input.write : undefined, cwd, home);
496
- const resolvedRead = readAll
497
- ? []
498
- : hasExplicitRead
499
- ? normalizeList(configuredRead)
500
- : collectReadPaths({
501
- cwd,
502
- read: configuredRead,
503
- moduleFiles,
504
- envFiles,
505
- denoLock,
506
- });
507
- const resolvedWrite = writeAll
508
- ? []
509
- : hasExplicitWrite
510
- ? normalizeList(configuredWrite)
511
- : collectWritePaths(cwd, configuredWrite);
512
- const netAll = input.net === true;
513
- const net = netAll
514
- ? []
515
- : normalizeStringList(Array.isArray(input.net) ? input.net : []);
516
- const denyNet = normalizeStringList(input.denyNet);
517
- const allowImportAll = input.allowImport === true;
518
- const allowImport = allowImportAll ? [] : normalizeStringList(Array.isArray(input.allowImport)
519
- ? input.allowImport
520
- : [...DEFAULT_ALLOW_IMPORT_HOSTS]);
521
- const envAllowAll = input.env?.allow === true;
522
- const envAllow = envAllowAll ? [] : normalizeStringList(Array.isArray(input.env?.allow) ? input.env.allow : []);
523
- const envDeny = normalizeStringList(input.env?.deny);
524
- const legacyRunEnabled = input.node?.allowChildProcess === true ||
525
- input.deno?.allowRun === true;
526
- const runSource = hasOwn(input, "run")
527
- ? input.run
528
- : (legacyRunEnabled ? true : []);
529
- const runAll = runSource === true;
530
- const run = runAll
531
- ? []
532
- : normalizeStringList(Array.isArray(runSource) ? runSource : []);
533
- const denyRun = normalizeStringList(input.denyRun);
534
- const workers = hasOwn(input, "workers")
535
- ? input.workers === true
536
- : input.node?.allowWorker === true;
537
- const ffiSource = hasOwn(input, "ffi")
538
- ? input.ffi
539
- : (input.node?.allowAddons === true ? true : false);
540
- const ffiAll = ffiSource === true;
541
- const ffi = ffiAll ? [] : toUniquePathList(Array.isArray(ffiSource) ? ffiSource : undefined, cwd, home);
542
- const denyFfi = toUniquePathList(input.denyFfi, cwd, home);
543
- const sysSource = input.sys;
544
- const sysAll = sysSource === true;
545
- const sys = sysAll
546
- ? []
547
- : normalizeSysApiList(Array.isArray(sysSource) ? sysSource : []);
548
- const denySys = normalizeSysApiList(input.denySys);
549
- const wasi = hasOwn(input, "wasi")
550
- ? input.wasi === true
551
- : input.node?.allowWasi === true;
552
- const nodeSettings = {
553
- allowWorker: workers,
554
- allowChildProcess: runAll || run.length > 0,
555
- allowAddons: ffiAll || ffi.length > 0,
556
- allowWasi: wasi,
557
- };
558
- const denoSettings = {
559
- frozen: input.deno?.frozen !== false,
560
- allowRun: runAll || run.length > 0,
561
- };
562
- return {
563
- enabled: true,
564
- mode,
565
- unsafe: false,
566
- allowConsole,
567
- cwd,
568
- read: resolvedRead,
569
- readAll,
570
- write: resolvedWrite,
571
- writeAll,
572
- denyRead,
573
- denyWrite,
574
- net,
575
- netAll,
576
- denyNet,
577
- allowImport,
578
- allowImportAll,
579
- env: {
580
- allow: envAllow,
581
- allowAll: envAllowAll,
582
- deny: envDeny,
583
- files: envFiles,
584
- },
585
- envFiles,
586
- run,
587
- runAll,
588
- denyRun,
589
- workers,
590
- ffi,
591
- ffiAll,
592
- denyFfi,
593
- sys,
594
- sysAll,
595
- denySys,
596
- wasi,
597
- lockFiles: {
598
- deno: denoLock,
599
- },
600
- node: {
601
- ...nodeSettings,
602
- flags: toNodeFlags({
603
- read: resolvedRead,
604
- readAll,
605
- write: resolvedWrite,
606
- writeAll,
607
- envFiles,
608
- node: nodeSettings,
609
- }),
610
- },
611
- deno: {
612
- ...denoSettings,
613
- flags: toDenoFlags({
614
- read: resolvedRead,
615
- readAll,
616
- write: resolvedWrite,
617
- writeAll,
618
- denyRead,
619
- denyWrite,
620
- net,
621
- netAll,
622
- denyNet,
623
- allowImport,
624
- allowImportAll,
625
- envAllow,
626
- envAllowAll,
627
- envDeny,
628
- envFiles,
629
- run,
630
- runAll,
631
- denyRun,
632
- ffi,
633
- ffiAll,
634
- denyFfi,
635
- sys,
636
- sysAll,
637
- denySys,
638
- denoLock,
639
- denoLockEnabled,
640
- frozen: denoSettings.frozen,
641
- }),
642
- },
643
- l3: cloneL3Keys(),
644
- };
645
- };
646
- export const toRuntimePermissionFlags = (protocol) => protocol?.enabled === true && protocol.unsafe !== true
647
- ? (RUNTIME === "node"
648
- ? protocol.node.flags
649
- : (RUNTIME === "deno" ? protocol.deno.flags : []))
650
- : [];
@@ -1,19 +0,0 @@
1
- import type { Balancer, CreateContext } from "../types.js";
2
- export type Handler<A, R> = (args: A) => R;
3
- type LaneHandler = (args: any) => Promise<unknown>;
4
- type LaneInvoker = (args: any) => Promise<unknown>;
5
- type manager = {
6
- contexts: readonly CreateContext[];
7
- balancer?: Balancer;
8
- handlers: LaneHandler[];
9
- inlinerGate?: {
10
- index: number;
11
- threshold: number;
12
- };
13
- };
14
- export declare const managerMethod: ({ contexts, balancer, handlers, inlinerGate, }: manager) => LaneInvoker;
15
- export declare function roundRobin(_contexts: readonly CreateContext[]): (handlers: LaneHandler[]) => (max: number) => (args: any) => Promise<unknown>;
16
- export declare function firstIdle(contexts: readonly CreateContext[]): (handlers: LaneHandler[]) => (max: number) => (args: any) => Promise<unknown>;
17
- export declare const randomLane: (_: readonly CreateContext[]) => (handlers: LaneHandler[]) => (max: number) => (args: any) => Promise<unknown>;
18
- export declare function firstIdleRandom(contexts: readonly CreateContext[]): (handlers: LaneHandler[]) => (max: number) => (args: any) => Promise<unknown>;
19
- export {};