@ronin/compiler 0.17.12 → 0.17.13-leo-ron-1113-experimental-403

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
@@ -1,3 +1,11 @@
1
+ /** Query types used for reading data. */
2
+ declare const DML_READ_QUERY_TYPES: readonly ["get", "count"];
3
+ /** Query types used for writing data. */
4
+ declare const DML_WRITE_QUERY_TYPES: readonly ["set", "add", "remove"];
5
+ /** Query types used for interacting with data. */
6
+ declare const DML_QUERY_TYPES: readonly ["get", "count", "set", "add", "remove"];
7
+ /** Query types used for interacting with the database schema. */
8
+ declare const DDL_QUERY_TYPES: readonly ["create", "alter", "drop"];
1
9
  /**
2
10
  * A list of placeholders that can be located inside queries after those queries were
3
11
  * serialized into JSON objects.
@@ -15,46 +23,9 @@ declare const QUERY_SYMBOLS: {
15
23
  readonly FIELD_PARENT_NEW: "__RONIN_FIELD_PARENT_NEW_";
16
24
  readonly VALUE: "__RONIN_VALUE";
17
25
  };
18
- 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' | 'EXISTING_MODEL_ENTITY' | 'REQUIRED_MODEL_ENTITY' | 'MUTUALLY_EXCLUSIVE_INSTRUCTIONS' | 'MISSING_INSTRUCTION' | 'MISSING_FIELD';
19
- interface Issue {
20
- message: string;
21
- path: Array<string | number>;
22
- }
23
- interface Details {
24
- message: string;
25
- code: RoninErrorCode;
26
- field?: string;
27
- fields?: Array<string>;
28
- issues?: Array<Issue>;
29
- queries?: Array<Query> | null;
30
- }
31
- declare class RoninError extends Error {
32
- code: Details['code'];
33
- field?: Details['field'];
34
- fields?: Details['fields'];
35
- issues?: Details['issues'];
36
- queries?: Details['queries'];
37
- constructor(details: Details);
38
- }
39
- /**
40
- * Checks if the provided value contains a RONIN model symbol (a represenation of a
41
- * particular entity inside a query, such as an expression or a sub query) and returns
42
- * its type and value.
43
- *
44
- * @param value - The value that should be checked.
45
- *
46
- * @returns The type and value of the symbol, if the provided value contains one.
47
- */
48
- declare const getQuerySymbol: (value: unknown) => {
49
- type: "query";
50
- value: Query;
51
- } | {
52
- type: "expression";
53
- value: string;
54
- } | null;
55
26
 
56
- type QueryTypeEnum = 'get' | 'set' | 'add' | 'remove' | 'count';
57
- type ModelQueryTypeEnum = 'create' | 'alter' | 'drop';
27
+ type QueryTypeEnum = (typeof DML_QUERY_TYPES)[number];
28
+ type ModelQueryTypeEnum = (typeof DDL_QUERY_TYPES)[number];
58
29
  type ModelEntityEnum = 'field' | 'index' | 'trigger' | 'preset';
59
30
  type FieldValue = string | number | boolean | null | unknown;
60
31
  type FieldSelector = Record<string, FieldValue | StoredObject>;
@@ -150,23 +121,23 @@ type AlterQuery = {
150
121
  model: string;
151
122
  to?: Partial<Omit<PublicModel, 'fields' | 'indexes' | 'triggers' | 'presets' | 'idPrefix'>>;
152
123
  create?: {
153
- field?: ModelField;
154
- index?: ModelIndex;
155
- trigger?: ModelTrigger;
156
- preset?: ModelPreset;
124
+ field?: Omit<ModelField, 'system'>;
125
+ index?: Omit<ModelIndex, 'system'>;
126
+ trigger?: Omit<ModelTrigger, 'system'>;
127
+ preset?: Omit<ModelPreset, 'system'>;
157
128
  };
158
129
  alter?: {
159
130
  field?: string;
160
- to?: Partial<ModelField>;
131
+ to?: Partial<Omit<ModelField, 'system'>>;
161
132
  } | {
162
133
  index?: string;
163
- to?: Partial<ModelIndex>;
134
+ to?: Partial<Omit<ModelIndex, 'system'>>;
164
135
  } | {
165
136
  trigger?: string;
166
- to?: Partial<ModelTrigger>;
137
+ to?: Omit<ModelTrigger, 'system'>;
167
138
  } | {
168
139
  preset?: string;
169
- to?: Partial<ModelPreset>;
140
+ to?: Omit<ModelPreset, 'system'>;
170
141
  };
171
142
  drop?: Partial<Record<ModelEntityEnum, string>>;
172
143
  };
@@ -227,6 +198,8 @@ type ModelFieldBasics = {
227
198
  };
228
199
  /** An expression that gets evaluated every time a value is provided for the field. */
229
200
  check?: Expression;
201
+ /** Whether the field was automatically added by RONIN. */
202
+ system?: boolean;
230
203
  };
231
204
  type ModelField = ModelFieldBasics & ({
232
205
  /** The kind of value that should be stored inside the field. */
@@ -340,10 +313,14 @@ type ModelTrigger<T extends ModelEntityList<ModelField> = ModelEntityList<ModelF
340
313
  filter?: WithInstruction;
341
314
  };
342
315
  type ModelPreset = {
316
+ /** The visual display name of the preset. */
317
+ name?: string;
343
318
  /** The identifier that can be used for adding the preset to a query. */
344
319
  slug: string;
345
320
  /** The query instructions that should be applied when the preset is used. */
346
321
  instructions: GetInstructions;
322
+ /** Whether the preset was automatically added by RONIN. */
323
+ system?: boolean;
347
324
  };
348
325
  type ModelEntityList<T extends {
349
326
  slug: string;
@@ -420,6 +397,44 @@ type ExpandedResult<T = ResultRecord> = {
420
397
  };
421
398
  type Result<T = ResultRecord> = RegularResult<T> | ExpandedResult<T>;
422
399
 
400
+ 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' | 'EXISTING_MODEL_ENTITY' | 'REQUIRED_MODEL_ENTITY' | 'MUTUALLY_EXCLUSIVE_INSTRUCTIONS' | 'MISSING_INSTRUCTION' | 'MISSING_FIELD';
401
+ interface Issue {
402
+ message: string;
403
+ path: Array<string | number>;
404
+ }
405
+ interface Details {
406
+ message: string;
407
+ code: RoninErrorCode;
408
+ field?: string;
409
+ fields?: Array<string>;
410
+ issues?: Array<Issue>;
411
+ queries?: Array<Query> | null;
412
+ }
413
+ declare class RoninError extends Error {
414
+ code: Details['code'];
415
+ field?: Details['field'];
416
+ fields?: Details['fields'];
417
+ issues?: Details['issues'];
418
+ queries?: Details['queries'];
419
+ constructor(details: Details);
420
+ }
421
+ /**
422
+ * Checks if the provided value contains a RONIN model symbol (a represenation of a
423
+ * particular entity inside a query, such as an expression or a sub query) and returns
424
+ * its type and value.
425
+ *
426
+ * @param value - The value that should be checked.
427
+ *
428
+ * @returns The type and value of the symbol, if the provided value contains one.
429
+ */
430
+ declare const getQuerySymbol: (value: unknown) => {
431
+ type: "query";
432
+ value: Query;
433
+ } | {
434
+ type: "expression";
435
+ value: string;
436
+ } | null;
437
+
423
438
  interface TransactionOptions {
424
439
  /** A list of models that already exist in the database. */
425
440
  models?: Array<PublicModel>;
@@ -458,4 +473,4 @@ declare class Transaction {
458
473
 
459
474
  declare const CLEAN_ROOT_MODEL: PublicModel;
460
475
 
461
- export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, type DropQuery, type ExpandedResult, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, 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, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
476
+ 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_READ_QUERY_TYPES, DML_WRITE_QUERY_TYPES, type DropQuery, type ExpandedResult, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, 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, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
package/dist/index.js CHANGED
@@ -1,4 +1,11 @@
1
- // src/utils/helpers.ts
1
+ // src/utils/constants.ts
2
+ var DML_READ_QUERY_TYPES = ["get", "count"];
3
+ var DML_WRITE_QUERY_TYPES = ["set", "add", "remove"];
4
+ var DML_QUERY_TYPES = [
5
+ ...DML_READ_QUERY_TYPES,
6
+ ...DML_WRITE_QUERY_TYPES
7
+ ];
8
+ var DDL_QUERY_TYPES = ["create", "alter", "drop"];
2
9
  var QUERY_SYMBOLS = {
3
10
  // Represents a sub query.
4
11
  QUERY: "__RONIN_QUERY",
@@ -24,6 +31,8 @@ var CURRENT_TIME_EXPRESSION = {
24
31
  [QUERY_SYMBOLS.EXPRESSION]: `strftime('%Y-%m-%dT%H:%M:%f', 'now') || 'Z'`
25
32
  };
26
33
  var MOUNTING_PATH_SUFFIX = /(.*?)(\{(\d+)\})?$/;
34
+
35
+ // src/utils/helpers.ts
27
36
  var composeMountingPath = (single, key, mountingPath) => {
28
37
  if (key === "ronin_root") {
29
38
  return mountingPath ? mountingPath.replace(
@@ -764,7 +773,9 @@ var addDefaultModelPresets = (list, model) => {
764
773
  }
765
774
  }
766
775
  }
767
- }
776
+ },
777
+ name: slugToName(fieldSlug),
778
+ system: true
768
779
  };
769
780
  defaultPresets[fieldSlug] = preset2;
770
781
  continue;
@@ -788,7 +799,9 @@ var addDefaultModelPresets = (list, model) => {
788
799
  }
789
800
  }
790
801
  }
791
- }
802
+ },
803
+ name: slugToName(fieldSlug),
804
+ system: true
792
805
  };
793
806
  defaultPresets[fieldSlug] = preset;
794
807
  }
@@ -823,7 +836,9 @@ var addDefaultModelPresets = (list, model) => {
823
836
  }
824
837
  }
825
838
  }
826
- }
839
+ },
840
+ name: slugToName(presetSlug),
841
+ system: true
827
842
  };
828
843
  defaultPresets[presetSlug] = preset;
829
844
  }
@@ -1186,7 +1201,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1186
1201
  if (queryType === "get" && !isJoiningMultipleRows && (single || instructions?.limitedTo)) {
1187
1202
  statement += handleLimitedTo(single, instructions?.limitedTo);
1188
1203
  }
1189
- if (["add", "set", "remove"].includes(queryType) && returning) {
1204
+ if (DML_WRITE_QUERY_TYPES.includes(queryType) && returning) {
1190
1205
  statement += `RETURNING ${columns}`;
1191
1206
  }
1192
1207
  const mainStatement = {
@@ -1511,25 +1526,30 @@ var getSystemFields = (idPrefix) => ({
1511
1526
  // cannot rely on the `idPrefix` column here. Instead, we need to inject it
1512
1527
  // directly into the expression as a static string.
1513
1528
  [QUERY_SYMBOLS.EXPRESSION]: `'${idPrefix}_' || lower(substr(hex(randomblob(12)), 1, 16))`
1514
- }
1529
+ },
1530
+ system: true
1515
1531
  },
1516
1532
  "ronin.createdAt": {
1517
1533
  name: "RONIN - Created At",
1518
1534
  type: "date",
1519
- defaultValue: CURRENT_TIME_EXPRESSION
1535
+ defaultValue: CURRENT_TIME_EXPRESSION,
1536
+ system: true
1520
1537
  },
1521
1538
  "ronin.createdBy": {
1522
1539
  name: "RONIN - Created By",
1523
- type: "string"
1540
+ type: "string",
1541
+ system: true
1524
1542
  },
1525
1543
  "ronin.updatedAt": {
1526
1544
  name: "RONIN - Updated At",
1527
1545
  type: "date",
1528
- defaultValue: CURRENT_TIME_EXPRESSION
1546
+ defaultValue: CURRENT_TIME_EXPRESSION,
1547
+ system: true
1529
1548
  },
1530
1549
  "ronin.updatedBy": {
1531
1550
  name: "RONIN - Updated By",
1532
- type: "string"
1551
+ type: "string",
1552
+ system: true
1533
1553
  }
1534
1554
  });
1535
1555
  var ROOT_MODEL = {
@@ -2356,6 +2376,10 @@ var Transaction = class {
2356
2376
  };
2357
2377
  var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
2358
2378
  export {
2379
+ DDL_QUERY_TYPES,
2380
+ DML_QUERY_TYPES,
2381
+ DML_READ_QUERY_TYPES,
2382
+ DML_WRITE_QUERY_TYPES,
2359
2383
  QUERY_SYMBOLS,
2360
2384
  CLEAN_ROOT_MODEL as ROOT_MODEL,
2361
2385
  RoninError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.17.12",
3
+ "version": "0.17.13-leo-ron-1113-experimental-403",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {