@poe-platform/safe-js 0.1.799 → 0.1.801
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/README.md +4 -2
- package/dist/safe-js/chunks/{chunk-KULEMOAE.js → chunk-4KMUWNZD.js} +5 -156
- package/dist/safe-js/chunks/{chunk-ULPZIHB5.js → chunk-5RLD4TVI.js} +174 -127
- package/dist/safe-js/chunks/{chunk-MCFRB5X3.js → chunk-6H5VC5W5.js} +84 -14
- package/dist/safe-js/chunks/{chunk-TBZILU4U.js → chunk-7THYP46K.js} +1 -1
- package/dist/safe-js/chunks/{chunk-UU4T2KIT.js → chunk-CK3YK2EC.js} +1 -1
- package/dist/safe-js/chunks/{chunk-3O7HA6WT.js → chunk-F6Y734YA.js} +2 -2
- package/dist/safe-js/chunks/{chunk-M6S3F3WM.js → chunk-HFRBLE6Y.js} +42 -36
- package/dist/safe-js/chunks/{chunk-OPYN6N5M.js → chunk-HPHCQNFV.js} +154 -1
- package/dist/safe-js/chunks/{chunk-W6C3Q6U4.js → chunk-IB6WAQAE.js} +2 -2
- package/dist/safe-js/chunks/{chunk-ZKLJW27N.js → chunk-PMOXSLM5.js} +1 -1
- package/dist/safe-js/chunks/chunk-QRWRR6IA.js +78 -0
- package/dist/safe-js/chunks/{chunk-MDJ7MJYI.js → chunk-XOMGWE37.js} +2 -2
- package/dist/safe-js/chunks/{chunk-QTCPJ7FN.js → chunk-XV5OYKND.js} +1 -1
- package/dist/safe-js/chunks/{chunk-OTVZWRYE.js → chunk-YCFOANSU.js} +23 -18
- package/dist/safe-js/chunks/{cli-runtime-DYXJZCGV.js → cli-runtime-L4IABN2W.js} +15 -15
- package/dist/safe-js/chunks/{dump-XDJEF2LG.js → dump-KUPBSXSL.js} +2 -2
- package/dist/safe-js/chunks/{harness-32OOFC5A.js → harness-3DDUS3RY.js} +2 -2
- package/dist/safe-js/chunks/{mcp-PTCA53MN.js → mcp-5TMFK3UE.js} +3 -3
- package/dist/safe-js/chunks/{migration-file-EEGIOHQB.js → migration-file-4CYSJ6LO.js} +3 -3
- package/dist/safe-js/chunks/{restore-U3CCH36B.js → restore-GDHBT5ZD.js} +3 -3
- package/dist/safe-js/chunks/{run-Q74MU3QQ.js → run-M6N5KCPF.js} +5 -5
- package/dist/safe-js/chunks/{runtime-modules-SL5D6LAJ.js → runtime-modules-MGSXY4BN.js} +2 -2
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.d.ts +6 -0
- package/dist/safe-js/core.js +33 -7
- package/dist/safe-js/index.js +24 -93
- package/dist/safe-js/interp/data-copy.d.ts +3 -2
- package/dist/safe-js/interp/host-bridge.d.ts +5 -4
- package/dist/safe-js/modules/fs-config.d.ts +1 -0
- package/dist/safe-js/modules/fs.d.ts +2 -0
- package/dist/safe-js/modules/fs.js +2 -2
- package/dist/safe-js/node-unavailable.d.ts +1 -0
- package/dist/safe-js/portable/chunks/chunk-2FNMGWDK.js +58703 -0
- package/dist/safe-js/portable/chunks/chunk-H5X3T5VP.js +909 -0
- package/dist/safe-js/portable/chunks/chunk-XCTU25SU.js +111 -0
- package/dist/safe-js/portable/chunks/source-files-CVU252FB.js +7 -0
- package/dist/safe-js/portable/core.js +14763 -0
- package/dist/safe-js/portable/modules/fs.js +9 -0
- package/dist/safe-js/snapshot/arguments.d.ts +2 -0
- package/dist/safe-js/snapshot/property-descriptors.d.ts +2 -0
- package/dist/safe-js/snapshot/regexp-properties.d.ts +2 -0
- package/dist/safe-js/snapshot/symbols.d.ts +2 -0
- package/dist/safe-js/workerd.d.ts +3 -0
- package/dist/safe-js/workerd.js +74436 -0
- package/package.json +30 -6
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fsConstants,
|
|
3
|
+
hostFs,
|
|
4
|
+
paths_default
|
|
5
|
+
} from "./chunk-H5X3T5VP.js";
|
|
6
|
+
|
|
7
|
+
// packages/safe-js/src/modules/source-files.ts
|
|
8
|
+
import { resolvePath } from "@poe-platform/safe-fs/core";
|
|
9
|
+
async function createRootedSourceResolver(root, adapter) {
|
|
10
|
+
const realpath = (filename) => adapter ? adapter.realpath(filename) : hostFs.realpath(filename);
|
|
11
|
+
const stat = async (filename) => adapter ? sourceStat(await adapter.stat(filename)) : await hostFs.stat(filename);
|
|
12
|
+
const granted = adapter ? resolvePath("/", root) : paths_default.resolve(root);
|
|
13
|
+
const directory = await realpath(granted);
|
|
14
|
+
if (!(await stat(directory)).isDirectory()) throw new TypeError("Source module root must be a directory.");
|
|
15
|
+
const contains = (filename) => {
|
|
16
|
+
const relative = paths_default.relative(directory, filename);
|
|
17
|
+
return relative !== ".." && !relative.startsWith(`..${paths_default.sep}`) && !paths_default.isAbsolute(relative);
|
|
18
|
+
};
|
|
19
|
+
const resolver = async (specifier, referrer, { signal }) => {
|
|
20
|
+
signal?.throwIfAborted();
|
|
21
|
+
if (!specifier.startsWith("./") && !specifier.startsWith("../") || !paths_default.isAbsolute(referrer)) return void 0;
|
|
22
|
+
const relative = paths_default.relative(granted, referrer);
|
|
23
|
+
const canonicalReferrer = relative !== ".." && !relative.startsWith(`..${paths_default.sep}`) && !paths_default.isAbsolute(relative) ? paths_default.resolve(directory, relative) : referrer;
|
|
24
|
+
if (!contains(canonicalReferrer)) return void 0;
|
|
25
|
+
const candidate = paths_default.resolve(paths_default.dirname(canonicalReferrer), specifier);
|
|
26
|
+
if (!contains(candidate)) return void 0;
|
|
27
|
+
try {
|
|
28
|
+
const id = await realpath(candidate);
|
|
29
|
+
signal?.throwIfAborted();
|
|
30
|
+
if (!contains(id)) return void 0;
|
|
31
|
+
const expected = await stat(id);
|
|
32
|
+
signal?.throwIfAborted();
|
|
33
|
+
if (!expected.isFile()) return void 0;
|
|
34
|
+
const handle = adapter ? await openSourceFile(adapter, id, signal) : await hostFs.open(id, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
|
|
35
|
+
try {
|
|
36
|
+
signal?.throwIfAborted();
|
|
37
|
+
const actual = await handle.stat();
|
|
38
|
+
signal?.throwIfAborted();
|
|
39
|
+
if (!actual.isFile() || ("identity" in actual && "identity" in expected ? !sameSourceIdentity(actual.identity, expected.identity) : actual.dev !== expected.dev || actual.ino !== expected.ino)) return void 0;
|
|
40
|
+
const currentId = await realpath(id);
|
|
41
|
+
signal?.throwIfAborted();
|
|
42
|
+
if (currentId !== id) return void 0;
|
|
43
|
+
const source = await handle.readFile({ encoding: "utf8", signal });
|
|
44
|
+
signal?.throwIfAborted();
|
|
45
|
+
return { id, source };
|
|
46
|
+
} finally {
|
|
47
|
+
await handle.close();
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
signal?.throwIfAborted();
|
|
51
|
+
if (error !== null && typeof error === "object" && "code" in error && ["ENOENT", "ENOTDIR", "ELOOP"].includes(String(error.code))) return void 0;
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return Object.assign(resolver, { async entryId(filename) {
|
|
56
|
+
if (filename === void 0) return paths_default.join(directory, "<entry>");
|
|
57
|
+
const supplied = paths_default.resolve(granted, filename);
|
|
58
|
+
const relative = paths_default.relative(granted, supplied);
|
|
59
|
+
const candidate = relative !== ".." && !relative.startsWith(`..${paths_default.sep}`) && !paths_default.isAbsolute(relative) ? paths_default.resolve(directory, relative) : supplied;
|
|
60
|
+
if (!contains(candidate)) throw new TypeError("Source entry must be inside its granted root.");
|
|
61
|
+
try {
|
|
62
|
+
const id = await realpath(candidate);
|
|
63
|
+
if (!contains(id)) throw new TypeError("Source entry must be inside its granted root.");
|
|
64
|
+
return id;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT") return candidate;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
} });
|
|
70
|
+
}
|
|
71
|
+
function sourceStat(value) {
|
|
72
|
+
return {
|
|
73
|
+
identity: value,
|
|
74
|
+
dev: value.dev,
|
|
75
|
+
ino: value.ino,
|
|
76
|
+
isFile: () => value.type === "file",
|
|
77
|
+
isDirectory: () => value.type === "directory"
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function sameSourceIdentity(actual, expected) {
|
|
81
|
+
if (expected.identityScope !== void 0 && expected.opaqueIdentity !== void 0) {
|
|
82
|
+
return actual.identityScope === expected.identityScope && actual.opaqueIdentity === expected.opaqueIdentity && (expected.opaqueVersion === void 0 || actual.opaqueVersion === expected.opaqueVersion);
|
|
83
|
+
}
|
|
84
|
+
return expected.dev !== void 0 && expected.ino !== void 0 && actual.dev === expected.dev && actual.ino === expected.ino;
|
|
85
|
+
}
|
|
86
|
+
async function openSourceFile(adapter, id, signal) {
|
|
87
|
+
if (!adapter.openReadFile) throw new TypeError("Source filesystem must support retained reads.");
|
|
88
|
+
const handle = await adapter.openReadFile(id, signal ? { signal } : {});
|
|
89
|
+
return {
|
|
90
|
+
stat: async () => sourceStat(await handle.stat(signal ? { signal } : {})),
|
|
91
|
+
close: handle.close.bind(handle),
|
|
92
|
+
async readFile(_options) {
|
|
93
|
+
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
94
|
+
const chunks = [];
|
|
95
|
+
let position = 0;
|
|
96
|
+
for (; ; ) {
|
|
97
|
+
signal?.throwIfAborted();
|
|
98
|
+
const chunk = await handle.read(position, 64 * 1024, signal ? { signal } : {});
|
|
99
|
+
if (chunk.byteLength === 0) break;
|
|
100
|
+
chunks.push(decoder.decode(chunk, { stream: true }));
|
|
101
|
+
position += chunk.byteLength;
|
|
102
|
+
}
|
|
103
|
+
chunks.push(decoder.decode());
|
|
104
|
+
return chunks.join("");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
createRootedSourceResolver
|
|
111
|
+
};
|