@ronin/compiler 0.14.14-leo-ron-1099-1-experimental-357 → 0.14.14-leo-ron-1099-1-experimental-359

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.
Files changed (2) hide show
  1. package/dist/index.js +65 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -256,55 +256,6 @@ 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
-
308
259
  // src/instructions/including.ts
309
260
  var handleIncluding = (models, model, statementParams, single, instruction, options = {}) => {
310
261
  let statement = "";
@@ -315,6 +266,7 @@ var handleIncluding = (models, model, statementParams, single, instruction, opti
315
266
  if (symbol?.type !== "query") continue;
316
267
  const { queryType, queryModel, queryInstructions } = splitQuery(symbol.value);
317
268
  let modifiableQueryInstructions = queryInstructions;
269
+ if (queryType === "count") continue;
318
270
  const relatedModel = getModelBySlug(models, queryModel);
319
271
  let joinType = "LEFT";
320
272
  let relatedTableSelector = `"${relatedModel.table}"`;
@@ -340,7 +292,8 @@ var handleIncluding = (models, model, statementParams, single, instruction, opti
340
292
  }
341
293
  },
342
294
  models,
343
- statementParams
295
+ statementParams,
296
+ { parentModel: model }
344
297
  );
345
298
  relatedTableSelector = `(${subSelect.main.statement})`;
346
299
  }
@@ -438,8 +391,20 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
438
391
  for (const [key, value] of Object.entries(flatObject)) {
439
392
  const symbol2 = getQuerySymbol(value);
440
393
  if (symbol2?.type === "query") {
441
- const { queryModel, queryInstructions } = splitQuery(symbol2.value);
394
+ const { queryType, queryModel, queryInstructions } = splitQuery(symbol2.value);
442
395
  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
+ }
443
408
  isJoining = true;
444
409
  const subSingle = queryModel !== subQueryModel.pluralSlug;
445
410
  if (!model.tableAlias)
@@ -598,6 +563,55 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
598
563
  return statement;
599
564
  };
600
565
 
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
+
601
615
  // src/utils/index.ts
602
616
  var compileQueryInput = (defaultQuery, models, statementParams, options) => {
603
617
  const dependencyStatements = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.14-leo-ron-1099-1-experimental-357",
3
+ "version": "0.14.14-leo-ron-1099-1-experimental-359",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {