@ronin/compiler 0.14.14-leo-ron-1099-1-experimental-361 → 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 CHANGED
@@ -132,7 +132,7 @@ type CreateQuery = {
132
132
  };
133
133
  type AlterQuery = {
134
134
  model: string;
135
- to?: Partial<Omit<PublicModel, 'fields' | 'indexes' | 'triggers' | 'presets' | 'idPrefix'>>;
135
+ to?: Partial<PublicModel>;
136
136
  create?: {
137
137
  field?: ModelField;
138
138
  index?: ModelIndex;
@@ -245,7 +245,7 @@ type ModelField = ModelFieldBasics & ({
245
245
  /** The target model of the relationship that is being established. */
246
246
  target: string;
247
247
  /** Whether the field should be related to one record, or many records. */
248
- kind?: 'one';
248
+ kind?: 'one' | 'many';
249
249
  /**
250
250
  * If the target record is updated or deleted, the defined actions maybe executed.
251
251
  */
@@ -253,13 +253,6 @@ type ModelField = ModelFieldBasics & ({
253
253
  onDelete?: ModelFieldLinkAction;
254
254
  onUpdate?: ModelFieldLinkAction;
255
255
  };
256
- } | {
257
- /** The kind of value that should be stored inside the field. */
258
- type: 'link';
259
- /** The target model of the relationship that is being established. */
260
- target: string;
261
- /** Whether the field should be related to one record, or many records. */
262
- kind: 'many';
263
256
  });
264
257
  type ModelIndexField<T extends Array<ModelField> = Array<ModelField>> = {
265
258
  /** The collating sequence used for text placed inside the field. */
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 { queryType, queryModel, queryInstructions } = splitQuery(symbol2.value);
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 = [];
@@ -1528,20 +1514,12 @@ var getSystemModels = (models, model) => {
1528
1514
  {
1529
1515
  slug: "source",
1530
1516
  type: "link",
1531
- target: model.slug,
1532
- actions: {
1533
- onDelete: "CASCADE",
1534
- onUpdate: "CASCADE"
1535
- }
1517
+ target: model.slug
1536
1518
  },
1537
1519
  {
1538
1520
  slug: "target",
1539
1521
  type: "link",
1540
- target: relatedModel.slug,
1541
- actions: {
1542
- onDelete: "CASCADE",
1543
- onUpdate: "CASCADE"
1544
- }
1522
+ target: relatedModel.slug
1545
1523
  }
1546
1524
  ]
1547
1525
  });
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-361",
3
+ "version": "0.14.14",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {