@ronin/compiler 0.14.12 → 0.14.13-leo-ron-1099-1-experimental-354

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
@@ -95,7 +95,7 @@ type OrderedByInstruction = {
95
95
  ascending?: Array<string | Expression>;
96
96
  descending?: Array<string | Expression>;
97
97
  };
98
- type ForInstruction = Array<string> | Record<string, string>;
98
+ type UsingInstruction = Array<string> | Record<string, string>;
99
99
  type CombinedInstructions = {
100
100
  with?: WithInstruction | Array<WithInstruction>;
101
101
  to?: FieldSelector;
@@ -105,14 +105,14 @@ type CombinedInstructions = {
105
105
  before?: string | null;
106
106
  after?: string | null;
107
107
  limitedTo?: number;
108
- for?: ForInstruction;
108
+ using?: UsingInstruction;
109
109
  };
110
- type InstructionSchema = 'with' | 'to' | 'including' | 'selecting' | 'orderedBy' | 'orderedBy.ascending' | 'orderedBy.descending' | 'before' | 'after' | 'limitedTo' | 'for';
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' | 'for'> & {
115
+ type AddQuery = Record<string, Omit<CombinedInstructions, 'with' | 'using'> & {
116
116
  to: FieldSelector;
117
117
  }>;
118
118
  type RemoveQuery = Record<string, Omit<CombinedInstructions, 'to'>>;
@@ -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' | 'for'> & {
124
+ type AddInstructions = Omit<CombinedInstructions, 'with' | 'using'> & {
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 handleFor = (model, instructions) => {
261
- const normalizedFor = Array.isArray(instructions.for) ? Object.fromEntries(instructions.for.map((presetSlug) => [presetSlug, null])) : instructions.for;
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 replacedForFilter = structuredClone(preset.instructions);
272
+ const replacedUsingFilter = structuredClone(preset.instructions);
273
273
  if (arg !== null) {
274
274
  findInObject(
275
- replacedForFilter,
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 replacedForFilter) {
281
- if (!Object.hasOwn(replacedForFilter, subInstruction)) continue;
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
- ...replacedForFilter[instructionName],
288
+ ...replacedUsingFilter[instructionName],
289
289
  ...currentValue
290
290
  ];
291
291
  } else if (isObject(currentValue)) {
292
292
  newValue = {
293
- ...replacedForFilter[instructionName],
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]: replacedForFilter[instructionName]
301
+ [instructionName]: replacedUsingFilter[instructionName]
302
302
  });
303
303
  }
304
304
  }
@@ -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 && Object.hasOwn(instructions, "for")) {
619
- instructions = handleFor(model, 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 = {};
@@ -1247,9 +1247,12 @@ var addDefaultModelAttributes = (model, isNew) => {
1247
1247
  };
1248
1248
  var addDefaultModelFields = (model, isNew) => {
1249
1249
  const copiedModel = { ...model };
1250
- const newFields = copiedModel.fields || [];
1251
- if (isNew || newFields.length > 0) {
1252
- copiedModel.fields = [...getSystemFields(copiedModel.idPrefix), ...newFields];
1250
+ const existingFields = copiedModel.fields || [];
1251
+ if (isNew || existingFields.length > 0) {
1252
+ const additionalFields = getSystemFields(copiedModel.idPrefix).filter((newField) => {
1253
+ return !existingFields.some(({ slug }) => slug === newField.slug);
1254
+ });
1255
+ copiedModel.fields = [...additionalFields, ...existingFields];
1253
1256
  }
1254
1257
  return copiedModel;
1255
1258
  };
@@ -1361,8 +1364,12 @@ var addDefaultModelPresets = (list, model) => {
1361
1364
  slug: presetSlug
1362
1365
  });
1363
1366
  }
1364
- if (Object.keys(defaultPresets).length > 0) {
1365
- model.presets = [...defaultPresets, ...model.presets || []];
1367
+ if (defaultPresets.length > 0) {
1368
+ const existingPresets = model.presets || [];
1369
+ const additionalPresets = defaultPresets.filter((newPreset) => {
1370
+ return !existingPresets.some(({ slug }) => slug === newPreset.slug);
1371
+ });
1372
+ model.presets = [...additionalPresets, ...existingPresets];
1366
1373
  }
1367
1374
  return model;
1368
1375
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.12",
3
+ "version": "0.14.13-leo-ron-1099-1-experimental-354",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {