@ricsam/quickjs-fs 0.0.1 → 0.2.1
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 +70 -43
- package/dist/cjs/directory-handle.cjs +166 -0
- package/dist/cjs/directory-handle.cjs.map +10 -0
- package/dist/cjs/file-handle.cjs +125 -0
- package/dist/cjs/file-handle.cjs.map +10 -0
- package/dist/cjs/index.cjs +43 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/memory-adapter.cjs +269 -0
- package/dist/cjs/memory-adapter.cjs.map +10 -0
- package/dist/cjs/node-adapter.cjs +221 -0
- package/dist/cjs/node-adapter.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/setup.cjs +140 -0
- package/dist/cjs/setup.cjs.map +10 -0
- package/dist/cjs/types.cjs +26 -0
- package/dist/cjs/types.cjs.map +9 -0
- package/dist/cjs/writable-stream.cjs +119 -0
- package/dist/cjs/writable-stream.cjs.map +10 -0
- package/dist/mjs/directory-handle.mjs +135 -0
- package/dist/mjs/directory-handle.mjs.map +10 -0
- package/dist/mjs/file-handle.mjs +94 -0
- package/dist/mjs/file-handle.mjs.map +10 -0
- package/dist/mjs/index.mjs +12 -0
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/memory-adapter.mjs +237 -0
- package/dist/mjs/memory-adapter.mjs.map +10 -0
- package/dist/mjs/node-adapter.mjs +189 -0
- package/dist/mjs/node-adapter.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/mjs/setup.mjs +112 -0
- package/dist/mjs/setup.mjs.map +10 -0
- package/dist/mjs/types.mjs +3 -0
- package/dist/mjs/types.mjs.map +9 -0
- package/dist/mjs/writable-stream.mjs +88 -0
- package/dist/mjs/writable-stream.mjs.map +10 -0
- package/dist/types/handles/directory-handle.d.ts +12 -0
- package/dist/types/handles/file-handle.d.ts +14 -0
- package/dist/types/handles/writable-stream.d.ts +6 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/memory-adapter.d.ts +18 -0
- package/dist/types/node-adapter.d.ts +23 -0
- package/dist/types/setup.d.ts +56 -0
- package/dist/types/types.d.ts +85 -0
- package/package.json +51 -6
package/README.md
CHANGED
|
@@ -1,45 +1,72 @@
|
|
|
1
1
|
# @ricsam/quickjs-fs
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
File System Access API (OPFS-compatible).
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { setupFs, createNodeDirectoryHandle } from "@ricsam/quickjs-fs";
|
|
7
|
+
|
|
8
|
+
const handle = setupFs(context, {
|
|
9
|
+
getDirectory: async (path) => {
|
|
10
|
+
// Validate path access
|
|
11
|
+
if (!path.startsWith("/allowed")) {
|
|
12
|
+
throw new Error("Access denied");
|
|
13
|
+
}
|
|
14
|
+
return createNodeDirectoryHandle(`./sandbox${path}`);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Injected Globals:**
|
|
20
|
+
- `fs.getDirectory(path)` - Entry point for file system access
|
|
21
|
+
- `FileSystemDirectoryHandle`, `FileSystemFileHandle`
|
|
22
|
+
- `FileSystemWritableFileStream`
|
|
23
|
+
|
|
24
|
+
**Usage in QuickJS:**
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
// Get directory handle
|
|
28
|
+
const root = await fs.getDirectory("/data");
|
|
29
|
+
|
|
30
|
+
// Read a file
|
|
31
|
+
const fileHandle = await root.getFileHandle("config.json");
|
|
32
|
+
const file = await fileHandle.getFile();
|
|
33
|
+
const text = await file.text();
|
|
34
|
+
const config = JSON.parse(text);
|
|
35
|
+
|
|
36
|
+
// Write a file
|
|
37
|
+
const outputHandle = await root.getFileHandle("output.txt", { create: true });
|
|
38
|
+
const writable = await outputHandle.createWritable();
|
|
39
|
+
await writable.write("Hello, World!");
|
|
40
|
+
await writable.close();
|
|
41
|
+
|
|
42
|
+
// Directory operations
|
|
43
|
+
const subDir = await root.getDirectoryHandle("subdir", { create: true });
|
|
44
|
+
await root.removeEntry("old-file.txt");
|
|
45
|
+
await root.removeEntry("old-dir", { recursive: true });
|
|
46
|
+
|
|
47
|
+
// Iterate directory
|
|
48
|
+
for await (const [name, handle] of root.entries()) {
|
|
49
|
+
console.log(name, handle.kind); // "file" or "directory"
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Host Adapters
|
|
54
|
+
|
|
55
|
+
**Node.js/Bun adapter:**
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { createNodeDirectoryHandle } from "@ricsam/quickjs-fs";
|
|
59
|
+
|
|
60
|
+
const dirHandle = createNodeDirectoryHandle("/path/to/directory");
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**In-memory adapter (for testing):**
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { createMemoryDirectoryHandle } from "@ricsam/quickjs-fs";
|
|
67
|
+
|
|
68
|
+
const memFs = createMemoryDirectoryHandle({
|
|
69
|
+
"config.json": JSON.stringify({ debug: true }),
|
|
70
|
+
"data/users.json": JSON.stringify([]),
|
|
71
|
+
});
|
|
72
|
+
```
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/fs/src/handles/directory-handle.ts
|
|
31
|
+
var exports_directory_handle = {};
|
|
32
|
+
__export(exports_directory_handle, {
|
|
33
|
+
registerHostDirectoryHandle: () => registerHostDirectoryHandle,
|
|
34
|
+
pendingHostHandles: () => pendingHostHandles,
|
|
35
|
+
createFileSystemDirectoryHandleClass: () => createFileSystemDirectoryHandleClass
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(exports_directory_handle);
|
|
38
|
+
var import_quickjs_core = require("@ricsam/quickjs-core");
|
|
39
|
+
var import_file_handle = require("./file-handle.ts");
|
|
40
|
+
var nextHostHandleId = 0;
|
|
41
|
+
var pendingHostHandles = new Map;
|
|
42
|
+
function registerHostDirectoryHandle(handle) {
|
|
43
|
+
const id = nextHostHandleId++;
|
|
44
|
+
pendingHostHandles.set(id, { handle, name: handle.name });
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
function createFileSystemDirectoryHandleClass(context, stateMap) {
|
|
48
|
+
return import_quickjs_core.defineClass(context, stateMap, {
|
|
49
|
+
name: "FileSystemDirectoryHandle",
|
|
50
|
+
construct: (args) => {
|
|
51
|
+
const hostHandleId = args[0];
|
|
52
|
+
const pending = pendingHostHandles.get(hostHandleId);
|
|
53
|
+
if (!pending) {
|
|
54
|
+
throw new Error(`No pending host handle with ID ${hostHandleId}`);
|
|
55
|
+
}
|
|
56
|
+
pendingHostHandles.delete(hostHandleId);
|
|
57
|
+
return {
|
|
58
|
+
kind: "directory",
|
|
59
|
+
name: pending.name,
|
|
60
|
+
hostHandle: pending.handle
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
properties: {
|
|
64
|
+
kind: {
|
|
65
|
+
get() {
|
|
66
|
+
return "directory";
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
name: {
|
|
70
|
+
get() {
|
|
71
|
+
return this.name;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
methods: {
|
|
76
|
+
async _getFileHandleInternal(name, options) {
|
|
77
|
+
const opts = options;
|
|
78
|
+
const hostFile = await this.hostHandle.getFileHandle(String(name), {
|
|
79
|
+
create: opts?.create
|
|
80
|
+
});
|
|
81
|
+
return { __fileHandleId: import_file_handle.registerHostFileHandle(hostFile) };
|
|
82
|
+
},
|
|
83
|
+
async _getDirectoryHandleInternal(name, options) {
|
|
84
|
+
const opts = options;
|
|
85
|
+
const hostDir = await this.hostHandle.getDirectoryHandle(String(name), {
|
|
86
|
+
create: opts?.create
|
|
87
|
+
});
|
|
88
|
+
return { __directoryHandleId: registerHostDirectoryHandle(hostDir) };
|
|
89
|
+
},
|
|
90
|
+
async removeEntry(name, options) {
|
|
91
|
+
const opts = options;
|
|
92
|
+
await this.hostHandle.removeEntry(String(name), {
|
|
93
|
+
recursive: opts?.recursive
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
async resolve(possibleDescendant) {
|
|
97
|
+
if (!possibleDescendant || typeof possibleDescendant !== "object") {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const descendant = possibleDescendant;
|
|
101
|
+
return this.hostHandle.resolve(descendant.hostHandle);
|
|
102
|
+
},
|
|
103
|
+
async entries() {
|
|
104
|
+
const result = [];
|
|
105
|
+
for await (const [name, handle] of this.hostHandle.entries()) {
|
|
106
|
+
if (handle.kind === "file") {
|
|
107
|
+
result.push([
|
|
108
|
+
name,
|
|
109
|
+
{
|
|
110
|
+
kind: "file",
|
|
111
|
+
name: handle.name,
|
|
112
|
+
hostHandle: handle
|
|
113
|
+
}
|
|
114
|
+
]);
|
|
115
|
+
} else {
|
|
116
|
+
result.push([
|
|
117
|
+
name,
|
|
118
|
+
{
|
|
119
|
+
kind: "directory",
|
|
120
|
+
name: handle.name,
|
|
121
|
+
hostHandle: handle
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
},
|
|
128
|
+
async keys() {
|
|
129
|
+
const result = [];
|
|
130
|
+
for await (const name of this.hostHandle.keys()) {
|
|
131
|
+
result.push(name);
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
},
|
|
135
|
+
async values() {
|
|
136
|
+
const result = [];
|
|
137
|
+
for await (const handle of this.hostHandle.values()) {
|
|
138
|
+
if (handle.kind === "file") {
|
|
139
|
+
result.push({
|
|
140
|
+
kind: "file",
|
|
141
|
+
name: handle.name,
|
|
142
|
+
hostHandle: handle
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
result.push({
|
|
146
|
+
kind: "directory",
|
|
147
|
+
name: handle.name,
|
|
148
|
+
hostHandle: handle
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
},
|
|
154
|
+
async isSameEntry(other) {
|
|
155
|
+
if (!other || typeof other !== "object") {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const otherHandle = other;
|
|
159
|
+
return this.hostHandle === otherHandle.hostHandle;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
//# debugId=9FF50EE4CEB5814A64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/handles/directory-handle.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { StateMap } from \"@ricsam/quickjs-core\";\nimport { defineClass } from \"@ricsam/quickjs-core\";\nimport type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\nimport type {\n FileSystemDirectoryHandleState,\n FileSystemFileHandleState,\n HostDirectoryHandle,\n} from \"../types.ts\";\nimport { registerHostFileHandle } from \"./file-handle.ts\";\n\n// Registry for pending host handles that will be picked up by constructor\nlet nextHostHandleId = 0;\nexport const pendingHostHandles = new Map<\n number,\n { handle: HostDirectoryHandle; name: string }\n>();\n\nexport function registerHostDirectoryHandle(\n handle: HostDirectoryHandle\n): number {\n const id = nextHostHandleId++;\n pendingHostHandles.set(id, { handle, name: handle.name });\n return id;\n}\n\n/**\n * Create the FileSystemDirectoryHandle class for QuickJS\n */\nexport function createFileSystemDirectoryHandleClass(\n context: QuickJSContext,\n stateMap: StateMap\n): QuickJSHandle {\n return defineClass<FileSystemDirectoryHandleState>(context, stateMap, {\n name: \"FileSystemDirectoryHandle\",\n construct: (args) => {\n // First argument is the host handle ID\n const hostHandleId = args[0] as number;\n const pending = pendingHostHandles.get(hostHandleId);\n if (!pending) {\n throw new Error(`No pending host handle with ID ${hostHandleId}`);\n }\n pendingHostHandles.delete(hostHandleId);\n return {\n kind: \"directory\" as const,\n name: pending.name,\n hostHandle: pending.handle,\n };\n },\n properties: {\n kind: {\n get(this: FileSystemDirectoryHandleState) {\n return \"directory\";\n },\n },\n name: {\n get(this: FileSystemDirectoryHandleState) {\n return this.name;\n },\n },\n },\n methods: {\n async _getFileHandleInternal(\n this: FileSystemDirectoryHandleState,\n name: unknown,\n options?: unknown\n ): Promise<{ __fileHandleId: number }> {\n const opts = options as { create?: boolean } | undefined;\n const hostFile = await this.hostHandle.getFileHandle(String(name), {\n create: opts?.create,\n });\n\n return { __fileHandleId: registerHostFileHandle(hostFile) };\n },\n async _getDirectoryHandleInternal(\n this: FileSystemDirectoryHandleState,\n name: unknown,\n options?: unknown\n ): Promise<{ __directoryHandleId: number }> {\n const opts = options as { create?: boolean } | undefined;\n const hostDir = await this.hostHandle.getDirectoryHandle(String(name), {\n create: opts?.create,\n });\n\n return { __directoryHandleId: registerHostDirectoryHandle(hostDir) };\n },\n async removeEntry(\n this: FileSystemDirectoryHandleState,\n name: unknown,\n options?: unknown\n ): Promise<void> {\n const opts = options as { recursive?: boolean } | undefined;\n await this.hostHandle.removeEntry(String(name), {\n recursive: opts?.recursive,\n });\n },\n async resolve(\n this: FileSystemDirectoryHandleState,\n possibleDescendant: unknown\n ): Promise<string[] | null> {\n if (!possibleDescendant || typeof possibleDescendant !== \"object\") {\n return null;\n }\n\n const descendant = possibleDescendant as\n | FileSystemFileHandleState\n | FileSystemDirectoryHandleState;\n return this.hostHandle.resolve(descendant.hostHandle);\n },\n async entries(\n this: FileSystemDirectoryHandleState\n ): Promise<\n Array<\n [string, FileSystemFileHandleState | FileSystemDirectoryHandleState]\n >\n > {\n const result: Array<\n [string, FileSystemFileHandleState | FileSystemDirectoryHandleState]\n > = [];\n\n for await (const [name, handle] of this.hostHandle.entries()) {\n if (handle.kind === \"file\") {\n result.push([\n name,\n {\n kind: \"file\",\n name: handle.name,\n hostHandle: handle,\n },\n ]);\n } else {\n result.push([\n name,\n {\n kind: \"directory\",\n name: handle.name,\n hostHandle: handle,\n },\n ]);\n }\n }\n\n return result;\n },\n async keys(this: FileSystemDirectoryHandleState): Promise<string[]> {\n const result: string[] = [];\n for await (const name of this.hostHandle.keys()) {\n result.push(name);\n }\n return result;\n },\n async values(\n this: FileSystemDirectoryHandleState\n ): Promise<\n Array<FileSystemFileHandleState | FileSystemDirectoryHandleState>\n > {\n const result: Array<\n FileSystemFileHandleState | FileSystemDirectoryHandleState\n > = [];\n\n for await (const handle of this.hostHandle.values()) {\n if (handle.kind === \"file\") {\n result.push({\n kind: \"file\",\n name: handle.name,\n hostHandle: handle,\n });\n } else {\n result.push({\n kind: \"directory\",\n name: handle.name,\n hostHandle: handle,\n });\n }\n }\n\n return result;\n },\n async isSameEntry(\n this: FileSystemDirectoryHandleState,\n other: unknown\n ): Promise<boolean> {\n if (!other || typeof other !== \"object\") {\n return false;\n }\n const otherHandle = other as FileSystemDirectoryHandleState;\n return this.hostHandle === otherHandle.hostHandle;\n },\n },\n });\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAC4B,IAA5B;AAOuC,IAAvC;AAGA,IAAI,mBAAmB;AAChB,IAAM,qBAAqB,IAAI;AAK/B,SAAS,2BAA2B,CACzC,QACQ;AAAA,EACR,MAAM,KAAK;AAAA,EACX,mBAAmB,IAAI,IAAI,EAAE,QAAQ,MAAM,OAAO,KAAK,CAAC;AAAA,EACxD,OAAO;AAAA;AAMF,SAAS,oCAAoC,CAClD,SACA,UACe;AAAA,EACf,OAAO,gCAA4C,SAAS,UAAU;AAAA,IACpE,MAAM;AAAA,IACN,WAAW,CAAC,SAAS;AAAA,MAEnB,MAAM,eAAe,KAAK;AAAA,MAC1B,MAAM,UAAU,mBAAmB,IAAI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AY;AAAA;AAAA,IAE3C;AAAA,EACF,CAAC;AAAA;",
|
|
8
|
+
"debugId": "9FF50EE4CEB5814A64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/fs/src/handles/file-handle.ts
|
|
31
|
+
var exports_file_handle = {};
|
|
32
|
+
__export(exports_file_handle, {
|
|
33
|
+
registerHostWritableStream: () => registerHostWritableStream,
|
|
34
|
+
registerHostFileHandle: () => registerHostFileHandle,
|
|
35
|
+
pendingWritableStreams: () => pendingWritableStreams,
|
|
36
|
+
pendingFileHandles: () => pendingFileHandles,
|
|
37
|
+
createFileSystemFileHandleClass: () => createFileSystemFileHandleClass
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(exports_file_handle);
|
|
40
|
+
var import_quickjs_core = require("@ricsam/quickjs-core");
|
|
41
|
+
var nextFileHandleId = 0;
|
|
42
|
+
var pendingFileHandles = new Map;
|
|
43
|
+
var nextWritableStreamId = 0;
|
|
44
|
+
var pendingWritableStreams = new Map;
|
|
45
|
+
function registerHostFileHandle(handle) {
|
|
46
|
+
const id = nextFileHandleId++;
|
|
47
|
+
pendingFileHandles.set(id, { handle, name: handle.name });
|
|
48
|
+
return id;
|
|
49
|
+
}
|
|
50
|
+
function registerHostWritableStream(stream) {
|
|
51
|
+
const id = nextWritableStreamId++;
|
|
52
|
+
pendingWritableStreams.set(id, stream);
|
|
53
|
+
return id;
|
|
54
|
+
}
|
|
55
|
+
function createFileSystemFileHandleClass(context, stateMap) {
|
|
56
|
+
return import_quickjs_core.defineClass(context, stateMap, {
|
|
57
|
+
name: "FileSystemFileHandle",
|
|
58
|
+
construct: (args) => {
|
|
59
|
+
const hostHandleId = args[0];
|
|
60
|
+
const pending = pendingFileHandles.get(hostHandleId);
|
|
61
|
+
if (!pending) {
|
|
62
|
+
throw new Error(`No pending file handle with ID ${hostHandleId}`);
|
|
63
|
+
}
|
|
64
|
+
pendingFileHandles.delete(hostHandleId);
|
|
65
|
+
return {
|
|
66
|
+
kind: "file",
|
|
67
|
+
name: pending.name,
|
|
68
|
+
hostHandle: pending.handle
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
properties: {
|
|
72
|
+
kind: {
|
|
73
|
+
get() {
|
|
74
|
+
return "file";
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
name: {
|
|
78
|
+
get() {
|
|
79
|
+
return this.name;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
methods: {
|
|
84
|
+
async getFile() {
|
|
85
|
+
const file = await this.hostHandle.getFile();
|
|
86
|
+
const buffer = await file.arrayBuffer();
|
|
87
|
+
const data = new Uint8Array(buffer);
|
|
88
|
+
return {
|
|
89
|
+
parts: [data],
|
|
90
|
+
type: file.type,
|
|
91
|
+
size: file.size,
|
|
92
|
+
name: file.name,
|
|
93
|
+
lastModified: file.lastModified,
|
|
94
|
+
webkitRelativePath: "",
|
|
95
|
+
async text() {
|
|
96
|
+
return new TextDecoder().decode(data);
|
|
97
|
+
},
|
|
98
|
+
async arrayBuffer() {
|
|
99
|
+
return buffer;
|
|
100
|
+
},
|
|
101
|
+
async bytes() {
|
|
102
|
+
return data;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
async _createWritableInternal(options) {
|
|
107
|
+
const opts = options;
|
|
108
|
+
const hostStream = await this.hostHandle.createWritable({
|
|
109
|
+
keepExistingData: opts?.keepExistingData
|
|
110
|
+
});
|
|
111
|
+
return { __writableStreamId: registerHostWritableStream(hostStream) };
|
|
112
|
+
},
|
|
113
|
+
async isSameEntry(other) {
|
|
114
|
+
if (!other || typeof other !== "object") {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const otherHandle = other;
|
|
118
|
+
return this.hostHandle === otherHandle.hostHandle;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
//# debugId=03934374EFF6363C64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/handles/file-handle.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\nimport type { StateMap } from \"@ricsam/quickjs-core\";\nimport { defineClass } from \"@ricsam/quickjs-core\";\nimport type { FileSystemFileHandleState, HostFileHandle, HostWritableFileStream } from \"../types.ts\";\n\n// Registry for pending host handles that will be picked up by constructor\nlet nextFileHandleId = 0;\nexport const pendingFileHandles = new Map<number, { handle: HostFileHandle; name: string }>();\nlet nextWritableStreamId = 0;\nexport const pendingWritableStreams = new Map<number, HostWritableFileStream>();\n\nexport function registerHostFileHandle(handle: HostFileHandle): number {\n const id = nextFileHandleId++;\n pendingFileHandles.set(id, { handle, name: handle.name });\n return id;\n}\n\nexport function registerHostWritableStream(stream: HostWritableFileStream): number {\n const id = nextWritableStreamId++;\n pendingWritableStreams.set(id, stream);\n return id;\n}\n\n/**\n * Create the FileSystemFileHandle class for QuickJS\n */\nexport function createFileSystemFileHandleClass(\n context: QuickJSContext,\n stateMap: StateMap\n): QuickJSHandle {\n return defineClass<FileSystemFileHandleState>(context, stateMap, {\n name: \"FileSystemFileHandle\",\n construct: (args) => {\n const hostHandleId = args[0] as number;\n const pending = pendingFileHandles.get(hostHandleId);\n if (!pending) {\n throw new Error(`No pending file handle with ID ${hostHandleId}`);\n }\n pendingFileHandles.delete(hostHandleId);\n return {\n kind: \"file\" as const,\n name: pending.name,\n hostHandle: pending.handle,\n };\n },\n properties: {\n kind: {\n get(this: FileSystemFileHandleState) {\n return \"file\";\n },\n },\n name: {\n get(this: FileSystemFileHandleState) {\n return this.name;\n },\n },\n },\n methods: {\n async getFile(this: FileSystemFileHandleState): Promise<object> {\n const file = await this.hostHandle.getFile();\n\n // Convert native File to our internal File representation\n const buffer = await file.arrayBuffer();\n const data = new Uint8Array(buffer);\n\n return {\n parts: [data],\n type: file.type,\n size: file.size,\n name: file.name,\n lastModified: file.lastModified,\n webkitRelativePath: \"\",\n // Include methods that will be recognized\n async text() {\n return new TextDecoder().decode(data);\n },\n async arrayBuffer() {\n return buffer;\n },\n async bytes() {\n return data;\n },\n };\n },\n async _createWritableInternal(\n this: FileSystemFileHandleState,\n options?: unknown\n ): Promise<{ __writableStreamId: number }> {\n const opts = options as { keepExistingData?: boolean } | undefined;\n const hostStream = await this.hostHandle.createWritable({\n keepExistingData: opts?.keepExistingData,\n });\n\n return { __writableStreamId: registerHostWritableStream(hostStream) };\n },\n async isSameEntry(\n this: FileSystemFileHandleState,\n other: unknown\n ): Promise<boolean> {\n if (!other || typeof other !== \"object\") {\n return false;\n }\n const otherHandle = other as FileSystemFileHandleState;\n return this.hostHandle === otherHandle.hostHandle;\n },\n },\n });\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE4B,IAA5B;AAIA,IAAI,mBAAmB;AAChB,IAAM,qBAAqB,IAAI;AACtC,IAAI,uBAAuB;AACpB,IAAM,yBAAyB,IAAI;AAEnC,SAAS,sBAAsB,CAAC,QAAgC;AAAA,EACrE,MAAM,KAAK;AAAA,EACX,mBAAmB,IAAI,IAAI,EAAE,QAAQ,MAAM,OAAO,KAAK,CAAC;AAAA,EACxD,OAAO;AAAA;AAGF,SAAS,0BAA0B,CAAC,QAAwC;AAAA,EACjF,MAAM,KAAK;AAAA,EACX,uBAAuB,IAAI,IAAI,MAAM;AAAA,EACrC,OAAO;AAAA;AAMF,SAAS,+BAA+B,CAC7C,SACA,UACe;AAAA,EACf,OAAO,gCAAuC,SAAS,UAAU;AAAA,IAC/D,MAAM;AAAA,IACN,WAAW,CAAC,SAAS;AAAA,MACnB,MAAM,eAAe,KAAK;AAAA,MAC1B,MAAM,UAAU,mBAAmB,IAAI,YAAY;AAAA,MACnD,IAAI,CAAC,SAAS;AAAA,QACZ,MAAM,IAAI,MAAM,kCAAkC,cAAc;AAAA,MAClE;AAAA,MACA,mBAAmB,OAAO,YAAY;AAAA,MACtC,OAAO;AAAA,QACL,MAAM;AAAA,QACN,MAAM,QAAQ;AAAA,QACd,YAAY,QAAQ;AAAA,MACtB;AAAA;AAAA,IAEF,YAAY;AAAA,MACV,MAAM;AAAA,QACJ,GAAG,GAAkC;AAAA,UACnC,OAAO;AAAA;AAAA,MAEX;AAAA,MACA,MAAM;AAAA,QACJ,GAAG,GAAkC;AAAA,UACnC,OAAO,KAAK;AAAA;AAAA,MAEhB;AAAA,IACF;AAAA,IACA,SAAS;AAAA,WACD,QAAO,GAAmD;AAAA,QAC9D,MAAM,OAAO,MAAM,KAAK,WAAW,QAAQ;AAAA,QAG3C,MAAM,SAAS,MAAM,KAAK,YAAY;AAAA,QACtC,MAAM,OAAO,IAAI,WAAW,MAAM;AAAA,QAElC,OAAO;AAAA,UACL,OAAO,CAAC,IAAI;AAAA,UACZ,MAAM,KAAK;AAAA,UACX,MAAM,KAAK;AAAA,UACX,MAAM,KAAK;AAAA,UACX,cAAc,KAAK;AAAA,UACnB,oBAAoB;AAAA,eAEd,KAAI,GAAG;AAAA,YACX,OAAO,IAAI,YAAY,EAAE,OAAO,IAAI;AAAA;AAAA,eAEhC,YAAW,GAAG;AAAA,YAClB,OAAO;AAAA;AAAA,eAEH,MAAK,GAAG;AAAA,YACZ,OAAO;AAAA;AAAA,QAEX;AAAA;AAAA,WAEI,wBAAuB,CAE3B,SACyC;AAAA,QACzC,MAAM,OAAO;AAAA,QACb,MAAM,aAAa,MAAM,KAAK,WAAW,eAAe;AAAA,UACtD,kBAAkB,MAAM;AAAA,QAC1B,CAAC;AAAA,QAED,OAAO,EAAE,oBAAoB,2BAA2B,UAAU,EAAE;AAAA;AAAA,WAEhE,YAAW,CAEf,OACkB;AAAA,QAClB,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU;AAAA,UACvC,OAAO;AAAA,QACT;AAAA,QACA,MAAM,cAAc;AAAA,QACpB,OAAO,KAAK,eAAe,YAAY;AAAA;AAAA,IAE3C;AAAA,EACF,CAAC;AAAA;",
|
|
8
|
+
"debugId": "03934374EFF6363C64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/fs/src/index.ts
|
|
31
|
+
var exports_src = {};
|
|
32
|
+
__export(exports_src, {
|
|
33
|
+
setupFs: () => import_setup.setupFs,
|
|
34
|
+
createNodeDirectoryHandle: () => import_node_adapter.createNodeDirectoryHandle,
|
|
35
|
+
createMemoryDirectoryHandle: () => import_memory_adapter.createMemoryDirectoryHandle
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(exports_src);
|
|
38
|
+
var import_setup = require("./setup.ts");
|
|
39
|
+
var import_node_adapter = require("./node-adapter.ts");
|
|
40
|
+
var import_memory_adapter = require("./memory-adapter.ts");
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
//# debugId=A9E29D78C7B0FEDC64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export { setupFs } from \"./setup.ts\";\nexport { createNodeDirectoryHandle } from \"./node-adapter.ts\";\nexport { createMemoryDirectoryHandle } from \"./memory-adapter.ts\";\n\nexport type {\n SetupFsOptions,\n FsHandle,\n HostDirectoryHandle,\n HostFileHandle,\n HostWritableFileStream,\n WriteParams,\n} from \"./types.ts\";\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAwB,IAAxB;AAC0C,IAA1C;AAC4C,IAA5C;",
|
|
8
|
+
"debugId": "A9E29D78C7B0FEDC64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|