@dbsp/core 6.1.0 → 6.1.1
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.
|
@@ -262,12 +262,24 @@ ${errors.map((e) => ` - ${e}`).join("\n")}`
|
|
|
262
262
|
}
|
|
263
263
|
};
|
|
264
264
|
|
|
265
|
-
// src/
|
|
265
|
+
// src/relational-read-plans.ts
|
|
266
266
|
import {
|
|
267
|
-
|
|
268
|
-
isParamIntent
|
|
267
|
+
isParamIntent as isParamIntent2
|
|
269
268
|
} from "@dbsp/types";
|
|
269
|
+
|
|
270
|
+
// src/dx/default-filter-refusals.ts
|
|
271
|
+
import { isParamIntent } from "@dbsp/types";
|
|
270
272
|
import { getTrustedNqlRelationFilterFields } from "@dbsp/types/internal";
|
|
273
|
+
|
|
274
|
+
// src/intent-payload.ts
|
|
275
|
+
import { EXPRESSION_BRAND } from "@dbsp/types";
|
|
276
|
+
function isBoundPayload(node, key, child) {
|
|
277
|
+
if (key !== "value" && key !== "values") return false;
|
|
278
|
+
if (node.kind === "namedArg") return false;
|
|
279
|
+
return !child || typeof child !== "object" || !(EXPRESSION_BRAND in child);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/dx/default-filter-refusals.ts
|
|
271
283
|
function findDefaultFilterScan(intent, model, filters, path, skipRoot = false, derivedRanges = /* @__PURE__ */ new Set()) {
|
|
272
284
|
if (!filters || !Object.keys(filters).length) return;
|
|
273
285
|
const root = intent;
|
|
@@ -325,8 +337,7 @@ function findDefaultFilterScan(intent, model, filters, path, skipRoot = false, d
|
|
|
325
337
|
}
|
|
326
338
|
}
|
|
327
339
|
for (const [key, child] of Object.entries(node)) {
|
|
328
|
-
if ((
|
|
329
|
-
continue;
|
|
340
|
+
if (isBoundPayload(node, key, child)) continue;
|
|
330
341
|
visit(child, source, `${location}.${key}`);
|
|
331
342
|
}
|
|
332
343
|
};
|
|
@@ -406,8 +417,7 @@ function assertUnsupportedNqlDefaultFilters(intent, model, filters, path) {
|
|
|
406
417
|
}
|
|
407
418
|
}
|
|
408
419
|
for (const [key, child] of Object.entries(node)) {
|
|
409
|
-
if ((
|
|
410
|
-
continue;
|
|
420
|
+
if (isBoundPayload(node, key, child)) continue;
|
|
411
421
|
visit(child, source, `${location}.${key}`);
|
|
412
422
|
}
|
|
413
423
|
};
|
|
@@ -441,6 +451,26 @@ function registerRelationalReadPolicy(intent, model, filters) {
|
|
|
441
451
|
function getRelationalReadPolicy(intent) {
|
|
442
452
|
return plans.get(intent);
|
|
443
453
|
}
|
|
454
|
+
function containsRelationalReadPolicy(intent) {
|
|
455
|
+
const seen = /* @__PURE__ */ new Set();
|
|
456
|
+
const visit = (value) => {
|
|
457
|
+
if (!value || typeof value !== "object" || seen.has(value)) return false;
|
|
458
|
+
seen.add(value);
|
|
459
|
+
if (isParamIntent2(value)) return false;
|
|
460
|
+
const node = value;
|
|
461
|
+
if (node.kind === "param" || node.kind === "literal" || node.kind === "parameter")
|
|
462
|
+
return false;
|
|
463
|
+
if (typeof node.from === "string" && plans.has(value))
|
|
464
|
+
return true;
|
|
465
|
+
if (Array.isArray(value)) return value.some(visit);
|
|
466
|
+
for (const [key, child] of Object.entries(node)) {
|
|
467
|
+
if (isBoundPayload(node, key, child)) continue;
|
|
468
|
+
if (visit(child)) return true;
|
|
469
|
+
}
|
|
470
|
+
return false;
|
|
471
|
+
};
|
|
472
|
+
return visit(intent);
|
|
473
|
+
}
|
|
444
474
|
|
|
445
475
|
// src/transition/diagnostic-text.ts
|
|
446
476
|
function escapeDiagnosticText(value) {
|
|
@@ -463,7 +493,7 @@ function escapeDiagnosticText(value) {
|
|
|
463
493
|
// src/resolved-conditions.ts
|
|
464
494
|
import {
|
|
465
495
|
EXPRESSION_BRAND as EXPRESSION_BRAND2,
|
|
466
|
-
isParamIntent as
|
|
496
|
+
isParamIntent as isParamIntent3,
|
|
467
497
|
RangeAllocator,
|
|
468
498
|
REF_BRAND
|
|
469
499
|
} from "@dbsp/types";
|
|
@@ -481,7 +511,7 @@ function isRef(value) {
|
|
|
481
511
|
return value !== null && typeof value === "object" && REF_BRAND in value;
|
|
482
512
|
}
|
|
483
513
|
function containsOuterReference(value) {
|
|
484
|
-
if (!value || typeof value !== "object" ||
|
|
514
|
+
if (!value || typeof value !== "object" || isParamIntent3(value)) return false;
|
|
485
515
|
if (isSubqueryRef(value) && value.outer === true) return true;
|
|
486
516
|
return Object.values(value).some(
|
|
487
517
|
(item) => Array.isArray(item) ? item.some(containsOuterReference) : containsOuterReference(item)
|
|
@@ -673,6 +703,10 @@ function resolveConditionContext(where, root, visible, enclosing, allocator, mod
|
|
|
673
703
|
};
|
|
674
704
|
else if (select?.type === "aggregate" && select.aggregates[0]) {
|
|
675
705
|
const agg = select.aggregates[0];
|
|
706
|
+
if (use === "scalar" && agg.filter !== void 0)
|
|
707
|
+
throw new Error(
|
|
708
|
+
"scalar subquery with an aggregate FILTER is not supported \u2014 it would silently change which rows match; restructure the query or use a CTE."
|
|
709
|
+
);
|
|
676
710
|
projection = {
|
|
677
711
|
kind: "aggregate",
|
|
678
712
|
function: agg.function,
|
|
@@ -851,7 +885,7 @@ function resolveConditionContext(where, root, visible, enclosing, allocator, mod
|
|
|
851
885
|
});
|
|
852
886
|
const expr = (value) => expression(value, current, ranges, enclosing2);
|
|
853
887
|
const arg = (value, stringsAreColumns = false) => {
|
|
854
|
-
if (
|
|
888
|
+
if (isParamIntent3(value))
|
|
855
889
|
return { kind: "parameter", value: value.value };
|
|
856
890
|
if (isExpression(value)) return expr(value.intent);
|
|
857
891
|
if (isRef(value)) return ref3(value.target);
|
|
@@ -1007,9 +1041,9 @@ function resolveConditionContext(where, root, visible, enclosing, allocator, mod
|
|
|
1007
1041
|
};
|
|
1008
1042
|
const parameter = (value, cast2 = "none") => ({
|
|
1009
1043
|
kind: "parameter",
|
|
1010
|
-
value:
|
|
1044
|
+
value: isParamIntent3(value) ? value.value : value,
|
|
1011
1045
|
cast: cast2,
|
|
1012
|
-
bound:
|
|
1046
|
+
bound: isParamIntent3(value)
|
|
1013
1047
|
});
|
|
1014
1048
|
const rangeParameter = (value) => {
|
|
1015
1049
|
const authored = parameter(value, "range");
|
|
@@ -1026,11 +1060,11 @@ function resolveConditionContext(where, root, visible, enclosing, allocator, mod
|
|
|
1026
1060
|
return { ...authored, cast: "range-element" };
|
|
1027
1061
|
};
|
|
1028
1062
|
const normalizeList = (value) => {
|
|
1029
|
-
if (
|
|
1063
|
+
if (isParamIntent3(value)) return value;
|
|
1030
1064
|
if (!Array.isArray(value)) return value;
|
|
1031
|
-
if (value.length === 1 &&
|
|
1065
|
+
if (value.length === 1 && isParamIntent3(value[0]) && Array.isArray(value[0].value))
|
|
1032
1066
|
return value[0];
|
|
1033
|
-
return value.map((v) =>
|
|
1067
|
+
return value.map((v) => isParamIntent3(v) ? v.value : v);
|
|
1034
1068
|
};
|
|
1035
1069
|
const visit = (node, current, ranges, enclosing2, fieldOverride) => {
|
|
1036
1070
|
if (current === root && node === getDefaultFilter(activeFilters, root.table) && mode?.rootDefaultFilter)
|
|
@@ -1082,7 +1116,7 @@ function resolveConditionContext(where, root, visible, enclosing, allocator, mod
|
|
|
1082
1116
|
return column(fieldOverride ?? node.field, current, ranges, enclosing2);
|
|
1083
1117
|
};
|
|
1084
1118
|
const rhs = (value, cast2) => {
|
|
1085
|
-
if (
|
|
1119
|
+
if (isParamIntent3(value)) return parameter(value, cast2);
|
|
1086
1120
|
if (isFieldRef(value))
|
|
1087
1121
|
return column(
|
|
1088
1122
|
value.alias ? `${value.alias}.${value.column}` : value.column,
|
|
@@ -3585,7 +3619,7 @@ function pluralize(name) {
|
|
|
3585
3619
|
// src/resolved-includes.ts
|
|
3586
3620
|
import {
|
|
3587
3621
|
EXPRESSION_BRAND as EXPRESSION_BRAND4,
|
|
3588
|
-
isParamIntent as
|
|
3622
|
+
isParamIntent as isParamIntent4,
|
|
3589
3623
|
RangeAllocator as RangeAllocator3,
|
|
3590
3624
|
toColumnList
|
|
3591
3625
|
} from "@dbsp/types";
|
|
@@ -3631,7 +3665,7 @@ function assertSupportedIncludeWhere(includes, strategies, parent = "", intentPa
|
|
|
3631
3665
|
}
|
|
3632
3666
|
if (include.where) {
|
|
3633
3667
|
const visit = (node) => {
|
|
3634
|
-
if (!node || typeof node !== "object" ||
|
|
3668
|
+
if (!node || typeof node !== "object" || isParamIntent4(node)) return;
|
|
3635
3669
|
if (Array.isArray(node)) {
|
|
3636
3670
|
for (const child of node) visit(child);
|
|
3637
3671
|
return;
|
|
@@ -4040,7 +4074,7 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
4040
4074
|
const expressionSubqueries = [];
|
|
4041
4075
|
const inspected = /* @__PURE__ */ new WeakSet();
|
|
4042
4076
|
const inspect = (value, intentPath) => {
|
|
4043
|
-
if (!value || typeof value !== "object" ||
|
|
4077
|
+
if (!value || typeof value !== "object" || isParamIntent4(value)) return;
|
|
4044
4078
|
if (inspected.has(value)) return;
|
|
4045
4079
|
inspected.add(value);
|
|
4046
4080
|
if (Array.isArray(value)) {
|
|
@@ -4058,7 +4092,7 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
4058
4092
|
);
|
|
4059
4093
|
if (node.kind === "subquery" && node.query) {
|
|
4060
4094
|
const query = node.query;
|
|
4061
|
-
if (!model || !
|
|
4095
|
+
if (!model || !containsRelationalReadPolicy(query) && !findDefaultFilterScan(
|
|
4062
4096
|
query,
|
|
4063
4097
|
model,
|
|
4064
4098
|
options.defaultFilters,
|
|
@@ -4116,8 +4150,7 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
4116
4150
|
return;
|
|
4117
4151
|
}
|
|
4118
4152
|
for (const [key, child] of Object.entries(node)) {
|
|
4119
|
-
if ((
|
|
4120
|
-
continue;
|
|
4153
|
+
if (isBoundPayload(node, key, child)) continue;
|
|
4121
4154
|
inspect(child, `${intentPath}.${key}`);
|
|
4122
4155
|
}
|
|
4123
4156
|
inspected.delete(value);
|
|
@@ -4588,7 +4621,7 @@ function optimizeInToExists(where, sourceTable, model, negated = false) {
|
|
|
4588
4621
|
const inWhere = where;
|
|
4589
4622
|
if (!inWhere.subquery) return where;
|
|
4590
4623
|
const sq = inWhere.subquery;
|
|
4591
|
-
if (sq.limit != null || sq.orderBy?.length || sq.offset != null || sq.groupBy?.length || sq.having != null || sq.distinct || sq.distinctOn?.length || sq.joins?.length || sq.include?.length || sq.batchValuesSource != null || sq.existsWrap || sq.lock != null || sq.select != null && sq.select.type !== "fields") {
|
|
4624
|
+
if (getRelationalReadPolicy(sq) !== void 0 || sq.limit != null || sq.orderBy?.length || sq.offset != null || sq.groupBy?.length || sq.having != null || sq.distinct || sq.distinctOn?.length || sq.joins?.length || sq.include?.length || sq.batchValuesSource != null || sq.existsWrap || sq.lock != null || sq.select != null && sq.select.type !== "fields") {
|
|
4592
4625
|
return where;
|
|
4593
4626
|
}
|
|
4594
4627
|
const subSelect = inWhere.subquery.select;
|
|
@@ -25399,7 +25432,10 @@ function createOrmInstance(model, strictMode, relationHints, adapter, schemaName
|
|
|
25399
25432
|
"selectExpression() requires an adapter. Pass an adapter when creating the ORM."
|
|
25400
25433
|
);
|
|
25401
25434
|
}
|
|
25402
|
-
const compiled = adapter.compileSelectExpression(expr.intent, {
|
|
25435
|
+
const compiled = adapter.compileSelectExpression(expr.intent, {
|
|
25436
|
+
model,
|
|
25437
|
+
...defaultFilters !== void 0 && { defaultFilters }
|
|
25438
|
+
});
|
|
25403
25439
|
return {
|
|
25404
25440
|
sql: compiled.sql,
|
|
25405
25441
|
parameters: compiled.parameters,
|
|
@@ -26882,4 +26918,4 @@ export {
|
|
|
26882
26918
|
runAssertions,
|
|
26883
26919
|
isOverallSuccess
|
|
26884
26920
|
};
|
|
26885
|
-
//# sourceMappingURL=chunk-
|
|
26921
|
+
//# sourceMappingURL=chunk-DUIL3IMF.js.map
|