@ronin/compiler 0.14.13-leo-ron-1099-1-experimental-354 → 0.14.13
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/index.d.ts +5 -5
- package/dist/index.js +11 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -95,7 +95,7 @@ type OrderedByInstruction = {
|
|
95
95
|
ascending?: Array<string | Expression>;
|
96
96
|
descending?: Array<string | Expression>;
|
97
97
|
};
|
98
|
-
type
|
98
|
+
type ForInstruction = Array<string> | Record<string, string>;
|
99
99
|
type CombinedInstructions = {
|
100
100
|
with?: WithInstruction | Array<WithInstruction>;
|
101
101
|
to?: FieldSelector;
|
@@ -105,14 +105,14 @@ type CombinedInstructions = {
|
|
105
105
|
before?: string | null;
|
106
106
|
after?: string | null;
|
107
107
|
limitedTo?: number;
|
108
|
-
|
108
|
+
for?: ForInstruction;
|
109
109
|
};
|
110
|
-
type InstructionSchema = 'with' | 'to' | 'including' | 'selecting' | 'orderedBy' | 'orderedBy.ascending' | 'orderedBy.descending' | 'before' | 'after' | 'limitedTo' | '
|
110
|
+
type InstructionSchema = 'with' | 'to' | 'including' | 'selecting' | 'orderedBy' | 'orderedBy.ascending' | 'orderedBy.descending' | 'before' | 'after' | 'limitedTo' | 'for';
|
111
111
|
type GetQuery = Record<string, Omit<CombinedInstructions, 'to'> | null>;
|
112
112
|
type SetQuery = Record<string, Omit<CombinedInstructions, 'to'> & {
|
113
113
|
to: FieldSelector;
|
114
114
|
}>;
|
115
|
-
type AddQuery = Record<string, Omit<CombinedInstructions, 'with' | '
|
115
|
+
type AddQuery = Record<string, Omit<CombinedInstructions, 'with' | 'for'> & {
|
116
116
|
to: FieldSelector;
|
117
117
|
}>;
|
118
118
|
type RemoveQuery = Record<string, Omit<CombinedInstructions, 'to'>>;
|
@@ -121,7 +121,7 @@ type GetInstructions = Omit<CombinedInstructions, 'to'>;
|
|
121
121
|
type SetInstructions = Omit<CombinedInstructions, 'to'> & {
|
122
122
|
to: FieldSelector;
|
123
123
|
};
|
124
|
-
type AddInstructions = Omit<CombinedInstructions, 'with' | '
|
124
|
+
type AddInstructions = Omit<CombinedInstructions, 'with' | 'for'> & {
|
125
125
|
to: FieldSelector;
|
126
126
|
};
|
127
127
|
type RemoveInstructions = Omit<CombinedInstructions, 'to'>;
|
package/dist/index.js
CHANGED
@@ -257,8 +257,8 @@ var handleBeforeOrAfter = (model, statementParams, instructions) => {
|
|
257
257
|
};
|
258
258
|
|
259
259
|
// src/instructions/for.ts
|
260
|
-
var
|
261
|
-
const normalizedFor = Array.isArray(instructions.
|
260
|
+
var handleFor = (model, instructions) => {
|
261
|
+
const normalizedFor = Array.isArray(instructions.for) ? Object.fromEntries(instructions.for.map((presetSlug) => [presetSlug, null])) : instructions.for;
|
262
262
|
for (const presetSlug in normalizedFor) {
|
263
263
|
if (!Object.hasOwn(normalizedFor, presetSlug)) continue;
|
264
264
|
const arg = normalizedFor[presetSlug];
|
@@ -269,28 +269,28 @@ var handleUsing = (model, instructions) => {
|
|
269
269
|
code: "PRESET_NOT_FOUND"
|
270
270
|
});
|
271
271
|
}
|
272
|
-
const
|
272
|
+
const replacedForFilter = structuredClone(preset.instructions);
|
273
273
|
if (arg !== null) {
|
274
274
|
findInObject(
|
275
|
-
|
275
|
+
replacedForFilter,
|
276
276
|
QUERY_SYMBOLS.VALUE,
|
277
277
|
(match) => match.replace(QUERY_SYMBOLS.VALUE, arg)
|
278
278
|
);
|
279
279
|
}
|
280
|
-
for (const subInstruction in
|
281
|
-
if (!Object.hasOwn(
|
280
|
+
for (const subInstruction in replacedForFilter) {
|
281
|
+
if (!Object.hasOwn(replacedForFilter, subInstruction)) continue;
|
282
282
|
const instructionName = subInstruction;
|
283
283
|
const currentValue = instructions[instructionName];
|
284
284
|
if (currentValue) {
|
285
285
|
let newValue;
|
286
286
|
if (Array.isArray(currentValue)) {
|
287
287
|
newValue = [
|
288
|
-
...
|
288
|
+
...replacedForFilter[instructionName],
|
289
289
|
...currentValue
|
290
290
|
];
|
291
291
|
} else if (isObject(currentValue)) {
|
292
292
|
newValue = {
|
293
|
-
...
|
293
|
+
...replacedForFilter[instructionName],
|
294
294
|
...currentValue
|
295
295
|
};
|
296
296
|
}
|
@@ -298,7 +298,7 @@ var handleUsing = (model, instructions) => {
|
|
298
298
|
continue;
|
299
299
|
}
|
300
300
|
Object.assign(instructions, {
|
301
|
-
[instructionName]:
|
301
|
+
[instructionName]: replacedForFilter[instructionName]
|
302
302
|
});
|
303
303
|
}
|
304
304
|
}
|
@@ -615,8 +615,8 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
615
615
|
const single = queryModel !== model.pluralSlug;
|
616
616
|
let instructions = formatIdentifiers(model, queryInstructions);
|
617
617
|
const returning = options?.returning ?? true;
|
618
|
-
if (instructions &&
|
619
|
-
instructions =
|
618
|
+
if (instructions && Object.hasOwn(instructions, "for")) {
|
619
|
+
instructions = handleFor(model, instructions);
|
620
620
|
}
|
621
621
|
if (queryType === "count") {
|
622
622
|
if (!instructions) instructions = {};
|