@ronin/compiler 0.12.4-leo-ron-1071-experimental-254 → 0.12.4-leo-ron-1071-experimental-256

Sign up to get free protection for your applications and to get access to all the features.
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<T>(results: Array<Array<RawRow>>, raw?: true): Array<Result<T>>;
15675
- formatResults<T>(results: Array<Array<ObjectRow>>, raw?: false): Array<Result<T>>;
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,6 +1655,11 @@ var Transaction = class {
1654
1655
  usableRowIndex = 0;
1655
1656
  }
1656
1657
  }
1658
+ if (isMeta && PLURAL_MODEL_ENTITIES_VALUES.includes(newSlug)) {
1659
+ newValue = Object.entries(newValue).map(([slug, attributes]) => {
1660
+ return { slug, ...attributes };
1661
+ });
1662
+ }
1657
1663
  records[usableRowIndex] = setProperty(
1658
1664
  records[usableRowIndex],
1659
1665
  newSlug,
@@ -1683,60 +1689,67 @@ var Transaction = class {
1683
1689
  return Object.values(row);
1684
1690
  });
1685
1691
  });
1686
- const formattedResults = normalizedResults.map((rows, index) => {
1687
- const { returning, query, fields: rawModelFields } = this.internalStatements[index];
1688
- if (!returning) return null;
1689
- const { queryType, queryModel, queryInstructions } = splitQuery(query);
1690
- const model = getModelBySlug(this.models, queryModel);
1691
- const modelFields = Object.fromEntries(
1692
- model.fields.map((field) => [field.slug, field.type])
1693
- );
1694
- if (queryType === "count") {
1695
- return { amount: rows[0][0] };
1696
- }
1697
- const single = queryModel !== model.pluralSlug;
1698
- if (single) {
1699
- return {
1700
- 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),
1701
1719
  modelFields
1702
1720
  };
1703
- }
1704
- const pageSize = queryInstructions?.limitedTo;
1705
- const output = {
1706
- records: this.formatRows(rawModelFields, rows, single),
1707
- modelFields
1708
- };
1709
- if (pageSize && output.records.length > 0) {
1710
- if (output.records.length > pageSize) {
1711
- if (queryInstructions?.before) {
1712
- output.records.shift();
1713
- } else {
1714
- 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
+ );
1715
1748
  }
1716
- const direction = queryInstructions?.before ? "moreBefore" : "moreAfter";
1717
- const lastRecord = output.records.at(
1718
- direction === "moreAfter" ? -1 : 0
1719
- );
1720
- output[direction] = generatePaginationCursor(
1721
- model,
1722
- queryInstructions.orderedBy,
1723
- lastRecord
1724
- );
1725
- }
1726
- if (queryInstructions?.before || queryInstructions?.after) {
1727
- const direction = queryInstructions?.before ? "moreAfter" : "moreBefore";
1728
- const firstRecord = output.records.at(
1729
- direction === "moreAfter" ? -1 : 0
1730
- );
1731
- output[direction] = generatePaginationCursor(
1732
- model,
1733
- queryInstructions.orderedBy,
1734
- firstRecord
1735
- );
1736
1749
  }
1750
+ return output;
1737
1751
  }
1738
- return output;
1739
- });
1752
+ );
1740
1753
  return formattedResults.filter((result) => result !== null);
1741
1754
  }
1742
1755
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.12.4-leo-ron-1071-experimental-254",
3
+ "version": "0.12.4-leo-ron-1071-experimental-256",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {