@ronin/compiler 0.12.3 → 0.12.4-leo-ron-1071-experimental-255
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 +2 -2
- package/dist/index.js +84 -62
- package/package.json +1 -1
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
@@ -435,7 +435,7 @@ var pluralize = (word) => {
|
|
435
435
|
}
|
436
436
|
return `${word}s`;
|
437
437
|
};
|
438
|
-
var
|
438
|
+
var modelAttributes = [
|
439
439
|
["pluralSlug", "slug", pluralize],
|
440
440
|
["name", "slug", slugToName],
|
441
441
|
["pluralName", "pluralSlug", slugToName],
|
@@ -444,7 +444,7 @@ var modelSettings = [
|
|
444
444
|
];
|
445
445
|
var addDefaultModelFields = (model, isNew) => {
|
446
446
|
const copiedModel = { ...model };
|
447
|
-
for (const [setting, base, generator] of
|
447
|
+
for (const [setting, base, generator] of modelAttributes) {
|
448
448
|
if (copiedModel[setting] || !copiedModel[base]) continue;
|
449
449
|
copiedModel[setting] = generator(copiedModel[base]);
|
450
450
|
}
|
@@ -732,23 +732,30 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
732
732
|
[...models, modelWithFields],
|
733
733
|
modelWithFields
|
734
734
|
);
|
735
|
+
modelWithPresets.fields = modelWithPresets.fields.map((field2) => ({
|
736
|
+
...field2,
|
737
|
+
// Default field type.
|
738
|
+
type: field2.type || "string",
|
739
|
+
// Default field name.
|
740
|
+
name: field2.name || slugToName(field2.slug)
|
741
|
+
}));
|
742
|
+
const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
|
735
743
|
const entities = Object.fromEntries(
|
736
744
|
Object.entries(PLURAL_MODEL_ENTITIES).map(([type, pluralType2]) => {
|
737
745
|
const list = modelWithPresets[pluralType2];
|
738
746
|
return [pluralType2, formatModelEntity(type, list)];
|
739
747
|
})
|
740
748
|
);
|
741
|
-
const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
|
742
749
|
dependencyStatements.push({
|
743
750
|
statement: `CREATE TABLE "${modelWithPresets.table}" (${columns.join(", ")})`,
|
744
751
|
params: []
|
745
752
|
});
|
746
753
|
models.push(modelWithPresets);
|
747
|
-
const
|
754
|
+
const modelWithObjects = Object.assign({}, modelWithPresets);
|
748
755
|
for (const entity2 in entities) {
|
749
|
-
if (entities[entity2])
|
756
|
+
if (entities[entity2]) modelWithObjects[entity2] = entities[entity2];
|
750
757
|
}
|
751
|
-
queryTypeDetails = { to:
|
758
|
+
queryTypeDetails = { to: modelWithObjects };
|
752
759
|
getSystemModels(models, modelWithPresets).map((systemModel) => {
|
753
760
|
return handleSystemModel(models, dependencyStatements, "create", systemModel);
|
754
761
|
});
|
@@ -809,6 +816,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
809
816
|
if (action === "create") {
|
810
817
|
const field2 = jsonValue;
|
811
818
|
field2.type = field2.type || "string";
|
819
|
+
field2.name = field2.name || slugToName(field2.slug);
|
812
820
|
const fieldStatement = getFieldStatement(models, existingModel, field2);
|
813
821
|
if (fieldStatement) {
|
814
822
|
dependencyStatements.push({
|
@@ -817,12 +825,16 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
817
825
|
});
|
818
826
|
}
|
819
827
|
} else if (action === "alter") {
|
820
|
-
const
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
828
|
+
const field2 = jsonValue;
|
829
|
+
const newSlug = field2.slug;
|
830
|
+
if (newSlug) {
|
831
|
+
field2.name = field2.name || slugToName(field2.slug);
|
832
|
+
if (!existingLinkField) {
|
833
|
+
dependencyStatements.push({
|
834
|
+
statement: `${statement} RENAME COLUMN "${slug}" TO "${newSlug}"`,
|
835
|
+
params: []
|
836
|
+
});
|
837
|
+
}
|
826
838
|
}
|
827
839
|
} else if (action === "drop" && !existingLinkField) {
|
828
840
|
dependencyStatements.push({
|
@@ -1642,7 +1654,11 @@ var Transaction = class {
|
|
1642
1654
|
usableRowIndex = 0;
|
1643
1655
|
}
|
1644
1656
|
}
|
1645
|
-
records[usableRowIndex] = setProperty(
|
1657
|
+
records[usableRowIndex] = setProperty(
|
1658
|
+
records[usableRowIndex],
|
1659
|
+
newSlug,
|
1660
|
+
newValue
|
1661
|
+
);
|
1646
1662
|
}
|
1647
1663
|
}
|
1648
1664
|
return single ? records[0] : records;
|
@@ -1667,60 +1683,66 @@ var Transaction = class {
|
|
1667
1683
|
return Object.values(row);
|
1668
1684
|
});
|
1669
1685
|
});
|
1670
|
-
const formattedResults = normalizedResults.map(
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1686
|
+
const formattedResults = normalizedResults.map(
|
1687
|
+
(rows, index) => {
|
1688
|
+
const {
|
1689
|
+
returning,
|
1690
|
+
query,
|
1691
|
+
fields: rawModelFields
|
1692
|
+
} = this.internalStatements[index];
|
1693
|
+
if (!returning) return null;
|
1694
|
+
const { queryType, queryModel, queryInstructions } = splitQuery(query);
|
1695
|
+
const model = getModelBySlug(this.models, queryModel);
|
1696
|
+
const modelFields = Object.fromEntries(
|
1697
|
+
model.fields.map((field) => [field.slug, field.type])
|
1698
|
+
);
|
1699
|
+
if (queryType === "count") {
|
1700
|
+
return { amount: rows[0][0] };
|
1701
|
+
}
|
1702
|
+
const single = queryModel !== model.pluralSlug;
|
1703
|
+
if (single) {
|
1704
|
+
return {
|
1705
|
+
record: rows[0] ? this.formatRows(rawModelFields, rows, single) : null,
|
1706
|
+
modelFields
|
1707
|
+
};
|
1708
|
+
}
|
1709
|
+
const pageSize = queryInstructions?.limitedTo;
|
1710
|
+
const output = {
|
1711
|
+
records: this.formatRows(rawModelFields, rows, single),
|
1685
1712
|
modelFields
|
1686
1713
|
};
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
output
|
1714
|
+
if (pageSize && output.records.length > 0) {
|
1715
|
+
if (output.records.length > pageSize) {
|
1716
|
+
if (queryInstructions?.before) {
|
1717
|
+
output.records.shift();
|
1718
|
+
} else {
|
1719
|
+
output.records.pop();
|
1720
|
+
}
|
1721
|
+
const direction = queryInstructions?.before ? "moreBefore" : "moreAfter";
|
1722
|
+
const lastRecord = output.records.at(
|
1723
|
+
direction === "moreAfter" ? -1 : 0
|
1724
|
+
);
|
1725
|
+
output[direction] = generatePaginationCursor(
|
1726
|
+
model,
|
1727
|
+
queryInstructions.orderedBy,
|
1728
|
+
lastRecord
|
1729
|
+
);
|
1730
|
+
}
|
1731
|
+
if (queryInstructions?.before || queryInstructions?.after) {
|
1732
|
+
const direction = queryInstructions?.before ? "moreAfter" : "moreBefore";
|
1733
|
+
const firstRecord = output.records.at(
|
1734
|
+
direction === "moreAfter" ? -1 : 0
|
1735
|
+
);
|
1736
|
+
output[direction] = generatePaginationCursor(
|
1737
|
+
model,
|
1738
|
+
queryInstructions.orderedBy,
|
1739
|
+
firstRecord
|
1740
|
+
);
|
1699
1741
|
}
|
1700
|
-
const direction = queryInstructions?.before ? "moreBefore" : "moreAfter";
|
1701
|
-
const lastRecord = output.records.at(
|
1702
|
-
direction === "moreAfter" ? -1 : 0
|
1703
|
-
);
|
1704
|
-
output[direction] = generatePaginationCursor(
|
1705
|
-
model,
|
1706
|
-
queryInstructions.orderedBy,
|
1707
|
-
lastRecord
|
1708
|
-
);
|
1709
|
-
}
|
1710
|
-
if (queryInstructions?.before || queryInstructions?.after) {
|
1711
|
-
const direction = queryInstructions?.before ? "moreAfter" : "moreBefore";
|
1712
|
-
const firstRecord = output.records.at(
|
1713
|
-
direction === "moreAfter" ? -1 : 0
|
1714
|
-
);
|
1715
|
-
output[direction] = generatePaginationCursor(
|
1716
|
-
model,
|
1717
|
-
queryInstructions.orderedBy,
|
1718
|
-
firstRecord
|
1719
|
-
);
|
1720
1742
|
}
|
1743
|
+
return output;
|
1721
1744
|
}
|
1722
|
-
|
1723
|
-
});
|
1745
|
+
);
|
1724
1746
|
return formattedResults.filter((result) => result !== null);
|
1725
1747
|
}
|
1726
1748
|
};
|