@eidos.space/eidos-file 1.0.0 → 2.0.2
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 +17 -11
- package/FIELD-CONVERSION.md +75 -0
- package/README.md +18 -2
- package/dist/{adapter-contract-B3p-48Yb.d.mts → adapter-contract-CPhqAl4b.d.mts} +46 -65
- package/dist/adapter-contract-CPhqAl4b.d.mts.map +1 -0
- package/dist/better-sqlite3.d.mts +2 -2
- package/dist/better-sqlite3.d.mts.map +1 -1
- package/dist/better-sqlite3.mjs +13 -5
- package/dist/better-sqlite3.mjs.map +1 -1
- package/dist/browser.d.mts +4 -4
- package/dist/browser.mjs +3 -3
- package/dist/browser.mjs.map +1 -1
- package/dist/{csv-WEud-i_H.mjs → csv-CvzHNNGW.mjs} +48 -11
- package/dist/csv-CvzHNNGW.mjs.map +1 -0
- package/dist/csv.d.mts +4 -2
- package/dist/csv.d.mts.map +1 -1
- package/dist/csv.mjs +1 -1
- package/dist/index.d.mts +40 -14
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +578 -200
- package/dist/index.mjs.map +1 -1
- package/dist/node-sqlite.d.mts +111 -0
- package/dist/node-sqlite.d.mts.map +1 -0
- package/dist/node-sqlite.mjs +708 -0
- package/dist/node-sqlite.mjs.map +1 -0
- package/dist/{runtime-DCo5E0Kr.d.mts → runtime-CkL1OOJT.d.mts} +129 -7
- package/dist/runtime-CkL1OOJT.d.mts.map +1 -0
- package/dist/{runtime-CMdfE7Gx.mjs → runtime-qbuZMbV4.mjs} +674 -198
- package/dist/runtime-qbuZMbV4.mjs.map +1 -0
- package/dist/{select-options-DihMTuoa.mjs → select-options-Dr8XCYOS.mjs} +145 -80
- package/dist/select-options-Dr8XCYOS.mjs.map +1 -0
- package/dist/{sqlite-wasm-B86yaLG6.mjs → sqlite-wasm-fT8Z-5Ww.mjs} +34 -13
- package/dist/sqlite-wasm-fT8Z-5Ww.mjs.map +1 -0
- package/dist/system-metadata-merge-BaX38cp-.d.mts +77 -0
- package/dist/system-metadata-merge-BaX38cp-.d.mts.map +1 -0
- package/dist/system-metadata-merge-CjTqAwCi.mjs +819 -0
- package/dist/system-metadata-merge-CjTqAwCi.mjs.map +1 -0
- package/dist/{temporal-CVzLU63l.d.mts → temporal-ysCLNSub.d.mts} +8 -3
- package/dist/temporal-ysCLNSub.d.mts.map +1 -0
- package/package.json +10 -2
- package/dist/adapter-contract-B3p-48Yb.d.mts.map +0 -1
- package/dist/csv-WEud-i_H.mjs.map +0 -1
- package/dist/runtime-CMdfE7Gx.mjs.map +0 -1
- package/dist/runtime-DCo5E0Kr.d.mts.map +0 -1
- package/dist/select-options-DihMTuoa.mjs.map +0 -1
- package/dist/sqlite-wasm-B86yaLG6.mjs.map +0 -1
- package/dist/temporal-CVzLU63l.d.mts.map +0 -1
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import { M as EidosFileError } from "./select-options-Dr8XCYOS.mjs";
|
|
2
|
+
import { H as EIDOS_FILE_EXTENSION, ct as EidosAdapterError, ft as exactConnectionBindingCount, g as parseNonNegativeInt64, l as initializeEidosFileSchema, lt as assertExactConnectionBindings, m as MemoryByteSource, mt as sqlValueToNative, n as validateEidosFile, pt as nativeToSqlValue, rt as SQLITE_HEADER, t as EidosFileRuntime } from "./runtime-qbuZMbV4.mjs";
|
|
3
|
+
import { n as mergeEidosSystemMetadata } from "./system-metadata-merge-CjTqAwCi.mjs";
|
|
4
|
+
import { closeSync, existsSync, openSync, readSync, statSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { DatabaseSync, constants } from "node:sqlite";
|
|
7
|
+
//#region src/node-sqlite.ts
|
|
8
|
+
const DEFAULT_STATEMENT_CACHE_SIZE = 128;
|
|
9
|
+
const DEFAULT_BUSY_TIMEOUT_MS = 5e3;
|
|
10
|
+
const DEFAULT_MAX_RESULT_ROWS = 1e5;
|
|
11
|
+
const DEFAULT_MAX_RESULT_BYTES = 16 * 1024 * 1024;
|
|
12
|
+
const READ_ONLY_PRAGMAS = new Set([
|
|
13
|
+
"application_id",
|
|
14
|
+
"collation_list",
|
|
15
|
+
"compile_options",
|
|
16
|
+
"data_version",
|
|
17
|
+
"database_list",
|
|
18
|
+
"foreign_key_check",
|
|
19
|
+
"foreign_key_list",
|
|
20
|
+
"foreign_keys",
|
|
21
|
+
"function_list",
|
|
22
|
+
"index_info",
|
|
23
|
+
"index_list",
|
|
24
|
+
"index_xinfo",
|
|
25
|
+
"integrity_check",
|
|
26
|
+
"module_list",
|
|
27
|
+
"page_count",
|
|
28
|
+
"page_size",
|
|
29
|
+
"pragma_list",
|
|
30
|
+
"quick_check",
|
|
31
|
+
"table_info",
|
|
32
|
+
"table_list",
|
|
33
|
+
"table_xinfo",
|
|
34
|
+
"trusted_schema",
|
|
35
|
+
"user_version"
|
|
36
|
+
]);
|
|
37
|
+
const READ_ONLY_PRAGMAS_WITH_ARGUMENTS = new Set([
|
|
38
|
+
"foreign_key_check",
|
|
39
|
+
"foreign_key_list",
|
|
40
|
+
"index_info",
|
|
41
|
+
"index_list",
|
|
42
|
+
"index_xinfo",
|
|
43
|
+
"integrity_check",
|
|
44
|
+
"quick_check",
|
|
45
|
+
"table_info",
|
|
46
|
+
"table_xinfo"
|
|
47
|
+
]);
|
|
48
|
+
function electron43Database(database) {
|
|
49
|
+
return database;
|
|
50
|
+
}
|
|
51
|
+
function sqliteValue(value) {
|
|
52
|
+
if (typeof value === "bigint" && value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER)) return Number(value);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function sqliteRow(row) {
|
|
56
|
+
return Object.fromEntries(Object.entries(row).map(([key, value]) => [key, sqliteValue(value)]));
|
|
57
|
+
}
|
|
58
|
+
function nodeSqliteBindings(bindings) {
|
|
59
|
+
return bindings.map(sqlValueToNative);
|
|
60
|
+
}
|
|
61
|
+
function prepareObjectStatement(database, sql) {
|
|
62
|
+
const statement = database.prepare(sql);
|
|
63
|
+
statement.setReadBigInts(true);
|
|
64
|
+
statement.setAllowBareNamedParameters(false);
|
|
65
|
+
statement.setAllowUnknownNamedParameters(false);
|
|
66
|
+
return statement;
|
|
67
|
+
}
|
|
68
|
+
function prepareArrayStatement(database, sql) {
|
|
69
|
+
const statement = prepareObjectStatement(database, sql);
|
|
70
|
+
statement.setReturnArrays(true);
|
|
71
|
+
return statement;
|
|
72
|
+
}
|
|
73
|
+
function openDatabase(filePath, options = {}) {
|
|
74
|
+
return new DatabaseSync(filePath, {
|
|
75
|
+
allowExtension: false,
|
|
76
|
+
defensive: true,
|
|
77
|
+
enableDoubleQuotedStringLiterals: false,
|
|
78
|
+
enableForeignKeyConstraints: true,
|
|
79
|
+
readBigInts: true,
|
|
80
|
+
timeout: DEFAULT_BUSY_TIMEOUT_MS,
|
|
81
|
+
...options
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** Compatibility connection for the synchronous pre-1.0 EidosFileRuntime. */
|
|
85
|
+
var NodeSqliteEidosFileConnection = class {
|
|
86
|
+
capabilities = {
|
|
87
|
+
int64: true,
|
|
88
|
+
json1: true,
|
|
89
|
+
returning: true,
|
|
90
|
+
interrupt: false,
|
|
91
|
+
scalarFunctions: true
|
|
92
|
+
};
|
|
93
|
+
statements = /* @__PURE__ */ new Map();
|
|
94
|
+
statementCacheSize;
|
|
95
|
+
transactionDepth = 0;
|
|
96
|
+
savepointSequence = 0;
|
|
97
|
+
constructor(database, options = {}) {
|
|
98
|
+
this.database = database;
|
|
99
|
+
const requestedSize = options.statementCacheSize;
|
|
100
|
+
this.statementCacheSize = typeof requestedSize === "number" && Number.isFinite(requestedSize) ? Math.max(0, Math.trunc(requestedSize)) : DEFAULT_STATEMENT_CACHE_SIZE;
|
|
101
|
+
}
|
|
102
|
+
prepare(sql) {
|
|
103
|
+
const cached = this.statements.get(sql);
|
|
104
|
+
if (cached) {
|
|
105
|
+
this.statements.delete(sql);
|
|
106
|
+
this.statements.set(sql, cached);
|
|
107
|
+
return cached;
|
|
108
|
+
}
|
|
109
|
+
const statement = prepareObjectStatement(this.database, sql);
|
|
110
|
+
if (this.statementCacheSize === 0) return statement;
|
|
111
|
+
this.statements.set(sql, statement);
|
|
112
|
+
if (this.statements.size > this.statementCacheSize) {
|
|
113
|
+
const oldest = this.statements.keys().next().value;
|
|
114
|
+
if (typeof oldest === "string") this.statements.delete(oldest);
|
|
115
|
+
}
|
|
116
|
+
return statement;
|
|
117
|
+
}
|
|
118
|
+
clearStatements() {
|
|
119
|
+
this.statements.clear();
|
|
120
|
+
}
|
|
121
|
+
exec(sql) {
|
|
122
|
+
this.clearStatements();
|
|
123
|
+
this.database.exec(sql);
|
|
124
|
+
}
|
|
125
|
+
query(sql, params = []) {
|
|
126
|
+
return this.prepare(sql).all(...params).map(sqliteRow);
|
|
127
|
+
}
|
|
128
|
+
get(sql, params = []) {
|
|
129
|
+
const row = this.prepare(sql).get(...params);
|
|
130
|
+
return row ? sqliteRow(row) : void 0;
|
|
131
|
+
}
|
|
132
|
+
run(sql, params = []) {
|
|
133
|
+
const result = this.prepare(sql).run(...params);
|
|
134
|
+
return {
|
|
135
|
+
changes: Number(result.changes),
|
|
136
|
+
lastInsertRowid: result.lastInsertRowid
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
runMany(sql, parameterSets) {
|
|
140
|
+
const statement = this.prepare(sql);
|
|
141
|
+
for (const params of parameterSets) statement.run(...params);
|
|
142
|
+
}
|
|
143
|
+
registerFunction(name, operation, arity = operation.length) {
|
|
144
|
+
const scalar = (...values) => operation(...values);
|
|
145
|
+
Object.defineProperty(scalar, "length", { value: arity });
|
|
146
|
+
this.database.function(name, {
|
|
147
|
+
deterministic: true,
|
|
148
|
+
directOnly: false,
|
|
149
|
+
useBigIntArguments: true,
|
|
150
|
+
varargs: false
|
|
151
|
+
}, scalar);
|
|
152
|
+
}
|
|
153
|
+
transaction(operation) {
|
|
154
|
+
const outer = this.transactionDepth === 0;
|
|
155
|
+
const savepoint = `eidos_legacy_${++this.savepointSequence}`;
|
|
156
|
+
this.database.exec(outer ? "BEGIN IMMEDIATE" : `SAVEPOINT ${savepoint}`);
|
|
157
|
+
this.transactionDepth += 1;
|
|
158
|
+
try {
|
|
159
|
+
const result = operation();
|
|
160
|
+
this.database.exec(outer ? "COMMIT" : `RELEASE ${savepoint}`);
|
|
161
|
+
return result;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
this.database.exec(outer ? "ROLLBACK" : `ROLLBACK TO ${savepoint}; RELEASE ${savepoint}`);
|
|
164
|
+
throw error;
|
|
165
|
+
} finally {
|
|
166
|
+
this.transactionDepth -= 1;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
dataVersion() {
|
|
170
|
+
const value = prepareArrayStatement(this.database, "PRAGMA data_version").get()?.[0];
|
|
171
|
+
return typeof value === "bigint" ? Number(value) : Number(value ?? 0);
|
|
172
|
+
}
|
|
173
|
+
interrupt() {}
|
|
174
|
+
close() {
|
|
175
|
+
this.clearStatements();
|
|
176
|
+
if (this.database.isOpen) this.database.close();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
/** EA-Connection-1.0 binding for Electron 43's Node 24 node:sqlite runtime. */
|
|
180
|
+
var NodeSqliteConnectionPort = class {
|
|
181
|
+
connectionCapabilities;
|
|
182
|
+
maxResultRows;
|
|
183
|
+
maxResultBytes;
|
|
184
|
+
readOnly;
|
|
185
|
+
transactionModes = [];
|
|
186
|
+
snapshots = /* @__PURE__ */ new Set();
|
|
187
|
+
mutationAuthorizerCodes = new Set([
|
|
188
|
+
constants.SQLITE_CREATE_INDEX,
|
|
189
|
+
constants.SQLITE_CREATE_TABLE,
|
|
190
|
+
constants.SQLITE_CREATE_TEMP_INDEX,
|
|
191
|
+
constants.SQLITE_CREATE_TEMP_TABLE,
|
|
192
|
+
constants.SQLITE_CREATE_TEMP_TRIGGER,
|
|
193
|
+
constants.SQLITE_CREATE_TEMP_VIEW,
|
|
194
|
+
constants.SQLITE_CREATE_TRIGGER,
|
|
195
|
+
constants.SQLITE_CREATE_VIEW,
|
|
196
|
+
constants.SQLITE_DELETE,
|
|
197
|
+
constants.SQLITE_DROP_INDEX,
|
|
198
|
+
constants.SQLITE_DROP_TABLE,
|
|
199
|
+
constants.SQLITE_DROP_TEMP_INDEX,
|
|
200
|
+
constants.SQLITE_DROP_TEMP_TABLE,
|
|
201
|
+
constants.SQLITE_DROP_TEMP_TRIGGER,
|
|
202
|
+
constants.SQLITE_DROP_TEMP_VIEW,
|
|
203
|
+
constants.SQLITE_DROP_TRIGGER,
|
|
204
|
+
constants.SQLITE_DROP_VIEW,
|
|
205
|
+
constants.SQLITE_INSERT,
|
|
206
|
+
constants.SQLITE_TRANSACTION,
|
|
207
|
+
constants.SQLITE_UPDATE,
|
|
208
|
+
constants.SQLITE_ATTACH,
|
|
209
|
+
constants.SQLITE_DETACH,
|
|
210
|
+
constants.SQLITE_ALTER_TABLE,
|
|
211
|
+
constants.SQLITE_REINDEX,
|
|
212
|
+
constants.SQLITE_ANALYZE,
|
|
213
|
+
constants.SQLITE_CREATE_VTABLE,
|
|
214
|
+
constants.SQLITE_DROP_VTABLE,
|
|
215
|
+
constants.SQLITE_SAVEPOINT
|
|
216
|
+
]);
|
|
217
|
+
localCommit = 0;
|
|
218
|
+
savepointSequence = 0;
|
|
219
|
+
internalAuthorizationDepth = 0;
|
|
220
|
+
mainReadEstablished = false;
|
|
221
|
+
closed = false;
|
|
222
|
+
constructor(database, options = {}) {
|
|
223
|
+
this.database = database;
|
|
224
|
+
const busyTimeoutMs = positiveLimit(options.busyTimeoutMs, DEFAULT_BUSY_TIMEOUT_MS, "busyTimeoutMs");
|
|
225
|
+
this.maxResultRows = positiveLimit(options.maxResultRows, DEFAULT_MAX_RESULT_ROWS, "maxResultRows");
|
|
226
|
+
this.maxResultBytes = positiveLimit(options.maxResultBytes, DEFAULT_MAX_RESULT_BYTES, "maxResultBytes");
|
|
227
|
+
this.readOnly = options.readOnly ?? false;
|
|
228
|
+
const electronDatabase = electron43Database(database);
|
|
229
|
+
if (typeof electronDatabase.serialize !== "function" || typeof electronDatabase.limits !== "object" || typeof database.setAuthorizer !== "function") throw new EidosAdapterError("unsupported-capability", "node:sqlite from Node 24.16.0 or later is required");
|
|
230
|
+
database.enableDefensive(true);
|
|
231
|
+
database.exec(`PRAGMA foreign_keys = ON; PRAGMA trusted_schema = OFF; PRAGMA busy_timeout = ${busyTimeoutMs}`);
|
|
232
|
+
const sqliteVersion = this.runMandatoryProbes();
|
|
233
|
+
database.setAuthorizer((actionCode, firstArgument, secondArgument) => {
|
|
234
|
+
const readOnlyContext = this.readOnly || this.transactionModes.at(-1) === "read";
|
|
235
|
+
if (this.internalAuthorizationDepth === 0 && readOnlyContext) {
|
|
236
|
+
if (this.mutationAuthorizerCodes.has(actionCode) || actionCode === constants.SQLITE_PRAGMA && !isReadOnlyPragma(firstArgument, secondArgument)) return constants.SQLITE_DENY;
|
|
237
|
+
}
|
|
238
|
+
return constants.SQLITE_OK;
|
|
239
|
+
});
|
|
240
|
+
if (this.readOnly) this.execInternal("PRAGMA query_only = ON");
|
|
241
|
+
const limits = electronDatabase.limits;
|
|
242
|
+
this.connectionCapabilities = {
|
|
243
|
+
adapterVersion: "1.0",
|
|
244
|
+
sqliteVersion,
|
|
245
|
+
json1: true,
|
|
246
|
+
returning: true,
|
|
247
|
+
strict: true,
|
|
248
|
+
int64: true,
|
|
249
|
+
scalarFunctions: true,
|
|
250
|
+
directOnlyFunctions: true,
|
|
251
|
+
interrupt: false,
|
|
252
|
+
snapshot: true,
|
|
253
|
+
defensiveMode: true,
|
|
254
|
+
busyTimeoutMs,
|
|
255
|
+
maxVariables: databaseLimit(limits.variableNumber, "variableNumber"),
|
|
256
|
+
maxSqlBytes: databaseLimit(limits.sqlLength, "sqlLength"),
|
|
257
|
+
maxValueBytes: databaseLimit(limits.length, "length"),
|
|
258
|
+
maxResultRows: this.maxResultRows,
|
|
259
|
+
maxResultBytes: this.maxResultBytes
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
capabilities() {
|
|
263
|
+
this.assertOpen();
|
|
264
|
+
return { ...this.connectionCapabilities };
|
|
265
|
+
}
|
|
266
|
+
execSchema(sql) {
|
|
267
|
+
this.assertOpen();
|
|
268
|
+
if (/(?:^|;)\s*(?:BEGIN|COMMIT|ROLLBACK|SAVEPOINT|RELEASE)\b/i.test(sql)) throw new EidosAdapterError("invalid-argument", "Transaction-control SQL is owned by ConnectionPort.transaction");
|
|
269
|
+
if (this.readOnly || this.transactionModes.at(-1) === "read") throw new EidosAdapterError("read-only", "Schema statements are forbidden on a read-only connection or transaction");
|
|
270
|
+
try {
|
|
271
|
+
this.database.exec(sql);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
throw mapNodeSqliteError(error, this.inReadOnlyContext());
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
query(sql, bindings = []) {
|
|
277
|
+
this.assertOpen();
|
|
278
|
+
assertExactConnectionBindings(sql, bindings);
|
|
279
|
+
try {
|
|
280
|
+
const statement = prepareArrayStatement(this.database, sql);
|
|
281
|
+
const columns = statement.columns().map((column) => ({ name: column.name }));
|
|
282
|
+
if (columns.length === 0) throw new EidosAdapterError("invalid-argument", "query requires one row-producing statement");
|
|
283
|
+
const rows = [];
|
|
284
|
+
for (const nativeRow of statement.iterate(...nodeSqliteBindings(bindings))) {
|
|
285
|
+
if (rows.length >= this.maxResultRows) throw new EidosAdapterError("resource-limit", "Query result exceeds maxResultRows");
|
|
286
|
+
rows.push(nativeRow.map(nativeToSqlValue));
|
|
287
|
+
}
|
|
288
|
+
const result = {
|
|
289
|
+
columns,
|
|
290
|
+
rows
|
|
291
|
+
};
|
|
292
|
+
this.assertResultSize(result);
|
|
293
|
+
this.noteRead(sql);
|
|
294
|
+
return result;
|
|
295
|
+
} catch (error) {
|
|
296
|
+
throw mapNodeSqliteError(error, this.inReadOnlyContext());
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
get(sql, bindings = []) {
|
|
300
|
+
this.assertOpen();
|
|
301
|
+
assertExactConnectionBindings(sql, bindings);
|
|
302
|
+
try {
|
|
303
|
+
const statement = prepareArrayStatement(this.database, sql);
|
|
304
|
+
const columns = statement.columns().map((column) => ({ name: column.name }));
|
|
305
|
+
if (columns.length === 0) throw new EidosAdapterError("invalid-argument", "get requires one row-producing statement");
|
|
306
|
+
const native = statement.get(...nodeSqliteBindings(bindings));
|
|
307
|
+
const result = {
|
|
308
|
+
columns,
|
|
309
|
+
row: native ? native.map(nativeToSqlValue) : null
|
|
310
|
+
};
|
|
311
|
+
this.assertResultSize(result);
|
|
312
|
+
this.noteRead(sql);
|
|
313
|
+
return result;
|
|
314
|
+
} catch (error) {
|
|
315
|
+
throw mapNodeSqliteError(error, this.inReadOnlyContext());
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
run(sql, bindings = []) {
|
|
319
|
+
this.assertOpen();
|
|
320
|
+
assertExactConnectionBindings(sql, bindings);
|
|
321
|
+
try {
|
|
322
|
+
const statement = prepareArrayStatement(this.database, sql);
|
|
323
|
+
if (statement.columns().length > 0) throw new EidosAdapterError("invalid-argument", "run requires one no-result statement");
|
|
324
|
+
const result = statement.run(...nodeSqliteBindings(bindings));
|
|
325
|
+
return {
|
|
326
|
+
changes: String(result.changes),
|
|
327
|
+
lastInsertRowid: String(result.lastInsertRowid)
|
|
328
|
+
};
|
|
329
|
+
} catch (error) {
|
|
330
|
+
throw mapNodeSqliteError(error, this.inReadOnlyContext());
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
runMany(sql, bindingSets) {
|
|
334
|
+
this.assertOpen();
|
|
335
|
+
const expectedBindings = exactConnectionBindingCount(sql);
|
|
336
|
+
for (const bindings of bindingSets) if (bindings.length !== expectedBindings) throw new EidosAdapterError("invalid-argument", `Statement requires ${expectedBindings} bindings, received ${bindings.length}`);
|
|
337
|
+
try {
|
|
338
|
+
const statement = prepareArrayStatement(this.database, sql);
|
|
339
|
+
if (statement.columns().length > 0) throw new EidosAdapterError("invalid-argument", "runMany requires one no-result statement");
|
|
340
|
+
return bindingSets.map((bindings) => {
|
|
341
|
+
const result = statement.run(...nodeSqliteBindings(bindings));
|
|
342
|
+
return {
|
|
343
|
+
changes: String(result.changes),
|
|
344
|
+
lastInsertRowid: String(result.lastInsertRowid)
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
} catch (error) {
|
|
348
|
+
throw mapNodeSqliteError(error, this.inReadOnlyContext());
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
registerScalar(definition, operation) {
|
|
352
|
+
this.assertOpen();
|
|
353
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(definition.name) || !Number.isInteger(definition.arity) || definition.arity < 0 || definition.arity > 127 || definition.deterministic !== true || definition.directOnly !== true) throw new EidosAdapterError("invalid-argument", "Invalid ScalarDefinition");
|
|
354
|
+
try {
|
|
355
|
+
const scalar = (...values) => {
|
|
356
|
+
try {
|
|
357
|
+
return sqlValueToNative(operation(...values.map(nativeToSqlValue)));
|
|
358
|
+
} catch {
|
|
359
|
+
throw new EidosAdapterError("sql-function-error", "Deterministic scalar function failed");
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
Object.defineProperty(scalar, "length", { value: definition.arity });
|
|
363
|
+
this.database.function(definition.name, {
|
|
364
|
+
deterministic: true,
|
|
365
|
+
directOnly: true,
|
|
366
|
+
useBigIntArguments: true,
|
|
367
|
+
varargs: false
|
|
368
|
+
}, scalar);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
throw mapNodeSqliteError(error);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
transaction(mode, operation) {
|
|
374
|
+
this.assertOpen();
|
|
375
|
+
if (mode !== "read" && mode !== "write") throw new EidosAdapterError("invalid-argument", "Invalid transaction mode");
|
|
376
|
+
const parent = this.transactionModes.at(-1);
|
|
377
|
+
if (parent === "read" && mode === "write") throw new EidosAdapterError("read-only", "Cannot escalate a read transaction");
|
|
378
|
+
if (mode === "write" && this.readOnly) throw new EidosAdapterError("read-only", "Connection is read-only");
|
|
379
|
+
const outer = this.transactionModes.length === 0;
|
|
380
|
+
const effectiveMode = parent ?? mode;
|
|
381
|
+
const savepoint = `eidos_adapter_${++this.savepointSequence}`;
|
|
382
|
+
let started = false;
|
|
383
|
+
const noCallbackFailure = Symbol("no-callback-failure");
|
|
384
|
+
let callbackFailure = noCallbackFailure;
|
|
385
|
+
try {
|
|
386
|
+
this.execInternal(outer ? effectiveMode === "write" ? "BEGIN IMMEDIATE" : "BEGIN DEFERRED" : `SAVEPOINT ${savepoint}`);
|
|
387
|
+
started = true;
|
|
388
|
+
if (outer && effectiveMode === "read") this.execInternal("PRAGMA query_only = ON");
|
|
389
|
+
this.transactionModes.push(effectiveMode);
|
|
390
|
+
if (outer) this.mainReadEstablished = false;
|
|
391
|
+
let result;
|
|
392
|
+
try {
|
|
393
|
+
result = operation();
|
|
394
|
+
} catch (error) {
|
|
395
|
+
callbackFailure = error;
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
if (result instanceof Promise) return result.then((value) => {
|
|
399
|
+
try {
|
|
400
|
+
this.commitTransaction(outer, effectiveMode, savepoint);
|
|
401
|
+
return value;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
this.rollbackTransaction(outer, effectiveMode, savepoint);
|
|
404
|
+
throw mapNodeSqliteError(error, effectiveMode === "read");
|
|
405
|
+
} finally {
|
|
406
|
+
this.transactionModes.pop();
|
|
407
|
+
if (outer) this.mainReadEstablished = false;
|
|
408
|
+
}
|
|
409
|
+
}, (error) => {
|
|
410
|
+
try {
|
|
411
|
+
this.rollbackTransaction(outer, effectiveMode, savepoint);
|
|
412
|
+
throw error;
|
|
413
|
+
} finally {
|
|
414
|
+
this.transactionModes.pop();
|
|
415
|
+
if (outer) this.mainReadEstablished = false;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
this.commitTransaction(outer, effectiveMode, savepoint);
|
|
419
|
+
this.transactionModes.pop();
|
|
420
|
+
if (outer) this.mainReadEstablished = false;
|
|
421
|
+
return result;
|
|
422
|
+
} catch (error) {
|
|
423
|
+
try {
|
|
424
|
+
if (started) this.rollbackTransaction(outer, effectiveMode, savepoint);
|
|
425
|
+
throw callbackFailure === error && callbackFailure !== noCallbackFailure ? error : mapNodeSqliteError(error, effectiveMode === "read");
|
|
426
|
+
} finally {
|
|
427
|
+
if (started) this.transactionModes.pop();
|
|
428
|
+
if (outer) this.mainReadEstablished = false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
dataVersion() {
|
|
433
|
+
this.assertOpen();
|
|
434
|
+
try {
|
|
435
|
+
const external = this.withInternalAuthorization(() => prepareArrayStatement(this.database, "PRAGMA data_version").get())?.[0];
|
|
436
|
+
return `${this.localCommit}:${String(external ?? 0)}`;
|
|
437
|
+
} catch (error) {
|
|
438
|
+
throw mapNodeSqliteError(error);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
interrupt() {
|
|
442
|
+
this.assertOpen();
|
|
443
|
+
throw new EidosAdapterError("unsupported-capability", "node:sqlite uses the required utility-process terminate cancellation profile");
|
|
444
|
+
}
|
|
445
|
+
async snapshot(context) {
|
|
446
|
+
this.assertOpen();
|
|
447
|
+
if (this.transactionModes.length !== 1 || this.transactionModes[0] !== "read" || !this.mainReadEstablished) throw new EidosAdapterError("invalid-argument", "snapshot requires an established outer read transaction");
|
|
448
|
+
if (context.cancellation.cancelled()) throw new EidosAdapterError("cancelled", "Snapshot was cancelled");
|
|
449
|
+
const startedAt = Date.now();
|
|
450
|
+
if (context.deadlineMilliseconds !== void 0 && (!Number.isSafeInteger(context.deadlineMilliseconds) || context.deadlineMilliseconds < 1)) throw new EidosAdapterError("invalid-argument", "deadlineMilliseconds must be a positive safe integer");
|
|
451
|
+
const maxBytes = parseNonNegativeInt64(context.maxBytes, "maxBytes");
|
|
452
|
+
if (this.pragmaBigInt("page_count") * this.pragmaBigInt("page_size") > maxBytes) throw new EidosAdapterError("resource-limit", "Database snapshot exceeds maxBytes");
|
|
453
|
+
let bytes;
|
|
454
|
+
try {
|
|
455
|
+
bytes = new Uint8Array(this.withInternalAuthorization(() => electron43Database(this.database).serialize("main")));
|
|
456
|
+
} catch (error) {
|
|
457
|
+
throw mapNodeSqliteError(error, true);
|
|
458
|
+
}
|
|
459
|
+
if (context.cancellation.cancelled()) throw new EidosAdapterError("cancelled", "Snapshot was cancelled");
|
|
460
|
+
if (context.deadlineMilliseconds !== void 0 && Date.now() - startedAt >= context.deadlineMilliseconds) throw new EidosAdapterError("deadline-exceeded", "Snapshot deadline was exceeded");
|
|
461
|
+
if (BigInt(bytes.byteLength) > maxBytes) throw new EidosAdapterError("resource-limit", "Database snapshot exceeds maxBytes");
|
|
462
|
+
const source = new MemoryByteSource(bytes);
|
|
463
|
+
this.snapshots.add(source);
|
|
464
|
+
let released = false;
|
|
465
|
+
return {
|
|
466
|
+
bytes: source,
|
|
467
|
+
release: async () => {
|
|
468
|
+
if (released) return;
|
|
469
|
+
released = true;
|
|
470
|
+
source.release();
|
|
471
|
+
this.snapshots.delete(source);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
close() {
|
|
476
|
+
if (this.closed) return;
|
|
477
|
+
this.closed = true;
|
|
478
|
+
for (const snapshot of this.snapshots) snapshot.release();
|
|
479
|
+
this.snapshots.clear();
|
|
480
|
+
if (this.database.isOpen) {
|
|
481
|
+
this.database.setAuthorizer(null);
|
|
482
|
+
this.database.close();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
inReadOnlyContext() {
|
|
486
|
+
return this.readOnly || this.transactionModes.at(-1) === "read";
|
|
487
|
+
}
|
|
488
|
+
execInternal(sql) {
|
|
489
|
+
this.withInternalAuthorization(() => this.database.exec(sql));
|
|
490
|
+
}
|
|
491
|
+
withInternalAuthorization(operation) {
|
|
492
|
+
this.internalAuthorizationDepth += 1;
|
|
493
|
+
try {
|
|
494
|
+
return operation();
|
|
495
|
+
} finally {
|
|
496
|
+
this.internalAuthorizationDepth -= 1;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
commitTransaction(outer, mode, savepoint) {
|
|
500
|
+
this.execInternal(outer ? mode === "read" ? this.readOnly ? "COMMIT" : "PRAGMA query_only = OFF; COMMIT" : "COMMIT" : `RELEASE ${savepoint}`);
|
|
501
|
+
if (outer && mode === "write") this.localCommit += 1;
|
|
502
|
+
}
|
|
503
|
+
rollbackTransaction(outer, mode, savepoint) {
|
|
504
|
+
try {
|
|
505
|
+
this.execInternal(outer ? mode === "read" ? this.readOnly ? "ROLLBACK" : "PRAGMA query_only = OFF; ROLLBACK" : "ROLLBACK" : `ROLLBACK TO ${savepoint}; RELEASE ${savepoint}`);
|
|
506
|
+
} catch {
|
|
507
|
+
throw new EidosAdapterError("transport-fatal", "Transaction rollback could not be proven", false, true);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
assertOpen() {
|
|
511
|
+
if (this.closed || !this.database.isOpen) throw new EidosAdapterError("adapter-closed", "Connection is closed");
|
|
512
|
+
}
|
|
513
|
+
noteRead(sql) {
|
|
514
|
+
if (this.transactionModes.length === 1 && this.transactionModes[0] === "read" && !/^\s*PRAGMA\b/i.test(sql) && !/\btemp(?:\.|\s)/i.test(sql)) this.mainReadEstablished = true;
|
|
515
|
+
}
|
|
516
|
+
assertResultSize(value) {
|
|
517
|
+
let binaryBytes = 0;
|
|
518
|
+
const json = JSON.stringify(value, (_key, entry) => {
|
|
519
|
+
if (entry instanceof Uint8Array) {
|
|
520
|
+
binaryBytes += entry.byteLength;
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
return entry;
|
|
524
|
+
});
|
|
525
|
+
if (binaryBytes + Buffer.byteLength(json, "utf8") > this.maxResultBytes) throw new EidosAdapterError("resource-limit", "Query result exceeds maxResultBytes");
|
|
526
|
+
}
|
|
527
|
+
pragmaBigInt(name) {
|
|
528
|
+
const value = this.withInternalAuthorization(() => prepareArrayStatement(this.database, `PRAGMA ${name}`).get())?.[0];
|
|
529
|
+
return BigInt(value);
|
|
530
|
+
}
|
|
531
|
+
runMandatoryProbes() {
|
|
532
|
+
try {
|
|
533
|
+
const versionRow = prepareArrayStatement(this.database, "SELECT sqlite_version(), sqlite_source_id()").get();
|
|
534
|
+
if (compareSqliteVersion(versionRow[0], "3.45.0") < 0 || !versionRow[1]) throw new EidosAdapterError("unsupported-capability", "SQLite 3.45.0 or later with source ID is required");
|
|
535
|
+
const json = prepareArrayStatement(this.database, "SELECT json_valid('[]'), json_array_length('[1,2]')").get();
|
|
536
|
+
const foreignKeys = this.pragmaBigInt("foreign_keys");
|
|
537
|
+
const trustedSchema = this.pragmaBigInt("trusted_schema");
|
|
538
|
+
const values = prepareArrayStatement(this.database, "SELECT CAST('-9223372036854775808' AS INTEGER), CAST('9223372036854775807' AS INTEGER), X'000102FF'").get();
|
|
539
|
+
if (json[0] !== 1n || json[1] !== 2n || foreignKeys !== 1n || trustedSchema !== 0n || values[0] !== -9223372036854775808n || values[1] !== 9223372036854775807n || Buffer.from(values[2]).toString("hex") !== "000102ff") throw new EidosAdapterError("unsupported-capability", "SQLite mandatory value/PRAGMA probes failed");
|
|
540
|
+
this.database.function("eidos_adapter_probe_scalar", {
|
|
541
|
+
deterministic: true,
|
|
542
|
+
directOnly: true,
|
|
543
|
+
useBigIntArguments: true,
|
|
544
|
+
varargs: false
|
|
545
|
+
}, (value) => value);
|
|
546
|
+
if (prepareArrayStatement(this.database, "SELECT typeof(eidos_adapter_probe_scalar(NULL)), typeof(eidos_adapter_probe_scalar(1)), typeof(eidos_adapter_probe_scalar(1.5)), typeof(eidos_adapter_probe_scalar('x')), typeof(eidos_adapter_probe_scalar(X'0001')), hex(eidos_adapter_probe_scalar(X'0001'))").get().join(",") !== "null,integer,real,text,blob,0001") throw new EidosAdapterError("unsupported-capability", "Scalar function storage-class probe failed");
|
|
547
|
+
this.execInternal("SAVEPOINT eidos_adapter_probe_transaction");
|
|
548
|
+
try {
|
|
549
|
+
this.database.exec("CREATE TEMP TABLE eidos_adapter_probe(id INTEGER PRIMARY KEY, value TEXT NOT NULL) STRICT");
|
|
550
|
+
const returned = prepareArrayStatement(this.database, "INSERT INTO eidos_adapter_probe(value) VALUES ('ok') RETURNING id, value").get();
|
|
551
|
+
this.database.exec("DROP TABLE eidos_adapter_probe");
|
|
552
|
+
if (returned[0] !== 1n || returned[1] !== "ok") throw new EidosAdapterError("unsupported-capability", "SQLite STRICT/RETURNING probe failed");
|
|
553
|
+
this.execInternal("RELEASE eidos_adapter_probe_transaction");
|
|
554
|
+
} catch (error) {
|
|
555
|
+
this.execInternal("ROLLBACK TO eidos_adapter_probe_transaction; RELEASE eidos_adapter_probe_transaction");
|
|
556
|
+
throw error;
|
|
557
|
+
}
|
|
558
|
+
return versionRow[0];
|
|
559
|
+
} catch (error) {
|
|
560
|
+
const mapped = mapNodeSqliteError(error);
|
|
561
|
+
if (mapped instanceof EidosAdapterError) throw mapped;
|
|
562
|
+
throw new EidosAdapterError("unsupported-capability", "SQLite mandatory probes failed");
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
function positiveLimit(value, fallback, label) {
|
|
567
|
+
const limit = value ?? fallback;
|
|
568
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 2147483647) throw new EidosAdapterError("invalid-argument", `${label} must be a positive JSON integer`);
|
|
569
|
+
return limit;
|
|
570
|
+
}
|
|
571
|
+
function databaseLimit(value, label) {
|
|
572
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new EidosAdapterError("unsupported-capability", `node:sqlite did not expose a valid ${label} limit`);
|
|
573
|
+
return value;
|
|
574
|
+
}
|
|
575
|
+
function compareSqliteVersion(left, right) {
|
|
576
|
+
const a = left.split(".").map(Number);
|
|
577
|
+
const b = right.split(".").map(Number);
|
|
578
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
579
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
580
|
+
if (difference !== 0) return difference;
|
|
581
|
+
}
|
|
582
|
+
return 0;
|
|
583
|
+
}
|
|
584
|
+
function isReadOnlyPragma(name, argument) {
|
|
585
|
+
const normalizedName = name?.toLowerCase();
|
|
586
|
+
if (!normalizedName || !READ_ONLY_PRAGMAS.has(normalizedName)) return false;
|
|
587
|
+
return argument === null || READ_ONLY_PRAGMAS_WITH_ARGUMENTS.has(normalizedName);
|
|
588
|
+
}
|
|
589
|
+
function mapNodeSqliteError(error, readOnlyContext = false) {
|
|
590
|
+
if (error instanceof EidosAdapterError) return error;
|
|
591
|
+
if (!(error instanceof Error)) return new EidosAdapterError("io-error", "Unknown SQLite Adapter failure");
|
|
592
|
+
const systemCode = error.code;
|
|
593
|
+
if (systemCode === "ENOENT") return new EidosAdapterError("io-error", "SQLite database was not found");
|
|
594
|
+
if (systemCode === "EACCES" || systemCode === "EPERM") return new EidosAdapterError("permission-denied", "SQLite database access was denied");
|
|
595
|
+
if (systemCode === "ERR_INVALID_STATE" && /closed|not open/i.test(error.message)) return new EidosAdapterError("adapter-closed", "Connection is closed");
|
|
596
|
+
const extended = error.errcode;
|
|
597
|
+
const extendedCode = typeof extended === "number" && Number.isInteger(extended) ? extended : void 0;
|
|
598
|
+
const primaryCode = extendedCode === void 0 ? void 0 : extendedCode & 255;
|
|
599
|
+
const mapped = (code, message, retryable = false, fatal = false) => new EidosAdapterError(code, message, retryable, fatal, primaryCode, extendedCode);
|
|
600
|
+
switch (primaryCode) {
|
|
601
|
+
case 5: return mapped("busy", "SQLite is busy", true);
|
|
602
|
+
case 6: return mapped("locked", "SQLite is locked", true);
|
|
603
|
+
case 7: return mapped("out-of-memory", "SQLite ran out of memory", false, true);
|
|
604
|
+
case 8: return mapped("read-only", "SQLite connection is read-only");
|
|
605
|
+
case 9: return mapped("cancelled", "SQLite operation was interrupted");
|
|
606
|
+
case 10: return mapped("io-error", "SQLite I/O failed");
|
|
607
|
+
case 11: return mapped("corrupt", "SQLite database is corrupt", false, true);
|
|
608
|
+
case 18: return mapped("resource-limit", "SQLite value exceeds a resource limit");
|
|
609
|
+
case 19: return mapped("constraint", "SQLite constraint failed");
|
|
610
|
+
case 23: return mapped(readOnlyContext ? "read-only" : "permission-denied", readOnlyContext ? "Mutating statement is forbidden in a read transaction" : "SQLite statement was denied by the authorizer");
|
|
611
|
+
case 25: return mapped("invalid-argument", error.message);
|
|
612
|
+
case 26: return mapped("not-a-database", "Input is not a SQLite database", false, true);
|
|
613
|
+
}
|
|
614
|
+
if (error instanceof RangeError || error instanceof TypeError || /bind|parameter|statement/i.test(error.message)) return mapped("invalid-argument", error.message);
|
|
615
|
+
if (systemCode === "ERR_SQLITE_ERROR") return mapped("sql-error", error.message);
|
|
616
|
+
return mapped("io-error", error.message);
|
|
617
|
+
}
|
|
618
|
+
function hasSqliteHeader(filePath) {
|
|
619
|
+
if (!existsSync(filePath) || statSync(filePath).size < 16) return false;
|
|
620
|
+
const descriptor = openSync(filePath, "r");
|
|
621
|
+
try {
|
|
622
|
+
const header = Buffer.alloc(SQLITE_HEADER.length);
|
|
623
|
+
readSync(descriptor, header, 0, header.length, 0);
|
|
624
|
+
return header.toString("binary") === SQLITE_HEADER;
|
|
625
|
+
} finally {
|
|
626
|
+
closeSync(descriptor);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function createEidosFile(filePath, options = {}) {
|
|
630
|
+
assertEidosFileExtension(filePath);
|
|
631
|
+
if (existsSync(filePath) && statSync(filePath).size > 0) throw new EidosFileError("file-exists", `Eidos File already exists: ${filePath}`);
|
|
632
|
+
const connection = new NodeSqliteEidosFileConnection(openDatabase(filePath));
|
|
633
|
+
try {
|
|
634
|
+
connection.exec("PRAGMA foreign_keys = ON; PRAGMA trusted_schema = OFF; PRAGMA journal_mode = DELETE;");
|
|
635
|
+
initializeEidosFileSchema(connection, options);
|
|
636
|
+
const runtime = new EidosFileRuntime(connection, true);
|
|
637
|
+
if (options.defaultTable) runtime.createTable(options.defaultTable);
|
|
638
|
+
return runtime;
|
|
639
|
+
} catch (error) {
|
|
640
|
+
connection.close();
|
|
641
|
+
throw error;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function openEidosFile(filePath, options = {}) {
|
|
645
|
+
assertEidosFileExtension(filePath);
|
|
646
|
+
if (!existsSync(filePath)) throw new EidosFileError("file-not-found", `Eidos File not found: ${filePath}`);
|
|
647
|
+
if (!hasSqliteHeader(filePath)) throw new EidosFileError("invalid-sqlite", `Not a SQLite file: ${filePath}`);
|
|
648
|
+
const connection = new NodeSqliteEidosFileConnection(openDatabase(filePath, { readOnly: options.readonly ?? false }));
|
|
649
|
+
try {
|
|
650
|
+
connection.exec("PRAGMA foreign_keys = ON; PRAGMA trusted_schema = OFF;");
|
|
651
|
+
const result = validateEidosFile(connection);
|
|
652
|
+
if (!result.valid) throw new EidosFileError("not-eidos-file", result.errors.map((issue) => issue.message).join("; "));
|
|
653
|
+
return new EidosFileRuntime(connection, true);
|
|
654
|
+
} catch (error) {
|
|
655
|
+
connection.close();
|
|
656
|
+
throw error;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function inspectEidosFile(filePath) {
|
|
660
|
+
if (!hasSqliteHeader(filePath)) return {
|
|
661
|
+
valid: false,
|
|
662
|
+
metadata: null,
|
|
663
|
+
tables: [],
|
|
664
|
+
errors: [{
|
|
665
|
+
code: "invalid-sqlite",
|
|
666
|
+
message: "Not a SQLite file"
|
|
667
|
+
}],
|
|
668
|
+
warnings: []
|
|
669
|
+
};
|
|
670
|
+
const connection = new NodeSqliteEidosFileConnection(openDatabase(filePath, { readOnly: true }));
|
|
671
|
+
try {
|
|
672
|
+
connection.exec("PRAGMA foreign_keys = ON; PRAGMA trusted_schema = OFF;");
|
|
673
|
+
return validateEidosFile(connection);
|
|
674
|
+
} finally {
|
|
675
|
+
connection.close();
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
/** Node/Electron file adapter for the Runtime-owned system metadata merge profile. */
|
|
679
|
+
function mergeEidosSystemMetadataFiles(options) {
|
|
680
|
+
const base = new NodeSqliteEidosFileConnection(openDatabase(options.basePath, { readOnly: true }));
|
|
681
|
+
const ours = new NodeSqliteEidosFileConnection(openDatabase(options.oursPath, { readOnly: true }));
|
|
682
|
+
const theirs = new NodeSqliteEidosFileConnection(openDatabase(options.theirsPath, { readOnly: true }));
|
|
683
|
+
const result = new NodeSqliteEidosFileConnection(openDatabase(options.resultPath));
|
|
684
|
+
try {
|
|
685
|
+
return mergeEidosSystemMetadata({
|
|
686
|
+
base,
|
|
687
|
+
ours,
|
|
688
|
+
theirs,
|
|
689
|
+
result,
|
|
690
|
+
oursKey: options.oursKey,
|
|
691
|
+
theirsKey: options.theirsKey,
|
|
692
|
+
operationInstant: options.operationInstant
|
|
693
|
+
});
|
|
694
|
+
} finally {
|
|
695
|
+
result.close();
|
|
696
|
+
theirs.close();
|
|
697
|
+
ours.close();
|
|
698
|
+
base.close();
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function assertEidosFileExtension(filePath) {
|
|
702
|
+
if (path.extname(filePath).toLowerCase() === ".eidos") return;
|
|
703
|
+
throw new EidosFileError("invalid-identifier", `Eidos Files must use the ${EIDOS_FILE_EXTENSION} extension`);
|
|
704
|
+
}
|
|
705
|
+
//#endregion
|
|
706
|
+
export { NodeSqliteConnectionPort, NodeSqliteEidosFileConnection, createEidosFile, hasSqliteHeader, inspectEidosFile, mergeEidosSystemMetadataFiles, openEidosFile };
|
|
707
|
+
|
|
708
|
+
//# sourceMappingURL=node-sqlite.mjs.map
|