@dbsp/core 6.0.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.
- package/dist/{assertion-functions-DiuRuq1k.d.ts → assertion-functions-D6t_OvBt.d.ts} +14 -4
- package/dist/{chunk-UATOOZ2G.js → chunk-DUIL3IMF.js} +196 -100
- package/dist/chunk-DUIL3IMF.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-UATOOZ2G.js.map +0 -1
|
@@ -2673,14 +2673,16 @@ interface QueryBuilder<TResult = unknown> {
|
|
|
2673
2673
|
* Add an explicit SQL JOIN clause to the query (non-hydrating, flat result).
|
|
2674
2674
|
*
|
|
2675
2675
|
* Two modes based on whether `opts.on` is provided:
|
|
2676
|
-
* - **Relation mode** (no `on`): FK auto-resolved from the model, like `include` but flat.
|
|
2676
|
+
* - **Relation mode** (no `on`): FK auto-resolved from the model, like `include` but flat. A dotted relation
|
|
2677
|
+
* path joins one range per relation, each correlated to the previous one on its declared keys.
|
|
2677
2678
|
* - **Table mode** (`on` required): Explicit table + ON condition. Use `as` for self-joins.
|
|
2678
2679
|
*
|
|
2679
|
-
* @param relationOrTable - Relation name (FK mode) or table name (explicit mode)
|
|
2680
|
+
* @param relationOrTable - Relation name or dotted relation path (FK mode) or table name (explicit mode)
|
|
2680
2681
|
* @param opts - Optional join configuration
|
|
2681
|
-
* @param opts.type - Join type: `'inner'` (default) or `'left'
|
|
2682
|
+
* @param opts.type - Join type: `'inner'` (default) or `'left'`, applied to every hop of a path
|
|
2682
2683
|
* @param opts.on - ON condition (required for table mode, absent for relation mode)
|
|
2683
|
-
* @param opts.as - Alias for the joined table (required for self-joins)
|
|
2684
|
+
* @param opts.as - Alias for the joined table (required for self-joins). In relation mode, a string names the
|
|
2685
|
+
* last hop and a list names every hop; unnamed hops are aliased by their path prefix joined with `_`.
|
|
2684
2686
|
* @returns A new QueryBuilder with the join appended
|
|
2685
2687
|
*
|
|
2686
2688
|
* @example
|
|
@@ -2688,6 +2690,9 @@ interface QueryBuilder<TResult = unknown> {
|
|
|
2688
2690
|
* // Relation mode — FK auto-resolved
|
|
2689
2691
|
* orm.from(calls).join('caller')
|
|
2690
2692
|
* orm.from(calls).join('callerFile', { type: 'left' })
|
|
2693
|
+
* // Relation path — JOIN symbols AS callee …, JOIN files AS callee_file ON callee.file_id = callee_file.id
|
|
2694
|
+
* orm.from(calls).join('callee.file', { type: 'left' })
|
|
2695
|
+
* orm.from(calls).join('callee.file', { as: ['c', 'cf'] })
|
|
2691
2696
|
*
|
|
2692
2697
|
* // Table mode — explicit ON condition
|
|
2693
2698
|
* orm.from(embeddings).join('embeddings', {
|
|
@@ -2697,6 +2702,11 @@ interface QueryBuilder<TResult = unknown> {
|
|
|
2697
2702
|
* })
|
|
2698
2703
|
* ```
|
|
2699
2704
|
*/
|
|
2705
|
+
join(relationPath: string, opts?: {
|
|
2706
|
+
type?: 'inner' | 'left';
|
|
2707
|
+
as?: string | readonly string[];
|
|
2708
|
+
on?: never;
|
|
2709
|
+
}): QueryBuilder<TResult>;
|
|
2700
2710
|
join(relationOrTable: string, opts?: {
|
|
2701
2711
|
type?: 'inner' | 'left';
|
|
2702
2712
|
on?: WhereIntent$1;
|
|
@@ -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";
|
|
@@ -3596,6 +3630,29 @@ import {
|
|
|
3596
3630
|
resolveDeclaredRelationPath as resolveDeclaredRelationPath2,
|
|
3597
3631
|
resolveIncludeRelationName
|
|
3598
3632
|
} from "@dbsp/types/internal";
|
|
3633
|
+
|
|
3634
|
+
// src/dx/relation-join-path.ts
|
|
3635
|
+
function relationJoinHops(relation, alias) {
|
|
3636
|
+
const segments = relation.split(".");
|
|
3637
|
+
for (const segment of segments) validateIdentifier(segment, "relation");
|
|
3638
|
+
if (alias !== void 0 && typeof alias !== "string") {
|
|
3639
|
+
if (alias.length !== segments.length)
|
|
3640
|
+
throw new Error(
|
|
3641
|
+
`join('${relation}'): 'as' lists ${alias.length} aliases for ${segments.length} hops.`
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
const last = segments.length - 1;
|
|
3645
|
+
const aliases = segments.map((_, k) => {
|
|
3646
|
+
if (alias !== void 0 && typeof alias !== "string")
|
|
3647
|
+
return alias[k];
|
|
3648
|
+
if (k === last && typeof alias === "string") return alias;
|
|
3649
|
+
return segments.slice(0, k + 1).join("_");
|
|
3650
|
+
});
|
|
3651
|
+
for (const hopAlias of aliases) validateIdentifier(hopAlias, "alias");
|
|
3652
|
+
return { segments, aliases };
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
// src/resolved-includes.ts
|
|
3599
3656
|
function assertSupportedIncludeWhere(includes, strategies, parent = "", intentParent = "", parentStrategy) {
|
|
3600
3657
|
for (const [index, include] of (includes ?? []).entries()) {
|
|
3601
3658
|
const path = `${parent}include[${index}](${include.relation})`;
|
|
@@ -3608,7 +3665,7 @@ function assertSupportedIncludeWhere(includes, strategies, parent = "", intentPa
|
|
|
3608
3665
|
}
|
|
3609
3666
|
if (include.where) {
|
|
3610
3667
|
const visit = (node) => {
|
|
3611
|
-
if (!node || typeof node !== "object" ||
|
|
3668
|
+
if (!node || typeof node !== "object" || isParamIntent4(node)) return;
|
|
3612
3669
|
if (Array.isArray(node)) {
|
|
3613
3670
|
for (const child of node) visit(child);
|
|
3614
3671
|
return;
|
|
@@ -3658,72 +3715,98 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
3658
3715
|
const visibleJoinRanges = [rootRange];
|
|
3659
3716
|
const firstJoinByQualifier = /* @__PURE__ */ new Map();
|
|
3660
3717
|
(intent.joins ?? []).forEach((join, index) => {
|
|
3661
|
-
const
|
|
3662
|
-
|
|
3663
|
-
firstJoinByQualifier.
|
|
3718
|
+
const qualifiers = join.relation !== void 0 ? relationJoinHops(join.relation, join.alias).aliases : [join.alias ?? join.batchValues?.alias ?? join.table];
|
|
3719
|
+
for (const qualifier of qualifiers)
|
|
3720
|
+
if (!firstJoinByQualifier.has(qualifier))
|
|
3721
|
+
firstJoinByQualifier.set(qualifier, index);
|
|
3664
3722
|
});
|
|
3665
|
-
const
|
|
3666
|
-
(
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
path
|
|
3694
|
-
table = resolved.targetTable;
|
|
3695
|
-
}
|
|
3696
|
-
const range = allocator.bind(table, alias);
|
|
3697
|
-
allocator.reserve(range.alias);
|
|
3698
|
-
visibleJoinRanges.push(range);
|
|
3699
|
-
const defaultFilter = join.batchValues ? void 0 : resolveScanDefaultFilter(options.defaultFilters, range, model);
|
|
3700
|
-
const on = resolveConditionContext(
|
|
3701
|
-
join.on,
|
|
3702
|
-
rootRange,
|
|
3703
|
-
[...visibleJoinRanges],
|
|
3704
|
-
[[range]],
|
|
3705
|
-
allocator,
|
|
3706
|
-
model,
|
|
3707
|
-
0,
|
|
3708
|
-
[],
|
|
3709
|
-
{
|
|
3710
|
-
defaultFilters: options.defaultFilters,
|
|
3711
|
-
subqueryRefusal: join.batchValues ? "Subquery in BatchValues JOIN ON condition is not supported." : "Subquery in JOIN ON condition is not supported.",
|
|
3712
|
-
firstJoinByQualifier,
|
|
3713
|
-
intentIndex
|
|
3714
|
-
}
|
|
3723
|
+
const resolveRelationJoinHops = (relationPath, alias) => {
|
|
3724
|
+
if (!model)
|
|
3725
|
+
throw new Error(
|
|
3726
|
+
`join('${relationPath}'): relation-mode join requires a model for FK resolution.`
|
|
3727
|
+
);
|
|
3728
|
+
const { segments, aliases } = relationJoinHops(relationPath, alias);
|
|
3729
|
+
const notFound = (segmentIndex, table2) => {
|
|
3730
|
+
const available = model.getRelationsFrom(table2).map((r) => r.name).join(", ");
|
|
3731
|
+
return new Error(
|
|
3732
|
+
segmentIndex === 0 ? `join('${relationPath}'): relation not found on table '${table2}'. Available: ${available}` : `join('${relationPath}'): relation '${segments[segmentIndex]}' not found on table '${table2}'. Available: ${available}`
|
|
3733
|
+
);
|
|
3734
|
+
};
|
|
3735
|
+
let table = intent.from;
|
|
3736
|
+
for (const [segmentIndex, segment] of segments.entries()) {
|
|
3737
|
+
const relation = model.getRelationsFrom(table).find((r) => r.name === segment);
|
|
3738
|
+
if (!relation) throw notFound(segmentIndex, table);
|
|
3739
|
+
if (relation.type === "belongsToMany")
|
|
3740
|
+
throw new InvalidOperationError(
|
|
3741
|
+
"relation",
|
|
3742
|
+
belongsToManyJoinIncludeRefusal(`${table}.${relation.name}`)
|
|
3743
|
+
);
|
|
3744
|
+
table = relation.target;
|
|
3745
|
+
}
|
|
3746
|
+
const resolved = resolveDeclaredRelationPath2(model, intent.from, segments);
|
|
3747
|
+
if (!resolved.ok)
|
|
3748
|
+
throw notFound(resolved.segmentIndex, resolved.sourceTable);
|
|
3749
|
+
if (resolved.hops.length !== segments.length || resolved.hops.some((hop, k) => hop.segmentIndex !== k))
|
|
3750
|
+
throw new Error(
|
|
3751
|
+
`join('${relationPath}'): the resolved relation path does not hold one hop per segment.`
|
|
3715
3752
|
);
|
|
3753
|
+
return segments.map((_, k) => {
|
|
3754
|
+
const target = resolved.relations[k].target;
|
|
3716
3755
|
return {
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3756
|
+
table: target,
|
|
3757
|
+
alias: aliases[k],
|
|
3758
|
+
path: {
|
|
3759
|
+
ok: true,
|
|
3760
|
+
logicalSegments: segments.slice(0, k + 1),
|
|
3761
|
+
relations: resolved.relations.slice(0, k + 1),
|
|
3762
|
+
hops: resolved.hops.slice(0, k + 1),
|
|
3763
|
+
targetTable: target
|
|
3764
|
+
}
|
|
3726
3765
|
};
|
|
3766
|
+
});
|
|
3767
|
+
};
|
|
3768
|
+
const joins = (intent.joins ?? []).flatMap(
|
|
3769
|
+
(join, intentIndex) => {
|
|
3770
|
+
const hops = join.relation !== void 0 ? resolveRelationJoinHops(join.relation, join.alias) : (() => {
|
|
3771
|
+
const alias = join.alias ?? join.batchValues?.alias ?? join.table;
|
|
3772
|
+
return [{ table: join.table ?? alias, alias, path: void 0 }];
|
|
3773
|
+
})();
|
|
3774
|
+
let sourceRange = rootRange;
|
|
3775
|
+
return hops.map((hop) => {
|
|
3776
|
+
const range = allocator.bind(hop.table, hop.alias);
|
|
3777
|
+
allocator.reserve(range.alias);
|
|
3778
|
+
visibleJoinRanges.push(range);
|
|
3779
|
+
const defaultFilter = join.batchValues ? void 0 : resolveScanDefaultFilter(options.defaultFilters, range, model);
|
|
3780
|
+
const on = resolveConditionContext(
|
|
3781
|
+
join.on,
|
|
3782
|
+
rootRange,
|
|
3783
|
+
[...visibleJoinRanges],
|
|
3784
|
+
[[range]],
|
|
3785
|
+
allocator,
|
|
3786
|
+
model,
|
|
3787
|
+
0,
|
|
3788
|
+
[],
|
|
3789
|
+
{
|
|
3790
|
+
defaultFilters: options.defaultFilters,
|
|
3791
|
+
subqueryRefusal: join.batchValues ? "Subquery in BatchValues JOIN ON condition is not supported." : "Subquery in JOIN ON condition is not supported.",
|
|
3792
|
+
firstJoinByQualifier,
|
|
3793
|
+
intentIndex
|
|
3794
|
+
}
|
|
3795
|
+
);
|
|
3796
|
+
const resolvedJoin = {
|
|
3797
|
+
intentPath: `join[${intentIndex}]`,
|
|
3798
|
+
intentIndex,
|
|
3799
|
+
kind: join.relation !== void 0 ? "relation" : join.batchValues ? "values" : "table",
|
|
3800
|
+
type: join.type,
|
|
3801
|
+
range,
|
|
3802
|
+
sourceRange,
|
|
3803
|
+
...hop.path && { path: hop.path },
|
|
3804
|
+
...on && { on },
|
|
3805
|
+
...defaultFilter && { defaultFilter }
|
|
3806
|
+
};
|
|
3807
|
+
sourceRange = range;
|
|
3808
|
+
return resolvedJoin;
|
|
3809
|
+
});
|
|
3727
3810
|
}
|
|
3728
3811
|
);
|
|
3729
3812
|
const generatedAliases = /* @__PURE__ */ new Map();
|
|
@@ -3991,7 +4074,7 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
3991
4074
|
const expressionSubqueries = [];
|
|
3992
4075
|
const inspected = /* @__PURE__ */ new WeakSet();
|
|
3993
4076
|
const inspect = (value, intentPath) => {
|
|
3994
|
-
if (!value || typeof value !== "object" ||
|
|
4077
|
+
if (!value || typeof value !== "object" || isParamIntent4(value)) return;
|
|
3995
4078
|
if (inspected.has(value)) return;
|
|
3996
4079
|
inspected.add(value);
|
|
3997
4080
|
if (Array.isArray(value)) {
|
|
@@ -4009,7 +4092,7 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
4009
4092
|
);
|
|
4010
4093
|
if (node.kind === "subquery" && node.query) {
|
|
4011
4094
|
const query = node.query;
|
|
4012
|
-
if (!model || !
|
|
4095
|
+
if (!model || !containsRelationalReadPolicy(query) && !findDefaultFilterScan(
|
|
4013
4096
|
query,
|
|
4014
4097
|
model,
|
|
4015
4098
|
options.defaultFilters,
|
|
@@ -4067,8 +4150,7 @@ function resolveReportIncludes(intent, decisions, model, options = {}) {
|
|
|
4067
4150
|
return;
|
|
4068
4151
|
}
|
|
4069
4152
|
for (const [key, child] of Object.entries(node)) {
|
|
4070
|
-
if ((
|
|
4071
|
-
continue;
|
|
4153
|
+
if (isBoundPayload(node, key, child)) continue;
|
|
4072
4154
|
inspect(child, `${intentPath}.${key}`);
|
|
4073
4155
|
}
|
|
4074
4156
|
inspected.delete(value);
|
|
@@ -4539,7 +4621,7 @@ function optimizeInToExists(where, sourceTable, model, negated = false) {
|
|
|
4539
4621
|
const inWhere = where;
|
|
4540
4622
|
if (!inWhere.subquery) return where;
|
|
4541
4623
|
const sq = inWhere.subquery;
|
|
4542
|
-
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") {
|
|
4543
4625
|
return where;
|
|
4544
4626
|
}
|
|
4545
4627
|
const subSelect = inWhere.subquery.select;
|
|
@@ -23616,8 +23698,13 @@ var QueryBuilderImpl = class _QueryBuilderImpl {
|
|
|
23616
23698
|
join(relationOrTableOrBatch, opts) {
|
|
23617
23699
|
const builder = this.clone();
|
|
23618
23700
|
const type = opts?.type ?? "inner";
|
|
23701
|
+
const alias = opts?.as;
|
|
23619
23702
|
if (isBatchValuesRef(relationOrTableOrBatch)) {
|
|
23620
23703
|
const bv = relationOrTableOrBatch;
|
|
23704
|
+
if (alias !== void 0 && typeof alias !== "string")
|
|
23705
|
+
throw new Error(
|
|
23706
|
+
`join('${bv.alias}'): an alias list requires a relation path.`
|
|
23707
|
+
);
|
|
23621
23708
|
if (!opts?.on) {
|
|
23622
23709
|
throw new Error(
|
|
23623
23710
|
"join(batchValuesRef): an `on` condition is required for BatchValues joins"
|
|
@@ -23627,8 +23714,8 @@ var QueryBuilderImpl = class _QueryBuilderImpl {
|
|
|
23627
23714
|
for (const col2 of bv.columns) {
|
|
23628
23715
|
validateIdentifier(col2, "column");
|
|
23629
23716
|
}
|
|
23630
|
-
if (
|
|
23631
|
-
validateIdentifier(
|
|
23717
|
+
if (alias !== void 0) {
|
|
23718
|
+
validateIdentifier(alias, "alias");
|
|
23632
23719
|
}
|
|
23633
23720
|
const joinIntent = {
|
|
23634
23721
|
batchValues: {
|
|
@@ -23640,25 +23727,31 @@ var QueryBuilderImpl = class _QueryBuilderImpl {
|
|
|
23640
23727
|
},
|
|
23641
23728
|
on: opts.on,
|
|
23642
23729
|
type,
|
|
23643
|
-
|
|
23730
|
+
alias: alias ?? bv.alias
|
|
23644
23731
|
};
|
|
23645
23732
|
builder.joinIntents.push(joinIntent);
|
|
23646
|
-
} else {
|
|
23733
|
+
} else if (opts?.on) {
|
|
23647
23734
|
validateIdentifier(relationOrTableOrBatch, "table");
|
|
23648
|
-
if (
|
|
23649
|
-
|
|
23650
|
-
|
|
23651
|
-
|
|
23735
|
+
if (alias !== void 0 && typeof alias !== "string")
|
|
23736
|
+
throw new Error(
|
|
23737
|
+
`join('${relationOrTableOrBatch}'): an alias list requires a relation path.`
|
|
23738
|
+
);
|
|
23739
|
+
if (alias !== void 0) validateIdentifier(alias, "alias");
|
|
23740
|
+
builder.joinIntents.push({
|
|
23652
23741
|
table: relationOrTableOrBatch,
|
|
23653
23742
|
on: opts.on,
|
|
23654
23743
|
type,
|
|
23655
|
-
...
|
|
23656
|
-
}
|
|
23744
|
+
...alias !== void 0 && { alias }
|
|
23745
|
+
});
|
|
23746
|
+
} else {
|
|
23747
|
+
relationJoinHops(relationOrTableOrBatch, alias);
|
|
23748
|
+
builder.joinIntents.push({
|
|
23657
23749
|
relation: relationOrTableOrBatch,
|
|
23658
23750
|
type,
|
|
23659
|
-
...
|
|
23660
|
-
|
|
23661
|
-
|
|
23751
|
+
...alias !== void 0 && {
|
|
23752
|
+
alias: typeof alias === "string" ? alias : Object.freeze([...alias])
|
|
23753
|
+
}
|
|
23754
|
+
});
|
|
23662
23755
|
}
|
|
23663
23756
|
return builder;
|
|
23664
23757
|
}
|
|
@@ -25339,7 +25432,10 @@ function createOrmInstance(model, strictMode, relationHints, adapter, schemaName
|
|
|
25339
25432
|
"selectExpression() requires an adapter. Pass an adapter when creating the ORM."
|
|
25340
25433
|
);
|
|
25341
25434
|
}
|
|
25342
|
-
const compiled = adapter.compileSelectExpression(expr.intent, {
|
|
25435
|
+
const compiled = adapter.compileSelectExpression(expr.intent, {
|
|
25436
|
+
model,
|
|
25437
|
+
...defaultFilters !== void 0 && { defaultFilters }
|
|
25438
|
+
});
|
|
25343
25439
|
return {
|
|
25344
25440
|
sql: compiled.sql,
|
|
25345
25441
|
parameters: compiled.parameters,
|
|
@@ -26822,4 +26918,4 @@ export {
|
|
|
26822
26918
|
runAssertions,
|
|
26823
26919
|
isOverallSuccess
|
|
26824
26920
|
};
|
|
26825
|
-
//# sourceMappingURL=chunk-
|
|
26921
|
+
//# sourceMappingURL=chunk-DUIL3IMF.js.map
|