@ronin/compiler 0.14.13-leo-ron-1099-1-experimental-355 → 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 +6 -6
- package/dist/index.js +17 -19
- 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,15 +105,15 @@ 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' | '
|
116
|
-
|
115
|
+
type AddQuery = Record<string, Omit<CombinedInstructions, 'with' | 'for'> & {
|
116
|
+
to: FieldSelector;
|
117
117
|
}>;
|
118
118
|
type RemoveQuery = Record<string, Omit<CombinedInstructions, 'to'>>;
|
119
119
|
type CountQuery = Record<string, Omit<CombinedInstructions, 'to'> | null>;
|
@@ -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
|
}
|
@@ -550,7 +550,7 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
550
550
|
const query = compileQueryInput(
|
551
551
|
{
|
552
552
|
[subQueryType]: {
|
553
|
-
[associativeModelSlug]: { with: recordDetails }
|
553
|
+
[associativeModelSlug]: subQueryType === "add" ? { to: recordDetails } : { with: recordDetails }
|
554
554
|
}
|
555
555
|
},
|
556
556
|
models,
|
@@ -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 = {};
|
@@ -673,12 +673,10 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
673
673
|
statement += `"${model.table}" `;
|
674
674
|
}
|
675
675
|
if (queryType === "add" || queryType === "set") {
|
676
|
-
|
677
|
-
const instructionValue = instructions[instructionName];
|
678
|
-
if (!(instructionValue && isObject(instructionValue)) || Object.keys(instructionValue).length === 0) {
|
676
|
+
if (!isObject(instructions.to) || Object.keys(instructions.to).length === 0) {
|
679
677
|
throw new RoninError({
|
680
|
-
message: `When using a \`${queryType}\` query, the
|
681
|
-
code:
|
678
|
+
message: `When using a \`${queryType}\` query, the \`to\` instruction must be a non-empty object.`,
|
679
|
+
code: "INVALID_TO_VALUE",
|
682
680
|
queries: [query]
|
683
681
|
});
|
684
682
|
}
|
@@ -688,7 +686,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
688
686
|
statementParams,
|
689
687
|
queryType,
|
690
688
|
dependencyStatements,
|
691
|
-
{ with: instructions.with, to:
|
689
|
+
{ with: instructions.with, to: instructions.to },
|
692
690
|
options?.parentModel
|
693
691
|
);
|
694
692
|
statement += `${toStatement} `;
|
@@ -1721,7 +1719,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
1721
1719
|
if (!Object.hasOwn(entities, entity2)) continue;
|
1722
1720
|
Object.defineProperty(modelWithObjects, entity2, { value: entities[entity2] });
|
1723
1721
|
}
|
1724
|
-
queryTypeDetails = {
|
1722
|
+
queryTypeDetails = { to: modelWithObjects };
|
1725
1723
|
getSystemModels(models, modelWithPresets).map((systemModel) => {
|
1726
1724
|
return handleSystemModel(models, dependencyStatements, "create", systemModel);
|
1727
1725
|
});
|