@ronin/compiler 0.8.8-leo-ron-1083-experimental-193 → 0.8.8-leo-ron-1083-experimental-194

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -5995,7 +5995,7 @@ type Result = SingleRecordResult | MultipleRecordResult | AmountResult;
5995
5995
 
5996
5996
  declare class Transaction {
5997
5997
  statements: Array<Statement>;
5998
- models: Array<PublicModel>;
5998
+ models: Array<Model>;
5999
5999
  private queries;
6000
6000
  constructor(queries: Array<Query>, options?: Parameters<typeof this.compileQueries>[2] & {
6001
6001
  models?: Array<PublicModel>;
@@ -6010,6 +6010,7 @@ declare class Transaction {
6010
6010
  * @returns The composed SQL statements.
6011
6011
  */
6012
6012
  private compileQueries;
6013
+ private formatRecord;
6013
6014
  formatOutput(results: Array<Array<Row>>): Array<Result>;
6014
6015
  }
6015
6016
 
package/dist/index.js CHANGED
@@ -1353,12 +1353,11 @@ var compileQueryInput = (query, models, statementParams, options) => {
1353
1353
  // src/index.ts
1354
1354
  var Transaction = class {
1355
1355
  statements;
1356
- models;
1356
+ models = [];
1357
1357
  queries;
1358
1358
  constructor(queries, options) {
1359
1359
  const models = options?.models || [];
1360
1360
  this.statements = this.compileQueries(queries, models, options);
1361
- this.models = models;
1362
1361
  this.queries = queries;
1363
1362
  }
1364
1363
  /**
@@ -1395,17 +1394,27 @@ var Transaction = class {
1395
1394
  dependencyStatements.push(...result.dependencies);
1396
1395
  mainStatements.push(result.main);
1397
1396
  }
1397
+ this.models = modelListWithPresets;
1398
1398
  return [...dependencyStatements, ...mainStatements];
1399
1399
  };
1400
+ formatRecord(model, record) {
1401
+ const formattedRecord = { ...record };
1402
+ for (const key in record) {
1403
+ const { field } = getFieldFromModel(model, key, "to");
1404
+ if (field.type === "json") {
1405
+ formattedRecord[key] = JSON.parse(record[key]);
1406
+ continue;
1407
+ }
1408
+ formattedRecord[key] = record[key];
1409
+ }
1410
+ return expand(formattedRecord);
1411
+ }
1400
1412
  formatOutput(results) {
1401
1413
  return results.map((result, index) => {
1402
1414
  const query = this.queries.at(-index);
1403
- const { queryType, queryModel } = splitQuery(query);
1415
+ const { queryModel } = splitQuery(query);
1404
1416
  const model = getModelBySlug(this.models, queryModel);
1405
- const single = queryModel !== model.pluralSlug;
1406
- if (single) return { record: result[0] };
1407
- if (queryType === "count") return { amount: result[0] };
1408
- return { records: result };
1417
+ return { record: this.formatRecord(model, result[0]) };
1409
1418
  });
1410
1419
  }
1411
1420
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.8.8-leo-ron-1083-experimental-193",
3
+ "version": "0.8.8-leo-ron-1083-experimental-194",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {