@ronin/compiler 0.10.3-leo-ron-1083-experimental-217 → 0.10.3-leo-ron-1083-experimental-219

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
@@ -6005,6 +6005,45 @@ type AmountResult = {
6005
6005
  };
6006
6006
  type Result = SingleRecordResult | MultipleRecordResult | AmountResult;
6007
6007
 
6008
+ /**
6009
+ * A list of placeholders that can be located inside queries after those queries were
6010
+ * serialized into JSON objects.
6011
+ *
6012
+ * These placeholders are used to represent special keys and values. For example, if a
6013
+ * query is nested into a query, the nested query will be marked with `__RONIN_QUERY`,
6014
+ * which allows for distinguishing that nested query from an object of instructions.
6015
+ */
6016
+ declare const QUERY_SYMBOLS: {
6017
+ readonly QUERY: "__RONIN_QUERY";
6018
+ readonly EXPRESSION: "__RONIN_EXPRESSION";
6019
+ readonly FIELD: "__RONIN_FIELD_";
6020
+ readonly FIELD_PARENT: "__RONIN_FIELD_PARENT_";
6021
+ readonly FIELD_PARENT_OLD: "__RONIN_FIELD_PARENT_OLD_";
6022
+ readonly FIELD_PARENT_NEW: "__RONIN_FIELD_PARENT_NEW_";
6023
+ readonly VALUE: "__RONIN_VALUE";
6024
+ };
6025
+ type RoninErrorCode = 'MODEL_NOT_FOUND' | 'FIELD_NOT_FOUND' | 'INDEX_NOT_FOUND' | 'TRIGGER_NOT_FOUND' | 'PRESET_NOT_FOUND' | 'INVALID_WITH_VALUE' | 'INVALID_TO_VALUE' | 'INVALID_INCLUDING_VALUE' | 'INVALID_FOR_VALUE' | 'INVALID_BEFORE_OR_AFTER_INSTRUCTION' | 'INVALID_MODEL_VALUE' | 'MUTUALLY_EXCLUSIVE_INSTRUCTIONS' | 'MISSING_INSTRUCTION' | 'MISSING_FIELD';
6026
+ interface Issue {
6027
+ message: string;
6028
+ path: Array<string | number>;
6029
+ }
6030
+ interface Details {
6031
+ message: string;
6032
+ code: RoninErrorCode;
6033
+ field?: string;
6034
+ fields?: Array<string>;
6035
+ issues?: Array<Issue>;
6036
+ queries?: Array<Query> | null;
6037
+ }
6038
+ declare class RoninError extends Error {
6039
+ code: Details['code'];
6040
+ field?: Details['field'];
6041
+ fields?: Details['fields'];
6042
+ issues?: Details['issues'];
6043
+ queries?: Details['queries'];
6044
+ constructor(details: Details);
6045
+ }
6046
+
6008
6047
  interface TransactionOptions {
6009
6048
  /** A list of models that already exist in the database. */
6010
6049
  models?: Array<PublicModel>;
@@ -6037,4 +6076,4 @@ declare class Transaction {
6037
6076
 
6038
6077
  declare const CLEAN_ROOT_MODEL: PublicModel;
6039
6078
 
6040
- export { type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, type Query, CLEAN_ROOT_MODEL as ROOT_MODEL, type Result, type Statement, Transaction };
6079
+ export { type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, type Query, CLEAN_ROOT_MODEL as ROOT_MODEL, type Result, RoninError, type Statement, Transaction };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/utils/helpers.ts
2
2
  import { init as cuid } from "@paralleldrive/cuid2";
3
- var RONIN_MODEL_SYMBOLS = {
3
+ var QUERY_SYMBOLS = {
4
4
  // Represents a sub query.
5
5
  QUERY: "__RONIN_QUERY",
6
6
  // Represents an expression that should be evaluated.
@@ -17,7 +17,7 @@ var RONIN_MODEL_SYMBOLS = {
17
17
  VALUE: "__RONIN_VALUE"
18
18
  };
19
19
  var RONIN_MODEL_FIELD_REGEX = new RegExp(
20
- `${RONIN_MODEL_SYMBOLS.FIELD}[_a-zA-Z0-9.]+`,
20
+ `${QUERY_SYMBOLS.FIELD}[_a-zA-Z0-9.]+`,
21
21
  "g"
22
22
  );
23
23
  var MODEL_ENTITY_ERROR_CODES = {
@@ -68,16 +68,16 @@ var isObject = (value) => value != null && typeof value === "object" && Array.is
68
68
  var getSymbol = (value) => {
69
69
  if (!isObject(value)) return null;
70
70
  const objectValue = value;
71
- if (RONIN_MODEL_SYMBOLS.QUERY in objectValue) {
71
+ if (QUERY_SYMBOLS.QUERY in objectValue) {
72
72
  return {
73
73
  type: "query",
74
- value: objectValue[RONIN_MODEL_SYMBOLS.QUERY]
74
+ value: objectValue[QUERY_SYMBOLS.QUERY]
75
75
  };
76
76
  }
77
- if (RONIN_MODEL_SYMBOLS.EXPRESSION in objectValue) {
77
+ if (QUERY_SYMBOLS.EXPRESSION in objectValue) {
78
78
  return {
79
79
  type: "expression",
80
- value: objectValue[RONIN_MODEL_SYMBOLS.EXPRESSION]
80
+ value: objectValue[QUERY_SYMBOLS.EXPRESSION]
81
81
  };
82
82
  }
83
83
  return null;
@@ -151,15 +151,15 @@ var prepareStatementValue = (statementParams, value) => {
151
151
  };
152
152
  var parseFieldExpression = (model, instructionName, expression, parentModel) => {
153
153
  return expression.replace(RONIN_MODEL_FIELD_REGEX, (match) => {
154
- let toReplace = RONIN_MODEL_SYMBOLS.FIELD;
154
+ let toReplace = QUERY_SYMBOLS.FIELD;
155
155
  let rootModel = model;
156
- if (match.startsWith(RONIN_MODEL_SYMBOLS.FIELD_PARENT)) {
156
+ if (match.startsWith(QUERY_SYMBOLS.FIELD_PARENT)) {
157
157
  rootModel = parentModel;
158
- toReplace = RONIN_MODEL_SYMBOLS.FIELD_PARENT;
159
- if (match.startsWith(RONIN_MODEL_SYMBOLS.FIELD_PARENT_OLD)) {
160
- rootModel.tableAlias = toReplace = RONIN_MODEL_SYMBOLS.FIELD_PARENT_OLD;
161
- } else if (match.startsWith(RONIN_MODEL_SYMBOLS.FIELD_PARENT_NEW)) {
162
- rootModel.tableAlias = toReplace = RONIN_MODEL_SYMBOLS.FIELD_PARENT_NEW;
158
+ toReplace = QUERY_SYMBOLS.FIELD_PARENT;
159
+ if (match.startsWith(QUERY_SYMBOLS.FIELD_PARENT_OLD)) {
160
+ rootModel.tableAlias = toReplace = QUERY_SYMBOLS.FIELD_PARENT_OLD;
161
+ } else if (match.startsWith(QUERY_SYMBOLS.FIELD_PARENT_NEW)) {
162
+ rootModel.tableAlias = toReplace = QUERY_SYMBOLS.FIELD_PARENT_NEW;
163
163
  }
164
164
  }
165
165
  const fieldSlug = match.replace(toReplace, "");
@@ -238,7 +238,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
238
238
  }
239
239
  };
240
240
  recordTarget = {
241
- [RONIN_MODEL_SYMBOLS.QUERY]: subQuery
241
+ [QUERY_SYMBOLS.QUERY]: subQuery
242
242
  };
243
243
  }
244
244
  return composeConditions(
@@ -348,7 +348,7 @@ var getModelBySlug = (models, slug) => {
348
348
  };
349
349
  var composeAssociationModelSlug = (model, field) => convertToCamelCase(`ronin_link_${model.slug}_${field.slug}`);
350
350
  var getFieldSelector = (model, field, fieldPath, instructionName) => {
351
- const symbol = model.tableAlias?.startsWith(RONIN_MODEL_SYMBOLS.FIELD_PARENT) ? `${model.tableAlias.replace(RONIN_MODEL_SYMBOLS.FIELD_PARENT, "").slice(0, -1)}.` : "";
351
+ const symbol = model.tableAlias?.startsWith(QUERY_SYMBOLS.FIELD_PARENT) ? `${model.tableAlias.replace(QUERY_SYMBOLS.FIELD_PARENT, "").slice(0, -1)}.` : "";
352
352
  const tablePrefix = symbol || (model.tableAlias ? `"${model.tableAlias}".` : "");
353
353
  if (field.type === "json" && instructionName !== "to") {
354
354
  const dotParts = fieldPath.split(".");
@@ -544,14 +544,14 @@ var addDefaultModelPresets = (list, model) => {
544
544
  instructions: {
545
545
  including: {
546
546
  [field.slug]: {
547
- [RONIN_MODEL_SYMBOLS.QUERY]: {
547
+ [QUERY_SYMBOLS.QUERY]: {
548
548
  get: {
549
549
  [relatedModel.slug]: {
550
550
  with: {
551
551
  // Compare the `id` field of the related model to the link field on
552
552
  // the root model (`field.slug`).
553
553
  id: {
554
- [RONIN_MODEL_SYMBOLS.EXPRESSION]: `${RONIN_MODEL_SYMBOLS.FIELD_PARENT}${field.slug}`
554
+ [QUERY_SYMBOLS.EXPRESSION]: `${QUERY_SYMBOLS.FIELD_PARENT}${field.slug}`
555
555
  }
556
556
  }
557
557
  }
@@ -579,12 +579,12 @@ var addDefaultModelPresets = (list, model) => {
579
579
  instructions: {
580
580
  including: {
581
581
  [presetSlug]: {
582
- [RONIN_MODEL_SYMBOLS.QUERY]: {
582
+ [QUERY_SYMBOLS.QUERY]: {
583
583
  get: {
584
584
  [pluralSlug]: {
585
585
  with: {
586
586
  [childField.slug]: {
587
- [RONIN_MODEL_SYMBOLS.EXPRESSION]: `${RONIN_MODEL_SYMBOLS.FIELD_PARENT}id`
587
+ [QUERY_SYMBOLS.EXPRESSION]: `${QUERY_SYMBOLS.FIELD_PARENT}id`
588
588
  }
589
589
  }
590
590
  }
@@ -851,11 +851,11 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
851
851
  statementParts.push(`OF (${fieldSelectors.join(", ")})`);
852
852
  }
853
853
  statementParts.push("ON", `"${existingModel.table}"`);
854
- if (trigger.filter || trigger.effects.some((query2) => findInObject(query2, RONIN_MODEL_SYMBOLS.FIELD))) {
854
+ if (trigger.filter || trigger.effects.some((query2) => findInObject(query2, QUERY_SYMBOLS.FIELD))) {
855
855
  statementParts.push("FOR EACH ROW");
856
856
  }
857
857
  if (trigger.filter) {
858
- const tableAlias = trigger.action === "DELETE" ? RONIN_MODEL_SYMBOLS.FIELD_PARENT_OLD : RONIN_MODEL_SYMBOLS.FIELD_PARENT_NEW;
858
+ const tableAlias = trigger.action === "DELETE" ? QUERY_SYMBOLS.FIELD_PARENT_OLD : QUERY_SYMBOLS.FIELD_PARENT_NEW;
859
859
  const withStatement = handleWith(
860
860
  models,
861
861
  { ...existingModel, tableAlias },
@@ -877,7 +877,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
877
877
  }
878
878
  dependencyStatements.push({ statement, params });
879
879
  }
880
- const field = `${RONIN_MODEL_SYMBOLS.FIELD}${pluralType}`;
880
+ const field = `${QUERY_SYMBOLS.FIELD}${pluralType}`;
881
881
  let json;
882
882
  switch (action) {
883
883
  case "create": {
@@ -941,7 +941,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
941
941
  model: {
942
942
  with: { slug: modelSlug },
943
943
  to: {
944
- [pluralType]: { [RONIN_MODEL_SYMBOLS.EXPRESSION]: json }
944
+ [pluralType]: { [QUERY_SYMBOLS.EXPRESSION]: json }
945
945
  }
946
946
  }
947
947
  }
@@ -1060,8 +1060,8 @@ var handleFor = (model, instructions) => {
1060
1060
  if (arg !== null) {
1061
1061
  findInObject(
1062
1062
  replacedForFilter,
1063
- RONIN_MODEL_SYMBOLS.VALUE,
1064
- (match) => match.replace(RONIN_MODEL_SYMBOLS.VALUE, arg)
1063
+ QUERY_SYMBOLS.VALUE,
1064
+ (match) => match.replace(QUERY_SYMBOLS.VALUE, arg)
1065
1065
  );
1066
1066
  }
1067
1067
  for (const subInstruction in replacedForFilter) {
@@ -1207,7 +1207,7 @@ var handleSelecting = (models, model, statementParams, instructions, options) =>
1207
1207
  const value2 = parseFieldExpression(
1208
1208
  { ...queryModel, tableAlias: tableName },
1209
1209
  "including",
1210
- `${RONIN_MODEL_SYMBOLS.FIELD}${field.slug}`
1210
+ `${QUERY_SYMBOLS.FIELD}${field.slug}`
1211
1211
  );
1212
1212
  return {
1213
1213
  key: `${tableName}.${field.slug}`,
@@ -1607,6 +1607,8 @@ var Transaction = class {
1607
1607
  };
1608
1608
  var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
1609
1609
  export {
1610
+ QUERY_SYMBOLS,
1610
1611
  CLEAN_ROOT_MODEL as ROOT_MODEL,
1612
+ RoninError,
1611
1613
  Transaction
1612
1614
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.10.3-leo-ron-1083-experimental-217",
3
+ "version": "0.10.3-leo-ron-1083-experimental-219",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {