@ronin/compiler 0.18.8 → 0.18.9-ronin-error-experimental-453

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
@@ -4,8 +4,16 @@ declare const DML_QUERY_TYPES_READ: readonly ["get", "count"];
4
4
  declare const DML_QUERY_TYPES_WRITE: readonly ["set", "add", "remove"];
5
5
  /** Query types used for interacting with data. */
6
6
  declare const DML_QUERY_TYPES: readonly ["get", "count", "set", "add", "remove"];
7
+ /** Query types used for reading the database schema. */
8
+ declare const DDL_QUERY_TYPES_READ: readonly ["list"];
9
+ /** Query types used for writing the database schema. */
10
+ declare const DDL_QUERY_TYPES_WRITE: readonly ["create", "alter", "drop"];
7
11
  /** Query types used for interacting with the database schema. */
8
12
  declare const DDL_QUERY_TYPES: readonly ["list", "create", "alter", "drop"];
13
+ /** All read query types. */
14
+ declare const QUERY_TYPES_READ: readonly ["get", "count", "list"];
15
+ /** All write query types. */
16
+ declare const QUERY_TYPES_WRITE: readonly ["set", "add", "remove", "create", "alter", "drop"];
9
17
  /** All query types. */
10
18
  declare const QUERY_TYPES: readonly ["get", "count", "set", "add", "remove", "list", "create", "alter", "drop"];
11
19
  /**
@@ -390,20 +398,20 @@ type ExpandedResult<T = ResultRecord> = {
390
398
  };
391
399
  type Result<T = ResultRecord> = RegularResult<T> | ExpandedResult<T>;
392
400
 
393
- 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';
394
402
  interface Issue {
395
403
  message: string;
396
404
  path: Array<string | number>;
397
405
  }
398
406
  interface Details {
399
407
  message: string;
400
- code: RoninErrorCode;
408
+ code: CompilerErrorCode;
401
409
  field?: string;
402
410
  fields?: Array<string>;
403
411
  issues?: Array<Issue>;
404
412
  queries?: Array<Query> | null;
405
413
  }
406
- declare class RoninError extends Error {
414
+ declare class CompilerError extends Error {
407
415
  code: Details['code'];
408
416
  field?: Details['field'];
409
417
  fields?: Details['fields'];
@@ -466,4 +474,4 @@ declare class Transaction {
466
474
 
467
475
  declare const CLEAN_ROOT_MODEL: PublicModel;
468
476
 
469
- 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, 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, 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
@@ -5,7 +5,20 @@ var DML_QUERY_TYPES = [
5
5
  ...DML_QUERY_TYPES_READ,
6
6
  ...DML_QUERY_TYPES_WRITE
7
7
  ];
8
- var DDL_QUERY_TYPES = ["list", "create", "alter", "drop"];
8
+ var DDL_QUERY_TYPES_READ = ["list"];
9
+ var DDL_QUERY_TYPES_WRITE = ["create", "alter", "drop"];
10
+ var DDL_QUERY_TYPES = [
11
+ ...DDL_QUERY_TYPES_READ,
12
+ ...DDL_QUERY_TYPES_WRITE
13
+ ];
14
+ var QUERY_TYPES_READ = [
15
+ ...DML_QUERY_TYPES_READ,
16
+ ...DDL_QUERY_TYPES_READ
17
+ ];
18
+ var QUERY_TYPES_WRITE = [
19
+ ...DML_QUERY_TYPES_WRITE,
20
+ ...DDL_QUERY_TYPES_WRITE
21
+ ];
9
22
  var QUERY_TYPES = [...DML_QUERY_TYPES, ...DDL_QUERY_TYPES];
10
23
  var QUERY_SYMBOLS = {
11
24
  // Represents a sub query.
@@ -44,7 +57,7 @@ var MODEL_ENTITY_ERROR_CODES = {
44
57
  index: "INDEX_NOT_FOUND",
45
58
  preset: "PRESET_NOT_FOUND"
46
59
  };
47
- var RoninError = class extends Error {
60
+ var CompilerError = class extends Error {
48
61
  code;
49
62
  field;
50
63
  fields;
@@ -52,7 +65,7 @@ var RoninError = class extends Error {
52
65
  queries;
53
66
  constructor(details) {
54
67
  super(details.message);
55
- this.name = "RoninError";
68
+ this.name = "CompilerError";
56
69
  this.code = details.code;
57
70
  this.field = details.field;
58
71
  this.fields = details.fields;
@@ -198,13 +211,13 @@ var generatePaginationCursor = (model, orderedBy, record) => {
198
211
  // src/instructions/before-after.ts
199
212
  var handleBeforeOrAfter = (model, statementParams, queryType, instructions) => {
200
213
  if (!(instructions.before || instructions.after)) {
201
- throw new RoninError({
214
+ throw new CompilerError({
202
215
  message: "The `before` or `after` instruction must not be empty.",
203
216
  code: "MISSING_INSTRUCTION"
204
217
  });
205
218
  }
206
219
  if (instructions.before && instructions.after) {
207
- throw new RoninError({
220
+ throw new CompilerError({
208
221
  message: "The `before` and `after` instructions cannot co-exist. Choose one.",
209
222
  code: "MUTUALLY_EXCLUSIVE_INSTRUCTIONS"
210
223
  });
@@ -213,7 +226,7 @@ var handleBeforeOrAfter = (model, statementParams, queryType, instructions) => {
213
226
  let message = "When providing a pagination cursor in the `before` or `after`";
214
227
  message += " instruction, a `limitedTo` instruction must be provided as well, to";
215
228
  message += " define the page size.";
216
- throw new RoninError({
229
+ throw new CompilerError({
217
230
  message,
218
231
  code: "MISSING_INSTRUCTION"
219
232
  });
@@ -1025,7 +1038,7 @@ var handleUsing = (model, instructions) => {
1025
1038
  const arg = normalizedUsing[presetSlug];
1026
1039
  const preset = model.presets?.[presetSlug];
1027
1040
  if (!preset) {
1028
- throw new RoninError({
1041
+ throw new CompilerError({
1029
1042
  message: `Preset "${presetSlug}" does not exist in model "${model.name}".`,
1030
1043
  code: "PRESET_NOT_FOUND"
1031
1044
  });
@@ -1175,7 +1188,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1175
1188
  const instructionName = queryType === "add" ? "with" : "to";
1176
1189
  const instructionValue = instructions[instructionName];
1177
1190
  if (!(instructionValue && isObject(instructionValue)) || Object.keys(instructionValue).length === 0) {
1178
- throw new RoninError({
1191
+ throw new CompilerError({
1179
1192
  message: `When using a \`${queryType}\` query, the \`${instructionName}\` instruction must be a non-empty object.`,
1180
1193
  code: instructionName === "to" ? "INVALID_TO_VALUE" : "INVALID_WITH_VALUE",
1181
1194
  queries: [query]
@@ -1205,7 +1218,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1205
1218
  }
1206
1219
  if (instructions && (typeof instructions.before !== "undefined" || typeof instructions.after !== "undefined")) {
1207
1220
  if (single) {
1208
- throw new RoninError({
1221
+ throw new CompilerError({
1209
1222
  message: "The `before` and `after` instructions are not supported when querying for a single record.",
1210
1223
  code: "INVALID_BEFORE_OR_AFTER_INSTRUCTION",
1211
1224
  queries: [query]
@@ -1377,7 +1390,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
1377
1390
  if (modelField && fieldIsJSON && !valueIsJSON && value !== null) {
1378
1391
  const messagePrefix = "The provided field value is not";
1379
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.`;
1380
- throw new RoninError({
1393
+ throw new CompilerError({
1381
1394
  message,
1382
1395
  field: modelField?.slug,
1383
1396
  code: "INVALID_FIELD_VALUE"
@@ -1441,7 +1454,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
1441
1454
  );
1442
1455
  return conditions.join(" OR ");
1443
1456
  }
1444
- throw new RoninError({
1457
+ throw new CompilerError({
1445
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.`,
1446
1459
  code: "INVALID_WITH_VALUE",
1447
1460
  queries: null
@@ -1511,7 +1524,7 @@ var getModelBySlug = (models, slug) => {
1511
1524
  return model2.slug === slug || model2.pluralSlug === slug;
1512
1525
  });
1513
1526
  if (!model) {
1514
- throw new RoninError({
1527
+ throw new CompilerError({
1515
1528
  message: `No matching model with either Slug or Plural Slug of "${slug}" could be found.`,
1516
1529
  code: "MODEL_NOT_FOUND"
1517
1530
  });
@@ -1549,7 +1562,7 @@ function getFieldFromModel(model, fieldPath, source, shouldThrow = true) {
1549
1562
  modelField = modelFields.find((field) => field.slug === fieldPath);
1550
1563
  if (!modelField) {
1551
1564
  if (shouldThrow) {
1552
- throw new RoninError({
1565
+ throw new CompilerError({
1553
1566
  message: `${errorPrefix} does not exist in model "${model.name}".`,
1554
1567
  code: "FIELD_NOT_FOUND",
1555
1568
  field: fieldPath,
@@ -1695,7 +1708,7 @@ var getFieldStatement = (models, model, field) => {
1695
1708
  if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
1696
1709
  if (field.type === "json") {
1697
1710
  if (!isObject(field.defaultValue)) {
1698
- throw new RoninError({
1711
+ throw new CompilerError({
1699
1712
  message: `The default value of JSON field "${field.slug}" must be an object.`,
1700
1713
  code: "INVALID_MODEL_VALUE",
1701
1714
  field: "fields"
@@ -1955,13 +1968,13 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
1955
1968
  const pluralType = PLURAL_MODEL_ENTITIES[entity];
1956
1969
  const existingEntity = existingModel[pluralType]?.[slug];
1957
1970
  if ((action === "alter" || action === "drop") && !existingEntity) {
1958
- throw new RoninError({
1971
+ throw new CompilerError({
1959
1972
  message: `No ${entity} with slug "${slug}" defined in model "${existingModel.name}".`,
1960
1973
  code: MODEL_ENTITY_ERROR_CODES[entity]
1961
1974
  });
1962
1975
  }
1963
1976
  if (action === "create" && existingEntity) {
1964
- throw new RoninError({
1977
+ throw new CompilerError({
1965
1978
  message: `A ${entity} with the slug "${slug}" already exists.`,
1966
1979
  code: "EXISTING_MODEL_ENTITY",
1967
1980
  fields: ["slug"]
@@ -1998,7 +2011,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
1998
2011
  const systemFields = getSystemFields(existingModel.idPrefix);
1999
2012
  const isSystemField = slug in systemFields;
2000
2013
  if (isSystemField) {
2001
- throw new RoninError({
2014
+ throw new CompilerError({
2002
2015
  message: `The ${entity} "${slug}" is a system ${entity} and cannot be removed.`,
2003
2016
  code: "REQUIRED_MODEL_ENTITY"
2004
2017
  });
@@ -2016,7 +2029,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
2016
2029
  let statement = `${statementAction}${index?.unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
2017
2030
  if (action === "create") {
2018
2031
  if (!Array.isArray(index.fields) || index.fields.length === 0) {
2019
- throw new RoninError({
2032
+ throw new CompilerError({
2020
2033
  message: `When ${actionReadable} ${PLURAL_MODEL_ENTITIES[entity]}, at least one field must be provided.`,
2021
2034
  code: "INVALID_MODEL_VALUE",
2022
2035
  field: PLURAL_MODEL_ENTITIES[entity]
@@ -2396,14 +2409,18 @@ var Transaction = class {
2396
2409
  };
2397
2410
  var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
2398
2411
  export {
2412
+ CompilerError,
2399
2413
  DDL_QUERY_TYPES,
2414
+ DDL_QUERY_TYPES_READ,
2415
+ DDL_QUERY_TYPES_WRITE,
2400
2416
  DML_QUERY_TYPES,
2401
2417
  DML_QUERY_TYPES_READ,
2402
2418
  DML_QUERY_TYPES_WRITE,
2403
2419
  QUERY_SYMBOLS,
2404
2420
  QUERY_TYPES,
2421
+ QUERY_TYPES_READ,
2422
+ QUERY_TYPES_WRITE,
2405
2423
  CLEAN_ROOT_MODEL as ROOT_MODEL,
2406
- RoninError,
2407
2424
  Transaction,
2408
2425
  getQuerySymbol
2409
2426
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.18.8",
3
+ "version": "0.18.9-ronin-error-experimental-453",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {