@ronin/compiler 0.12.3 → 0.12.4-leo-ron-1071-experimental-254
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -13
- 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<T>(results: Array<Array<RawRow>>, raw?: true): Array<Result<T>>;
|
15675
|
+
formatResults<T>(results: Array<Array<ObjectRow>>, raw?: false): Array<Result<T>>;
|
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;
|