@eidos.space/eidos-file 0.1.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.
@@ -0,0 +1,66 @@
1
+ # Eidos File developer platform
2
+
3
+ This document records the implementation audit behind the public package
4
+ boundary. It describes current code, not a future app SDK.
5
+
6
+ ## What “file” means in Eidos today
7
+
8
+ | Area | Current responsibility | Public-platform decision |
9
+ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
10
+ | File-based Space | A folder is the source of truth; `@eidos.space/file-space` reads, writes, watches, previews, and indexes Markdown and binary files | Remains a Node/Desktop Space runtime. It is not part of the Eidos File SDK |
11
+ | File handlers | Installed extension contributions select editors for Markdown, code, media, and other paths | Remains the Eidos extension system. Public React views use a separate trusted registry |
12
+ | Eidos File | A `.eidos` SQLite database with portable tables, fields, views, relations, queries, and mutations | Owned by `@eidos.space/eidos-file` |
13
+ | Browser editor | File picker/import fallback, SQLite WASM, save state, conflict checks, and recovery | Reusable lifecycle moved behind `@eidos.space/eidos-file/browser` and `EidosFileSession` |
14
+ | Desktop editor | File Space services and Electron-owned filesystem access provide an app-specific data source | Stays behind the same public `EidosFileDataSource`; IPC is never public |
15
+ | React editor | Grid, Gallery, Kanban, view routing, selection, commands, and host theme | Owned by `@eidos.space/eidos-file-ui` |
16
+
17
+ ## Coupling audit
18
+
19
+ - `@eidos.space/eidos-file` main entry is framework-agnostic and browser-safe.
20
+ `better-sqlite3` and SQLite WASM are isolated to explicit subpaths.
21
+ - `@eidos.space/eidos-file-ui` depends on React and DOM APIs, but not Eidos
22
+ routes, Zustand stores, Electron, or application aliases.
23
+ - `@eidos.space/file-space` uses Node filesystem capabilities and remains
24
+ unsuitable for browser embedding.
25
+ - Existing Space file handlers receive Eidos extension context and app-owned
26
+ filesystem APIs. They are not interchangeable with trusted React views.
27
+ - Asset previews are host resolvers. Views receive URLs, never unrestricted
28
+ filesystem access.
29
+
30
+ ## Minimal public model
31
+
32
+ ```text
33
+ EidosFileHandle ──read/write/CAS──> EidosFileSession
34
+ │
35
+ EidosFileRuntimeAdapter
36
+ │
37
+ EidosFileDataSource
38
+ │
39
+ React View Host
40
+ ```
41
+
42
+ The handle owns descriptor identity, permissions, and persistence. The runtime
43
+ owns format validation and data semantics. The session owns asynchronous
44
+ lifecycle and recovery. The view host owns selection, local state, commands,
45
+ theme, and rendering.
46
+
47
+ ## First-release scope
48
+
49
+ Included:
50
+
51
+ - `.eidos` format validation, migration, query, paging, and mutation;
52
+ - browser import, native picker, save, Save As, conflict, recovery, and cleanup;
53
+ - Node/Electron `better-sqlite3` entry;
54
+ - typed React provider, hooks, view host, Grid, optional Gallery/Kanban plugins,
55
+ and trusted custom view registration;
56
+ - light/dark theme tokens and precompiled standalone CSS.
57
+
58
+ Out of scope:
59
+
60
+ - the complete Eidos app shell or Space navigation;
61
+ - Markdown/Base format ownership and Base UI;
62
+ - arbitrary File Space handlers or extension installation;
63
+ - untrusted code execution, remote file upload, sync, collaboration, or auth;
64
+ - hidden access to Eidos stores, routes, IPC, filesystem, or database singletons;
65
+ - a generic document framework for formats that do not share Eidos File
66
+ runtime semantics.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 mayneyao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # `@eidos.space/eidos-file`
2
+
3
+ Headless runtime and host contracts for portable Eidos `.eidos` files.
4
+
5
+ An Eidos File is a normal SQLite database containing portable table, field,
6
+ view, and relation metadata. The package does not depend on the Eidos app,
7
+ Zustand stores, routes, Electron IPC, or a database singleton.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @eidos.space/eidos-file@0.1.0
13
+ ```
14
+
15
+ Add `@eidos.space/eidos-file-ui@0.1.0` when rendering React views.
16
+
17
+ ## Browser host
18
+
19
+ The browser entry includes a SQLite WASM runtime, native file picker adapter,
20
+ copy-mode fallback, conflict detection, and IndexedDB recovery store.
21
+
22
+ ```ts
23
+ import { EidosFileSession } from "@eidos.space/eidos-file"
24
+ import {
25
+ EidosFileBrowserRuntime,
26
+ IndexedDbEidosFileRecoveryStore,
27
+ openBrowserEidosFile,
28
+ pickBrowserEidosFile,
29
+ } from "@eidos.space/eidos-file/browser"
30
+
31
+ const session = new EidosFileSession(
32
+ new EidosFileBrowserRuntime(),
33
+ new IndexedDbEidosFileRecoveryStore()
34
+ )
35
+
36
+ const direct = await pickBrowserEidosFile()
37
+ const imported = fileInput.files?.[0]
38
+ ? await openBrowserEidosFile(fileInput.files[0])
39
+ : null
40
+ const handle = direct ?? imported
41
+
42
+ if (handle) await session.open(handle)
43
+ ```
44
+
45
+ SQLite WASM uses WebAssembly and top-level await. A Vite host should enable the
46
+ same two standard plugins:
47
+
48
+ ```ts
49
+ import { defineConfig } from "vite"
50
+ import topLevelAwait from "vite-plugin-top-level-await"
51
+ import wasm from "vite-plugin-wasm"
52
+
53
+ export default defineConfig({
54
+ plugins: [wasm(), topLevelAwait()],
55
+ optimizeDeps: { exclude: ["@sqlite.org/sqlite-wasm"] },
56
+ })
57
+ ```
58
+
59
+ Call `session.markDirty()` after a committed mutation. `checkpoint()` stores a
60
+ recoverable working copy. `save()` exports an integrity-checked database and
61
+ performs a compare-and-swap write against the revision observed at open time.
62
+
63
+ ```ts
64
+ import { EidosFileHostError } from "@eidos.space/eidos-file"
65
+
66
+ session.markDirty()
67
+ await session.checkpoint()
68
+
69
+ try {
70
+ await session.save()
71
+ } catch (error) {
72
+ if (error instanceof EidosFileHostError && error.code === "conflict") {
73
+ // Offer reload, forced overwrite, or Save As. Do not silently choose.
74
+ }
75
+ }
76
+ ```
77
+
78
+ Chromium-based browsers can write to the original file after user permission.
79
+ Other browsers open an imported copy; hosts can offer Save As when supported or
80
+ `downloadEidosFile()` as the fallback. File bytes stay in the browser.
81
+
82
+ ## Node and Electron
83
+
84
+ The optional `better-sqlite3` entry owns native file access. The main entry
85
+ remains browser-safe and works against the small `EidosFileConnection`
86
+ interface.
87
+
88
+ ```ts
89
+ import { createEidosFile } from "@eidos.space/eidos-file/better-sqlite3"
90
+
91
+ const file = createEidosFile("tasks.eidos", {
92
+ title: "Tasks",
93
+ defaultTable: { name: "Tasks" },
94
+ })
95
+
96
+ file.insertRow(file.info().defaultTableId!, { title: "Ship Eidos File" })
97
+ file.close()
98
+ ```
99
+
100
+ ## Public boundaries
101
+
102
+ - `EidosFileDescriptor` is adapter-owned identity, metadata, size, and an
103
+ opaque revision token.
104
+ - `EidosFileHandle` owns reading, permissions, and optional verified writes.
105
+ - `EidosFileRuntimeAdapter` turns bytes into an `EidosFileDocument`.
106
+ - `EidosFileDataSource` is the async paging and mutation contract consumed by
107
+ views.
108
+ - `EidosFileSession` owns open, dirty, saving, conflict, error, recovery, and
109
+ cleanup states.
110
+ - `EidosFileHandlerRegistry` matches file types. It does not install or execute
111
+ extensions.
112
+
113
+ See [DEVELOPER_PLATFORM.md](./DEVELOPER_PLATFORM.md) for the audited product
114
+ boundary and first-release scope.
115
+
116
+ ## Security
117
+
118
+ Adapters are the authority boundary. A view never receives SQLite, a native
119
+ file handle, the browser picker, Electron IPC, or host application state.
120
+ React views are trusted application code, not sandboxed extensions. A host must
121
+ review and statically import them just like any other dependency.
122
+
123
+ ## Format notes
124
+
125
+ Files remain valid SQLite databases and can be inspected with ordinary SQLite
126
+ tools. Gallery and Kanban query indexes are disposable SQLite indexes maintained
127
+ by the runtime; they are not Eidos metadata or user data.
@@ -0,0 +1,32 @@
1
+ import { _t as EidosFileRunResult, a as CreateEidosFileOptions, gt as EidosFileConnection, lt as EidosFileValidationResult, t as EidosFileRuntime, vt as EidosFileSqlParams } from "./runtime-C3bstvB8.mjs";
2
+ import Database from "better-sqlite3";
3
+
4
+ //#region src/better-sqlite3.d.ts
5
+ interface BetterSqlite3EidosFileConnectionOptions {
6
+ statementCacheSize?: number;
7
+ }
8
+ declare class BetterSqlite3EidosFileConnection implements EidosFileConnection {
9
+ readonly database: Database.Database;
10
+ private readonly statements;
11
+ private readonly statementCacheSize;
12
+ constructor(database: Database.Database, options?: BetterSqlite3EidosFileConnectionOptions);
13
+ private prepare;
14
+ private clearStatements;
15
+ exec(sql: string): void;
16
+ query<T extends object>(sql: string, params?: EidosFileSqlParams): T[];
17
+ get<T extends object>(sql: string, params?: EidosFileSqlParams): T | undefined;
18
+ run(sql: string, params?: EidosFileSqlParams): EidosFileRunResult;
19
+ runMany(sql: string, parameterSets: readonly EidosFileSqlParams[]): void;
20
+ transaction<T>(operation: () => T): T;
21
+ close(): void;
22
+ }
23
+ declare function hasSqliteHeader(filePath: string): boolean;
24
+ declare function createEidosFile(filePath: string, options?: CreateEidosFileOptions): EidosFileRuntime;
25
+ declare function openEidosFile(filePath: string, options?: {
26
+ migrate?: boolean;
27
+ readonly?: boolean;
28
+ }): EidosFileRuntime;
29
+ declare function inspectEidosFile(filePath: string): EidosFileValidationResult;
30
+ //#endregion
31
+ export { BetterSqlite3EidosFileConnection, BetterSqlite3EidosFileConnectionOptions, createEidosFile, hasSqliteHeader, inspectEidosFile, openEidosFile };
32
+ //# sourceMappingURL=better-sqlite3.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"better-sqlite3.d.mts","names":[],"sources":["../src/better-sqlite3.ts"],"mappings":";;;;UAmBiB,uCAAA;EACf,kBAAA;AAAA;AAAA,cAGW,gCAAA,YAA4C,mBAAA;EAAA,SAQ5C,QAAA,EAAU,QAAA,CAAS,QAAA;EAAA,iBAPb,UAAA;EAAA,iBAIA,kBAAA;cAGN,QAAA,EAAU,QAAA,CAAS,QAAA,EAC5B,OAAA,GAAS,uCAAA;EAAA,QASH,OAAA;EAAA,QAiBA,eAAA;EAIR,IAAA,CAAK,GAAA;EAKL,KAAA,kBAAA,CAAwB,GAAA,UAAa,MAAA,GAAQ,kBAAA,GAA0B,CAAA;EAIvE,GAAA,kBAAA,CACE,GAAA,UACA,MAAA,GAAQ,kBAAA,GACP,CAAA;EAIH,GAAA,CAAI,GAAA,UAAa,MAAA,GAAQ,kBAAA,GAA0B,kBAAA;EAInD,OAAA,CAAQ,GAAA,UAAa,aAAA,WAAwB,kBAAA;EAK7C,WAAA,GAAA,CAAe,SAAA,QAAiB,CAAA,GAAI,CAAA;EAIpC,KAAA,CAAA;AAAA;AAAA,iBAMc,eAAA,CAAgB,QAAA;AAAA,iBAchB,eAAA,CACd,QAAA,UACA,OAAA,GAAS,sBAAA,GACR,gBAAA;AAAA,iBAsBa,aAAA,CACd,QAAA,UACA,OAAA;EAAW,OAAA;EAAmB,QAAA;AAAA,IAC7B,gBAAA;AAAA,iBAmDa,gBAAA,CAAiB,QAAA,WAAD,yBAAA"}
@@ -0,0 +1,137 @@
1
+ import { v as EidosFileError } from "./relation-values-B0JhHBjZ.mjs";
2
+ import { C as EIDOS_FILE_EXTENSION, P as SQLITE_HEADER, d as migrateEidosFileSchema, n as validateEidosFile, p as initializeEidosFileSchema, t as EidosFileRuntime } from "./runtime-CWC5y95G.mjs";
3
+ import { closeSync, existsSync, openSync, readSync, statSync } from "node:fs";
4
+ import path from "node:path";
5
+ import Database from "better-sqlite3";
6
+ //#region src/better-sqlite3.ts
7
+ const DEFAULT_STATEMENT_CACHE_SIZE = 128;
8
+ var BetterSqlite3EidosFileConnection = class {
9
+ statements = /* @__PURE__ */ new Map();
10
+ statementCacheSize;
11
+ constructor(database, options = {}) {
12
+ this.database = database;
13
+ const requestedSize = options.statementCacheSize;
14
+ this.statementCacheSize = typeof requestedSize === "number" && Number.isFinite(requestedSize) ? Math.max(0, Math.trunc(requestedSize)) : DEFAULT_STATEMENT_CACHE_SIZE;
15
+ }
16
+ prepare(sql) {
17
+ const cached = this.statements.get(sql);
18
+ if (cached) {
19
+ this.statements.delete(sql);
20
+ this.statements.set(sql, cached);
21
+ return cached;
22
+ }
23
+ const statement = this.database.prepare(sql);
24
+ if (this.statementCacheSize === 0) return statement;
25
+ this.statements.set(sql, statement);
26
+ if (this.statements.size > this.statementCacheSize) {
27
+ const oldest = this.statements.keys().next().value;
28
+ if (typeof oldest === "string") this.statements.delete(oldest);
29
+ }
30
+ return statement;
31
+ }
32
+ clearStatements() {
33
+ this.statements.clear();
34
+ }
35
+ exec(sql) {
36
+ this.clearStatements();
37
+ this.database.exec(sql);
38
+ }
39
+ query(sql, params = []) {
40
+ return this.prepare(sql).all(...params);
41
+ }
42
+ get(sql, params = []) {
43
+ return this.prepare(sql).get(...params);
44
+ }
45
+ run(sql, params = []) {
46
+ return this.prepare(sql).run(...params);
47
+ }
48
+ runMany(sql, parameterSets) {
49
+ const statement = this.prepare(sql);
50
+ for (const params of parameterSets) statement.run(...params);
51
+ }
52
+ transaction(operation) {
53
+ return this.database.transaction(operation)();
54
+ }
55
+ close() {
56
+ this.clearStatements();
57
+ this.database.close();
58
+ }
59
+ };
60
+ function hasSqliteHeader(filePath) {
61
+ if (!existsSync(filePath) || statSync(filePath).size < 16) return false;
62
+ const descriptor = openSync(filePath, "r");
63
+ try {
64
+ const header = Buffer.alloc(SQLITE_HEADER.length);
65
+ readSync(descriptor, header, 0, header.length, 0);
66
+ return header.toString("binary") === SQLITE_HEADER;
67
+ } finally {
68
+ closeSync(descriptor);
69
+ }
70
+ }
71
+ function createEidosFile(filePath, options = {}) {
72
+ assertEidosFileExtension(filePath);
73
+ if (existsSync(filePath) && statSync(filePath).size > 0) throw new EidosFileError("file-exists", `Eidos File already exists: ${filePath}`);
74
+ const connection = new BetterSqlite3EidosFileConnection(new Database(filePath));
75
+ try {
76
+ connection.exec("PRAGMA foreign_keys = ON; PRAGMA journal_mode = DELETE;");
77
+ initializeEidosFileSchema(connection, options);
78
+ const runtime = new EidosFileRuntime(connection, true);
79
+ if (options.defaultTable) runtime.createTable(options.defaultTable);
80
+ return runtime;
81
+ } catch (error) {
82
+ connection.close();
83
+ throw error;
84
+ }
85
+ }
86
+ function openEidosFile(filePath, options = {}) {
87
+ assertEidosFileExtension(filePath);
88
+ if (!existsSync(filePath)) throw new EidosFileError("file-not-found", `Eidos File not found: ${filePath}`);
89
+ if (!hasSqliteHeader(filePath)) throw new EidosFileError("invalid-sqlite", `Not a SQLite file: ${filePath}`);
90
+ const connection = new BetterSqlite3EidosFileConnection(new Database(filePath, {
91
+ fileMustExist: true,
92
+ readonly: options.readonly ?? false
93
+ }));
94
+ try {
95
+ connection.exec("PRAGMA foreign_keys = ON");
96
+ const initial = validateEidosFile(connection);
97
+ const onlyMigrationWarnings = initial.errors.length === 0 && initial.warnings.some((warning) => warning.code === "schema-migration-available");
98
+ if (options.migrate && !options.readonly && onlyMigrationWarnings) migrateEidosFileSchema(connection);
99
+ const result = validateEidosFile(connection);
100
+ if (!result.valid) throw new EidosFileError("not-eidos-file", result.errors.map((issue) => issue.message).join("; "));
101
+ const runtime = new EidosFileRuntime(connection, true);
102
+ if (options.migrate && !options.readonly) runtime.optimizeViewQueries();
103
+ return runtime;
104
+ } catch (error) {
105
+ connection.close();
106
+ throw error;
107
+ }
108
+ }
109
+ function assertEidosFileExtension(filePath) {
110
+ if (path.extname(filePath).toLowerCase() === ".eidos") return;
111
+ throw new EidosFileError("invalid-identifier", `Eidos Files must use the ${EIDOS_FILE_EXTENSION} extension`);
112
+ }
113
+ function inspectEidosFile(filePath) {
114
+ if (!hasSqliteHeader(filePath)) return {
115
+ valid: false,
116
+ metadata: null,
117
+ tables: [],
118
+ errors: [{
119
+ code: "invalid-sqlite",
120
+ message: "Not a SQLite file"
121
+ }],
122
+ warnings: []
123
+ };
124
+ const connection = new BetterSqlite3EidosFileConnection(new Database(filePath, {
125
+ fileMustExist: true,
126
+ readonly: true
127
+ }));
128
+ try {
129
+ return validateEidosFile(connection);
130
+ } finally {
131
+ connection.close();
132
+ }
133
+ }
134
+ //#endregion
135
+ export { BetterSqlite3EidosFileConnection, createEidosFile, hasSqliteHeader, inspectEidosFile, openEidosFile };
136
+
137
+ //# sourceMappingURL=better-sqlite3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"better-sqlite3.mjs","names":[],"sources":["../src/better-sqlite3.ts"],"sourcesContent":["import { existsSync, openSync, closeSync, readSync, statSync } from \"node:fs\"\nimport path from \"node:path\"\nimport Database from \"better-sqlite3\"\n\nimport type {\n EidosFileConnection,\n EidosFileRunResult,\n EidosFileSqlParams,\n} from \"./connection\"\nimport { EIDOS_FILE_EXTENSION, SQLITE_HEADER } from \"./constants\"\nimport { EidosFileError } from \"./errors\"\nimport { migrateEidosFileSchema } from \"./migrations\"\nimport { EidosFileRuntime } from \"./runtime\"\nimport { initializeEidosFileSchema } from \"./schema\"\nimport type { CreateEidosFileOptions } from \"./types\"\nimport { validateEidosFile } from \"./validation\"\n\nconst DEFAULT_STATEMENT_CACHE_SIZE = 128\n\nexport interface BetterSqlite3EidosFileConnectionOptions {\n statementCacheSize?: number\n}\n\nexport class BetterSqlite3EidosFileConnection implements EidosFileConnection {\n private readonly statements = new Map<\n string,\n Database.Statement<unknown[], unknown>\n >()\n private readonly statementCacheSize: number\n\n constructor(\n readonly database: Database.Database,\n options: BetterSqlite3EidosFileConnectionOptions = {}\n ) {\n const requestedSize = options.statementCacheSize\n this.statementCacheSize =\n typeof requestedSize === \"number\" && Number.isFinite(requestedSize)\n ? Math.max(0, Math.trunc(requestedSize))\n : DEFAULT_STATEMENT_CACHE_SIZE\n }\n\n private prepare(sql: string): Database.Statement<unknown[], unknown> {\n const cached = this.statements.get(sql)\n if (cached) {\n this.statements.delete(sql)\n this.statements.set(sql, cached)\n return cached\n }\n const statement = this.database.prepare(sql)\n if (this.statementCacheSize === 0) return statement\n this.statements.set(sql, statement)\n if (this.statements.size > this.statementCacheSize) {\n const oldest = this.statements.keys().next().value\n if (typeof oldest === \"string\") this.statements.delete(oldest)\n }\n return statement\n }\n\n private clearStatements(): void {\n this.statements.clear()\n }\n\n exec(sql: string): void {\n this.clearStatements()\n this.database.exec(sql)\n }\n\n query<T extends object>(sql: string, params: EidosFileSqlParams = []): T[] {\n return this.prepare(sql).all(...params) as T[]\n }\n\n get<T extends object>(\n sql: string,\n params: EidosFileSqlParams = []\n ): T | undefined {\n return this.prepare(sql).get(...params) as T | undefined\n }\n\n run(sql: string, params: EidosFileSqlParams = []): EidosFileRunResult {\n return this.prepare(sql).run(...params)\n }\n\n runMany(sql: string, parameterSets: readonly EidosFileSqlParams[]): void {\n const statement = this.prepare(sql)\n for (const params of parameterSets) statement.run(...params)\n }\n\n transaction<T>(operation: () => T): T {\n return this.database.transaction(operation)()\n }\n\n close(): void {\n this.clearStatements()\n this.database.close()\n }\n}\n\nexport function hasSqliteHeader(filePath: string): boolean {\n if (!existsSync(filePath) || statSync(filePath).size < SQLITE_HEADER.length) {\n return false\n }\n const descriptor = openSync(filePath, \"r\")\n try {\n const header = Buffer.alloc(SQLITE_HEADER.length)\n readSync(descriptor, header, 0, header.length, 0)\n return header.toString(\"binary\") === SQLITE_HEADER\n } finally {\n closeSync(descriptor)\n }\n}\n\nexport function createEidosFile(\n filePath: string,\n options: CreateEidosFileOptions = {}\n): EidosFileRuntime {\n assertEidosFileExtension(filePath)\n if (existsSync(filePath) && statSync(filePath).size > 0) {\n throw new EidosFileError(\n \"file-exists\",\n `Eidos File already exists: ${filePath}`\n )\n }\n const database = new Database(filePath)\n const connection = new BetterSqlite3EidosFileConnection(database)\n try {\n connection.exec(\"PRAGMA foreign_keys = ON; PRAGMA journal_mode = DELETE;\")\n initializeEidosFileSchema(connection, options)\n const runtime = new EidosFileRuntime(connection, true)\n if (options.defaultTable) runtime.createTable(options.defaultTable)\n return runtime\n } catch (error) {\n connection.close()\n throw error\n }\n}\n\nexport function openEidosFile(\n filePath: string,\n options: { migrate?: boolean; readonly?: boolean } = {}\n): EidosFileRuntime {\n assertEidosFileExtension(filePath)\n if (!existsSync(filePath)) {\n throw new EidosFileError(\n \"file-not-found\",\n `Eidos File not found: ${filePath}`\n )\n }\n if (!hasSqliteHeader(filePath)) {\n throw new EidosFileError(\"invalid-sqlite\", `Not a SQLite file: ${filePath}`)\n }\n const database = new Database(filePath, {\n fileMustExist: true,\n readonly: options.readonly ?? false,\n })\n const connection = new BetterSqlite3EidosFileConnection(database)\n try {\n connection.exec(\"PRAGMA foreign_keys = ON\")\n const initial = validateEidosFile(connection)\n const onlyMigrationWarnings =\n initial.errors.length === 0 &&\n initial.warnings.some(\n (warning) => warning.code === \"schema-migration-available\"\n )\n if (options.migrate && !options.readonly && onlyMigrationWarnings) {\n migrateEidosFileSchema(connection)\n }\n const result = validateEidosFile(connection)\n if (!result.valid) {\n throw new EidosFileError(\n \"not-eidos-file\",\n result.errors.map((issue) => issue.message).join(\"; \")\n )\n }\n const runtime = new EidosFileRuntime(connection, true)\n if (options.migrate && !options.readonly) runtime.optimizeViewQueries()\n return runtime\n } catch (error) {\n connection.close()\n throw error\n }\n}\n\nfunction assertEidosFileExtension(filePath: string): void {\n if (path.extname(filePath).toLowerCase() === EIDOS_FILE_EXTENSION) return\n throw new EidosFileError(\n \"invalid-identifier\",\n `Eidos Files must use the ${EIDOS_FILE_EXTENSION} extension`\n )\n}\n\nexport function inspectEidosFile(filePath: string) {\n if (!hasSqliteHeader(filePath)) {\n return {\n valid: false,\n metadata: null,\n tables: [],\n errors: [{ code: \"invalid-sqlite\", message: \"Not a SQLite file\" }],\n warnings: [],\n }\n }\n const database = new Database(filePath, {\n fileMustExist: true,\n readonly: true,\n })\n const connection = new BetterSqlite3EidosFileConnection(database)\n try {\n return validateEidosFile(connection)\n } finally {\n connection.close()\n }\n}\n"],"mappings":";;;;;;AAiBA,MAAM,+BAA+B;AAMrC,IAAa,mCAAb,MAA6E;CAC3E,6BAA8B,IAAI,KAG/B;CACH;CAEA,YACE,UACA,UAAmD,EAAE,EACrD;AAFS,OAAA,WAAA;EAGT,MAAM,gBAAgB,QAAQ;AAC9B,OAAK,qBACH,OAAO,kBAAkB,YAAY,OAAO,SAAS,cAAc,GAC/D,KAAK,IAAI,GAAG,KAAK,MAAM,cAAc,CAAC,GACtC;;CAGR,QAAgB,KAAqD;EACnE,MAAM,SAAS,KAAK,WAAW,IAAI,IAAI;AACvC,MAAI,QAAQ;AACV,QAAK,WAAW,OAAO,IAAI;AAC3B,QAAK,WAAW,IAAI,KAAK,OAAO;AAChC,UAAO;;EAET,MAAM,YAAY,KAAK,SAAS,QAAQ,IAAI;AAC5C,MAAI,KAAK,uBAAuB,EAAG,QAAO;AAC1C,OAAK,WAAW,IAAI,KAAK,UAAU;AACnC,MAAI,KAAK,WAAW,OAAO,KAAK,oBAAoB;GAClD,MAAM,SAAS,KAAK,WAAW,MAAM,CAAC,MAAM,CAAC;AAC7C,OAAI,OAAO,WAAW,SAAU,MAAK,WAAW,OAAO,OAAO;;AAEhE,SAAO;;CAGT,kBAAgC;AAC9B,OAAK,WAAW,OAAO;;CAGzB,KAAK,KAAmB;AACtB,OAAK,iBAAiB;AACtB,OAAK,SAAS,KAAK,IAAI;;CAGzB,MAAwB,KAAa,SAA6B,EAAE,EAAO;AACzE,SAAO,KAAK,QAAQ,IAAI,CAAC,IAAI,GAA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;AACjE,KAAI;AACF,SAAO,kBAAkB,WAAW;WAC5B;AACR,aAAW,OAAO"}
@@ -0,0 +1,58 @@
1
+ import { $ as EidosFileRowsDeleteResult, A as EidosFileFilterValue, B as EidosFileOptionValueChange, C as EidosFileCsvImportResult, D as EidosFileFilterGroup, E as EidosFileFieldType, F as EidosFileFormulaPreviewSample, G as EidosFileRowMutationResult, H as EidosFileRelationValue, I as EidosFileFormulaProperty, J as EidosFileRowPageProjection, K as EidosFileRowPage, L as EidosFileLookupAggregate, M as EidosFileFormulaPreview, N as EidosFileFormulaPreviewDependency, O as EidosFileFilterOperator, P as EidosFileFormulaPreviewInput, Q as EidosFileRowValue, R as EidosFileLookupProperty, S as EidosFileCsvImportPlan, T as EidosFileFieldPlacement, U as EidosFileRow, V as EidosFileRelationProperty, W as EidosFileRowGroupCount, X as EidosFileRowRange, Y as EidosFileRowQuery, Z as EidosFileRowUpdate, _ as EidosFileCsvExportResult, _t as EidosFileRunResult, a as CreateEidosFileOptions, at as EidosFileStorageCodec, b as EidosFileCsvImportIssue, c as CreateEidosFileSourceFieldInput, ct as EidosFileValidationIssue, d as EidosFileColumnStatConfig, dt as EidosFileViewInfo, et as EidosFileRowsMutationResult, f as EidosFileColumnStatResult, ft as ImportEidosFileFieldInput, g as EidosFileCsvExportOptions, gt as EidosFileConnection, h as EidosFileCsvExportColumn, ht as UpdateEidosFileViewInput, i as CreateEidosFileLookupFieldInput, it as EidosFileSortDirection, j as EidosFileFormulaDisplayType, k as EidosFileFilterRule, l as CreateEidosFileTableInput, lt as EidosFileValidationResult, m as EidosFileCsvColumnOverride, mt as UpdateEidosFileTableInput, n as CreateEidosFileFieldInput, nt as EidosFileSnapshot, o as CreateEidosFileReferenceInput, ot as EidosFileTableInfo, p as EidosFileColumnStatType, pt as UpdateEidosFileFieldInput, q as EidosFileRowPageOptions, r as CreateEidosFileFormulaFieldInput, rt as EidosFileSort, s as CreateEidosFileRelationFieldInput, st as EidosFileTableSnapshot, tt as EidosFileSelectOption, u as CreateEidosFileViewInput, ut as EidosFileValueKind, v as EidosFileCsvFieldType, vt as EidosFileSqlParams, w as EidosFileFieldInfo, x as EidosFileCsvImportOptions, y as EidosFileCsvImportColumn, yt as EidosFileSqlPrimitive, z as EidosFileMetadata } from "./runtime-C3bstvB8.mjs";
2
+ import { E as EIDOS_FILE_FORMAT, T as EIDOS_FILE_EXTENSION, a as EidosFileHandle, d as EidosFileReadResult, f as EidosFileRecoverySnapshot, i as EidosFileDocument, k as EIDOS_FILE_MIME_TYPE, m as EidosFileRuntimeAdapter, p as EidosFileRecoveryStore, r as EidosFileDescriptor, s as EidosFileHostCapabilities, u as EidosFilePermissionState, x as EidosFileDataSource, y as EidosFileWriteOptions } from "./host-CqP1MeMK.mjs";
3
+
4
+ //#region src/browser.d.ts
5
+ declare global {
6
+ interface Window {
7
+ showOpenFilePicker?: (options?: OpenFilePickerOptions) => Promise<FileSystemFileHandle[]>;
8
+ showSaveFilePicker?: (options?: SaveFilePickerOptions) => Promise<FileSystemFileHandle>;
9
+ }
10
+ }
11
+ declare function supportsBrowserFileAccess(target?: Pick<Window, "showOpenFilePicker"> | undefined): boolean;
12
+ declare function supportsBrowserSaveAs(target?: Pick<Window, "showSaveFilePicker"> | undefined): boolean;
13
+ declare function digestEidosFileBytes(bytes: ArrayBuffer | Uint8Array): Promise<string>;
14
+ declare class BrowserEidosFileHandle implements EidosFileHandle {
15
+ private file;
16
+ readonly nativeHandle: FileSystemFileHandle | undefined;
17
+ readonly capabilities: EidosFileHostCapabilities;
18
+ private current;
19
+ private constructor();
20
+ static fromFile(file: File, nativeHandle?: FileSystemFileHandle): Promise<BrowserEidosFileHandle>;
21
+ descriptor(): Promise<EidosFileDescriptor>;
22
+ permission(): Promise<EidosFilePermissionState>;
23
+ requestPermission(): Promise<EidosFilePermissionState>;
24
+ read(options?: {
25
+ signal?: AbortSignal;
26
+ }): Promise<EidosFileReadResult>;
27
+ write(bytes: Uint8Array, options?: EidosFileWriteOptions): Promise<EidosFileDescriptor>;
28
+ }
29
+ declare function openBrowserEidosFile(file: File): Promise<BrowserEidosFileHandle>;
30
+ declare function openBrowserEidosFileHandle(handle: FileSystemFileHandle): Promise<BrowserEidosFileHandle>;
31
+ declare function pickBrowserEidosFile(): Promise<BrowserEidosFileHandle | null>;
32
+ declare function pickBrowserEidosFileDestination(suggestedName: string): Promise<BrowserEidosFileHandle | null>;
33
+ declare function downloadEidosFile(bytes: Uint8Array, suggestedName: string): void;
34
+ /**
35
+ * Browser runtime for small-to-medium files and embedders.
36
+ *
37
+ * It runs SQLite WASM in the current JavaScript realm. Hosts with long-running
38
+ * or very large workloads can put the same adapter behind a Worker without
39
+ * changing the data-source or view contracts.
40
+ */
41
+ declare class EidosFileBrowserRuntime implements EidosFileRuntimeAdapter {
42
+ open(read: EidosFileReadResult, options?: {
43
+ signal?: AbortSignal;
44
+ }): Promise<EidosFileDocument>;
45
+ }
46
+ declare class IndexedDbEidosFileRecoveryStore implements EidosFileRecoveryStore {
47
+ private readonly databaseName;
48
+ private readonly storeName;
49
+ constructor(databaseName?: string, storeName?: string);
50
+ load(id: string): Promise<EidosFileRecoverySnapshot | null>;
51
+ save(snapshot: EidosFileRecoverySnapshot): Promise<void>;
52
+ delete(id: string): Promise<void>;
53
+ private openDatabase;
54
+ private withStore;
55
+ }
56
+ //#endregion
57
+ export { BrowserEidosFileHandle, CreateEidosFileFieldInput, CreateEidosFileFormulaFieldInput, CreateEidosFileLookupFieldInput, CreateEidosFileOptions, CreateEidosFileReferenceInput, CreateEidosFileRelationFieldInput, CreateEidosFileSourceFieldInput, CreateEidosFileTableInput, CreateEidosFileViewInput, EIDOS_FILE_EXTENSION, EIDOS_FILE_FORMAT, EIDOS_FILE_MIME_TYPE, EidosFileBrowserRuntime, EidosFileColumnStatConfig, EidosFileColumnStatResult, EidosFileColumnStatType, EidosFileConnection, EidosFileCsvColumnOverride, EidosFileCsvExportColumn, EidosFileCsvExportOptions, EidosFileCsvExportResult, EidosFileCsvFieldType, EidosFileCsvImportColumn, EidosFileCsvImportIssue, EidosFileCsvImportOptions, EidosFileCsvImportPlan, EidosFileCsvImportResult, type EidosFileDataSource, type EidosFileDescriptor, type EidosFileDocument, EidosFileFieldInfo, EidosFileFieldPlacement, EidosFileFieldType, EidosFileFilterGroup, EidosFileFilterOperator, EidosFileFilterRule, EidosFileFilterValue, EidosFileFormulaDisplayType, EidosFileFormulaPreview, EidosFileFormulaPreviewDependency, EidosFileFormulaPreviewInput, EidosFileFormulaPreviewSample, EidosFileFormulaProperty, type EidosFileHandle, type EidosFileHostCapabilities, EidosFileLookupAggregate, EidosFileLookupProperty, EidosFileMetadata, EidosFileOptionValueChange, type EidosFilePermissionState, type EidosFileReadResult, type EidosFileRecoverySnapshot, type EidosFileRecoveryStore, EidosFileRelationProperty, EidosFileRelationValue, EidosFileRow, EidosFileRowGroupCount, EidosFileRowMutationResult, EidosFileRowPage, EidosFileRowPageOptions, EidosFileRowPageProjection, EidosFileRowQuery, EidosFileRowRange, EidosFileRowUpdate, EidosFileRowValue, EidosFileRowsDeleteResult, EidosFileRowsMutationResult, EidosFileRunResult, type EidosFileRuntimeAdapter, EidosFileSelectOption, EidosFileSnapshot, EidosFileSort, EidosFileSortDirection, EidosFileSqlParams, EidosFileSqlPrimitive, EidosFileStorageCodec, EidosFileTableInfo, EidosFileTableSnapshot, EidosFileValidationIssue, EidosFileValidationResult, EidosFileValueKind, EidosFileViewInfo, type EidosFileWriteOptions, ImportEidosFileFieldInput, IndexedDbEidosFileRecoveryStore, UpdateEidosFileFieldInput, UpdateEidosFileTableInput, UpdateEidosFileViewInput, digestEidosFileBytes, downloadEidosFile, openBrowserEidosFile, openBrowserEidosFileHandle, pickBrowserEidosFile, pickBrowserEidosFileDestination, supportsBrowserFileAccess, supportsBrowserSaveAs };
58
+ //# sourceMappingURL=browser.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.mts","names":[],"sources":["../src/browser.ts"],"mappings":";;;;QAmDQ,MAAA;EA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