@ronin/compiler 0.14.2 → 0.14.3

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 +35 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -403,12 +403,10 @@ var handleOrderedBy = (model, instruction) => {
403
403
  // src/instructions/selecting.ts
404
404
  var handleSelecting = (models, model, statementParams, single, instructions, options = {}) => {
405
405
  let isJoining = false;
406
- const selectedFields = (instructions.selecting ? instructions.selecting.map((slug) => {
407
- const { field } = getFieldFromModel(model, slug, {
408
- instructionName: "selecting"
409
- });
410
- return field;
411
- }) : model.fields).filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => {
406
+ const selectedFields = filterSelectedFields(
407
+ model,
408
+ instructions.selecting
409
+ ).filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => {
412
410
  const newField = { ...field, mountingPath: field.slug };
413
411
  if (options.mountingPath) {
414
412
  newField.mountingPath = `${options.mountingPath}.${field.slug}`;
@@ -508,15 +506,12 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
508
506
  if (symbol?.type === "query") {
509
507
  const { queryModel: subQueryModelSlug, queryInstructions: subQueryInstructions } = splitQuery(symbol.value);
510
508
  const subQueryModel = getModelBySlug(models, subQueryModelSlug);
511
- if (subQueryInstructions?.selecting) {
512
- const currentFields = new Set(subQueryInstructions.selecting);
513
- currentFields.add("id");
514
- subQueryInstructions.selecting = Array.from(currentFields);
515
- }
516
509
  const subQuerySelectedFields = subQueryInstructions?.selecting;
517
510
  const subQueryIncludedFields = subQueryInstructions?.including;
518
511
  const subQueryFields = [
519
- ...subQuerySelectedFields || (subQueryModel.fields || []).map((field) => field.slug),
512
+ ...filterSelectedFields(subQueryModel, subQuerySelectedFields).map(
513
+ (field) => field.slug
514
+ ),
520
515
  ...subQueryIncludedFields ? Object.keys(
521
516
  flatten(subQueryIncludedFields || {})
522
517
  ) : []
@@ -762,6 +757,32 @@ var replaceJSON = (key, value) => {
762
757
  if (key === QUERY_SYMBOLS.EXPRESSION) return value.replaceAll(`'`, `''`);
763
758
  return value;
764
759
  };
760
+ var matchSelectedFields = (fields, pattern) => {
761
+ let regexStr = pattern.replace(/\./g, "\\.");
762
+ regexStr = regexStr.replace(/\*\*/g, "<<DOUBLESTAR>>");
763
+ regexStr = regexStr.replace(/\*/g, "[^.]*");
764
+ regexStr = regexStr.replace(/<<DOUBLESTAR>>/g, ".*");
765
+ const regex2 = new RegExp(`^${regexStr}$`);
766
+ return fields.filter((field) => regex2.test(field.slug));
767
+ };
768
+ var filterSelectedFields = (model, instruction) => {
769
+ if (!instruction) return model.fields;
770
+ let selectedFields = [];
771
+ for (const pattern of instruction) {
772
+ const isNegative = pattern.startsWith("!");
773
+ const cleanPattern = isNegative ? pattern.slice(1) : pattern;
774
+ const matchedFields = matchSelectedFields(
775
+ isNegative ? selectedFields : model.fields,
776
+ cleanPattern
777
+ );
778
+ if (isNegative) {
779
+ selectedFields = selectedFields.filter((field) => !matchedFields.includes(field));
780
+ } else {
781
+ selectedFields.push(...matchedFields);
782
+ }
783
+ }
784
+ return selectedFields;
785
+ };
765
786
  var prepareStatementValue = (statementParams, value) => {
766
787
  if (value === null) return "NULL";
767
788
  if (!statementParams) {
@@ -1261,7 +1282,8 @@ var addDefaultModelPresets = (list, model) => {
1261
1282
  }
1262
1283
  }
1263
1284
  }
1264
- }
1285
+ },
1286
+ selecting: ["**", "!source", "!target"]
1265
1287
  }
1266
1288
  }
1267
1289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {