@ronin/compiler 0.14.14-leo-ron-1099-1-experimental-360 → 0.14.14
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 +1 -1
- package/dist/index.js +51 -65
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -132,7 +132,7 @@ type CreateQuery = {
|
|
132
132
|
};
|
133
133
|
type AlterQuery = {
|
134
134
|
model: string;
|
135
|
-
to?: Partial<
|
135
|
+
to?: Partial<PublicModel>;
|
136
136
|
create?: {
|
137
137
|
field?: ModelField;
|
138
138
|
index?: ModelIndex;
|
package/dist/index.js
CHANGED
@@ -256,6 +256,55 @@ var handleBeforeOrAfter = (model, statementParams, instructions) => {
|
|
256
256
|
return `${clause}(${conditions.join(" OR ")})`;
|
257
257
|
};
|
258
258
|
|
259
|
+
// src/instructions/for.ts
|
260
|
+
var handleUsing = (model, instructions) => {
|
261
|
+
const normalizedFor = Array.isArray(instructions.using) ? Object.fromEntries(instructions.using.map((presetSlug) => [presetSlug, null])) : instructions.using;
|
262
|
+
for (const presetSlug in normalizedFor) {
|
263
|
+
if (!Object.hasOwn(normalizedFor, presetSlug)) continue;
|
264
|
+
const arg = normalizedFor[presetSlug];
|
265
|
+
const preset = model.presets?.find((preset2) => preset2.slug === presetSlug);
|
266
|
+
if (!preset) {
|
267
|
+
throw new RoninError({
|
268
|
+
message: `Preset "${presetSlug}" does not exist in model "${model.name}".`,
|
269
|
+
code: "PRESET_NOT_FOUND"
|
270
|
+
});
|
271
|
+
}
|
272
|
+
const replacedUsingFilter = structuredClone(preset.instructions);
|
273
|
+
if (arg !== null) {
|
274
|
+
findInObject(
|
275
|
+
replacedUsingFilter,
|
276
|
+
QUERY_SYMBOLS.VALUE,
|
277
|
+
(match) => match.replace(QUERY_SYMBOLS.VALUE, arg)
|
278
|
+
);
|
279
|
+
}
|
280
|
+
for (const subInstruction in replacedUsingFilter) {
|
281
|
+
if (!Object.hasOwn(replacedUsingFilter, subInstruction)) continue;
|
282
|
+
const instructionName = subInstruction;
|
283
|
+
const currentValue = instructions[instructionName];
|
284
|
+
if (currentValue) {
|
285
|
+
let newValue;
|
286
|
+
if (Array.isArray(currentValue)) {
|
287
|
+
newValue = [
|
288
|
+
...replacedUsingFilter[instructionName],
|
289
|
+
...currentValue
|
290
|
+
];
|
291
|
+
} else if (isObject(currentValue)) {
|
292
|
+
newValue = {
|
293
|
+
...replacedUsingFilter[instructionName],
|
294
|
+
...currentValue
|
295
|
+
};
|
296
|
+
}
|
297
|
+
Object.assign(instructions, { [instructionName]: newValue });
|
298
|
+
continue;
|
299
|
+
}
|
300
|
+
Object.assign(instructions, {
|
301
|
+
[instructionName]: replacedUsingFilter[instructionName]
|
302
|
+
});
|
303
|
+
}
|
304
|
+
}
|
305
|
+
return instructions;
|
306
|
+
};
|
307
|
+
|
259
308
|
// src/instructions/including.ts
|
260
309
|
var handleIncluding = (models, model, statementParams, single, instruction, options = {}) => {
|
261
310
|
let statement = "";
|
@@ -266,7 +315,6 @@ var handleIncluding = (models, model, statementParams, single, instruction, opti
|
|
266
315
|
if (symbol?.type !== "query") continue;
|
267
316
|
const { queryType, queryModel, queryInstructions } = splitQuery(symbol.value);
|
268
317
|
let modifiableQueryInstructions = queryInstructions;
|
269
|
-
if (queryType === "count") continue;
|
270
318
|
const relatedModel = getModelBySlug(models, queryModel);
|
271
319
|
let joinType = "LEFT";
|
272
320
|
let relatedTableSelector = `"${relatedModel.table}"`;
|
@@ -292,8 +340,7 @@ var handleIncluding = (models, model, statementParams, single, instruction, opti
|
|
292
340
|
}
|
293
341
|
},
|
294
342
|
models,
|
295
|
-
statementParams
|
296
|
-
{ parentModel: model }
|
343
|
+
statementParams
|
297
344
|
);
|
298
345
|
relatedTableSelector = `(${subSelect.main.statement})`;
|
299
346
|
}
|
@@ -391,20 +438,8 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
391
438
|
for (const [key, value] of Object.entries(flatObject)) {
|
392
439
|
const symbol2 = getQuerySymbol(value);
|
393
440
|
if (symbol2?.type === "query") {
|
394
|
-
const {
|
441
|
+
const { queryModel, queryInstructions } = splitQuery(symbol2.value);
|
395
442
|
const subQueryModel = getModelBySlug(models, queryModel);
|
396
|
-
if (queryType === "count") {
|
397
|
-
const subSelect = compileQueryInput(symbol2.value, models, statementParams, {
|
398
|
-
parentModel: { ...model, tableAlias: model.table }
|
399
|
-
});
|
400
|
-
selectedFields.push({
|
401
|
-
slug: key,
|
402
|
-
mountingPath: key,
|
403
|
-
type: "number",
|
404
|
-
mountedValue: `(${subSelect.main.statement})`
|
405
|
-
});
|
406
|
-
continue;
|
407
|
-
}
|
408
443
|
isJoining = true;
|
409
444
|
const subSingle = queryModel !== subQueryModel.pluralSlug;
|
410
445
|
if (!model.tableAlias)
|
@@ -563,55 +598,6 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
563
598
|
return statement;
|
564
599
|
};
|
565
600
|
|
566
|
-
// src/instructions/using.ts
|
567
|
-
var handleUsing = (model, instructions) => {
|
568
|
-
const normalizedUsing = Array.isArray(instructions.using) ? Object.fromEntries(instructions.using.map((presetSlug) => [presetSlug, null])) : instructions.using;
|
569
|
-
for (const presetSlug in normalizedUsing) {
|
570
|
-
if (!Object.hasOwn(normalizedUsing, presetSlug)) continue;
|
571
|
-
const arg = normalizedUsing[presetSlug];
|
572
|
-
const preset = model.presets?.find((preset2) => preset2.slug === presetSlug);
|
573
|
-
if (!preset) {
|
574
|
-
throw new RoninError({
|
575
|
-
message: `Preset "${presetSlug}" does not exist in model "${model.name}".`,
|
576
|
-
code: "PRESET_NOT_FOUND"
|
577
|
-
});
|
578
|
-
}
|
579
|
-
const replacedUsingFilter = structuredClone(preset.instructions);
|
580
|
-
if (arg !== null) {
|
581
|
-
findInObject(
|
582
|
-
replacedUsingFilter,
|
583
|
-
QUERY_SYMBOLS.VALUE,
|
584
|
-
(match) => match.replace(QUERY_SYMBOLS.VALUE, arg)
|
585
|
-
);
|
586
|
-
}
|
587
|
-
for (const subInstruction in replacedUsingFilter) {
|
588
|
-
if (!Object.hasOwn(replacedUsingFilter, subInstruction)) continue;
|
589
|
-
const instructionName = subInstruction;
|
590
|
-
const currentValue = instructions[instructionName];
|
591
|
-
if (currentValue) {
|
592
|
-
let newValue;
|
593
|
-
if (Array.isArray(currentValue)) {
|
594
|
-
newValue = [
|
595
|
-
...replacedUsingFilter[instructionName],
|
596
|
-
...currentValue
|
597
|
-
];
|
598
|
-
} else if (isObject(currentValue)) {
|
599
|
-
newValue = {
|
600
|
-
...replacedUsingFilter[instructionName],
|
601
|
-
...currentValue
|
602
|
-
};
|
603
|
-
}
|
604
|
-
Object.assign(instructions, { [instructionName]: newValue });
|
605
|
-
continue;
|
606
|
-
}
|
607
|
-
Object.assign(instructions, {
|
608
|
-
[instructionName]: replacedUsingFilter[instructionName]
|
609
|
-
});
|
610
|
-
}
|
611
|
-
}
|
612
|
-
return instructions;
|
613
|
-
};
|
614
|
-
|
615
601
|
// src/utils/index.ts
|
616
602
|
var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
617
603
|
const dependencyStatements = [];
|