@ronin/compiler 0.14.2-leo-ron-1099-1-experimental-319 → 0.14.2-leo-ron-1099-1-experimental-321

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 -8
  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}`;
@@ -511,7 +509,9 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
511
509
  const subQuerySelectedFields = subQueryInstructions?.selecting;
512
510
  const subQueryIncludedFields = subQueryInstructions?.including;
513
511
  const subQueryFields = [
514
- ...subQuerySelectedFields || (subQueryModel.fields || []).map((field) => field.slug),
512
+ ...filterSelectedFields(subQueryModel, subQuerySelectedFields).map(
513
+ (field) => field.slug
514
+ ),
515
515
  ...subQueryIncludedFields ? Object.keys(
516
516
  flatten(subQueryIncludedFields || {})
517
517
  ) : []
@@ -757,6 +757,32 @@ var replaceJSON = (key, value) => {
757
757
  if (key === QUERY_SYMBOLS.EXPRESSION) return value.replaceAll(`'`, `''`);
758
758
  return value;
759
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
+ };
760
786
  var prepareStatementValue = (statementParams, value) => {
761
787
  if (value === null) return "NULL";
762
788
  if (!statementParams) {
@@ -1256,7 +1282,8 @@ var addDefaultModelPresets = (list, model) => {
1256
1282
  }
1257
1283
  }
1258
1284
  }
1259
- }
1285
+ },
1286
+ selecting: ["**", "!source", "!target"]
1260
1287
  }
1261
1288
  }
1262
1289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.2-leo-ron-1099-1-experimental-319",
3
+ "version": "0.14.2-leo-ron-1099-1-experimental-321",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {