@ronin/compiler 0.14.1 → 0.14.2

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
@@ -36,6 +36,22 @@ declare class RoninError extends Error {
36
36
  queries?: Details['queries'];
37
37
  constructor(details: Details);
38
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;
39
55
 
40
56
  type QueryTypeEnum = 'get' | 'set' | 'add' | 'remove' | 'count';
41
57
  type ModelQueryTypeEnum = 'create' | 'alter' | 'drop';
@@ -378,4 +394,4 @@ declare class Transaction {
378
394
 
379
395
  declare const CLEAN_ROOT_MODEL: PublicModel;
380
396
 
381
- export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, 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 RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, Transaction, type WithInstruction };
397
+ export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, 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 RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, Transaction, type WithInstruction, getQuerySymbol };
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@ var convertToCamelCase = (str) => {
70
70
  return sanitize(str).split(SPLIT_REGEX).map((part, index) => index === 0 ? part.toLowerCase() : capitalize(part)).join("");
71
71
  };
72
72
  var isObject = (value) => value != null && typeof value === "object" && Array.isArray(value) === false;
73
- var getSymbol = (value) => {
73
+ var getQuerySymbol = (value) => {
74
74
  if (!isObject(value)) return null;
75
75
  const objectValue = value;
76
76
  if (QUERY_SYMBOLS.QUERY in objectValue) {
@@ -110,7 +110,7 @@ var flatten = (obj, prefix = "", res = {}) => {
110
110
  if (!Object.hasOwn(obj, key)) continue;
111
111
  const path = prefix ? `${prefix}.${key}` : key;
112
112
  const value = obj[key];
113
- if (typeof value === "object" && value !== null && !getSymbol(value)) {
113
+ if (typeof value === "object" && value !== null && !getQuerySymbol(value)) {
114
114
  flatten(value, path, res);
115
115
  } else {
116
116
  res[path] = value;
@@ -304,7 +304,7 @@ var handleIncluding = (models, model, statementParams, single, instruction) => {
304
304
  let tableSubQuery;
305
305
  for (const ephemeralFieldSlug in instruction) {
306
306
  if (!Object.hasOwn(instruction, ephemeralFieldSlug)) continue;
307
- const symbol = getSymbol(instruction[ephemeralFieldSlug]);
307
+ const symbol = getQuerySymbol(instruction[ephemeralFieldSlug]);
308
308
  if (symbol?.type !== "query") continue;
309
309
  const { queryType, queryModel, queryInstructions } = splitQuery(symbol.value);
310
310
  let modifiableQueryInstructions = queryInstructions;
@@ -383,7 +383,7 @@ var handleOrderedBy = (model, instruction) => {
383
383
  if (statement.length > 0) {
384
384
  statement += ", ";
385
385
  }
386
- const symbol = getSymbol(item.value);
386
+ const symbol = getQuerySymbol(item.value);
387
387
  const instructionName = item.order === "ASC" ? "orderedBy.ascending" : "orderedBy.descending";
388
388
  if (symbol?.type === "expression") {
389
389
  statement += `(${parseFieldExpression(model, instructionName, symbol.value)}) ${item.order}`;
@@ -419,14 +419,14 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
419
419
  const joinedSelectedFields = [];
420
420
  const joinedColumns = [];
421
421
  if (instructions.including) {
422
- const symbol = getSymbol(instructions.including);
422
+ const symbol = getQuerySymbol(instructions.including);
423
423
  if (symbol?.type === "query") {
424
424
  instructions.including.ronin_root = { ...instructions.including };
425
425
  delete instructions.including[QUERY_SYMBOLS.QUERY];
426
426
  }
427
427
  const flatObject = flatten(instructions.including);
428
428
  for (const [key, value] of Object.entries(flatObject)) {
429
- const symbol2 = getSymbol(value);
429
+ const symbol2 = getQuerySymbol(value);
430
430
  if (symbol2?.type === "query") {
431
431
  const { queryModel, queryInstructions } = splitQuery(symbol2.value);
432
432
  const subQueryModel = getModelBySlug(models, queryModel);
@@ -504,7 +504,7 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
504
504
  ...toInstruction.ronin
505
505
  };
506
506
  }
507
- const symbol = getSymbol(toInstruction);
507
+ const symbol = getQuerySymbol(toInstruction);
508
508
  if (symbol?.type === "query") {
509
509
  const { queryModel: subQueryModelSlug, queryInstructions: subQueryInstructions } = splitQuery(symbol.value);
510
510
  const subQueryModel = getModelBySlug(models, subQueryModelSlug);
@@ -802,7 +802,7 @@ var composeFieldValues = (models, model, statementParams, instructionName, value
802
802
  { instructionName }
803
803
  );
804
804
  const collectStatementValue = options.type !== "fields";
805
- const symbol = getSymbol(value);
805
+ const symbol = getQuerySymbol(value);
806
806
  let conditionMatcher = "=";
807
807
  let conditionValue = value;
808
808
  if (options.condition) {
@@ -848,7 +848,7 @@ var composeConditions = (models, model, statementParams, instructionName, value,
848
848
  });
849
849
  const { field: modelField } = fieldDetails || {};
850
850
  const consumeJSON = modelField?.type === "json" && instructionName === "to";
851
- if (modelField && !(isObject(value) || Array.isArray(value)) || getSymbol(value) || consumeJSON) {
851
+ if (modelField && !(isObject(value) || Array.isArray(value)) || getQuerySymbol(value) || consumeJSON) {
852
852
  return composeFieldValues(
853
853
  models,
854
854
  model,
@@ -1507,7 +1507,7 @@ var getFieldStatement = (models, model, field) => {
1507
1507
  if (field.unique === true) statement += " UNIQUE";
1508
1508
  if (field.required === true) statement += " NOT NULL";
1509
1509
  if (typeof field.defaultValue !== "undefined") {
1510
- const symbol = getSymbol(field.defaultValue);
1510
+ const symbol = getQuerySymbol(field.defaultValue);
1511
1511
  let value = typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue;
1512
1512
  if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
1513
1513
  statement += ` DEFAULT ${value}`;
@@ -1519,12 +1519,12 @@ var getFieldStatement = (models, model, field) => {
1519
1519
  statement += " AUTOINCREMENT";
1520
1520
  }
1521
1521
  if (typeof field.check !== "undefined") {
1522
- const symbol = getSymbol(field.check);
1522
+ const symbol = getQuerySymbol(field.check);
1523
1523
  statement += ` CHECK (${parseFieldExpression(model, "to", symbol?.value)})`;
1524
1524
  }
1525
1525
  if (typeof field.computedAs !== "undefined") {
1526
1526
  const { kind, value } = field.computedAs;
1527
- const symbol = getSymbol(value);
1527
+ const symbol = getQuerySymbol(value);
1528
1528
  statement += ` GENERATED ALWAYS AS (${parseFieldExpression(model, "to", symbol?.value)}) ${kind}`;
1529
1529
  }
1530
1530
  if (field.type === "link") {
@@ -2090,5 +2090,6 @@ export {
2090
2090
  QUERY_SYMBOLS,
2091
2091
  CLEAN_ROOT_MODEL as ROOT_MODEL,
2092
2092
  RoninError,
2093
- Transaction
2093
+ Transaction,
2094
+ getQuerySymbol
2094
2095
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {