@ronin/compiler 0.12.4 → 0.12.5

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
@@ -15671,8 +15671,8 @@ declare class Transaction {
15671
15671
  */
15672
15672
  private compileQueries;
15673
15673
  private formatRows;
15674
- formatResults(results: Array<Array<RawRow>>, raw?: true): Array<Result>;
15675
- formatResults(results: Array<Array<ObjectRow>>, raw?: false): Array<Result>;
15674
+ formatResults<Record>(results: Array<Array<RawRow>>, raw?: true): Array<Result<Record>>;
15675
+ formatResults<Record>(results: Array<Array<ObjectRow>>, raw?: false): Array<Result<Record>>;
15676
15676
  }
15677
15677
 
15678
15678
  declare const CLEAN_ROOT_MODEL: PublicModel;
package/dist/index.js CHANGED
@@ -675,6 +675,7 @@ var PLURAL_MODEL_ENTITIES = {
675
675
  trigger: "triggers",
676
676
  preset: "presets"
677
677
  };
678
+ var PLURAL_MODEL_ENTITIES_VALUES = Object.values(PLURAL_MODEL_ENTITIES);
678
679
  var formatModelEntity = (type, entities) => {
679
680
  const entries = entities?.map((entity) => {
680
681
  const { slug, ...rest } = "slug" in entity ? entity : { slug: `${type}Slug`, ...entity };
@@ -1630,7 +1631,7 @@ var Transaction = class {
1630
1631
  this.models = modelListWithPresets;
1631
1632
  return statements;
1632
1633
  };
1633
- formatRows(fields, rows, single) {
1634
+ formatRows(fields, rows, single, isMeta) {
1634
1635
  const records = [];
1635
1636
  for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
1636
1637
  const row = rows[rowIndex];
@@ -1654,7 +1655,16 @@ var Transaction = class {
1654
1655
  usableRowIndex = 0;
1655
1656
  }
1656
1657
  }
1657
- records[usableRowIndex] = setProperty(records[usableRowIndex], newSlug, newValue);
1658
+ if (isMeta && PLURAL_MODEL_ENTITIES_VALUES.includes(newSlug)) {
1659
+ newValue = Object.entries(newValue).map(([slug, attributes]) => {
1660
+ return { slug, ...attributes };
1661
+ });
1662
+ }
1663
+ records[usableRowIndex] = setProperty(
1664
+ records[usableRowIndex],
1665
+ newSlug,
1666
+ newValue
1667
+ );
1658
1668
  }
1659
1669
  }
1660
1670
  return single ? records[0] : records;
@@ -1679,60 +1689,67 @@ var Transaction = class {
1679
1689
  return Object.values(row);
1680
1690
  });
1681
1691
  });
1682
- const formattedResults = normalizedResults.map((rows, index) => {
1683
- const { returning, query, fields: rawModelFields } = this.internalStatements[index];
1684
- if (!returning) return null;
1685
- const { queryType, queryModel, queryInstructions } = splitQuery(query);
1686
- const model = getModelBySlug(this.models, queryModel);
1687
- const modelFields = Object.fromEntries(
1688
- model.fields.map((field) => [field.slug, field.type])
1689
- );
1690
- if (queryType === "count") {
1691
- return { amount: rows[0][0] };
1692
- }
1693
- const single = queryModel !== model.pluralSlug;
1694
- if (single) {
1695
- return {
1696
- record: rows[0] ? this.formatRows(rawModelFields, rows, single) : null,
1692
+ const formattedResults = normalizedResults.map(
1693
+ (rows, index) => {
1694
+ const {
1695
+ returning,
1696
+ query,
1697
+ fields: rawModelFields
1698
+ } = this.internalStatements[index];
1699
+ if (!returning) return null;
1700
+ const { queryType, queryModel, queryInstructions } = splitQuery(query);
1701
+ const model = getModelBySlug(this.models, queryModel);
1702
+ const isMeta = queryModel === "model" || queryModel === "models";
1703
+ const modelFields = Object.fromEntries(
1704
+ model.fields.map((field) => [field.slug, field.type])
1705
+ );
1706
+ if (queryType === "count") {
1707
+ return { amount: rows[0][0] };
1708
+ }
1709
+ const single = queryModel !== model.pluralSlug;
1710
+ if (single) {
1711
+ return {
1712
+ record: rows[0] ? this.formatRows(rawModelFields, rows, single, isMeta) : null,
1713
+ modelFields
1714
+ };
1715
+ }
1716
+ const pageSize = queryInstructions?.limitedTo;
1717
+ const output = {
1718
+ records: this.formatRows(rawModelFields, rows, single, isMeta),
1697
1719
  modelFields
1698
1720
  };
1699
- }
1700
- const pageSize = queryInstructions?.limitedTo;
1701
- const output = {
1702
- records: this.formatRows(rawModelFields, rows, single),
1703
- modelFields
1704
- };
1705
- if (pageSize && output.records.length > 0) {
1706
- if (output.records.length > pageSize) {
1707
- if (queryInstructions?.before) {
1708
- output.records.shift();
1709
- } else {
1710
- output.records.pop();
1721
+ if (pageSize && output.records.length > 0) {
1722
+ if (output.records.length > pageSize) {
1723
+ if (queryInstructions?.before) {
1724
+ output.records.shift();
1725
+ } else {
1726
+ output.records.pop();
1727
+ }
1728
+ const direction = queryInstructions?.before ? "moreBefore" : "moreAfter";
1729
+ const lastRecord = output.records.at(
1730
+ direction === "moreAfter" ? -1 : 0
1731
+ );
1732
+ output[direction] = generatePaginationCursor(
1733
+ model,
1734
+ queryInstructions.orderedBy,
1735
+ lastRecord
1736
+ );
1737
+ }
1738
+ if (queryInstructions?.before || queryInstructions?.after) {
1739
+ const direction = queryInstructions?.before ? "moreAfter" : "moreBefore";
1740
+ const firstRecord = output.records.at(
1741
+ direction === "moreAfter" ? -1 : 0
1742
+ );
1743
+ output[direction] = generatePaginationCursor(
1744
+ model,
1745
+ queryInstructions.orderedBy,
1746
+ firstRecord
1747
+ );
1711
1748
  }
1712
- const direction = queryInstructions?.before ? "moreBefore" : "moreAfter";
1713
- const lastRecord = output.records.at(
1714
- direction === "moreAfter" ? -1 : 0
1715
- );
1716
- output[direction] = generatePaginationCursor(
1717
- model,
1718
- queryInstructions.orderedBy,
1719
- lastRecord
1720
- );
1721
- }
1722
- if (queryInstructions?.before || queryInstructions?.after) {
1723
- const direction = queryInstructions?.before ? "moreAfter" : "moreBefore";
1724
- const firstRecord = output.records.at(
1725
- direction === "moreAfter" ? -1 : 0
1726
- );
1727
- output[direction] = generatePaginationCursor(
1728
- model,
1729
- queryInstructions.orderedBy,
1730
- firstRecord
1731
- );
1732
1749
  }
1750
+ return output;
1733
1751
  }
1734
- return output;
1735
- });
1752
+ );
1736
1753
  return formattedResults.filter((result) => result !== null);
1737
1754
  }
1738
1755
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.12.4",
3
+ "version": "0.12.5",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {