@ronin/compiler 0.11.6 → 0.11.7-leo-ron-1071-experimental-248

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
@@ -5998,16 +5998,18 @@ type NativeRecord = Record<string, unknown> & {
5998
5998
  };
5999
5999
  type SingleRecordResult<T = NativeRecord> = {
6000
6000
  record: T | null;
6001
+ modelFields: Record<ModelField['slug'], ModelField['type']>;
6001
6002
  };
6002
- type MultipleRecordResult = {
6003
- records: Array<NativeRecord>;
6003
+ type MultipleRecordResult<T = NativeRecord> = {
6004
+ records: Array<T>;
6004
6005
  moreAfter?: string;
6005
6006
  moreBefore?: string;
6007
+ modelFields: Record<ModelField['slug'], ModelField['type']>;
6006
6008
  };
6007
6009
  type AmountResult = {
6008
6010
  amount: number;
6009
6011
  };
6010
- type Result = SingleRecordResult | MultipleRecordResult | AmountResult;
6012
+ type Result<T = NativeRecord> = SingleRecordResult<T> | MultipleRecordResult<T> | AmountResult;
6011
6013
 
6012
6014
  /**
6013
6015
  * A list of placeholders that can be located inside queries after those queries were
@@ -6062,8 +6064,7 @@ interface TransactionOptions {
6062
6064
  declare class Transaction {
6063
6065
  statements: Array<Statement>;
6064
6066
  models: Array<Model>;
6065
- private queries;
6066
- private fields;
6067
+ private internalStatements;
6067
6068
  constructor(queries: Array<Query>, options?: TransactionOptions);
6068
6069
  /**
6069
6070
  * Composes SQL statements for the provided RONIN queries.
package/dist/index.js CHANGED
@@ -1570,14 +1570,12 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1570
1570
 
1571
1571
  // src/index.ts
1572
1572
  var Transaction = class {
1573
- statements;
1573
+ statements = [];
1574
1574
  models = [];
1575
- queries;
1576
- fields = [];
1575
+ internalStatements = [];
1577
1576
  constructor(queries, options) {
1578
1577
  const models = options?.models || [];
1579
- this.statements = this.compileQueries(queries, models, options);
1580
- this.queries = queries;
1578
+ this.compileQueries(queries, models, options);
1581
1579
  }
1582
1580
  /**
1583
1581
  * Composes SQL statements for the provided RONIN queries.
@@ -1607,8 +1605,15 @@ var Transaction = class {
1607
1605
  options?.inlineParams ? null : [],
1608
1606
  { expandColumns: options?.expandColumns }
1609
1607
  );
1610
- statements.push(...result.dependencies, result.main);
1611
- this.fields.push(result.loadedFields);
1608
+ const subStatements = [...result.dependencies, result.main];
1609
+ this.statements.push(...subStatements);
1610
+ this.internalStatements.push(
1611
+ ...subStatements.map((statement) => ({
1612
+ ...statement,
1613
+ query,
1614
+ fields: result.loadedFields
1615
+ }))
1616
+ );
1612
1617
  }
1613
1618
  this.models = modelListWithPresets;
1614
1619
  return statements;
@@ -1655,31 +1660,35 @@ var Transaction = class {
1655
1660
  * RONIN record, an array of RONIN records, or a RONIN count result.
1656
1661
  */
1657
1662
  formatResults(results, raw = true) {
1658
- const relevantResults = results.filter((_, index) => {
1659
- return this.statements[index].returning;
1660
- });
1661
- const normalizedResults = raw ? relevantResults : relevantResults.map((rows) => {
1663
+ const normalizedResults = raw ? results : results.map((rows) => {
1662
1664
  return rows.map((row) => {
1663
1665
  if (Array.isArray(row)) return row;
1664
1666
  if (row["COUNT(*)"]) return [row["COUNT(*)"]];
1665
1667
  return Object.values(row);
1666
1668
  });
1667
1669
  });
1668
- return normalizedResults.map((rows, index) => {
1669
- const query = this.queries.at(-index);
1670
- const fields = this.fields.at(-index);
1670
+ const formattedResults = normalizedResults.map((rows, index) => {
1671
+ const { returning, query, fields: rawModelFields } = this.internalStatements[index];
1672
+ if (!returning) return null;
1671
1673
  const { queryType, queryModel, queryInstructions } = splitQuery(query);
1672
1674
  const model = getModelBySlug(this.models, queryModel);
1675
+ const modelFields = Object.fromEntries(
1676
+ model.fields.map((field) => [field.slug, field.type])
1677
+ );
1673
1678
  if (queryType === "count") {
1674
1679
  return { amount: rows[0][0] };
1675
1680
  }
1676
1681
  const single = queryModel !== model.pluralSlug;
1677
1682
  if (single) {
1678
- return { record: rows[0] ? this.formatRows(fields, rows, single) : null };
1683
+ return {
1684
+ record: rows[0] ? this.formatRows(rawModelFields, rows, single) : null,
1685
+ modelFields
1686
+ };
1679
1687
  }
1680
1688
  const pageSize = queryInstructions?.limitedTo;
1681
1689
  const output = {
1682
- records: this.formatRows(fields, rows, single)
1690
+ records: this.formatRows(rawModelFields, rows, single),
1691
+ modelFields
1683
1692
  };
1684
1693
  if (pageSize && output.records.length > 0) {
1685
1694
  if (output.records.length > pageSize) {
@@ -1712,6 +1721,7 @@ var Transaction = class {
1712
1721
  }
1713
1722
  return output;
1714
1723
  });
1724
+ return formattedResults.filter((result) => result !== null);
1715
1725
  }
1716
1726
  };
1717
1727
  var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.11.6",
3
+ "version": "0.11.7-leo-ron-1071-experimental-248",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {