@ronin/compiler 0.17.7 → 0.17.8

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
@@ -117,6 +117,14 @@ type AddQuery = Record<string, Omit<CombinedInstructions, 'with' | 'using'> & {
117
117
  }>;
118
118
  type RemoveQuery = Record<string, Omit<CombinedInstructions, 'to'>>;
119
119
  type CountQuery = Record<string, Omit<CombinedInstructions, 'to'> | null>;
120
+ type AllQueryInstructions = {
121
+ for?: string;
122
+ };
123
+ type AllQuery = {
124
+ all: AllQueryInstructions | null;
125
+ };
126
+ type GetAllQuery = AllQuery;
127
+ type CountAllQuery = AllQuery;
120
128
  type GetInstructions = Omit<CombinedInstructions, 'to'>;
121
129
  type SetInstructions = Omit<CombinedInstructions, 'to'> & {
122
130
  to: FieldSelector;
@@ -158,11 +166,11 @@ type DropQuery = {
158
166
  model: string;
159
167
  };
160
168
  type Query = {
161
- get?: GetQuery;
169
+ get?: GetQuery | GetAllQuery;
162
170
  set?: SetQuery;
163
171
  add?: AddQuery;
164
172
  remove?: RemoveQuery;
165
- count?: CountQuery;
173
+ count?: CountQuery | CountAllQuery;
166
174
  create?: CreateQuery;
167
175
  alter?: AlterQuery;
168
176
  drop?: DropQuery;
package/dist/index.js CHANGED
@@ -1719,7 +1719,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
1719
1719
  const action = subAltering && query.alter ? Object.keys(query.alter).filter((key) => key !== "model")[0] : queryType;
1720
1720
  const actionReadable = action === "create" ? "creating" : action === "alter" ? "altering" : "dropping";
1721
1721
  const entity = subAltering && query.alter ? Object.keys(query.alter[action])[0] : "model";
1722
- let slug = entity === "model" && action === "create" ? null : query[queryType].model;
1722
+ let slug = entity === "model" && action === "create" ? null : query[queryType] && "model" in query[queryType] ? query[queryType].model : null;
1723
1723
  let modelSlug = slug;
1724
1724
  let jsonValue;
1725
1725
  if ("create" in query && query.create) {
@@ -2098,9 +2098,19 @@ var Transaction = class {
2098
2098
  const expandedQueries = queries.flatMap((query, expansionIndex) => {
2099
2099
  const { queryType, queryModel, queryInstructions } = splitQuery(query);
2100
2100
  if (queryModel === "all") {
2101
- return modelsWithAttributes.map((model) => {
2101
+ const { for: forInstruction, ...restInstructions } = queryInstructions || {};
2102
+ let modelList = modelsWithAttributes;
2103
+ if (forInstruction) {
2104
+ const mainModel = getModelBySlug(modelsWithAttributes, forInstruction);
2105
+ modelList = Object.values(mainModel.fields || {}).filter((field) => field.type === "link").map((field) => {
2106
+ return modelsWithAttributes.find(
2107
+ (model) => model.slug === field.target
2108
+ );
2109
+ });
2110
+ }
2111
+ return modelList.map((model) => {
2102
2112
  const query2 = {
2103
- [queryType]: { [model.pluralSlug]: queryInstructions }
2113
+ [queryType]: { [model.pluralSlug]: restInstructions }
2104
2114
  };
2105
2115
  return { query: query2, expansionIndex };
2106
2116
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.17.7",
3
+ "version": "0.17.8",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {