@ronin/compiler 0.14.13 → 0.14.14-leo-ron-1099-1-experimental-357
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 +7 -7
- package/dist/index.js +19 -17
- 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 UsingInstruction = 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
|
+
using?: UsingInstruction;
|
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' | 'using';
|
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' | 'using'> & {
|
116
|
+
with: 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' | 'using'> & {
|
125
125
|
to: FieldSelector;
|
126
126
|
};
|
127
127
|
type RemoveInstructions = Omit<CombinedInstructions, 'to'>;
|
@@ -132,7 +132,7 @@ type CreateQuery = {
|
|
132
132
|
};
|
133
133
|
type AlterQuery = {
|
134
134
|
model: string;
|
135
|
-
to?: Partial<PublicModel
|
135
|
+
to?: Partial<Omit<PublicModel, 'fields' | 'indexes' | 'triggers' | 'presets' | 'idPrefix'>>;
|
136
136
|
create?: {
|
137
137
|
field?: ModelField;
|
138
138
|
index?: ModelIndex;
|
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 handleUsing = (model, instructions) => {
|
261
|
+
const normalizedFor = Array.isArray(instructions.using) ? Object.fromEntries(instructions.using.map((presetSlug) => [presetSlug, null])) : instructions.using;
|
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 handleFor = (model, instructions) => {
|
|
269
269
|
code: "PRESET_NOT_FOUND"
|
270
270
|
});
|
271
271
|
}
|
272
|
-
const
|
272
|
+
const replacedUsingFilter = structuredClone(preset.instructions);
|
273
273
|
if (arg !== null) {
|
274
274
|
findInObject(
|
275
|
-
|
275
|
+
replacedUsingFilter,
|
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 replacedUsingFilter) {
|
281
|
+
if (!Object.hasOwn(replacedUsingFilter, 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
|
+
...replacedUsingFilter[instructionName],
|
289
289
|
...currentValue
|
290
290
|
];
|
291
291
|
} else if (isObject(currentValue)) {
|
292
292
|
newValue = {
|
293
|
-
...
|
293
|
+
...replacedUsingFilter[instructionName],
|
294
294
|
...currentValue
|
295
295
|
};
|
296
296
|
}
|
@@ -298,7 +298,7 @@ var handleFor = (model, instructions) => {
|
|
298
298
|
continue;
|
299
299
|
}
|
300
300
|
Object.assign(instructions, {
|
301
|
-
[instructionName]:
|
301
|
+
[instructionName]: replacedUsingFilter[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]:
|
553
|
+
[associativeModelSlug]: { 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 && typeof instructions.using !== "undefined") {
|
619
|
+
instructions = handleUsing(model, instructions);
|
620
620
|
}
|
621
621
|
if (queryType === "count") {
|
622
622
|
if (!instructions) instructions = {};
|
@@ -673,10 +673,12 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
673
673
|
statement += `"${model.table}" `;
|
674
674
|
}
|
675
675
|
if (queryType === "add" || queryType === "set") {
|
676
|
-
|
676
|
+
const instructionName = queryType === "add" ? "with" : "to";
|
677
|
+
const instructionValue = instructions[instructionName];
|
678
|
+
if (!(instructionValue && isObject(instructionValue)) || Object.keys(instructionValue).length === 0) {
|
677
679
|
throw new RoninError({
|
678
|
-
message: `When using a \`${queryType}\` query, the \`
|
679
|
-
code: "INVALID_TO_VALUE",
|
680
|
+
message: `When using a \`${queryType}\` query, the \`${instructionName}\` instruction must be a non-empty object.`,
|
681
|
+
code: instructionName === "to" ? "INVALID_TO_VALUE" : "INVALID_WITH_VALUE",
|
680
682
|
queries: [query]
|
681
683
|
});
|
682
684
|
}
|
@@ -686,7 +688,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
686
688
|
statementParams,
|
687
689
|
queryType,
|
688
690
|
dependencyStatements,
|
689
|
-
{ with: instructions.with, to:
|
691
|
+
{ with: instructions.with, to: instructionValue },
|
690
692
|
options?.parentModel
|
691
693
|
);
|
692
694
|
statement += `${toStatement} `;
|
@@ -1719,7 +1721,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
1719
1721
|
if (!Object.hasOwn(entities, entity2)) continue;
|
1720
1722
|
Object.defineProperty(modelWithObjects, entity2, { value: entities[entity2] });
|
1721
1723
|
}
|
1722
|
-
queryTypeDetails = {
|
1724
|
+
queryTypeDetails = { with: modelWithObjects };
|
1723
1725
|
getSystemModels(models, modelWithPresets).map((systemModel) => {
|
1724
1726
|
return handleSystemModel(models, dependencyStatements, "create", systemModel);
|
1725
1727
|
});
|