@ronin/compiler 0.11.4 → 0.11.5-leo-ron-1083-experimental-245

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/index.js +21 -11
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -658,7 +658,8 @@ var getFieldStatement = (models, model, field) => {
658
658
  if (field.type === "link") {
659
659
  if (field.kind === "many") return null;
660
660
  const actions = field.actions || {};
661
- const targetTable = getModelBySlug(models, field.target).table;
661
+ const modelList = models.some((item) => item.slug === model.slug) ? models : [...models, model];
662
+ const targetTable = getModelBySlug(modelList, field.target).table;
662
663
  statement += ` REFERENCES ${targetTable}("id")`;
663
664
  for (const trigger in actions) {
664
665
  const triggerName = trigger.toUpperCase().slice(2);
@@ -1209,6 +1210,7 @@ var handleOrderedBy = (model, instruction) => {
1209
1210
  // src/instructions/selecting.ts
1210
1211
  var handleSelecting = (models, model, statementParams, instructions, options) => {
1211
1212
  let loadedFields = [];
1213
+ let expandColumns = false;
1212
1214
  let statement = "*";
1213
1215
  let isJoining = false;
1214
1216
  if (instructions.including) {
@@ -1217,9 +1219,10 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
1217
1219
  for (const [key, value] of Object.entries(flatObject)) {
1218
1220
  const symbol = getSymbol(value);
1219
1221
  if (symbol?.type === "query") {
1220
- isJoining = true;
1221
1222
  const { queryModel, queryInstructions } = splitQuery(symbol.value);
1222
1223
  const subQueryModel = getModelBySlug(models, queryModel);
1224
+ isJoining = true;
1225
+ expandColumns = Boolean(options?.expandColumns || queryInstructions?.selecting);
1223
1226
  const tableAlias = composeIncludedTableAlias(key);
1224
1227
  const single = queryModel !== subQueryModel.pluralSlug;
1225
1228
  if (!single) {
@@ -1227,10 +1230,15 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
1227
1230
  }
1228
1231
  const queryModelFields = queryInstructions?.selecting ? subQueryModel.fields.filter((field) => {
1229
1232
  return queryInstructions.selecting?.includes(field.slug);
1230
- }) : subQueryModel.fields;
1233
+ }) : (
1234
+ // Exclude link fields with cardinality "many", since those don't exist as columns.
1235
+ subQueryModel.fields.filter((field) => {
1236
+ return !(field.type === "link" && field.kind === "many");
1237
+ })
1238
+ );
1231
1239
  for (const field of queryModelFields) {
1232
1240
  loadedFields.push({ ...field, parentField: key });
1233
- if (options?.expandColumns) {
1241
+ if (expandColumns) {
1234
1242
  const newValue2 = parseFieldExpression(
1235
1243
  { ...subQueryModel, tableAlias },
1236
1244
  "including",
@@ -1254,7 +1262,6 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
1254
1262
  });
1255
1263
  }
1256
1264
  }
1257
- const expandColumns = isJoining && options?.expandColumns;
1258
1265
  if (expandColumns) {
1259
1266
  instructions.selecting = model.fields.filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => field.slug);
1260
1267
  }
@@ -1272,7 +1279,12 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
1272
1279
  }).join(", ");
1273
1280
  loadedFields = [...selectedFields, ...loadedFields];
1274
1281
  } else {
1275
- loadedFields = [...model.fields, ...loadedFields];
1282
+ loadedFields = [
1283
+ ...model.fields.filter(
1284
+ (field) => !(field.type === "link" && field.kind === "many")
1285
+ ),
1286
+ ...loadedFields
1287
+ ];
1276
1288
  }
1277
1289
  if (instructions.including && Object.keys(instructions.including).length > 0) {
1278
1290
  statement += ", ";
@@ -1587,8 +1599,7 @@ var Transaction = class {
1587
1599
  const modelListWithPresets = modelList.map((model) => {
1588
1600
  return addDefaultModelPresets(modelList, model);
1589
1601
  });
1590
- const dependencyStatements = [];
1591
- const mainStatements = [];
1602
+ const statements = [];
1592
1603
  for (const query of queries) {
1593
1604
  const result = compileQueryInput(
1594
1605
  query,
@@ -1596,12 +1607,11 @@ var Transaction = class {
1596
1607
  options?.inlineParams ? null : [],
1597
1608
  { expandColumns: options?.expandColumns }
1598
1609
  );
1599
- dependencyStatements.push(...result.dependencies);
1600
- mainStatements.push(result.main);
1610
+ statements.push(...result.dependencies, result.main);
1601
1611
  this.fields.push(result.loadedFields);
1602
1612
  }
1603
1613
  this.models = modelListWithPresets;
1604
- return [...dependencyStatements, ...mainStatements];
1614
+ return statements;
1605
1615
  };
1606
1616
  formatRows(fields, rows, single) {
1607
1617
  const records = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.11.4",
3
+ "version": "0.11.5-leo-ron-1083-experimental-245",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@biomejs/biome": "1.9.2",
36
- "@ronin/engine": "0.0.2",
36
+ "@ronin/engine": "0.0.19",
37
37
  "@types/bun": "1.1.10",
38
38
  "@types/title": "3.4.3",
39
39
  "tsup": "8.3.0",