@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
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { a as eidosFileTypeHandler, c as AdapterTransportRuntimeClient, d as transportFitsHostLimit, f as validateAdapterCarrier, i as EidosFileSession, l as AdapterTransportServer, n as EidosFileHandlerRegistry, o as EidosFileRuntimeDataSource, p as validateAdapterEnvelope, r as EidosFileHostError, s as eidosFileSnapshot, t as SQLiteWasmConnectionPort, u as EIDOS_ADAPTER_TRANSPORT_LIMITS } from "./sqlite-wasm-
|
|
3
|
-
import { $ as
|
|
4
|
-
import { _ as
|
|
1
|
+
import { A as isCanonicalEidosFileJson, C as assertEidosFileUuid, D as isEidosFileUuid, E as isEidosFileReservedTableName, M as EidosFileError, O as quoteIdentifier, S as assertEidosFileTableName, T as createEidosFileUuid, _ as normalizeEidosFileAttachmentPath, b as assertEidosFileDisplayName, c as normalizeEidosFileDate, d as decodeEidosFileAttachmentPaths, f as decodeEidosFileValues, g as isSafeEidosFileUri, h as encodeEidosFileValues, j as parseEidosFileJson, k as canonicalizeEidosFileJson, l as normalizeEidosFileInstant, m as encodeEidosFileAttachmentPaths, n as parseEidosFileSelectOptions, o as isCanonicalEidosFileDate, p as eidosFileUriClass, r as currentEidosFileInstant, s as isCanonicalEidosFileInstant, t as assertEidosFileSelectOptions, u as assertEidosFileValues, v as EidosUuidV7Generator, w as createEidosFileIdentifier, x as assertEidosFileTableId, y as assertEidosFileColumnName } from "./select-options-Dr8XCYOS.mjs";
|
|
2
|
+
import { a as eidosFileTypeHandler, c as AdapterTransportRuntimeClient, d as transportFitsHostLimit, f as validateAdapterCarrier, i as EidosFileSession, l as AdapterTransportServer, n as EidosFileHandlerRegistry, o as EidosFileRuntimeDataSource, p as validateAdapterEnvelope, r as EidosFileHostError, s as eidosFileSnapshot, t as SQLiteWasmConnectionPort, u as EIDOS_ADAPTER_TRANSPORT_LIMITS } from "./sqlite-wasm-fT8Z-5Ww.mjs";
|
|
3
|
+
import { $ as EIDOS_FILE_SCHEMA_VERSION, A as eidosFileLookupStorageCodec, B as rewriteEidosFileFormulaFieldReferences, C as normalizeEidosFileRowQuery, D as eidosFileLookupAggregateSupportsTarget, E as eidosFileFieldStoresJsonArray, F as EIDOS_FILE_FORMULA_FUNCTION_NAMES, G as EIDOS_FILE_FORMAT, H as EIDOS_FILE_EXTENSION, I as compileEidosFileFormula, J as EIDOS_FILE_LOOKUP_FIELDS_TABLE, K as EIDOS_FILE_FORMAT_VERSION, L as compileEidosFileFormulaFields, M as eidosFileLookupTargetValueType, N as eidosFileLookupValueType, O as eidosFileLookupDisplayType, P as EIDOS_FILE_FORMULA_FIELD_FUNCTION_NAMES, Q as EIDOS_FILE_REQUIRED_TABLES, R as compileEidosFileFormulaSource, S as normalizeEidosFileFilter, T as removeEidosFileFilterField, U as EIDOS_FILE_FEATURES_TABLE, V as EIDOS_FILE_APPLICATION_ID, W as EIDOS_FILE_FIELDS_TABLE, X as EIDOS_FILE_MIME_TYPE, Y as EIDOS_FILE_META_TABLE, Z as EIDOS_FILE_RELATION_FIELDS_TABLE, _ as assertEidosFileRowQuery, a as EIDOS_FILE_FORMAT_VERSION_TEXT, at as eidosFileColumnStatLabel, b as eidosFileRowQueryPredicateColumns, c as incrementEidosFileRevision, ct as EidosAdapterError, d as decodeEidosFileRelationDisplay, dt as assertUnicodeString, et as EIDOS_FILE_SYSTEM_COLUMNS, f as decodeEidosFileRelationIds, g as parseNonNegativeInt64, h as cancellationPortFromSignal, i as scanStableRowPages, it as hasEidosFileSqliteHeader, j as eidosFileLookupTargetDisplayType, k as eidosFileLookupElementType, l as initializeEidosFileSchema, m as MemoryByteSource, mt as sqlValueToNative, n as validateEidosFile, nt as EIDOS_FILE_VIEWS_TABLE, o as EIDOS_FILE_SCHEMA_SQL, ot as eidosFileColumnStatTypesForField, p as encodeEidosFileRelationIds, pt as nativeToSqlValue, q as EIDOS_FILE_FORMULA_FIELDS_TABLE, r as smallestDependencyCycle, rt as SQLITE_HEADER, s as configureEidosFileConnection, st as ConnectionPortEidosFileConnection, t as EidosFileRuntime, tt as EIDOS_FILE_TABLES_TABLE, u as setEidosFileMetadata, ut as assertInt64Decimal, v as compileEidosFileRowQuery, w as normalizeEidosFileSorts, x as eidosFileSortExpression, y as eidosFileRowQueryAffectedByFieldChanges, z as eidosFileFormulaReferences } from "./runtime-qbuZMbV4.mjs";
|
|
4
|
+
import { _ as isMutableEidosFileFieldType, a as eidosFileCsvExportHeader, b as decodeEidosFileStringArray, c as importEidosFileCsv, d as prepareEidosFileCsvImport, f as MUTABLE_BASE_FIELD_TYPES, g as encodeEidosFileMultiSelectValues, h as eidosFileFieldDisplayValues, i as createEidosFileCsvRowEncoder, l as parseEidosFileCsvRows, m as eidosFileFieldConversionMayRequireLossyConfirmation, n as EIDOS_FILE_CSV_PREVIEW_ROW_COUNT, o as eidosFileCsvRowToEidosFileRow, p as decodeEidosFileMultiSelectValues, r as createEidosFileCsvImportPlan, s as encodeEidosFileCsvRecord, t as EIDOS_FILE_CSV_INFERENCE_ROW_COUNT, u as planEidosFileCsvImport, v as planEidosFileFieldConversion, x as encodeEidosFileJsonArray, y as decodeEidosFileJsonArray } from "./csv-CvzHNNGW.mjs";
|
|
5
|
+
import { n as mergeEidosSystemMetadata, t as EIDOS_SYSTEM_METADATA_TABLES } from "./system-metadata-merge-CjTqAwCi.mjs";
|
|
5
6
|
//#region src/canonical-conversion.ts
|
|
7
|
+
/**
|
|
8
|
+
* Product defaults for conversions requested by the Eidos File editor.
|
|
9
|
+
*
|
|
10
|
+
* These policies are intentionally explicit: the Runtime still reports an
|
|
11
|
+
* `explicit-lossy` preflight and requires confirmation whenever the values in
|
|
12
|
+
* the current Field would actually lose information.
|
|
13
|
+
*/
|
|
14
|
+
function recommendedEidosFileConversionPolicies(from, to) {
|
|
15
|
+
const policies = [];
|
|
16
|
+
if (from === "integer" && to === "number") policies.push("round-binary64");
|
|
17
|
+
if (from === "number" && to === "integer") policies.push("round-ties-even");
|
|
18
|
+
if ((from === "integer" || from === "number") && to === "checkbox") policies.push("zero-false-nonzero-true");
|
|
19
|
+
if (from === "datetime" && to === "date") policies.push("utc-date");
|
|
20
|
+
if (from === "multi-select" && to === "select") policies.push("first");
|
|
21
|
+
if (!LIST_TYPES.has(from) && LIST_TYPES.has(to)) policies.push("null-to-empty-list");
|
|
22
|
+
return policies;
|
|
23
|
+
}
|
|
24
|
+
/** Returns the nullable shape used by editor-initiated conversions. */
|
|
25
|
+
function eidosFileConversionTargetNullable(from, to, sourceNullable) {
|
|
26
|
+
return sourceNullable || from === "multi-select" && to === "select";
|
|
27
|
+
}
|
|
6
28
|
const INT64_MIN = -9223372036854775808n;
|
|
7
29
|
const INT64_MAX = 9223372036854775807n;
|
|
8
30
|
const INT64 = /^(?:0|-[1-9][0-9]*|[1-9][0-9]*)$/u;
|
|
@@ -18,10 +40,17 @@ const TEXT_TYPES = new Set([
|
|
|
18
40
|
"url",
|
|
19
41
|
"select"
|
|
20
42
|
]);
|
|
43
|
+
const SHARED_TEXT_COLUMN_TYPES = new Set([
|
|
44
|
+
"text",
|
|
45
|
+
"select",
|
|
46
|
+
"url"
|
|
47
|
+
]);
|
|
48
|
+
/** True when a conversion can retain the exact nullable SQLite column DDL. */
|
|
49
|
+
function eidosFileConversionCanReusePhysicalColumn(from, to, sourceNullable, targetNullable) {
|
|
50
|
+
return sourceNullable === targetNullable && SHARED_TEXT_COLUMN_TYPES.has(from) && SHARED_TEXT_COLUMN_TYPES.has(to);
|
|
51
|
+
}
|
|
21
52
|
function planCanonicalFieldConversion(input) {
|
|
22
53
|
const policies = new Set(input.policies ?? []);
|
|
23
|
-
const sourceHasSqlNull = input.rows.some((row) => row.value === null);
|
|
24
|
-
const sourceHasJsonNull = input.rows.some((row) => input.from === "json" && row.value === "null");
|
|
25
54
|
const sourceHasEmptyList = input.rows.some((row) => {
|
|
26
55
|
if (row.value === null || typeof row.value !== "string") return false;
|
|
27
56
|
return row.value === "[]";
|
|
@@ -32,11 +61,8 @@ function planCanonicalFieldConversion(input) {
|
|
|
32
61
|
let error;
|
|
33
62
|
for (const row of input.rows) try {
|
|
34
63
|
let converted;
|
|
35
|
-
if (row.value === null) converted = convertNull(input, policies,
|
|
36
|
-
else converted = convertNonNull(input, row.value, policies
|
|
37
|
-
sourceHasSqlNull,
|
|
38
|
-
sourceHasJsonNull
|
|
39
|
-
});
|
|
64
|
+
if (row.value === null) converted = convertNull(input, policies, sourceHasEmptyList);
|
|
65
|
+
else converted = convertNonNull(input, row.value, policies);
|
|
40
66
|
if (converted.value === null && !input.toNullable && !LIST_TYPES.has(input.to)) throw new Error("Destination non-nullability rejects SQL NULL");
|
|
41
67
|
validateDestination(input, converted.value);
|
|
42
68
|
const changed = storageClass(input.from) !== storageClass(input.to) || !sameStorageValue(row.value, converted.value);
|
|
@@ -73,7 +99,7 @@ function planCanonicalFieldConversion(input) {
|
|
|
73
99
|
}))
|
|
74
100
|
};
|
|
75
101
|
}
|
|
76
|
-
function convertNull(input, policies,
|
|
102
|
+
function convertNull(input, policies, sourceHasEmptyList) {
|
|
77
103
|
if (LIST_TYPES.has(input.to)) {
|
|
78
104
|
if (!policies.has("null-to-empty-list")) throw new Error("SQL NULL requires null-to-empty-list for a list destination");
|
|
79
105
|
return {
|
|
@@ -85,10 +111,10 @@ function convertNull(input, policies, sourceHasJsonNull, sourceHasEmptyList) {
|
|
|
85
111
|
if (!input.toNullable) throw new Error("Destination non-nullability rejects SQL NULL");
|
|
86
112
|
return {
|
|
87
113
|
value: null,
|
|
88
|
-
class:
|
|
114
|
+
class: 0
|
|
89
115
|
};
|
|
90
116
|
}
|
|
91
|
-
function convertNonNull(input, value, policies
|
|
117
|
+
function convertNonNull(input, value, policies) {
|
|
92
118
|
const { from, to } = input;
|
|
93
119
|
if (from === to) return {
|
|
94
120
|
value,
|
|
@@ -130,7 +156,7 @@ function convertNonNull(input, value, policies, domain) {
|
|
|
130
156
|
value: asCheckbox(value) ? "true" : "false",
|
|
131
157
|
class: 1
|
|
132
158
|
};
|
|
133
|
-
if (
|
|
159
|
+
if (LIST_TYPES.has(from)) return {
|
|
134
160
|
value: asText(value),
|
|
135
161
|
class: 0
|
|
136
162
|
};
|
|
@@ -169,7 +195,6 @@ function convertNonNull(input, value, policies, domain) {
|
|
|
169
195
|
code: "list-tail-dropped"
|
|
170
196
|
};
|
|
171
197
|
}
|
|
172
|
-
if (from === "json") return unwrapJsonScalar(value, "select", policies, domain);
|
|
173
198
|
}
|
|
174
199
|
if (to === "number") {
|
|
175
200
|
if (from === "integer") {
|
|
@@ -199,7 +224,6 @@ function convertNonNull(input, value, policies, domain) {
|
|
|
199
224
|
class: 1
|
|
200
225
|
};
|
|
201
226
|
}
|
|
202
|
-
if (from === "json") return unwrapJsonScalar(value, "number", policies, domain);
|
|
203
227
|
}
|
|
204
228
|
if (to === "integer") {
|
|
205
229
|
if (from === "checkbox") return {
|
|
@@ -211,7 +235,6 @@ function convertNonNull(input, value, policies, domain) {
|
|
|
211
235
|
class: 1
|
|
212
236
|
};
|
|
213
237
|
if (from === "number") return numberToInteger(asNumber(value), policies);
|
|
214
|
-
if (from === "json") return unwrapJsonScalar(value, "integer", policies, domain);
|
|
215
238
|
}
|
|
216
239
|
if (to === "checkbox") {
|
|
217
240
|
if (from === "text" || from === "select") {
|
|
@@ -252,86 +275,23 @@ function convertNonNull(input, value, policies, domain) {
|
|
|
252
275
|
code: "numeric-to-checkbox"
|
|
253
276
|
};
|
|
254
277
|
}
|
|
255
|
-
if (from === "json") return unwrapJsonScalar(value, "checkbox", policies, domain);
|
|
256
|
-
}
|
|
257
|
-
if (to === "date" || to === "datetime" || to === "url") {
|
|
258
|
-
if (from === "json") return unwrapJsonScalar(value, to, policies, domain);
|
|
259
|
-
}
|
|
260
|
-
if (to === "json") {
|
|
261
|
-
if (from === "json" || LIST_TYPES.has(from)) return {
|
|
262
|
-
value: asText(value),
|
|
263
|
-
class: 0
|
|
264
|
-
};
|
|
265
|
-
if (TEXT_TYPES.has(from)) return {
|
|
266
|
-
value: canonicalizeEidosFileJson(asText(value)),
|
|
267
|
-
class: 1
|
|
268
|
-
};
|
|
269
|
-
if (from === "number") return {
|
|
270
|
-
value: canonicalizeEidosFileJson(asNumber(value)),
|
|
271
|
-
class: 1
|
|
272
|
-
};
|
|
273
|
-
if (from === "integer") {
|
|
274
|
-
const integer = asInteger(value);
|
|
275
|
-
const number = Number(integer);
|
|
276
|
-
if (Number.isInteger(number) && BigInt(number) === integer) return {
|
|
277
|
-
value: canonicalizeEidosFileJson(number),
|
|
278
|
-
class: 1
|
|
279
|
-
};
|
|
280
|
-
if (!policies.has("round-binary64") || !Number.isFinite(number)) throw new Error("Integer JSON conversion requires round-binary64");
|
|
281
|
-
return {
|
|
282
|
-
value: canonicalizeEidosFileJson(number),
|
|
283
|
-
class: 2,
|
|
284
|
-
code: "binary64-rounded"
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
if (from === "checkbox") return {
|
|
288
|
-
value: asCheckbox(value) ? "true" : "false",
|
|
289
|
-
class: 1
|
|
290
|
-
};
|
|
291
278
|
}
|
|
292
279
|
if (LIST_TYPES.has(to)) {
|
|
293
280
|
if (from === "select" && to === "multi-select") return {
|
|
294
281
|
value: canonicalizeEidosFileJson([asText(value)]),
|
|
295
282
|
class: 1
|
|
296
283
|
};
|
|
297
|
-
if (from === "text"
|
|
284
|
+
if (from === "text" && to === "multi-select") return {
|
|
285
|
+
value: canonicalizeEidosFileJson([asText(value)]),
|
|
286
|
+
class: 1
|
|
287
|
+
};
|
|
288
|
+
if (from === "multi-select" && to === "relation" || from === "relation" && to === "multi-select" || from === to) return {
|
|
298
289
|
value: asText(value),
|
|
299
290
|
class: 0
|
|
300
291
|
};
|
|
301
292
|
}
|
|
302
293
|
throw new Error(`Conversion from ${from} to ${to} is forbidden`);
|
|
303
294
|
}
|
|
304
|
-
function unwrapJsonScalar(value, to, policies, domain) {
|
|
305
|
-
const parsed = parseEidosFileJson(asText(value));
|
|
306
|
-
if (parsed === null) {
|
|
307
|
-
if (!policies.has("json-null-to-sql-null")) throw new Error("JSON literal null requires json-null-to-sql-null");
|
|
308
|
-
return {
|
|
309
|
-
value: null,
|
|
310
|
-
class: domain.sourceHasSqlNull && domain.sourceHasJsonNull ? 2 : 1,
|
|
311
|
-
code: "json-null-to-sql-null"
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
if (to === "number" && typeof parsed === "number") return {
|
|
315
|
-
value: parsed,
|
|
316
|
-
class: 1
|
|
317
|
-
};
|
|
318
|
-
if (to === "integer" && typeof parsed === "number") return numberToInteger(parsed, policies);
|
|
319
|
-
if (to === "checkbox" && typeof parsed === "boolean") return {
|
|
320
|
-
value: parsed ? 1n : 0n,
|
|
321
|
-
class: 1
|
|
322
|
-
};
|
|
323
|
-
if ([
|
|
324
|
-
"text",
|
|
325
|
-
"date",
|
|
326
|
-
"datetime",
|
|
327
|
-
"url",
|
|
328
|
-
"select"
|
|
329
|
-
].includes(to) && typeof parsed === "string") return {
|
|
330
|
-
value: parsed,
|
|
331
|
-
class: 1
|
|
332
|
-
};
|
|
333
|
-
throw new Error(`JSON root is incompatible with ${to}`);
|
|
334
|
-
}
|
|
335
295
|
function numberToInteger(number, policies) {
|
|
336
296
|
let result = number;
|
|
337
297
|
let code;
|
|
@@ -376,14 +336,11 @@ function validateDestination(input, value) {
|
|
|
376
336
|
case "url":
|
|
377
337
|
if (!isUriReference(asText(value))) throw new Error("Invalid URI-reference");
|
|
378
338
|
return;
|
|
379
|
-
case "json":
|
|
380
|
-
if (!isCanonicalEidosFileJson(asText(value))) throw new Error("Invalid canonical JSON");
|
|
381
|
-
return;
|
|
382
339
|
case "multi-select":
|
|
383
340
|
parseStringList(value);
|
|
384
341
|
return;
|
|
385
342
|
case "file":
|
|
386
|
-
|
|
343
|
+
decodeEidosFileValues(asText(value));
|
|
387
344
|
return;
|
|
388
345
|
case "relation": {
|
|
389
346
|
const ids = parseStringList(value);
|
|
@@ -477,8 +434,7 @@ const EIDOS_RUNTIME_LIMITS = Object.freeze({
|
|
|
477
434
|
groupFieldsMax: 8,
|
|
478
435
|
searchBytesMax: 4096,
|
|
479
436
|
listElementsMax: 1e4,
|
|
480
|
-
logicalValueBytesMax: 1048576,
|
|
481
|
-
jsonCellBytesMax: 1048576,
|
|
437
|
+
logicalValueBytesMax: 2 * 1048576,
|
|
482
438
|
formulaBytesMax: 4096,
|
|
483
439
|
formulaNodesMax: 1e4,
|
|
484
440
|
formulaDepthMax: 256,
|
|
@@ -513,7 +469,8 @@ function runtimeCapabilities(writable) {
|
|
|
513
469
|
mutateRows: writable,
|
|
514
470
|
mutateView: writable,
|
|
515
471
|
schemaPreflight: writable,
|
|
516
|
-
mutateSchema: writable
|
|
472
|
+
mutateSchema: writable,
|
|
473
|
+
csvImport: writable
|
|
517
474
|
};
|
|
518
475
|
}
|
|
519
476
|
var Runtime = class {
|
|
@@ -580,6 +537,7 @@ var EidosRuntimeService = class {
|
|
|
580
537
|
this.writable = writable;
|
|
581
538
|
this.generator = generator;
|
|
582
539
|
this.capabilitiesValue = runtimeCapabilities(writable);
|
|
540
|
+
if (writable) this.importCsv = (request, context) => this.importCsvRequest(request, context);
|
|
583
541
|
this.epoch = generator.next();
|
|
584
542
|
this.cursorSecret = environment.entropy.randomBytes(16).slice();
|
|
585
543
|
if (this.cursorSecret.byteLength !== 16) throw runtimeError("adapter-error", "EntropyPort returned an invalid cursor authentication key");
|
|
@@ -679,6 +637,11 @@ var EidosRuntimeService = class {
|
|
|
679
637
|
return this.invoke(context, async () => this.read(async () => {
|
|
680
638
|
assertLimit(request.limit, EIDOS_RUNTIME_LIMITS.pageSizeMax, "limit");
|
|
681
639
|
assertProjection(request.projection);
|
|
640
|
+
if (request.offset !== void 0) {
|
|
641
|
+
if (!Number.isSafeInteger(request.offset) || request.offset < 0) throw runtimeError("invalid-request", "offset must be a non-negative JSON safe integer");
|
|
642
|
+
if (request.cursor !== void 0) throw runtimeError("invalid-request", "offset and cursor cannot be used together");
|
|
643
|
+
if (request.direction === "backward") throw runtimeError("invalid-request", "offset only supports forward row queries");
|
|
644
|
+
}
|
|
682
645
|
const query = this.compatibilityQuery(request.tableId, request.query);
|
|
683
646
|
const direction = request.direction ?? "forward";
|
|
684
647
|
const metadata = this.core.info();
|
|
@@ -702,6 +665,7 @@ var EidosRuntimeService = class {
|
|
|
702
665
|
fields,
|
|
703
666
|
query: traversal,
|
|
704
667
|
limit: request.limit + 1,
|
|
668
|
+
...request.offset !== void 0 ? { offset: request.offset } : {},
|
|
705
669
|
cursor: coreCursor,
|
|
706
670
|
resolveRelations: request.projection.resolveRelations.length > 0
|
|
707
671
|
});
|
|
@@ -722,7 +686,7 @@ var EidosRuntimeService = class {
|
|
|
722
686
|
backward: this.core.createRowCursor(request.tableId, this.compatibilityQuery(request.tableId, backwardQuery), row)
|
|
723
687
|
});
|
|
724
688
|
};
|
|
725
|
-
const hasEarlier = direction === "backward" ? hasMoreInTraversal : request.cursor !== void 0;
|
|
689
|
+
const hasEarlier = direction === "backward" ? hasMoreInTraversal : request.cursor !== void 0 || (request.offset ?? 0) > 0;
|
|
726
690
|
const hasLater = direction === "forward" ? hasMoreInTraversal : request.cursor !== void 0;
|
|
727
691
|
return {
|
|
728
692
|
fileId: metadata.fileId,
|
|
@@ -857,6 +821,13 @@ var EidosRuntimeService = class {
|
|
|
857
821
|
}, false, request);
|
|
858
822
|
}
|
|
859
823
|
mutateRows(request, context) {
|
|
824
|
+
return this.mutateRowsRequest(request, context, false);
|
|
825
|
+
}
|
|
826
|
+
/** @internal Host/editor bridge for deletion-only undo while Runtime 1.0 mutationUndo remains disabled. */
|
|
827
|
+
mutateRowsWithUndo(request, context) {
|
|
828
|
+
return this.mutateRowsRequest(request, context, true);
|
|
829
|
+
}
|
|
830
|
+
mutateRowsRequest(request, context, reversibleDeletes) {
|
|
860
831
|
return this.invoke(context, async () => {
|
|
861
832
|
this.assertWritable("mutateRows");
|
|
862
833
|
if (request.changes.length < 1 || request.changes.length > EIDOS_RUNTIME_LIMITS.mutationRowsMax) throw runtimeError("invalid-request", "changes must be within mutationRowsMax");
|
|
@@ -886,7 +857,7 @@ var EidosRuntimeService = class {
|
|
|
886
857
|
rowId
|
|
887
858
|
});
|
|
888
859
|
}
|
|
889
|
-
const inserts = request.changes.filter((change) => change.kind === "create").map((change) => ({ fields: this.mutationValues(request.tableId, change.values) }));
|
|
860
|
+
const inserts = request.changes.filter((change) => change.kind === "create").map((change) => ({ fields: this.mutationValues(request.tableId, change.values, true) }));
|
|
890
861
|
const updates = request.changes.filter((change) => change.kind === "update").map((change) => ({
|
|
891
862
|
id: change.rowId,
|
|
892
863
|
fields: this.mutationValues(request.tableId, change.values)
|
|
@@ -894,7 +865,11 @@ var EidosRuntimeService = class {
|
|
|
894
865
|
const deletes = request.changes.filter((change) => change.kind === "delete").map((change) => change.rowId);
|
|
895
866
|
const beforeRevision = String(this.core.info().revision);
|
|
896
867
|
return this.withCommitBarrier("mutateRows", beforeRevision, context, async () => {
|
|
897
|
-
const
|
|
868
|
+
const reversibleDelete = reversibleDeletes && inserts.length === 0 && updates.length === 0 && deletes.length > 0 ? this.core.deleteRowsReversible(request.tableId, deletes, parseRevision(request.expectedRevision)) : null;
|
|
869
|
+
const result = reversibleDelete ? {
|
|
870
|
+
...reversibleDelete,
|
|
871
|
+
rows: []
|
|
872
|
+
} : this.core.mutateRows({
|
|
898
873
|
tableId: request.tableId,
|
|
899
874
|
insert: inserts,
|
|
900
875
|
update: updates,
|
|
@@ -912,16 +887,20 @@ var EidosRuntimeService = class {
|
|
|
912
887
|
revision: String(after.revision),
|
|
913
888
|
changed: String(after.revision) !== beforeRevision,
|
|
914
889
|
created,
|
|
915
|
-
affectedRows
|
|
890
|
+
affectedRows,
|
|
891
|
+
...reversibleDelete?.undoToken ? { undoToken: reversibleDelete.undoToken } : {}
|
|
916
892
|
};
|
|
917
|
-
if (request.returning)
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
893
|
+
if (request.returning) {
|
|
894
|
+
const returnedRowIds = request.changes.flatMap((change) => {
|
|
895
|
+
if (change.kind === "create") {
|
|
896
|
+
const allocated = created.find((entry) => entry.clientKey === change.clientKey);
|
|
897
|
+
return allocated ? [allocated.rowId] : [];
|
|
898
|
+
}
|
|
899
|
+
if (change.kind === "update") return [change.rowId];
|
|
900
|
+
return [];
|
|
901
|
+
});
|
|
902
|
+
response.returnedRows = await this.getRowsByIdDirect(request.tableId, returnedRowIds, request.returning, request.returning.resolveRelations.length === 0 ? result.rows : void 0);
|
|
903
|
+
}
|
|
925
904
|
return response;
|
|
926
905
|
}, (result) => ({
|
|
927
906
|
operation: "mutateRows",
|
|
@@ -935,8 +914,40 @@ var EidosRuntimeService = class {
|
|
|
935
914
|
}));
|
|
936
915
|
}, false, request);
|
|
937
916
|
}
|
|
938
|
-
|
|
939
|
-
|
|
917
|
+
/** @internal Inverse of mutateRowsWithUndo; not the negotiated Runtime 1.0 extension. */
|
|
918
|
+
revertRowDeletion(request, context) {
|
|
919
|
+
return this.invoke(context, async () => {
|
|
920
|
+
this.assertWritable("revertRowDeletion");
|
|
921
|
+
const current = this.core.info();
|
|
922
|
+
assertCurrentRevision(request.expectedRevision, String(current.revision));
|
|
923
|
+
const beforeRevision = String(current.revision);
|
|
924
|
+
return this.withCommitBarrier("revertMutation", beforeRevision, context, async () => {
|
|
925
|
+
const result = this.core.revertRowMutation(request.undoToken);
|
|
926
|
+
const after = this.core.info();
|
|
927
|
+
return {
|
|
928
|
+
fileId: after.fileId,
|
|
929
|
+
revision: String(after.revision),
|
|
930
|
+
changed: String(after.revision) !== beforeRevision,
|
|
931
|
+
created: [],
|
|
932
|
+
affectedRows: result.affected,
|
|
933
|
+
rowCount: String(result.rowCount),
|
|
934
|
+
...result.undoToken ? { undoToken: result.undoToken } : {}
|
|
935
|
+
};
|
|
936
|
+
}, (result) => ({
|
|
937
|
+
operation: "revertMutation",
|
|
938
|
+
result: {
|
|
939
|
+
fileId: result.fileId,
|
|
940
|
+
revision: result.revision,
|
|
941
|
+
changed: true,
|
|
942
|
+
created: result.created,
|
|
943
|
+
affectedRows: result.affectedRows
|
|
944
|
+
}
|
|
945
|
+
}));
|
|
946
|
+
}, false, request);
|
|
947
|
+
}
|
|
948
|
+
mutationValues(tableId, values, completeCreate = false) {
|
|
949
|
+
const tableFields = this.core.listFields(tableId);
|
|
950
|
+
const fields = new Map(tableFields.map((field) => [field.id, field]));
|
|
940
951
|
const normalized = {};
|
|
941
952
|
for (const [fieldId, value] of Object.entries(values)) {
|
|
942
953
|
const field = fields.get(fieldId);
|
|
@@ -949,24 +960,139 @@ var EidosRuntimeService = class {
|
|
|
949
960
|
normalized[fieldId] = null;
|
|
950
961
|
continue;
|
|
951
962
|
}
|
|
963
|
+
if (type === "file") assertEidosFileValues(value);
|
|
964
|
+
else if (type === "file-entry") assertEidosFileValues([value]);
|
|
952
965
|
if (!logicalValueMatchesType(value, type)) throw runtimeError("invalid-value", "Mutation value type is invalid", { fieldId });
|
|
953
966
|
if (Array.isArray(value) && value.length > EIDOS_RUNTIME_LIMITS.listElementsMax) throw runtimeError("resource-limit", "List exceeds listElementsMax", { fieldId });
|
|
954
967
|
if (type === "date" && !isCanonicalEidosFileDate(value)) throw runtimeError("invalid-value", "Date is not canonical", { fieldId });
|
|
955
968
|
if (type === "datetime" && !isCanonicalEidosFileInstant(value)) throw runtimeError("invalid-value", "Datetime is not canonical", { fieldId });
|
|
956
|
-
if (type === "json") {
|
|
957
|
-
const text = value;
|
|
958
|
-
if (new TextEncoder().encode(text).byteLength > EIDOS_RUNTIME_LIMITS.jsonCellBytesMax) throw runtimeError("resource-limit", "JSON cell exceeds jsonCellBytesMax", { fieldId });
|
|
959
|
-
try {
|
|
960
|
-
if (canonicalizeEidosFileJson(JSON.parse(text)) !== text) throw new Error("non-canonical");
|
|
961
|
-
} catch {
|
|
962
|
-
throw runtimeError("invalid-value", "JSON Field value must be canonical JCS text", { fieldId });
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
969
|
if (type === "integer") normalized[fieldId] = parseSignedInt64(value, "Integer value");
|
|
966
970
|
else normalized[fieldId] = value;
|
|
967
971
|
}
|
|
972
|
+
if (completeCreate) for (const field of tableFields) {
|
|
973
|
+
const fieldId = field.id;
|
|
974
|
+
if (!fieldWritable(field) || fieldId in normalized) continue;
|
|
975
|
+
if (field.nullable) {
|
|
976
|
+
normalized[fieldId] = null;
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
if (field.type === "multi-select" || field.type === "file" || field.type === "relation") {
|
|
980
|
+
normalized[fieldId] = [];
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
throw runtimeError("invalid-value", "Required Field value is missing", { fieldId });
|
|
984
|
+
}
|
|
968
985
|
return normalized;
|
|
969
986
|
}
|
|
987
|
+
importCsvRequest(request, context) {
|
|
988
|
+
const requestSummary = {
|
|
989
|
+
tableId: request.tableId,
|
|
990
|
+
expectedRevision: request.expectedRevision,
|
|
991
|
+
hasHeader: request.hasHeader,
|
|
992
|
+
columns: request.columns,
|
|
993
|
+
csvBytes: request.csv instanceof Uint8Array ? request.csv.byteLength : -1
|
|
994
|
+
};
|
|
995
|
+
return this.invoke(context, async () => {
|
|
996
|
+
this.assertWritable("importCsv");
|
|
997
|
+
if (!(request.csv instanceof Uint8Array)) throw runtimeError("invalid-request", "CSV bytes are required");
|
|
998
|
+
if (typeof request.hasHeader !== "boolean") throw runtimeError("invalid-request", "hasHeader must be boolean");
|
|
999
|
+
if (request.csv.byteLength > EIDOS_RUNTIME_LIMITS.csvBytesMax) throw runtimeError("resource-limit", "CSV exceeds csvBytesMax");
|
|
1000
|
+
if (!Array.isArray(request.columns) || request.columns.length < 1) throw runtimeError("invalid-request", "CSV columns are required");
|
|
1001
|
+
if (request.columns.length > EIDOS_RUNTIME_LIMITS.projectionFieldsMax) throw runtimeError("resource-limit", "CSV column mapping is too large");
|
|
1002
|
+
const before = this.core.info();
|
|
1003
|
+
assertCurrentRevision(request.expectedRevision, String(before.revision));
|
|
1004
|
+
const table = this.core.getTable(request.tableId);
|
|
1005
|
+
const fields = new Map(this.core.listFields(request.tableId).map((field) => [field.id, field]));
|
|
1006
|
+
const csvIndexes = /* @__PURE__ */ new Set();
|
|
1007
|
+
const fieldIds = /* @__PURE__ */ new Set();
|
|
1008
|
+
const columns = request.columns.map(({ csvIndex, fieldId }) => {
|
|
1009
|
+
if (!Number.isSafeInteger(csvIndex) || csvIndex < 0) throw runtimeError("invalid-request", "CSV column indexes must be non-negative integers");
|
|
1010
|
+
if (csvIndexes.has(csvIndex) || fieldIds.has(fieldId)) throw runtimeError("invalid-request", "CSV column mappings must be unique");
|
|
1011
|
+
csvIndexes.add(csvIndex);
|
|
1012
|
+
fieldIds.add(fieldId);
|
|
1013
|
+
const field = fields.get(fieldId);
|
|
1014
|
+
if (!field) throw runtimeError("not-found", "CSV destination Field not found", { fieldId });
|
|
1015
|
+
if (!fieldWritable(field)) throw runtimeError("forbidden", "CSV destination Field is read-only", { fieldId });
|
|
1016
|
+
const type = csvImportFieldType(field);
|
|
1017
|
+
if (!type) throw runtimeError("unsupported", `CSV import does not support ${field.type} Fields`, { fieldId });
|
|
1018
|
+
return {
|
|
1019
|
+
sourceIndex: csvIndex,
|
|
1020
|
+
sourceName: field.name,
|
|
1021
|
+
name: field.name,
|
|
1022
|
+
columnName: field.id,
|
|
1023
|
+
type
|
|
1024
|
+
};
|
|
1025
|
+
});
|
|
1026
|
+
let content;
|
|
1027
|
+
try {
|
|
1028
|
+
content = new TextDecoder("utf-8", { fatal: true }).decode(request.csv);
|
|
1029
|
+
} catch {
|
|
1030
|
+
throw runtimeError("invalid-value", "CSV must be valid UTF-8");
|
|
1031
|
+
}
|
|
1032
|
+
const plan = {
|
|
1033
|
+
fileName: "runtime-import.csv",
|
|
1034
|
+
tableName: table.name,
|
|
1035
|
+
rowCount: 0,
|
|
1036
|
+
skippedRowCount: 0,
|
|
1037
|
+
columns,
|
|
1038
|
+
sampleRows: [],
|
|
1039
|
+
issues: []
|
|
1040
|
+
};
|
|
1041
|
+
const rows = parseEidosFileCsvRows({
|
|
1042
|
+
name: plan.fileName,
|
|
1043
|
+
content
|
|
1044
|
+
}, plan, { hasHeader: request.hasHeader });
|
|
1045
|
+
if (rows.length === 0) return {
|
|
1046
|
+
fileId: before.fileId,
|
|
1047
|
+
tableId: request.tableId,
|
|
1048
|
+
revision: String(before.revision),
|
|
1049
|
+
changed: false,
|
|
1050
|
+
createdRows: []
|
|
1051
|
+
};
|
|
1052
|
+
const beforeRevision = String(before.revision);
|
|
1053
|
+
const importedRows = rows.map((row) => {
|
|
1054
|
+
const rowId = this.generator.next();
|
|
1055
|
+
return {
|
|
1056
|
+
rowId,
|
|
1057
|
+
row: {
|
|
1058
|
+
...row,
|
|
1059
|
+
_id: rowId
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
});
|
|
1063
|
+
const createdRows = importedRows.map(({ rowId }, index) => ({
|
|
1064
|
+
recordIndex: index + (request.hasHeader ? 1 : 0),
|
|
1065
|
+
rowId
|
|
1066
|
+
}));
|
|
1067
|
+
assertJcsBytes({
|
|
1068
|
+
fileId: before.fileId,
|
|
1069
|
+
tableId: request.tableId,
|
|
1070
|
+
revision: "-9223372036854775808",
|
|
1071
|
+
changed: true,
|
|
1072
|
+
createdRows
|
|
1073
|
+
}, EIDOS_RUNTIME_LIMITS.responseBytesMax, "CSV import result");
|
|
1074
|
+
return this.withCommitBarrier("importCsv", beforeRevision, context, () => {
|
|
1075
|
+
this.core.applyCanonicalMutation(() => this.core.appendImportedRows(request.tableId, importedRows.map((entry) => entry.row)), parseRevision(request.expectedRevision));
|
|
1076
|
+
const after = this.core.info();
|
|
1077
|
+
return {
|
|
1078
|
+
fileId: after.fileId,
|
|
1079
|
+
tableId: request.tableId,
|
|
1080
|
+
revision: String(after.revision),
|
|
1081
|
+
changed: String(after.revision) !== beforeRevision,
|
|
1082
|
+
createdRows
|
|
1083
|
+
};
|
|
1084
|
+
}, (result) => ({
|
|
1085
|
+
operation: "importCsv",
|
|
1086
|
+
result: {
|
|
1087
|
+
fileId: result.fileId,
|
|
1088
|
+
tableId: result.tableId,
|
|
1089
|
+
revision: result.revision,
|
|
1090
|
+
changed: true,
|
|
1091
|
+
createdRows: result.createdRows
|
|
1092
|
+
}
|
|
1093
|
+
}));
|
|
1094
|
+
}, false, requestSummary);
|
|
1095
|
+
}
|
|
970
1096
|
async mutateView(request, context) {
|
|
971
1097
|
return this.invoke(context, () => {
|
|
972
1098
|
this.assertWritable("mutateView");
|
|
@@ -1273,7 +1399,7 @@ var EidosRuntimeService = class {
|
|
|
1273
1399
|
name: view.name,
|
|
1274
1400
|
type: view.type,
|
|
1275
1401
|
query: {
|
|
1276
|
-
...view.filter ? { filter: compatibilityFilterToRuntime(view.filter) } : {},
|
|
1402
|
+
...view.filter ? { filter: compatibilityFilterToRuntime(view.filter, this.core.listFields(view.tableId)) } : {},
|
|
1277
1403
|
...view.sorts.length > 0 ? { sort: view.sorts.map((sort) => ({
|
|
1278
1404
|
fieldId: sort.field,
|
|
1279
1405
|
direction: sort.direction,
|
|
@@ -1341,14 +1467,68 @@ var EidosRuntimeService = class {
|
|
|
1341
1467
|
aggregateNow(request) {
|
|
1342
1468
|
if (request.items.length < 1 || request.items.length > EIDOS_RUNTIME_LIMITS.aggregateItemsMax) throw runtimeError("invalid-request", "Aggregate items exceed aggregateItemsMax");
|
|
1343
1469
|
const keys = /* @__PURE__ */ new Set();
|
|
1470
|
+
for (const item of request.items) {
|
|
1471
|
+
if (!item.key || keys.has(item.key)) throw runtimeError("invalid-request", "Aggregate keys must be non-empty and unique");
|
|
1472
|
+
keys.add(item.key);
|
|
1473
|
+
}
|
|
1474
|
+
const query = this.compatibilityQuery(request.tableId, request.query ?? {});
|
|
1475
|
+
if (request.items.every((item) => item.op === "count-all")) {
|
|
1476
|
+
const metadata = this.core.info();
|
|
1477
|
+
const count = String(this.core.countRows(request.tableId, query));
|
|
1478
|
+
return {
|
|
1479
|
+
fileId: metadata.fileId,
|
|
1480
|
+
tableId: request.tableId,
|
|
1481
|
+
revision: String(metadata.revision),
|
|
1482
|
+
results: request.items.map((item) => ({
|
|
1483
|
+
key: item.key,
|
|
1484
|
+
value: count
|
|
1485
|
+
}))
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1344
1488
|
const fields = this.core.listFields(request.tableId);
|
|
1345
1489
|
const fieldsById = new Map(fields.map((field) => [field.id, field]));
|
|
1490
|
+
if (!(request.query !== void 0 && Object.keys(request.query).length > 0) && request.items.every((item) => item.op === "count-all" || item.op === "distinct-count" && fieldsById.get(item.fieldId)?.physicalName || item.op === "distinct-values" && fieldsById.get(item.fieldId)?.physicalName && [
|
|
1491
|
+
"text",
|
|
1492
|
+
"select",
|
|
1493
|
+
"url"
|
|
1494
|
+
].includes(fieldsById.get(item.fieldId).type))) {
|
|
1495
|
+
const metadata = this.core.info();
|
|
1496
|
+
const table = this.core.getTable(request.tableId);
|
|
1497
|
+
const tableSql = quoteSqlIdentifier(table.physicalName ?? table.rawTableName);
|
|
1498
|
+
return {
|
|
1499
|
+
fileId: metadata.fileId,
|
|
1500
|
+
tableId: request.tableId,
|
|
1501
|
+
revision: String(metadata.revision),
|
|
1502
|
+
results: request.items.map((item) => {
|
|
1503
|
+
if (item.op === "count-all") return {
|
|
1504
|
+
key: item.key,
|
|
1505
|
+
value: String(this.core.countRows(request.tableId))
|
|
1506
|
+
};
|
|
1507
|
+
const field = fieldsById.get(item.fieldId);
|
|
1508
|
+
if (item.op === "distinct-values") {
|
|
1509
|
+
const rows = this.core.connection.query(`SELECT DISTINCT ${quoteSqlIdentifier(field.physicalName)} AS value
|
|
1510
|
+
FROM ${tableSql}
|
|
1511
|
+
WHERE ${quoteSqlIdentifier(field.physicalName)} IS NOT NULL
|
|
1512
|
+
ORDER BY ${quoteSqlIdentifier(field.physicalName)} COLLATE BINARY
|
|
1513
|
+
LIMIT ?`, [item.limit + 1]);
|
|
1514
|
+
return {
|
|
1515
|
+
key: item.key,
|
|
1516
|
+
values: rows.slice(0, item.limit).map((row) => String(row.value)),
|
|
1517
|
+
truncated: rows.length > item.limit
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
const count = this.core.connection.get(`SELECT count(DISTINCT ${quoteSqlIdentifier(field.physicalName)}) AS count FROM ${tableSql}`)?.count;
|
|
1521
|
+
return {
|
|
1522
|
+
key: item.key,
|
|
1523
|
+
value: String(count ?? 0)
|
|
1524
|
+
};
|
|
1525
|
+
})
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1346
1528
|
const fieldIds = Array.from(new Set([...request.items.flatMap((item) => item.op === "count-all" ? [] : [item.fieldId]), ...runtimeQueryFieldIds(request.query)]));
|
|
1347
1529
|
for (const fieldId of fieldIds) if (!fieldsById.has(fieldId)) throw runtimeError("not-found", "Aggregate Field not found", { fieldId });
|
|
1348
|
-
const rows = this.core.runtimeScanLogicalRows(request.tableId, fieldIds,
|
|
1530
|
+
const rows = this.core.runtimeScanLogicalRows(request.tableId, fieldIds, query).sort((left, right) => binaryCompare(left.id, right.id));
|
|
1349
1531
|
const results = request.items.map((item) => {
|
|
1350
|
-
if (!item.key || keys.has(item.key)) throw runtimeError("invalid-request", "Aggregate keys must be non-empty and unique");
|
|
1351
|
-
keys.add(item.key);
|
|
1352
1532
|
if (item.op === "count-all") return {
|
|
1353
1533
|
key: item.key,
|
|
1354
1534
|
value: String(rows.length)
|
|
@@ -1464,8 +1644,14 @@ var EidosRuntimeService = class {
|
|
|
1464
1644
|
previousCursor: start > 0 ? cursorForGroup(selected[0]) : null
|
|
1465
1645
|
};
|
|
1466
1646
|
}
|
|
1467
|
-
async getRowsByIdDirect(tableId, rowIds, projection) {
|
|
1468
|
-
const rows =
|
|
1647
|
+
async getRowsByIdDirect(tableId, rowIds, projection, preloadedRows) {
|
|
1648
|
+
const rows = preloadedRows ? (() => {
|
|
1649
|
+
const byId = new Map(preloadedRows.map((row) => [row.id, row]));
|
|
1650
|
+
return rowIds.flatMap((rowId) => {
|
|
1651
|
+
const row = byId.get(rowId);
|
|
1652
|
+
return row ? [row] : [];
|
|
1653
|
+
});
|
|
1654
|
+
})() : this.fetchRowsByIds(tableId, rowIds, projection);
|
|
1469
1655
|
const found = new Set(rows.map((row) => row.id));
|
|
1470
1656
|
const metadata = this.core.info();
|
|
1471
1657
|
const columns = this.columns(tableId, projection);
|
|
@@ -1481,21 +1667,14 @@ var EidosRuntimeService = class {
|
|
|
1481
1667
|
}
|
|
1482
1668
|
fetchRowsByIds(tableId, rowIds, projection) {
|
|
1483
1669
|
if (rowIds.length === 0) return [];
|
|
1484
|
-
|
|
1485
|
-
if (!rowIdField?.id) throw runtimeError("corrupt-file", "Table is missing its Row-ID Field");
|
|
1670
|
+
if (!this.core.listFields(tableId).find((field) => field.systemRole === "row-id" || field.type === "row-id")?.id) throw runtimeError("corrupt-file", "Table is missing its Row-ID Field");
|
|
1486
1671
|
const found = /* @__PURE__ */ new Map();
|
|
1487
1672
|
for (let offset = 0; offset < rowIds.length; offset += EIDOS_RUNTIME_LIMITS.rowsByIdMax) {
|
|
1488
1673
|
const ids = rowIds.slice(offset, offset + EIDOS_RUNTIME_LIMITS.rowsByIdMax);
|
|
1489
|
-
const rows = this.core.
|
|
1674
|
+
const rows = this.core.getLogicalRowsByIds(tableId, ids, {
|
|
1490
1675
|
fields: projection.fields,
|
|
1491
|
-
query: this.compatibilityQuery(tableId, { filter: {
|
|
1492
|
-
op: "in",
|
|
1493
|
-
fieldId: rowIdField.id,
|
|
1494
|
-
values: ids
|
|
1495
|
-
} }),
|
|
1496
|
-
limit: ids.length,
|
|
1497
1676
|
resolveRelations: projection.resolveRelations.length > 0
|
|
1498
|
-
})
|
|
1677
|
+
});
|
|
1499
1678
|
for (const row of rows) found.set(row.id, row);
|
|
1500
1679
|
}
|
|
1501
1680
|
return rowIds.flatMap((rowId) => {
|
|
@@ -1753,6 +1932,20 @@ var EidosRuntimeService = class {
|
|
|
1753
1932
|
object: "field",
|
|
1754
1933
|
id: leaf.fieldId
|
|
1755
1934
|
});
|
|
1935
|
+
for (const view of this.core.listViews(field.tableId)) {
|
|
1936
|
+
const queryReferencesField = view.sorts.some((sort) => sort.field === leaf.fieldId) || compatibilityFilterReferencesField(view.filter, leaf.fieldId);
|
|
1937
|
+
const layoutReferencesField = knownViewLayoutReferencesField(view.properties, leaf.fieldId);
|
|
1938
|
+
if (!queryReferencesField && !layoutReferencesField) continue;
|
|
1939
|
+
dependencies.set("view:" + view.id, {
|
|
1940
|
+
object: "view",
|
|
1941
|
+
id: view.id
|
|
1942
|
+
});
|
|
1943
|
+
if (queryReferencesField) forbid("dependency-blocked", "Saved View query still references the Field", {
|
|
1944
|
+
tableId: field.tableId,
|
|
1945
|
+
fieldId: leaf.fieldId,
|
|
1946
|
+
viewId: view.id
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1756
1949
|
break;
|
|
1757
1950
|
}
|
|
1758
1951
|
case "rename-field":
|
|
@@ -1842,14 +2035,33 @@ var EidosRuntimeService = class {
|
|
|
1842
2035
|
valueChanges: [],
|
|
1843
2036
|
error: "Virtual and inverse Fields cannot be converted"
|
|
1844
2037
|
};
|
|
2038
|
+
const targetNullable = "toNullable" in change ? change.toNullable : false;
|
|
2039
|
+
if (eidosFileConversionCanReusePhysicalColumn(field.type, change.to, field.nullable ?? false, targetNullable) && change.to !== "url") return {
|
|
2040
|
+
classification: "metadata-only",
|
|
2041
|
+
rows: [],
|
|
2042
|
+
affectedRows: "0",
|
|
2043
|
+
valueChanges: []
|
|
2044
|
+
};
|
|
1845
2045
|
const table = this.core.getTable(field.tableId);
|
|
1846
|
-
const rows =
|
|
1847
|
-
|
|
1848
|
-
|
|
2046
|
+
const rows = [];
|
|
2047
|
+
scanStableRowPages(this.core.connection, {
|
|
2048
|
+
columnsSql: `"_id" AS id, ${quoteSqlIdentifier(field.physicalName)} AS value`,
|
|
2049
|
+
tableSql: quoteSqlIdentifier(table.physicalName ?? table.rawTableName),
|
|
2050
|
+
rowIdSql: `"_id"`,
|
|
2051
|
+
rowIdKey: "id"
|
|
2052
|
+
}, (page) => rows.push(...page));
|
|
1849
2053
|
let relationIds;
|
|
1850
2054
|
if (change.to === "relation") {
|
|
1851
2055
|
const target = this.core.getTable(change.definition.targetTableId);
|
|
1852
|
-
relationIds =
|
|
2056
|
+
relationIds = /* @__PURE__ */ new Set();
|
|
2057
|
+
scanStableRowPages(this.core.connection, {
|
|
2058
|
+
columnsSql: `"_id" AS id`,
|
|
2059
|
+
tableSql: quoteSqlIdentifier(target.physicalName ?? target.rawTableName),
|
|
2060
|
+
rowIdSql: `"_id"`,
|
|
2061
|
+
rowIdKey: "id"
|
|
2062
|
+
}, (page) => {
|
|
2063
|
+
for (const row of page) relationIds.add(row.id);
|
|
2064
|
+
});
|
|
1853
2065
|
}
|
|
1854
2066
|
return planCanonicalFieldConversion({
|
|
1855
2067
|
from: field.type,
|
|
@@ -2051,7 +2263,9 @@ var EidosRuntimeService = class {
|
|
|
2051
2263
|
const field = this.field(leaf.fieldId);
|
|
2052
2264
|
const conversion = this.conversionPlan(leaf);
|
|
2053
2265
|
if (conversion.classification === "forbidden") throw runtimeError("forbidden", conversion.error ?? "Conversion predicates no longer hold");
|
|
2054
|
-
|
|
2266
|
+
const targetNullable = "toNullable" in leaf ? leaf.toNullable : false;
|
|
2267
|
+
if (conversion.classification === "metadata-only" && (leaf.to === "text" || leaf.to === "select" || leaf.to === "url") && eidosFileConversionCanReusePhysicalColumn(field.type, leaf.to, field.nullable ?? false, targetNullable)) this.core.convertStoredFieldMetadataOnly(leaf.fieldId, leaf.to, targetNullable);
|
|
2268
|
+
else this.core.convertStoredField(leaf.fieldId, leaf.to, targetNullable, conversion.rows, leaf.to === "relation" ? {
|
|
2055
2269
|
targetTableId: leaf.definition.targetTableId,
|
|
2056
2270
|
cardinality: leaf.definition.cardinality,
|
|
2057
2271
|
onDelete: leaf.definition.onDelete
|
|
@@ -2108,7 +2322,7 @@ var EidosRuntimeService = class {
|
|
|
2108
2322
|
try {
|
|
2109
2323
|
return assertEidosFileValues([candidate])[0];
|
|
2110
2324
|
} catch (error) {
|
|
2111
|
-
throw runtimeError("invalid-value", error instanceof Error ? error.message : "Invalid File entry");
|
|
2325
|
+
throw runtimeError(error instanceof EidosFileError && error.code === "resource-limit" ? "resource-limit" : "invalid-value", error instanceof Error ? error.message : "Invalid File entry");
|
|
2112
2326
|
}
|
|
2113
2327
|
}
|
|
2114
2328
|
read(operation) {
|
|
@@ -2249,6 +2463,17 @@ function fieldValueType(field) {
|
|
|
2249
2463
|
}
|
|
2250
2464
|
return field.type;
|
|
2251
2465
|
}
|
|
2466
|
+
function csvImportFieldType(field) {
|
|
2467
|
+
if (field.isRecordLabel) return "record-label";
|
|
2468
|
+
return [
|
|
2469
|
+
"text",
|
|
2470
|
+
"number",
|
|
2471
|
+
"checkbox",
|
|
2472
|
+
"date",
|
|
2473
|
+
"datetime",
|
|
2474
|
+
"url"
|
|
2475
|
+
].includes(field.type) ? field.type : null;
|
|
2476
|
+
}
|
|
2252
2477
|
function fieldWritable(field) {
|
|
2253
2478
|
const relation = field.type === "relation" ? relationDefinition(field) : void 0;
|
|
2254
2479
|
return !field.systemRole && field.type !== "formula" && field.type !== "lookup" && !(field.type === "relation" && relation?.direction === "inverse");
|
|
@@ -2301,6 +2526,20 @@ function runtimeQueryFieldIds(query) {
|
|
|
2301
2526
|
if (query.filter) visit(query.filter);
|
|
2302
2527
|
return [...ids];
|
|
2303
2528
|
}
|
|
2529
|
+
function compatibilityFilterReferencesField(filter, fieldId) {
|
|
2530
|
+
if (!filter) return false;
|
|
2531
|
+
return filter.children.some((child) => child.type === "group" ? compatibilityFilterReferencesField(child, fieldId) : child.field === fieldId);
|
|
2532
|
+
}
|
|
2533
|
+
function knownViewLayoutReferencesField(layout, fieldId) {
|
|
2534
|
+
if (!layout) return false;
|
|
2535
|
+
if ([
|
|
2536
|
+
"cardFields",
|
|
2537
|
+
"fieldOrder",
|
|
2538
|
+
"hiddenFields"
|
|
2539
|
+
].some((key) => Array.isArray(layout[key]) && layout[key].includes(fieldId))) return true;
|
|
2540
|
+
if (layout.coverField === fieldId || layout.groupField === fieldId || layout.fieldWidths !== null && typeof layout.fieldWidths === "object" && !Array.isArray(layout.fieldWidths) && Object.prototype.hasOwnProperty.call(layout.fieldWidths, fieldId)) return true;
|
|
2541
|
+
return false;
|
|
2542
|
+
}
|
|
2304
2543
|
function reverseRuntimeQuery(query, fields) {
|
|
2305
2544
|
const sorts = (query.sort ?? []).map((sort) => ({
|
|
2306
2545
|
...sort,
|
|
@@ -2330,6 +2569,12 @@ function runtimeQueryToCompatibility(query) {
|
|
|
2330
2569
|
}))
|
|
2331
2570
|
};
|
|
2332
2571
|
}
|
|
2572
|
+
function runtimeListElementType(type) {
|
|
2573
|
+
if (typeof type === "object") return type.element;
|
|
2574
|
+
if (type === "multi-select") return "select";
|
|
2575
|
+
if (type === "relation") return "row-id";
|
|
2576
|
+
if (type === "file") return "file-entry";
|
|
2577
|
+
}
|
|
2333
2578
|
function assertRuntimeRowQuery(fields, query) {
|
|
2334
2579
|
if (!query || typeof query !== "object" || Array.isArray(query)) throw runtimeError("invalid-query", "RowQuery must be an object");
|
|
2335
2580
|
const byId = new Map(fields.map((field) => [field.id, field]));
|
|
@@ -2393,7 +2638,8 @@ function assertRuntimeRowQuery(fields, query) {
|
|
|
2393
2638
|
return;
|
|
2394
2639
|
}
|
|
2395
2640
|
if (node.op === "has-any" || node.op === "has-all") {
|
|
2396
|
-
|
|
2641
|
+
const elementType = runtimeListElementType(type);
|
|
2642
|
+
if (!elementType || !Array.isArray(node.values) || !node.values.every((value) => value !== null && filterValueMatchesType(value, elementType))) throw runtimeError("invalid-query", "List Filter operand is invalid");
|
|
2397
2643
|
return;
|
|
2398
2644
|
}
|
|
2399
2645
|
if (node.op === "relation-has") {
|
|
@@ -2406,14 +2652,14 @@ function assertRuntimeRowQuery(fields, query) {
|
|
|
2406
2652
|
return;
|
|
2407
2653
|
}
|
|
2408
2654
|
if (node.op === "in") {
|
|
2409
|
-
if (!Array.isArray(node.values) || !node.values.every((value) => value !== null &&
|
|
2655
|
+
if (!Array.isArray(node.values) || !node.values.every((value) => value !== null && filterValueMatchesType(value, type))) throw runtimeError("invalid-query", "in operands are invalid");
|
|
2410
2656
|
return;
|
|
2411
2657
|
}
|
|
2412
2658
|
if (node.op === "between") {
|
|
2413
|
-
if (typeof type !== "string" || !isSortableType(type) || node.lower === null || node.upper === null || !
|
|
2659
|
+
if (typeof type !== "string" || !isSortableType(type) || node.lower === null || node.upper === null || !filterValueMatchesType(node.lower, type) || !filterValueMatchesType(node.upper, type)) throw runtimeError("invalid-query", "between operands are invalid");
|
|
2414
2660
|
return;
|
|
2415
2661
|
}
|
|
2416
|
-
if (!("value" in node) || node.value === null || !
|
|
2662
|
+
if (!("value" in node) || node.value === null || !filterValueMatchesType(node.value, type) || [
|
|
2417
2663
|
"lt",
|
|
2418
2664
|
"lte",
|
|
2419
2665
|
"gt",
|
|
@@ -2422,6 +2668,10 @@ function assertRuntimeRowQuery(fields, query) {
|
|
|
2422
2668
|
};
|
|
2423
2669
|
if (query.filter) visit(query.filter, 1);
|
|
2424
2670
|
}
|
|
2671
|
+
function filterValueMatchesType(value, type) {
|
|
2672
|
+
if (type === "row-id") return typeof value === "string";
|
|
2673
|
+
return logicalValueMatchesType(value, type);
|
|
2674
|
+
}
|
|
2425
2675
|
function isSortableType(type) {
|
|
2426
2676
|
return [
|
|
2427
2677
|
"text",
|
|
@@ -2456,8 +2706,18 @@ function logicalValueMatchesType(value, type) {
|
|
|
2456
2706
|
case "datetime": return typeof value === "string";
|
|
2457
2707
|
case "multi-select": return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
2458
2708
|
case "relation": return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
2459
|
-
case "file":
|
|
2460
|
-
|
|
2709
|
+
case "file": try {
|
|
2710
|
+
assertEidosFileValues(value);
|
|
2711
|
+
return true;
|
|
2712
|
+
} catch {
|
|
2713
|
+
return false;
|
|
2714
|
+
}
|
|
2715
|
+
case "file-entry": try {
|
|
2716
|
+
assertEidosFileValues([value]);
|
|
2717
|
+
return true;
|
|
2718
|
+
} catch {
|
|
2719
|
+
return false;
|
|
2720
|
+
}
|
|
2461
2721
|
case "json":
|
|
2462
2722
|
if (typeof value !== "string") return false;
|
|
2463
2723
|
try {
|
|
@@ -2467,20 +2727,24 @@ function logicalValueMatchesType(value, type) {
|
|
|
2467
2727
|
}
|
|
2468
2728
|
}
|
|
2469
2729
|
}
|
|
2470
|
-
function isFileEntry(value) {
|
|
2471
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
2472
|
-
const entry = value;
|
|
2473
|
-
return typeof entry.id === "string" && typeof entry.name === "string" && typeof entry.mediaType === "string" && typeof entry.size === "string" && typeof entry.uri === "string";
|
|
2474
|
-
}
|
|
2475
2730
|
function runtimeFilterToCompatibility(node) {
|
|
2731
|
+
const filter = runtimeFilterNodeToCompatibility(node);
|
|
2732
|
+
return filter.type === "group" ? filter : {
|
|
2733
|
+
type: "group",
|
|
2734
|
+
conjunction: "and",
|
|
2735
|
+
children: [filter]
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
2738
|
+
function runtimeFilterNodeToCompatibility(node) {
|
|
2476
2739
|
const group = (conjunction, children) => ({
|
|
2477
2740
|
type: "group",
|
|
2478
2741
|
conjunction,
|
|
2479
2742
|
children
|
|
2480
2743
|
});
|
|
2481
|
-
if (node.op === "and" || node.op === "or") return group(node.op, node.args.map(
|
|
2744
|
+
if (node.op === "and" || node.op === "or") return group(node.op, node.args.map(runtimeFilterNodeToCompatibility));
|
|
2482
2745
|
if (node.op === "not") {
|
|
2483
|
-
const
|
|
2746
|
+
const filter = runtimeFilterNodeToCompatibility(node.arg);
|
|
2747
|
+
const nested = filter.type === "group" ? filter : group("and", [filter]);
|
|
2484
2748
|
return {
|
|
2485
2749
|
...nested,
|
|
2486
2750
|
negated: nested.negated !== true
|
|
@@ -2497,23 +2761,32 @@ function runtimeFilterToCompatibility(node) {
|
|
|
2497
2761
|
operator: "less-than-or-equal",
|
|
2498
2762
|
value: node.upper
|
|
2499
2763
|
}]);
|
|
2500
|
-
if (node.op === "has-all") return
|
|
2764
|
+
if (node.op === "has-all") return {
|
|
2501
2765
|
type: "rule",
|
|
2502
2766
|
field: node.fieldId,
|
|
2503
2767
|
operator: "is-all-of",
|
|
2504
2768
|
value: node.values
|
|
2505
|
-
}
|
|
2769
|
+
};
|
|
2770
|
+
if (node.op === "in") return group("or", node.values.map((value) => ({
|
|
2771
|
+
type: "rule",
|
|
2772
|
+
field: node.fieldId,
|
|
2773
|
+
operator: "equals",
|
|
2774
|
+
value
|
|
2775
|
+
})));
|
|
2776
|
+
if (node.op === "is-null" || node.op === "is-not-null") return {
|
|
2777
|
+
type: "rule",
|
|
2778
|
+
field: node.fieldId,
|
|
2779
|
+
operator: node.op === "is-null" ? "equals" : "not-equals",
|
|
2780
|
+
value: null
|
|
2781
|
+
};
|
|
2506
2782
|
const leaf = node;
|
|
2507
2783
|
const operator = {
|
|
2508
|
-
"is-null": "is-empty",
|
|
2509
|
-
"is-not-null": "is-not-empty",
|
|
2510
2784
|
eq: "equals",
|
|
2511
2785
|
ne: "not-equals",
|
|
2512
2786
|
lt: "less-than",
|
|
2513
2787
|
lte: "less-than-or-equal",
|
|
2514
2788
|
gt: "greater-than",
|
|
2515
2789
|
gte: "greater-than-or-equal",
|
|
2516
|
-
in: "is-any-of",
|
|
2517
2790
|
contains: "contains",
|
|
2518
2791
|
"starts-with": "starts-with",
|
|
2519
2792
|
"ends-with": "ends-with",
|
|
@@ -2522,52 +2795,136 @@ function runtimeFilterToCompatibility(node) {
|
|
|
2522
2795
|
}[leaf.op];
|
|
2523
2796
|
if (!operator) throw runtimeError("invalid-query", "Filter operation is unsupported");
|
|
2524
2797
|
const value = leaf.op === "in" || leaf.op === "has-any" ? leaf.values : leaf.op === "relation-has" ? [leaf.rowId] : "value" in leaf ? leaf.value : void 0;
|
|
2525
|
-
return
|
|
2798
|
+
return {
|
|
2526
2799
|
type: "rule",
|
|
2527
2800
|
field: leaf.fieldId,
|
|
2528
2801
|
operator,
|
|
2529
2802
|
...value === void 0 ? {} : { value }
|
|
2530
|
-
}
|
|
2803
|
+
};
|
|
2531
2804
|
}
|
|
2532
|
-
function compatibilityFilterToRuntime(group) {
|
|
2533
|
-
|
|
2805
|
+
function compatibilityFilterToRuntime(group, fields = []) {
|
|
2806
|
+
const node = {
|
|
2534
2807
|
op: group.conjunction,
|
|
2535
2808
|
args: group.children.map((child) => {
|
|
2536
|
-
if (child.type === "group") return compatibilityFilterToRuntime(child);
|
|
2537
|
-
|
|
2538
|
-
if (operator === "is-null" || operator === "is-not-null") return {
|
|
2539
|
-
op: operator,
|
|
2540
|
-
fieldId: child.field
|
|
2541
|
-
};
|
|
2542
|
-
if (operator === "in") return {
|
|
2543
|
-
op: "in",
|
|
2544
|
-
fieldId: child.field,
|
|
2545
|
-
values: Array.isArray(child.value) ? child.value : [child.value ?? null]
|
|
2546
|
-
};
|
|
2547
|
-
return {
|
|
2548
|
-
op: operator ?? "eq",
|
|
2549
|
-
fieldId: child.field,
|
|
2550
|
-
value: Array.isArray(child.value) ? child.value[0] : child.value ?? null
|
|
2551
|
-
};
|
|
2809
|
+
if (child.type === "group") return compatibilityFilterToRuntime(child, fields);
|
|
2810
|
+
return compatibilityFilterRuleToRuntime(child, fields);
|
|
2552
2811
|
})
|
|
2553
2812
|
};
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2813
|
+
return group.negated ? {
|
|
2814
|
+
op: "not",
|
|
2815
|
+
arg: node
|
|
2816
|
+
} : node;
|
|
2817
|
+
}
|
|
2818
|
+
function compatibilityFilterRuleToRuntime(rule, fields) {
|
|
2819
|
+
const field = fields.find((candidate) => candidate.id === rule.field);
|
|
2820
|
+
const type = field ? fieldValueType(field) : void 0;
|
|
2821
|
+
const list = type !== void 0 && runtimeListElementType(type) !== void 0;
|
|
2822
|
+
const values = Array.isArray(rule.value) ? rule.value : [rule.value ?? null];
|
|
2823
|
+
const scalarValue = values[0] ?? null;
|
|
2824
|
+
const equalityValue = list && Array.isArray(rule.value) ? rule.value : scalarValue;
|
|
2825
|
+
const requireValue = () => {
|
|
2826
|
+
if (scalarValue === null) throw runtimeError("corrupt-file", "Stored View filter operand is missing");
|
|
2827
|
+
return scalarValue;
|
|
2828
|
+
};
|
|
2829
|
+
const requireValues = () => {
|
|
2830
|
+
if (values.some((value) => value === null)) throw runtimeError("corrupt-file", "Stored View filter operand is null");
|
|
2831
|
+
return values;
|
|
2832
|
+
};
|
|
2833
|
+
const membership = () => list ? {
|
|
2834
|
+
op: "has-any",
|
|
2835
|
+
fieldId: rule.field,
|
|
2836
|
+
values: requireValues()
|
|
2837
|
+
} : {
|
|
2838
|
+
op: "in",
|
|
2839
|
+
fieldId: rule.field,
|
|
2840
|
+
values: requireValues()
|
|
2841
|
+
};
|
|
2842
|
+
switch (rule.operator) {
|
|
2843
|
+
case "is-empty": return list ? {
|
|
2844
|
+
op: "eq",
|
|
2845
|
+
fieldId: rule.field,
|
|
2846
|
+
value: []
|
|
2847
|
+
} : {
|
|
2848
|
+
op: "is-null",
|
|
2849
|
+
fieldId: rule.field
|
|
2850
|
+
};
|
|
2851
|
+
case "is-not-empty": return list ? {
|
|
2852
|
+
op: "ne",
|
|
2853
|
+
fieldId: rule.field,
|
|
2854
|
+
value: []
|
|
2855
|
+
} : {
|
|
2856
|
+
op: "is-not-null",
|
|
2857
|
+
fieldId: rule.field
|
|
2858
|
+
};
|
|
2859
|
+
case "equals": return equalityValue === null ? {
|
|
2860
|
+
op: "is-null",
|
|
2861
|
+
fieldId: rule.field
|
|
2862
|
+
} : {
|
|
2863
|
+
op: "eq",
|
|
2864
|
+
fieldId: rule.field,
|
|
2865
|
+
value: equalityValue
|
|
2866
|
+
};
|
|
2867
|
+
case "not-equals": return equalityValue === null ? {
|
|
2868
|
+
op: "is-not-null",
|
|
2869
|
+
fieldId: rule.field
|
|
2870
|
+
} : {
|
|
2871
|
+
op: "ne",
|
|
2872
|
+
fieldId: rule.field,
|
|
2873
|
+
value: equalityValue
|
|
2874
|
+
};
|
|
2875
|
+
case "less-than": return {
|
|
2876
|
+
op: "lt",
|
|
2877
|
+
fieldId: rule.field,
|
|
2878
|
+
value: requireValue()
|
|
2879
|
+
};
|
|
2880
|
+
case "less-than-or-equal": return {
|
|
2881
|
+
op: "lte",
|
|
2882
|
+
fieldId: rule.field,
|
|
2883
|
+
value: requireValue()
|
|
2884
|
+
};
|
|
2885
|
+
case "greater-than": return {
|
|
2886
|
+
op: "gt",
|
|
2887
|
+
fieldId: rule.field,
|
|
2888
|
+
value: requireValue()
|
|
2889
|
+
};
|
|
2890
|
+
case "greater-than-or-equal": return {
|
|
2891
|
+
op: "gte",
|
|
2892
|
+
fieldId: rule.field,
|
|
2893
|
+
value: requireValue()
|
|
2894
|
+
};
|
|
2895
|
+
case "contains": return list ? membership() : {
|
|
2896
|
+
op: "contains",
|
|
2897
|
+
fieldId: rule.field,
|
|
2898
|
+
value: String(requireValue())
|
|
2899
|
+
};
|
|
2900
|
+
case "not-contains": return {
|
|
2901
|
+
op: "not",
|
|
2902
|
+
arg: list ? membership() : {
|
|
2903
|
+
op: "contains",
|
|
2904
|
+
fieldId: rule.field,
|
|
2905
|
+
value: String(requireValue())
|
|
2906
|
+
}
|
|
2907
|
+
};
|
|
2908
|
+
case "starts-with": return {
|
|
2909
|
+
op: "starts-with",
|
|
2910
|
+
fieldId: rule.field,
|
|
2911
|
+
value: String(requireValue())
|
|
2912
|
+
};
|
|
2913
|
+
case "ends-with": return {
|
|
2914
|
+
op: "ends-with",
|
|
2915
|
+
fieldId: rule.field,
|
|
2916
|
+
value: String(requireValue())
|
|
2917
|
+
};
|
|
2918
|
+
case "is-any-of": return membership();
|
|
2919
|
+
case "is-all-of": return {
|
|
2920
|
+
op: "has-all",
|
|
2921
|
+
fieldId: rule.field,
|
|
2922
|
+
values: requireValues()
|
|
2923
|
+
};
|
|
2924
|
+
case "is-none-of": return {
|
|
2925
|
+
op: "not",
|
|
2926
|
+
arg: membership()
|
|
2927
|
+
};
|
|
2571
2928
|
}
|
|
2572
2929
|
}
|
|
2573
2930
|
function compatibilityLogicalValue(value, type) {
|
|
@@ -2577,12 +2934,24 @@ function compatibilityLogicalValue(value, type) {
|
|
|
2577
2934
|
if (!Array.isArray(parsed)) return null;
|
|
2578
2935
|
return parsed.map((entry) => compatibilityLogicalValue(entry, type.element));
|
|
2579
2936
|
}
|
|
2580
|
-
if (typeof value === "string" && typeof type === "string" && [
|
|
2581
|
-
|
|
2582
|
-
"
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2937
|
+
if (typeof value === "string" && typeof type === "string" && ["multi-select", "relation"].includes(type)) return JSON.parse(value);
|
|
2938
|
+
if (type === "file") try {
|
|
2939
|
+
return typeof value === "string" ? decodeEidosFileValues(value) : assertEidosFileValues(value);
|
|
2940
|
+
} catch {
|
|
2941
|
+
throw runtimeError("corrupt-file", "Stored File value is invalid");
|
|
2942
|
+
}
|
|
2943
|
+
if (typeof value === "string" && type === "file-entry") try {
|
|
2944
|
+
const parsed = JSON.parse(value);
|
|
2945
|
+
if (canonicalizeEidosFileJson(parsed) !== value) throw new Error();
|
|
2946
|
+
return assertEidosFileValues([parsed])[0];
|
|
2947
|
+
} catch {
|
|
2948
|
+
throw runtimeError("corrupt-file", "Stored File entry is invalid");
|
|
2949
|
+
}
|
|
2950
|
+
if (type === "file-entry") try {
|
|
2951
|
+
return assertEidosFileValues([value])[0];
|
|
2952
|
+
} catch {
|
|
2953
|
+
throw runtimeError("corrupt-file", "Stored File entry is invalid");
|
|
2954
|
+
}
|
|
2586
2955
|
if (type === "checkbox" && typeof value === "number") return value === 1;
|
|
2587
2956
|
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || Array.isArray(value) || typeof value === "object" && value !== null) return value;
|
|
2588
2957
|
return null;
|
|
@@ -2992,6 +3361,7 @@ function assertAggregateItems(items, fieldsById) {
|
|
|
2992
3361
|
if (!item.key || keys.has(item.key)) throw runtimeError("invalid-request", "Aggregate keys must be non-empty and unique");
|
|
2993
3362
|
keys.add(item.key);
|
|
2994
3363
|
if (item.op !== "count-all" && !fieldsById.has(item.fieldId)) throw runtimeError("not-found", "Aggregate Field not found", { fieldId: item.fieldId });
|
|
3364
|
+
if (item.op === "distinct-values" && (!Number.isInteger(item.limit) || item.limit < 1 || item.limit > EIDOS_RUNTIME_LIMITS.pageSizeMax)) throw runtimeError("invalid-request", "Distinct value limit exceeds pageSizeMax", { fieldId: item.fieldId });
|
|
2995
3365
|
}
|
|
2996
3366
|
}
|
|
2997
3367
|
function aggregateResultsForRows(items, fieldsById, rows) {
|
|
@@ -3075,6 +3445,14 @@ function aggregateItemResult(item, valueType, values) {
|
|
|
3075
3445
|
key: item.key,
|
|
3076
3446
|
value: String(distinct.size)
|
|
3077
3447
|
};
|
|
3448
|
+
if (item.op === "distinct-values") {
|
|
3449
|
+
const ordered = Array.from(distinct.values()).sort((left, right) => compareAggregateValues(left, right, valueType));
|
|
3450
|
+
return {
|
|
3451
|
+
key: item.key,
|
|
3452
|
+
values: ordered.slice(0, item.limit).map((value) => publicAggregateValue(value, valueType)),
|
|
3453
|
+
truncated: ordered.length > item.limit
|
|
3454
|
+
};
|
|
3455
|
+
}
|
|
3078
3456
|
const sortable = typeof valueType === "string" && isSortableType(valueType);
|
|
3079
3457
|
const numeric = valueType === "integer" || valueType === "number";
|
|
3080
3458
|
if ((item.op === "sum" || item.op === "average") && !numeric) throw runtimeError("invalid-request", `${item.op} requires an Integer or Number Field`, { fieldId: item.fieldId });
|
|
@@ -3232,6 +3610,6 @@ function jcsByteLength(value) {
|
|
|
3232
3610
|
return new TextEncoder().encode(canonicalizeEidosFileJson(value)).byteLength;
|
|
3233
3611
|
}
|
|
3234
3612
|
//#endregion
|
|
3235
|
-
export { AdapterTransportRuntimeClient, AdapterTransportServer, ConnectionPortEidosFileConnection, EIDOS_ADAPTER_TRANSPORT_LIMITS, EIDOS_FILE_APPLICATION_ID, EIDOS_FILE_CSV_INFERENCE_ROW_COUNT, EIDOS_FILE_CSV_PREVIEW_ROW_COUNT, EIDOS_FILE_EXTENSION, EIDOS_FILE_FEATURES_TABLE, EIDOS_FILE_FIELDS_TABLE, EIDOS_FILE_FORMAT, EIDOS_FILE_FORMAT_VERSION, EIDOS_FILE_FORMAT_VERSION_TEXT, EIDOS_FILE_FORMULA_FIELDS_TABLE, EIDOS_FILE_FORMULA_FIELD_FUNCTION_NAMES, EIDOS_FILE_FORMULA_FUNCTION_NAMES, EIDOS_FILE_LOOKUP_FIELDS_TABLE, EIDOS_FILE_META_TABLE, EIDOS_FILE_MIME_TYPE, EIDOS_FILE_RELATION_FIELDS_TABLE, EIDOS_FILE_REQUIRED_TABLES, EIDOS_FILE_SCHEMA_SQL, EIDOS_FILE_SCHEMA_VERSION, EIDOS_FILE_SYSTEM_COLUMNS, EIDOS_FILE_TABLES_TABLE, EIDOS_FILE_VIEWS_TABLE, EIDOS_RUNTIME_LIMITS, EidosAdapterError, EidosFileError, EidosFileHandlerRegistry, EidosFileHostError, EidosFileRuntime, EidosFileRuntimeDataSource, EidosFileSession, EidosRuntimeService, EidosUuidV7Generator, MUTABLE_BASE_FIELD_TYPES, MemoryByteSource, Runtime, SQLITE_HEADER, SQLiteWasmConnectionPort, assertEidosFileColumnName, assertEidosFileDisplayName, assertEidosFileRowQuery, assertEidosFileSelectOptions, assertEidosFileTableId, assertEidosFileUuid, assertEidosFileValues, assertInt64Decimal, assertUnicodeString, cancellationPortFromSignal, canonicalizeEidosFileJson, compileEidosFileFormula, compileEidosFileFormulaFields, compileEidosFileFormulaSource, compileEidosFileRowQuery, configureEidosFileConnection, createEidosFileCsvImportPlan, createEidosFileCsvRowEncoder, createEidosFileIdentifier, createEidosFileUuid, currentEidosFileInstant, decodeEidosFileAttachmentPaths, decodeEidosFileJsonArray, decodeEidosFileMultiSelectValues, decodeEidosFileRelationDisplay, decodeEidosFileRelationIds, decodeEidosFileStringArray, decodeEidosFileValues, eidosFileColumnStatLabel, eidosFileColumnStatTypesForField, eidosFileCsvExportHeader, eidosFileCsvRowToEidosFileRow, eidosFileFieldDisplayValues, eidosFileFieldStoresJsonArray, eidosFileFormulaReferences, eidosFileLookupAggregateSupportsTarget, eidosFileLookupDisplayType, eidosFileLookupElementType, eidosFileLookupStorageCodec, eidosFileLookupTargetDisplayType, eidosFileLookupTargetValueType, eidosFileLookupValueType,
|
|
3613
|
+
export { AdapterTransportRuntimeClient, AdapterTransportServer, ConnectionPortEidosFileConnection, EIDOS_ADAPTER_TRANSPORT_LIMITS, EIDOS_FILE_APPLICATION_ID, EIDOS_FILE_CSV_INFERENCE_ROW_COUNT, EIDOS_FILE_CSV_PREVIEW_ROW_COUNT, EIDOS_FILE_EXTENSION, EIDOS_FILE_FEATURES_TABLE, EIDOS_FILE_FIELDS_TABLE, EIDOS_FILE_FORMAT, EIDOS_FILE_FORMAT_VERSION, EIDOS_FILE_FORMAT_VERSION_TEXT, EIDOS_FILE_FORMULA_FIELDS_TABLE, EIDOS_FILE_FORMULA_FIELD_FUNCTION_NAMES, EIDOS_FILE_FORMULA_FUNCTION_NAMES, EIDOS_FILE_LOOKUP_FIELDS_TABLE, EIDOS_FILE_META_TABLE, EIDOS_FILE_MIME_TYPE, EIDOS_FILE_RELATION_FIELDS_TABLE, EIDOS_FILE_REQUIRED_TABLES, EIDOS_FILE_SCHEMA_SQL, EIDOS_FILE_SCHEMA_VERSION, EIDOS_FILE_SYSTEM_COLUMNS, EIDOS_FILE_TABLES_TABLE, EIDOS_FILE_VIEWS_TABLE, EIDOS_RUNTIME_LIMITS, EIDOS_SYSTEM_METADATA_TABLES, EidosAdapterError, EidosFileError, EidosFileHandlerRegistry, EidosFileHostError, EidosFileRuntime, EidosFileRuntimeDataSource, EidosFileSession, EidosRuntimeService, EidosUuidV7Generator, MUTABLE_BASE_FIELD_TYPES, MemoryByteSource, Runtime, SQLITE_HEADER, SQLiteWasmConnectionPort, assertEidosFileColumnName, assertEidosFileDisplayName, assertEidosFileRowQuery, assertEidosFileSelectOptions, assertEidosFileTableId, assertEidosFileTableName, assertEidosFileUuid, assertEidosFileValues, assertInt64Decimal, assertUnicodeString, cancellationPortFromSignal, canonicalizeEidosFileJson, compileEidosFileFormula, compileEidosFileFormulaFields, compileEidosFileFormulaSource, compileEidosFileRowQuery, configureEidosFileConnection, createEidosFileCsvImportPlan, createEidosFileCsvRowEncoder, createEidosFileIdentifier, createEidosFileUuid, currentEidosFileInstant, decodeEidosFileAttachmentPaths, decodeEidosFileJsonArray, decodeEidosFileMultiSelectValues, decodeEidosFileRelationDisplay, decodeEidosFileRelationIds, decodeEidosFileStringArray, decodeEidosFileValues, eidosFileColumnStatLabel, eidosFileColumnStatTypesForField, eidosFileConversionCanReusePhysicalColumn, eidosFileConversionTargetNullable, eidosFileCsvExportHeader, eidosFileCsvRowToEidosFileRow, eidosFileFieldConversionMayRequireLossyConfirmation, eidosFileFieldDisplayValues, eidosFileFieldStoresJsonArray, eidosFileFormulaReferences, eidosFileLookupAggregateSupportsTarget, eidosFileLookupDisplayType, eidosFileLookupElementType, eidosFileLookupStorageCodec, eidosFileLookupTargetDisplayType, eidosFileLookupTargetValueType, eidosFileLookupValueType, eidosFileRowQueryAffectedByFieldChanges, eidosFileRowQueryPredicateColumns, eidosFileSnapshot, eidosFileSortExpression, eidosFileTypeHandler, eidosFileUriClass, encodeEidosFileAttachmentPaths, encodeEidosFileCsvRecord, encodeEidosFileJsonArray, encodeEidosFileMultiSelectValues, encodeEidosFileRelationIds, encodeEidosFileValues, hasEidosFileSqliteHeader, importEidosFileCsv, incrementEidosFileRevision, initializeEidosFileSchema, isCanonicalEidosFileDate, isCanonicalEidosFileInstant, isCanonicalEidosFileJson, isEidosFileReservedTableName, isEidosFileUuid, isMutableEidosFileFieldType, isSafeEidosFileUri, mergeEidosSystemMetadata, nativeToSqlValue, normalizeEidosFileAttachmentPath, normalizeEidosFileDate, normalizeEidosFileFilter, normalizeEidosFileInstant, normalizeEidosFileRowQuery, normalizeEidosFileSorts, parseEidosFileCsvRows, parseEidosFileJson, parseEidosFileSelectOptions, parseNonNegativeInt64, planCanonicalFieldConversion, planEidosFileCsvImport, planEidosFileFieldConversion, prepareEidosFileCsvImport, quoteIdentifier, recommendedEidosFileConversionPolicies, removeEidosFileFilterField, rewriteEidosFileFormulaFieldReferences, setEidosFileMetadata, sqlValueToNative, transportFitsHostLimit, validateAdapterCarrier, validateAdapterEnvelope, validateEidosFile };
|
|
3236
3614
|
|
|
3237
3615
|
//# sourceMappingURL=index.mjs.map
|