@eidos.space/eidos-file 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/better-sqlite3.mjs +1 -1
- package/dist/browser.mjs +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +122 -8
- package/dist/index.mjs.map +1 -1
- package/dist/node-sqlite.mjs +2 -2
- package/dist/runtime-BSYpcOBe.d.mts.map +1 -1
- package/dist/{runtime-Dt0bwaa5.mjs → runtime-D9Vp-lxn.mjs} +482 -39
- package/dist/runtime-D9Vp-lxn.mjs.map +1 -0
- package/dist/{sqlite-wasm-ll8cBQm8.mjs → sqlite-wasm-DzuW0TZZ.mjs} +2 -2
- package/dist/{sqlite-wasm-ll8cBQm8.mjs.map → sqlite-wasm-DzuW0TZZ.mjs.map} +1 -1
- package/dist/{system-metadata-merge-sRC1W6xr.mjs → system-metadata-merge-DJ9yCprr.mjs} +2 -2
- package/dist/{system-metadata-merge-sRC1W6xr.mjs.map → system-metadata-merge-DJ9yCprr.mjs.map} +1 -1
- package/package.json +2 -1
- package/dist/runtime-Dt0bwaa5.mjs.map +0 -1
|
@@ -2737,6 +2737,25 @@ const FILTER_OPERATORS = new Set([
|
|
|
2737
2737
|
"is-between",
|
|
2738
2738
|
"is-relative-to-today"
|
|
2739
2739
|
]);
|
|
2740
|
+
const RUNTIME_FILTER_OPERATORS$1 = new Set([
|
|
2741
|
+
"is-null",
|
|
2742
|
+
"is-not-null",
|
|
2743
|
+
"eq",
|
|
2744
|
+
"ne",
|
|
2745
|
+
"lt",
|
|
2746
|
+
"lte",
|
|
2747
|
+
"gt",
|
|
2748
|
+
"gte",
|
|
2749
|
+
"between",
|
|
2750
|
+
"in",
|
|
2751
|
+
"contains",
|
|
2752
|
+
"starts-with",
|
|
2753
|
+
"ends-with",
|
|
2754
|
+
"has-any",
|
|
2755
|
+
"has-all",
|
|
2756
|
+
"relation-has",
|
|
2757
|
+
"relative-date"
|
|
2758
|
+
]);
|
|
2740
2759
|
const LEVELS = {
|
|
2741
2760
|
identity: 0,
|
|
2742
2761
|
structural: 1,
|
|
@@ -3259,17 +3278,128 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3259
3278
|
if (!query || Array.isArray(query) || typeof query !== "object") throw new Error("View query_json must be an object");
|
|
3260
3279
|
if (!layout || Array.isArray(layout) || typeof layout !== "object") throw new Error("View layout_json must be an object");
|
|
3261
3280
|
let unsupportedQuery = Object.keys(query).some((key) => key !== "filter" && key !== "sort");
|
|
3281
|
+
const hasOnlyKeys = (value, keys) => Object.keys(value).every((key) => keys.includes(key));
|
|
3262
3282
|
const checkFilter = (value) => {
|
|
3263
3283
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("View filter nodes must be objects");
|
|
3264
3284
|
const node = value;
|
|
3265
|
-
if (
|
|
3266
|
-
if (
|
|
3267
|
-
if (
|
|
3285
|
+
if (node.op === "and" || node.op === "or") {
|
|
3286
|
+
if (!Array.isArray(node.args)) throw new Error("View filter group must contain args");
|
|
3287
|
+
if (!hasOnlyKeys(node, ["op", "args"])) unsupportedQuery = true;
|
|
3268
3288
|
node.args.forEach(checkFilter);
|
|
3269
3289
|
return;
|
|
3270
3290
|
}
|
|
3271
|
-
if (
|
|
3291
|
+
if (node.op === "not") {
|
|
3292
|
+
if (!("arg" in node)) throw new Error("View filter negation must contain an arg");
|
|
3293
|
+
if (!hasOnlyKeys(node, ["op", "arg"])) unsupportedQuery = true;
|
|
3294
|
+
checkFilter(node.arg);
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3272
3297
|
if (typeof node.op !== "string") throw new Error("View filter rule has an invalid operator");
|
|
3298
|
+
if ("fieldId" in node) {
|
|
3299
|
+
if (typeof node.fieldId !== "string" || !fieldIds.has(node.fieldId)) throw new Error("View filter references an unknown Field ID");
|
|
3300
|
+
if (!RUNTIME_FILTER_OPERATORS$1.has(node.op)) {
|
|
3301
|
+
unsupportedQuery = true;
|
|
3302
|
+
return;
|
|
3303
|
+
}
|
|
3304
|
+
const field = fieldsById.get(node.fieldId);
|
|
3305
|
+
if ((field.storageCodec === "json_array" || field.storageCodec === "relation") && [
|
|
3306
|
+
"lt",
|
|
3307
|
+
"lte",
|
|
3308
|
+
"gt",
|
|
3309
|
+
"gte",
|
|
3310
|
+
"starts-with",
|
|
3311
|
+
"ends-with"
|
|
3312
|
+
].includes(node.op)) throw new Error("View filter uses a scalar comparison on a list Field");
|
|
3313
|
+
if (node.op === "is-null" || node.op === "is-not-null") {
|
|
3314
|
+
if (!hasOnlyKeys(node, ["op", "fieldId"])) unsupportedQuery = true;
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
if ([
|
|
3318
|
+
"eq",
|
|
3319
|
+
"ne",
|
|
3320
|
+
"lt",
|
|
3321
|
+
"lte",
|
|
3322
|
+
"gt",
|
|
3323
|
+
"gte"
|
|
3324
|
+
].includes(node.op)) {
|
|
3325
|
+
if (!("value" in node) || node.value === null) throw new Error("View filter operand must be non-null");
|
|
3326
|
+
if (!hasOnlyKeys(node, [
|
|
3327
|
+
"op",
|
|
3328
|
+
"fieldId",
|
|
3329
|
+
"value"
|
|
3330
|
+
])) unsupportedQuery = true;
|
|
3331
|
+
if (field.type === "relation" && (!Array.isArray(node.value) || !node.value.every(isEidosFileUuid))) throw new Error("View Relation filter values must be canonical Row IDs");
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3334
|
+
if (node.op === "between") {
|
|
3335
|
+
if (!("lower" in node) || !("upper" in node)) throw new Error("View between filter is missing an operand");
|
|
3336
|
+
if (node.lower === null || node.upper === null) throw new Error("View between operands must be non-null");
|
|
3337
|
+
if (!hasOnlyKeys(node, [
|
|
3338
|
+
"op",
|
|
3339
|
+
"fieldId",
|
|
3340
|
+
"lower",
|
|
3341
|
+
"upper"
|
|
3342
|
+
])) unsupportedQuery = true;
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3345
|
+
if ([
|
|
3346
|
+
"in",
|
|
3347
|
+
"has-any",
|
|
3348
|
+
"has-all"
|
|
3349
|
+
].includes(node.op)) {
|
|
3350
|
+
if (!Array.isArray(node.values) || node.values.some((entry) => entry === null)) throw new Error("View membership filter values must be a non-null array");
|
|
3351
|
+
if (!hasOnlyKeys(node, [
|
|
3352
|
+
"op",
|
|
3353
|
+
"fieldId",
|
|
3354
|
+
"values"
|
|
3355
|
+
])) unsupportedQuery = true;
|
|
3356
|
+
if (field.type === "relation" && !(node.op === "in" ? node.values.every((value) => Array.isArray(value) && value.every(isEidosFileUuid)) : node.values.every(isEidosFileUuid))) throw new Error("View Relation filter values must be canonical Row IDs");
|
|
3357
|
+
return;
|
|
3358
|
+
}
|
|
3359
|
+
if ([
|
|
3360
|
+
"contains",
|
|
3361
|
+
"starts-with",
|
|
3362
|
+
"ends-with"
|
|
3363
|
+
].includes(node.op)) {
|
|
3364
|
+
if (typeof node.value !== "string") throw new Error("View text filter value must be a string");
|
|
3365
|
+
if (!hasOnlyKeys(node, [
|
|
3366
|
+
"op",
|
|
3367
|
+
"fieldId",
|
|
3368
|
+
"value"
|
|
3369
|
+
])) unsupportedQuery = true;
|
|
3370
|
+
return;
|
|
3371
|
+
}
|
|
3372
|
+
if (node.op === "relation-has") {
|
|
3373
|
+
if (field.type !== "relation" || !isEidosFileUuid(node.rowId)) throw new Error("View Relation filter must reference a canonical Row ID");
|
|
3374
|
+
if (!hasOnlyKeys(node, [
|
|
3375
|
+
"op",
|
|
3376
|
+
"fieldId",
|
|
3377
|
+
"rowId"
|
|
3378
|
+
])) unsupportedQuery = true;
|
|
3379
|
+
return;
|
|
3380
|
+
}
|
|
3381
|
+
if (node.op === "relative-date") {
|
|
3382
|
+
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");
|
|
3383
|
+
if (![
|
|
3384
|
+
"past",
|
|
3385
|
+
"next",
|
|
3386
|
+
"this"
|
|
3387
|
+
].includes(String(node.direction)) || ![
|
|
3388
|
+
"day",
|
|
3389
|
+
"week",
|
|
3390
|
+
"month",
|
|
3391
|
+
"year"
|
|
3392
|
+
].includes(String(node.unit))) throw new Error("View relative filter value is invalid");
|
|
3393
|
+
if (!hasOnlyKeys(node, [
|
|
3394
|
+
"op",
|
|
3395
|
+
"fieldId",
|
|
3396
|
+
"direction",
|
|
3397
|
+
"unit"
|
|
3398
|
+
])) unsupportedQuery = true;
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
if (typeof node.field !== "string" || !fieldIds.has(node.field)) throw new Error("View filter references an unknown Field ID");
|
|
3273
3403
|
if (!FILTER_OPERATORS.has(node.op)) {
|
|
3274
3404
|
unsupportedQuery = true;
|
|
3275
3405
|
return;
|
|
@@ -3312,8 +3442,9 @@ function validateEidosFile(connection, options = {}) {
|
|
|
3312
3442
|
if ("sort" in query) {
|
|
3313
3443
|
if (!Array.isArray(query.sort)) throw new Error("View sort must be an array");
|
|
3314
3444
|
for (const item of query.sort) {
|
|
3315
|
-
|
|
3316
|
-
if (item
|
|
3445
|
+
const fieldId = item && !Array.isArray(item) && typeof item === "object" ? typeof item.fieldId === "string" ? item.fieldId : item.field : void 0;
|
|
3446
|
+
if (!item || Array.isArray(item) || typeof item !== "object" || typeof fieldId !== "string" || !fieldIds.has(fieldId)) throw new Error("View sort contains an invalid Field reference or direction");
|
|
3447
|
+
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 !== "fieldId" && key !== "direction" && key !== "nulls")) unsupportedQuery = true;
|
|
3317
3448
|
}
|
|
3318
3449
|
}
|
|
3319
3450
|
if (unsupportedQuery) add(warnings, "view-query-unsupported", `View ${view.id} uses query semantics from a newer Eidos version`);
|
|
@@ -3529,13 +3660,14 @@ function presentationSettingsObject(source) {
|
|
|
3529
3660
|
]) delete property[key];
|
|
3530
3661
|
return property;
|
|
3531
3662
|
}
|
|
3663
|
+
function assertedRawSelectOptions(property) {
|
|
3664
|
+
assertEidosFileSelectOptions(property);
|
|
3665
|
+
return Array.isArray(property?.options) ? property.options.map((option) => ({ ...option })) : [];
|
|
3666
|
+
}
|
|
3532
3667
|
function presentationSettings(input) {
|
|
3533
3668
|
const property = presentationSettingsObject("property" in input ? input.property : void 0);
|
|
3534
3669
|
if (input.type === "select" || input.type === "multi-select") {
|
|
3535
|
-
property.options =
|
|
3536
|
-
color: option.color,
|
|
3537
|
-
name: option.name
|
|
3538
|
-
}));
|
|
3670
|
+
property.options = assertedRawSelectOptions("property" in input ? input.property : void 0);
|
|
3539
3671
|
if (input.type === "select") {
|
|
3540
3672
|
const defaultOption = assertEidosFileSelectDefaultOption(property);
|
|
3541
3673
|
if (defaultOption === null) delete property.defaultOption;
|
|
@@ -3548,8 +3680,9 @@ function transformOptionValue(value, fieldId, changes) {
|
|
|
3548
3680
|
if (Array.isArray(value)) return value.map((entry) => transformOptionValue(entry, fieldId, changes));
|
|
3549
3681
|
if (!value || typeof value !== "object") return value;
|
|
3550
3682
|
const object = value;
|
|
3683
|
+
const referencesField = object.fieldId === fieldId || object.field === fieldId;
|
|
3551
3684
|
const next = {};
|
|
3552
|
-
for (const [key, entry] of Object.entries(object)) if (
|
|
3685
|
+
for (const [key, entry] of Object.entries(object)) if (referencesField && (key === "value" || key === "values" || key === "lower" || key === "upper")) next[key] = Array.isArray(entry) ? entry.map((item) => typeof item === "string" ? changes.get(item) ?? item : item) : typeof entry === "string" ? changes.get(entry) ?? entry : entry;
|
|
3553
3686
|
else next[key] = transformOptionValue(entry, fieldId, changes);
|
|
3554
3687
|
return next;
|
|
3555
3688
|
}
|
|
@@ -3695,27 +3828,165 @@ function filterToStorage(filter, fields) {
|
|
|
3695
3828
|
if (!normalized) return null;
|
|
3696
3829
|
const byKey = /* @__PURE__ */ new Map();
|
|
3697
3830
|
for (const field of fields) if (field.id) {
|
|
3698
|
-
byKey.set(field.id, field
|
|
3699
|
-
byKey.set(field.tableColumnName, field
|
|
3700
|
-
byKey.set(field.name, field
|
|
3831
|
+
byKey.set(field.id, field);
|
|
3832
|
+
byKey.set(field.tableColumnName, field);
|
|
3833
|
+
byKey.set(field.name, field);
|
|
3701
3834
|
}
|
|
3702
|
-
const
|
|
3703
|
-
const
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
});
|
|
3835
|
+
const convertRule = (rule) => {
|
|
3836
|
+
const field = byKey.get(rule.field);
|
|
3837
|
+
if (!field?.id) return null;
|
|
3838
|
+
const fieldId = field.id;
|
|
3839
|
+
const list = field.storageCodec === "json_array" || field.storageCodec === "relation";
|
|
3840
|
+
const values = Array.isArray(rule.value) ? rule.value : [rule.value ?? null];
|
|
3841
|
+
const scalar = values[0] ?? null;
|
|
3842
|
+
const equalityValue = list && Array.isArray(rule.value) ? rule.value : scalar;
|
|
3843
|
+
const requireValue = () => {
|
|
3844
|
+
if (scalar === null) throw new EidosFileError("invalid-query", `Saved View filter ${rule.operator} requires an operand`);
|
|
3845
|
+
return scalar;
|
|
3846
|
+
};
|
|
3847
|
+
const requireValues = () => {
|
|
3848
|
+
if (values.some((value) => value === null)) throw new EidosFileError("invalid-query", `Saved View filter ${rule.operator} requires non-null operands`);
|
|
3849
|
+
return values;
|
|
3850
|
+
};
|
|
3851
|
+
const membership = () => list ? {
|
|
3852
|
+
fieldId,
|
|
3853
|
+
op: "has-any",
|
|
3854
|
+
values: requireValues()
|
|
3855
|
+
} : {
|
|
3856
|
+
fieldId,
|
|
3857
|
+
op: "in",
|
|
3858
|
+
values: requireValues()
|
|
3859
|
+
};
|
|
3860
|
+
if (rule.operator === "is-relative-to-today") {
|
|
3861
|
+
const relative = rule.value;
|
|
3862
|
+
if (!relative || typeof relative !== "object" || Array.isArray(relative) || !("direction" in relative) || !("unit" in relative) || ![
|
|
3863
|
+
"past",
|
|
3864
|
+
"next",
|
|
3865
|
+
"this"
|
|
3866
|
+
].includes(String(relative.direction)) || ![
|
|
3867
|
+
"day",
|
|
3868
|
+
"week",
|
|
3869
|
+
"month",
|
|
3870
|
+
"year"
|
|
3871
|
+
].includes(String(relative.unit))) throw new EidosFileError("invalid-query", "Saved View relative date filter is invalid");
|
|
3872
|
+
return {
|
|
3873
|
+
direction: relative.direction,
|
|
3874
|
+
fieldId,
|
|
3875
|
+
op: "relative-date",
|
|
3876
|
+
unit: relative.unit
|
|
3877
|
+
};
|
|
3712
3878
|
}
|
|
3713
|
-
|
|
3714
|
-
|
|
3879
|
+
if (rule.operator === "is-between") {
|
|
3880
|
+
if (!Array.isArray(rule.value) || rule.value.length !== 2 || rule.value.some((value) => value === null)) throw new EidosFileError("invalid-query", "Saved View between filter is invalid");
|
|
3881
|
+
return {
|
|
3882
|
+
fieldId,
|
|
3883
|
+
lower: rule.value[0],
|
|
3884
|
+
op: "between",
|
|
3885
|
+
upper: rule.value[1]
|
|
3886
|
+
};
|
|
3887
|
+
}
|
|
3888
|
+
switch (rule.operator) {
|
|
3889
|
+
case "is-empty": return list ? {
|
|
3890
|
+
fieldId,
|
|
3891
|
+
op: "eq",
|
|
3892
|
+
value: []
|
|
3893
|
+
} : {
|
|
3894
|
+
fieldId,
|
|
3895
|
+
op: "is-null"
|
|
3896
|
+
};
|
|
3897
|
+
case "is-not-empty": return list ? {
|
|
3898
|
+
fieldId,
|
|
3899
|
+
op: "ne",
|
|
3900
|
+
value: []
|
|
3901
|
+
} : {
|
|
3902
|
+
fieldId,
|
|
3903
|
+
op: "is-not-null"
|
|
3904
|
+
};
|
|
3905
|
+
case "equals": return equalityValue === null ? {
|
|
3906
|
+
fieldId,
|
|
3907
|
+
op: "is-null"
|
|
3908
|
+
} : {
|
|
3909
|
+
fieldId,
|
|
3910
|
+
op: "eq",
|
|
3911
|
+
value: equalityValue
|
|
3912
|
+
};
|
|
3913
|
+
case "not-equals": return equalityValue === null ? {
|
|
3914
|
+
fieldId,
|
|
3915
|
+
op: "is-not-null"
|
|
3916
|
+
} : {
|
|
3917
|
+
fieldId,
|
|
3918
|
+
op: "ne",
|
|
3919
|
+
value: equalityValue
|
|
3920
|
+
};
|
|
3921
|
+
case "less-than": return {
|
|
3922
|
+
fieldId,
|
|
3923
|
+
op: "lt",
|
|
3924
|
+
value: requireValue()
|
|
3925
|
+
};
|
|
3926
|
+
case "less-than-or-equal": return {
|
|
3927
|
+
fieldId,
|
|
3928
|
+
op: "lte",
|
|
3929
|
+
value: requireValue()
|
|
3930
|
+
};
|
|
3931
|
+
case "greater-than": return {
|
|
3932
|
+
fieldId,
|
|
3933
|
+
op: "gt",
|
|
3934
|
+
value: requireValue()
|
|
3935
|
+
};
|
|
3936
|
+
case "greater-than-or-equal": return {
|
|
3937
|
+
fieldId,
|
|
3938
|
+
op: "gte",
|
|
3939
|
+
value: requireValue()
|
|
3940
|
+
};
|
|
3941
|
+
case "contains": return list ? membership() : {
|
|
3942
|
+
fieldId,
|
|
3943
|
+
op: "contains",
|
|
3944
|
+
value: String(requireValue())
|
|
3945
|
+
};
|
|
3946
|
+
case "not-contains": return {
|
|
3947
|
+
arg: list ? membership() : {
|
|
3948
|
+
fieldId,
|
|
3949
|
+
op: "contains",
|
|
3950
|
+
value: String(requireValue())
|
|
3951
|
+
},
|
|
3952
|
+
op: "not"
|
|
3953
|
+
};
|
|
3954
|
+
case "starts-with": return {
|
|
3955
|
+
fieldId,
|
|
3956
|
+
op: "starts-with",
|
|
3957
|
+
value: String(requireValue())
|
|
3958
|
+
};
|
|
3959
|
+
case "ends-with": return {
|
|
3960
|
+
fieldId,
|
|
3961
|
+
op: "ends-with",
|
|
3962
|
+
value: String(requireValue())
|
|
3963
|
+
};
|
|
3964
|
+
case "is-any-of": return membership();
|
|
3965
|
+
case "is-all-of": return {
|
|
3966
|
+
fieldId,
|
|
3967
|
+
op: "has-all",
|
|
3968
|
+
values: requireValues()
|
|
3969
|
+
};
|
|
3970
|
+
case "is-none-of": return {
|
|
3971
|
+
arg: membership(),
|
|
3972
|
+
op: "not"
|
|
3973
|
+
};
|
|
3974
|
+
}
|
|
3975
|
+
};
|
|
3976
|
+
const convertGroup = (group) => {
|
|
3977
|
+
const node = {
|
|
3978
|
+
args: group.children.flatMap((child) => {
|
|
3979
|
+
const converted = child.type === "group" ? convertGroup(child) : convertRule(child);
|
|
3980
|
+
return converted ? [converted] : [];
|
|
3981
|
+
}),
|
|
3715
3982
|
op: group.conjunction
|
|
3716
3983
|
};
|
|
3984
|
+
return group.negated ? {
|
|
3985
|
+
arg: node,
|
|
3986
|
+
op: "not"
|
|
3987
|
+
} : node;
|
|
3717
3988
|
};
|
|
3718
|
-
return
|
|
3989
|
+
return convertGroup(normalized);
|
|
3719
3990
|
}
|
|
3720
3991
|
function filterFromStorage(value, fields) {
|
|
3721
3992
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
@@ -3746,7 +4017,133 @@ function filterFromStorage(value, fields) {
|
|
|
3746
4017
|
children
|
|
3747
4018
|
};
|
|
3748
4019
|
};
|
|
3749
|
-
|
|
4020
|
+
const runtimeGroup = (conjunction, children) => ({
|
|
4021
|
+
type: "group",
|
|
4022
|
+
conjunction,
|
|
4023
|
+
children
|
|
4024
|
+
});
|
|
4025
|
+
const convertRuntime = (input) => {
|
|
4026
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
4027
|
+
const node = input;
|
|
4028
|
+
if ((node.op === "and" || node.op === "or") && Array.isArray(node.args)) return runtimeGroup(node.op, node.args.flatMap((child) => {
|
|
4029
|
+
const converted = convertRuntime(child);
|
|
4030
|
+
return converted ? [converted] : [];
|
|
4031
|
+
}));
|
|
4032
|
+
if (node.op === "not" && node.arg !== void 0) {
|
|
4033
|
+
const child = convertRuntime(node.arg);
|
|
4034
|
+
if (!child) return null;
|
|
4035
|
+
const nested = child.type === "group" ? child : runtimeGroup("and", [child]);
|
|
4036
|
+
return {
|
|
4037
|
+
...nested,
|
|
4038
|
+
negated: nested.negated !== true
|
|
4039
|
+
};
|
|
4040
|
+
}
|
|
4041
|
+
if (typeof node.fieldId !== "string" || !ids.has(node.fieldId) || typeof node.op !== "string") return null;
|
|
4042
|
+
const field = node.fieldId;
|
|
4043
|
+
if (node.op === "between") return {
|
|
4044
|
+
type: "rule",
|
|
4045
|
+
field,
|
|
4046
|
+
operator: "is-between",
|
|
4047
|
+
value: [node.lower, node.upper]
|
|
4048
|
+
};
|
|
4049
|
+
if (node.op === "relative-date") return {
|
|
4050
|
+
type: "rule",
|
|
4051
|
+
field,
|
|
4052
|
+
operator: "is-relative-to-today",
|
|
4053
|
+
value: {
|
|
4054
|
+
direction: node.direction,
|
|
4055
|
+
unit: node.unit
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
4058
|
+
if (node.op === "has-all") return {
|
|
4059
|
+
type: "rule",
|
|
4060
|
+
field,
|
|
4061
|
+
operator: "is-all-of",
|
|
4062
|
+
value: node.values
|
|
4063
|
+
};
|
|
4064
|
+
if (node.op === "in") return runtimeGroup("or", node.values.map((entry) => ({
|
|
4065
|
+
type: "rule",
|
|
4066
|
+
field,
|
|
4067
|
+
operator: "equals",
|
|
4068
|
+
value: entry
|
|
4069
|
+
})));
|
|
4070
|
+
if (node.op === "is-null" || node.op === "is-not-null") return {
|
|
4071
|
+
type: "rule",
|
|
4072
|
+
field,
|
|
4073
|
+
operator: node.op === "is-null" ? "equals" : "not-equals",
|
|
4074
|
+
value: null
|
|
4075
|
+
};
|
|
4076
|
+
const operator = RUNTIME_TO_COMPATIBILITY_OPERATOR[node.op];
|
|
4077
|
+
if (!operator) return null;
|
|
4078
|
+
return {
|
|
4079
|
+
type: "rule",
|
|
4080
|
+
field,
|
|
4081
|
+
operator,
|
|
4082
|
+
...node.op === "has-any" ? { value: node.values } : node.op === "relation-has" ? { value: [node.rowId] } : "value" in node ? { value: node.value } : {}
|
|
4083
|
+
};
|
|
4084
|
+
};
|
|
4085
|
+
const containsRuntimeField = (input) => {
|
|
4086
|
+
if (!input || typeof input !== "object") return false;
|
|
4087
|
+
if (Array.isArray(input)) return input.some(containsRuntimeField);
|
|
4088
|
+
const node = input;
|
|
4089
|
+
return typeof node.fieldId === "string" || Object.values(node).some(containsRuntimeField);
|
|
4090
|
+
};
|
|
4091
|
+
if (!containsRuntimeField(value)) return normalizeEidosFileFilter(convert(value));
|
|
4092
|
+
const converted = convertRuntime(value);
|
|
4093
|
+
return normalizeEidosFileFilter(converted?.type === "group" ? converted : converted ? runtimeGroup("and", [converted]) : null);
|
|
4094
|
+
}
|
|
4095
|
+
const RUNTIME_TO_COMPATIBILITY_OPERATOR = {
|
|
4096
|
+
eq: "equals",
|
|
4097
|
+
ne: "not-equals",
|
|
4098
|
+
lt: "less-than",
|
|
4099
|
+
lte: "less-than-or-equal",
|
|
4100
|
+
gt: "greater-than",
|
|
4101
|
+
gte: "greater-than-or-equal",
|
|
4102
|
+
contains: "contains",
|
|
4103
|
+
"starts-with": "starts-with",
|
|
4104
|
+
"ends-with": "ends-with",
|
|
4105
|
+
"has-any": "is-any-of",
|
|
4106
|
+
"relation-has": "is-any-of"
|
|
4107
|
+
};
|
|
4108
|
+
const RUNTIME_FILTER_OPERATORS = new Set([
|
|
4109
|
+
"is-null",
|
|
4110
|
+
"is-not-null",
|
|
4111
|
+
"eq",
|
|
4112
|
+
"ne",
|
|
4113
|
+
"lt",
|
|
4114
|
+
"lte",
|
|
4115
|
+
"gt",
|
|
4116
|
+
"gte",
|
|
4117
|
+
"between",
|
|
4118
|
+
"in",
|
|
4119
|
+
"contains",
|
|
4120
|
+
"starts-with",
|
|
4121
|
+
"ends-with",
|
|
4122
|
+
"has-any",
|
|
4123
|
+
"has-all",
|
|
4124
|
+
"relation-has",
|
|
4125
|
+
"relative-date"
|
|
4126
|
+
]);
|
|
4127
|
+
function sortsFromStorage(value) {
|
|
4128
|
+
if (!Array.isArray(value)) return [];
|
|
4129
|
+
return value.flatMap((entry) => {
|
|
4130
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return [];
|
|
4131
|
+
const sort = entry;
|
|
4132
|
+
const field = typeof sort.fieldId === "string" ? sort.fieldId : typeof sort.field === "string" ? sort.field : null;
|
|
4133
|
+
if (!field) return [];
|
|
4134
|
+
return [{
|
|
4135
|
+
field,
|
|
4136
|
+
direction: sort.direction === "desc" ? "desc" : "asc",
|
|
4137
|
+
nulls: sort.nulls === "first" ? "first" : "last"
|
|
4138
|
+
}];
|
|
4139
|
+
});
|
|
4140
|
+
}
|
|
4141
|
+
function sortsToStorage(sorts) {
|
|
4142
|
+
return sorts.map((sort) => ({
|
|
4143
|
+
direction: sort.direction,
|
|
4144
|
+
fieldId: sort.field,
|
|
4145
|
+
...sort.nulls === "first" ? { nulls: "first" } : {}
|
|
4146
|
+
}));
|
|
3750
4147
|
}
|
|
3751
4148
|
function storedViewQueryStatus(query, fields) {
|
|
3752
4149
|
const fieldIds = new Set(fields.flatMap((field) => field.id ? [field.id] : []));
|
|
@@ -3773,7 +4170,54 @@ function storedViewQueryStatus(query, fields) {
|
|
|
3773
4170
|
const filterSupported = (value) => {
|
|
3774
4171
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3775
4172
|
const node = value;
|
|
3776
|
-
if (
|
|
4173
|
+
if ((node.op === "and" || node.op === "or") && Array.isArray(node.args)) return Object.keys(node).every((key) => key === "op" || key === "args") && node.args.every(filterSupported);
|
|
4174
|
+
if (node.op === "not") return Object.keys(node).every((key) => key === "op" || key === "arg") && filterSupported(node.arg);
|
|
4175
|
+
if (typeof node.fieldId === "string") {
|
|
4176
|
+
if (!fieldIds.has(node.fieldId) || typeof node.op !== "string" || !RUNTIME_FILTER_OPERATORS.has(node.op)) return false;
|
|
4177
|
+
const allowed = new Set(["fieldId", "op"]);
|
|
4178
|
+
if ([
|
|
4179
|
+
"eq",
|
|
4180
|
+
"ne",
|
|
4181
|
+
"lt",
|
|
4182
|
+
"lte",
|
|
4183
|
+
"gt",
|
|
4184
|
+
"gte",
|
|
4185
|
+
"contains",
|
|
4186
|
+
"starts-with",
|
|
4187
|
+
"ends-with"
|
|
4188
|
+
].includes(node.op)) {
|
|
4189
|
+
allowed.add("value");
|
|
4190
|
+
if (!("value" in node) || node.value === null) return false;
|
|
4191
|
+
} else if ([
|
|
4192
|
+
"in",
|
|
4193
|
+
"has-any",
|
|
4194
|
+
"has-all"
|
|
4195
|
+
].includes(node.op)) {
|
|
4196
|
+
allowed.add("values");
|
|
4197
|
+
if (!Array.isArray(node.values)) return false;
|
|
4198
|
+
} else if (node.op === "between") {
|
|
4199
|
+
allowed.add("lower");
|
|
4200
|
+
allowed.add("upper");
|
|
4201
|
+
if (!("lower" in node) || !("upper" in node) || node.lower === null || node.upper === null) return false;
|
|
4202
|
+
} else if (node.op === "relation-has") {
|
|
4203
|
+
allowed.add("rowId");
|
|
4204
|
+
if (typeof node.rowId !== "string") return false;
|
|
4205
|
+
} else if (node.op === "relative-date") {
|
|
4206
|
+
allowed.add("direction");
|
|
4207
|
+
allowed.add("unit");
|
|
4208
|
+
if (![
|
|
4209
|
+
"past",
|
|
4210
|
+
"next",
|
|
4211
|
+
"this"
|
|
4212
|
+
].includes(String(node.direction)) || ![
|
|
4213
|
+
"day",
|
|
4214
|
+
"week",
|
|
4215
|
+
"month",
|
|
4216
|
+
"year"
|
|
4217
|
+
].includes(String(node.unit))) return false;
|
|
4218
|
+
}
|
|
4219
|
+
return Object.keys(node).every((key) => allowed.has(key));
|
|
4220
|
+
}
|
|
3777
4221
|
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;
|
|
3778
4222
|
return supportedRuleValue(node.op, node.value);
|
|
3779
4223
|
};
|
|
@@ -3783,7 +4227,9 @@ function storedViewQueryStatus(query, fields) {
|
|
|
3783
4227
|
for (const value of query.sort) {
|
|
3784
4228
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "unsupported";
|
|
3785
4229
|
const sort = value;
|
|
3786
|
-
|
|
4230
|
+
const field = typeof sort.fieldId === "string" ? sort.fieldId : typeof sort.field === "string" ? sort.field : null;
|
|
4231
|
+
const fieldKey = typeof sort.fieldId === "string" ? "fieldId" : "field";
|
|
4232
|
+
if (!field || !fieldIds.has(field) || sort.direction !== "asc" && sort.direction !== "desc" || sort.nulls !== void 0 && sort.nulls !== "first" && sort.nulls !== "last" || Object.keys(sort).some((key) => key !== fieldKey && key !== "direction" && key !== "nulls")) return "unsupported";
|
|
3787
4233
|
}
|
|
3788
4234
|
}
|
|
3789
4235
|
return "supported";
|
|
@@ -4460,7 +4906,7 @@ var EidosFileRuntime = class {
|
|
|
4460
4906
|
if (changes.optionValueChanges && changes.optionValueChanges.length > 0) {
|
|
4461
4907
|
if (field.type !== "select" && field.type !== "multi-select") throw new EidosFileError("invalid-schema", "Only Select Fields have option values");
|
|
4462
4908
|
const replacements = new Map(changes.optionValueChanges.map((change) => [change.from, change.to]));
|
|
4463
|
-
const options =
|
|
4909
|
+
const options = assertedRawSelectOptions(settings);
|
|
4464
4910
|
const existingNames = new Set(options.map((option) => option.name));
|
|
4465
4911
|
settings.options = options.flatMap((option) => {
|
|
4466
4912
|
const replacement = replacements.get(option.name);
|
|
@@ -4474,10 +4920,7 @@ var EidosFileRuntime = class {
|
|
|
4474
4920
|
if (field.type === "select" && typeof settings.defaultOption === "string") settings.defaultOption = replacements.get(settings.defaultOption) ?? settings.defaultOption;
|
|
4475
4921
|
}
|
|
4476
4922
|
if (field.type === "select" || field.type === "multi-select") {
|
|
4477
|
-
settings.options =
|
|
4478
|
-
color: option.color,
|
|
4479
|
-
name: option.name
|
|
4480
|
-
}));
|
|
4923
|
+
settings.options = assertedRawSelectOptions(settings);
|
|
4481
4924
|
if (field.type === "select") {
|
|
4482
4925
|
const defaultOption = assertEidosFileSelectDefaultOption(settings);
|
|
4483
4926
|
if (defaultOption === null) delete settings.defaultOption;
|
|
@@ -4827,7 +5270,7 @@ var EidosFileRuntime = class {
|
|
|
4827
5270
|
const query = jsonObject(row.query_json);
|
|
4828
5271
|
const layout = jsonObject(row.layout_json);
|
|
4829
5272
|
const queryStatus = storedViewQueryStatus(query, fields);
|
|
4830
|
-
const storedSorts =
|
|
5273
|
+
const storedSorts = sortsFromStorage(query.sort);
|
|
4831
5274
|
const fieldIds = new Set(fields.flatMap((field) => field.id ? [field.id] : []));
|
|
4832
5275
|
const fieldOrder = Array.isArray(layout.fieldOrder) ? layout.fieldOrder.flatMap((value) => typeof value === "string" && fieldIds.has(value) ? [value] : []) : [];
|
|
4833
5276
|
const properties = { ...layout };
|
|
@@ -4901,7 +5344,7 @@ var EidosFileRuntime = class {
|
|
|
4901
5344
|
input.type,
|
|
4902
5345
|
canonicalizeEidosFileJson({
|
|
4903
5346
|
...filterToStorage(input.filter, fields) ? { filter: filterToStorage(input.filter, fields) } : {},
|
|
4904
|
-
...sorts.length > 0 ? { sort: sorts } : {}
|
|
5347
|
+
...sorts.length > 0 ? { sort: sortsToStorage(sorts) } : {}
|
|
4905
5348
|
}),
|
|
4906
5349
|
canonicalizeEidosFileJson({
|
|
4907
5350
|
...properties,
|
|
@@ -4970,7 +5413,7 @@ var EidosFileRuntime = class {
|
|
|
4970
5413
|
next.type,
|
|
4971
5414
|
queryChanged ? canonicalizeEidosFileJson({
|
|
4972
5415
|
...filterToStorage(next.filter, fields) ? { filter: filterToStorage(next.filter, fields) } : {},
|
|
4973
|
-
...sorts.length ? { sort: sorts } : {}
|
|
5416
|
+
...sorts.length ? { sort: sortsToStorage(sorts) } : {}
|
|
4974
5417
|
}) : currentRow.query_json,
|
|
4975
5418
|
layoutChanged ? canonicalizeEidosFileJson(layout) : currentRow.layout_json,
|
|
4976
5419
|
stablePosition(next.position, current.position ?? 0),
|
|
@@ -6218,4 +6661,4 @@ function fieldValueTypeForScan(field) {
|
|
|
6218
6661
|
//#endregion
|
|
6219
6662
|
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 };
|
|
6220
6663
|
|
|
6221
|
-
//# sourceMappingURL=runtime-
|
|
6664
|
+
//# sourceMappingURL=runtime-D9Vp-lxn.mjs.map
|