@eidos.space/eidos-file 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEVELOPER_PLATFORM.md +49 -53
- package/README.md +66 -99
- package/dist/adapter-contract-B3p-48Yb.d.mts +1149 -0
- package/dist/adapter-contract-B3p-48Yb.d.mts.map +1 -0
- package/dist/better-sqlite3.d.mts +64 -3
- package/dist/better-sqlite3.d.mts.map +1 -1
- package/dist/better-sqlite3.mjs +387 -14
- package/dist/better-sqlite3.mjs.map +1 -1
- package/dist/browser.d.mts +4 -3
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.mjs +30 -11
- package/dist/browser.mjs.map +1 -1
- package/dist/csv-WEud-i_H.mjs +376 -0
- package/dist/csv-WEud-i_H.mjs.map +1 -0
- package/dist/csv.d.mts +1 -1
- package/dist/csv.d.mts.map +1 -1
- package/dist/csv.mjs +1 -248
- package/dist/index.d.mts +312 -18
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3237 -4
- package/dist/index.mjs.map +1 -0
- package/dist/runtime-CMdfE7Gx.mjs +5476 -0
- package/dist/runtime-CMdfE7Gx.mjs.map +1 -0
- package/dist/runtime-DCo5E0Kr.d.mts +668 -0
- package/dist/runtime-DCo5E0Kr.d.mts.map +1 -0
- package/dist/select-options-DihMTuoa.mjs +518 -0
- package/dist/select-options-DihMTuoa.mjs.map +1 -0
- package/dist/sqlite-wasm-B86yaLG6.mjs +2000 -0
- package/dist/sqlite-wasm-B86yaLG6.mjs.map +1 -0
- package/dist/temporal-CVzLU63l.d.mts +517 -0
- package/dist/temporal-CVzLU63l.d.mts.map +1 -0
- package/package.json +2 -3
- package/dist/csv.mjs.map +0 -1
- package/dist/host-CqP1MeMK.d.mts +0 -213
- package/dist/host-CqP1MeMK.d.mts.map +0 -1
- package/dist/host-D5kZAhga.mjs +0 -478
- package/dist/host-D5kZAhga.mjs.map +0 -1
- package/dist/relation-values-B0JhHBjZ.mjs +0 -232
- package/dist/relation-values-B0JhHBjZ.mjs.map +0 -1
- package/dist/runtime-C3bstvB8.d.mts +0 -465
- package/dist/runtime-C3bstvB8.d.mts.map +0 -1
- package/dist/runtime-CWC5y95G.mjs +0 -2907
- package/dist/runtime-CWC5y95G.mjs.map +0 -1
package/dist/host-D5kZAhga.mjs
DELETED
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
import { C as EIDOS_FILE_EXTENSION, D as EIDOS_FILE_MIME_TYPE, w as EIDOS_FILE_FORMAT } from "./runtime-CWC5y95G.mjs";
|
|
2
|
-
//#region src/data-source.ts
|
|
3
|
-
function eidosFileSnapshot(runtime, path) {
|
|
4
|
-
return {
|
|
5
|
-
path,
|
|
6
|
-
metadata: runtime.info(),
|
|
7
|
-
tables: runtime.listTables().map((table) => ({
|
|
8
|
-
table,
|
|
9
|
-
fields: runtime.listFields(table.id),
|
|
10
|
-
views: runtime.listViews(table.id),
|
|
11
|
-
rowCount: runtime.countRows(table.id)
|
|
12
|
-
}))
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/** Adapts the synchronous core runtime to the public async view contract. */
|
|
16
|
-
var EidosFileRuntimeDataSource = class {
|
|
17
|
-
constructor(runtime, path) {
|
|
18
|
-
this.runtime = runtime;
|
|
19
|
-
this.path = path;
|
|
20
|
-
}
|
|
21
|
-
async getSnapshot() {
|
|
22
|
-
return eidosFileSnapshot(this.runtime, this.path);
|
|
23
|
-
}
|
|
24
|
-
async getPage(tableId, offset, limit, query, totalHint, cursor, projection) {
|
|
25
|
-
return this.runtime.getRowPage(tableId, offset, limit, query, totalHint, cursor, projection);
|
|
26
|
-
}
|
|
27
|
-
async getRow(tableId, rowId) {
|
|
28
|
-
return this.runtime.getRow(tableId, rowId);
|
|
29
|
-
}
|
|
30
|
-
async getGroupCounts(tableId, columnName, query) {
|
|
31
|
-
return this.runtime.countRowsByField(tableId, columnName, query);
|
|
32
|
-
}
|
|
33
|
-
async calculateColumnStats(tableId, configs, query) {
|
|
34
|
-
return this.runtime.calculateColumnStats(tableId, configs, query);
|
|
35
|
-
}
|
|
36
|
-
async insertRow(tableId, row) {
|
|
37
|
-
return this.mutationResult(tableId, this.runtime.insertRow(tableId, row));
|
|
38
|
-
}
|
|
39
|
-
async updateRow(tableId, rowId, changes) {
|
|
40
|
-
return this.mutationResult(tableId, this.runtime.updateRow(tableId, rowId, changes));
|
|
41
|
-
}
|
|
42
|
-
async deleteRowRanges(tableId, ranges, query) {
|
|
43
|
-
const deletedCount = this.runtime.deleteRowRanges(tableId, ranges, query);
|
|
44
|
-
return this.deleteResult(tableId, deletedCount);
|
|
45
|
-
}
|
|
46
|
-
async deleteRows(tableId, rowIds) {
|
|
47
|
-
return this.deleteResult(tableId, this.runtime.deleteRows(tableId, rowIds).length);
|
|
48
|
-
}
|
|
49
|
-
async updateField(tableId, columnName, changes) {
|
|
50
|
-
this.runtime.updateField(tableId, columnName, changes);
|
|
51
|
-
return this.getSnapshot();
|
|
52
|
-
}
|
|
53
|
-
async addField(tableId, field, placement) {
|
|
54
|
-
this.runtime.addField(tableId, field, placement);
|
|
55
|
-
return this.getSnapshot();
|
|
56
|
-
}
|
|
57
|
-
async deleteField(tableId, columnName) {
|
|
58
|
-
this.runtime.deleteField(tableId, columnName);
|
|
59
|
-
return this.getSnapshot();
|
|
60
|
-
}
|
|
61
|
-
async createTable(input) {
|
|
62
|
-
this.runtime.createTable(input);
|
|
63
|
-
return this.getSnapshot();
|
|
64
|
-
}
|
|
65
|
-
async createView(tableId, input) {
|
|
66
|
-
this.runtime.createView(tableId, input);
|
|
67
|
-
return this.getSnapshot();
|
|
68
|
-
}
|
|
69
|
-
async duplicateView(viewId, name) {
|
|
70
|
-
this.runtime.duplicateView(viewId, name);
|
|
71
|
-
return this.getSnapshot();
|
|
72
|
-
}
|
|
73
|
-
async deleteView(viewId) {
|
|
74
|
-
this.runtime.deleteView(viewId);
|
|
75
|
-
return this.getSnapshot();
|
|
76
|
-
}
|
|
77
|
-
async reorderViews(tableId, viewIds) {
|
|
78
|
-
this.runtime.reorderViews(tableId, viewIds);
|
|
79
|
-
return this.getSnapshot();
|
|
80
|
-
}
|
|
81
|
-
async updateView(viewId, changes) {
|
|
82
|
-
this.runtime.updateView(viewId, changes);
|
|
83
|
-
return this.getSnapshot();
|
|
84
|
-
}
|
|
85
|
-
mutationResult(tableId, row) {
|
|
86
|
-
return {
|
|
87
|
-
tableId,
|
|
88
|
-
row,
|
|
89
|
-
rowCount: this.runtime.countRows(tableId),
|
|
90
|
-
revision: this.runtime.info().updatedAt
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
deleteResult(tableId, deletedCount) {
|
|
94
|
-
return {
|
|
95
|
-
tableId,
|
|
96
|
-
deletedCount,
|
|
97
|
-
rowCount: this.runtime.countRows(tableId),
|
|
98
|
-
revision: this.runtime.info().updatedAt
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/host.ts
|
|
104
|
-
var EidosFileHostError = class extends Error {
|
|
105
|
-
constructor(code, message, conflict, cause) {
|
|
106
|
-
super(message);
|
|
107
|
-
this.code = code;
|
|
108
|
-
this.conflict = conflict;
|
|
109
|
-
this.cause = cause;
|
|
110
|
-
this.name = "EidosFileHostError";
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const initialState = {
|
|
114
|
-
phase: "idle",
|
|
115
|
-
descriptor: null,
|
|
116
|
-
permission: "unavailable",
|
|
117
|
-
capabilities: null,
|
|
118
|
-
source: null,
|
|
119
|
-
snapshot: null,
|
|
120
|
-
dirty: false,
|
|
121
|
-
error: null,
|
|
122
|
-
conflict: null,
|
|
123
|
-
recoveryAvailable: false
|
|
124
|
-
};
|
|
125
|
-
var EidosFileSession = class {
|
|
126
|
-
state = initialState;
|
|
127
|
-
handle = null;
|
|
128
|
-
document = null;
|
|
129
|
-
closePromise = null;
|
|
130
|
-
listeners = /* @__PURE__ */ new Set();
|
|
131
|
-
constructor(runtime, recovery) {
|
|
132
|
-
this.runtime = runtime;
|
|
133
|
-
this.recovery = recovery;
|
|
134
|
-
}
|
|
135
|
-
getState = () => this.state;
|
|
136
|
-
subscribe = (listener) => {
|
|
137
|
-
this.listeners.add(listener);
|
|
138
|
-
return () => this.listeners.delete(listener);
|
|
139
|
-
};
|
|
140
|
-
async open(handle, options) {
|
|
141
|
-
this.assertOpen();
|
|
142
|
-
const previousState = this.state;
|
|
143
|
-
const previousDocument = this.document;
|
|
144
|
-
const previousHandle = this.handle;
|
|
145
|
-
this.setState({
|
|
146
|
-
...initialState,
|
|
147
|
-
phase: "opening",
|
|
148
|
-
capabilities: handle.capabilities
|
|
149
|
-
});
|
|
150
|
-
let document = null;
|
|
151
|
-
try {
|
|
152
|
-
const read = await handle.read(options);
|
|
153
|
-
document = await this.runtime.open(read, options);
|
|
154
|
-
const snapshot = await document.source.getSnapshot();
|
|
155
|
-
const permission = await handle.permission();
|
|
156
|
-
const recoveryAvailable = Boolean(this.recovery && await this.recovery.load(read.descriptor.id));
|
|
157
|
-
this.document = document;
|
|
158
|
-
this.handle = handle;
|
|
159
|
-
document = null;
|
|
160
|
-
this.setState({
|
|
161
|
-
phase: "ready",
|
|
162
|
-
descriptor: {
|
|
163
|
-
...read.descriptor,
|
|
164
|
-
metadata: snapshot.metadata
|
|
165
|
-
},
|
|
166
|
-
permission,
|
|
167
|
-
capabilities: handle.capabilities,
|
|
168
|
-
source: this.document.source,
|
|
169
|
-
snapshot,
|
|
170
|
-
dirty: false,
|
|
171
|
-
error: null,
|
|
172
|
-
conflict: null,
|
|
173
|
-
recoveryAvailable
|
|
174
|
-
});
|
|
175
|
-
await settleResources(previousDocument, previousHandle === handle ? null : previousHandle);
|
|
176
|
-
return snapshot;
|
|
177
|
-
} catch (cause) {
|
|
178
|
-
await settleResources(document, previousHandle === handle ? null : handle);
|
|
179
|
-
const error = hostError("read-failed", "Unable to open Eidos File", cause);
|
|
180
|
-
this.setState(previousDocument && previousState.source ? {
|
|
181
|
-
...previousState,
|
|
182
|
-
phase: "error",
|
|
183
|
-
error,
|
|
184
|
-
conflict: null
|
|
185
|
-
} : {
|
|
186
|
-
...initialState,
|
|
187
|
-
phase: "error",
|
|
188
|
-
error
|
|
189
|
-
});
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async refresh() {
|
|
194
|
-
const snapshot = await this.requireDocument().source.getSnapshot();
|
|
195
|
-
this.setState({
|
|
196
|
-
...this.state,
|
|
197
|
-
snapshot
|
|
198
|
-
});
|
|
199
|
-
return snapshot;
|
|
200
|
-
}
|
|
201
|
-
markDirty(snapshot) {
|
|
202
|
-
this.requireDocument();
|
|
203
|
-
this.setState({
|
|
204
|
-
...this.state,
|
|
205
|
-
phase: "dirty",
|
|
206
|
-
dirty: true,
|
|
207
|
-
snapshot: snapshot ?? this.state.snapshot,
|
|
208
|
-
error: null,
|
|
209
|
-
conflict: null
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
async checkpoint() {
|
|
213
|
-
const document = this.requireDocument();
|
|
214
|
-
if (!this.recovery || !this.state.descriptor || !this.state.dirty) return null;
|
|
215
|
-
const bytes = await document.exportBytes();
|
|
216
|
-
const recovery = {
|
|
217
|
-
id: this.state.descriptor.id,
|
|
218
|
-
descriptor: this.state.descriptor,
|
|
219
|
-
bytes,
|
|
220
|
-
updatedAt: Date.now()
|
|
221
|
-
};
|
|
222
|
-
await this.recovery.save(recovery);
|
|
223
|
-
this.setState({
|
|
224
|
-
...this.state,
|
|
225
|
-
recoveryAvailable: true
|
|
226
|
-
});
|
|
227
|
-
return recovery;
|
|
228
|
-
}
|
|
229
|
-
async save(options = {}) {
|
|
230
|
-
const document = this.requireDocument();
|
|
231
|
-
if (!this.handle?.write || !this.state.capabilities?.write) throw new EidosFileHostError("permission-denied", "This host cannot write to the open Eidos File. Use Save As instead.");
|
|
232
|
-
const permission = await this.requestWritePermission();
|
|
233
|
-
if (permission !== "granted") throw new EidosFileHostError("permission-denied", "Write permission was not granted for this Eidos File.");
|
|
234
|
-
const expectedRevision = this.state.descriptor?.revision;
|
|
235
|
-
this.setState({
|
|
236
|
-
...this.state,
|
|
237
|
-
phase: "saving",
|
|
238
|
-
error: null,
|
|
239
|
-
conflict: null
|
|
240
|
-
});
|
|
241
|
-
try {
|
|
242
|
-
const bytes = await document.exportBytes({ signal: options.signal });
|
|
243
|
-
const descriptor = await this.handle.write(bytes, {
|
|
244
|
-
...options,
|
|
245
|
-
expectedRevision
|
|
246
|
-
});
|
|
247
|
-
const snapshot = await document.source.getSnapshot();
|
|
248
|
-
await this.recovery?.delete(descriptor.id);
|
|
249
|
-
this.setState({
|
|
250
|
-
...this.state,
|
|
251
|
-
phase: "ready",
|
|
252
|
-
descriptor: {
|
|
253
|
-
...descriptor,
|
|
254
|
-
metadata: snapshot.metadata
|
|
255
|
-
},
|
|
256
|
-
permission,
|
|
257
|
-
snapshot,
|
|
258
|
-
dirty: false,
|
|
259
|
-
error: null,
|
|
260
|
-
conflict: null,
|
|
261
|
-
recoveryAvailable: false
|
|
262
|
-
});
|
|
263
|
-
return descriptor;
|
|
264
|
-
} catch (cause) {
|
|
265
|
-
if (cause instanceof EidosFileHostError && cause.code === "conflict") {
|
|
266
|
-
this.setState({
|
|
267
|
-
...this.state,
|
|
268
|
-
phase: "conflict",
|
|
269
|
-
dirty: true,
|
|
270
|
-
error: cause,
|
|
271
|
-
conflict: cause.conflict ?? null
|
|
272
|
-
});
|
|
273
|
-
throw cause;
|
|
274
|
-
}
|
|
275
|
-
const error = hostError("write-failed", "Unable to save Eidos File", cause);
|
|
276
|
-
this.setState({
|
|
277
|
-
...this.state,
|
|
278
|
-
phase: "error",
|
|
279
|
-
dirty: true,
|
|
280
|
-
error
|
|
281
|
-
});
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async saveAs(handle) {
|
|
286
|
-
const document = this.requireDocument();
|
|
287
|
-
if (!handle.write) throw new EidosFileHostError("permission-denied", "The selected destination is not writable.");
|
|
288
|
-
const permission = await requestHandleWritePermission(handle);
|
|
289
|
-
if (permission !== "granted") throw new EidosFileHostError("permission-denied", "Write permission was not granted for the selected destination.");
|
|
290
|
-
const bytes = await document.exportBytes();
|
|
291
|
-
const descriptor = await handle.write(bytes, { force: true });
|
|
292
|
-
const previousHandle = this.handle;
|
|
293
|
-
const previousDescriptorId = this.state.descriptor?.id;
|
|
294
|
-
this.handle = handle;
|
|
295
|
-
const snapshot = await document.source.getSnapshot();
|
|
296
|
-
this.setState({
|
|
297
|
-
...this.state,
|
|
298
|
-
phase: "ready",
|
|
299
|
-
descriptor: {
|
|
300
|
-
...descriptor,
|
|
301
|
-
metadata: snapshot.metadata
|
|
302
|
-
},
|
|
303
|
-
permission,
|
|
304
|
-
capabilities: handle.capabilities,
|
|
305
|
-
snapshot,
|
|
306
|
-
dirty: false,
|
|
307
|
-
error: null,
|
|
308
|
-
conflict: null,
|
|
309
|
-
recoveryAvailable: false
|
|
310
|
-
});
|
|
311
|
-
await Promise.allSettled([...previousHandle && previousHandle !== handle ? [Promise.resolve().then(() => previousHandle.close?.())] : [], ...this.recovery ? [this.recovery.delete(previousDescriptorId ?? descriptor.id)] : []]);
|
|
312
|
-
return descriptor;
|
|
313
|
-
}
|
|
314
|
-
async reload(options) {
|
|
315
|
-
const previousDocument = this.requireDocument();
|
|
316
|
-
if (!this.handle) throw new EidosFileHostError("closed", "No file is open");
|
|
317
|
-
const handle = this.handle;
|
|
318
|
-
let replacement = null;
|
|
319
|
-
try {
|
|
320
|
-
const read = await handle.read(options);
|
|
321
|
-
replacement = await this.runtime.open(read, options);
|
|
322
|
-
const snapshot = await replacement.source.getSnapshot();
|
|
323
|
-
this.document = replacement;
|
|
324
|
-
replacement = null;
|
|
325
|
-
this.setState({
|
|
326
|
-
...this.state,
|
|
327
|
-
phase: "ready",
|
|
328
|
-
descriptor: {
|
|
329
|
-
...read.descriptor,
|
|
330
|
-
metadata: snapshot.metadata
|
|
331
|
-
},
|
|
332
|
-
source: this.document.source,
|
|
333
|
-
snapshot,
|
|
334
|
-
dirty: false,
|
|
335
|
-
error: null,
|
|
336
|
-
conflict: null,
|
|
337
|
-
recoveryAvailable: false
|
|
338
|
-
});
|
|
339
|
-
await Promise.allSettled([Promise.resolve().then(() => previousDocument.close()), ...this.recovery ? [this.recovery.delete(read.descriptor.id)] : []]);
|
|
340
|
-
return snapshot;
|
|
341
|
-
} catch (cause) {
|
|
342
|
-
await settleResources(replacement);
|
|
343
|
-
const error = hostError("read-failed", "Unable to reload Eidos File", cause);
|
|
344
|
-
this.setState({
|
|
345
|
-
...this.state,
|
|
346
|
-
phase: "error",
|
|
347
|
-
error,
|
|
348
|
-
conflict: null
|
|
349
|
-
});
|
|
350
|
-
throw error;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
async restore(recovery) {
|
|
354
|
-
this.assertOpen();
|
|
355
|
-
const previousDocument = this.document;
|
|
356
|
-
let document = null;
|
|
357
|
-
try {
|
|
358
|
-
document = await this.runtime.open({
|
|
359
|
-
descriptor: recovery.descriptor,
|
|
360
|
-
bytes: copyArrayBuffer(recovery.bytes)
|
|
361
|
-
});
|
|
362
|
-
const snapshot = await document.source.getSnapshot();
|
|
363
|
-
this.document = document;
|
|
364
|
-
document = null;
|
|
365
|
-
this.setState({
|
|
366
|
-
...this.state,
|
|
367
|
-
phase: "dirty",
|
|
368
|
-
descriptor: {
|
|
369
|
-
...recovery.descriptor,
|
|
370
|
-
metadata: snapshot.metadata
|
|
371
|
-
},
|
|
372
|
-
source: this.document.source,
|
|
373
|
-
snapshot,
|
|
374
|
-
dirty: true,
|
|
375
|
-
error: null,
|
|
376
|
-
conflict: null,
|
|
377
|
-
recoveryAvailable: true
|
|
378
|
-
});
|
|
379
|
-
await settleResources(previousDocument);
|
|
380
|
-
return snapshot;
|
|
381
|
-
} catch (cause) {
|
|
382
|
-
await settleResources(document);
|
|
383
|
-
const error = hostError("read-failed", "Unable to restore Eidos File recovery data", cause);
|
|
384
|
-
this.setState({
|
|
385
|
-
...this.state,
|
|
386
|
-
phase: "error",
|
|
387
|
-
error,
|
|
388
|
-
conflict: null
|
|
389
|
-
});
|
|
390
|
-
throw error;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
async close() {
|
|
394
|
-
if (this.state.phase === "closed") return;
|
|
395
|
-
if (this.closePromise) return this.closePromise;
|
|
396
|
-
this.closePromise = this.closeResources();
|
|
397
|
-
return this.closePromise;
|
|
398
|
-
}
|
|
399
|
-
async closeResources() {
|
|
400
|
-
const document = this.document;
|
|
401
|
-
const handle = this.handle;
|
|
402
|
-
this.document = null;
|
|
403
|
-
this.handle = null;
|
|
404
|
-
const results = await settleResources(document, handle);
|
|
405
|
-
this.setState({
|
|
406
|
-
...initialState,
|
|
407
|
-
phase: "closed"
|
|
408
|
-
});
|
|
409
|
-
this.listeners.clear();
|
|
410
|
-
const failure = results.find((result) => result.status === "rejected");
|
|
411
|
-
if (failure) throw failure.reason;
|
|
412
|
-
}
|
|
413
|
-
async requestWritePermission() {
|
|
414
|
-
if (!this.handle) return "unavailable";
|
|
415
|
-
const requested = await requestHandleWritePermission(this.handle);
|
|
416
|
-
this.setState({
|
|
417
|
-
...this.state,
|
|
418
|
-
permission: requested
|
|
419
|
-
});
|
|
420
|
-
return requested;
|
|
421
|
-
}
|
|
422
|
-
assertOpen() {
|
|
423
|
-
if (this.state.phase === "closed") throw new EidosFileHostError("closed", "The Eidos File session is closed");
|
|
424
|
-
}
|
|
425
|
-
requireDocument() {
|
|
426
|
-
this.assertOpen();
|
|
427
|
-
if (!this.document || !this.state.source) throw new EidosFileHostError("closed", "No Eidos File is open");
|
|
428
|
-
return this.document;
|
|
429
|
-
}
|
|
430
|
-
setState(state) {
|
|
431
|
-
this.state = state;
|
|
432
|
-
for (const listener of this.listeners) listener();
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
const eidosFileTypeHandler = {
|
|
436
|
-
id: EIDOS_FILE_FORMAT,
|
|
437
|
-
label: "Eidos File",
|
|
438
|
-
extensions: [EIDOS_FILE_EXTENSION],
|
|
439
|
-
mimeTypes: [EIDOS_FILE_MIME_TYPE],
|
|
440
|
-
accepts: ({ name, mimeType }) => mimeType === "application/vnd.eidos+sqlite3" || name.toLowerCase().endsWith(".eidos")
|
|
441
|
-
};
|
|
442
|
-
var EidosFileHandlerRegistry = class {
|
|
443
|
-
handlers = /* @__PURE__ */ new Map();
|
|
444
|
-
constructor(handlers = [eidosFileTypeHandler]) {
|
|
445
|
-
for (const handler of handlers) this.register(handler);
|
|
446
|
-
}
|
|
447
|
-
register(handler) {
|
|
448
|
-
if (this.handlers.has(handler.id)) throw new Error(`Duplicate Eidos File handler: ${handler.id}`);
|
|
449
|
-
this.handlers.set(handler.id, handler);
|
|
450
|
-
return () => this.handlers.delete(handler.id);
|
|
451
|
-
}
|
|
452
|
-
match(descriptor) {
|
|
453
|
-
return [...this.handlers.values()].find((handler) => handler.accepts(descriptor)) ?? null;
|
|
454
|
-
}
|
|
455
|
-
list() {
|
|
456
|
-
return [...this.handlers.values()];
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
function hostError(code, message, cause) {
|
|
460
|
-
return cause instanceof EidosFileHostError ? cause : new EidosFileHostError(code, message, void 0, cause);
|
|
461
|
-
}
|
|
462
|
-
function copyArrayBuffer(bytes) {
|
|
463
|
-
const copy = new Uint8Array(bytes.byteLength);
|
|
464
|
-
copy.set(bytes);
|
|
465
|
-
return copy.buffer;
|
|
466
|
-
}
|
|
467
|
-
async function requestHandleWritePermission(handle) {
|
|
468
|
-
const current = await handle.permission();
|
|
469
|
-
if (current === "granted" || !handle.requestPermission) return current;
|
|
470
|
-
return handle.requestPermission();
|
|
471
|
-
}
|
|
472
|
-
function settleResources(document, handle) {
|
|
473
|
-
return Promise.allSettled([...document ? [Promise.resolve().then(async () => document.close())] : [], ...handle?.close ? [Promise.resolve().then(async () => handle.close?.())] : []]);
|
|
474
|
-
}
|
|
475
|
-
//#endregion
|
|
476
|
-
export { EidosFileRuntimeDataSource as a, eidosFileTypeHandler as i, EidosFileHostError as n, eidosFileSnapshot as o, EidosFileSession as r, EidosFileHandlerRegistry as t };
|
|
477
|
-
|
|
478
|
-
//# sourceMappingURL=host-D5kZAhga.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"host-D5kZAhga.mjs","names":[],"sources":["../src/data-source.ts","../src/host.ts"],"sourcesContent":["import type { EidosFileRuntime } from \"./runtime\"\nimport type {\n CreateEidosFileFieldInput,\n CreateEidosFileTableInput,\n CreateEidosFileViewInput,\n EidosFileColumnStatConfig,\n EidosFileColumnStatResult,\n EidosFileFieldPlacement,\n EidosFileRow,\n EidosFileRowGroupCount,\n EidosFileRowMutationResult,\n EidosFileRowPage,\n EidosFileRowPageProjection,\n EidosFileRowQuery,\n EidosFileRowRange,\n EidosFileRowsDeleteResult,\n EidosFileSnapshot,\n UpdateEidosFileFieldInput,\n UpdateEidosFileViewInput,\n} from \"./types\"\n\n/**\n * Async, host-neutral data contract consumed by Eidos File views.\n *\n * A host may implement this with a Worker, an Electron bridge, a remote\n * process, or the browser runtime. Views never receive a SQLite connection,\n * native file handle, router, or application store.\n */\nexport interface EidosFileDataSource {\n getSnapshot(): Promise<EidosFileSnapshot>\n getPage(\n tableId: string,\n offset: number,\n limit: number,\n query: EidosFileRowQuery,\n totalHint?: number,\n cursor?: string,\n projection?: EidosFileRowPageProjection\n ): Promise<EidosFileRowPage>\n getRow?(tableId: string, rowId: string): Promise<EidosFileRow | null>\n getGroupCounts?(\n tableId: string,\n columnName: string,\n query: EidosFileRowQuery\n ): Promise<EidosFileRowGroupCount[]>\n calculateColumnStats(\n tableId: string,\n configs: EidosFileColumnStatConfig[],\n query: EidosFileRowQuery\n ): Promise<EidosFileColumnStatResult[]>\n insertRow(\n tableId: string,\n row: EidosFileRow\n ): Promise<EidosFileRowMutationResult>\n updateRow(\n tableId: string,\n rowId: string,\n changes: EidosFileRow\n ): Promise<EidosFileRowMutationResult>\n deleteRowRanges(\n tableId: string,\n ranges: EidosFileRowRange[],\n query: EidosFileRowQuery\n ): Promise<EidosFileRowsDeleteResult>\n deleteRows(\n tableId: string,\n rowIds: string[]\n ): Promise<EidosFileRowsDeleteResult>\n updateField(\n tableId: string,\n columnName: string,\n changes: UpdateEidosFileFieldInput\n ): Promise<EidosFileSnapshot>\n addField(\n tableId: string,\n field: CreateEidosFileFieldInput,\n placement?: EidosFileFieldPlacement\n ): Promise<EidosFileSnapshot>\n deleteField(tableId: string, columnName: string): Promise<EidosFileSnapshot>\n createTable(input: CreateEidosFileTableInput): Promise<EidosFileSnapshot>\n createView(\n tableId: string,\n input: CreateEidosFileViewInput\n ): Promise<EidosFileSnapshot>\n duplicateView(viewId: string, name?: string): Promise<EidosFileSnapshot>\n deleteView(viewId: string): Promise<EidosFileSnapshot>\n reorderViews(tableId: string, viewIds: string[]): Promise<EidosFileSnapshot>\n updateView(\n viewId: string,\n changes: UpdateEidosFileViewInput\n ): Promise<EidosFileSnapshot>\n}\n\nexport function eidosFileSnapshot(\n runtime: EidosFileRuntime,\n path: string\n): EidosFileSnapshot {\n return {\n path,\n metadata: runtime.info(),\n tables: runtime.listTables().map((table) => ({\n table,\n fields: runtime.listFields(table.id),\n views: runtime.listViews(table.id),\n rowCount: runtime.countRows(table.id),\n })),\n }\n}\n\n/** Adapts the synchronous core runtime to the public async view contract. */\nexport class EidosFileRuntimeDataSource implements EidosFileDataSource {\n constructor(\n readonly runtime: EidosFileRuntime,\n readonly path: string\n ) {}\n\n async getSnapshot(): Promise<EidosFileSnapshot> {\n return eidosFileSnapshot(this.runtime, this.path)\n }\n\n async getPage(\n tableId: string,\n offset: number,\n limit: number,\n query: EidosFileRowQuery,\n totalHint?: number,\n cursor?: string,\n projection?: EidosFileRowPageProjection\n ): Promise<EidosFileRowPage> {\n return this.runtime.getRowPage(\n tableId,\n offset,\n limit,\n query,\n totalHint,\n cursor,\n projection\n )\n }\n\n async getRow(tableId: string, rowId: string): Promise<EidosFileRow | null> {\n return this.runtime.getRow(tableId, rowId)\n }\n\n async getGroupCounts(\n tableId: string,\n columnName: string,\n query: EidosFileRowQuery\n ): Promise<EidosFileRowGroupCount[]> {\n return this.runtime.countRowsByField(tableId, columnName, query)\n }\n\n async calculateColumnStats(\n tableId: string,\n configs: EidosFileColumnStatConfig[],\n query: EidosFileRowQuery\n ): Promise<EidosFileColumnStatResult[]> {\n return this.runtime.calculateColumnStats(tableId, configs, query)\n }\n\n async insertRow(\n tableId: string,\n row: EidosFileRow\n ): Promise<EidosFileRowMutationResult> {\n return this.mutationResult(tableId, this.runtime.insertRow(tableId, row))\n }\n\n async updateRow(\n tableId: string,\n rowId: string,\n changes: EidosFileRow\n ): Promise<EidosFileRowMutationResult> {\n return this.mutationResult(\n tableId,\n this.runtime.updateRow(tableId, rowId, changes)\n )\n }\n\n async deleteRowRanges(\n tableId: string,\n ranges: EidosFileRowRange[],\n query: EidosFileRowQuery\n ): Promise<EidosFileRowsDeleteResult> {\n const deletedCount = this.runtime.deleteRowRanges(tableId, ranges, query)\n return this.deleteResult(tableId, deletedCount)\n }\n\n async deleteRows(\n tableId: string,\n rowIds: string[]\n ): Promise<EidosFileRowsDeleteResult> {\n return this.deleteResult(\n tableId,\n this.runtime.deleteRows(tableId, rowIds).length\n )\n }\n\n async updateField(\n tableId: string,\n columnName: string,\n changes: UpdateEidosFileFieldInput\n ): Promise<EidosFileSnapshot> {\n this.runtime.updateField(tableId, columnName, changes)\n return this.getSnapshot()\n }\n\n async addField(\n tableId: string,\n field: CreateEidosFileFieldInput,\n placement?: EidosFileFieldPlacement\n ): Promise<EidosFileSnapshot> {\n this.runtime.addField(tableId, field, placement)\n return this.getSnapshot()\n }\n\n async deleteField(\n tableId: string,\n columnName: string\n ): Promise<EidosFileSnapshot> {\n this.runtime.deleteField(tableId, columnName)\n return this.getSnapshot()\n }\n\n async createTable(\n input: CreateEidosFileTableInput\n ): Promise<EidosFileSnapshot> {\n this.runtime.createTable(input)\n return this.getSnapshot()\n }\n\n async createView(\n tableId: string,\n input: CreateEidosFileViewInput\n ): Promise<EidosFileSnapshot> {\n this.runtime.createView(tableId, input)\n return this.getSnapshot()\n }\n\n async duplicateView(\n viewId: string,\n name?: string\n ): Promise<EidosFileSnapshot> {\n this.runtime.duplicateView(viewId, name)\n return this.getSnapshot()\n }\n\n async deleteView(viewId: string): Promise<EidosFileSnapshot> {\n this.runtime.deleteView(viewId)\n return this.getSnapshot()\n }\n\n async reorderViews(\n tableId: string,\n viewIds: string[]\n ): Promise<EidosFileSnapshot> {\n this.runtime.reorderViews(tableId, viewIds)\n return this.getSnapshot()\n }\n\n async updateView(\n viewId: string,\n changes: UpdateEidosFileViewInput\n ): Promise<EidosFileSnapshot> {\n this.runtime.updateView(viewId, changes)\n return this.getSnapshot()\n }\n\n private mutationResult(\n tableId: string,\n row: EidosFileRow\n ): EidosFileRowMutationResult {\n return {\n tableId,\n row,\n rowCount: this.runtime.countRows(tableId),\n revision: this.runtime.info().updatedAt,\n }\n }\n\n private deleteResult(\n tableId: string,\n deletedCount: number\n ): EidosFileRowsDeleteResult {\n return {\n tableId,\n deletedCount,\n rowCount: this.runtime.countRows(tableId),\n revision: this.runtime.info().updatedAt,\n }\n }\n}\n","import {\n EIDOS_FILE_EXTENSION,\n EIDOS_FILE_FORMAT,\n EIDOS_FILE_MIME_TYPE,\n} from \"./constants\"\nimport type { EidosFileDataSource } from \"./data-source\"\nimport type { EidosFileMetadata, EidosFileSnapshot } from \"./types\"\n\nexport type EidosFilePermissionState =\n | \"granted\"\n | \"prompt\"\n | \"denied\"\n | \"unavailable\"\n\nexport interface EidosFileHostCapabilities {\n read: true\n write: boolean\n saveAs: boolean\n recovery: boolean\n persistentFileAccess: boolean\n}\n\nexport interface EidosFileDescriptor {\n /** Stable for the lifetime of the host adapter, opaque to views. */\n id: string\n name: string\n format: typeof EIDOS_FILE_FORMAT\n mimeType: typeof EIDOS_FILE_MIME_TYPE\n size: number\n /** Adapter-owned compare-and-swap token. Never derive behavior from it. */\n revision: string\n lastModified?: number\n metadata?: EidosFileMetadata\n}\n\nexport interface EidosFileReadResult {\n descriptor: EidosFileDescriptor\n bytes: ArrayBuffer\n}\n\nexport interface EidosFileWriteOptions {\n expectedRevision?: string\n force?: boolean\n signal?: AbortSignal\n}\n\nexport interface EidosFileHandle {\n readonly capabilities: EidosFileHostCapabilities\n descriptor(): Promise<EidosFileDescriptor>\n permission(): Promise<EidosFilePermissionState>\n requestPermission?(): Promise<EidosFilePermissionState>\n read(options?: { signal?: AbortSignal }): Promise<EidosFileReadResult>\n write?(\n bytes: Uint8Array,\n options?: EidosFileWriteOptions\n ): Promise<EidosFileDescriptor>\n close?(): void | Promise<void>\n}\n\nexport interface EidosFileDocument {\n readonly source: EidosFileDataSource\n exportBytes(options?: { signal?: AbortSignal }): Promise<Uint8Array>\n close(): void | Promise<void>\n}\n\nexport interface EidosFileRuntimeAdapter {\n open(\n read: EidosFileReadResult,\n options?: { signal?: AbortSignal }\n ): Promise<EidosFileDocument>\n}\n\nexport interface EidosFileRecoverySnapshot {\n id: string\n descriptor: EidosFileDescriptor\n bytes: Uint8Array\n updatedAt: number\n}\n\nexport interface EidosFileRecoveryStore {\n load(id: string): Promise<EidosFileRecoverySnapshot | null>\n save(snapshot: EidosFileRecoverySnapshot): Promise<void>\n delete(id: string): Promise<void>\n}\n\nexport type EidosFileSessionPhase =\n | \"idle\"\n | \"opening\"\n | \"ready\"\n | \"dirty\"\n | \"saving\"\n | \"conflict\"\n | \"error\"\n | \"closed\"\n\nexport interface EidosFileConflict {\n expectedRevision: string\n actual: EidosFileDescriptor\n}\n\nexport interface EidosFileSessionState {\n phase: EidosFileSessionPhase\n descriptor: EidosFileDescriptor | null\n permission: EidosFilePermissionState\n capabilities: EidosFileHostCapabilities | null\n source: EidosFileDataSource | null\n snapshot: EidosFileSnapshot | null\n dirty: boolean\n error: Error | null\n conflict: EidosFileConflict | null\n recoveryAvailable: boolean\n}\n\nexport type EidosFileHostErrorCode =\n | \"closed\"\n | \"permission-denied\"\n | \"read-failed\"\n | \"write-failed\"\n | \"conflict\"\n\nexport class EidosFileHostError extends Error {\n constructor(\n readonly code: EidosFileHostErrorCode,\n message: string,\n readonly conflict?: EidosFileConflict,\n readonly cause?: unknown\n ) {\n super(message)\n this.name = \"EidosFileHostError\"\n }\n}\n\nconst initialState: EidosFileSessionState = {\n phase: \"idle\",\n descriptor: null,\n permission: \"unavailable\",\n capabilities: null,\n source: null,\n snapshot: null,\n dirty: false,\n error: null,\n conflict: null,\n recoveryAvailable: false,\n}\n\nexport class EidosFileSession {\n private state: EidosFileSessionState = initialState\n private handle: EidosFileHandle | null = null\n private document: EidosFileDocument | null = null\n private closePromise: Promise<void> | null = null\n private readonly listeners = new Set<() => void>()\n\n constructor(\n private readonly runtime: EidosFileRuntimeAdapter,\n private readonly recovery?: EidosFileRecoveryStore\n ) {}\n\n getState = (): EidosFileSessionState => this.state\n\n subscribe = (listener: () => void): (() => void) => {\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n async open(handle: EidosFileHandle, options?: { signal?: AbortSignal }) {\n this.assertOpen()\n const previousState = this.state\n const previousDocument = this.document\n const previousHandle = this.handle\n this.setState({\n ...initialState,\n phase: \"opening\",\n capabilities: handle.capabilities,\n })\n let document: EidosFileDocument | null = null\n try {\n const read = await handle.read(options)\n document = await this.runtime.open(read, options)\n const snapshot = await document.source.getSnapshot()\n const permission = await handle.permission()\n const recoveryAvailable = Boolean(\n this.recovery && (await this.recovery.load(read.descriptor.id))\n )\n this.document = document\n this.handle = handle\n document = null\n this.setState({\n phase: \"ready\",\n descriptor: { ...read.descriptor, metadata: snapshot.metadata },\n permission,\n capabilities: handle.capabilities,\n source: this.document.source,\n snapshot,\n dirty: false,\n error: null,\n conflict: null,\n recoveryAvailable,\n })\n await settleResources(\n previousDocument,\n previousHandle === handle ? null : previousHandle\n )\n return snapshot\n } catch (cause) {\n await settleResources(document, previousHandle === handle ? null : handle)\n const error = hostError(\"read-failed\", \"Unable to open Eidos File\", cause)\n this.setState(\n previousDocument && previousState.source\n ? { ...previousState, phase: \"error\", error, conflict: null }\n : { ...initialState, phase: \"error\", error }\n )\n throw error\n }\n }\n\n async refresh(): Promise<EidosFileSnapshot> {\n const document = this.requireDocument()\n const snapshot = await document.source.getSnapshot()\n this.setState({ ...this.state, snapshot })\n return snapshot\n }\n\n markDirty(snapshot?: EidosFileSnapshot): void {\n this.requireDocument()\n this.setState({\n ...this.state,\n phase: \"dirty\",\n dirty: true,\n snapshot: snapshot ?? this.state.snapshot,\n error: null,\n conflict: null,\n })\n }\n\n async checkpoint(): Promise<EidosFileRecoverySnapshot | null> {\n const document = this.requireDocument()\n if (!this.recovery || !this.state.descriptor || !this.state.dirty)\n return null\n const bytes = await document.exportBytes()\n const recovery: EidosFileRecoverySnapshot = {\n id: this.state.descriptor.id,\n descriptor: this.state.descriptor,\n bytes,\n updatedAt: Date.now(),\n }\n await this.recovery.save(recovery)\n this.setState({ ...this.state, recoveryAvailable: true })\n return recovery\n }\n\n async save(\n options: EidosFileWriteOptions = {}\n ): Promise<EidosFileDescriptor> {\n const document = this.requireDocument()\n if (!this.handle?.write || !this.state.capabilities?.write) {\n throw new EidosFileHostError(\n \"permission-denied\",\n \"This host cannot write to the open Eidos File. Use Save As instead.\"\n )\n }\n const permission = await this.requestWritePermission()\n if (permission !== \"granted\") {\n throw new EidosFileHostError(\n \"permission-denied\",\n \"Write permission was not granted for this Eidos File.\"\n )\n }\n const expectedRevision = this.state.descriptor?.revision\n this.setState({\n ...this.state,\n phase: \"saving\",\n error: null,\n conflict: null,\n })\n try {\n const bytes = await document.exportBytes({ signal: options.signal })\n const descriptor = await this.handle.write(bytes, {\n ...options,\n expectedRevision,\n })\n const snapshot = await document.source.getSnapshot()\n await this.recovery?.delete(descriptor.id)\n this.setState({\n ...this.state,\n phase: \"ready\",\n descriptor: { ...descriptor, metadata: snapshot.metadata },\n permission,\n snapshot,\n dirty: false,\n error: null,\n conflict: null,\n recoveryAvailable: false,\n })\n return descriptor\n } catch (cause) {\n if (cause instanceof EidosFileHostError && cause.code === \"conflict\") {\n this.setState({\n ...this.state,\n phase: \"conflict\",\n dirty: true,\n error: cause,\n conflict: cause.conflict ?? null,\n })\n throw cause\n }\n const error = hostError(\n \"write-failed\",\n \"Unable to save Eidos File\",\n cause\n )\n this.setState({ ...this.state, phase: \"error\", dirty: true, error })\n throw error\n }\n }\n\n async saveAs(handle: EidosFileHandle): Promise<EidosFileDescriptor> {\n const document = this.requireDocument()\n if (!handle.write) {\n throw new EidosFileHostError(\n \"permission-denied\",\n \"The selected destination is not writable.\"\n )\n }\n const permission = await requestHandleWritePermission(handle)\n if (permission !== \"granted\") {\n throw new EidosFileHostError(\n \"permission-denied\",\n \"Write permission was not granted for the selected destination.\"\n )\n }\n const bytes = await document.exportBytes()\n const descriptor = await handle.write(bytes, { force: true })\n const previousHandle = this.handle\n const previousDescriptorId = this.state.descriptor?.id\n this.handle = handle\n const snapshot = await document.source.getSnapshot()\n this.setState({\n ...this.state,\n phase: \"ready\",\n descriptor: { ...descriptor, metadata: snapshot.metadata },\n permission,\n capabilities: handle.capabilities,\n snapshot,\n dirty: false,\n error: null,\n conflict: null,\n recoveryAvailable: false,\n })\n await Promise.allSettled([\n ...(previousHandle && previousHandle !== handle\n ? [Promise.resolve().then(() => previousHandle.close?.())]\n : []),\n ...(this.recovery\n ? [this.recovery.delete(previousDescriptorId ?? descriptor.id)]\n : []),\n ])\n return descriptor\n }\n\n async reload(options?: { signal?: AbortSignal }): Promise<EidosFileSnapshot> {\n const previousDocument = this.requireDocument()\n if (!this.handle) throw new EidosFileHostError(\"closed\", \"No file is open\")\n const handle = this.handle\n let replacement: EidosFileDocument | null = null\n try {\n const read = await handle.read(options)\n replacement = await this.runtime.open(read, options)\n const snapshot = await replacement.source.getSnapshot()\n this.document = replacement\n replacement = null\n this.setState({\n ...this.state,\n phase: \"ready\",\n descriptor: { ...read.descriptor, metadata: snapshot.metadata },\n source: this.document.source,\n snapshot,\n dirty: false,\n error: null,\n conflict: null,\n recoveryAvailable: false,\n })\n await Promise.allSettled([\n Promise.resolve().then(() => previousDocument.close()),\n ...(this.recovery ? [this.recovery.delete(read.descriptor.id)] : []),\n ])\n return snapshot\n } catch (cause) {\n await settleResources(replacement)\n const error = hostError(\n \"read-failed\",\n \"Unable to reload Eidos File\",\n cause\n )\n this.setState({ ...this.state, phase: \"error\", error, conflict: null })\n throw error\n }\n }\n\n async restore(\n recovery: EidosFileRecoverySnapshot\n ): Promise<EidosFileSnapshot> {\n this.assertOpen()\n const previousDocument = this.document\n let document: EidosFileDocument | null = null\n try {\n document = await this.runtime.open({\n descriptor: recovery.descriptor,\n bytes: copyArrayBuffer(recovery.bytes),\n })\n const snapshot = await document.source.getSnapshot()\n this.document = document\n document = null\n this.setState({\n ...this.state,\n phase: \"dirty\",\n descriptor: { ...recovery.descriptor, metadata: snapshot.metadata },\n source: this.document.source,\n snapshot,\n dirty: true,\n error: null,\n conflict: null,\n recoveryAvailable: true,\n })\n await settleResources(previousDocument)\n return snapshot\n } catch (cause) {\n await settleResources(document)\n const error = hostError(\n \"read-failed\",\n \"Unable to restore Eidos File recovery data\",\n cause\n )\n this.setState({ ...this.state, phase: \"error\", error, conflict: null })\n throw error\n }\n }\n\n async close(): Promise<void> {\n if (this.state.phase === \"closed\") return\n if (this.closePromise) return this.closePromise\n this.closePromise = this.closeResources()\n return this.closePromise\n }\n\n private async closeResources(): Promise<void> {\n const document = this.document\n const handle = this.handle\n this.document = null\n this.handle = null\n const results = await settleResources(document, handle)\n this.setState({ ...initialState, phase: \"closed\" })\n this.listeners.clear()\n const failure = results.find(\n (result): result is PromiseRejectedResult => result.status === \"rejected\"\n )\n if (failure) throw failure.reason\n }\n\n private async requestWritePermission(): Promise<EidosFilePermissionState> {\n if (!this.handle) return \"unavailable\"\n const requested = await requestHandleWritePermission(this.handle)\n this.setState({ ...this.state, permission: requested })\n return requested\n }\n\n private assertOpen(): void {\n if (this.state.phase === \"closed\") {\n throw new EidosFileHostError(\"closed\", \"The Eidos File session is closed\")\n }\n }\n\n private requireDocument(): EidosFileDocument {\n this.assertOpen()\n if (!this.document || !this.state.source) {\n throw new EidosFileHostError(\"closed\", \"No Eidos File is open\")\n }\n return this.document\n }\n\n private setState(state: EidosFileSessionState): void {\n this.state = state\n for (const listener of this.listeners) listener()\n }\n}\n\nexport interface EidosFileTypeHandler {\n id: string\n label: string\n extensions: readonly string[]\n mimeTypes: readonly string[]\n accepts(descriptor: EidosFileCandidateDescriptor): boolean\n}\n\nexport interface EidosFileCandidateDescriptor {\n name: string\n mimeType: string\n}\n\nexport const eidosFileTypeHandler: EidosFileTypeHandler = {\n id: EIDOS_FILE_FORMAT,\n label: \"Eidos File\",\n extensions: [EIDOS_FILE_EXTENSION],\n mimeTypes: [EIDOS_FILE_MIME_TYPE],\n accepts: ({ name, mimeType }) =>\n mimeType === EIDOS_FILE_MIME_TYPE ||\n name.toLowerCase().endsWith(EIDOS_FILE_EXTENSION),\n}\n\nexport class EidosFileHandlerRegistry {\n private readonly handlers = new Map<string, EidosFileTypeHandler>()\n\n constructor(\n handlers: readonly EidosFileTypeHandler[] = [eidosFileTypeHandler]\n ) {\n for (const handler of handlers) this.register(handler)\n }\n\n register(handler: EidosFileTypeHandler): () => void {\n if (this.handlers.has(handler.id)) {\n throw new Error(`Duplicate Eidos File handler: ${handler.id}`)\n }\n this.handlers.set(handler.id, handler)\n return () => this.handlers.delete(handler.id)\n }\n\n match(descriptor: EidosFileCandidateDescriptor): EidosFileTypeHandler | null {\n return (\n [...this.handlers.values()].find((handler) =>\n handler.accepts(descriptor)\n ) ?? null\n )\n }\n\n list(): readonly EidosFileTypeHandler[] {\n return [...this.handlers.values()]\n }\n}\n\nfunction hostError(\n code: Exclude<\n EidosFileHostErrorCode,\n \"conflict\" | \"closed\" | \"permission-denied\"\n >,\n message: string,\n cause: unknown\n): EidosFileHostError {\n return cause instanceof EidosFileHostError\n ? cause\n : new EidosFileHostError(code, message, undefined, cause)\n}\n\nfunction copyArrayBuffer(bytes: Uint8Array): ArrayBuffer {\n const copy = new Uint8Array(bytes.byteLength)\n copy.set(bytes)\n return copy.buffer\n}\n\nasync function requestHandleWritePermission(\n handle: EidosFileHandle\n): Promise<EidosFilePermissionState> {\n const current = await handle.permission()\n if (current === \"granted\" || !handle.requestPermission) return current\n return handle.requestPermission()\n}\n\nfunction settleResources(\n document?: EidosFileDocument | null,\n handle?: EidosFileHandle | null\n): Promise<PromiseSettledResult<void>[]> {\n return Promise.allSettled([\n ...(document ? [Promise.resolve().then(async () => document.close())] : []),\n ...(handle?.close\n ? [Promise.resolve().then(async () => handle.close?.())]\n : []),\n ])\n}\n"],"mappings":";;AA6FA,SAAgB,kBACd,SACA,MACmB;AACnB,QAAO;EACL;EACA,UAAU,QAAQ,MAAM;EACxB,QAAQ,QAAQ,YAAY,CAAC,KAAK,WAAW;GAC3C;GACA,QAAQ,QAAQ,WAAW,MAAM,GAAG;GACpC,OAAO,QAAQ,UAAU,MAAM,GAAG;GAClC,UAAU,QAAQ,UAAU,MAAM,GAAG;GACtC,EAAE;EACJ;;;AAIH,IAAa,6BAAb,MAAuE;CACrE,YACE,SACA,MACA;AAFS,OAAA,UAAA;AACA,OAAA,OAAA;;CAGX,MAAM,cAA0C;AAC9C,SAAO,kBAAkB,KAAK,SAAS,KAAK,KAAK;;CAGnD,MAAM,QACJ,SACA,QACA,OACA,OACA,WACA,QACA,YAC2B;AAC3B,SAAO,KAAK,QAAQ,WAClB,SACA,QACA,OACA,OACA,WACA,QACA,WACD;;CAGH,MAAM,OAAO,SAAiB,OAA6C;AACzE,SAAO,KAAK,QAAQ,OAAO,SAAS,MAAM;;CAG5C,MAAM,eACJ,SACA,YACA,OACmC;AACnC,SAAO,KAAK,QAAQ,iBAAiB,SAAS,YAAY,MAAM;;CAGlE,MAAM,qBACJ,SACA,SACA,OACsC;AACtC,SAAO,KAAK,QAAQ,qBAAqB,SAAS,SAAS,MAAM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