@ronin/compiler 0.17.9 → 0.17.10-leo-ron-1099-experimental-400

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
@@ -118,7 +118,15 @@ type AddQuery = Record<string, Omit<CombinedInstructions, 'with' | 'using'> & {
118
118
  type RemoveQuery = Record<string, Omit<CombinedInstructions, 'to'>>;
119
119
  type CountQuery = Record<string, Omit<CombinedInstructions, 'to'> | null>;
120
120
  type AllQueryInstructions = {
121
- for?: string;
121
+ /**
122
+ * Limit the list of models for which queries should be generated to only the models
123
+ * that the provided model links to.
124
+ */
125
+ for?: PublicModel['slug'];
126
+ /**
127
+ * Provide query instructions for specific models.
128
+ */
129
+ on?: Record<PublicModel['slug'], Omit<CombinedInstructions, 'to'> | null>;
122
130
  };
123
131
  type AllQuery = {
124
132
  all: AllQueryInstructions | null;
package/dist/index.js CHANGED
@@ -1038,7 +1038,8 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1038
1038
  return {
1039
1039
  dependencies: [],
1040
1040
  main: dependencyStatements[0],
1041
- selectedFields: []
1041
+ selectedFields: [],
1042
+ model: ROOT_MODEL_WITH_ATTRIBUTES
1042
1043
  };
1043
1044
  const parsedQuery = splitQuery(query);
1044
1045
  const { queryType, queryModel, queryInstructions } = parsedQuery;
@@ -1196,7 +1197,8 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1196
1197
  return {
1197
1198
  dependencies: dependencyStatements,
1198
1199
  main: mainStatement,
1199
- selectedFields
1200
+ selectedFields,
1201
+ model
1200
1202
  };
1201
1203
  };
1202
1204
 
@@ -2072,7 +2074,11 @@ var Transaction = class {
2072
2074
  #internalQueries = [];
2073
2075
  constructor(queries, options) {
2074
2076
  const models = options?.models || [];
2075
- this.#internalQueries = queries.map((query) => ({ query, selectedFields: [] }));
2077
+ this.#internalQueries = queries.map((query) => ({
2078
+ query,
2079
+ selectedFields: [],
2080
+ models: []
2081
+ }));
2076
2082
  this.#compileQueries(models, options);
2077
2083
  }
2078
2084
  /**
@@ -2099,34 +2105,42 @@ var Transaction = class {
2099
2105
  return addDefaultModelPresets(modelsWithFields, model);
2100
2106
  });
2101
2107
  const statements = [];
2102
- const expandedQueries = this.#internalQueries.flatMap(({ query }, expansionIndex) => {
2108
+ const expandedQueries = this.#internalQueries.flatMap(({ query }, index) => {
2103
2109
  const { queryType, queryModel, queryInstructions } = splitQuery(query);
2104
2110
  if (queryModel === "all") {
2105
- const { for: forInstruction, ...restInstructions } = queryInstructions || {};
2106
- let modelList = modelsWithAttributes;
2111
+ const {
2112
+ for: forInstruction,
2113
+ on: onInstruction,
2114
+ ...restInstructions
2115
+ } = queryInstructions || {};
2116
+ let modelList = modelsWithPresets.filter((model) => {
2117
+ return model.slug !== ROOT_MODEL.slug;
2118
+ });
2107
2119
  if (forInstruction) {
2108
- const mainModel = getModelBySlug(modelsWithAttributes, forInstruction);
2120
+ const mainModel = getModelBySlug(modelList, forInstruction);
2109
2121
  modelList = Object.values(mainModel.fields || {}).filter((field) => field.type === "link").map((field) => {
2110
- return modelsWithAttributes.find(
2122
+ return modelList.find(
2111
2123
  (model) => model.slug === field.target
2112
2124
  );
2113
2125
  });
2114
2126
  }
2115
- this.#internalQueries[expansionIndex].affectedModels = modelList.map(
2116
- (model) => model.slug
2117
- );
2127
+ this.#internalQueries[index].models = modelList;
2118
2128
  return modelList.map((model) => {
2129
+ const instructions = Object.assign(
2130
+ {},
2131
+ restInstructions,
2132
+ onInstruction?.[model.pluralSlug]
2133
+ );
2119
2134
  const query2 = {
2120
- [queryType]: { [model.pluralSlug]: restInstructions }
2135
+ [queryType]: { [model.pluralSlug]: instructions }
2121
2136
  };
2122
- return { query: query2, expansionIndex };
2137
+ return { query: query2, index };
2123
2138
  });
2124
2139
  }
2125
- return { query };
2140
+ return { query, index };
2126
2141
  });
2127
- for (let index = 0; index < expandedQueries.length; index++) {
2128
- const { query, expansionIndex } = expandedQueries[index];
2129
- const { dependencies, main, selectedFields } = compileQueryInput(
2142
+ for (const { query, index } of expandedQueries) {
2143
+ const { dependencies, main, selectedFields, model } = compileQueryInput(
2130
2144
  query,
2131
2145
  modelsWithPresets,
2132
2146
  options?.inlineParams ? null : [],
@@ -2137,8 +2151,10 @@ var Transaction = class {
2137
2151
  const postDependencies = dependencies.map(({ after, ...rest }) => after ? rest : null).filter((item) => item != null);
2138
2152
  const subStatements = [...preDependencies, main, ...postDependencies];
2139
2153
  this.statements.push(...subStatements);
2140
- const queryIndex = typeof expansionIndex === "undefined" ? index : expansionIndex;
2141
- this.#internalQueries[queryIndex].selectedFields = selectedFields;
2154
+ this.#internalQueries[index].selectedFields = selectedFields;
2155
+ if (this.#internalQueries[index].models.length === 0) {
2156
+ this.#internalQueries[index].models = [model];
2157
+ }
2142
2158
  }
2143
2159
  this.models = modelsWithPresets;
2144
2160
  return statements;
@@ -2291,7 +2307,7 @@ var Transaction = class {
2291
2307
  let resultIndex = 0;
2292
2308
  return this.#internalQueries.reduce(
2293
2309
  (finalResults, internalQuery) => {
2294
- const { query, selectedFields, affectedModels } = internalQuery;
2310
+ const { query, selectedFields, models: affectedModels } = internalQuery;
2295
2311
  const { queryType, queryModel, queryInstructions } = splitQuery(query);
2296
2312
  const absoluteResults = raw ? cleanResults : cleanResults.map((rows) => {
2297
2313
  return rows.map((row) => {
@@ -2300,15 +2316,18 @@ var Transaction = class {
2300
2316
  return Object.values(row);
2301
2317
  });
2302
2318
  });
2303
- if (queryModel === "all" && affectedModels) {
2304
- const modelList = affectedModels.map((slug) => {
2305
- return getModelBySlug(this.models, slug);
2306
- });
2319
+ if (queryModel === "all") {
2307
2320
  const models = {};
2308
- for (const model of modelList) {
2321
+ const { on: onInstruction, ...restInstructions } = queryInstructions || {};
2322
+ for (const model of affectedModels) {
2323
+ const instructions = Object.assign(
2324
+ {},
2325
+ restInstructions,
2326
+ onInstruction?.[model.pluralSlug]
2327
+ );
2309
2328
  const result = this.formatIndividualResult(
2310
2329
  queryType,
2311
- queryInstructions,
2330
+ instructions,
2312
2331
  model,
2313
2332
  absoluteResults[resultIndex++],
2314
2333
  selectedFields,
@@ -2318,7 +2337,7 @@ var Transaction = class {
2318
2337
  }
2319
2338
  finalResults.push({ models });
2320
2339
  } else {
2321
- const model = getModelBySlug(this.models, queryModel);
2340
+ const model = affectedModels[0];
2322
2341
  const result = this.formatIndividualResult(
2323
2342
  queryType,
2324
2343
  queryInstructions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.17.9",
3
+ "version": "0.17.10-leo-ron-1099-experimental-400",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {