@eidos.space/eidos-file 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-contract-vfw3_C3w.d.mts → adapter-contract-DxNrTPJu.d.mts} +2 -2
- package/dist/{adapter-contract-vfw3_C3w.d.mts.map → adapter-contract-DxNrTPJu.d.mts.map} +1 -1
- package/dist/better-sqlite3.d.mts +2 -2
- package/dist/better-sqlite3.mjs +1 -1
- package/dist/browser.d.mts +3 -3
- package/dist/browser.mjs +2 -2
- package/dist/csv.d.mts +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +45 -19
- package/dist/index.mjs.map +1 -1
- package/dist/node-sqlite.d.mts +3 -3
- package/dist/node-sqlite.mjs +2 -2
- package/dist/{runtime-mvRkk__c.mjs → runtime-C5aMa-zZ.mjs} +260 -88
- package/dist/runtime-C5aMa-zZ.mjs.map +1 -0
- package/dist/{runtime-CtP7-fVC.d.mts → runtime-C9auix85.d.mts} +9 -2
- package/dist/runtime-C9auix85.d.mts.map +1 -0
- package/dist/select-options-DSzDn3qm.mjs.map +1 -1
- package/dist/{sqlite-wasm-BhRD8n56.mjs → sqlite-wasm-Sabcp1ey.mjs} +2 -2
- package/dist/{sqlite-wasm-BhRD8n56.mjs.map → sqlite-wasm-Sabcp1ey.mjs.map} +1 -1
- package/dist/{system-metadata-merge-CickEFxi.mjs → system-metadata-merge-B9NzlMRW.mjs} +2 -2
- package/dist/{system-metadata-merge-CickEFxi.mjs.map → system-metadata-merge-B9NzlMRW.mjs.map} +1 -1
- package/dist/{system-metadata-merge-CKMMBV4p.d.mts → system-metadata-merge-BALgEqIq.d.mts} +2 -2
- package/dist/{system-metadata-merge-CKMMBV4p.d.mts.map → system-metadata-merge-BALgEqIq.d.mts.map} +1 -1
- package/dist/{temporal-CP8ZDj59.d.mts → temporal-Dtx9P2Rz.d.mts} +3 -3
- package/dist/{temporal-CP8ZDj59.d.mts.map → temporal-Dtx9P2Rz.d.mts.map} +1 -1
- package/package.json +2 -2
- package/dist/runtime-CtP7-fVC.d.mts.map +0 -1
- package/dist/runtime-mvRkk__c.mjs.map +0 -1
|
@@ -3392,6 +3392,7 @@ function smallestDependencyCycle(graph) {
|
|
|
3392
3392
|
}
|
|
3393
3393
|
//#endregion
|
|
3394
3394
|
//#region src/validation.ts
|
|
3395
|
+
const SUPPORTED_VTAB_MODULES = new Set(["fs_meta"]);
|
|
3395
3396
|
const REQUIRED_COLUMNS = {
|
|
3396
3397
|
[EIDOS_FILE_META_TABLE]: [
|
|
3397
3398
|
"singleton",
|
|
@@ -3834,6 +3835,21 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3834
3835
|
errors,
|
|
3835
3836
|
warnings
|
|
3836
3837
|
};
|
|
3838
|
+
if (sqliteTables.has("eidos__features")) {
|
|
3839
|
+
const loadedModules = new Set(connection.query("PRAGMA module_list").map((row) => row.name));
|
|
3840
|
+
for (const feature of connection.query(`SELECT name, required, config_json FROM ${EIDOS_FILE_FEATURES_TABLE}`)) {
|
|
3841
|
+
if (!isCanonicalEidosFileJson(feature.config_json)) add(errors, "invalid-schema", `Feature ${feature.name} has non-canonical config_json`);
|
|
3842
|
+
const moduleName = feature.name.startsWith("vtab:") ? feature.name.slice(5) : null;
|
|
3843
|
+
if (feature.required === 1 && (!moduleName || !SUPPORTED_VTAB_MODULES.has(moduleName) || !loadedModules.has(moduleName))) add(errors, "unsupported-feature", `Required feature is unavailable in this runtime: ${feature.name}`);
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
if (errors.some((issue) => issue.code === "unsupported-feature")) return {
|
|
3847
|
+
valid: errors.length === 0,
|
|
3848
|
+
metadata,
|
|
3849
|
+
tables: [],
|
|
3850
|
+
errors,
|
|
3851
|
+
warnings
|
|
3852
|
+
};
|
|
3837
3853
|
for (const [tableName, requiredColumns] of Object.entries(REQUIRED_COLUMNS)) {
|
|
3838
3854
|
if (!sqliteTables.has(tableName)) continue;
|
|
3839
3855
|
const columns = new Map(connection.query(`PRAGMA table_xinfo(${quoteIdentifier(tableName)})`).map((column) => [column.name, column.type.toUpperCase()]));
|
|
@@ -3855,10 +3871,6 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3855
3871
|
if (mode.strict !== 1) add(errors, "invalid-schema", `${tableName} must be STRICT`, tableName);
|
|
3856
3872
|
if (mode.wr !== 1) add(errors, "invalid-schema", `${tableName} has the wrong WITHOUT ROWID mode`, tableName);
|
|
3857
3873
|
}
|
|
3858
|
-
if (sqliteTables.has("eidos__features")) for (const feature of connection.query(`SELECT name, required, config_json FROM ${EIDOS_FILE_FEATURES_TABLE}`)) {
|
|
3859
|
-
if (!isCanonicalEidosFileJson(feature.config_json)) add(errors, "invalid-schema", `Feature ${feature.name} has non-canonical config_json`);
|
|
3860
|
-
if (feature.required === 1) add(errors, "unsupported-feature", `Unknown required feature: ${feature.name}`);
|
|
3861
|
-
}
|
|
3862
3874
|
const tableRows = sqliteTables.has("eidos__tables") ? connection.query(`SELECT * FROM ${EIDOS_FILE_TABLES_TABLE} ORDER BY position, id`) : [];
|
|
3863
3875
|
const tables = [];
|
|
3864
3876
|
const tableRowsById = /* @__PURE__ */ new Map();
|
|
@@ -3890,8 +3902,11 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3890
3902
|
tableNames.add(foldedTableName);
|
|
3891
3903
|
if (!validPhysicalMapping("table", row.name, row.physical_name)) add(errors, "invalid-schema", `Table ${row.name} has an invalid physical name`, row.physical_name);
|
|
3892
3904
|
const tableObject = sqliteTables.get(row.physical_name);
|
|
3905
|
+
const isVirtualTable = settings.tableType === "virtual" || Boolean(settings.vtabModule);
|
|
3893
3906
|
if (!tableObject) add(errors, "invalid-schema", `Missing user table ${row.physical_name}`, row.physical_name);
|
|
3894
|
-
else if (
|
|
3907
|
+
else if (isVirtualTable) {
|
|
3908
|
+
if (!/\bVIRTUAL\b/i.test(tableObject.sql ?? "")) add(errors, "invalid-schema", `Virtual table ${row.physical_name} must be a SQLite virtual table`, row.physical_name);
|
|
3909
|
+
} else if (!/\bSTRICT\b/i.test(tableObject.sql ?? "")) add(errors, "invalid-schema", `User table ${row.physical_name} must be STRICT`, row.physical_name);
|
|
3895
3910
|
} catch (error) {
|
|
3896
3911
|
add(errors, "invalid-schema", error instanceof Error ? error.message : "Invalid Table ID");
|
|
3897
3912
|
}
|
|
@@ -4039,14 +4054,18 @@ function validateEidosFile(connection, options = {}) {
|
|
|
4039
4054
|
}
|
|
4040
4055
|
const triggerObjects = new Map(sqliteObjects.filter((object) => object.type === "trigger").map((object) => [object.name, object]));
|
|
4041
4056
|
const expectedTriggers = /* @__PURE__ */ new Map();
|
|
4042
|
-
for (const [tableId, table] of tableRowsById)
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4057
|
+
for (const [tableId, table] of tableRowsById) {
|
|
4058
|
+
const tableSettings = tableSettingsById.get(tableId) ?? {};
|
|
4059
|
+
if (tableSettings.tableType === "virtual" || Boolean(tableSettings.vtabModule)) continue;
|
|
4060
|
+
expectedTriggers.set(`eidos__row_id_immutable__${tableId.replace(/-/g, "")}`, {
|
|
4061
|
+
table: table.physical_name,
|
|
4062
|
+
fragments: [
|
|
4063
|
+
"before update of",
|
|
4064
|
+
"_id",
|
|
4065
|
+
"eidos_row_id_immutable"
|
|
4066
|
+
]
|
|
4067
|
+
});
|
|
4068
|
+
}
|
|
4050
4069
|
for (const [fieldId, relation] of relations) {
|
|
4051
4070
|
if (relation.direction !== "forward") continue;
|
|
4052
4071
|
const field = fieldRowsById.get(fieldId);
|
|
@@ -4166,7 +4185,10 @@ function validateEidosFile(connection, options = {}) {
|
|
|
4166
4185
|
"_created_at",
|
|
4167
4186
|
"_updated_at"
|
|
4168
4187
|
]) if (!physicalColumns.has(required)) add(errors, "invalid-schema", `User table ${table.name} is missing ${required}`);
|
|
4169
|
-
|
|
4188
|
+
const isVirtual = tableSettingsById.get(table.id)?.tableType === "virtual" || Boolean(tableSettingsById.get(table.id)?.vtabModule);
|
|
4189
|
+
if (!isVirtual) {
|
|
4190
|
+
if (physicalColumns.get("_id") !== "TEXT" || !declaresBinaryText(sqliteTables.get(table.physical_name)?.sql ?? null, "_id")) add(errors, "invalid-schema", `User table ${table.name}._id must use canonical UUIDv7 TEXT COLLATE BINARY`);
|
|
4191
|
+
} else if (physicalColumns.get("_id") !== "TEXT") add(errors, "invalid-schema", `Virtual table ${table.name}._id must be TEXT`);
|
|
4170
4192
|
for (const field of fields) {
|
|
4171
4193
|
const fieldId = field.id;
|
|
4172
4194
|
if (field.physicalName) {
|
|
@@ -4174,7 +4196,7 @@ function validateEidosFile(connection, options = {}) {
|
|
|
4174
4196
|
const expected = expectedColumnType(field.type);
|
|
4175
4197
|
if (!actualType) add(errors, "invalid-schema", `Stored Field ${field.name} has no physical column`);
|
|
4176
4198
|
else if (expected && actualType !== expected) add(errors, "invalid-schema", `Field ${field.name} must use SQLite ${expected}, found ${actualType}`);
|
|
4177
|
-
if (![
|
|
4199
|
+
if (!isVirtual && ![
|
|
4178
4200
|
"row-id",
|
|
4179
4201
|
"created-time",
|
|
4180
4202
|
"last-edited-time"
|
|
@@ -4460,43 +4482,58 @@ function validateEidosFile(connection, options = {}) {
|
|
|
4460
4482
|
if (level === "content" || level === "full") {
|
|
4461
4483
|
const quickCheck = connection.get("PRAGMA quick_check");
|
|
4462
4484
|
if (quickCheck?.quick_check !== "ok") add(errors, "invalid-schema", `SQLite quick_check failed: ${quickCheck?.quick_check ?? "unknown"}`);
|
|
4485
|
+
const contentSchemaValid = errors.length === 0;
|
|
4463
4486
|
for (const [tableId, fields] of fieldsByTable) {
|
|
4464
4487
|
const table = tableRowsById.get(tableId);
|
|
4465
4488
|
const stored = fields.filter((field) => field.physicalName);
|
|
4466
4489
|
if (stored.length === 0) continue;
|
|
4467
4490
|
const selection = stored.map((field) => quoteIdentifier(field.physicalName)).join(", ");
|
|
4468
|
-
|
|
4469
|
-
const
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
if (
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4491
|
+
const validateRows = (rows) => {
|
|
4492
|
+
for (const row of rows) for (const field of stored) {
|
|
4493
|
+
const value = row[field.physicalName];
|
|
4494
|
+
if (value === null || value === void 0) continue;
|
|
4495
|
+
if (field.type === "row-id") {
|
|
4496
|
+
if (!(tableSettingsById.get(tableId)?.tableType === "virtual" || Boolean(tableSettingsById.get(tableId)?.vtabModule)) && !isEidosFileUuid(value)) add(errors, "invalid-value", `${table.name}._id must be canonical lowercase UUIDv7 TEXT`);
|
|
4497
|
+
}
|
|
4498
|
+
if (field.type === "number" && (typeof value !== "number" || !Number.isFinite(value))) add(errors, "invalid-value", `${table.name}.${field.name} must be finite REAL`);
|
|
4499
|
+
if (field.type === "checkbox" && value !== 0 && value !== 1) add(errors, "invalid-value", `${table.name}.${field.name} must be 0, 1, or NULL`);
|
|
4500
|
+
if (field.type === "date" && !isCanonicalEidosFileDate(value)) add(errors, "invalid-value", `${table.name}.${field.name} must be canonical YYYY-MM-DD text`);
|
|
4501
|
+
if (field.type === "url" && !isEidosFileUriReference(value)) add(errors, "invalid-value", `${table.name}.${field.name} must be a valid URI-reference`);
|
|
4502
|
+
if ([
|
|
4503
|
+
"datetime",
|
|
4504
|
+
"created-time",
|
|
4505
|
+
"last-edited-time"
|
|
4506
|
+
].includes(field.type) && !isCanonicalEidosFileInstant(value)) add(errors, "invalid-value", `${table.name}.${field.name} must be canonical UTC millisecond text`);
|
|
4507
|
+
if (["multi-select", "file"].includes(field.type)) {
|
|
4508
|
+
let parsed = null;
|
|
4509
|
+
if (field.type === "file" && typeof value === "string") try {
|
|
4510
|
+
parsed = decodeEidosFileValues(value);
|
|
4511
|
+
} catch (error) {
|
|
4512
|
+
add(errors, "invalid-value", `${table.name}.${field.name}: ${error instanceof Error ? error.message : "invalid File value"}`);
|
|
4513
|
+
}
|
|
4514
|
+
else if (typeof value === "string" && isCanonicalEidosFileJson(value)) parsed = parseEidosFileJson(value);
|
|
4515
|
+
if (!Array.isArray(parsed)) add(errors, "invalid-value", `${table.name}.${field.name} must be a canonical JSON array`);
|
|
4516
|
+
if (field.type === "multi-select" && Array.isArray(parsed) && (!parsed.every((entry) => typeof entry === "string") || new Set(parsed).size !== parsed.length)) add(errors, "invalid-value", `${table.name}.${field.name} must be a unique string array`);
|
|
4517
|
+
}
|
|
4518
|
+
if (field.type === "relation") {
|
|
4519
|
+
const ids = relationIds(value);
|
|
4520
|
+
const relation = relations.get(field.id);
|
|
4521
|
+
if (!ids || relation?.direction !== "forward") add(errors, "invalid-value", `${table.name}.${field.name} must be a canonical UUID array`);
|
|
4522
|
+
else if (relation.cardinality === "one" && ids.length > 1) add(errors, "invalid-value", `${table.name}.${field.name} exceeds cardinality one`);
|
|
4489
4523
|
}
|
|
4490
|
-
else if (typeof value === "string" && isCanonicalEidosFileJson(value)) parsed = parseEidosFileJson(value);
|
|
4491
|
-
if (!Array.isArray(parsed)) add(errors, "invalid-value", `${table.name}.${field.name} must be a canonical JSON array`);
|
|
4492
|
-
if (field.type === "multi-select" && Array.isArray(parsed) && (!parsed.every((entry) => typeof entry === "string") || new Set(parsed).size !== parsed.length)) add(errors, "invalid-value", `${table.name}.${field.name} must be a unique string array`);
|
|
4493
|
-
}
|
|
4494
|
-
if (field.type === "relation") {
|
|
4495
|
-
const ids = relationIds(value);
|
|
4496
|
-
const relation = relations.get(field.id);
|
|
4497
|
-
if (!ids || relation?.direction !== "forward") add(errors, "invalid-value", `${table.name}.${field.name} must be a canonical UUID array`);
|
|
4498
|
-
else if (relation.cardinality === "one" && ids.length > 1) add(errors, "invalid-value", `${table.name}.${field.name} exceeds cardinality one`);
|
|
4499
4524
|
}
|
|
4525
|
+
};
|
|
4526
|
+
const rowId = stored.find((field) => field.type === "row-id");
|
|
4527
|
+
if (rowId?.physicalName && contentSchemaValid) scanStableRowPages(connection, {
|
|
4528
|
+
columnsSql: selection,
|
|
4529
|
+
tableSql: quoteIdentifier(table.physical_name),
|
|
4530
|
+
rowIdSql: quoteIdentifier(rowId.physicalName),
|
|
4531
|
+
rowIdKey: rowId.physicalName
|
|
4532
|
+
}, validateRows);
|
|
4533
|
+
else for (let offset = 0;; offset += 256) {
|
|
4534
|
+
const rows = connection.query(`SELECT ${selection} FROM ${quoteIdentifier(table.physical_name)} LIMIT 256 OFFSET ?`, [offset]);
|
|
4535
|
+
validateRows(rows);
|
|
4536
|
+
if (rows.length < 256) break;
|
|
4500
4537
|
}
|
|
4501
4538
|
for (const field of fields) {
|
|
4502
4539
|
const relation = field.id ? relations.get(field.id) : void 0;
|
|
@@ -4714,6 +4751,35 @@ function uniqueSortFields(fields, sorts) {
|
|
|
4714
4751
|
}];
|
|
4715
4752
|
});
|
|
4716
4753
|
}
|
|
4754
|
+
function replaceVirtualTableFields(sql, fields) {
|
|
4755
|
+
const declaration = sql.match(/^CREATE\s+VIRTUAL\s+TABLE\s+(?:"(?:[^"]|"")*"|'(?:[^']|'')*'|`(?:[^`]|``)*`|\[[^\]]*\]|[^\s(]+)\s+USING\s+\w+\s*\(/i);
|
|
4756
|
+
const start = declaration ? declaration[0].length - 1 : -1;
|
|
4757
|
+
const end = sql.lastIndexOf(")");
|
|
4758
|
+
if (start < 0 || end < start) throw new EidosFileError("invalid-schema", "Invalid virtual table declaration");
|
|
4759
|
+
const args = [];
|
|
4760
|
+
let argument = "", quote = "";
|
|
4761
|
+
for (const character of sql.slice(start + 1, end)) if (quote) {
|
|
4762
|
+
argument += character;
|
|
4763
|
+
if (character === quote) quote = "";
|
|
4764
|
+
} else if (character === "'" || character === "\"" || character === "`") {
|
|
4765
|
+
quote = character;
|
|
4766
|
+
argument += character;
|
|
4767
|
+
} else if (character === ",") {
|
|
4768
|
+
args.push(argument);
|
|
4769
|
+
argument = "";
|
|
4770
|
+
} else argument += character;
|
|
4771
|
+
args.push(argument);
|
|
4772
|
+
if (quote) throw new EidosFileError("invalid-schema", "Unterminated virtual table argument");
|
|
4773
|
+
const replacement = `fields = '${fields.replace(/'/g, "''")}'`;
|
|
4774
|
+
const index = args.findIndex((arg) => /^\s*fields\s*=/i.test(arg));
|
|
4775
|
+
if (index < 0) args.push(replacement);
|
|
4776
|
+
else args[index] = replacement;
|
|
4777
|
+
return `${sql.slice(0, start + 1)}${args.join(",")}${sql.slice(end)}`;
|
|
4778
|
+
}
|
|
4779
|
+
function assertCursorRowId(value, label = "Cursor Row ID") {
|
|
4780
|
+
if (typeof value !== "string" || value.length === 0 || value.includes("\0")) throw new EidosFileError("invalid-query", `${label} is invalid`);
|
|
4781
|
+
return value;
|
|
4782
|
+
}
|
|
4717
4783
|
function compileKeysetAfter(sorts, values, lastId) {
|
|
4718
4784
|
if (values.length !== sorts.length) throw new EidosFileError("invalid-query", "Cursor sort tuple is invalid");
|
|
4719
4785
|
const params = [];
|
|
@@ -4754,7 +4820,7 @@ function compileKeysetAfter(sorts, values, lastId) {
|
|
|
4754
4820
|
}
|
|
4755
4821
|
});
|
|
4756
4822
|
finalParts.push("\"__base_rowid\" > ?");
|
|
4757
|
-
params.push(
|
|
4823
|
+
params.push(assertCursorRowId(lastId, "Cursor Row ID"));
|
|
4758
4824
|
branches.push(`(${finalParts.join(" AND ")})`);
|
|
4759
4825
|
return {
|
|
4760
4826
|
sql: `(${branches.join(" OR ")})`,
|
|
@@ -4801,7 +4867,7 @@ function compileKeysetBefore(sorts, values, firstId) {
|
|
|
4801
4867
|
}
|
|
4802
4868
|
});
|
|
4803
4869
|
finalParts.push("\"__base_rowid\" < ?");
|
|
4804
|
-
params.push(
|
|
4870
|
+
params.push(assertCursorRowId(firstId, "Row ID"));
|
|
4805
4871
|
branches.push(`(${finalParts.join(" AND ")})`);
|
|
4806
4872
|
return {
|
|
4807
4873
|
sql: `(${branches.join(" OR ")})`,
|
|
@@ -5221,6 +5287,7 @@ function storedViewQueryStatus(query, fields) {
|
|
|
5221
5287
|
}
|
|
5222
5288
|
var EidosFileRuntime = class {
|
|
5223
5289
|
mutationDepth = 0;
|
|
5290
|
+
virtualFieldCleanup = [];
|
|
5224
5291
|
mutationInstant = null;
|
|
5225
5292
|
rowMutationUndoEntries = /* @__PURE__ */ new Map();
|
|
5226
5293
|
rowMutationUndoBytes = 0;
|
|
@@ -5267,6 +5334,70 @@ var EidosFileRuntime = class {
|
|
|
5267
5334
|
if (!row) throw new EidosFileError("table-not-found", `Eidos File Table not found: ${tableId}`);
|
|
5268
5335
|
return row;
|
|
5269
5336
|
}
|
|
5337
|
+
isVirtualTable(tableId) {
|
|
5338
|
+
const settings = jsonObject(this.tableRow(tableId).settings_json);
|
|
5339
|
+
return settings.tableType === "virtual" || typeof settings.vtabModule === "string";
|
|
5340
|
+
}
|
|
5341
|
+
tableCapabilities(tableId) {
|
|
5342
|
+
const settings = jsonObject(this.tableRow(tableId).settings_json);
|
|
5343
|
+
const caps = settings.capabilities ?? {};
|
|
5344
|
+
const isVirt = settings.tableType === "virtual" || typeof settings.vtabModule === "string";
|
|
5345
|
+
return {
|
|
5346
|
+
insert: typeof caps.insert === "boolean" ? caps.insert : !isVirt,
|
|
5347
|
+
delete: typeof caps.delete === "boolean" || caps.delete === "clear_meta" ? caps.delete : true,
|
|
5348
|
+
update: typeof caps.update === "boolean" ? caps.update : true,
|
|
5349
|
+
alterSchema: typeof caps.alterSchema === "boolean" ? caps.alterSchema : true
|
|
5350
|
+
};
|
|
5351
|
+
}
|
|
5352
|
+
syncVirtualTableSchema(tableId) {
|
|
5353
|
+
const table = this.getTable(tableId);
|
|
5354
|
+
const tableName = table.physicalName ?? table.rawTableName;
|
|
5355
|
+
const schemaRow = this.connection.get("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?", [tableName]);
|
|
5356
|
+
if (!schemaRow || !schemaRow.sql) return;
|
|
5357
|
+
const fieldsSql = this.listFields(tableId).filter((f) => {
|
|
5358
|
+
if (!f.physicalName || f.settings?.isSystem === true) return false;
|
|
5359
|
+
if (f.systemRole !== null) return false;
|
|
5360
|
+
const name = (f.physicalName ?? f.name).toLowerCase();
|
|
5361
|
+
if ([
|
|
5362
|
+
"_id",
|
|
5363
|
+
"id",
|
|
5364
|
+
"name",
|
|
5365
|
+
"extension",
|
|
5366
|
+
"size",
|
|
5367
|
+
"_created_at",
|
|
5368
|
+
"_updated_at",
|
|
5369
|
+
"mtime",
|
|
5370
|
+
"path",
|
|
5371
|
+
"is_dir",
|
|
5372
|
+
"file",
|
|
5373
|
+
"mimetype",
|
|
5374
|
+
"mime_type"
|
|
5375
|
+
].includes(name)) return false;
|
|
5376
|
+
return true;
|
|
5377
|
+
}).map((f) => {
|
|
5378
|
+
const colName = f.physicalName ?? f.name;
|
|
5379
|
+
const typeStr = f.type;
|
|
5380
|
+
return {
|
|
5381
|
+
name: colName,
|
|
5382
|
+
type: typeStr === "integer" || typeStr === "rating" || typeStr === "boolean" || typeStr === "checkbox" ? "INTEGER" : typeStr === "number" || typeStr === "float" ? "REAL" : "TEXT",
|
|
5383
|
+
key: String(f.settings?.vtabStorageKey ?? colName)
|
|
5384
|
+
};
|
|
5385
|
+
});
|
|
5386
|
+
const newSql = replaceVirtualTableFields(schemaRow.sql, JSON.stringify(fieldsSql));
|
|
5387
|
+
this.connection.exec(`DROP TABLE ${quoteIdentifier(tableName)};`);
|
|
5388
|
+
this.connection.exec(newSql);
|
|
5389
|
+
this.schemaCache = void 0;
|
|
5390
|
+
}
|
|
5391
|
+
assertRowId(tableId, rowId, label = "Row ID") {
|
|
5392
|
+
return this.rowIdValidator(tableId, label)(rowId);
|
|
5393
|
+
}
|
|
5394
|
+
rowIdValidator(tableId, label = "Row ID") {
|
|
5395
|
+
if (this.isVirtualTable(tableId)) return (rowId) => {
|
|
5396
|
+
if (typeof rowId !== "string" || rowId.length === 0 || rowId.includes("\0")) throw new EidosFileError("invalid-value", `${label} is invalid`);
|
|
5397
|
+
return rowId;
|
|
5398
|
+
};
|
|
5399
|
+
return (rowId) => assertEidosFileUuid(rowId, label);
|
|
5400
|
+
}
|
|
5270
5401
|
fieldRows(tableId) {
|
|
5271
5402
|
return this.connection.query(`SELECT * FROM ${EIDOS_FILE_FIELDS_TABLE}
|
|
5272
5403
|
WHERE table_id = ? ORDER BY position, id`, [assertEidosFileUuid(tableId, "Table ID")]);
|
|
@@ -5336,6 +5467,7 @@ var EidosFileRuntime = class {
|
|
|
5336
5467
|
position: row.position,
|
|
5337
5468
|
settings,
|
|
5338
5469
|
property,
|
|
5470
|
+
writable: settings.writable !== false && settings.readOnly !== true && settings.isSystem !== true && !row.system_role && type !== "formula" && type !== "lookup" && !(type === "relation" && relation?.direction === "inverse"),
|
|
5339
5471
|
storageCodec: type === "relation" && relation?.direction === "forward" ? "relation" : type === "file" || type === "multi-select" || type === "lookup" && lookup?.aggregate === "values" ? "json_array" : "scalar",
|
|
5340
5472
|
valueKind: [
|
|
5341
5473
|
"row-id",
|
|
@@ -5388,23 +5520,22 @@ var EidosFileRuntime = class {
|
|
|
5388
5520
|
return schema;
|
|
5389
5521
|
}
|
|
5390
5522
|
listTables() {
|
|
5391
|
-
return Array.from(this.allSchema().tables.values()).sort((left, right) => left.position - right.position || uuid(left.id).localeCompare(uuid(right.id))).map((row) =>
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
}));
|
|
5523
|
+
return Array.from(this.allSchema().tables.values()).sort((left, right) => left.position - right.position || uuid(left.id).localeCompare(uuid(right.id))).map((row) => {
|
|
5524
|
+
const settings = jsonObject(row.settings_json);
|
|
5525
|
+
return {
|
|
5526
|
+
icon: typeof settings.icon === "string" ? settings.icon : null,
|
|
5527
|
+
description: typeof settings.description === "string" ? settings.description : null,
|
|
5528
|
+
contentFieldId: typeof settings.contentFieldId === "string" ? settings.contentFieldId : null,
|
|
5529
|
+
settings,
|
|
5530
|
+
id: uuid(row.id),
|
|
5531
|
+
name: row.name,
|
|
5532
|
+
physicalName: row.physical_name,
|
|
5533
|
+
rawTableName: row.physical_name,
|
|
5534
|
+
position: row.position,
|
|
5535
|
+
createdAt: row.created_at,
|
|
5536
|
+
updatedAt: row.updated_at
|
|
5537
|
+
};
|
|
5538
|
+
});
|
|
5408
5539
|
}
|
|
5409
5540
|
getTable(tableId) {
|
|
5410
5541
|
const row = this.tableRow(tableId);
|
|
@@ -5418,6 +5549,7 @@ var EidosFileRuntime = class {
|
|
|
5418
5549
|
icon: typeof settings.icon === "string" ? settings.icon : null,
|
|
5419
5550
|
description: typeof settings.description === "string" ? settings.description : null,
|
|
5420
5551
|
contentFieldId: typeof settings.contentFieldId === "string" ? settings.contentFieldId : null,
|
|
5552
|
+
settings,
|
|
5421
5553
|
createdAt: row.created_at,
|
|
5422
5554
|
updatedAt: row.updated_at
|
|
5423
5555
|
};
|
|
@@ -5454,6 +5586,10 @@ var EidosFileRuntime = class {
|
|
|
5454
5586
|
this.mutationDepth += 1;
|
|
5455
5587
|
try {
|
|
5456
5588
|
const operationResult = operation();
|
|
5589
|
+
for (const { tableId, key } of this.virtualFieldCleanup) {
|
|
5590
|
+
const table = this.connection.get(`SELECT physical_name FROM ${EIDOS_FILE_TABLES_TABLE} WHERE id = ?`, [tableId]);
|
|
5591
|
+
if (table) this.connection.run(`UPDATE ${quoteIdentifier(table.physical_name)} SET "__fs_meta_remove_key" = ?`, [key]);
|
|
5592
|
+
}
|
|
5457
5593
|
const totalChangesAfter = this.connection.get("SELECT total_changes() AS total")?.total ?? totalChangesBefore;
|
|
5458
5594
|
if (BigInt(totalChangesAfter) === BigInt(totalChangesBefore)) return operationResult;
|
|
5459
5595
|
const validation = validateEidosFile(this.connection, { level: "semantic" });
|
|
@@ -5470,6 +5606,7 @@ var EidosFileRuntime = class {
|
|
|
5470
5606
|
if (clearRowUndoAfterCommit) this.clearRowMutationUndoEntries();
|
|
5471
5607
|
return result;
|
|
5472
5608
|
} finally {
|
|
5609
|
+
this.virtualFieldCleanup = [];
|
|
5473
5610
|
this.nestedMutationInvalidatesRowUndo = previousInvalidation;
|
|
5474
5611
|
}
|
|
5475
5612
|
}
|
|
@@ -5643,6 +5780,7 @@ var EidosFileRuntime = class {
|
|
|
5643
5780
|
input.property.displayType
|
|
5644
5781
|
]);
|
|
5645
5782
|
if (field.type === "relation" && input.type === "relation") {
|
|
5783
|
+
if (this.isVirtualTable(tableId) || this.isVirtualTable(input.property.targetTableId)) throw new EidosFileError("table-mutation-not-supported", "Relations require ordinary tables; filesystem metadata tables use file paths as row identities and do not support relation triggers");
|
|
5646
5784
|
const direction = input.property.direction ?? "forward";
|
|
5647
5785
|
const sourceFieldId = input.property.sourceFieldId ?? null;
|
|
5648
5786
|
const cardinality = direction === "inverse" ? "many" : input.property.cardinality ?? (input.property.multiple ? "many" : "one");
|
|
@@ -5837,6 +5975,7 @@ var EidosFileRuntime = class {
|
|
|
5837
5975
|
physicalName,
|
|
5838
5976
|
settings: {
|
|
5839
5977
|
...presentationSettings(input),
|
|
5978
|
+
...this.isVirtualTable(tableId) && physicalName ? { vtabStorageKey: input.name } : {},
|
|
5840
5979
|
...input.type === "rating" ? { display: { kind: "rating" } } : {}
|
|
5841
5980
|
},
|
|
5842
5981
|
input,
|
|
@@ -5851,8 +5990,13 @@ var EidosFileRuntime = class {
|
|
|
5851
5990
|
].includes(prepared.type) && this.countRows(tableId) > 0) throw new EidosFileError("constraint-conflict", "A populated Table cannot add a non-null scalar Field without a default");
|
|
5852
5991
|
return this.mutateSchemaState(() => {
|
|
5853
5992
|
if (prepared.isRecordLabel && prepared.type === "lookup") throw new EidosFileError("invalid-schema", "A Lookup cannot be the Record Label Field in Eidos File 1.0");
|
|
5854
|
-
const
|
|
5855
|
-
if (
|
|
5993
|
+
const isVirtual = this.isVirtualTable(tableId);
|
|
5994
|
+
if (isVirtual) {
|
|
5995
|
+
if (!this.tableCapabilities(tableId).alterSchema) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support altering schema");
|
|
5996
|
+
} else {
|
|
5997
|
+
const definition = fieldColumnSql(prepared);
|
|
5998
|
+
if (definition) this.connection.exec(`ALTER TABLE ${quoteIdentifier(table.physicalName ?? table.rawTableName)} ADD COLUMN ${definition}`);
|
|
5999
|
+
}
|
|
5856
6000
|
this.insertFieldMetadata(tableId, prepared, fields.length, this.operationInstant());
|
|
5857
6001
|
this.insertFieldSubtypeMetadata(tableId, prepared);
|
|
5858
6002
|
if (prepared.isRecordLabel) this.connection.run(`UPDATE ${EIDOS_FILE_TABLES_TABLE}
|
|
@@ -5874,6 +6018,7 @@ var EidosFileRuntime = class {
|
|
|
5874
6018
|
view.id
|
|
5875
6019
|
]);
|
|
5876
6020
|
}
|
|
6021
|
+
if (isVirtual) this.syncVirtualTableSchema(tableId);
|
|
5877
6022
|
return this.fieldByKey(tableId, id);
|
|
5878
6023
|
});
|
|
5879
6024
|
}
|
|
@@ -5896,11 +6041,14 @@ var EidosFileRuntime = class {
|
|
|
5896
6041
|
let name = field.name;
|
|
5897
6042
|
let physicalName = field.physicalName ?? null;
|
|
5898
6043
|
if (changes.name !== void 0 && changes.name !== field.name) {
|
|
6044
|
+
if (this.isVirtualTable(tableId)) throw new EidosFileError("table-mutation-not-supported", "File metadata fields cannot be renamed; their names identify filesystem attributes");
|
|
5899
6045
|
name = assertEidosFileDisplayName(changes.name, "Field name");
|
|
5900
6046
|
if (this.listFields(tableId).some((candidate) => candidate.id !== field.id && candidate.name.replace(/[A-Z]/g, (character) => character.toLowerCase()) === name.replace(/[A-Z]/g, (character) => character.toLowerCase()))) throw new EidosFileError("constraint-conflict", `Duplicate Field name: ${name}`);
|
|
5901
6047
|
if (field.physicalName) {
|
|
5902
6048
|
physicalName = name;
|
|
5903
|
-
if (physicalName !== field.physicalName)
|
|
6049
|
+
if (physicalName !== field.physicalName) if (this.isVirtualTable(tableId)) {
|
|
6050
|
+
if (!this.tableCapabilities(tableId).alterSchema) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support altering schema");
|
|
6051
|
+
} else this.connection.exec(`ALTER TABLE ${quoteIdentifier(table.physicalName ?? table.rawTableName)} RENAME COLUMN ${quoteIdentifier(field.physicalName)} TO ${quoteIdentifier(physicalName)}`);
|
|
5904
6052
|
}
|
|
5905
6053
|
const formulaRows = this.connection.query(`SELECT formula.field_id, formula.source_text
|
|
5906
6054
|
FROM ${EIDOS_FILE_FORMULA_FIELDS_TABLE} formula
|
|
@@ -5911,8 +6059,12 @@ var EidosFileRuntime = class {
|
|
|
5911
6059
|
if (expression !== formula.source_text) this.connection.run(`UPDATE ${EIDOS_FILE_FORMULA_FIELDS_TABLE} SET source_text = ? WHERE field_id = ?`, [expression, formula.field_id]);
|
|
5912
6060
|
}
|
|
5913
6061
|
}
|
|
5914
|
-
let settings = field.settings
|
|
5915
|
-
if (
|
|
6062
|
+
let settings = field.settings ? { ...field.settings } : {};
|
|
6063
|
+
if (this.isVirtualTable(tableId) && field.physicalName) settings.vtabStorageKey ??= field.physicalName;
|
|
6064
|
+
if (changes.property !== void 0) settings = {
|
|
6065
|
+
...settings,
|
|
6066
|
+
...presentationSettingsObject(changes.property)
|
|
6067
|
+
};
|
|
5916
6068
|
if (changes.optionValueChanges && changes.optionValueChanges.length > 0) {
|
|
5917
6069
|
if (field.type !== "select" && field.type !== "multi-select") throw new EidosFileError("invalid-schema", "Only Select Fields have option values");
|
|
5918
6070
|
const replacements = new Map(changes.optionValueChanges.map((change) => [change.from, change.to]));
|
|
@@ -6070,6 +6222,7 @@ var EidosFileRuntime = class {
|
|
|
6070
6222
|
tableId
|
|
6071
6223
|
]);
|
|
6072
6224
|
}
|
|
6225
|
+
if (this.isVirtualTable(tableId) && physicalName !== field.physicalName) this.syncVirtualTableSchema(tableId);
|
|
6073
6226
|
return this.fieldByKey(tableId, fieldId);
|
|
6074
6227
|
});
|
|
6075
6228
|
}
|
|
@@ -6246,7 +6399,7 @@ var EidosFileRuntime = class {
|
|
|
6246
6399
|
const table = this.getTable(tableId);
|
|
6247
6400
|
const field = this.fieldByKey(tableId, fieldKey);
|
|
6248
6401
|
if (!field.id) return false;
|
|
6249
|
-
if (field.valueKind === "system") throw new EidosFileError("protected-field", "System Fields cannot be deleted");
|
|
6402
|
+
if (field.valueKind === "system" || field.settings?.isSystem === true) throw new EidosFileError("protected-field", "System Fields cannot be deleted");
|
|
6250
6403
|
if (field.isRecordLabel && !replacementRecordLabelFieldId) throw new EidosFileError("constraint-conflict", "Deleting the Record Label Field requires a replacement Field ID");
|
|
6251
6404
|
const replacement = replacementRecordLabelFieldId ? this.fieldByKey(tableId, replacementRecordLabelFieldId) : void 0;
|
|
6252
6405
|
if (replacement?.id === field.id) throw new EidosFileError("constraint-conflict", "The replacement Record Label Field must be a different Field");
|
|
@@ -6275,8 +6428,19 @@ var EidosFileRuntime = class {
|
|
|
6275
6428
|
for (const formula of this.listFields(tableId).filter((candidate) => candidate.type === "formula")) if (compileEidosFileFormula(formula, this.listFields(tableId)).dependencyFieldIds.includes(field.id)) throw new EidosFileError("formula-in-use", `Formula ${formula.name} depends on ${field.name}`);
|
|
6276
6429
|
this.removeFieldFromViewLayouts(tableId, field.id);
|
|
6277
6430
|
if (field.type === "relation") this.dropRelationTriggers(field.id);
|
|
6278
|
-
|
|
6279
|
-
|
|
6431
|
+
const isVirtual = this.isVirtualTable(tableId);
|
|
6432
|
+
if (isVirtual) {
|
|
6433
|
+
if (!this.tableCapabilities(tableId).alterSchema) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support altering schema");
|
|
6434
|
+
} else if (field.physicalName) this.connection.exec(`ALTER TABLE ${quoteIdentifier(table.physicalName ?? table.rawTableName)} DROP COLUMN ${quoteIdentifier(field.physicalName)}`);
|
|
6435
|
+
const result = this.connection.run(`DELETE FROM ${EIDOS_FILE_FIELDS_TABLE} WHERE id = ?`, [field.id]);
|
|
6436
|
+
if (isVirtual) {
|
|
6437
|
+
this.syncVirtualTableSchema(tableId);
|
|
6438
|
+
if (field.physicalName) this.virtualFieldCleanup.push({
|
|
6439
|
+
tableId,
|
|
6440
|
+
key: String(field.settings?.vtabStorageKey ?? field.physicalName)
|
|
6441
|
+
});
|
|
6442
|
+
}
|
|
6443
|
+
return result.changes > 0;
|
|
6280
6444
|
});
|
|
6281
6445
|
}
|
|
6282
6446
|
viewRow(viewId) {
|
|
@@ -6788,7 +6952,7 @@ var EidosFileRuntime = class {
|
|
|
6788
6952
|
}
|
|
6789
6953
|
/** Returns the zero-based position of a Row ID in a filtered/sorted query. */
|
|
6790
6954
|
getRowIndex(tableId, rowId, query = {}) {
|
|
6791
|
-
const id =
|
|
6955
|
+
const id = this.assertRowId(tableId, rowId, "Row ID");
|
|
6792
6956
|
const compatibleQuery = this.compatibilityQuery(tableId, query);
|
|
6793
6957
|
const fields = this.listFields(tableId);
|
|
6794
6958
|
const source = this.logicalSource(tableId, this.requiredQueryFieldKeys(fields, compatibleQuery), false, false, this.querySearchFragmentFieldIds(fields, compatibleQuery));
|
|
@@ -6805,7 +6969,7 @@ var EidosFileRuntime = class {
|
|
|
6805
6969
|
return Number(result?.count ?? 0);
|
|
6806
6970
|
}
|
|
6807
6971
|
getRecordNeighbors(tableId, rowId, query = {}) {
|
|
6808
|
-
const id =
|
|
6972
|
+
const id = this.assertRowId(tableId, rowId, "Row ID");
|
|
6809
6973
|
const compatibleQuery = this.compatibilityQuery(tableId, query);
|
|
6810
6974
|
const fields = this.listFields(tableId);
|
|
6811
6975
|
const source = this.logicalSource(tableId, this.requiredQueryFieldKeys(fields, compatibleQuery), false, false, this.querySearchFragmentFieldIds(fields, compatibleQuery));
|
|
@@ -6829,7 +6993,7 @@ var EidosFileRuntime = class {
|
|
|
6829
6993
|
}
|
|
6830
6994
|
getRow(tableId, rowId) {
|
|
6831
6995
|
const source = this.logicalSource(tableId);
|
|
6832
|
-
const row = this.connection.get(`WITH logical AS (${source.sql}) SELECT * FROM logical WHERE "__base_rowid" = ?`, [
|
|
6996
|
+
const row = this.connection.get(`WITH logical AS (${source.sql}) SELECT * FROM logical WHERE "__base_rowid" = ?`, [this.assertRowId(tableId, rowId, "Row ID")]);
|
|
6833
6997
|
if (!row) return null;
|
|
6834
6998
|
return Object.fromEntries(Object.entries(row).flatMap(([key, value]) => key === "__base_rowid" ? [] : [[key, rowValue(value)]]));
|
|
6835
6999
|
}
|
|
@@ -6853,7 +7017,7 @@ var EidosFileRuntime = class {
|
|
|
6853
7017
|
getLogicalRowsByIds(tableId, rowIds, options = {}) {
|
|
6854
7018
|
if (rowIds.length === 0) return [];
|
|
6855
7019
|
if (rowIds.length > 500) throw new EidosFileError("resource-limit", "getLogicalRowsByIds accepts at most 500 Row IDs");
|
|
6856
|
-
const ids = rowIds.map((rowId) =>
|
|
7020
|
+
const ids = rowIds.map((rowId) => this.assertRowId(tableId, rowId, "Row ID"));
|
|
6857
7021
|
const fields = this.listFields(tableId);
|
|
6858
7022
|
const requested = options.fields ? options.fields.map((id) => this.fieldByKey(tableId, id)) : fields;
|
|
6859
7023
|
const rowIdField = fields.find((field) => field.type === "row-id");
|
|
@@ -7215,7 +7379,7 @@ var EidosFileRuntime = class {
|
|
|
7215
7379
|
for (const [key, value] of Object.entries(row)) {
|
|
7216
7380
|
if (key === "_id" || key === "id" || key.endsWith("__display")) continue;
|
|
7217
7381
|
const field = this.fieldByKey(tableId, key);
|
|
7218
|
-
if (!field.physicalName || field.valueKind === "system") throw new EidosFileError("protected-field", `Field ${field.name} is read-only`);
|
|
7382
|
+
if (!field.physicalName || field.valueKind === "system" || field.settings?.writable === false || field.settings?.readOnly === true || field.settings?.isSystem === true) throw new EidosFileError("protected-field", `Field ${field.name} is read-only`);
|
|
7219
7383
|
changes.push({
|
|
7220
7384
|
field,
|
|
7221
7385
|
value: this.normalizeStoredValue(field, value, allowUnresolvedRelations)
|
|
@@ -7236,9 +7400,10 @@ var EidosFileRuntime = class {
|
|
|
7236
7400
|
return changes;
|
|
7237
7401
|
}
|
|
7238
7402
|
insertRowInTransaction(tableId, row, allowUnresolvedRelations, applyCreateDefaults) {
|
|
7403
|
+
if (!this.tableCapabilities(tableId).insert) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support row creation");
|
|
7239
7404
|
const table = this.getTable(tableId);
|
|
7240
7405
|
const requestedId = row._id ?? row.id;
|
|
7241
|
-
const rowId = typeof requestedId === "string" ?
|
|
7406
|
+
const rowId = typeof requestedId === "string" ? this.assertRowId(tableId, requestedId, "Row ID") : this.allocateId();
|
|
7242
7407
|
const now = this.operationInstant();
|
|
7243
7408
|
const changes = this.rowChanges(tableId, row, allowUnresolvedRelations, applyCreateDefaults);
|
|
7244
7409
|
const columns = [
|
|
@@ -7260,6 +7425,7 @@ var EidosFileRuntime = class {
|
|
|
7260
7425
|
}
|
|
7261
7426
|
insertImportedRowsInTransaction(tableId, rows) {
|
|
7262
7427
|
if (rows.length === 0) return [];
|
|
7428
|
+
if (!this.tableCapabilities(tableId).insert) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support row creation");
|
|
7263
7429
|
const table = this.getTable(tableId);
|
|
7264
7430
|
const fields = this.listFields(tableId);
|
|
7265
7431
|
const fieldByKey = /* @__PURE__ */ new Map();
|
|
@@ -7272,9 +7438,10 @@ var EidosFileRuntime = class {
|
|
|
7272
7438
|
const tableName = table.physicalName ?? table.rawTableName;
|
|
7273
7439
|
const plans = /* @__PURE__ */ new Map();
|
|
7274
7440
|
const now = this.operationInstant();
|
|
7441
|
+
const validateRowId = this.rowIdValidator(tableId);
|
|
7275
7442
|
const ids = rows.map((row) => {
|
|
7276
7443
|
const requestedId = row._id ?? row.id;
|
|
7277
|
-
const rowId = typeof requestedId === "string" ?
|
|
7444
|
+
const rowId = typeof requestedId === "string" ? validateRowId(requestedId) : this.allocateId();
|
|
7278
7445
|
const keys = Object.keys(row).filter((key) => key !== "_id" && key !== "id" && !key.endsWith("__display"));
|
|
7279
7446
|
const signature = JSON.stringify(keys);
|
|
7280
7447
|
let plan = plans.get(signature);
|
|
@@ -7282,7 +7449,7 @@ var EidosFileRuntime = class {
|
|
|
7282
7449
|
const plannedFields = keys.map((key) => {
|
|
7283
7450
|
const field = fieldByKey.get(key);
|
|
7284
7451
|
if (!field) throw new EidosFileError("field-not-found", `Eidos File Field not found: ${key}`);
|
|
7285
|
-
if (!field.physicalName || field.valueKind === "system") throw new EidosFileError("protected-field", `Field ${field.name} is read-only`);
|
|
7452
|
+
if (!field.physicalName || field.valueKind === "system" || field.settings?.writable === false || field.settings?.readOnly === true || field.settings?.isSystem === true) throw new EidosFileError("protected-field", `Field ${field.name} is read-only`);
|
|
7286
7453
|
return field;
|
|
7287
7454
|
});
|
|
7288
7455
|
const columns = [
|
|
@@ -7344,10 +7511,11 @@ var EidosFileRuntime = class {
|
|
|
7344
7511
|
}])[0];
|
|
7345
7512
|
}
|
|
7346
7513
|
updateRows(tableId, updates) {
|
|
7514
|
+
if (!this.tableCapabilities(tableId).update) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support row updates");
|
|
7347
7515
|
const table = this.getTable(tableId);
|
|
7348
7516
|
return this.mutate(() => {
|
|
7349
7517
|
for (const update of updates) {
|
|
7350
|
-
const rowId =
|
|
7518
|
+
const rowId = this.assertRowId(tableId, update.rowId, "Row ID");
|
|
7351
7519
|
const changes = this.rowChanges(tableId, update.changes, true);
|
|
7352
7520
|
if (changes.length === 0) continue;
|
|
7353
7521
|
const assignments = [...changes.map((change) => `${quoteIdentifier(change.field.physicalName)} = ?`), `"_updated_at" = ?`];
|
|
@@ -7412,7 +7580,7 @@ var EidosFileRuntime = class {
|
|
|
7412
7580
|
return prepared.token;
|
|
7413
7581
|
}
|
|
7414
7582
|
captureRowDeletionUndoState(tableId, rowIds) {
|
|
7415
|
-
const ids = Array.from(new Set(rowIds.map((id) =>
|
|
7583
|
+
const ids = Array.from(new Set(rowIds.map((id) => this.assertRowId(tableId, id, "Row ID"))));
|
|
7416
7584
|
const table = this.getTable(tableId);
|
|
7417
7585
|
const physicalTable = table.physicalName ?? table.rawTableName;
|
|
7418
7586
|
const rawRows = ids.length === 0 ? [] : this.connection.query(`SELECT * FROM ${quoteIdentifier(physicalTable)} WHERE "_id" IN (${ids.map(() => "?").join(", ")})`, ids);
|
|
@@ -7577,7 +7745,7 @@ var EidosFileRuntime = class {
|
|
|
7577
7745
|
}
|
|
7578
7746
|
deleteRows(tableId, rowIds) {
|
|
7579
7747
|
if (rowIds.length === 0) return [];
|
|
7580
|
-
const ids = Array.from(new Set(rowIds.map((id) =>
|
|
7748
|
+
const ids = Array.from(new Set(rowIds.map((id) => this.assertRowId(tableId, id, "Row ID"))));
|
|
7581
7749
|
if (ids.length > 500) throw new EidosFileError("resource-limit", "deleteRows accepts at most 500 Row IDs");
|
|
7582
7750
|
return this.mutateRows({
|
|
7583
7751
|
tableId,
|
|
@@ -7632,7 +7800,7 @@ var EidosFileRuntime = class {
|
|
|
7632
7800
|
const sampleExpression = canonicalTemporalProjection(expression, input.displayType);
|
|
7633
7801
|
const table = this.getTable(tableId);
|
|
7634
7802
|
const label = fields.find((field) => field.isRecordLabel);
|
|
7635
|
-
const previewRowIds = input.rowIds === void 0 ? void 0 : Array.from(new Set(input.rowIds.map((rowId) =>
|
|
7803
|
+
const previewRowIds = input.rowIds === void 0 ? void 0 : Array.from(new Set(input.rowIds.map((rowId) => this.assertRowId(tableId, rowId, "Formula preview Row ID")))).slice(0, 100);
|
|
7636
7804
|
const rowFilter = previewRowIds === void 0 ? "" : previewRowIds.length === 0 ? "WHERE 0" : `WHERE base."_id" IN (${previewRowIds.map(() => "?").join(", ")})`;
|
|
7637
7805
|
const samples = this.connection.query(`SELECT base."_id" AS row_id,
|
|
7638
7806
|
${this.fieldExpression(label, "base", schema)} AS title,
|
|
@@ -7710,7 +7878,7 @@ var EidosFileRuntime = class {
|
|
|
7710
7878
|
const row = id ? { _id: id } : {};
|
|
7711
7879
|
for (const [fieldId, value] of Object.entries(fields)) {
|
|
7712
7880
|
const field = this.fieldByKey(tableId, fieldId);
|
|
7713
|
-
if (field.isDerived || field.valueKind === "system" && field.type !== "row-id") throw new EidosFileError("invalid-value", `Field ${field.name} is read-only`);
|
|
7881
|
+
if (field.isDerived || field.valueKind === "system" && field.type !== "row-id" || field.settings?.writable === false || field.settings?.readOnly === true || field.settings?.isSystem === true) throw new EidosFileError("invalid-value", `Field ${field.name} is read-only`);
|
|
7714
7882
|
row[field.id] = value;
|
|
7715
7883
|
}
|
|
7716
7884
|
return row;
|
|
@@ -7719,15 +7887,19 @@ var EidosFileRuntime = class {
|
|
|
7719
7887
|
const operationCount = (input.insert?.length ?? 0) + (input.update?.length ?? 0) + (input.delete?.length ?? 0);
|
|
7720
7888
|
if (operationCount === 0) throw new EidosFileError("invalid-value", "mutateRows requires at least one operation");
|
|
7721
7889
|
if (operationCount > 500) throw new EidosFileError("resource-limit", "mutateRows accepts at most 500 row operations per atomic batch");
|
|
7890
|
+
const caps = this.tableCapabilities(input.tableId);
|
|
7891
|
+
if (input.insert?.length && !caps.insert) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support row creation");
|
|
7892
|
+
if (input.delete?.length && !caps.delete) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support row deletion");
|
|
7893
|
+
if (input.update?.length && !caps.update) throw new EidosFileError("table-mutation-not-supported", "Virtual table does not support row updates");
|
|
7722
7894
|
const table = this.getTable(input.tableId);
|
|
7723
7895
|
const result = this.mutate(() => {
|
|
7724
7896
|
const operationInstant = this.operationInstant();
|
|
7725
|
-
const deleteIds = (input.delete ?? []).map((id) =>
|
|
7897
|
+
const deleteIds = (input.delete ?? []).map((id) => this.assertRowId(input.tableId, id, "Row ID"));
|
|
7726
7898
|
const deleteSet = new Set(deleteIds);
|
|
7727
7899
|
if (deleteSet.size !== deleteIds.length) throw new EidosFileError("invalid-value", "A Row ID may occur only once in one mutation");
|
|
7728
7900
|
for (const rowId of deleteIds) if (!this.connection.get(`SELECT 1 AS present FROM ${quoteIdentifier(table.physicalName ?? table.rawTableName)} WHERE "_id" = ?`, [rowId])) throw new EidosFileError("row-not-found", `Row not found: ${rowId}`);
|
|
7729
7901
|
const preparedUpdates = (input.update ?? []).map((update) => {
|
|
7730
|
-
const rowId =
|
|
7902
|
+
const rowId = this.assertRowId(input.tableId, update.id, "Row ID");
|
|
7731
7903
|
const requestedChanges = this.rowChanges(input.tableId, this.logicalMutationFields(input.tableId, update.fields), false);
|
|
7732
7904
|
const current = this.connection.get(`SELECT * FROM ${quoteIdentifier(table.physicalName ?? table.rawTableName)} WHERE "_id" = ?`, [rowId]);
|
|
7733
7905
|
if (!current) throw new EidosFileError("row-not-found", `Row not found: ${rowId}`);
|
|
@@ -7856,4 +8028,4 @@ function fieldValueTypeForScan(field) {
|
|
|
7856
8028
|
//#endregion
|
|
7857
8029
|
export { EIDOS_FILE_FORMAT as $, eidosFileLookupDisplayType as A, compileEidosFileFormula as B, isEidosFileFilterOperator as C, assertExactConnectionBindings as Ct, removeEidosFileFilterField as D, nativeToSqlValue as Dt, normalizeEidosFileSorts as E, exactConnectionBindingCount as Et, eidosFileLookupValueType as F, configuredTypeRef as G, compileEidosFileFormulaSource as H, EIDOS_FILE_FORMULA_FIELD_FUNCTION_NAMES as I, eidosFileTypeRefQueryCapabilities as J, eidosFileFieldQueryCapabilities as K, EIDOS_FILE_FORMULA_FUNCTION_NAMES as L, eidosFileLookupStorageCodec as M, eidosFileLookupTargetDisplayType as N, eidosFileFieldStoresJsonArray as O, sqlValueToNative as Ot, eidosFileLookupTargetValueType as P, EIDOS_FILE_FIELDS_TABLE as Q, EIDOS_FILE_FORMULA_PROFILE as R, eidosFileSortExpression as S, EidosAdapterError as St, normalizeEidosFileRowQuery as T, assertUnicodeString as Tt, eidosFileFormulaReferences as U, compileEidosFileFormulaFields as V, rewriteEidosFileFormulaFieldReferences as W, EIDOS_FILE_EXTENSION as X, EIDOS_FILE_APPLICATION_ID as Y, EIDOS_FILE_FEATURES_TABLE as Z, assertEidosFileRowQuery as _, eidosFileTextMultiSelectChoices as _t, EIDOS_FILE_FORMAT_VERSION_TEXT as a, EIDOS_FILE_RELATION_FIELDS_TABLE as at, eidosFileRowQueryPredicateColumns as b, recommendedEidosFileConversionPolicies as bt, incrementEidosFileRevision as c, EIDOS_FILE_SYSTEM_COLUMNS as ct, decodeEidosFileRelationDisplay as d, SQLITE_HEADER as dt, EIDOS_FILE_FORMAT_VERSION as et, decodeEidosFileRelationIds as f, hasEidosFileSqliteHeader as ft, parseNonNegativeInt64 as g, eidosFileConversionTargetNullable as gt, cancellationPortFromSignal as h, eidosFileConversionCanReusePhysicalColumn as ht, scanStableRowPages as i, EIDOS_FILE_MIME_TYPE as it, eidosFileLookupElementType as j, eidosFileLookupAggregateSupportsTarget as k, initializeEidosFileSchema as l, EIDOS_FILE_TABLES_TABLE as lt, MemoryByteSource as m, eidosFileColumnStatTypesForField as mt, validateEidosFile as n, EIDOS_FILE_LOOKUP_FIELDS_TABLE as nt, EIDOS_FILE_SCHEMA_SQL as o, EIDOS_FILE_REQUIRED_TABLES as ot, encodeEidosFileRelationIds as p, eidosFileColumnStatLabel as pt, eidosFileFieldValueType as q, smallestDependencyCycle as r, EIDOS_FILE_META_TABLE as rt, configureEidosFileConnection as s, EIDOS_FILE_SCHEMA_VERSION as st, EidosFileRuntime as t, EIDOS_FILE_FORMULA_FIELDS_TABLE as tt, setEidosFileMetadata as u, EIDOS_FILE_VIEWS_TABLE as ut, compileEidosFileRowQuery as v, isEidosFileUriReference as vt, normalizeEidosFileFilter as w, assertInt64Decimal as wt, eidosFileRowQuerySearchFields as x, ConnectionPortEidosFileConnection as xt, eidosFileRowQueryAffectedByFieldChanges as y, planCanonicalFieldConversion as yt, assertEidosFileFormulaProfile as z };
|
|
7858
8030
|
|
|
7859
|
-
//# sourceMappingURL=runtime-
|
|
8031
|
+
//# sourceMappingURL=runtime-C5aMa-zZ.mjs.map
|