@ronin/compiler 0.18.9 → 0.18.10

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
@@ -398,20 +398,20 @@ type ExpandedResult<T = ResultRecord> = {
398
398
  };
399
399
  type Result<T = ResultRecord> = RegularResult<T> | ExpandedResult<T>;
400
400
 
401
- 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' | 'INVALID_FIELD_VALUE' | 'EXISTING_MODEL_ENTITY' | 'REQUIRED_MODEL_ENTITY' | 'MUTUALLY_EXCLUSIVE_INSTRUCTIONS' | 'MISSING_INSTRUCTION' | 'MISSING_FIELD';
401
+ type CompilerErrorCode = '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' | 'INVALID_FIELD_VALUE' | 'EXISTING_MODEL_ENTITY' | 'REQUIRED_MODEL_ENTITY' | 'MUTUALLY_EXCLUSIVE_INSTRUCTIONS' | 'MISSING_INSTRUCTION' | 'MISSING_FIELD';
402
402
  interface Issue {
403
403
  message: string;
404
404
  path: Array<string | number>;
405
405
  }
406
406
  interface Details {
407
407
  message: string;
408
- code: RoninErrorCode;
408
+ code: CompilerErrorCode;
409
409
  field?: string;
410
410
  fields?: Array<string>;
411
411
  issues?: Array<Issue>;
412
412
  queries?: Array<Query> | null;
413
413
  }
414
- declare class RoninError extends Error {
414
+ declare class CompilerError extends Error {
415
415
  code: Details['code'];
416
416
  field?: Details['field'];
417
417
  fields?: Details['fields'];
@@ -474,4 +474,4 @@ declare class Transaction {
474
474
 
475
475
  declare const CLEAN_ROOT_MODEL: PublicModel;
476
476
 
477
- export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, DDL_QUERY_TYPES, DDL_QUERY_TYPES_READ, DDL_QUERY_TYPES_WRITE, DML_QUERY_TYPES, DML_QUERY_TYPES_READ, DML_QUERY_TYPES_WRITE, type DropQuery, type ExpandedResult, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type ListQuery, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, QUERY_SYMBOLS, QUERY_TYPES, QUERY_TYPES_READ, QUERY_TYPES_WRITE, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RegularResult, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, type ResultRecord, type ResultRecordBase, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
477
+ export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, CompilerError, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, DDL_QUERY_TYPES, DDL_QUERY_TYPES_READ, DDL_QUERY_TYPES_WRITE, DML_QUERY_TYPES, DML_QUERY_TYPES_READ, DML_QUERY_TYPES_WRITE, type DropQuery, type ExpandedResult, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type ListQuery, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, QUERY_SYMBOLS, QUERY_TYPES, QUERY_TYPES_READ, QUERY_TYPES_WRITE, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RegularResult, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, type ResultRecord, type ResultRecordBase, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ var MODEL_ENTITY_ERROR_CODES = {
57
57
  index: "INDEX_NOT_FOUND",
58
58
  preset: "PRESET_NOT_FOUND"
59
59
  };
60
- var RoninError = class extends Error {
60
+ var CompilerError = class extends Error {
61
61
  code;
62
62
  field;
63
63
  fields;
@@ -65,7 +65,7 @@ var RoninError = class extends Error {
65
65
  queries;
66
66
  constructor(details) {
67
67
  super(details.message);
68
- this.name = "RoninError";
68
+ this.name = "CompilerError";
69
69
  this.code = details.code;
70
70
  this.field = details.field;
71
71
  this.fields = details.fields;
@@ -211,13 +211,13 @@ var generatePaginationCursor = (model, orderedBy, record) => {
211
211
  // src/instructions/before-after.ts
212
212
  var handleBeforeOrAfter = (model, statementParams, queryType, instructions) => {
213
213
  if (!(instructions.before || instructions.after)) {
214
- throw new RoninError({
214
+ throw new CompilerError({
215
215
  message: "The `before` or `after` instruction must not be empty.",
216
216
  code: "MISSING_INSTRUCTION"
217
217
  });
218
218
  }
219
219
  if (instructions.before && instructions.after) {
220
- throw new RoninError({
220
+ throw new CompilerError({
221
221
  message: "The `before` and `after` instructions cannot co-exist. Choose one.",
222
222
  code: "MUTUALLY_EXCLUSIVE_INSTRUCTIONS"
223
223
  });
@@ -226,7 +226,7 @@ var handleBeforeOrAfter = (model, statementParams, queryType, instructions) => {
226
226
  let message = "When providing a pagination cursor in the `before` or `after`";
227
227
  message += " instruction, a `limitedTo` instruction must be provided as well, to";
228
228
  message += " define the page size.";
229
- throw new RoninError({
229
+ throw new CompilerError({
230
230
  message,
231
231
  code: "MISSING_INSTRUCTION"
232
232
  });
@@ -1038,7 +1038,7 @@ var handleUsing = (model, instructions) => {
1038
1038
  const arg = normalizedUsing[presetSlug];
1039
1039
  const preset = model.presets?.[presetSlug];
1040
1040
  if (!preset) {
1041
- throw new RoninError({
1041
+ throw new CompilerError({
1042
1042
  message: `Preset "${presetSlug}" does not exist in model "${model.name}".`,
1043
1043
  code: "PRESET_NOT_FOUND"
1044
1044
  });
@@ -1188,7 +1188,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1188
1188
  const instructionName = queryType === "add" ? "with" : "to";
1189
1189
  const instructionValue = instructions[instructionName];
1190
1190
  if (!(instructionValue && isObject(instructionValue)) || Object.keys(instructionValue).length === 0) {
1191
- throw new RoninError({
1191
+ throw new CompilerError({
1192
1192
  message: `When using a \`${queryType}\` query, the \`${instructionName}\` instruction must be a non-empty object.`,
1193
1193
  code: instructionName === "to" ? "INVALID_TO_VALUE" : "INVALID_WITH_VALUE",
1194
1194
  queries: [query]
@@ -1218,7 +1218,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1218
1218
  }
1219
1219
  if (instructions && (typeof instructions.before !== "undefined" || typeof instructions.after !== "undefined")) {
1220
1220
  if (single) {
1221
- throw new RoninError({
1221
+ throw new CompilerError({
1222
1222
  message: "The `before` and `after` instructions are not supported when querying for a single record.",
1223
1223
  code: "INVALID_BEFORE_OR_AFTER_INSTRUCTION",
1224
1224
  queries: [query]
@@ -1390,7 +1390,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
1390
1390
  if (modelField && fieldIsJSON && !valueIsJSON && value !== null) {
1391
1391
  const messagePrefix = "The provided field value is not";
1392
1392
  const message = modelField.type === "json" ? `${messagePrefix} valid JSON. Only objects and arrays should be provided. Other types of values should be stored in their respective primitive field types.` : `${messagePrefix} a valid Blob reference.`;
1393
- throw new RoninError({
1393
+ throw new CompilerError({
1394
1394
  message,
1395
1395
  field: modelField?.slug,
1396
1396
  code: "INVALID_FIELD_VALUE"
@@ -1454,7 +1454,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
1454
1454
  );
1455
1455
  return conditions.join(" OR ");
1456
1456
  }
1457
- throw new RoninError({
1457
+ throw new CompilerError({
1458
1458
  message: `The \`with\` instruction must not contain an empty field. The following fields are empty: \`${options.fieldSlug}\`. If you meant to query by an empty field, try using \`null\` instead.`,
1459
1459
  code: "INVALID_WITH_VALUE",
1460
1460
  queries: null
@@ -1524,7 +1524,7 @@ var getModelBySlug = (models, slug) => {
1524
1524
  return model2.slug === slug || model2.pluralSlug === slug;
1525
1525
  });
1526
1526
  if (!model) {
1527
- throw new RoninError({
1527
+ throw new CompilerError({
1528
1528
  message: `No matching model with either Slug or Plural Slug of "${slug}" could be found.`,
1529
1529
  code: "MODEL_NOT_FOUND"
1530
1530
  });
@@ -1562,7 +1562,7 @@ function getFieldFromModel(model, fieldPath, source, shouldThrow = true) {
1562
1562
  modelField = modelFields.find((field) => field.slug === fieldPath);
1563
1563
  if (!modelField) {
1564
1564
  if (shouldThrow) {
1565
- throw new RoninError({
1565
+ throw new CompilerError({
1566
1566
  message: `${errorPrefix} does not exist in model "${model.name}".`,
1567
1567
  code: "FIELD_NOT_FOUND",
1568
1568
  field: fieldPath,
@@ -1708,7 +1708,7 @@ var getFieldStatement = (models, model, field) => {
1708
1708
  if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
1709
1709
  if (field.type === "json") {
1710
1710
  if (!isObject(field.defaultValue)) {
1711
- throw new RoninError({
1711
+ throw new CompilerError({
1712
1712
  message: `The default value of JSON field "${field.slug}" must be an object.`,
1713
1713
  code: "INVALID_MODEL_VALUE",
1714
1714
  field: "fields"
@@ -1968,13 +1968,13 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
1968
1968
  const pluralType = PLURAL_MODEL_ENTITIES[entity];
1969
1969
  const existingEntity = existingModel[pluralType]?.[slug];
1970
1970
  if ((action === "alter" || action === "drop") && !existingEntity) {
1971
- throw new RoninError({
1971
+ throw new CompilerError({
1972
1972
  message: `No ${entity} with slug "${slug}" defined in model "${existingModel.name}".`,
1973
1973
  code: MODEL_ENTITY_ERROR_CODES[entity]
1974
1974
  });
1975
1975
  }
1976
1976
  if (action === "create" && existingEntity) {
1977
- throw new RoninError({
1977
+ throw new CompilerError({
1978
1978
  message: `A ${entity} with the slug "${slug}" already exists.`,
1979
1979
  code: "EXISTING_MODEL_ENTITY",
1980
1980
  fields: ["slug"]
@@ -2011,7 +2011,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
2011
2011
  const systemFields = getSystemFields(existingModel.idPrefix);
2012
2012
  const isSystemField = slug in systemFields;
2013
2013
  if (isSystemField) {
2014
- throw new RoninError({
2014
+ throw new CompilerError({
2015
2015
  message: `The ${entity} "${slug}" is a system ${entity} and cannot be removed.`,
2016
2016
  code: "REQUIRED_MODEL_ENTITY"
2017
2017
  });
@@ -2029,7 +2029,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
2029
2029
  let statement = `${statementAction}${index?.unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
2030
2030
  if (action === "create") {
2031
2031
  if (!Array.isArray(index.fields) || index.fields.length === 0) {
2032
- throw new RoninError({
2032
+ throw new CompilerError({
2033
2033
  message: `When ${actionReadable} ${PLURAL_MODEL_ENTITIES[entity]}, at least one field must be provided.`,
2034
2034
  code: "INVALID_MODEL_VALUE",
2035
2035
  field: PLURAL_MODEL_ENTITIES[entity]
@@ -2409,6 +2409,7 @@ var Transaction = class {
2409
2409
  };
2410
2410
  var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
2411
2411
  export {
2412
+ CompilerError,
2412
2413
  DDL_QUERY_TYPES,
2413
2414
  DDL_QUERY_TYPES_READ,
2414
2415
  DDL_QUERY_TYPES_WRITE,
@@ -2420,7 +2421,6 @@ export {
2420
2421
  QUERY_TYPES_READ,
2421
2422
  QUERY_TYPES_WRITE,
2422
2423
  CLEAN_ROOT_MODEL as ROOT_MODEL,
2423
- RoninError,
2424
2424
  Transaction,
2425
2425
  getQuerySymbol
2426
2426
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.18.9",
3
+ "version": "0.18.10",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {