@atscript/db 0.1.146 → 0.1.147
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/agg.cjs +1 -1
- package/dist/agg.d.cts +1 -1
- package/dist/agg.d.mts +1 -1
- package/dist/agg.mjs +1 -1
- package/dist/{aggregate-fns-CfsveE1w.mjs → aggregate-fns-C0BymEqa.mjs} +3 -1
- package/dist/{aggregate-fns-CGBv3E8S.cjs → aggregate-fns-CtsRbZn9.cjs} +8 -0
- package/dist/{buckets-DYFu0eZ8.d.cts → buckets-CjdPipCC.d.cts} +522 -17
- package/dist/{buckets-DRycmhOW.d.mts → buckets-DYopfd2Y.d.mts} +522 -17
- package/dist/{column-diff-e2oHc71_.mjs → column-diff-CO06iQvI.mjs} +862 -115
- package/dist/{column-diff-D_Kyuh0S.cjs → column-diff-Dt7EDJsA.cjs} +872 -113
- package/dist/{column-diff-Q9UmWn5x.d.mts → fk-diff-BtOmL4OW.d.mts} +48 -2
- package/dist/{column-diff-w-Mym_3w.d.cts → fk-diff-DLqwVkKG.d.cts} +48 -2
- package/dist/index.cjs +28 -33
- package/dist/index.d.cts +40 -15
- package/dist/index.d.mts +40 -15
- package/dist/index.mjs +5 -33
- package/dist/{nested-writer-CnOOAehr.mjs → nested-writer-D35UsDBT.mjs} +542 -2
- package/dist/{nested-writer-xfQwxplL.cjs → nested-writer-SqtYJHF0.cjs} +666 -0
- package/dist/plugin.cjs +266 -5
- package/dist/plugin.mjs +267 -6
- package/dist/rel.cjs +2 -2
- package/dist/rel.d.cts +2 -2
- package/dist/rel.d.mts +2 -2
- package/dist/rel.mjs +2 -2
- package/dist/{relation-helpers-B-0NRKat.d.mts → relation-helpers-C2bLtE-t.d.mts} +1 -1
- package/dist/{relation-helpers-BOMm_HUI.d.cts → relation-helpers-DH3LvwLV.d.cts} +1 -1
- package/dist/relation-loader-BFhVuJ-B.cjs +369 -0
- package/dist/relation-loader-C0qE8xgR.mjs +370 -0
- package/dist/shared.cjs +1 -1
- package/dist/shared.d.cts +4 -3
- package/dist/shared.d.mts +4 -3
- package/dist/shared.mjs +1 -1
- package/dist/sync.cjs +10 -6
- package/dist/sync.d.cts +2 -25
- package/dist/sync.d.mts +2 -25
- package/dist/sync.mjs +10 -6
- package/dist/{validation-utils-DOsB4e6G.cjs → validation-utils-Da2GjobR.cjs} +35 -24
- package/dist/{validation-utils-CMR4fe2M.mjs → validation-utils-Dq0uZ7ef.mjs} +35 -24
- package/dist/{validator-Bw6ks9Hy.d.mts → validator-CMnTI6r7.d.cts} +9 -6
- package/dist/{validator-Bw6ks9Hy.d.cts → validator-CMnTI6r7.d.mts} +9 -6
- package/dist/validator.d.cts +1 -1
- package/dist/validator.d.mts +1 -1
- package/package.json +8 -8
- package/dist/relation-loader-CBPY6kM7.cjs +0 -461
- package/dist/relation-loader-D9XuXaMv.mjs +0 -462
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
const require_nested_writer = require("./nested-writer-SqtYJHF0.cjs");
|
|
2
|
+
//#region src/rel/relation-loader.ts
|
|
3
|
+
var relation_loader_exports = /* @__PURE__ */ require("./plugin.cjs").__exportAll({
|
|
4
|
+
ensureSelectIncludesFields: () => ensureSelectIncludesFields,
|
|
5
|
+
loadRelationsImpl: () => loadRelationsImpl
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Loads related data for `$with` relations and attaches them to result rows.
|
|
9
|
+
*/
|
|
10
|
+
async function loadRelationsImpl(rows, withRelations, host) {
|
|
11
|
+
if (rows.length === 0 || withRelations.length === 0) return;
|
|
12
|
+
if (host.adapter.supportsNativeRelations()) return host.adapter.loadRelations(rows, withRelations, host._meta.relations, host._meta.foreignKeys, host._tableResolver);
|
|
13
|
+
if (!host._tableResolver) return;
|
|
14
|
+
const tasks = [];
|
|
15
|
+
for (const withRel of withRelations) {
|
|
16
|
+
const relName = withRel.name;
|
|
17
|
+
if (relName.includes(".")) continue;
|
|
18
|
+
const relation = host._meta.relations.get(relName);
|
|
19
|
+
if (!relation) throw new Error(`Unknown relation "${relName}" in $with. Available relations: ${[...host._meta.relations.keys()].join(", ") || "(none)"}`);
|
|
20
|
+
const targetType = relation.targetType();
|
|
21
|
+
if (!targetType) continue;
|
|
22
|
+
const targetTable = host._tableResolver(targetType);
|
|
23
|
+
if (!targetTable) {
|
|
24
|
+
host.logger.warn(`Could not resolve table for relation "${relName}" — skipping`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const statics = require_nested_writer.relationStaticFilter(relation, relName);
|
|
28
|
+
const merged = require_nested_writer.andFilters(statics.target, withRel.filter);
|
|
29
|
+
const filter = Object.keys(merged).length > 0 ? merged : void 0;
|
|
30
|
+
const flatRel = withRel;
|
|
31
|
+
const controls = { ...withRel.controls || {} };
|
|
32
|
+
if (flatRel.$sort && !controls.$sort) controls.$sort = flatRel.$sort;
|
|
33
|
+
if (flatRel.$limit !== null && flatRel.$limit !== void 0 && (controls.$limit === null || controls.$limit === void 0)) controls.$limit = flatRel.$limit;
|
|
34
|
+
if (flatRel.$skip !== null && flatRel.$skip !== void 0 && (controls.$skip === null || controls.$skip === void 0)) controls.$skip = flatRel.$skip;
|
|
35
|
+
if (flatRel.$select && !controls.$select) controls.$select = flatRel.$select;
|
|
36
|
+
if (flatRel.$with && !controls.$with) controls.$with = flatRel.$with;
|
|
37
|
+
const { $skip, $limit, ...pageless } = controls;
|
|
38
|
+
const skip = asCount($skip) || void 0;
|
|
39
|
+
const limit = asCount($limit);
|
|
40
|
+
const relQuery = {
|
|
41
|
+
filter,
|
|
42
|
+
controls: pageless,
|
|
43
|
+
page: skip === void 0 && limit === void 0 ? void 0 : {
|
|
44
|
+
skip,
|
|
45
|
+
limit
|
|
46
|
+
},
|
|
47
|
+
junctionFilter: statics.junction
|
|
48
|
+
};
|
|
49
|
+
if (relation.direction === "to") tasks.push(loadToRelation(rows, {
|
|
50
|
+
relName,
|
|
51
|
+
relation,
|
|
52
|
+
targetTable,
|
|
53
|
+
relQuery
|
|
54
|
+
}, host));
|
|
55
|
+
else if (relation.direction === "via") tasks.push(loadViaRelation(rows, {
|
|
56
|
+
relName,
|
|
57
|
+
relation,
|
|
58
|
+
targetTable,
|
|
59
|
+
relQuery
|
|
60
|
+
}, host));
|
|
61
|
+
else tasks.push(loadFromRelation(rows, {
|
|
62
|
+
relName,
|
|
63
|
+
relation,
|
|
64
|
+
targetTable,
|
|
65
|
+
relQuery
|
|
66
|
+
}, host));
|
|
67
|
+
}
|
|
68
|
+
await Promise.all(tasks);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Loads a `@db.rel.to` relation (FK is on this table). Single-valued: the
|
|
72
|
+
* relation's `$skip` / `$limit` page each row's (at most one) target row.
|
|
73
|
+
*/
|
|
74
|
+
async function loadToRelation(rows, opts, host) {
|
|
75
|
+
const { relName, relation, targetTable, relQuery } = opts;
|
|
76
|
+
const fkEntry = require_nested_writer.findFKForRelation(relation, host._meta.foreignKeys);
|
|
77
|
+
if (!fkEntry) return;
|
|
78
|
+
const { localFields, targetFields } = fkEntry;
|
|
79
|
+
const index = indexFirst(await readRelatedByKeys(rows, {
|
|
80
|
+
localFields,
|
|
81
|
+
targetFields,
|
|
82
|
+
targetTable,
|
|
83
|
+
relQuery
|
|
84
|
+
}), targetFields);
|
|
85
|
+
for (const row of rows) row[relName] = index.get(require_nested_writer.compositeKey(localFields, row)) ?? null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Loads a `@db.rel.from` relation (FK is on the target table). `$sort`,
|
|
89
|
+
* `$skip` and `$limit` apply to the related rows of each row.
|
|
90
|
+
*/
|
|
91
|
+
async function loadFromRelation(rows, opts, host) {
|
|
92
|
+
const { relName, relation, targetTable, relQuery } = opts;
|
|
93
|
+
const remoteFK = require_nested_writer.findRemoteFK(targetTable, host.tableName, relation.alias);
|
|
94
|
+
if (!remoteFK) {
|
|
95
|
+
host.logger.warn(`Could not find FK on target table for relation "${relName}"`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const localFields = remoteFK.targetFields;
|
|
99
|
+
const remoteFields = remoteFK.fields;
|
|
100
|
+
const related = await readRelatedByKeys(rows, {
|
|
101
|
+
localFields,
|
|
102
|
+
targetFields: remoteFields,
|
|
103
|
+
targetTable,
|
|
104
|
+
relQuery
|
|
105
|
+
});
|
|
106
|
+
if (relation.isArray) {
|
|
107
|
+
const groups = groupBy(related, (item) => require_nested_writer.compositeKey(remoteFields, item));
|
|
108
|
+
for (const row of rows) row[relName] = groups.get(require_nested_writer.compositeKey(localFields, row)) ?? [];
|
|
109
|
+
} else {
|
|
110
|
+
const index = indexFirst(related, remoteFields);
|
|
111
|
+
for (const row of rows) row[relName] = index.get(require_nested_writer.compositeKey(localFields, row)) ?? null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Loads a `@db.rel.via` relation (M:N through a junction table). The target
|
|
116
|
+
* rows are read once for all rows; `$sort` orders, and `$skip` / `$limit`
|
|
117
|
+
* page, the target rows of each row.
|
|
118
|
+
*/
|
|
119
|
+
async function loadViaRelation(rows, opts, host) {
|
|
120
|
+
const { relName, relation, targetTable, relQuery } = opts;
|
|
121
|
+
if (!relation.viaType || !host._tableResolver) return;
|
|
122
|
+
const junctionType = relation.viaType();
|
|
123
|
+
if (!junctionType) return;
|
|
124
|
+
const junctionTable = host._tableResolver(junctionType);
|
|
125
|
+
if (!junctionTable) {
|
|
126
|
+
host.logger.warn(`Could not resolve junction table for via relation "${relName}"`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const fkToThis = require_nested_writer.findRemoteFK(junctionTable, host.tableName);
|
|
130
|
+
if (!fkToThis) {
|
|
131
|
+
host.logger.warn(`Could not find FK on junction table pointing to "${host.tableName}" for via relation "${relName}"`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const targetTableName = require_nested_writer.resolveRelationTargetTable(relation);
|
|
135
|
+
const fkToTarget = require_nested_writer.findRemoteFK(junctionTable, targetTableName);
|
|
136
|
+
if (!fkToTarget) {
|
|
137
|
+
host.logger.warn(`Could not find FK on junction table pointing to target "${targetTableName}" for via relation "${relName}"`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const localPKFields = fkToThis.targetFields;
|
|
141
|
+
const fields = {
|
|
142
|
+
junctionLocalFields: fkToThis.fields,
|
|
143
|
+
junctionTargetFields: fkToTarget.fields,
|
|
144
|
+
targetPKFields: fkToTarget.targetFields
|
|
145
|
+
};
|
|
146
|
+
const parentFilter = matchAnyFilter(rows, localPKFields, fields.junctionLocalFields);
|
|
147
|
+
const junctionRows = parentFilter ? await junctionTable.findMany({
|
|
148
|
+
filter: require_nested_writer.andFilters(parentFilter, relQuery.junctionFilter),
|
|
149
|
+
controls: { $select: [...fields.junctionLocalFields, ...fields.junctionTargetFields] }
|
|
150
|
+
}) : [];
|
|
151
|
+
const targetFilter = matchAnyFilter(junctionRows, fields.junctionTargetFields, fields.targetPKFields);
|
|
152
|
+
if (!targetFilter) {
|
|
153
|
+
for (const row of rows) row[relName] = relation.isArray ? [] : null;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const sorted = hasSort(relQuery.controls);
|
|
157
|
+
let groups = /* @__PURE__ */ new Map();
|
|
158
|
+
const pick = (targets) => {
|
|
159
|
+
groups = groupViaTargets(targets, junctionRows, fields, sorted);
|
|
160
|
+
const page = relQuery.page;
|
|
161
|
+
if (!page) return targets;
|
|
162
|
+
const start = page.skip ?? 0;
|
|
163
|
+
const end = page.limit === void 0 ? void 0 : start + page.limit;
|
|
164
|
+
const kept = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const [key, group] of groups) {
|
|
166
|
+
const slice = group.slice(start, end);
|
|
167
|
+
groups.set(key, slice);
|
|
168
|
+
for (const target of slice) kept.add(target);
|
|
169
|
+
}
|
|
170
|
+
return targets.filter((target) => kept.has(target));
|
|
171
|
+
};
|
|
172
|
+
await readRelated(targetTable, {
|
|
173
|
+
filter: relQuery.filter ? { $and: [targetFilter, relQuery.filter] } : targetFilter,
|
|
174
|
+
controls: ensureSelectIncludesFields(relQuery.controls, fields.targetPKFields)
|
|
175
|
+
}, { pick });
|
|
176
|
+
for (const row of rows) {
|
|
177
|
+
const group = groups.get(require_nested_writer.compositeKey(localPKFields, row));
|
|
178
|
+
row[relName] = relation.isArray ? group ?? [] : group?.[0] ?? null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Each row's targets (keyed by the junction's local key), once per junction
|
|
183
|
+
* row. The junction rows only map rows to targets: with a `$sort` the targets
|
|
184
|
+
* keep the order the target read returned them in, else junction order.
|
|
185
|
+
*/
|
|
186
|
+
function groupViaTargets(targets, junctionRows, fields, sorted) {
|
|
187
|
+
const groups = /* @__PURE__ */ new Map();
|
|
188
|
+
if (sorted) {
|
|
189
|
+
const linksByTarget = groupBy(junctionRows, (jRow) => require_nested_writer.compositeKey(fields.junctionTargetFields, jRow));
|
|
190
|
+
for (const target of targets) for (const jRow of linksByTarget.get(require_nested_writer.compositeKey(fields.targetPKFields, target)) ?? []) appendTo(groups, require_nested_writer.compositeKey(fields.junctionLocalFields, jRow), target);
|
|
191
|
+
} else {
|
|
192
|
+
const index = indexFirst(targets, fields.targetPKFields);
|
|
193
|
+
for (const jRow of junctionRows) {
|
|
194
|
+
const target = index.get(require_nested_writer.compositeKey(fields.junctionTargetFields, jRow));
|
|
195
|
+
if (target) appendTo(groups, require_nested_writer.compositeKey(fields.junctionLocalFields, jRow), target);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return groups;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Reads the target rows whose `targetFields` match `localFields` of any of
|
|
202
|
+
* `rows`, the relation's `$skip` / `$limit` applied per such row.
|
|
203
|
+
*/
|
|
204
|
+
async function readRelatedByKeys(rows, opts) {
|
|
205
|
+
const { localFields, targetFields, targetTable, relQuery } = opts;
|
|
206
|
+
const keyFilter = matchAnyFilter(rows, localFields, targetFields);
|
|
207
|
+
if (!keyFilter) return [];
|
|
208
|
+
return readRelated(targetTable, {
|
|
209
|
+
filter: relQuery.filter ? { $and: [keyFilter, relQuery.filter] } : keyFilter,
|
|
210
|
+
controls: ensureSelectIncludesFields(relQuery.controls, targetFields)
|
|
211
|
+
}, {
|
|
212
|
+
partitionBy: targetFields,
|
|
213
|
+
page: relQuery.page
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Reads related rows. With `partitionBy` and a `page`, the page applies per
|
|
218
|
+
* group of rows sharing the `partitionBy` values; `pick` keeps a subset of
|
|
219
|
+
* the rows before their own (nested) `$with` relations load.
|
|
220
|
+
*/
|
|
221
|
+
async function readRelated(table, query, opts) {
|
|
222
|
+
const { partitionBy, page, pick } = opts;
|
|
223
|
+
const partitioned = partitionBy && page;
|
|
224
|
+
if (table._findManyForRelation) {
|
|
225
|
+
const controls = partitioned ? {
|
|
226
|
+
...query.controls,
|
|
227
|
+
...pageControls(page)
|
|
228
|
+
} : query.controls;
|
|
229
|
+
return table._findManyForRelation({
|
|
230
|
+
filter: query.filter,
|
|
231
|
+
controls
|
|
232
|
+
}, {
|
|
233
|
+
partitionBy: partitioned ? partitionBy : void 0,
|
|
234
|
+
pick
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
let rows = await table.findMany(query);
|
|
238
|
+
if (partitioned) rows = require_nested_writer.slicePerGroup(rows, (row) => require_nested_writer.compositeKey(partitionBy, row), page);
|
|
239
|
+
return pick ? pick(rows) : rows;
|
|
240
|
+
}
|
|
241
|
+
/** A `$skip` / `$limit` value as a number (`undefined` when unset or not a number). */
|
|
242
|
+
function asCount(value) {
|
|
243
|
+
if (value === null || value === void 0 || value === "") return;
|
|
244
|
+
const n = Number(value);
|
|
245
|
+
return Number.isFinite(n) ? n : void 0;
|
|
246
|
+
}
|
|
247
|
+
/** `$skip` / `$limit` controls of a page (only the ones set). */
|
|
248
|
+
function pageControls(page) {
|
|
249
|
+
const controls = {};
|
|
250
|
+
if (page.skip !== void 0) controls.$skip = page.skip;
|
|
251
|
+
if (page.limit !== void 0) controls.$limit = page.limit;
|
|
252
|
+
return controls;
|
|
253
|
+
}
|
|
254
|
+
/** Whether `controls` carry a non-empty `$sort`. */
|
|
255
|
+
function hasSort(controls) {
|
|
256
|
+
const sort = controls.$sort;
|
|
257
|
+
return !!sort && typeof sort === "object" && Object.keys(sort).length > 0;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* A filter matching the rows whose `toFields` equal `fromFields` of any of
|
|
261
|
+
* `rows` — `$in` for a single field, `$or` of conditions for a composite key.
|
|
262
|
+
* `undefined` when no row has every `fromFields` value.
|
|
263
|
+
*/
|
|
264
|
+
function matchAnyFilter(rows, fromFields, toFields) {
|
|
265
|
+
if (fromFields.length === 1) {
|
|
266
|
+
const values = /* @__PURE__ */ new Set();
|
|
267
|
+
for (const row of rows) {
|
|
268
|
+
const v = row[fromFields[0]];
|
|
269
|
+
if (v !== null && v !== void 0) values.add(v);
|
|
270
|
+
}
|
|
271
|
+
return values.size > 0 ? { [toFields[0]]: { $in: [...values] } } : void 0;
|
|
272
|
+
}
|
|
273
|
+
const seen = /* @__PURE__ */ new Set();
|
|
274
|
+
const conditions = [];
|
|
275
|
+
for (const row of rows) {
|
|
276
|
+
const key = require_nested_writer.compositeKey(fromFields, row);
|
|
277
|
+
if (seen.has(key)) continue;
|
|
278
|
+
seen.add(key);
|
|
279
|
+
const condition = {};
|
|
280
|
+
let valid = true;
|
|
281
|
+
for (let i = 0; i < fromFields.length; i++) {
|
|
282
|
+
const v = row[fromFields[i]];
|
|
283
|
+
if (v === null || v === void 0) {
|
|
284
|
+
valid = false;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
condition[toFields[i]] = v;
|
|
288
|
+
}
|
|
289
|
+
if (valid) conditions.push(condition);
|
|
290
|
+
}
|
|
291
|
+
if (conditions.length === 0) return;
|
|
292
|
+
return conditions.length === 1 ? conditions[0] : { $or: conditions };
|
|
293
|
+
}
|
|
294
|
+
/** The first of `items` per `fields` key. */
|
|
295
|
+
function indexFirst(items, fields) {
|
|
296
|
+
const index = /* @__PURE__ */ new Map();
|
|
297
|
+
for (const item of items) {
|
|
298
|
+
const key = require_nested_writer.compositeKey(fields, item);
|
|
299
|
+
if (!index.has(key)) index.set(key, item);
|
|
300
|
+
}
|
|
301
|
+
return index;
|
|
302
|
+
}
|
|
303
|
+
/** `items` grouped by `keyOf`, each group in the order of `items`. */
|
|
304
|
+
function groupBy(items, keyOf) {
|
|
305
|
+
const groups = /* @__PURE__ */ new Map();
|
|
306
|
+
for (const item of items) appendTo(groups, keyOf(item), item);
|
|
307
|
+
return groups;
|
|
308
|
+
}
|
|
309
|
+
function appendTo(groups, key, item) {
|
|
310
|
+
const group = groups.get(key);
|
|
311
|
+
if (group) group.push(item);
|
|
312
|
+
else groups.set(key, [item]);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Ensure the given join fields survive the user's $select on a $with relation
|
|
316
|
+
* read. Without this, the JS-side join would key off undefined and silently
|
|
317
|
+
* return empty relations.
|
|
318
|
+
*
|
|
319
|
+
* - Array $select: append missing FK fields.
|
|
320
|
+
* - Include-mode object $select (any value is 1/true, or empty object): set
|
|
321
|
+
* missing FK fields to 1.
|
|
322
|
+
* - Exclude-mode object $select: leave alone — FK survives by default. If the
|
|
323
|
+
* FK is explicitly excluded, throw rather than silently override user intent.
|
|
324
|
+
*/
|
|
325
|
+
function ensureSelectIncludesFields(controls, fields) {
|
|
326
|
+
if (!controls) return controls;
|
|
327
|
+
const sel = controls.$select;
|
|
328
|
+
if (sel === void 0 || sel === null) return controls;
|
|
329
|
+
if (Array.isArray(sel)) {
|
|
330
|
+
const augmented = [...sel];
|
|
331
|
+
for (const f of fields) if (!augmented.includes(f)) augmented.push(f);
|
|
332
|
+
return {
|
|
333
|
+
...controls,
|
|
334
|
+
$select: augmented
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (typeof sel === "object") {
|
|
338
|
+
const selObj = sel;
|
|
339
|
+
const isInclude = Object.keys(selObj).length === 0 || Object.values(selObj).some((v) => v === 1 || v === true);
|
|
340
|
+
const augmented = { ...selObj };
|
|
341
|
+
let mutated = false;
|
|
342
|
+
for (const f of fields) {
|
|
343
|
+
const v = augmented[f];
|
|
344
|
+
if (v === 0 || v === false) throw new Error(`Cannot exclude join column "${f}" from $select on $with relation`);
|
|
345
|
+
if (v === void 0 && isInclude) {
|
|
346
|
+
augmented[f] = 1;
|
|
347
|
+
mutated = true;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return mutated ? {
|
|
351
|
+
...controls,
|
|
352
|
+
$select: augmented
|
|
353
|
+
} : controls;
|
|
354
|
+
}
|
|
355
|
+
return controls;
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
Object.defineProperty(exports, "loadRelationsImpl", {
|
|
359
|
+
enumerable: true,
|
|
360
|
+
get: function() {
|
|
361
|
+
return loadRelationsImpl;
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
Object.defineProperty(exports, "relation_loader_exports", {
|
|
365
|
+
enumerable: true,
|
|
366
|
+
get: function() {
|
|
367
|
+
return relation_loader_exports;
|
|
368
|
+
}
|
|
369
|
+
});
|