knitting 0.1.46

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