@eidos.space/eidos-file 0.1.0 → 2.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.
Files changed (48) hide show
  1. package/DEVELOPER_PLATFORM.md +55 -53
  2. package/FIELD-CONVERSION.md +75 -0
  3. package/README.md +89 -106
  4. package/dist/adapter-contract-BRKKEulb.d.mts +1110 -0
  5. package/dist/adapter-contract-BRKKEulb.d.mts.map +1 -0
  6. package/dist/better-sqlite3.d.mts +64 -3
  7. package/dist/better-sqlite3.d.mts.map +1 -1
  8. package/dist/better-sqlite3.mjs +395 -14
  9. package/dist/better-sqlite3.mjs.map +1 -1
  10. package/dist/browser.d.mts +4 -3
  11. package/dist/browser.d.mts.map +1 -1
  12. package/dist/browser.mjs +30 -11
  13. package/dist/browser.mjs.map +1 -1
  14. package/dist/csv-BQPkzC5Y.mjs +386 -0
  15. package/dist/csv-BQPkzC5Y.mjs.map +1 -0
  16. package/dist/csv.d.mts +4 -2
  17. package/dist/csv.d.mts.map +1 -1
  18. package/dist/csv.mjs +1 -248
  19. package/dist/index.d.mts +327 -18
  20. package/dist/index.d.mts.map +1 -1
  21. package/dist/index.mjs +3555 -4
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/node-sqlite.d.mts +98 -0
  24. package/dist/node-sqlite.d.mts.map +1 -0
  25. package/dist/node-sqlite.mjs +684 -0
  26. package/dist/node-sqlite.mjs.map +1 -0
  27. package/dist/runtime-9_adwQ0y.mjs +5637 -0
  28. package/dist/runtime-9_adwQ0y.mjs.map +1 -0
  29. package/dist/runtime-C9IcEeTi.d.mts +728 -0
  30. package/dist/runtime-C9IcEeTi.d.mts.map +1 -0
  31. package/dist/select-options-CfNwfc_a.mjs +561 -0
  32. package/dist/select-options-CfNwfc_a.mjs.map +1 -0
  33. package/dist/sqlite-wasm-BM6hsxH8.mjs +2007 -0
  34. package/dist/sqlite-wasm-BM6hsxH8.mjs.map +1 -0
  35. package/dist/temporal-fyRCzJjy.d.mts +517 -0
  36. package/dist/temporal-fyRCzJjy.d.mts.map +1 -0
  37. package/package.json +11 -4
  38. package/dist/csv.mjs.map +0 -1
  39. package/dist/host-CqP1MeMK.d.mts +0 -213
  40. package/dist/host-CqP1MeMK.d.mts.map +0 -1
  41. package/dist/host-D5kZAhga.mjs +0 -478
  42. package/dist/host-D5kZAhga.mjs.map +0 -1
  43. package/dist/relation-values-B0JhHBjZ.mjs +0 -232
  44. package/dist/relation-values-B0JhHBjZ.mjs.map +0 -1
  45. package/dist/runtime-C3bstvB8.d.mts +0 -465
  46. package/dist/runtime-C3bstvB8.d.mts.map +0 -1
  47. package/dist/runtime-CWC5y95G.mjs +0 -2907
  48. package/dist/runtime-CWC5y95G.mjs.map +0 -1
@@ -0,0 +1,517 @@
1
+ import { Ct as UpdateEidosFileTableInput, Ft as RequestContext, M as EidosFileFormulaPreview, P as EidosFileFormulaPreviewInput, Q as EidosFileRowPage, St as UpdateEidosFileFieldInput, V as EidosFileLogicalValue, W as EidosFileMetadata, X as EidosFileRowGroupCount, Y as EidosFileRow, Z as EidosFileRowMutationResult, at as EidosFileRowsDeleteResult, c as CreateEidosFileTableInput, d as EidosFileColumnStatResult, et as EidosFileRowPageProjection, jt as JsonValue, l as CreateEidosFileViewInput, n as CreateEidosFileFieldInput, nt as EidosFileRowRange, t as EidosFileRuntime, tt as EidosFileRowQuery, u as EidosFileColumnStatConfig, ut as EidosFileSnapshot, w as EidosFileFieldPlacement, wt as UpdateEidosFileViewInput } from "./runtime-C9IcEeTi.mjs";
2
+ import { C as ScalarDefinition, N as CommitReconciliation, S as RunResult, T as SqlValue, Tt as RuntimeError, Zt as TransportCommitBarrier, a as ConnectionCapabilities, bt as RuntimeClient, f as HostLimits, o as ConnectionPort, s as ConnectionSnapshot, t as AdapterError, w as SnapshotContext, x as QueryResult } from "./adapter-contract-BRKKEulb.mjs";
3
+ import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
4
+
5
+ //#region src/constants.d.ts
6
+ /** Eidos File 1.0 application-file identity. */
7
+ declare const EIDOS_FILE_FORMAT: "eidos-file";
8
+ declare const EIDOS_FILE_FORMAT_VERSION: "1.0";
9
+ declare const EIDOS_FILE_SCHEMA_VERSION: 1;
10
+ declare const EIDOS_FILE_APPLICATION_ID: 1162429523;
11
+ declare const EIDOS_FILE_EXTENSION: ".eidos";
12
+ declare const EIDOS_FILE_MIME_TYPE: "application/vnd.eidos+sqlite3";
13
+ declare const SQLITE_HEADER: "SQLite format 3\0";
14
+ declare function hasEidosFileSqliteHeader(bytes: ArrayBuffer | Uint8Array): boolean;
15
+ declare const EIDOS_FILE_META_TABLE: "eidos__meta";
16
+ declare const EIDOS_FILE_FEATURES_TABLE: "eidos__features";
17
+ declare const EIDOS_FILE_TABLES_TABLE: "eidos__tables";
18
+ declare const EIDOS_FILE_FIELDS_TABLE: "eidos__fields";
19
+ declare const EIDOS_FILE_RELATION_FIELDS_TABLE: "eidos__relation_fields";
20
+ declare const EIDOS_FILE_FORMULA_FIELDS_TABLE: "eidos__formula_fields";
21
+ declare const EIDOS_FILE_LOOKUP_FIELDS_TABLE: "eidos__lookup_fields";
22
+ declare const EIDOS_FILE_VIEWS_TABLE: "eidos__views";
23
+ declare const EIDOS_FILE_REQUIRED_TABLES: readonly ["eidos__meta", "eidos__features", "eidos__tables", "eidos__fields", "eidos__relation_fields", "eidos__formula_fields", "eidos__lookup_fields", "eidos__views"];
24
+ declare const EIDOS_FILE_SYSTEM_COLUMNS: readonly ["_id", "_created_at", "_updated_at"];
25
+ //#endregion
26
+ //#region src/data-source.d.ts
27
+ /**
28
+ * Async, host-neutral data contract consumed by Eidos File views.
29
+ *
30
+ * A host may implement this with a Worker, an Electron bridge, a remote
31
+ * process, or the browser runtime. Views never receive a SQLite connection,
32
+ * native file handle, router, or application store.
33
+ */
34
+ interface EidosFileDataSource {
35
+ getSnapshot(): Promise<EidosFileSnapshot>;
36
+ getPage(tableId: string, offset: number, limit: number, query: EidosFileRowQuery, totalHint?: number, cursor?: string, projection?: EidosFileRowPageProjection): Promise<EidosFileRowPage>;
37
+ getRow?(tableId: string, rowId: string): Promise<EidosFileRow | null>;
38
+ getGroupCounts?(tableId: string, fieldId: string, query: EidosFileRowQuery): Promise<EidosFileRowGroupCount[]>;
39
+ calculateColumnStats(tableId: string, configs: EidosFileColumnStatConfig[], query: EidosFileRowQuery): Promise<EidosFileColumnStatResult[]>;
40
+ /**
41
+ * Validate a draft formula against the live file and return sample values.
42
+ * Hosts without a runtime preview boundary may omit this; the shared UI
43
+ * still performs schema-level compilation before saving.
44
+ */
45
+ previewFormula?(tableId: string, input: EidosFileFormulaPreviewInput): Promise<EidosFileFormulaPreview>;
46
+ insertRow(tableId: string, fields: Record<string, EidosFileLogicalValue>): Promise<EidosFileRowMutationResult>;
47
+ updateRow(tableId: string, rowId: string, fields: Record<string, EidosFileLogicalValue>): Promise<EidosFileRowMutationResult>;
48
+ deleteRowRanges(tableId: string, ranges: EidosFileRowRange[], query: EidosFileRowQuery): Promise<EidosFileRowsDeleteResult>;
49
+ deleteRows(tableId: string, rowIds: string[]): Promise<EidosFileRowsDeleteResult>;
50
+ updateField(tableId: string, fieldId: string, changes: UpdateEidosFileFieldInput): Promise<EidosFileSnapshot>;
51
+ addField(tableId: string, field: CreateEidosFileFieldInput, placement?: EidosFileFieldPlacement): Promise<EidosFileSnapshot>;
52
+ deleteField(tableId: string, fieldId: string): Promise<EidosFileSnapshot>;
53
+ createTable(input: CreateEidosFileTableInput): Promise<EidosFileSnapshot>;
54
+ updateTable(tableId: string, changes: UpdateEidosFileTableInput): Promise<EidosFileSnapshot>;
55
+ deleteTable(tableId: string): Promise<EidosFileSnapshot>;
56
+ createView(tableId: string, input: CreateEidosFileViewInput): Promise<EidosFileSnapshot>;
57
+ duplicateView(viewId: string, name?: string): Promise<EidosFileSnapshot>;
58
+ deleteView(viewId: string): Promise<EidosFileSnapshot>;
59
+ reorderViews(tableId: string, viewIds: string[]): Promise<EidosFileSnapshot>;
60
+ updateView(viewId: string, changes: UpdateEidosFileViewInput): Promise<EidosFileSnapshot>;
61
+ }
62
+ declare function eidosFileSnapshot(runtime: EidosFileRuntime, path: string): EidosFileSnapshot;
63
+ /** Adapts the synchronous core runtime to the public async view contract. */
64
+ declare class EidosFileRuntimeDataSource implements EidosFileDataSource {
65
+ readonly runtime: EidosFileRuntime;
66
+ readonly path: string;
67
+ constructor(runtime: EidosFileRuntime, path: string);
68
+ getSnapshot(): Promise<EidosFileSnapshot>;
69
+ getPage(tableId: string, offset: number, limit: number, query: EidosFileRowQuery, totalHint?: number, cursor?: string, projection?: EidosFileRowPageProjection): Promise<EidosFileRowPage>;
70
+ getRow(tableId: string, rowId: string): Promise<EidosFileRow | null>;
71
+ getGroupCounts(tableId: string, fieldId: string, query: EidosFileRowQuery): Promise<EidosFileRowGroupCount[]>;
72
+ calculateColumnStats(tableId: string, configs: EidosFileColumnStatConfig[], query: EidosFileRowQuery): Promise<EidosFileColumnStatResult[]>;
73
+ previewFormula(tableId: string, input: EidosFileFormulaPreviewInput): Promise<EidosFileFormulaPreview>;
74
+ insertRow(tableId: string, fields: Record<string, EidosFileLogicalValue>): Promise<EidosFileRowMutationResult>;
75
+ updateRow(tableId: string, rowId: string, fields: Record<string, EidosFileLogicalValue>): Promise<EidosFileRowMutationResult>;
76
+ deleteRowRanges(tableId: string, ranges: EidosFileRowRange[], query: EidosFileRowQuery): Promise<EidosFileRowsDeleteResult>;
77
+ deleteRows(tableId: string, rowIds: string[]): Promise<EidosFileRowsDeleteResult>;
78
+ updateField(tableId: string, fieldId: string, changes: UpdateEidosFileFieldInput): Promise<EidosFileSnapshot>;
79
+ addField(tableId: string, field: CreateEidosFileFieldInput, placement?: EidosFileFieldPlacement): Promise<EidosFileSnapshot>;
80
+ deleteField(tableId: string, fieldId: string): Promise<EidosFileSnapshot>;
81
+ createTable(input: CreateEidosFileTableInput): Promise<EidosFileSnapshot>;
82
+ updateTable(tableId: string, changes: UpdateEidosFileTableInput): Promise<EidosFileSnapshot>;
83
+ deleteTable(tableId: string): Promise<EidosFileSnapshot>;
84
+ createView(tableId: string, input: CreateEidosFileViewInput): Promise<EidosFileSnapshot>;
85
+ duplicateView(viewId: string, name?: string): Promise<EidosFileSnapshot>;
86
+ deleteView(viewId: string): Promise<EidosFileSnapshot>;
87
+ reorderViews(tableId: string, viewIds: string[]): Promise<EidosFileSnapshot>;
88
+ updateView(viewId: string, changes: UpdateEidosFileViewInput): Promise<EidosFileSnapshot>;
89
+ private mutationResult;
90
+ private deleteResult;
91
+ }
92
+ //#endregion
93
+ //#region src/host.d.ts
94
+ type EidosFilePermissionState = "granted" | "prompt" | "denied" | "unavailable";
95
+ interface EidosFileHostCapabilities {
96
+ read: true;
97
+ write: boolean;
98
+ saveAs: boolean;
99
+ recovery: boolean;
100
+ persistentFileAccess: boolean;
101
+ }
102
+ interface EidosFileDescriptor {
103
+ /** Stable for the lifetime of the host adapter, opaque to views. */
104
+ id: string;
105
+ name: string;
106
+ format: typeof EIDOS_FILE_FORMAT;
107
+ mimeType: typeof EIDOS_FILE_MIME_TYPE;
108
+ size: number;
109
+ /** Adapter-owned compare-and-swap token. Never derive behavior from it. */
110
+ revision: string;
111
+ lastModified?: number;
112
+ metadata?: EidosFileMetadata;
113
+ }
114
+ interface EidosFileReadResult {
115
+ descriptor: EidosFileDescriptor;
116
+ bytes: ArrayBuffer;
117
+ }
118
+ interface EidosFileWriteOptions {
119
+ expectedRevision?: string;
120
+ force?: boolean;
121
+ signal?: AbortSignal;
122
+ }
123
+ interface EidosFileHandle {
124
+ readonly capabilities: EidosFileHostCapabilities;
125
+ descriptor(): Promise<EidosFileDescriptor>;
126
+ permission(): Promise<EidosFilePermissionState>;
127
+ requestPermission?(): Promise<EidosFilePermissionState>;
128
+ read(options?: {
129
+ signal?: AbortSignal;
130
+ }): Promise<EidosFileReadResult>;
131
+ write?(bytes: Uint8Array, options?: EidosFileWriteOptions): Promise<EidosFileDescriptor>;
132
+ close?(): void | Promise<void>;
133
+ }
134
+ interface EidosFileDocument {
135
+ readonly source: EidosFileDataSource;
136
+ exportBytes(options?: {
137
+ signal?: AbortSignal;
138
+ }): Promise<Uint8Array>;
139
+ close(): void | Promise<void>;
140
+ }
141
+ interface EidosFileRuntimeAdapter {
142
+ open(read: EidosFileReadResult, options?: {
143
+ signal?: AbortSignal;
144
+ }): Promise<EidosFileDocument>;
145
+ }
146
+ interface EidosFileRecoverySnapshot {
147
+ id: string;
148
+ descriptor: EidosFileDescriptor;
149
+ bytes: Uint8Array;
150
+ updatedAt: number;
151
+ }
152
+ interface EidosFileRecoveryStore {
153
+ load(id: string): Promise<EidosFileRecoverySnapshot | null>;
154
+ save(snapshot: EidosFileRecoverySnapshot): Promise<void>;
155
+ delete(id: string): Promise<void>;
156
+ }
157
+ type EidosFileSessionPhase = "idle" | "opening" | "ready" | "dirty" | "saving" | "conflict" | "error" | "closed";
158
+ interface EidosFileConflict {
159
+ expectedRevision: string;
160
+ actual: EidosFileDescriptor;
161
+ }
162
+ interface EidosFileSessionState {
163
+ phase: EidosFileSessionPhase;
164
+ descriptor: EidosFileDescriptor | null;
165
+ permission: EidosFilePermissionState;
166
+ capabilities: EidosFileHostCapabilities | null;
167
+ source: EidosFileDataSource | null;
168
+ snapshot: EidosFileSnapshot | null;
169
+ dirty: boolean;
170
+ error: Error | null;
171
+ conflict: EidosFileConflict | null;
172
+ recoveryAvailable: boolean;
173
+ }
174
+ type EidosFileHostErrorCode = "closed" | "permission-denied" | "read-failed" | "write-failed" | "conflict";
175
+ declare class EidosFileHostError extends Error {
176
+ readonly code: EidosFileHostErrorCode;
177
+ readonly conflict?: EidosFileConflict | undefined;
178
+ readonly cause?: unknown | undefined;
179
+ constructor(code: EidosFileHostErrorCode, message: string, conflict?: EidosFileConflict | undefined, cause?: unknown | undefined);
180
+ }
181
+ declare class EidosFileSession {
182
+ private readonly runtime;
183
+ private readonly recovery?;
184
+ private state;
185
+ private handle;
186
+ private document;
187
+ private closePromise;
188
+ private readonly listeners;
189
+ constructor(runtime: EidosFileRuntimeAdapter, recovery?: EidosFileRecoveryStore | undefined);
190
+ getState: () => EidosFileSessionState;
191
+ subscribe: (listener: () => void) => (() => void);
192
+ open(handle: EidosFileHandle, options?: {
193
+ signal?: AbortSignal;
194
+ }): Promise<EidosFileSnapshot>;
195
+ refresh(): Promise<EidosFileSnapshot>;
196
+ markDirty(snapshot?: EidosFileSnapshot): void;
197
+ checkpoint(): Promise<EidosFileRecoverySnapshot | null>;
198
+ save(options?: EidosFileWriteOptions): Promise<EidosFileDescriptor>;
199
+ saveAs(handle: EidosFileHandle): Promise<EidosFileDescriptor>;
200
+ reload(options?: {
201
+ signal?: AbortSignal;
202
+ }): Promise<EidosFileSnapshot>;
203
+ restore(recovery: EidosFileRecoverySnapshot): Promise<EidosFileSnapshot>;
204
+ close(): Promise<void>;
205
+ private closeResources;
206
+ private requestWritePermission;
207
+ private assertOpen;
208
+ private requireDocument;
209
+ private setState;
210
+ }
211
+ interface EidosFileTypeHandler {
212
+ id: string;
213
+ label: string;
214
+ extensions: readonly string[];
215
+ mimeTypes: readonly string[];
216
+ accepts(descriptor: EidosFileCandidateDescriptor): boolean;
217
+ }
218
+ interface EidosFileCandidateDescriptor {
219
+ name: string;
220
+ mimeType: string;
221
+ }
222
+ declare const eidosFileTypeHandler: EidosFileTypeHandler;
223
+ declare class EidosFileHandlerRegistry {
224
+ private readonly handlers;
225
+ constructor(handlers?: readonly EidosFileTypeHandler[]);
226
+ register(handler: EidosFileTypeHandler): () => void;
227
+ match(descriptor: EidosFileCandidateDescriptor): EidosFileTypeHandler | null;
228
+ list(): readonly EidosFileTypeHandler[];
229
+ }
230
+ //#endregion
231
+ //#region src/sqlite-wasm.d.ts
232
+ type Sqlite3Static = Awaited<ReturnType<typeof sqlite3InitModule>>;
233
+ type SqliteDatabase = InstanceType<Sqlite3Static["oo1"]["DB"]>;
234
+ interface SQLiteWasmConnectionPortOptions {
235
+ busyTimeoutMs?: number;
236
+ maxResultRows?: number;
237
+ maxResultBytes?: number;
238
+ }
239
+ /**
240
+ * EA-Connection-1.0 binding for the official SQLite WASM build.
241
+ *
242
+ * This class is intended to live beside Runtime in a Dedicated Worker. The
243
+ * Window side must expose RuntimeClient over the Adapter transport profile,
244
+ * never this object or its underlying database.
245
+ */
246
+ declare class SQLiteWasmConnectionPort implements ConnectionPort {
247
+ readonly database: SqliteDatabase;
248
+ readonly sqlite3: Sqlite3Static;
249
+ private readonly connectionCapabilities;
250
+ private readonly maxResultRows;
251
+ private readonly maxResultBytes;
252
+ private readonly transactionModes;
253
+ private readonly snapshots;
254
+ private readonly scalarPointers;
255
+ private localCommit;
256
+ private savepointSequence;
257
+ private mainReadEstablished;
258
+ private closed;
259
+ constructor(database: SqliteDatabase, sqlite3: Sqlite3Static, options?: SQLiteWasmConnectionPortOptions);
260
+ capabilities(): ConnectionCapabilities;
261
+ execSchema(sql: string): void;
262
+ query(sql: string, bindings?: readonly SqlValue[]): QueryResult;
263
+ get(sql: string, bindings?: readonly SqlValue[]): {
264
+ columns: Array<{
265
+ name: string;
266
+ }>;
267
+ row: SqlValue[] | null;
268
+ };
269
+ run(sql: string, bindings?: readonly SqlValue[]): RunResult;
270
+ runMany(sql: string, bindingSets: readonly (readonly SqlValue[])[]): RunResult[];
271
+ registerScalar(definition: ScalarDefinition, operation: (...values: SqlValue[]) => SqlValue): void;
272
+ transaction<T>(mode: "read" | "write", operation: () => T): T;
273
+ transaction<T>(mode: "read" | "write", operation: () => Promise<T>): Promise<T>;
274
+ dataVersion(): string;
275
+ interrupt(): void;
276
+ snapshot(context: SnapshotContext): Promise<ConnectionSnapshot>;
277
+ close(): void;
278
+ private bind;
279
+ private readRow;
280
+ private readValue;
281
+ private writeScalarResult;
282
+ private assertReader;
283
+ private assertWriter;
284
+ private assertStatementAllowed;
285
+ private runResult;
286
+ private rollbackTransaction;
287
+ private noteRead;
288
+ private assertSnapshotContext;
289
+ private runMandatoryProbes;
290
+ private assertOpen;
291
+ private mapError;
292
+ }
293
+ //#endregion
294
+ //#region src/adapter-transport.d.ts
295
+ interface AdapterTransportLimits {
296
+ maxOutstandingRequests: number;
297
+ maxQueuedBytes: number;
298
+ maxRequestBytes: number;
299
+ maxResponseBytes: number;
300
+ defaultTimeoutMs: number;
301
+ maxTimeoutMs: number;
302
+ commitAckTimeoutMs: number;
303
+ }
304
+ declare const EIDOS_ADAPTER_TRANSPORT_LIMITS: Readonly<AdapterTransportLimits>;
305
+ interface AdapterAttachmentDescriptor {
306
+ id: string;
307
+ slot: string;
308
+ byteLength: number;
309
+ }
310
+ interface AdapterWireBase {
311
+ protocol: "eidos-adapter";
312
+ }
313
+ interface AdapterWireSessionBase extends AdapterWireBase {
314
+ version: "1.0";
315
+ epoch: string;
316
+ sessionID: string;
317
+ }
318
+ type AdapterWireEnvelope = (AdapterWireBase & {
319
+ kind: "hello";
320
+ versions: string[];
321
+ }) | (AdapterWireBase & {
322
+ kind: "hello-error";
323
+ error: AdapterError;
324
+ }) | (AdapterWireSessionBase & {
325
+ kind: "hello-result";
326
+ limits: AdapterTransportLimits;
327
+ cancelMode: "interrupt" | "terminate";
328
+ }) | (AdapterWireSessionBase & {
329
+ kind: "request";
330
+ requestID: string;
331
+ sequence: number;
332
+ timeoutMs?: number;
333
+ operation: string;
334
+ payload: JsonValue;
335
+ attachments?: AdapterAttachmentDescriptor[];
336
+ }) | (AdapterWireSessionBase & {
337
+ kind: "response";
338
+ requestID: string;
339
+ sequence: number;
340
+ ok: true;
341
+ result: JsonValue;
342
+ attachments?: AdapterAttachmentDescriptor[];
343
+ }) | (AdapterWireSessionBase & {
344
+ kind: "response";
345
+ requestID: string;
346
+ sequence: number;
347
+ ok: false;
348
+ error: {
349
+ source: "runtime";
350
+ error: RuntimeError;
351
+ } | {
352
+ source: "adapter";
353
+ error: AdapterError;
354
+ };
355
+ }) | (AdapterWireSessionBase & {
356
+ kind: "commit-prepared";
357
+ requestID: string;
358
+ sequence: number;
359
+ receipt: AdapterCommitReceipt;
360
+ }) | (AdapterWireSessionBase & {
361
+ kind: "commit-ack";
362
+ requestID: string;
363
+ sequence: number;
364
+ receiptID: string;
365
+ requestDigest: string;
366
+ }) | (AdapterWireSessionBase & {
367
+ kind: "cancel";
368
+ requestID: string;
369
+ }) | (AdapterWireSessionBase & {
370
+ kind: "close";
371
+ requestID: string;
372
+ timeoutMs?: number;
373
+ }) | (AdapterWireSessionBase & {
374
+ kind: "close-result";
375
+ requestID: string;
376
+ });
377
+ interface AdapterStructuredCloneCarrier {
378
+ envelope: AdapterWireEnvelope;
379
+ buffers: ArrayBuffer[];
380
+ }
381
+ interface AdapterCommitReceipt {
382
+ protocol: "eidos-commit-receipt";
383
+ version: "1.0";
384
+ receiptID: string;
385
+ epoch: string;
386
+ sessionID: string;
387
+ workingID: string;
388
+ requestID: string;
389
+ sequence: number;
390
+ operation: string;
391
+ fileID: string;
392
+ baseRevision: string;
393
+ commitRevision: string;
394
+ requestDigest: string;
395
+ reconciliation: CommitReconciliation;
396
+ }
397
+ interface AdapterTransportChannel {
398
+ post(carrier: AdapterStructuredCloneCarrier, transfers?: Transferable[]): void;
399
+ subscribe(listener: (carrier: AdapterStructuredCloneCarrier) => void, onClose?: (reason?: unknown) => void): () => void;
400
+ close?(): void;
401
+ }
402
+ declare function validateAdapterCarrier(carrier: unknown): asserts carrier is AdapterStructuredCloneCarrier;
403
+ declare function validateAdapterEnvelope(envelope: unknown): asserts envelope is AdapterWireEnvelope;
404
+ interface AdapterTransportServerOptions {
405
+ epoch: string;
406
+ sessionID: string;
407
+ workingID: string;
408
+ limits?: AdapterTransportLimits;
409
+ cancelMode: "interrupt" | "terminate";
410
+ allocateReceiptID(): string;
411
+ retainPreparedReceipt?(receipt: AdapterCommitReceipt): void;
412
+ settlePreparedReceipt?(receipt: AdapterCommitReceipt, committed: boolean): void;
413
+ closeConnection(): void;
414
+ }
415
+ declare class AdapterTransportServer {
416
+ private readonly send;
417
+ private readonly options;
418
+ readonly commitBarrier: TransportCommitBarrier;
419
+ private runtime;
420
+ private readonly limits;
421
+ private sequence;
422
+ private queue;
423
+ private active;
424
+ private pendingAck;
425
+ private helloComplete;
426
+ private closing;
427
+ private closed;
428
+ private queuedBytes;
429
+ private outstandingRequests;
430
+ constructor(send: (carrier: AdapterStructuredCloneCarrier, transfers?: Transferable[]) => void, options: AdapterTransportServerOptions);
431
+ attachRuntime(runtime: RuntimeClient): void;
432
+ receive(carrier: unknown): void;
433
+ private receiveHello;
434
+ private receiveRequest;
435
+ private executeRequest;
436
+ private prepareCommit;
437
+ private receiveCommitAck;
438
+ private receiveClose;
439
+ private failure;
440
+ private fatal;
441
+ private post;
442
+ }
443
+ interface AdapterTransportRuntimeClientOptions {
444
+ /** Host-private working identity used only to validate commit receipts. */
445
+ workingID: string;
446
+ retainPreparedReceipt(receipt: AdapterCommitReceipt): void;
447
+ settlePreparedReceipt(receipt: AdapterCommitReceipt): void;
448
+ }
449
+ declare class AdapterTransportRuntimeClient implements RuntimeClient {
450
+ private readonly channel;
451
+ private readonly options;
452
+ revertMutation: RuntimeClient["revertMutation"];
453
+ exportCsv: RuntimeClient["exportCsv"];
454
+ importCsv: RuntimeClient["importCsv"];
455
+ private limits;
456
+ private epoch;
457
+ private sessionID;
458
+ private sequence;
459
+ private wireID;
460
+ private queuedBytes;
461
+ private readonly pending;
462
+ private readonly applicationToWire;
463
+ private readonly unsubscribe;
464
+ private helloResolve;
465
+ private helloReject;
466
+ private state;
467
+ constructor(channel: AdapterTransportChannel, options: AdapterTransportRuntimeClientOptions);
468
+ connect(): Promise<this>;
469
+ negotiate(request: Parameters<RuntimeClient["negotiate"]>[0], context: RequestContext): ReturnType<RuntimeClient["negotiate"]>;
470
+ getSnapshot(request: Parameters<RuntimeClient["getSnapshot"]>[0], context: RequestContext): ReturnType<RuntimeClient["getSnapshot"]>;
471
+ getSchemaPage(request: Parameters<RuntimeClient["getSchemaPage"]>[0], context: RequestContext): ReturnType<RuntimeClient["getSchemaPage"]>;
472
+ queryRows(request: Parameters<RuntimeClient["queryRows"]>[0], context: RequestContext): ReturnType<RuntimeClient["queryRows"]>;
473
+ getRowsById(request: Parameters<RuntimeClient["getRowsById"]>[0], context: RequestContext): ReturnType<RuntimeClient["getRowsById"]>;
474
+ aggregate(request: Parameters<RuntimeClient["aggregate"]>[0], context: RequestContext): ReturnType<RuntimeClient["aggregate"]>;
475
+ groupRows(request: Parameters<RuntimeClient["groupRows"]>[0], context: RequestContext): ReturnType<RuntimeClient["groupRows"]>;
476
+ queryGroupRows(request: Parameters<RuntimeClient["queryGroupRows"]>[0], context: RequestContext): ReturnType<RuntimeClient["queryGroupRows"]>;
477
+ previewFormula(request: Parameters<RuntimeClient["previewFormula"]>[0], context: RequestContext): ReturnType<RuntimeClient["previewFormula"]>;
478
+ mutateRows(request: Parameters<RuntimeClient["mutateRows"]>[0], context: RequestContext): ReturnType<RuntimeClient["mutateRows"]>;
479
+ mutateView(request: Parameters<RuntimeClient["mutateView"]>[0], context: RequestContext): ReturnType<RuntimeClient["mutateView"]>;
480
+ preflightSchema(request: Parameters<RuntimeClient["preflightSchema"]>[0], context: RequestContext): ReturnType<RuntimeClient["preflightSchema"]>;
481
+ getSchemaPlanDependencies(request: Parameters<RuntimeClient["getSchemaPlanDependencies"]>[0], context: RequestContext): ReturnType<RuntimeClient["getSchemaPlanDependencies"]>;
482
+ mutateSchema(request: Parameters<RuntimeClient["mutateSchema"]>[0], context: RequestContext): ReturnType<RuntimeClient["mutateSchema"]>;
483
+ validate(request: Parameters<RuntimeClient["validate"]>[0], context: RequestContext): ReturnType<RuntimeClient["validate"]>;
484
+ cancel(request: {
485
+ requestId: string;
486
+ }): Promise<void>;
487
+ close(context: RequestContext): Promise<void>;
488
+ private call;
489
+ private installOptionalMethods;
490
+ private receive;
491
+ private receivePrepared;
492
+ private settle;
493
+ private channelClosed;
494
+ private fatalPending;
495
+ private finishClose;
496
+ private nextWireID;
497
+ }
498
+ /** Host byte limits are decimal strings and must never be compared as Number. */
499
+ declare function transportFitsHostLimit(bytes: number, limit: HostLimits["candidateBytesMax"]): boolean;
500
+ //#endregion
501
+ //#region src/temporal.d.ts
502
+ /** Returns whether a value is the canonical Eidos File calendar date. */
503
+ declare function isCanonicalEidosFileDate(value: unknown): value is string;
504
+ /** Returns whether a value is the canonical 24-octet Eidos File instant. */
505
+ declare function isCanonicalEidosFileInstant(value: unknown): value is string;
506
+ /** Validates an exact `YYYY-MM-DD` API/storage value. */
507
+ declare function normalizeEidosFileDate(value: string, label?: string): string;
508
+ /**
509
+ * Normalizes RFC 3339 API input to the canonical UTC millisecond form.
510
+ * Precision beyond milliseconds is rejected instead of silently truncated.
511
+ */
512
+ declare function normalizeEidosFileInstant(value: string, label?: string): string;
513
+ /** Returns the current canonical UTC instant. */
514
+ declare function currentEidosFileInstant(now?: Date): string;
515
+ //#endregion
516
+ export { EIDOS_FILE_META_TABLE as $, EidosFileHostErrorCode as A, EidosFileWriteOptions as B, EidosFileConflict as C, EidosFileHandlerRegistry as D, EidosFileHandle as E, EidosFileRuntimeAdapter as F, EIDOS_FILE_APPLICATION_ID as G, EidosFileDataSource as H, EidosFileSession as I, EIDOS_FILE_FIELDS_TABLE as J, EIDOS_FILE_EXTENSION as K, EidosFileSessionPhase as L, EidosFileReadResult as M, EidosFileRecoverySnapshot as N, EidosFileHostCapabilities as O, EidosFileRecoveryStore as P, EIDOS_FILE_LOOKUP_FIELDS_TABLE as Q, EidosFileSessionState as R, EidosFileCandidateDescriptor as S, EidosFileDocument as T, EidosFileRuntimeDataSource as U, eidosFileTypeHandler as V, eidosFileSnapshot as W, EIDOS_FILE_FORMAT_VERSION as X, EIDOS_FILE_FORMAT as Y, EIDOS_FILE_FORMULA_FIELDS_TABLE as Z, transportFitsHostLimit as _, normalizeEidosFileInstant as a, EIDOS_FILE_TABLES_TABLE as at, SQLiteWasmConnectionPort as b, AdapterStructuredCloneCarrier as c, hasEidosFileSqliteHeader as ct, AdapterTransportRuntimeClient as d, EIDOS_FILE_MIME_TYPE as et, AdapterTransportRuntimeClientOptions as f, EIDOS_ADAPTER_TRANSPORT_LIMITS as g, AdapterWireEnvelope as h, normalizeEidosFileDate as i, EIDOS_FILE_SYSTEM_COLUMNS as it, EidosFilePermissionState as j, EidosFileHostError as k, AdapterTransportChannel as l, AdapterTransportServerOptions as m, isCanonicalEidosFileDate as n, EIDOS_FILE_REQUIRED_TABLES as nt, AdapterAttachmentDescriptor as o, EIDOS_FILE_VIEWS_TABLE as ot, AdapterTransportServer as p, EIDOS_FILE_FEATURES_TABLE as q, isCanonicalEidosFileInstant as r, EIDOS_FILE_SCHEMA_VERSION as rt, AdapterCommitReceipt as s, SQLITE_HEADER as st, currentEidosFileInstant as t, EIDOS_FILE_RELATION_FIELDS_TABLE as tt, AdapterTransportLimits as u, validateAdapterCarrier as v, EidosFileDescriptor as w, SQLiteWasmConnectionPortOptions as x, validateAdapterEnvelope as y, EidosFileTypeHandler as z };
517
+ //# sourceMappingURL=temporal-fyRCzJjy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"temporal-fyRCzJjy.d.mts","names":[],"sources":["../src/constants.ts","../src/data-source.ts","../src/host.ts","../src/sqlite-wasm.ts","../src/adapter-transport.ts","../src/temporal.ts"],"mappings":";;;;;;cACa,iBAAA;AAAA,cACA,yBAAA;AAAA,cACA,yBAAA;AAAA,cACA,yBAAA;AAAA,cACA,oBAAA;AAAA,cACA,oBAAA;AAAA,cACA,aAAA;AAAA,iBAEG,wBAAA,CACd,KAAA,EAAO,WAAA,GAAc,UAAA;AAAA,cAUV,qBAAA;AAAA,cACA,yBAAA;AAAA,cACA,uBAAA;AAAA,cACA,uBAAA;AAAA,cACA,gCAAA;AAAA,cAEA,+BAAA;AAAA,cACA,8BAAA;AAAA,cACA,sBAAA;AAAA,cAEA,0BAAA;AAAA,cAWA,yBAAA;;;;;;AAxCb;;;;UC+BiB,mBAAA;EACf,WAAA,IAAe,OAAA,CAAQ,iBAAA;EACvB,OAAA,CACE,OAAA,UACA,MAAA,UACA,KAAA,UACA,KAAA,EAAO,iBAAA,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AAA,EAAS,cAAA,GAMJ,UAAA,CAAW,aAAA;EAElB,YAAA,CACE,OAAA,EAAS,UAAA,CAAW,aAAA,sBACpB,OAAA,EAAS,cAAA,GAE6C,UAAA,CACpD,aAAA;EAGJ,QAAA,CACE,OAAA,EAAS,UAAA,CAAW,aAAA,kBACpB,OAAA,EAAS,cAAA,GAEyC,UAAA,CAChD,aAAA;EAIE,MAAA,CAAO,OAAA;IAAW,SAAA;EAAA,IAAsB,OAAA;EAkBxC,KAAA,CAAM,OAAA,EAAS,cAAA,GAAiB,OAAA;EAAA,QAkD9B,IAAA;EAAA,QA0HA,sBAAA;EAAA,QA2BM,OAAA;EAAA,QAoDA,eAAA;EAAA,QAuCN,MAAA;EAAA,QAYA,aAAA;EAAA,QAgBA,YAAA;EAAA,QAkBA,WAAA;EAAA,QAOA,UAAA;AAAA;;iBAugBM,sBAAA,CACd,KAAA,UACA,KAAA,EAAO,UAAA;;;;iBCr2DO,wBAAA,CAAyB,KAAA,YAAiB,KAAA;;iBAK1C,2BAAA,CAA4B,KAAA,YAAiB,KAAA;;iBAa7C,sBAAA,CAAuB,KAAA,UAAe,KAAA;;;;;iBActC,yBAAA,CACd,KAAA,UACA,KAAA;;iBAmDc,uBAAA,CAAwB,GAAA,GAAG,IAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eidos.space/eidos-file",
3
- "version": "0.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "Independent SQLite-backed runtime for the open Eidos File format",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -17,6 +17,11 @@
17
17
  "import": "./dist/better-sqlite3.mjs",
18
18
  "default": "./dist/better-sqlite3.mjs"
19
19
  },
20
+ "./node-sqlite": {
21
+ "types": "./dist/node-sqlite.d.mts",
22
+ "import": "./dist/node-sqlite.mjs",
23
+ "default": "./dist/node-sqlite.mjs"
24
+ },
20
25
  "./browser": {
21
26
  "types": "./dist/browser.d.mts",
22
27
  "browser": "./dist/browser.mjs",
@@ -32,6 +37,7 @@
32
37
  "files": [
33
38
  "dist",
34
39
  "README.md",
40
+ "FIELD-CONVERSION.md",
35
41
  "DEVELOPER_PLATFORM.md",
36
42
  "LICENSE"
37
43
  ],
@@ -64,13 +70,12 @@
64
70
  },
65
71
  "dependencies": {
66
72
  "@sqlite.org/sqlite-wasm": "3.45.3-build2",
67
- "csv-parse": "^5.6.0",
68
- "pgsql-ast-parser": "^11.2.0"
73
+ "csv-parse": "^5.6.0"
69
74
  },
70
75
  "devDependencies": {
71
76
  "@microsoft/api-extractor": "7.58.11",
72
77
  "@types/better-sqlite3": "^7.6.13",
73
- "@types/node": "^20.4.1",
78
+ "@types/node": "^24.12.2",
74
79
  "better-sqlite3": "^12.0.0",
75
80
  "tsdown": "^0.21.7",
76
81
  "typescript": "^5.8.3",
@@ -78,9 +83,11 @@
78
83
  },
79
84
  "scripts": {
80
85
  "build": "tsdown",
86
+ "build:quickjs": "esbuild src/quickjs-entry.ts --bundle --format=iife --target=es2020 --alias:vitest=./src/quickjs/expect-shim.ts --outfile=../../apps/cli/qjs-host/bundle/eidos-runtime.js --minify",
81
87
  "api:report": "api-extractor run --local && api-extractor run --local --config api-extractor.browser.json",
82
88
  "api:check": "api-extractor run && api-extractor run --config api-extractor.browser.json",
83
89
  "test": "vitest run --config vitest.config.ts",
90
+ "test:node-sqlite": "node ../../scripts/run-electron-node.mjs ../../node_modules/vitest/vitest.mjs run --config vitest.node-sqlite.config.ts",
84
91
  "typecheck": "tsc --noEmit",
85
92
  "typecheck:public": "tsc -p test-d/tsconfig.json",
86
93
  "typecheck:tsgo": "tsgo --noEmit"
package/dist/csv.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"csv.mjs","names":[],"sources":["../src/csv.ts"],"sourcesContent":["// The browser ESM entry bundles its own byte helpers and also runs in Node.\n// Using it keeps the shared CSV runtime portable instead of leaking Node's\n// global `Buffer` requirement into Web Workers.\nimport { parse } from \"csv-parse/browser/esm/sync\"\n\nimport { EidosFileError } from \"./errors\"\nimport { eidosFileFieldDisplayValues } from \"./field-conversion\"\nimport {\n decodeEidosFileRelationDisplay,\n decodeEidosFileRelationIds,\n} from \"./relation-values\"\nimport type { EidosFileRuntime } from \"./runtime\"\nimport type {\n EidosFileCsvExportColumn,\n EidosFileFieldInfo,\n EidosFileCsvFieldType,\n EidosFileCsvImportColumn,\n EidosFileCsvImportIssue,\n EidosFileCsvImportOptions,\n EidosFileCsvImportPlan,\n EidosFileCsvImportResult,\n EidosFileRow,\n} from \"./types\"\n\nexport const EIDOS_FILE_CSV_PREVIEW_ROW_COUNT = 5\nexport const EIDOS_FILE_CSV_INFERENCE_ROW_COUNT = 1_000\n\nfunction encodeCsvCell(value: string): string {\n return /[\",\\r\\n]/.test(value) ? `\"${value.replace(/\"/g, '\"\"')}\"` : value\n}\n\nexport function encodeEidosFileCsvRecord(values: readonly string[]): string {\n return `${values.map(encodeCsvCell).join(\",\")}\\r\\n`\n}\n\nexport function eidosFileCsvExportHeader(\n columns: readonly EidosFileCsvExportColumn[]\n): string {\n return encodeEidosFileCsvRecord(columns.map((column) => column.name))\n}\n\nexport function createEidosFileCsvRowEncoder(\n fields: readonly EidosFileFieldInfo[],\n columns: readonly EidosFileCsvExportColumn[]\n): (row: EidosFileRow) => string {\n const fieldsByColumn = new Map(\n fields.map((field) => [field.tableColumnName, field])\n )\n const resolvedFields = columns.map((column) => {\n const field = fieldsByColumn.get(column.columnName)\n if (!field) {\n throw new EidosFileError(\n \"field-not-found\",\n `Eidos File field not found: ${column.columnName}`\n )\n }\n return field\n })\n\n return (row) =>\n encodeEidosFileCsvRecord(\n resolvedFields.map((field) => {\n if (field.type === \"link\") {\n const display = decodeEidosFileRelationDisplay(\n row[`${field.tableColumnName}__display`]\n )\n return (\n display.length > 0\n ? display.map((entry) => entry.title)\n : decodeEidosFileRelationIds(row[field.tableColumnName])\n ).join(\", \")\n }\n return eidosFileFieldDisplayValues(\n field,\n row[field.tableColumnName] ?? null\n ).join(\", \")\n })\n )\n}\n\ninterface ParsedCsv {\n header: string[]\n rows: string[][]\n skippedRowCount: number\n issues: EidosFileCsvImportIssue[]\n}\n\nfunction invalidCsv(error: unknown): EidosFileError {\n const candidate = error as { code?: string; lines?: number; message?: string }\n if (candidate.code === \"CSV_QUOTE_NOT_CLOSED\") {\n return new EidosFileError(\n \"invalid-csv\",\n `CSV parsing failed: unclosed quote at line ${candidate.lines ?? \"unknown\"}`\n )\n }\n if (candidate.code === \"CSV_INVALID_CLOSING_QUOTE\") {\n return new EidosFileError(\n \"invalid-csv\",\n \"CSV parsing failed: invalid closing quote\"\n )\n }\n return new EidosFileError(\n \"invalid-csv\",\n `CSV parsing failed: ${candidate.message ?? String(error)}`\n )\n}\n\nfunction parseCsv(content: string): ParsedCsv {\n if (!content.trim()) {\n throw new EidosFileError(\"invalid-csv\", \"CSV file is empty\")\n }\n let records: string[][]\n let malformedRows = 0\n try {\n const parseOptions = {\n bom: true,\n columns: false,\n relax_column_count: true,\n relax_quotes: true,\n skip_empty_lines: true,\n skip_records_with_error: true,\n on_skip: () => {\n malformedRows += 1\n },\n }\n records = parse(content, parseOptions) as string[][]\n } catch (error) {\n throw invalidCsv(error)\n }\n if (records.length === 0 || records[0].length === 0) {\n throw new EidosFileError(\"invalid-csv\", \"CSV header is missing\")\n }\n const header = records[0].map((value) => String(value ?? \"\").trim())\n const rows: string[][] = []\n let inconsistentRows = 0\n for (const record of records.slice(1)) {\n if (record.length !== header.length) {\n inconsistentRows += 1\n continue\n }\n rows.push(record.map((value) => String(value ?? \"\")))\n }\n const issues: EidosFileCsvImportIssue[] = []\n if (malformedRows > 0) {\n issues.push({\n code: \"malformed-row\",\n count: malformedRows,\n message: `${malformedRows} malformed row${malformedRows === 1 ? \" was\" : \"s were\"} skipped`,\n })\n }\n if (inconsistentRows > 0) {\n issues.push({\n code: \"inconsistent-column-count\",\n count: inconsistentRows,\n message: `${inconsistentRows} row${inconsistentRows === 1 ? \" has\" : \"s have\"} a different column count and will be skipped`,\n })\n }\n return {\n header,\n rows,\n skippedRowCount: malformedRows + inconsistentRows,\n issues,\n }\n}\n\nfunction uniqueName(name: string, used: Set<string>, fallback: string): string {\n const base = name.trim() || fallback\n let candidate = base\n let suffix = 2\n while (used.has(candidate.toLocaleLowerCase())) {\n candidate = `${base} ${suffix}`\n suffix += 1\n }\n used.add(candidate.toLocaleLowerCase())\n return candidate\n}\n\nfunction columnIdentifier(\n name: string,\n index: number,\n used: Set<string>\n): string {\n const normalized = name\n .normalize(\"NFKD\")\n .replace(/[\\u0300-\\u036f]/g, \"\")\n .toLocaleLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\")\n const stem = /^[a-z]/.test(normalized) ? normalized : `field_${index + 1}`\n let candidate = stem === \"title\" ? `field_${index + 1}` : stem\n let suffix = 2\n while (used.has(candidate)) {\n candidate = `${stem}_${suffix}`\n suffix += 1\n }\n used.add(candidate)\n return candidate\n}\n\nfunction isIsoDate(value: string): boolean {\n return /^\\d{4}-\\d{2}-\\d{2}$/.test(value) && !Number.isNaN(Date.parse(value))\n}\n\nfunction isIsoDateTime(value: string): boolean {\n return (\n /^\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?$/.test(\n value\n ) && !Number.isNaN(Date.parse(value))\n )\n}\n\nfunction isUrl(value: string): boolean {\n try {\n const url = new URL(value)\n return url.protocol === \"http:\" || url.protocol === \"https:\"\n } catch {\n return false\n }\n}\n\nfunction inferType(values: string[]): EidosFileCsvFieldType {\n const populated = values.map((value) => value.trim()).filter(Boolean)\n if (populated.length === 0) return \"text\"\n if (populated.every((value) => /^(?:true|false)$/i.test(value))) {\n return \"checkbox\"\n }\n if (\n populated.every((value) => value !== \"\" && Number.isFinite(Number(value)))\n ) {\n return \"number\"\n }\n if (populated.every(isIsoDate)) return \"date\"\n if (populated.every(isIsoDateTime)) return \"datetime\"\n if (populated.every(isUrl)) return \"url\"\n return \"text\"\n}\n\nfunction defaultTableName(fileName: string): string {\n const withoutExtension = fileName.replace(/\\.[^.]+$/, \"\").trim()\n return withoutExtension || \"Imported table\"\n}\n\nfunction buildColumns(\n header: string[],\n rows: string[][]\n): EidosFileCsvImportColumn[] {\n const usedNames = new Set<string>()\n const usedColumns = new Set<string>([\"title\"])\n return header.map((sourceName, sourceIndex) => {\n const name = uniqueName(sourceName, usedNames, `Column ${sourceIndex + 1}`)\n if (sourceIndex === 0) {\n return {\n sourceIndex,\n sourceName,\n name,\n columnName: \"title\",\n type: \"title\",\n }\n }\n return {\n sourceIndex,\n sourceName,\n name,\n columnName: columnIdentifier(name, sourceIndex, usedColumns),\n type: inferType(\n rows\n .slice(0, EIDOS_FILE_CSV_INFERENCE_ROW_COUNT)\n .map((row) => row[sourceIndex] ?? \"\")\n ),\n }\n })\n}\n\nexport function planEidosFileCsvImport(\n file: { name: string; content: string },\n options: EidosFileCsvImportOptions = {}\n): EidosFileCsvImportPlan {\n const { plan, parsed } = buildImportPlan(file, options)\n parsed.rows.forEach((row, rowIndex) =>\n eidosFileCsvRowToEidosFileRow(row, rowIndex + 2, plan)\n )\n return plan\n}\n\nexport function prepareEidosFileCsvImport(\n file: { name: string; content: string },\n options: EidosFileCsvImportOptions = {}\n): { plan: EidosFileCsvImportPlan; rows: EidosFileRow[] } {\n const { plan, parsed } = buildImportPlan(file, options)\n return {\n plan,\n rows: parsed.rows.map((row, rowIndex) =>\n eidosFileCsvRowToEidosFileRow(row, rowIndex + 2, plan)\n ),\n }\n}\n\nexport function importEidosFileCsv(\n eidosFile: EidosFileRuntime,\n file: { name: string; content: string },\n options: EidosFileCsvImportOptions = {}\n): EidosFileCsvImportResult {\n const { plan, rows } = prepareEidosFileCsvImport(file, options)\n return eidosFile.connection.transaction(() => {\n const table = eidosFile.createTable({\n name: plan.tableName,\n fields: plan.columns.flatMap((column) =>\n column.type === \"title\"\n ? []\n : [\n {\n name: column.name,\n columnName: column.columnName,\n type: column.type,\n },\n ]\n ),\n })\n eidosFile.updateField(table.id, \"title\", { name: plan.columns[0].name })\n if (rows.length > 0) eidosFile.insertImportedRows(table.id, rows)\n return {\n table,\n importedRowCount: rows.length,\n skippedRowCount: plan.skippedRowCount,\n }\n })\n}\n\nfunction buildImportPlan(\n file: { name: string; content: string },\n options: EidosFileCsvImportOptions\n): { plan: EidosFileCsvImportPlan; parsed: ParsedCsv } {\n const parsed = parseCsv(file.content)\n const plan = createEidosFileCsvImportPlan(\n {\n fileName: file.name,\n header: parsed.header,\n inferenceRows: parsed.rows,\n rowCount: parsed.rows.length,\n skippedRowCount: parsed.skippedRowCount,\n sampleRows: parsed.rows.slice(0, EIDOS_FILE_CSV_PREVIEW_ROW_COUNT),\n issues: parsed.issues,\n },\n options\n )\n return { plan, parsed }\n}\n\nexport interface EidosFileCsvImportPlanSource {\n fileName: string\n header: string[]\n inferenceRows: string[][]\n rowCount: number\n skippedRowCount: number\n sampleRows: string[][]\n issues: EidosFileCsvImportIssue[]\n}\n\nexport function createEidosFileCsvImportPlan(\n source: EidosFileCsvImportPlanSource,\n options: EidosFileCsvImportOptions = {}\n): EidosFileCsvImportPlan {\n const columns = buildColumns(source.header, source.inferenceRows)\n const overrides = new Map(\n (options.columns ?? []).map((override) => [override.sourceIndex, override])\n )\n for (const column of columns) {\n const override = overrides.get(column.sourceIndex)\n if (!override) continue\n if (override.name !== undefined) {\n const name = override.name.trim()\n if (!name) {\n throw new EidosFileError(\n \"invalid-csv\",\n \"CSV field names cannot be empty\"\n )\n }\n column.name = name\n }\n if (column.type !== \"title\" && override.type) column.type = override.type\n }\n const tableName =\n options.tableName?.trim() || defaultTableName(source.fileName)\n return {\n fileName: source.fileName,\n tableName,\n rowCount: source.rowCount,\n skippedRowCount: source.skippedRowCount,\n columns,\n sampleRows: source.sampleRows,\n issues: source.issues,\n }\n}\n\nfunction convertValue(\n value: string,\n type: EidosFileCsvImportColumn[\"type\"],\n rowNumber: number,\n fieldName: string\n): EidosFileRow[string] {\n const trimmed = value.trim()\n if (!trimmed) return null\n if (type === \"number\") {\n const number = Number(trimmed)\n if (!Number.isFinite(number)) {\n throw new EidosFileError(\n \"invalid-csv\",\n `CSV row ${rowNumber}, field “${fieldName}” is not a number`\n )\n }\n return number\n }\n if (type === \"checkbox\") {\n if (!/^(?:true|false)$/i.test(trimmed)) {\n throw new EidosFileError(\n \"invalid-csv\",\n `CSV row ${rowNumber}, field “${fieldName}” is not true or false`\n )\n }\n return /^true$/i.test(trimmed) ? 1 : 0\n }\n return value\n}\n\nexport function eidosFileCsvRowToEidosFileRow(\n row: string[],\n rowNumber: number,\n plan: EidosFileCsvImportPlan\n): EidosFileRow {\n return Object.fromEntries(\n plan.columns.map((column) => [\n column.columnName,\n convertValue(\n row[column.sourceIndex] ?? \"\",\n column.type,\n rowNumber,\n column.name\n ),\n ])\n )\n}\n\nexport function parseEidosFileCsvRows(\n file: { name: string; content: string },\n plan: EidosFileCsvImportPlan\n): EidosFileRow[] {\n return parseCsv(file.content).rows.map((row, rowIndex) =>\n eidosFileCsvRowToEidosFileRow(row, rowIndex + 2, plan)\n )\n}\n"],"mappings":";;;AAwBA,MAAa,mCAAmC;AAChD,MAAa,qCAAqC;AAElD,SAAS,cAAc,OAAuB;AAC5C,QAAO,WAAW,KAAK,MAAM,GAAG,IAAI,MAAM,QAAQ,MAAM,OAAK,CAAC,KAAK;;AAGrE,SAAgB,yBAAyB,QAAmC;AAC1E,QAAO,GAAG,OAAO,IAAI,cAAc,CAAC,KAAK,IAAI,CAAC;;AAGhD,SAAgB,yBACd,SACQ;AACR,QAAO,yBAAyB,QAAQ,KAAK,WAAW,OAAO,KAAK,CAAC;;AAGvE,SAAgB,6BACd,QACA,SAC+B;CAC/B,MAAM,iBAAiB,IAAI,IACzB,OAAO,KAAK,UAAU,CAAC,MAAM,iBAAiB,MAAM,CAAC,CACtD;CACD,MAAM,iBAAiB,QAAQ,KAAK,WAAW;EAC7C,MAAM,QAA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