@ronin/compiler 0.17.14 → 0.17.15-leo-ron-1113-experimental-406

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,11 +1,13 @@
1
1
  /** Query types used for reading data. */
2
- declare const DML_READ_QUERY_TYPES: readonly ["get", "count"];
2
+ declare const DML_QUERY_TYPES_READ: readonly ["get", "count"];
3
3
  /** Query types used for writing data. */
4
- declare const DML_WRITE_QUERY_TYPES: readonly ["set", "add", "remove"];
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
7
  /** Query types used for interacting with the database schema. */
8
8
  declare const DDL_QUERY_TYPES: readonly ["create", "alter", "drop"];
9
+ /** All query types. */
10
+ declare const QUERY_TYPES: readonly ["get", "count", "set", "add", "remove", "create", "alter", "drop"];
9
11
  /**
10
12
  * A list of placeholders that can be located inside queries after those queries were
11
13
  * serialized into JSON objects.
@@ -473,4 +475,4 @@ declare class Transaction {
473
475
 
474
476
  declare const CLEAN_ROOT_MODEL: PublicModel;
475
477
 
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 };
478
+ 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 PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, 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, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  // src/utils/constants.ts
2
- var DML_READ_QUERY_TYPES = ["get", "count"];
3
- var DML_WRITE_QUERY_TYPES = ["set", "add", "remove"];
2
+ var DML_QUERY_TYPES_READ = ["get", "count"];
3
+ var DML_QUERY_TYPES_WRITE = ["set", "add", "remove"];
4
4
  var DML_QUERY_TYPES = [
5
- ...DML_READ_QUERY_TYPES,
6
- ...DML_WRITE_QUERY_TYPES
5
+ ...DML_QUERY_TYPES_READ,
6
+ ...DML_QUERY_TYPES_WRITE
7
7
  ];
8
8
  var DDL_QUERY_TYPES = ["create", "alter", "drop"];
9
+ var QUERY_TYPES = [...DML_QUERY_TYPES, ...DDL_QUERY_TYPES];
9
10
  var QUERY_SYMBOLS = {
10
11
  // Represents a sub query.
11
12
  QUERY: "__RONIN_QUERY",
@@ -1201,7 +1202,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1201
1202
  if (queryType === "get" && !isJoiningMultipleRows && (single || instructions?.limitedTo)) {
1202
1203
  statement += handleLimitedTo(single, instructions?.limitedTo);
1203
1204
  }
1204
- if (DML_WRITE_QUERY_TYPES.includes(queryType) && returning) {
1205
+ if (DML_QUERY_TYPES_WRITE.includes(queryType) && returning) {
1205
1206
  statement += `RETURNING ${columns}`;
1206
1207
  }
1207
1208
  const mainStatement = {
@@ -1252,18 +1253,18 @@ var filterSelectedFields = (model, instruction) => {
1252
1253
  return selectedFields;
1253
1254
  };
1254
1255
  var prepareStatementValue = (statementParams, value) => {
1256
+ const inlineParams = !statementParams;
1255
1257
  if (value === null) return "NULL";
1256
- if (!statementParams) {
1257
- if (typeof value === "string") return `'${value}'`;
1258
- const valueString = typeof value === "object" ? `json('${JSON.stringify(value, replaceJSON)}')` : value.toString();
1259
- return valueString;
1260
- }
1261
1258
  let formattedValue = value;
1262
1259
  if (Array.isArray(value) || isObject(value)) {
1263
- formattedValue = JSON.stringify(value);
1260
+ formattedValue = JSON.stringify(value, inlineParams ? replaceJSON : void 0);
1264
1261
  } else if (typeof value === "boolean") {
1265
1262
  formattedValue = value ? 1 : 0;
1266
1263
  }
1264
+ if (!statementParams) {
1265
+ if (typeof formattedValue === "string") return `'${formattedValue}'`;
1266
+ return formattedValue.toString();
1267
+ }
1267
1268
  const index = statementParams.push(formattedValue);
1268
1269
  return `?${index}`;
1269
1270
  };
@@ -2037,7 +2038,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
2037
2038
  case "create": {
2038
2039
  const { slug: slug2, ...entityValue } = jsonValue;
2039
2040
  const value = prepareStatementValue(statementParams, entityValue);
2040
- json = `json_insert(${field}, '$.${slug2}', ${value})`;
2041
+ json = `json_insert(${field}, '$.${slug2}', json(${value}))`;
2041
2042
  if (!existingModel[pluralType]) existingModel[pluralType] = {};
2042
2043
  existingModel[pluralType][slug2] = jsonValue;
2043
2044
  break;
@@ -2054,7 +2055,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query,
2054
2055
  Object.assign(targetEntities[newSlug], entityValue);
2055
2056
  delete targetEntities[slug];
2056
2057
  const value = prepareStatementValue(statementParams, targetEntities[newSlug]);
2057
- json = `json_insert(json_remove(${field}, '$.${slug}'), '$.${newSlug}', ${value})`;
2058
+ json = `json_insert(json_remove(${field}, '$.${slug}'), '$.${newSlug}', json(${value}))`;
2058
2059
  } else {
2059
2060
  Object.assign(targetEntities[slug], jsonValue);
2060
2061
  const value = prepareStatementValue(statementParams, jsonValue);
@@ -2378,9 +2379,10 @@ var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
2378
2379
  export {
2379
2380
  DDL_QUERY_TYPES,
2380
2381
  DML_QUERY_TYPES,
2381
- DML_READ_QUERY_TYPES,
2382
- DML_WRITE_QUERY_TYPES,
2382
+ DML_QUERY_TYPES_READ,
2383
+ DML_QUERY_TYPES_WRITE,
2383
2384
  QUERY_SYMBOLS,
2385
+ QUERY_TYPES,
2384
2386
  CLEAN_ROOT_MODEL as ROOT_MODEL,
2385
2387
  RoninError,
2386
2388
  Transaction,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.17.14",
3
+ "version": "0.17.15-leo-ron-1113-experimental-406",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {