@eidos.space/eidos-file 2.0.3 → 2.0.5
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-CPhqAl4b.d.mts → adapter-contract-CNigdeQ7.d.mts} +9 -2
- package/dist/{adapter-contract-CPhqAl4b.d.mts.map → adapter-contract-CNigdeQ7.d.mts.map} +1 -1
- package/dist/better-sqlite3.d.mts +2 -2
- package/dist/better-sqlite3.mjs +2 -2
- package/dist/browser.d.mts +4 -4
- package/dist/browser.mjs +3 -3
- package/dist/{csv-CvzHNNGW.mjs → csv-BVaUkU1o.mjs} +2 -2
- package/dist/{csv-CvzHNNGW.mjs.map → csv-BVaUkU1o.mjs.map} +1 -1
- package/dist/csv.d.mts +1 -1
- package/dist/csv.mjs +1 -1
- package/dist/index.d.mts +19 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +75 -16
- package/dist/index.mjs.map +1 -1
- package/dist/node-sqlite.d.mts +3 -3
- package/dist/node-sqlite.mjs +3 -3
- package/dist/{runtime-qbuZMbV4.mjs → runtime-ApHTYmlB.mjs} +292 -50
- package/dist/runtime-ApHTYmlB.mjs.map +1 -0
- package/dist/{runtime-CkL1OOJT.d.mts → runtime-BSYpcOBe.d.mts} +16 -5
- package/dist/runtime-BSYpcOBe.d.mts.map +1 -0
- package/dist/{select-options-Dr8XCYOS.mjs → select-options-DSzDn3qm.mjs} +21 -2
- package/dist/{select-options-Dr8XCYOS.mjs.map → select-options-DSzDn3qm.mjs.map} +1 -1
- package/dist/{sqlite-wasm-fT8Z-5Ww.mjs → sqlite-wasm-yva8rnt5.mjs} +3 -3
- package/dist/{sqlite-wasm-fT8Z-5Ww.mjs.map → sqlite-wasm-yva8rnt5.mjs.map} +1 -1
- package/dist/{system-metadata-merge-CjTqAwCi.mjs → system-metadata-merge-Bz6nPbrn.mjs} +3 -3
- package/dist/{system-metadata-merge-CjTqAwCi.mjs.map → system-metadata-merge-Bz6nPbrn.mjs.map} +1 -1
- package/dist/{system-metadata-merge-BaX38cp-.d.mts → system-metadata-merge-DeHwokcY.d.mts} +2 -2
- package/dist/{system-metadata-merge-BaX38cp-.d.mts.map → system-metadata-merge-DeHwokcY.d.mts.map} +1 -1
- package/dist/{temporal-ysCLNSub.d.mts → temporal-CnuhXeP8.d.mts} +3 -3
- package/dist/{temporal-ysCLNSub.d.mts.map → temporal-CnuhXeP8.d.mts.map} +1 -1
- package/package.json +1 -1
- package/dist/runtime-CkL1OOJT.d.mts.map +0 -1
- package/dist/runtime-qbuZMbV4.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as isEidosFileUuid, C as assertEidosFileDisplayName, E as assertEidosFileUuid, F as EidosFileError, M as canonicalizeEidosFileJson, N as isCanonicalEidosFileJson, O as createEidosFileUuid, P as parseEidosFileJson, T as assertEidosFileTableName, c as eidosFileInstantSqlCheck, d as normalizeEidosFileDate, f as normalizeEidosFileInstant, h as decodeEidosFileValues, i as parseEidosFileSelectDefaultOption, j as quoteIdentifier, k as isEidosFileReservedTableName, l as isCanonicalEidosFileDate, n as assertEidosFileSelectDefaultOption, o as currentEidosFileInstant, p as assertEidosFileValues, r as assertEidosFileSelectOptions, s as eidosFileDateSqlCheck, t as assertEidosFileMultiSelectHasNoDefaultOption, u as isCanonicalEidosFileInstant } from "./select-options-DSzDn3qm.mjs";
|
|
2
2
|
//#region src/connection-port.ts
|
|
3
3
|
const INT64_MIN$2 = -9223372036854775808n;
|
|
4
4
|
const INT64_MAX$2 = 9223372036854775807n;
|
|
@@ -1329,8 +1329,14 @@ const FILTER_OPERATORS$1 = new Set([
|
|
|
1329
1329
|
"is-not-empty",
|
|
1330
1330
|
"is-any-of",
|
|
1331
1331
|
"is-all-of",
|
|
1332
|
-
"is-none-of"
|
|
1332
|
+
"is-none-of",
|
|
1333
|
+
"is-between",
|
|
1334
|
+
"is-relative-to-today"
|
|
1333
1335
|
]);
|
|
1336
|
+
/** Returns whether a persisted compatibility filter operator is executable. */
|
|
1337
|
+
function isEidosFileFilterOperator(value) {
|
|
1338
|
+
return FILTER_OPERATORS$1.has(value);
|
|
1339
|
+
}
|
|
1334
1340
|
const MAX_QUERY_DEPTH = 8;
|
|
1335
1341
|
const MAX_QUERY_FILTER_NODES = 100;
|
|
1336
1342
|
const MAX_QUERY_SORTS = 32;
|
|
@@ -1355,21 +1361,43 @@ function assertEidosFileRowQuery(value) {
|
|
|
1355
1361
|
filter.children.forEach((child) => visit(child, depth + 1));
|
|
1356
1362
|
return;
|
|
1357
1363
|
}
|
|
1358
|
-
if (filter.type !== "rule" || typeof filter.field !== "string" || !
|
|
1364
|
+
if (filter.type !== "rule" || typeof filter.field !== "string" || !isEidosFileFilterOperator(filter.operator)) throw new EidosFileError("invalid-query", "Invalid filter rule");
|
|
1365
|
+
if (filter.operator === "is-relative-to-today") {
|
|
1366
|
+
if (!isRelativeDateValue(filter.value)) throw new EidosFileError("invalid-query", "Relative date filter value is invalid");
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1359
1369
|
const values = Array.isArray(filter.value) ? filter.value : [filter.value];
|
|
1360
1370
|
if (values.length > 500 || values.some((entry) => entry !== void 0 && entry !== null && typeof entry !== "string" && typeof entry !== "number" && typeof entry !== "boolean")) throw new EidosFileError("query-limit", "Filter values exceed the query limit");
|
|
1371
|
+
if (filter.operator === "is-between" && values.length !== 2) throw new EidosFileError("invalid-query", "Between filter requires exactly two values");
|
|
1361
1372
|
};
|
|
1362
1373
|
if (query.filter !== void 0 && query.filter !== null) visit(query.filter, 0);
|
|
1363
1374
|
}
|
|
1364
1375
|
function filterValue(value) {
|
|
1365
1376
|
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value : void 0;
|
|
1366
1377
|
}
|
|
1378
|
+
function isRelativeDateValue(value) {
|
|
1379
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1380
|
+
const candidate = value;
|
|
1381
|
+
return [
|
|
1382
|
+
"past",
|
|
1383
|
+
"next",
|
|
1384
|
+
"this"
|
|
1385
|
+
].includes(String(candidate.direction)) && [
|
|
1386
|
+
"day",
|
|
1387
|
+
"week",
|
|
1388
|
+
"month",
|
|
1389
|
+
"year"
|
|
1390
|
+
].includes(String(candidate.unit));
|
|
1391
|
+
}
|
|
1367
1392
|
function normalizeFilterNode(value, depth) {
|
|
1368
1393
|
if (depth > MAX_QUERY_DEPTH || typeof value !== "object" || value === null) return null;
|
|
1369
1394
|
const candidate = value;
|
|
1370
1395
|
if (candidate.type === "rule") {
|
|
1371
|
-
if (typeof candidate.field !== "string" || !
|
|
1372
|
-
const values =
|
|
1396
|
+
if (typeof candidate.field !== "string" || !isEidosFileFilterOperator(candidate.operator)) return null;
|
|
1397
|
+
const values = candidate.operator === "is-relative-to-today" && isRelativeDateValue(candidate.value) ? {
|
|
1398
|
+
direction: candidate.value.direction,
|
|
1399
|
+
unit: candidate.value.unit
|
|
1400
|
+
} : Array.isArray(candidate.value) ? candidate.value.flatMap((entry) => {
|
|
1373
1401
|
const normalized = filterValue(entry);
|
|
1374
1402
|
return normalized === void 0 ? [] : [normalized];
|
|
1375
1403
|
}) : filterValue(candidate.value);
|
|
@@ -1526,6 +1554,65 @@ function sqlFieldValue(field, value) {
|
|
|
1526
1554
|
}
|
|
1527
1555
|
return sqlValue(value);
|
|
1528
1556
|
}
|
|
1557
|
+
function temporalFieldType(field) {
|
|
1558
|
+
const type = (field.type === "formula" || field.type === "lookup") && typeof field.property?.displayType === "string" ? field.property.displayType : field.type;
|
|
1559
|
+
if (type === "date") return "date";
|
|
1560
|
+
if (type === "datetime" || type === "created-time" || type === "last-edited-time") return "datetime";
|
|
1561
|
+
return null;
|
|
1562
|
+
}
|
|
1563
|
+
function shiftUtcMonth(instant, amount) {
|
|
1564
|
+
const result = new Date(instant.getTime());
|
|
1565
|
+
const day = result.getUTCDate();
|
|
1566
|
+
result.setUTCDate(1);
|
|
1567
|
+
result.setUTCMonth(result.getUTCMonth() + amount);
|
|
1568
|
+
const endOfTargetMonth = new Date(Date.UTC(result.getUTCFullYear(), result.getUTCMonth() + 1, 0)).getUTCDate();
|
|
1569
|
+
result.setUTCDate(Math.min(day, endOfTargetMonth));
|
|
1570
|
+
return result;
|
|
1571
|
+
}
|
|
1572
|
+
function shiftUtcYear(instant, amount) {
|
|
1573
|
+
const result = new Date(instant.getTime());
|
|
1574
|
+
const month = result.getUTCMonth();
|
|
1575
|
+
const day = result.getUTCDate();
|
|
1576
|
+
result.setUTCDate(1);
|
|
1577
|
+
result.setUTCFullYear(result.getUTCFullYear() + amount);
|
|
1578
|
+
result.setUTCMonth(month);
|
|
1579
|
+
const endOfTargetMonth = new Date(Date.UTC(result.getUTCFullYear(), month + 1, 0)).getUTCDate();
|
|
1580
|
+
result.setUTCDate(Math.min(day, endOfTargetMonth));
|
|
1581
|
+
return result;
|
|
1582
|
+
}
|
|
1583
|
+
function shiftUtcUnit(instant, unit, amount) {
|
|
1584
|
+
if (unit === "day" || unit === "week") {
|
|
1585
|
+
const days = unit === "day" ? 1 : 7;
|
|
1586
|
+
return new Date(instant.getTime() + amount * days * 864e5);
|
|
1587
|
+
}
|
|
1588
|
+
return unit === "month" ? shiftUtcMonth(instant, amount) : shiftUtcYear(instant, amount);
|
|
1589
|
+
}
|
|
1590
|
+
function utcPeriodStart(instant, unit) {
|
|
1591
|
+
const year = instant.getUTCFullYear();
|
|
1592
|
+
const month = instant.getUTCMonth();
|
|
1593
|
+
const day = instant.getUTCDate();
|
|
1594
|
+
if (unit === "year") return new Date(Date.UTC(year, 0, 1));
|
|
1595
|
+
if (unit === "month") return new Date(Date.UTC(year, month, 1));
|
|
1596
|
+
const start = new Date(Date.UTC(year, month, day));
|
|
1597
|
+
if (unit === "week") {
|
|
1598
|
+
const daysSinceMonday = (start.getUTCDay() + 6) % 7;
|
|
1599
|
+
start.setUTCDate(start.getUTCDate() - daysSinceMonday);
|
|
1600
|
+
}
|
|
1601
|
+
return start;
|
|
1602
|
+
}
|
|
1603
|
+
function relativeTemporalBounds(relative, referenceInstant, type) {
|
|
1604
|
+
const reference = new Date(normalizeEidosFileInstant(referenceInstant, "Relative filter reference"));
|
|
1605
|
+
return (() => {
|
|
1606
|
+
if (relative.direction === "this") {
|
|
1607
|
+
const start = utcPeriodStart(reference, relative.unit);
|
|
1608
|
+
const nextStart = relative.unit === "day" || relative.unit === "week" ? new Date(start.getTime() + (relative.unit === "day" ? 1 : 7) * 864e5) : shiftUtcUnit(start, relative.unit, 1);
|
|
1609
|
+
return [start, /* @__PURE__ */ new Date(nextStart.getTime() - 1)];
|
|
1610
|
+
}
|
|
1611
|
+
const past = relative.direction === "past";
|
|
1612
|
+
const boundary = shiftUtcUnit(reference, relative.unit, past ? -1 : 1);
|
|
1613
|
+
return past ? [boundary, reference] : [reference, boundary];
|
|
1614
|
+
})().map((value) => type === "date" ? value.toISOString().slice(0, 10) : value.toISOString());
|
|
1615
|
+
}
|
|
1529
1616
|
function likeExpression(field, operator, value, params) {
|
|
1530
1617
|
const column = quoteIdentifier(field.tableColumnName);
|
|
1531
1618
|
const escaped = escapeLike(value);
|
|
@@ -1552,13 +1639,28 @@ function likeExpression(field, operator, value, params) {
|
|
|
1552
1639
|
)` : `COALESCE(${caseInsensitiveLike(column, pattern, value, params)}, 0)`;
|
|
1553
1640
|
return operator === "not-contains" ? `NOT (${expression})` : expression;
|
|
1554
1641
|
}
|
|
1555
|
-
function compileRule(rule, fields, params) {
|
|
1642
|
+
function compileRule(rule, fields, params, referenceInstant) {
|
|
1556
1643
|
const field = requireField(fields, rule.field);
|
|
1557
1644
|
const column = quoteIdentifier(field.tableColumnName);
|
|
1558
1645
|
const arrayCodec = field.storageCodec === "json_array" || field.storageCodec === "relation";
|
|
1559
1646
|
const empty = arrayCodec ? `(${column} IS NULL OR (json_valid(${column}) AND json_type(${column}) = 'array' AND json_array_length(${column}) = 0))` : `(${column} IS NULL)`;
|
|
1560
1647
|
if (rule.operator === "is-empty") return empty;
|
|
1561
1648
|
if (rule.operator === "is-not-empty") return `NOT ${empty}`;
|
|
1649
|
+
if (rule.operator === "is-relative-to-today") {
|
|
1650
|
+
const type = temporalFieldType(field);
|
|
1651
|
+
if (!type) throw new EidosFileError("invalid-query", `${field.name} does not support relative date filters`);
|
|
1652
|
+
if (!isRelativeDateValue(rule.value)) throw new EidosFileError("invalid-query", `${field.name} relative date filter is invalid`);
|
|
1653
|
+
const [lower, upper] = relativeTemporalBounds(rule.value, referenceInstant, type);
|
|
1654
|
+
params.push(lower, upper);
|
|
1655
|
+
return `COALESCE(${column} >= ? AND ${column} <= ?, 0)`;
|
|
1656
|
+
}
|
|
1657
|
+
if (rule.operator === "is-between") {
|
|
1658
|
+
if (!Array.isArray(rule.value) || rule.value.length !== 2) throw new EidosFileError("invalid-query", `${field.name} between filter requires two values`);
|
|
1659
|
+
const [lower, upper] = rule.value;
|
|
1660
|
+
if (lower === null || upper === null) throw new EidosFileError("invalid-query", `${field.name} between filter values cannot be null`);
|
|
1661
|
+
params.push(sqlFieldValue(field, lower), sqlFieldValue(field, upper));
|
|
1662
|
+
return `COALESCE(${column} >= ? AND ${column} <= ?, 0)`;
|
|
1663
|
+
}
|
|
1562
1664
|
if (rule.operator === "is-any-of" || rule.operator === "is-all-of" || rule.operator === "is-none-of") {
|
|
1563
1665
|
const values = Array.isArray(rule.value) ? rule.value : [];
|
|
1564
1666
|
if (values.length === 0) return rule.operator === "is-any-of" ? "0" : "1";
|
|
@@ -1585,6 +1687,7 @@ function compileRule(rule, fields, params) {
|
|
|
1585
1687
|
return rule.operator === "is-none-of" ? `NOT (${expression})` : expression;
|
|
1586
1688
|
}
|
|
1587
1689
|
const value = Array.isArray(rule.value) ? rule.value[0] : rule.value;
|
|
1690
|
+
if (value !== null && typeof value === "object") throw new EidosFileError("invalid-query", `${field.name} filter has an invalid structured operand`);
|
|
1588
1691
|
if (rule.operator === "equals" || rule.operator === "not-equals") {
|
|
1589
1692
|
if (arrayCodec && Array.isArray(rule.value)) {
|
|
1590
1693
|
params.push(canonicalizeEidosFileJson(rule.value));
|
|
@@ -1606,8 +1709,8 @@ function compileRule(rule, fields, params) {
|
|
|
1606
1709
|
params.push(sqlFieldValue(field, value));
|
|
1607
1710
|
return `COALESCE(${column} ${comparison} ?, 0)`;
|
|
1608
1711
|
}
|
|
1609
|
-
function compileGroup(group, fields, params) {
|
|
1610
|
-
const children = group.children.map((child) => child.type === "group" ? compileGroup(child, fields, params) : compileRule(child, fields, params));
|
|
1712
|
+
function compileGroup(group, fields, params, referenceInstant) {
|
|
1713
|
+
const children = group.children.map((child) => child.type === "group" ? compileGroup(child, fields, params, referenceInstant) : compileRule(child, fields, params, referenceInstant));
|
|
1611
1714
|
const expression = children.length === 0 ? group.conjunction === "or" ? "0" : "1" : `(${children.join(group.conjunction === "or" ? " OR " : " AND ")})`;
|
|
1612
1715
|
return group.negated ? `NOT (${expression})` : expression;
|
|
1613
1716
|
}
|
|
@@ -1629,7 +1732,7 @@ function compileSorts(sorts, fields) {
|
|
|
1629
1732
|
clauses.push("\"__base_rowid\" ASC");
|
|
1630
1733
|
return `ORDER BY ${clauses.join(", ")}`;
|
|
1631
1734
|
}
|
|
1632
|
-
function compileEidosFileRowQuery(fields, query = {}) {
|
|
1735
|
+
function compileEidosFileRowQuery(fields, query = {}, context = {}) {
|
|
1633
1736
|
query = normalizeEidosFileRowQuery(query);
|
|
1634
1737
|
const byColumn = new Map(fields.map((field) => [field.tableColumnName, field]));
|
|
1635
1738
|
const params = [];
|
|
@@ -1640,7 +1743,7 @@ function compileEidosFileRowQuery(fields, query = {}) {
|
|
|
1640
1743
|
const searchClauses = searchableFields(fields, query.searchFields).map((field) => caseInsensitiveLike(quoteIdentifier(field.tableColumnName), pattern, search, params));
|
|
1641
1744
|
if (searchClauses.length > 0) where.push(`(${searchClauses.join(" OR ")})`);
|
|
1642
1745
|
}
|
|
1643
|
-
if (query.filter) where.push(compileGroup(query.filter, byColumn, params));
|
|
1746
|
+
if (query.filter) where.push(compileGroup(query.filter, byColumn, params, context.referenceInstant ?? currentEidosFileInstant()));
|
|
1644
1747
|
return {
|
|
1645
1748
|
whereSql: where.length > 0 ? `WHERE ${where.join(" AND ")}` : "",
|
|
1646
1749
|
orderSql: compileSorts(query.sorts, byColumn),
|
|
@@ -2629,7 +2732,10 @@ const FILTER_OPERATORS = new Set([
|
|
|
2629
2732
|
"is-empty",
|
|
2630
2733
|
"is-not-empty",
|
|
2631
2734
|
"is-any-of",
|
|
2632
|
-
"is-
|
|
2735
|
+
"is-all-of",
|
|
2736
|
+
"is-none-of",
|
|
2737
|
+
"is-between",
|
|
2738
|
+
"is-relative-to-today"
|
|
2633
2739
|
]);
|
|
2634
2740
|
const LEVELS = {
|
|
2635
2741
|
identity: 0,
|
|
@@ -2847,6 +2953,8 @@ function validateEidosFile(connection, options = {}) {
|
|
|
2847
2953
|
}
|
|
2848
2954
|
if (row.type === "select" || row.type === "multi-select") try {
|
|
2849
2955
|
assertEidosFileSelectOptions(settings);
|
|
2956
|
+
if (row.type === "select") assertEidosFileSelectDefaultOption(settings);
|
|
2957
|
+
else assertEidosFileMultiSelectHasNoDefaultOption(settings);
|
|
2850
2958
|
} catch (error) {
|
|
2851
2959
|
add(errors, "invalid-schema", error instanceof Error ? error.message : "Invalid Select catalog");
|
|
2852
2960
|
}
|
|
@@ -3149,16 +3257,23 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3149
3257
|
const layout = parseEidosFileJson(view.layout_json);
|
|
3150
3258
|
if (!query || Array.isArray(query) || typeof query !== "object") throw new Error("View query_json must be an object");
|
|
3151
3259
|
if (!layout || Array.isArray(layout) || typeof layout !== "object") throw new Error("View layout_json must be an object");
|
|
3260
|
+
let unsupportedQuery = Object.keys(query).some((key) => key !== "filter" && key !== "sort");
|
|
3152
3261
|
const checkFilter = (value) => {
|
|
3153
3262
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("View filter nodes must be objects");
|
|
3154
3263
|
const node = value;
|
|
3155
3264
|
if (Array.isArray(node.args)) {
|
|
3156
|
-
if (
|
|
3265
|
+
if (typeof node.op !== "string") throw new Error("View filter group has an invalid op");
|
|
3266
|
+
if (node.op !== "and" && node.op !== "or" || Object.keys(node).some((key) => key !== "op" && key !== "args")) unsupportedQuery = true;
|
|
3157
3267
|
node.args.forEach(checkFilter);
|
|
3158
3268
|
return;
|
|
3159
3269
|
}
|
|
3160
3270
|
if (typeof node.field !== "string" || !fieldIds.has(node.field)) throw new Error("View filter references an unknown Field ID");
|
|
3161
|
-
if (typeof node.op !== "string"
|
|
3271
|
+
if (typeof node.op !== "string") throw new Error("View filter rule has an invalid operator");
|
|
3272
|
+
if (!FILTER_OPERATORS.has(node.op)) {
|
|
3273
|
+
unsupportedQuery = true;
|
|
3274
|
+
return;
|
|
3275
|
+
}
|
|
3276
|
+
if (Object.keys(node).some((key) => key !== "field" && key !== "op" && key !== "value")) unsupportedQuery = true;
|
|
3162
3277
|
const field = fieldsById.get(node.field);
|
|
3163
3278
|
if ((field.storageCodec === "json_array" || field.storageCodec === "relation") && [
|
|
3164
3279
|
"greater-than",
|
|
@@ -3171,12 +3286,36 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3171
3286
|
if (field.type === "relation" && "value" in node) {
|
|
3172
3287
|
if (!(Array.isArray(node.value) ? node.value : [node.value]).every((entry) => entry === null || isEidosFileUuid(entry))) throw new Error("View Relation filter values must be canonical Row IDs");
|
|
3173
3288
|
}
|
|
3289
|
+
if (node.op === "is-between") {
|
|
3290
|
+
if (!Array.isArray(node.value) || node.value.length !== 2) throw new Error("View between filter must contain exactly two values");
|
|
3291
|
+
}
|
|
3292
|
+
if (node.op === "is-relative-to-today") {
|
|
3293
|
+
if (field.type !== "date" && field.type !== "datetime" && field.type !== "created-time" && field.type !== "last-edited-time") throw new Error("View relative filter requires a Date or Datetime Field");
|
|
3294
|
+
const relative = node.value;
|
|
3295
|
+
if (!relative || typeof relative !== "object" || Array.isArray(relative)) throw new Error("View relative filter value is invalid");
|
|
3296
|
+
const relativeValue = relative;
|
|
3297
|
+
if (typeof relativeValue.direction !== "string" || typeof relativeValue.unit !== "string") throw new Error("View relative filter value is invalid");
|
|
3298
|
+
if (![
|
|
3299
|
+
"past",
|
|
3300
|
+
"next",
|
|
3301
|
+
"this"
|
|
3302
|
+
].includes(relativeValue.direction) || ![
|
|
3303
|
+
"day",
|
|
3304
|
+
"week",
|
|
3305
|
+
"month",
|
|
3306
|
+
"year"
|
|
3307
|
+
].includes(relativeValue.unit) || Object.keys(relativeValue).some((key) => key !== "direction" && key !== "unit")) unsupportedQuery = true;
|
|
3308
|
+
}
|
|
3174
3309
|
};
|
|
3175
3310
|
if ("filter" in query) checkFilter(query.filter);
|
|
3176
3311
|
if ("sort" in query) {
|
|
3177
3312
|
if (!Array.isArray(query.sort)) throw new Error("View sort must be an array");
|
|
3178
|
-
for (const item of query.sort)
|
|
3313
|
+
for (const item of query.sort) {
|
|
3314
|
+
if (!item || Array.isArray(item) || typeof item !== "object" || typeof item.field !== "string" || !fieldIds.has(item.field)) throw new Error("View sort contains an invalid Field reference or direction");
|
|
3315
|
+
if (item.direction !== "asc" && item.direction !== "desc" || item.nulls !== void 0 && item.nulls !== "first" && item.nulls !== "last" || Object.keys(item).some((key) => key !== "field" && key !== "direction" && key !== "nulls")) unsupportedQuery = true;
|
|
3316
|
+
}
|
|
3179
3317
|
}
|
|
3318
|
+
if (unsupportedQuery) add(warnings, "view-query-unsupported", `View ${view.id} uses query semantics from a newer Eidos version`);
|
|
3180
3319
|
for (const key of [
|
|
3181
3320
|
"cardFields",
|
|
3182
3321
|
"fieldOrder",
|
|
@@ -3185,7 +3324,11 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3185
3324
|
const value = layout[key];
|
|
3186
3325
|
if (value !== void 0 && (!Array.isArray(value) || !value.every((fieldId) => typeof fieldId === "string" && fieldIds.has(fieldId)))) throw new Error(`View ${key} must contain Field IDs from its Table`);
|
|
3187
3326
|
}
|
|
3188
|
-
for (const key of [
|
|
3327
|
+
for (const key of [
|
|
3328
|
+
"coverField",
|
|
3329
|
+
"groupField",
|
|
3330
|
+
"dateField"
|
|
3331
|
+
]) {
|
|
3189
3332
|
const value = layout[key];
|
|
3190
3333
|
if (value !== void 0 && value !== null && (typeof value !== "string" || !fieldIds.has(value))) throw new Error(`View ${key} must be null or a Field ID from its Table`);
|
|
3191
3334
|
}
|
|
@@ -3387,10 +3530,17 @@ function presentationSettingsObject(source) {
|
|
|
3387
3530
|
}
|
|
3388
3531
|
function presentationSettings(input) {
|
|
3389
3532
|
const property = presentationSettingsObject("property" in input ? input.property : void 0);
|
|
3390
|
-
if (input.type === "select" || input.type === "multi-select")
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3533
|
+
if (input.type === "select" || input.type === "multi-select") {
|
|
3534
|
+
property.options = assertEidosFileSelectOptions("property" in input ? input.property : void 0).map((option) => ({
|
|
3535
|
+
color: option.color,
|
|
3536
|
+
name: option.name
|
|
3537
|
+
}));
|
|
3538
|
+
if (input.type === "select") {
|
|
3539
|
+
const defaultOption = assertEidosFileSelectDefaultOption(property);
|
|
3540
|
+
if (defaultOption === null) delete property.defaultOption;
|
|
3541
|
+
else property.defaultOption = defaultOption;
|
|
3542
|
+
} else assertEidosFileMultiSelectHasNoDefaultOption(property);
|
|
3543
|
+
}
|
|
3394
3544
|
return property;
|
|
3395
3545
|
}
|
|
3396
3546
|
function transformOptionValue(value, fieldId, changes) {
|
|
@@ -3597,6 +3747,46 @@ function filterFromStorage(value, fields) {
|
|
|
3597
3747
|
};
|
|
3598
3748
|
return normalizeEidosFileFilter(convert(value));
|
|
3599
3749
|
}
|
|
3750
|
+
function storedViewQueryStatus(query, fields) {
|
|
3751
|
+
const fieldIds = new Set(fields.flatMap((field) => field.id ? [field.id] : []));
|
|
3752
|
+
if (Object.keys(query).some((key) => key !== "filter" && key !== "sort")) return "unsupported";
|
|
3753
|
+
const supportedScalar = (value) => value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
3754
|
+
const supportedRuleValue = (operator, value) => {
|
|
3755
|
+
if (operator === "is-relative-to-today") {
|
|
3756
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3757
|
+
const relative = value;
|
|
3758
|
+
return Object.keys(relative).every((key) => key === "direction" || key === "unit") && [
|
|
3759
|
+
"past",
|
|
3760
|
+
"next",
|
|
3761
|
+
"this"
|
|
3762
|
+
].includes(String(relative.direction)) && [
|
|
3763
|
+
"day",
|
|
3764
|
+
"week",
|
|
3765
|
+
"month",
|
|
3766
|
+
"year"
|
|
3767
|
+
].includes(String(relative.unit));
|
|
3768
|
+
}
|
|
3769
|
+
if (operator === "is-between") return Array.isArray(value) && value.length === 2 && value.every(supportedScalar);
|
|
3770
|
+
return value === void 0 || supportedScalar(value) || Array.isArray(value) && value.every(supportedScalar);
|
|
3771
|
+
};
|
|
3772
|
+
const filterSupported = (value) => {
|
|
3773
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3774
|
+
const node = value;
|
|
3775
|
+
if (Array.isArray(node.args)) return (node.op === "and" || node.op === "or") && Object.keys(node).every((key) => key === "op" || key === "args") && node.args.every(filterSupported);
|
|
3776
|
+
if (typeof node.field !== "string" || !fieldIds.has(node.field) || !isEidosFileFilterOperator(node.op) || Object.keys(node).some((key) => key !== "field" && key !== "op" && key !== "value")) return false;
|
|
3777
|
+
return supportedRuleValue(node.op, node.value);
|
|
3778
|
+
};
|
|
3779
|
+
if ("filter" in query && !filterSupported(query.filter)) return "unsupported";
|
|
3780
|
+
if ("sort" in query) {
|
|
3781
|
+
if (!Array.isArray(query.sort)) return "unsupported";
|
|
3782
|
+
for (const value of query.sort) {
|
|
3783
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return "unsupported";
|
|
3784
|
+
const sort = value;
|
|
3785
|
+
if (typeof sort.field !== "string" || !fieldIds.has(sort.field) || sort.direction !== "asc" && sort.direction !== "desc" || sort.nulls !== void 0 && sort.nulls !== "first" && sort.nulls !== "last" || Object.keys(sort).some((key) => key !== "field" && key !== "direction" && key !== "nulls")) return "unsupported";
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
return "supported";
|
|
3789
|
+
}
|
|
3600
3790
|
var EidosFileRuntime = class {
|
|
3601
3791
|
mutationDepth = 0;
|
|
3602
3792
|
mutationInstant = null;
|
|
@@ -4266,12 +4456,34 @@ var EidosFileRuntime = class {
|
|
|
4266
4456
|
}
|
|
4267
4457
|
let settings = field.settings ?? {};
|
|
4268
4458
|
if (changes.property !== void 0) settings = presentationSettingsObject(changes.property);
|
|
4269
|
-
if (field.type === "select" || field.type === "multi-select") settings.options = assertEidosFileSelectOptions(settings).map((option) => ({
|
|
4270
|
-
color: option.color,
|
|
4271
|
-
name: option.name
|
|
4272
|
-
}));
|
|
4273
4459
|
if (changes.optionValueChanges && changes.optionValueChanges.length > 0) {
|
|
4274
4460
|
if (field.type !== "select" && field.type !== "multi-select") throw new EidosFileError("invalid-schema", "Only Select Fields have option values");
|
|
4461
|
+
const replacements = new Map(changes.optionValueChanges.map((change) => [change.from, change.to]));
|
|
4462
|
+
const options = assertEidosFileSelectOptions(settings);
|
|
4463
|
+
const existingNames = new Set(options.map((option) => option.name));
|
|
4464
|
+
settings.options = options.flatMap((option) => {
|
|
4465
|
+
const replacement = replacements.get(option.name);
|
|
4466
|
+
if (replacement === void 0) return [option];
|
|
4467
|
+
if (existingNames.has(replacement)) return [];
|
|
4468
|
+
return [{
|
|
4469
|
+
...option,
|
|
4470
|
+
name: replacement
|
|
4471
|
+
}];
|
|
4472
|
+
});
|
|
4473
|
+
if (field.type === "select" && typeof settings.defaultOption === "string") settings.defaultOption = replacements.get(settings.defaultOption) ?? settings.defaultOption;
|
|
4474
|
+
}
|
|
4475
|
+
if (field.type === "select" || field.type === "multi-select") {
|
|
4476
|
+
settings.options = assertEidosFileSelectOptions(settings).map((option) => ({
|
|
4477
|
+
color: option.color,
|
|
4478
|
+
name: option.name
|
|
4479
|
+
}));
|
|
4480
|
+
if (field.type === "select") {
|
|
4481
|
+
const defaultOption = assertEidosFileSelectDefaultOption(settings);
|
|
4482
|
+
if (defaultOption === null) delete settings.defaultOption;
|
|
4483
|
+
else settings.defaultOption = defaultOption;
|
|
4484
|
+
} else assertEidosFileMultiSelectHasNoDefaultOption(settings);
|
|
4485
|
+
}
|
|
4486
|
+
if (changes.optionValueChanges && changes.optionValueChanges.length > 0) {
|
|
4275
4487
|
const replacements = new Map(changes.optionValueChanges.map((change) => [change.from, change.to]));
|
|
4276
4488
|
for (const [from, to] of replacements) if (field.type === "select") this.connection.run(`UPDATE ${quoteIdentifier(table.physicalName ?? table.rawTableName)}
|
|
4277
4489
|
SET ${quoteIdentifier(field.physicalName)} = ?, "_updated_at" = ?
|
|
@@ -4556,7 +4768,11 @@ var EidosFileRuntime = class {
|
|
|
4556
4768
|
"fieldOrder",
|
|
4557
4769
|
"hiddenFields"
|
|
4558
4770
|
]) if (Array.isArray(layout[key])) layout[key] = layout[key].filter((value) => value !== fieldId);
|
|
4559
|
-
for (const key of [
|
|
4771
|
+
for (const key of [
|
|
4772
|
+
"coverField",
|
|
4773
|
+
"groupField",
|
|
4774
|
+
"dateField"
|
|
4775
|
+
]) if (layout[key] === fieldId) layout[key] = null;
|
|
4560
4776
|
if (layout.fieldWidths && typeof layout.fieldWidths === "object" && !Array.isArray(layout.fieldWidths)) {
|
|
4561
4777
|
const fieldWidths = { ...layout.fieldWidths };
|
|
4562
4778
|
delete fieldWidths[fieldId];
|
|
@@ -4609,6 +4825,7 @@ var EidosFileRuntime = class {
|
|
|
4609
4825
|
const fields = this.listFields(tableId);
|
|
4610
4826
|
const query = jsonObject(row.query_json);
|
|
4611
4827
|
const layout = jsonObject(row.layout_json);
|
|
4828
|
+
const queryStatus = storedViewQueryStatus(query, fields);
|
|
4612
4829
|
const storedSorts = normalizeEidosFileSorts(query.sort);
|
|
4613
4830
|
const fieldIds = new Set(fields.flatMap((field) => field.id ? [field.id] : []));
|
|
4614
4831
|
const fieldOrder = Array.isArray(layout.fieldOrder) ? layout.fieldOrder.flatMap((value) => typeof value === "string" && fieldIds.has(value) ? [value] : []) : [];
|
|
@@ -4618,10 +4835,11 @@ var EidosFileRuntime = class {
|
|
|
4618
4835
|
name: row.name,
|
|
4619
4836
|
type: row.type,
|
|
4620
4837
|
tableId,
|
|
4621
|
-
|
|
4838
|
+
queryStatus,
|
|
4839
|
+
query: row.query_json,
|
|
4622
4840
|
properties,
|
|
4623
|
-
filter: filterFromStorage(query.filter, fields),
|
|
4624
|
-
sorts: storedSorts.filter((sort) => fieldIds.has(sort.field)),
|
|
4841
|
+
filter: queryStatus === "supported" ? filterFromStorage(query.filter, fields) : null,
|
|
4842
|
+
sorts: queryStatus === "supported" ? storedSorts.filter((sort) => fieldIds.has(sort.field)) : [],
|
|
4625
4843
|
orderMap: Object.fromEntries(fieldOrder.map((fieldId, index) => [fieldId, index])),
|
|
4626
4844
|
hiddenFields: Array.isArray(layout.hiddenFields) ? layout.hiddenFields.flatMap((value) => typeof value === "string" && fieldIds.has(value) ? [value] : []) : [],
|
|
4627
4845
|
position: row.position,
|
|
@@ -4688,6 +4906,7 @@ var EidosFileRuntime = class {
|
|
|
4688
4906
|
...properties,
|
|
4689
4907
|
cardFields: mapFieldList(properties.cardFields),
|
|
4690
4908
|
coverField: mappedLayoutField(properties.coverField),
|
|
4909
|
+
dateField: mappedLayoutField(properties.dateField),
|
|
4691
4910
|
fieldOrder,
|
|
4692
4911
|
fieldWidths,
|
|
4693
4912
|
groupField: mappedLayoutField(properties.groupField),
|
|
@@ -4701,7 +4920,8 @@ var EidosFileRuntime = class {
|
|
|
4701
4920
|
});
|
|
4702
4921
|
}
|
|
4703
4922
|
updateView(viewId, changes) {
|
|
4704
|
-
const
|
|
4923
|
+
const currentRow = this.viewRow(viewId);
|
|
4924
|
+
const current = this.mapView(currentRow);
|
|
4705
4925
|
const fields = this.listFields(current.tableId);
|
|
4706
4926
|
const name = assertEidosFileDisplayName(changes.name ?? current.name, "View name");
|
|
4707
4927
|
const foldedName = name.replace(/[A-Z]/g, (character) => character.toLowerCase());
|
|
@@ -4716,6 +4936,8 @@ var EidosFileRuntime = class {
|
|
|
4716
4936
|
orderMap: changes.orderMap === void 0 ? current.orderMap : changes.orderMap,
|
|
4717
4937
|
hiddenFields: changes.hiddenFields === void 0 ? current.hiddenFields : changes.hiddenFields
|
|
4718
4938
|
};
|
|
4939
|
+
const queryChanged = changes.filter !== void 0 || changes.sorts !== void 0;
|
|
4940
|
+
const layoutChanged = changes.properties !== void 0 || changes.orderMap !== void 0 || changes.hiddenFields !== void 0;
|
|
4719
4941
|
return this.mutate(() => {
|
|
4720
4942
|
const fieldByKey = new Map(fields.flatMap((field) => field.id ? [[field.tableColumnName, field.id], [field.id, field.id]] : []));
|
|
4721
4943
|
const sorts = normalizeEidosFileSorts(next.sorts).flatMap((sort) => {
|
|
@@ -4743,11 +4965,11 @@ var EidosFileRuntime = class {
|
|
|
4743
4965
|
WHERE id = ?`, [
|
|
4744
4966
|
next.name,
|
|
4745
4967
|
next.type,
|
|
4746
|
-
canonicalizeEidosFileJson({
|
|
4968
|
+
queryChanged ? canonicalizeEidosFileJson({
|
|
4747
4969
|
...filterToStorage(next.filter, fields) ? { filter: filterToStorage(next.filter, fields) } : {},
|
|
4748
4970
|
...sorts.length ? { sort: sorts } : {}
|
|
4749
|
-
}),
|
|
4750
|
-
canonicalizeEidosFileJson(layout),
|
|
4971
|
+
}) : currentRow.query_json,
|
|
4972
|
+
layoutChanged ? canonicalizeEidosFileJson(layout) : currentRow.layout_json,
|
|
4751
4973
|
stablePosition(next.position, current.position ?? 0),
|
|
4752
4974
|
this.operationInstant(),
|
|
4753
4975
|
viewId
|
|
@@ -4757,6 +4979,7 @@ var EidosFileRuntime = class {
|
|
|
4757
4979
|
}
|
|
4758
4980
|
duplicateView(viewId, name) {
|
|
4759
4981
|
const view = this.mapView(this.viewRow(viewId));
|
|
4982
|
+
if (view.queryStatus === "unsupported") throw new EidosFileError("unsupported-feature", "This View uses a saved query from a newer Eidos version");
|
|
4760
4983
|
return this.createView(view.tableId, {
|
|
4761
4984
|
name: name ?? `${view.name} copy`,
|
|
4762
4985
|
type: view.type,
|
|
@@ -4975,23 +5198,25 @@ var EidosFileRuntime = class {
|
|
|
4975
5198
|
...this.requiredQueryFieldKeys(fields, compatibleQuery)
|
|
4976
5199
|
]) : void 0;
|
|
4977
5200
|
const source = this.logicalSource(tableId, requested, projection?.includeRecordLabel !== false, projection?.includeRelationDisplays !== false);
|
|
4978
|
-
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery);
|
|
4979
5201
|
const querySignature = canonicalizeEidosFileJson(compatibleQuery);
|
|
4980
5202
|
const sorts = uniqueSortFields(source.fields, compatibleQuery.sorts);
|
|
4981
5203
|
const revision = String(this.info().revision ?? 0);
|
|
4982
5204
|
let effectiveOffset = offset;
|
|
4983
5205
|
let cursorWhere = "";
|
|
4984
5206
|
let cursorParams = [];
|
|
5207
|
+
let referenceInstant = this.nowInstant();
|
|
4985
5208
|
if (cursor) try {
|
|
4986
5209
|
const payload = JSON.parse(decodeURIComponent(cursor));
|
|
4987
5210
|
if (payload.version !== 1 || payload.direction !== "forward" || payload.revision !== revision || payload.tableId !== tableId || payload.query !== querySignature || !Array.isArray(payload.values)) throw new Error("cursor binding mismatch");
|
|
4988
5211
|
effectiveOffset = payload.offset;
|
|
5212
|
+
if (payload.referenceInstant !== void 0) referenceInstant = normalizeEidosFileInstant(payload.referenceInstant, "Cursor reference instant");
|
|
4989
5213
|
const keyset = compileKeysetAfter(sorts, payload.values.map(decodeCursorSqlValue), payload.lastId);
|
|
4990
5214
|
cursorWhere = keyset.sql;
|
|
4991
5215
|
cursorParams = keyset.params;
|
|
4992
5216
|
} catch {
|
|
4993
5217
|
throw new EidosFileError("invalid-query", "Invalid or stale Eidos File cursor");
|
|
4994
5218
|
}
|
|
5219
|
+
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery, { referenceInstant });
|
|
4995
5220
|
const whereSql = cursorWhere ? compiled.whereSql ? `${compiled.whereSql} AND ${cursorWhere}` : `WHERE ${cursorWhere}` : compiled.whereSql;
|
|
4996
5221
|
const rawRows = this.connection.query(`WITH logical AS (${source.sql})
|
|
4997
5222
|
SELECT * FROM logical ${whereSql} ${compiled.orderSql}
|
|
@@ -5022,7 +5247,7 @@ var EidosFileRuntime = class {
|
|
|
5022
5247
|
}
|
|
5023
5248
|
return Object.fromEntries(Object.entries(mapped).filter(([key]) => selected.has(key)));
|
|
5024
5249
|
});
|
|
5025
|
-
const total = totalHint ?? this.countRows(tableId, query);
|
|
5250
|
+
const total = totalHint ?? this.countRows(tableId, query, referenceInstant);
|
|
5026
5251
|
const nextOffset = effectiveOffset + rawRows.length;
|
|
5027
5252
|
const lastRawRow = rawRows.at(-1);
|
|
5028
5253
|
const nextCursor = lastRawRow && rawRows.length === limit && nextOffset < total ? encodeURIComponent(JSON.stringify({
|
|
@@ -5033,7 +5258,8 @@ var EidosFileRuntime = class {
|
|
|
5033
5258
|
offset: nextOffset,
|
|
5034
5259
|
values: sorts.map(({ field }) => encodeCursorSqlValue(cursorSortValue(lastRawRow, field))),
|
|
5035
5260
|
lastId: String(lastRawRow.__base_rowid),
|
|
5036
|
-
direction: "forward"
|
|
5261
|
+
direction: "forward",
|
|
5262
|
+
referenceInstant
|
|
5037
5263
|
})) : void 0;
|
|
5038
5264
|
return {
|
|
5039
5265
|
tableId,
|
|
@@ -5050,7 +5276,7 @@ var EidosFileRuntime = class {
|
|
|
5050
5276
|
const compatibleQuery = this.compatibilityQuery(tableId, query);
|
|
5051
5277
|
const fields = this.listFields(tableId);
|
|
5052
5278
|
const source = this.logicalSource(tableId, this.requiredQueryFieldKeys(fields, compatibleQuery), false, false);
|
|
5053
|
-
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery);
|
|
5279
|
+
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery, { referenceInstant: this.nowInstant() });
|
|
5054
5280
|
const sorts = uniqueSortFields(source.fields, compatibleQuery.sorts);
|
|
5055
5281
|
const targetWhere = compiled.whereSql ? `${compiled.whereSql} AND "__base_rowid" = ?` : "WHERE \"__base_rowid\" = ?";
|
|
5056
5282
|
const target = this.connection.get(`WITH logical AS (${source.sql})
|
|
@@ -5144,7 +5370,7 @@ var EidosFileRuntime = class {
|
|
|
5144
5370
|
runtimeScanLogicalRows(tableId, fieldIds, query) {
|
|
5145
5371
|
const compatibleQuery = this.compatibilityQuery(tableId, query);
|
|
5146
5372
|
const source = this.logicalSource(tableId, fieldIds, false, false);
|
|
5147
|
-
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery);
|
|
5373
|
+
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery, { referenceInstant: this.nowInstant() });
|
|
5148
5374
|
const selectedFields = fieldIds.map((fieldId) => this.fieldByKey(tableId, fieldId));
|
|
5149
5375
|
const encodedValues = selectedFields.map((field) => {
|
|
5150
5376
|
const column = quoteIdentifier(field.tableColumnName);
|
|
@@ -5214,14 +5440,15 @@ var EidosFileRuntime = class {
|
|
|
5214
5440
|
offset: 0,
|
|
5215
5441
|
values: values.map((value) => encodeCursorSqlValue(value)),
|
|
5216
5442
|
lastId: row.id,
|
|
5217
|
-
direction: "forward"
|
|
5443
|
+
direction: "forward",
|
|
5444
|
+
referenceInstant: this.nowInstant()
|
|
5218
5445
|
}));
|
|
5219
5446
|
}
|
|
5220
|
-
countRows(tableId, query = {}) {
|
|
5447
|
+
countRows(tableId, query = {}, referenceInstant = this.nowInstant()) {
|
|
5221
5448
|
const compatibleQuery = this.compatibilityQuery(tableId, query);
|
|
5222
5449
|
const fields = this.listFields(tableId);
|
|
5223
5450
|
const source = this.logicalSource(tableId, this.requiredQueryFieldKeys(fields, compatibleQuery), false, false);
|
|
5224
|
-
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery);
|
|
5451
|
+
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery, { referenceInstant });
|
|
5225
5452
|
return this.connection.get(`WITH logical AS (${source.sql}) SELECT count(*) AS count FROM logical ${compiled.whereSql}`, compiled.params)?.count ?? 0;
|
|
5226
5453
|
}
|
|
5227
5454
|
countRowsByField(tableId, fieldKey, query = {}) {
|
|
@@ -5229,7 +5456,7 @@ var EidosFileRuntime = class {
|
|
|
5229
5456
|
const compatibleQuery = this.compatibilityQuery(tableId, query);
|
|
5230
5457
|
const fields = this.listFields(tableId);
|
|
5231
5458
|
const source = this.logicalSource(tableId, [field.id, ...this.requiredQueryFieldKeys(fields, compatibleQuery)], false, false);
|
|
5232
|
-
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery);
|
|
5459
|
+
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery, { referenceInstant: this.nowInstant() });
|
|
5233
5460
|
const column = quoteIdentifier(field.tableColumnName);
|
|
5234
5461
|
if (field.storageCodec === "json_array" || field.storageCodec === "relation") return this.connection.query(`WITH logical AS (${source.sql}), filtered AS (
|
|
5235
5462
|
SELECT * FROM logical ${compiled.whereSql}
|
|
@@ -5246,7 +5473,7 @@ var EidosFileRuntime = class {
|
|
|
5246
5473
|
const fields = this.listFields(tableId);
|
|
5247
5474
|
configs = normalizeEidosFileColumnStatConfigs(configs, fields);
|
|
5248
5475
|
const source = this.logicalSource(tableId, [...configs.map((config) => config.fieldId), ...this.requiredQueryFieldKeys(fields, compatibleQuery)], false, false);
|
|
5249
|
-
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery);
|
|
5476
|
+
const compiled = compileEidosFileRowQuery(source.fields, compatibleQuery, { referenceInstant: this.nowInstant() });
|
|
5250
5477
|
return configs.map((config) => {
|
|
5251
5478
|
const field = this.fieldByKey(tableId, config.fieldId);
|
|
5252
5479
|
const column = quoteIdentifier(field.tableColumnName);
|
|
@@ -5342,7 +5569,7 @@ var EidosFileRuntime = class {
|
|
|
5342
5569
|
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint") return value;
|
|
5343
5570
|
throw new EidosFileError("invalid-value", `Unsupported value for ${field.name}`);
|
|
5344
5571
|
}
|
|
5345
|
-
rowChanges(tableId, row, allowUnresolvedRelations) {
|
|
5572
|
+
rowChanges(tableId, row, allowUnresolvedRelations, applyCreateDefaults = false) {
|
|
5346
5573
|
const changes = [];
|
|
5347
5574
|
for (const [key, value] of Object.entries(row)) {
|
|
5348
5575
|
if (key === "_id" || key === "id" || key.endsWith("__display")) continue;
|
|
@@ -5353,14 +5580,26 @@ var EidosFileRuntime = class {
|
|
|
5353
5580
|
value: this.normalizeStoredValue(field, value, allowUnresolvedRelations)
|
|
5354
5581
|
});
|
|
5355
5582
|
}
|
|
5583
|
+
if (applyCreateDefaults) {
|
|
5584
|
+
const suppliedFieldIds = new Set(changes.map((change) => change.field.id));
|
|
5585
|
+
for (const field of this.listFields(tableId)) {
|
|
5586
|
+
if (field.type !== "select" || !field.id || !field.physicalName || suppliedFieldIds.has(field.id)) continue;
|
|
5587
|
+
const defaultOption = parseEidosFileSelectDefaultOption(field.settings);
|
|
5588
|
+
if (defaultOption === null) continue;
|
|
5589
|
+
changes.push({
|
|
5590
|
+
field,
|
|
5591
|
+
value: this.normalizeStoredValue(field, defaultOption, allowUnresolvedRelations)
|
|
5592
|
+
});
|
|
5593
|
+
}
|
|
5594
|
+
}
|
|
5356
5595
|
return changes;
|
|
5357
5596
|
}
|
|
5358
|
-
insertRowInTransaction(tableId, row, allowUnresolvedRelations) {
|
|
5597
|
+
insertRowInTransaction(tableId, row, allowUnresolvedRelations, applyCreateDefaults) {
|
|
5359
5598
|
const table = this.getTable(tableId);
|
|
5360
5599
|
const requestedId = row._id ?? row.id;
|
|
5361
5600
|
const rowId = typeof requestedId === "string" ? assertEidosFileUuid(requestedId, "Row ID") : this.allocateId();
|
|
5362
5601
|
const now = this.operationInstant();
|
|
5363
|
-
const changes = this.rowChanges(tableId, row, allowUnresolvedRelations);
|
|
5602
|
+
const changes = this.rowChanges(tableId, row, allowUnresolvedRelations, applyCreateDefaults);
|
|
5364
5603
|
const columns = [
|
|
5365
5604
|
"_id",
|
|
5366
5605
|
"_created_at",
|
|
@@ -5435,11 +5674,11 @@ var EidosFileRuntime = class {
|
|
|
5435
5674
|
return ids;
|
|
5436
5675
|
}
|
|
5437
5676
|
insertRow(tableId, row) {
|
|
5438
|
-
const id = this.mutate(() => this.insertRowInTransaction(tableId, row, true));
|
|
5677
|
+
const id = this.mutate(() => this.insertRowInTransaction(tableId, row, true, true));
|
|
5439
5678
|
return this.getRow(tableId, id);
|
|
5440
5679
|
}
|
|
5441
5680
|
insertImportedRow(tableId, row) {
|
|
5442
|
-
const id = this.mutate(() => this.insertRowInTransaction(tableId, row, true));
|
|
5681
|
+
const id = this.mutate(() => this.insertRowInTransaction(tableId, row, true, false));
|
|
5443
5682
|
return this.getRow(tableId, id);
|
|
5444
5683
|
}
|
|
5445
5684
|
insertImportedRows(tableId, rows) {
|
|
@@ -5752,11 +5991,14 @@ var EidosFileRuntime = class {
|
|
|
5752
5991
|
const sampleExpression = canonicalTemporalProjection(expression, input.displayType);
|
|
5753
5992
|
const table = this.getTable(tableId);
|
|
5754
5993
|
const label = fields.find((field) => field.isRecordLabel);
|
|
5994
|
+
const previewRowIds = input.rowIds === void 0 ? void 0 : Array.from(new Set(input.rowIds.map((rowId) => assertEidosFileUuid(rowId, "Formula preview Row ID")))).slice(0, 100);
|
|
5995
|
+
const rowFilter = previewRowIds === void 0 ? "" : previewRowIds.length === 0 ? "WHERE 0" : `WHERE base."_id" IN (${previewRowIds.map(() => "?").join(", ")})`;
|
|
5755
5996
|
const samples = this.connection.query(`SELECT base."_id" AS row_id,
|
|
5756
5997
|
${this.fieldExpression(label, "base", schema)} AS title,
|
|
5757
5998
|
${sampleExpression} AS value
|
|
5758
5999
|
FROM ${quoteIdentifier(table.physicalName ?? table.rawTableName)} base
|
|
5759
|
-
|
|
6000
|
+
${rowFilter}
|
|
6001
|
+
ORDER BY base."_id" LIMIT ${previewRowIds?.length || 5}`, previewRowIds ?? []);
|
|
5760
6002
|
return {
|
|
5761
6003
|
expression,
|
|
5762
6004
|
dependencies: compiled.dependencyFieldIds.map((id) => {
|
|
@@ -5863,7 +6105,7 @@ var EidosFileRuntime = class {
|
|
|
5863
6105
|
}
|
|
5864
6106
|
}
|
|
5865
6107
|
}
|
|
5866
|
-
const inserted = (input.insert ?? []).map((row) => this.insertRowInTransaction(input.tableId, this.logicalMutationFields(input.tableId, row.fields, row.id), false));
|
|
6108
|
+
const inserted = (input.insert ?? []).map((row) => this.insertRowInTransaction(input.tableId, this.logicalMutationFields(input.tableId, row.fields, row.id), false, true));
|
|
5867
6109
|
const changedUpdates = [];
|
|
5868
6110
|
for (const { rowId, changes } of preparedUpdates) {
|
|
5869
6111
|
if (changes.length === 0) continue;
|
|
@@ -5947,6 +6189,6 @@ function fieldValueTypeForScan(field) {
|
|
|
5947
6189
|
return field.type;
|
|
5948
6190
|
}
|
|
5949
6191
|
//#endregion
|
|
5950
|
-
export {
|
|
6192
|
+
export { EIDOS_FILE_REQUIRED_TABLES as $, eidosFileLookupElementType as A, eidosFileFormulaReferences as B, normalizeEidosFileFilter as C, eidosFileFieldStoresJsonArray as D, removeEidosFileFilterField as E, EIDOS_FILE_FORMULA_FIELD_FUNCTION_NAMES as F, EIDOS_FILE_FIELDS_TABLE as G, EIDOS_FILE_APPLICATION_ID as H, EIDOS_FILE_FORMULA_FUNCTION_NAMES as I, EIDOS_FILE_FORMULA_FIELDS_TABLE as J, EIDOS_FILE_FORMAT as K, compileEidosFileFormula as L, eidosFileLookupTargetDisplayType as M, eidosFileLookupTargetValueType as N, eidosFileLookupAggregateSupportsTarget as O, eidosFileLookupValueType as P, EIDOS_FILE_RELATION_FIELDS_TABLE as Q, compileEidosFileFormulaFields as R, isEidosFileFilterOperator as S, normalizeEidosFileSorts as T, EIDOS_FILE_EXTENSION as U, rewriteEidosFileFormulaFieldReferences as V, EIDOS_FILE_FEATURES_TABLE as W, EIDOS_FILE_META_TABLE as X, EIDOS_FILE_LOOKUP_FIELDS_TABLE as Y, EIDOS_FILE_MIME_TYPE as Z, assertEidosFileRowQuery as _, EIDOS_FILE_FORMAT_VERSION_TEXT as a, hasEidosFileSqliteHeader as at, eidosFileRowQueryPredicateColumns as b, incrementEidosFileRevision as c, ConnectionPortEidosFileConnection as ct, decodeEidosFileRelationDisplay as d, assertInt64Decimal as dt, EIDOS_FILE_SCHEMA_VERSION as et, decodeEidosFileRelationIds as f, assertUnicodeString as ft, parseNonNegativeInt64 as g, cancellationPortFromSignal as h, sqlValueToNative as ht, scanStableRowPages as i, SQLITE_HEADER as it, eidosFileLookupStorageCodec as j, eidosFileLookupDisplayType as k, initializeEidosFileSchema as l, EidosAdapterError as lt, MemoryByteSource as m, nativeToSqlValue as mt, validateEidosFile as n, EIDOS_FILE_TABLES_TABLE as nt, EIDOS_FILE_SCHEMA_SQL as o, eidosFileColumnStatLabel as ot, encodeEidosFileRelationIds as p, exactConnectionBindingCount as pt, EIDOS_FILE_FORMAT_VERSION as q, smallestDependencyCycle as r, EIDOS_FILE_VIEWS_TABLE as rt, configureEidosFileConnection as s, eidosFileColumnStatTypesForField as st, EidosFileRuntime as t, EIDOS_FILE_SYSTEM_COLUMNS as tt, setEidosFileMetadata as u, assertExactConnectionBindings as ut, compileEidosFileRowQuery as v, normalizeEidosFileRowQuery as w, eidosFileSortExpression as x, eidosFileRowQueryAffectedByFieldChanges as y, compileEidosFileFormulaSource as z };
|
|
5951
6193
|
|
|
5952
|
-
//# sourceMappingURL=runtime-
|
|
6194
|
+
//# sourceMappingURL=runtime-ApHTYmlB.mjs.map
|