@zenstackhq/sdk 3.0.0-beta.2 → 3.0.0-beta.21
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.cjs +179 -590
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -70
- package/dist/index.d.ts +15 -70
- package/dist/index.js +188 -598
- package/dist/index.js.map +1 -1
- package/package.json +6 -16
- package/dist/schema.cjs +0 -19
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.cts +0 -165
- package/dist/schema.d.ts +0 -165
- package/dist/schema.js +0 -1
- package/dist/schema.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -33,8 +33,7 @@ var src_exports = {};
|
|
|
33
33
|
__export(src_exports, {
|
|
34
34
|
ModelUtils: () => model_utils_exports,
|
|
35
35
|
PrismaSchemaGenerator: () => PrismaSchemaGenerator,
|
|
36
|
-
TsSchemaGenerator: () => TsSchemaGenerator
|
|
37
|
-
ZModelCodeGenerator: () => ZModelCodeGenerator
|
|
36
|
+
TsSchemaGenerator: () => TsSchemaGenerator
|
|
38
37
|
});
|
|
39
38
|
module.exports = __toCommonJS(src_exports);
|
|
40
39
|
|
|
@@ -121,7 +120,7 @@ function resolved(ref) {
|
|
|
121
120
|
}
|
|
122
121
|
__name(resolved, "resolved");
|
|
123
122
|
function getAuthDecl(model) {
|
|
124
|
-
let found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
123
|
+
let found = model.declarations.find((d) => ((0, import_ast.isDataModel)(d) || (0, import_ast.isTypeDef)(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
125
124
|
if (!found) {
|
|
126
125
|
found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.name === "User");
|
|
127
126
|
}
|
|
@@ -136,6 +135,7 @@ var DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
|
|
|
136
135
|
|
|
137
136
|
// src/prisma/prisma-schema-generator.ts
|
|
138
137
|
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
138
|
+
var import_language = require("@zenstackhq/language");
|
|
139
139
|
var import_ast2 = require("@zenstackhq/language/ast");
|
|
140
140
|
var import_utils2 = require("@zenstackhq/language/utils");
|
|
141
141
|
var import_langium = require("langium");
|
|
@@ -533,6 +533,9 @@ var EnumField = class extends DeclarationBase {
|
|
|
533
533
|
|
|
534
534
|
// src/prisma/prisma-schema-generator.ts
|
|
535
535
|
var IDENTIFIER_NAME_MAX_LENGTH = 50 - DELEGATE_AUX_RELATION_PREFIX.length;
|
|
536
|
+
var NON_PRISMA_DATASOURCE_FIELDS = [
|
|
537
|
+
"defaultSchema"
|
|
538
|
+
];
|
|
536
539
|
var PrismaSchemaGenerator = class {
|
|
537
540
|
static {
|
|
538
541
|
__name(this, "PrismaSchemaGenerator");
|
|
@@ -570,7 +573,7 @@ var PrismaSchemaGenerator = class {
|
|
|
570
573
|
return this.PRELUDE + prisma.toString();
|
|
571
574
|
}
|
|
572
575
|
generateDataSource(prisma, dataSource) {
|
|
573
|
-
const fields = dataSource.fields.map((f) => ({
|
|
576
|
+
const fields = dataSource.fields.filter((f) => !NON_PRISMA_DATASOURCE_FIELDS.includes(f.name)).map((f) => ({
|
|
574
577
|
name: f.name,
|
|
575
578
|
text: this.configExprToText(f.value)
|
|
576
579
|
}));
|
|
@@ -618,14 +621,37 @@ var PrismaSchemaGenerator = class {
|
|
|
618
621
|
this.generateModelField(model, field, decl);
|
|
619
622
|
}
|
|
620
623
|
}
|
|
621
|
-
const allAttributes = (0, import_utils2.getAllAttributes)(decl);
|
|
622
|
-
for (const attr of allAttributes
|
|
624
|
+
const allAttributes = (0, import_utils2.getAllAttributes)(decl).filter((attr) => this.isPrismaAttribute(attr) && !this.isInheritedMapAttribute(attr, decl));
|
|
625
|
+
for (const attr of allAttributes) {
|
|
623
626
|
this.generateContainerAttribute(model, attr);
|
|
624
627
|
}
|
|
628
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
629
|
+
model.addAttribute("@@schema", [
|
|
630
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
631
|
+
]);
|
|
632
|
+
}
|
|
625
633
|
decl.comments.forEach((c) => model.addComment(c));
|
|
626
634
|
this.generateDelegateRelationForBase(model, decl);
|
|
627
635
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
628
636
|
}
|
|
637
|
+
getDatasourceField(zmodel, fieldName) {
|
|
638
|
+
const dataSource = zmodel.declarations.find(import_ast2.isDataSource);
|
|
639
|
+
return dataSource?.fields.find((f) => f.name === fieldName);
|
|
640
|
+
}
|
|
641
|
+
datasourceHasSchemasSetting(zmodel) {
|
|
642
|
+
return !!this.getDatasourceField(zmodel, "schemas");
|
|
643
|
+
}
|
|
644
|
+
getDefaultPostgresSchemaName(zmodel) {
|
|
645
|
+
const defaultSchemaField = this.getDatasourceField(zmodel, "defaultSchema");
|
|
646
|
+
return (0, import_utils2.getStringLiteral)(defaultSchemaField?.value) ?? "public";
|
|
647
|
+
}
|
|
648
|
+
isInheritedMapAttribute(attr, contextModel) {
|
|
649
|
+
if (attr.$container === contextModel) {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
|
|
653
|
+
return attrName === "@@map";
|
|
654
|
+
}
|
|
629
655
|
isPrismaAttribute(attr) {
|
|
630
656
|
if (!attr.decl.ref) {
|
|
631
657
|
return false;
|
|
@@ -634,7 +660,7 @@ var PrismaSchemaGenerator = class {
|
|
|
634
660
|
}
|
|
635
661
|
getUnsupportedFieldType(fieldType) {
|
|
636
662
|
if (fieldType.unsupported) {
|
|
637
|
-
const value =
|
|
663
|
+
const value = (0, import_utils2.getStringLiteral)(fieldType.unsupported.value);
|
|
638
664
|
if (value) {
|
|
639
665
|
return `Unsupported("${value}")`;
|
|
640
666
|
} else {
|
|
@@ -644,9 +670,6 @@ var PrismaSchemaGenerator = class {
|
|
|
644
670
|
return void 0;
|
|
645
671
|
}
|
|
646
672
|
}
|
|
647
|
-
getStringLiteral(node) {
|
|
648
|
-
return (0, import_ast2.isStringLiteral)(node) ? node.value : void 0;
|
|
649
|
-
}
|
|
650
673
|
generateModelField(model, field, contextModel, addToFront = false) {
|
|
651
674
|
let fieldType;
|
|
652
675
|
if (field.type.type) {
|
|
@@ -671,7 +694,7 @@ var PrismaSchemaGenerator = class {
|
|
|
671
694
|
(0, import_ast2.isTypeDef)(field.type.reference?.ref) ? false : field.type.array
|
|
672
695
|
);
|
|
673
696
|
const type = new ModelFieldType(fieldType, isArray, field.type.optional);
|
|
674
|
-
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.
|
|
697
|
+
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.isDefaultWithAuthInvocation(attr)).filter((attr) => (
|
|
675
698
|
// when building physical schema, exclude `@default` for id fields inherited from delegate base
|
|
676
699
|
!(model_utils_exports.isIdField(field, contextModel) && this.isInheritedFromDelegate(field, contextModel) && attr.decl.$refText === "@default")
|
|
677
700
|
)).map((attr) => this.makeFieldAttribute(attr));
|
|
@@ -681,7 +704,7 @@ var PrismaSchemaGenerator = class {
|
|
|
681
704
|
const result = model.addField(field.name, type, attributes, docs, addToFront);
|
|
682
705
|
return result;
|
|
683
706
|
}
|
|
684
|
-
|
|
707
|
+
isDefaultWithAuthInvocation(attr) {
|
|
685
708
|
if (attr.decl.ref?.name !== "@default") {
|
|
686
709
|
return false;
|
|
687
710
|
}
|
|
@@ -689,11 +712,7 @@ var PrismaSchemaGenerator = class {
|
|
|
689
712
|
if (!expr) {
|
|
690
713
|
return false;
|
|
691
714
|
}
|
|
692
|
-
return import_langium.AstUtils.streamAst(expr).some(
|
|
693
|
-
}
|
|
694
|
-
isFromPlugin(node) {
|
|
695
|
-
const model = import_langium.AstUtils.getContainerOfType(node, import_ast2.isModel);
|
|
696
|
-
return !!model && !!model.$document && model.$document.uri.path.endsWith("plugin.zmodel");
|
|
715
|
+
return import_langium.AstUtils.streamAst(expr).some(import_utils2.isAuthInvocation);
|
|
697
716
|
}
|
|
698
717
|
isInheritedFromDelegate(field, contextModel) {
|
|
699
718
|
return field.$container !== contextModel && model_utils_exports.isDelegateModel(field.$container);
|
|
@@ -720,7 +739,7 @@ var PrismaSchemaGenerator = class {
|
|
|
720
739
|
}
|
|
721
740
|
}
|
|
722
741
|
exprToText(expr) {
|
|
723
|
-
return new ZModelCodeGenerator({
|
|
742
|
+
return new import_language.ZModelCodeGenerator({
|
|
724
743
|
quote: "double"
|
|
725
744
|
}).generate(expr);
|
|
726
745
|
}
|
|
@@ -821,38 +840,58 @@ var TsSchemaGenerator = class {
|
|
|
821
840
|
static {
|
|
822
841
|
__name(this, "TsSchemaGenerator");
|
|
823
842
|
}
|
|
824
|
-
|
|
825
|
-
|
|
843
|
+
usedExpressionUtils = false;
|
|
844
|
+
async generate(model, options) {
|
|
845
|
+
import_node_fs.default.mkdirSync(options.outDir, {
|
|
826
846
|
recursive: true
|
|
827
847
|
});
|
|
828
|
-
this.
|
|
829
|
-
this.
|
|
830
|
-
this.
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
848
|
+
this.usedExpressionUtils = false;
|
|
849
|
+
this.generateSchema(model, options);
|
|
850
|
+
this.generateModelsAndTypeDefs(model, options);
|
|
851
|
+
this.generateInputTypes(model, options);
|
|
852
|
+
}
|
|
853
|
+
generateSchema(model, options) {
|
|
854
|
+
const targets = [];
|
|
855
|
+
if (!options.liteOnly) {
|
|
856
|
+
targets.push({
|
|
857
|
+
lite: false,
|
|
858
|
+
file: "schema.ts"
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
if (options.lite || options.liteOnly) {
|
|
862
|
+
targets.push({
|
|
863
|
+
lite: true,
|
|
864
|
+
file: "schema-lite.ts"
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
for (const { lite, file } of targets) {
|
|
868
|
+
const statements = [];
|
|
869
|
+
this.generateSchemaStatements(model, statements, lite);
|
|
870
|
+
this.generateBannerComments(statements);
|
|
871
|
+
const schemaOutputFile = import_node_path.default.join(options.outDir, file);
|
|
872
|
+
const sourceFile = ts.createSourceFile(schemaOutputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
873
|
+
const printer = ts.createPrinter();
|
|
874
|
+
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
875
|
+
import_node_fs.default.writeFileSync(schemaOutputFile, result);
|
|
876
|
+
}
|
|
841
877
|
}
|
|
842
|
-
generateSchemaStatements(model, statements) {
|
|
878
|
+
generateSchemaStatements(model, statements, lite) {
|
|
843
879
|
const hasComputedFields = model.declarations.some((d) => (0, import_ast3.isDataModel)(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
880
|
+
const schemaObject = this.createSchemaObject(model, lite);
|
|
844
881
|
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
845
882
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
846
883
|
...hasComputedFields ? [
|
|
847
884
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
848
885
|
] : [],
|
|
849
|
-
|
|
850
|
-
|
|
886
|
+
...this.usedExpressionUtils ? [
|
|
887
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
|
|
888
|
+
] : []
|
|
889
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
851
890
|
statements.push(runtimeImportDecl);
|
|
852
891
|
const declaration = ts.factory.createVariableStatement([
|
|
853
892
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
854
893
|
], ts.factory.createVariableDeclarationList([
|
|
855
|
-
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(
|
|
894
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(schemaObject, ts.factory.createTypeReferenceNode("const")), ts.factory.createTypeReferenceNode("SchemaDef")))
|
|
856
895
|
], ts.NodeFlags.Const));
|
|
857
896
|
statements.push(declaration);
|
|
858
897
|
const typeDeclaration = ts.factory.createTypeAliasDeclaration([
|
|
@@ -860,15 +899,19 @@ var TsSchemaGenerator = class {
|
|
|
860
899
|
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("typeof schema"));
|
|
861
900
|
statements.push(typeDeclaration);
|
|
862
901
|
}
|
|
863
|
-
|
|
902
|
+
createExpressionUtilsCall(method, args) {
|
|
903
|
+
this.usedExpressionUtils = true;
|
|
904
|
+
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
905
|
+
}
|
|
906
|
+
createSchemaObject(model, lite) {
|
|
864
907
|
const properties = [
|
|
865
908
|
// provider
|
|
866
909
|
ts.factory.createPropertyAssignment("provider", this.createProviderObject(model)),
|
|
867
910
|
// models
|
|
868
|
-
ts.factory.createPropertyAssignment("models", this.createModelsObject(model)),
|
|
911
|
+
ts.factory.createPropertyAssignment("models", this.createModelsObject(model, lite)),
|
|
869
912
|
// typeDefs
|
|
870
913
|
...model.declarations.some(import_ast3.isTypeDef) ? [
|
|
871
|
-
ts.factory.createPropertyAssignment("typeDefs", this.createTypeDefsObject(model))
|
|
914
|
+
ts.factory.createPropertyAssignment("typeDefs", this.createTypeDefsObject(model, lite))
|
|
872
915
|
] : []
|
|
873
916
|
];
|
|
874
917
|
const enums = model.declarations.filter(import_ast3.isEnum);
|
|
@@ -888,19 +931,23 @@ var TsSchemaGenerator = class {
|
|
|
888
931
|
}
|
|
889
932
|
createProviderObject(model) {
|
|
890
933
|
const dsProvider = this.getDataSourceProvider(model);
|
|
934
|
+
const defaultSchema = this.getDataSourceDefaultSchema(model);
|
|
891
935
|
return ts.factory.createObjectLiteralExpression([
|
|
892
|
-
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider
|
|
936
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider)),
|
|
937
|
+
...defaultSchema ? [
|
|
938
|
+
ts.factory.createPropertyAssignment("defaultSchema", ts.factory.createStringLiteral(defaultSchema))
|
|
939
|
+
] : []
|
|
893
940
|
], true);
|
|
894
941
|
}
|
|
895
|
-
createModelsObject(model) {
|
|
896
|
-
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => (0, import_ast3.isDataModel)(d) && !hasAttribute(d, "@@ignore")).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm))), true);
|
|
942
|
+
createModelsObject(model, lite) {
|
|
943
|
+
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => (0, import_ast3.isDataModel)(d) && !hasAttribute(d, "@@ignore")).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
|
|
897
944
|
}
|
|
898
|
-
createTypeDefsObject(model) {
|
|
899
|
-
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => (0, import_ast3.isTypeDef)(d)).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td))), true);
|
|
945
|
+
createTypeDefsObject(model, lite) {
|
|
946
|
+
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => (0, import_ast3.isTypeDef)(d)).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
|
|
900
947
|
}
|
|
901
|
-
createDataModelObject(dm) {
|
|
948
|
+
createDataModelObject(dm, lite) {
|
|
902
949
|
const allFields = (0, import_utils3.getAllFields)(dm);
|
|
903
|
-
const allAttributes = (0, import_utils3.getAllAttributes)(dm).filter((attr) => {
|
|
950
|
+
const allAttributes = lite ? [] : (0, import_utils3.getAllAttributes)(dm).filter((attr) => {
|
|
904
951
|
if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) {
|
|
905
952
|
return false;
|
|
906
953
|
}
|
|
@@ -915,7 +962,7 @@ var TsSchemaGenerator = class {
|
|
|
915
962
|
ts.factory.createPropertyAssignment("baseModel", ts.factory.createStringLiteral(dm.baseModel.$refText))
|
|
916
963
|
] : [],
|
|
917
964
|
// fields
|
|
918
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm))), true)),
|
|
965
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm, lite))), true)),
|
|
919
966
|
// attributes
|
|
920
967
|
...allAttributes.length > 0 ? [
|
|
921
968
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -931,6 +978,9 @@ var TsSchemaGenerator = class {
|
|
|
931
978
|
// subModels
|
|
932
979
|
...subModels.length > 0 ? [
|
|
933
980
|
ts.factory.createPropertyAssignment("subModels", ts.factory.createArrayLiteralExpression(subModels.map((subModel) => ts.factory.createStringLiteral(subModel))))
|
|
981
|
+
] : [],
|
|
982
|
+
...dm.isView ? [
|
|
983
|
+
ts.factory.createPropertyAssignment("isView", ts.factory.createTrue())
|
|
934
984
|
] : []
|
|
935
985
|
];
|
|
936
986
|
const computedFields = dm.fields.filter((f) => hasAttribute(f, "@computed"));
|
|
@@ -942,14 +992,14 @@ var TsSchemaGenerator = class {
|
|
|
942
992
|
getSubModels(dm) {
|
|
943
993
|
return dm.$container.declarations.filter(import_ast3.isDataModel).filter((d) => d.baseModel?.ref === dm).map((d) => d.name);
|
|
944
994
|
}
|
|
945
|
-
createTypeDefObject(td) {
|
|
995
|
+
createTypeDefObject(td, lite) {
|
|
946
996
|
const allFields = (0, import_utils3.getAllFields)(td);
|
|
947
997
|
const allAttributes = (0, import_utils3.getAllAttributes)(td);
|
|
948
998
|
const fields = [
|
|
949
999
|
// name
|
|
950
1000
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
|
|
951
1001
|
// fields
|
|
952
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0))), true)),
|
|
1002
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
|
|
953
1003
|
// attributes
|
|
954
1004
|
...allAttributes.length > 0 ? [
|
|
955
1005
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -959,9 +1009,9 @@ var TsSchemaGenerator = class {
|
|
|
959
1009
|
}
|
|
960
1010
|
createComputedFieldsObject(fields) {
|
|
961
1011
|
return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [
|
|
962
|
-
// parameter: `context: {
|
|
1012
|
+
// parameter: `context: { modelAlias: string }`
|
|
963
1013
|
ts.factory.createParameterDeclaration(void 0, void 0, "_context", void 0, ts.factory.createTypeLiteralNode([
|
|
964
|
-
ts.factory.createPropertySignature(void 0, "
|
|
1014
|
+
ts.factory.createPropertySignature(void 0, "modelAlias", void 0, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))
|
|
965
1015
|
]), void 0)
|
|
966
1016
|
], ts.factory.createTypeReferenceNode("OperandExpression", [
|
|
967
1017
|
ts.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type))
|
|
@@ -981,7 +1031,7 @@ var TsSchemaGenerator = class {
|
|
|
981
1031
|
}
|
|
982
1032
|
return result;
|
|
983
1033
|
}
|
|
984
|
-
createDataFieldObject(field, contextModel) {
|
|
1034
|
+
createDataFieldObject(field, contextModel, lite) {
|
|
985
1035
|
const objectFields = [
|
|
986
1036
|
// name
|
|
987
1037
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
@@ -1010,22 +1060,24 @@ var TsSchemaGenerator = class {
|
|
|
1010
1060
|
if (this.isDiscriminatorField(field)) {
|
|
1011
1061
|
objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
|
|
1012
1062
|
}
|
|
1013
|
-
if (field.attributes.length > 0) {
|
|
1063
|
+
if (!lite && field.attributes.length > 0) {
|
|
1014
1064
|
objectFields.push(ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr)))));
|
|
1015
1065
|
}
|
|
1016
1066
|
const defaultValue = this.getFieldMappedDefault(field);
|
|
1017
1067
|
if (defaultValue !== void 0) {
|
|
1018
1068
|
if (typeof defaultValue === "object" && !Array.isArray(defaultValue)) {
|
|
1019
1069
|
if ("call" in defaultValue) {
|
|
1020
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
1070
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("call", [
|
|
1021
1071
|
ts.factory.createStringLiteral(defaultValue.call),
|
|
1022
1072
|
...defaultValue.args.length > 0 ? [
|
|
1023
|
-
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.
|
|
1073
|
+
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createExpressionUtilsCall("literal", [
|
|
1074
|
+
this.createLiteralNode(arg)
|
|
1075
|
+
])))
|
|
1024
1076
|
] : []
|
|
1025
1077
|
])));
|
|
1026
1078
|
} else if ("authMember" in defaultValue) {
|
|
1027
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
1028
|
-
|
|
1079
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("member", [
|
|
1080
|
+
this.createExpressionUtilsCall("call", [
|
|
1029
1081
|
ts.factory.createStringLiteral("auth")
|
|
1030
1082
|
]),
|
|
1031
1083
|
ts.factory.createArrayLiteralExpression(defaultValue.authMember.map((m) => ts.factory.createStringLiteral(m)))
|
|
@@ -1061,11 +1113,18 @@ var TsSchemaGenerator = class {
|
|
|
1061
1113
|
const dataSource = model.declarations.find(import_ast3.isDataSource);
|
|
1062
1114
|
(0, import_common_helpers2.invariant)(dataSource, "No data source found in the model");
|
|
1063
1115
|
const providerExpr = dataSource.fields.find((f) => f.name === "provider")?.value;
|
|
1064
|
-
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(providerExpr), "Provider must be a literal");
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1116
|
+
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(providerExpr) && typeof providerExpr.value === "string", "Provider must be a string literal");
|
|
1117
|
+
return providerExpr.value;
|
|
1118
|
+
}
|
|
1119
|
+
getDataSourceDefaultSchema(model) {
|
|
1120
|
+
const dataSource = model.declarations.find(import_ast3.isDataSource);
|
|
1121
|
+
(0, import_common_helpers2.invariant)(dataSource, "No data source found in the model");
|
|
1122
|
+
const defaultSchemaExpr = dataSource.fields.find((f) => f.name === "defaultSchema")?.value;
|
|
1123
|
+
if (!defaultSchemaExpr) {
|
|
1124
|
+
return void 0;
|
|
1125
|
+
}
|
|
1126
|
+
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(defaultSchemaExpr) && typeof defaultSchemaExpr.value === "string", "Default schema must be a string literal");
|
|
1127
|
+
return defaultSchemaExpr.value;
|
|
1069
1128
|
}
|
|
1070
1129
|
getFieldMappedDefault(field) {
|
|
1071
1130
|
const defaultAttr = getAttribute(field, "@default");
|
|
@@ -1135,12 +1194,16 @@ var TsSchemaGenerator = class {
|
|
|
1135
1194
|
relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
|
|
1136
1195
|
}
|
|
1137
1196
|
const relation = getAttribute(field, "@relation");
|
|
1197
|
+
const fkFields = [];
|
|
1138
1198
|
if (relation) {
|
|
1139
1199
|
for (const arg of relation.args) {
|
|
1140
1200
|
const param = arg.$resolvedParam.name;
|
|
1141
1201
|
if (param === "fields" || param === "references") {
|
|
1142
1202
|
const fieldNames = this.getReferenceNames(arg.value);
|
|
1143
1203
|
if (fieldNames) {
|
|
1204
|
+
if (param === "fields") {
|
|
1205
|
+
fkFields.push(...fieldNames);
|
|
1206
|
+
}
|
|
1144
1207
|
relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
|
|
1145
1208
|
}
|
|
1146
1209
|
}
|
|
@@ -1150,6 +1213,15 @@ var TsSchemaGenerator = class {
|
|
|
1150
1213
|
}
|
|
1151
1214
|
}
|
|
1152
1215
|
}
|
|
1216
|
+
if (fkFields.length > 0) {
|
|
1217
|
+
const allHaveDefault = fkFields.every((fieldName) => {
|
|
1218
|
+
const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
|
|
1219
|
+
return fieldDef && hasAttribute(fieldDef, "@default");
|
|
1220
|
+
});
|
|
1221
|
+
if (allHaveDefault) {
|
|
1222
|
+
relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1153
1225
|
return ts.factory.createObjectLiteralExpression(relationFields);
|
|
1154
1226
|
}
|
|
1155
1227
|
getReferenceNames(expr) {
|
|
@@ -1218,7 +1290,11 @@ var TsSchemaGenerator = class {
|
|
|
1218
1290
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1219
1291
|
for (const attr of allAttributes) {
|
|
1220
1292
|
if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
|
|
1221
|
-
const
|
|
1293
|
+
const fieldsArg = (0, import_utils3.getAttributeArg)(attr, "fields");
|
|
1294
|
+
if (!fieldsArg) {
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
const fieldNames = this.getReferenceNames(fieldsArg);
|
|
1222
1298
|
if (!fieldNames) {
|
|
1223
1299
|
continue;
|
|
1224
1300
|
}
|
|
@@ -1257,7 +1333,21 @@ var TsSchemaGenerator = class {
|
|
|
1257
1333
|
return field.type.type ? ts.factory.createStringLiteral(field.type.type) : field.type.reference ? ts.factory.createStringLiteral(field.type.reference.$refText) : ts.factory.createStringLiteral("Unsupported");
|
|
1258
1334
|
}
|
|
1259
1335
|
createEnumObject(e) {
|
|
1260
|
-
return ts.factory.createObjectLiteralExpression(
|
|
1336
|
+
return ts.factory.createObjectLiteralExpression([
|
|
1337
|
+
ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
|
|
1338
|
+
// only generate `fields` if there are attributes on the fields
|
|
1339
|
+
...e.fields.some((f) => f.attributes.length > 0) ? [
|
|
1340
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([
|
|
1341
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
1342
|
+
...field.attributes.length > 0 ? [
|
|
1343
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes?.map((attr) => this.createAttributeObject(attr)) ?? [], true))
|
|
1344
|
+
] : []
|
|
1345
|
+
], true))), true))
|
|
1346
|
+
] : [],
|
|
1347
|
+
...e.attributes.length > 0 ? [
|
|
1348
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(e.attributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
1349
|
+
] : []
|
|
1350
|
+
], true);
|
|
1261
1351
|
}
|
|
1262
1352
|
getLiteral(expr) {
|
|
1263
1353
|
if (!(0, import_ast3.isLiteralExpr)(expr)) {
|
|
@@ -1339,7 +1429,7 @@ var TsSchemaGenerator = class {
|
|
|
1339
1429
|
});
|
|
1340
1430
|
}
|
|
1341
1431
|
createThisExpression() {
|
|
1342
|
-
return
|
|
1432
|
+
return this.createExpressionUtilsCall("_this");
|
|
1343
1433
|
}
|
|
1344
1434
|
createMemberExpression(expr) {
|
|
1345
1435
|
const members = [];
|
|
@@ -1353,32 +1443,32 @@ var TsSchemaGenerator = class {
|
|
|
1353
1443
|
this.createExpression(receiver),
|
|
1354
1444
|
ts.factory.createArrayLiteralExpression(members.map((m) => ts.factory.createStringLiteral(m)))
|
|
1355
1445
|
];
|
|
1356
|
-
return
|
|
1446
|
+
return this.createExpressionUtilsCall("member", args);
|
|
1357
1447
|
}
|
|
1358
1448
|
createNullExpression() {
|
|
1359
|
-
return
|
|
1449
|
+
return this.createExpressionUtilsCall("_null");
|
|
1360
1450
|
}
|
|
1361
1451
|
createBinaryExpression(expr) {
|
|
1362
|
-
return
|
|
1452
|
+
return this.createExpressionUtilsCall("binary", [
|
|
1363
1453
|
this.createExpression(expr.left),
|
|
1364
1454
|
this.createLiteralNode(expr.operator),
|
|
1365
1455
|
this.createExpression(expr.right)
|
|
1366
1456
|
]);
|
|
1367
1457
|
}
|
|
1368
1458
|
createUnaryExpression(expr) {
|
|
1369
|
-
return
|
|
1459
|
+
return this.createExpressionUtilsCall("unary", [
|
|
1370
1460
|
this.createLiteralNode(expr.operator),
|
|
1371
1461
|
this.createExpression(expr.operand)
|
|
1372
1462
|
]);
|
|
1373
1463
|
}
|
|
1374
1464
|
createArrayExpression(expr) {
|
|
1375
|
-
return
|
|
1465
|
+
return this.createExpressionUtilsCall("array", [
|
|
1376
1466
|
ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))
|
|
1377
1467
|
]);
|
|
1378
1468
|
}
|
|
1379
1469
|
createRefExpression(expr) {
|
|
1380
1470
|
if ((0, import_ast3.isDataField)(expr.target.ref)) {
|
|
1381
|
-
return
|
|
1471
|
+
return this.createExpressionUtilsCall("field", [
|
|
1382
1472
|
this.createLiteralNode(expr.target.$refText)
|
|
1383
1473
|
]);
|
|
1384
1474
|
} else if ((0, import_ast3.isEnumField)(expr.target.ref)) {
|
|
@@ -1388,7 +1478,7 @@ var TsSchemaGenerator = class {
|
|
|
1388
1478
|
}
|
|
1389
1479
|
}
|
|
1390
1480
|
createCallExpression(expr) {
|
|
1391
|
-
return
|
|
1481
|
+
return this.createExpressionUtilsCall("call", [
|
|
1392
1482
|
ts.factory.createStringLiteral(expr.function.$refText),
|
|
1393
1483
|
...expr.args.length > 0 ? [
|
|
1394
1484
|
ts.factory.createArrayLiteralExpression(expr.args.map((arg) => this.createExpression(arg.value)))
|
|
@@ -1396,25 +1486,25 @@ var TsSchemaGenerator = class {
|
|
|
1396
1486
|
]);
|
|
1397
1487
|
}
|
|
1398
1488
|
createLiteralExpression(type, value) {
|
|
1399
|
-
return (0, import_ts_pattern2.match)(type).with("BooleanLiteral", () =>
|
|
1489
|
+
return (0, import_ts_pattern2.match)(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1400
1490
|
this.createLiteralNode(value)
|
|
1401
|
-
])).with("NumberLiteral", () =>
|
|
1491
|
+
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1402
1492
|
ts.factory.createIdentifier(value)
|
|
1403
|
-
])).with("StringLiteral", () =>
|
|
1493
|
+
])).with("StringLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1404
1494
|
this.createLiteralNode(value)
|
|
1405
1495
|
])).otherwise(() => {
|
|
1406
1496
|
throw new Error(`Unsupported literal type: ${type}`);
|
|
1407
1497
|
});
|
|
1408
1498
|
}
|
|
1409
|
-
generateModelsAndTypeDefs(model,
|
|
1499
|
+
generateModelsAndTypeDefs(model, options) {
|
|
1410
1500
|
const statements = [];
|
|
1411
|
-
statements.push(this.generateSchemaImport(model, true, true));
|
|
1501
|
+
statements.push(this.generateSchemaImport(model, true, true, !!(options.lite || options.liteOnly)));
|
|
1412
1502
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
1413
1503
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)),
|
|
1414
1504
|
...model.declarations.some(import_ast3.isTypeDef) ? [
|
|
1415
1505
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1416
1506
|
] : []
|
|
1417
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1507
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1418
1508
|
const dataModels = model.declarations.filter(import_ast3.isDataModel);
|
|
1419
1509
|
for (const dm of dataModels) {
|
|
1420
1510
|
let modelType = ts.factory.createTypeAliasDeclaration([
|
|
@@ -1446,7 +1536,7 @@ var TsSchemaGenerator = class {
|
|
|
1446
1536
|
let enumDecl = ts.factory.createVariableStatement([
|
|
1447
1537
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1448
1538
|
], ts.factory.createVariableDeclarationList([
|
|
1449
|
-
ts.factory.createVariableDeclaration(e.name, void 0, void 0, ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("$schema"), ts.factory.createIdentifier("enums")), ts.factory.createIdentifier(e.name)))
|
|
1539
|
+
ts.factory.createVariableDeclaration(e.name, void 0, void 0, ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("$schema"), ts.factory.createIdentifier("enums")), ts.factory.createIdentifier(e.name)), ts.factory.createIdentifier("values")))
|
|
1450
1540
|
], ts.NodeFlags.Const));
|
|
1451
1541
|
if (e.comments.length > 0) {
|
|
1452
1542
|
enumDecl = this.generateDocs(enumDecl, e);
|
|
@@ -1461,13 +1551,13 @@ var TsSchemaGenerator = class {
|
|
|
1461
1551
|
statements.push(typeAlias);
|
|
1462
1552
|
}
|
|
1463
1553
|
this.generateBannerComments(statements);
|
|
1464
|
-
const outputFile = import_node_path.default.join(
|
|
1554
|
+
const outputFile = import_node_path.default.join(options.outDir, "models.ts");
|
|
1465
1555
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1466
1556
|
const printer = ts.createPrinter();
|
|
1467
1557
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1468
1558
|
import_node_fs.default.writeFileSync(outputFile, result);
|
|
1469
1559
|
}
|
|
1470
|
-
generateSchemaImport(model, schemaObject, schemaType) {
|
|
1560
|
+
generateSchemaImport(model, schemaObject, schemaType, useLite) {
|
|
1471
1561
|
const importSpecifiers = [];
|
|
1472
1562
|
if (schemaObject) {
|
|
1473
1563
|
if (model.declarations.some(import_ast3.isEnum)) {
|
|
@@ -1477,17 +1567,17 @@ var TsSchemaGenerator = class {
|
|
|
1477
1567
|
if (schemaType) {
|
|
1478
1568
|
importSpecifiers.push(ts.factory.createImportSpecifier(true, ts.factory.createIdentifier("SchemaType"), ts.factory.createIdentifier("$Schema")));
|
|
1479
1569
|
}
|
|
1480
|
-
return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral("./schema"));
|
|
1570
|
+
return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral(useLite ? "./schema-lite" : "./schema"));
|
|
1481
1571
|
}
|
|
1482
1572
|
generateDocs(tsDecl, decl) {
|
|
1483
1573
|
return ts.addSyntheticLeadingComment(tsDecl, ts.SyntaxKind.MultiLineCommentTrivia, `*
|
|
1484
1574
|
* ${decl.comments.map((c) => c.replace(/^\s*\/*\s*/, "")).join("\n * ")}
|
|
1485
1575
|
`, true);
|
|
1486
1576
|
}
|
|
1487
|
-
generateInputTypes(model,
|
|
1577
|
+
generateInputTypes(model, options) {
|
|
1488
1578
|
const dataModels = model.declarations.filter(import_ast3.isDataModel);
|
|
1489
1579
|
const statements = [];
|
|
1490
|
-
statements.push(this.generateSchemaImport(model, false, true));
|
|
1580
|
+
statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly)));
|
|
1491
1581
|
const inputTypes = [
|
|
1492
1582
|
"FindManyArgs",
|
|
1493
1583
|
"FindUniqueArgs",
|
|
@@ -1514,11 +1604,11 @@ var TsSchemaGenerator = class {
|
|
|
1514
1604
|
IncludeInput: "Include",
|
|
1515
1605
|
OmitInput: "Omit"
|
|
1516
1606
|
};
|
|
1517
|
-
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports(inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))))), ts.factory.createStringLiteral("@zenstackhq/
|
|
1607
|
+
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports(inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))))), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1518
1608
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1519
1609
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedModelResult as $SimplifiedModelResult")),
|
|
1520
1610
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
|
|
1521
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1611
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1522
1612
|
for (const dm of dataModels) {
|
|
1523
1613
|
for (const inputType of inputTypes) {
|
|
1524
1614
|
const exportName = inputTypeNameFixes[inputType] ? `${dm.name}${inputTypeNameFixes[inputType]}` : `${dm.name}${inputType}`;
|
|
@@ -1544,518 +1634,17 @@ var TsSchemaGenerator = class {
|
|
|
1544
1634
|
])));
|
|
1545
1635
|
}
|
|
1546
1636
|
this.generateBannerComments(statements);
|
|
1547
|
-
const outputFile = import_node_path.default.join(
|
|
1637
|
+
const outputFile = import_node_path.default.join(options.outDir, "input.ts");
|
|
1548
1638
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1549
1639
|
const printer = ts.createPrinter();
|
|
1550
1640
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1551
1641
|
import_node_fs.default.writeFileSync(outputFile, result);
|
|
1552
1642
|
}
|
|
1553
1643
|
};
|
|
1554
|
-
|
|
1555
|
-
// src/zmodel-code-generator.ts
|
|
1556
|
-
var import_ast4 = require("@zenstackhq/language/ast");
|
|
1557
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
1558
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1559
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1560
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1561
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1562
|
-
}
|
|
1563
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
1564
|
-
function _ts_metadata(k, v) {
|
|
1565
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1566
|
-
}
|
|
1567
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
1568
|
-
var generationHandlers = /* @__PURE__ */ new Map();
|
|
1569
|
-
function gen(name) {
|
|
1570
|
-
return function(_target, _propertyKey, descriptor) {
|
|
1571
|
-
if (!generationHandlers.get(name)) {
|
|
1572
|
-
generationHandlers.set(name, descriptor);
|
|
1573
|
-
}
|
|
1574
|
-
return descriptor;
|
|
1575
|
-
};
|
|
1576
|
-
}
|
|
1577
|
-
__name(gen, "gen");
|
|
1578
|
-
var ZModelCodeGenerator = class {
|
|
1579
|
-
static {
|
|
1580
|
-
__name(this, "ZModelCodeGenerator");
|
|
1581
|
-
}
|
|
1582
|
-
options;
|
|
1583
|
-
constructor(options) {
|
|
1584
|
-
this.options = {
|
|
1585
|
-
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
1586
|
-
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
1587
|
-
indent: options?.indent ?? 4,
|
|
1588
|
-
quote: options?.quote ?? "single"
|
|
1589
|
-
};
|
|
1590
|
-
}
|
|
1591
|
-
/**
|
|
1592
|
-
* Generates ZModel source code from AST.
|
|
1593
|
-
*/
|
|
1594
|
-
generate(ast) {
|
|
1595
|
-
const handler = generationHandlers.get(ast.$type);
|
|
1596
|
-
if (!handler) {
|
|
1597
|
-
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
1598
|
-
}
|
|
1599
|
-
return handler.value.call(this, ast);
|
|
1600
|
-
}
|
|
1601
|
-
_generateModel(ast) {
|
|
1602
|
-
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
1603
|
-
}
|
|
1604
|
-
_generateDataSource(ast) {
|
|
1605
|
-
return `datasource ${ast.name} {
|
|
1606
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1607
|
-
}`;
|
|
1608
|
-
}
|
|
1609
|
-
_generateEnum(ast) {
|
|
1610
|
-
return `enum ${ast.name} {
|
|
1611
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1612
|
-
}`;
|
|
1613
|
-
}
|
|
1614
|
-
_generateEnumField(ast) {
|
|
1615
|
-
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1616
|
-
}
|
|
1617
|
-
_generateGenerator(ast) {
|
|
1618
|
-
return `generator ${ast.name} {
|
|
1619
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1620
|
-
}`;
|
|
1621
|
-
}
|
|
1622
|
-
_generateConfigField(ast) {
|
|
1623
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1624
|
-
}
|
|
1625
|
-
_generateConfigArrayExpr(ast) {
|
|
1626
|
-
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
1627
|
-
}
|
|
1628
|
-
_generateConfigInvocationExpr(ast) {
|
|
1629
|
-
if (ast.args.length === 0) {
|
|
1630
|
-
return ast.name;
|
|
1631
|
-
} else {
|
|
1632
|
-
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
_generatePlugin(ast) {
|
|
1636
|
-
return `plugin ${ast.name} {
|
|
1637
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1638
|
-
}`;
|
|
1639
|
-
}
|
|
1640
|
-
_generatePluginField(ast) {
|
|
1641
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1642
|
-
}
|
|
1643
|
-
_generateDataModel(ast) {
|
|
1644
|
-
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.ref?.name).join(", ") : ""} {
|
|
1645
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
1646
|
-
}`;
|
|
1647
|
-
}
|
|
1648
|
-
_generateDataField(ast) {
|
|
1649
|
-
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1650
|
-
}
|
|
1651
|
-
fieldType(type) {
|
|
1652
|
-
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
1653
|
-
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
1654
|
-
}
|
|
1655
|
-
_generateDataModelAttribute(ast) {
|
|
1656
|
-
return this.attribute(ast);
|
|
1657
|
-
}
|
|
1658
|
-
_generateDataFieldAttribute(ast) {
|
|
1659
|
-
return this.attribute(ast);
|
|
1660
|
-
}
|
|
1661
|
-
attribute(ast) {
|
|
1662
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
1663
|
-
return `${resolved(ast.decl).name}${args}`;
|
|
1664
|
-
}
|
|
1665
|
-
_generateAttributeArg(ast) {
|
|
1666
|
-
if (ast.name) {
|
|
1667
|
-
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
1668
|
-
} else {
|
|
1669
|
-
return this.generate(ast.value);
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
_generateObjectExpr(ast) {
|
|
1673
|
-
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
1674
|
-
}
|
|
1675
|
-
objectField(field) {
|
|
1676
|
-
return `${field.name}: ${this.generate(field.value)}`;
|
|
1677
|
-
}
|
|
1678
|
-
_generateArrayExpr(ast) {
|
|
1679
|
-
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
1680
|
-
}
|
|
1681
|
-
_generateLiteralExpr(ast) {
|
|
1682
|
-
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
1683
|
-
}
|
|
1684
|
-
_generateNumberLiteral(ast) {
|
|
1685
|
-
return ast.value.toString();
|
|
1686
|
-
}
|
|
1687
|
-
_generateBooleanLiteral(ast) {
|
|
1688
|
-
return ast.value.toString();
|
|
1689
|
-
}
|
|
1690
|
-
_generateUnaryExpr(ast) {
|
|
1691
|
-
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
1692
|
-
}
|
|
1693
|
-
_generateBinaryExpr(ast) {
|
|
1694
|
-
const operator = ast.operator;
|
|
1695
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
1696
|
-
const rightExpr = this.generate(ast.right);
|
|
1697
|
-
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
1698
|
-
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
1699
|
-
}
|
|
1700
|
-
_generateReferenceExpr(ast) {
|
|
1701
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
1702
|
-
return `${ast.target.ref?.name}${args}`;
|
|
1703
|
-
}
|
|
1704
|
-
_generateReferenceArg(ast) {
|
|
1705
|
-
return `${ast.name}:${this.generate(ast.value)}`;
|
|
1706
|
-
}
|
|
1707
|
-
_generateMemberExpr(ast) {
|
|
1708
|
-
return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
|
|
1709
|
-
}
|
|
1710
|
-
_generateInvocationExpr(ast) {
|
|
1711
|
-
return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
1712
|
-
}
|
|
1713
|
-
_generateNullExpr() {
|
|
1714
|
-
return "null";
|
|
1715
|
-
}
|
|
1716
|
-
_generateThisExpr() {
|
|
1717
|
-
return "this";
|
|
1718
|
-
}
|
|
1719
|
-
_generateAttribute(ast) {
|
|
1720
|
-
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
1721
|
-
}
|
|
1722
|
-
_generateAttributeParam(ast) {
|
|
1723
|
-
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
1724
|
-
}
|
|
1725
|
-
_generateAttributeParamType(ast) {
|
|
1726
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
1727
|
-
}
|
|
1728
|
-
_generateFunctionDecl(ast) {
|
|
1729
|
-
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
1730
|
-
}
|
|
1731
|
-
_generateFunctionParam(ast) {
|
|
1732
|
-
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
1733
|
-
}
|
|
1734
|
-
_generateFunctionParamType(ast) {
|
|
1735
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
1736
|
-
}
|
|
1737
|
-
_generateTypeDef(ast) {
|
|
1738
|
-
return `type ${ast.name} {
|
|
1739
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
1740
|
-
}`;
|
|
1741
|
-
}
|
|
1742
|
-
argument(ast) {
|
|
1743
|
-
return this.generate(ast.value);
|
|
1744
|
-
}
|
|
1745
|
-
get binaryExprSpace() {
|
|
1746
|
-
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
1747
|
-
}
|
|
1748
|
-
get unaryExprSpace() {
|
|
1749
|
-
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
1750
|
-
}
|
|
1751
|
-
get indent() {
|
|
1752
|
-
return " ".repeat(this.options.indent);
|
|
1753
|
-
}
|
|
1754
|
-
isParenthesesNeededForBinaryExpr(ast) {
|
|
1755
|
-
const result = {
|
|
1756
|
-
left: false,
|
|
1757
|
-
right: false
|
|
1758
|
-
};
|
|
1759
|
-
const operator = ast.operator;
|
|
1760
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
1761
|
-
const currentPriority = import_ast4.BinaryExprOperatorPriority[operator];
|
|
1762
|
-
if (ast.left.$type === import_ast4.BinaryExpr && import_ast4.BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
1763
|
-
result.left = true;
|
|
1764
|
-
}
|
|
1765
|
-
if (!isCollectionPredicate && ast.right.$type === import_ast4.BinaryExpr && import_ast4.BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
1766
|
-
result.right = true;
|
|
1767
|
-
}
|
|
1768
|
-
return result;
|
|
1769
|
-
}
|
|
1770
|
-
isCollectionPredicateOperator(op) {
|
|
1771
|
-
return [
|
|
1772
|
-
"?",
|
|
1773
|
-
"!",
|
|
1774
|
-
"^"
|
|
1775
|
-
].includes(op);
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
1778
|
-
_ts_decorate([
|
|
1779
|
-
gen(import_ast4.Model),
|
|
1780
|
-
_ts_metadata("design:type", Function),
|
|
1781
|
-
_ts_metadata("design:paramtypes", [
|
|
1782
|
-
typeof import_ast4.Model === "undefined" ? Object : import_ast4.Model
|
|
1783
|
-
]),
|
|
1784
|
-
_ts_metadata("design:returntype", void 0)
|
|
1785
|
-
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
1786
|
-
_ts_decorate([
|
|
1787
|
-
gen(import_ast4.DataSource),
|
|
1788
|
-
_ts_metadata("design:type", Function),
|
|
1789
|
-
_ts_metadata("design:paramtypes", [
|
|
1790
|
-
typeof import_ast4.DataSource === "undefined" ? Object : import_ast4.DataSource
|
|
1791
|
-
]),
|
|
1792
|
-
_ts_metadata("design:returntype", void 0)
|
|
1793
|
-
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
1794
|
-
_ts_decorate([
|
|
1795
|
-
gen(import_ast4.Enum),
|
|
1796
|
-
_ts_metadata("design:type", Function),
|
|
1797
|
-
_ts_metadata("design:paramtypes", [
|
|
1798
|
-
typeof import_ast4.Enum === "undefined" ? Object : import_ast4.Enum
|
|
1799
|
-
]),
|
|
1800
|
-
_ts_metadata("design:returntype", void 0)
|
|
1801
|
-
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
1802
|
-
_ts_decorate([
|
|
1803
|
-
gen(import_ast4.EnumField),
|
|
1804
|
-
_ts_metadata("design:type", Function),
|
|
1805
|
-
_ts_metadata("design:paramtypes", [
|
|
1806
|
-
typeof import_ast4.EnumField === "undefined" ? Object : import_ast4.EnumField
|
|
1807
|
-
]),
|
|
1808
|
-
_ts_metadata("design:returntype", void 0)
|
|
1809
|
-
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
1810
|
-
_ts_decorate([
|
|
1811
|
-
gen(import_ast4.GeneratorDecl),
|
|
1812
|
-
_ts_metadata("design:type", Function),
|
|
1813
|
-
_ts_metadata("design:paramtypes", [
|
|
1814
|
-
typeof import_ast4.GeneratorDecl === "undefined" ? Object : import_ast4.GeneratorDecl
|
|
1815
|
-
]),
|
|
1816
|
-
_ts_metadata("design:returntype", void 0)
|
|
1817
|
-
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
1818
|
-
_ts_decorate([
|
|
1819
|
-
gen(import_ast4.ConfigField),
|
|
1820
|
-
_ts_metadata("design:type", Function),
|
|
1821
|
-
_ts_metadata("design:paramtypes", [
|
|
1822
|
-
typeof import_ast4.ConfigField === "undefined" ? Object : import_ast4.ConfigField
|
|
1823
|
-
]),
|
|
1824
|
-
_ts_metadata("design:returntype", void 0)
|
|
1825
|
-
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
1826
|
-
_ts_decorate([
|
|
1827
|
-
gen(import_ast4.ConfigArrayExpr),
|
|
1828
|
-
_ts_metadata("design:type", Function),
|
|
1829
|
-
_ts_metadata("design:paramtypes", [
|
|
1830
|
-
typeof import_ast4.ConfigArrayExpr === "undefined" ? Object : import_ast4.ConfigArrayExpr
|
|
1831
|
-
]),
|
|
1832
|
-
_ts_metadata("design:returntype", void 0)
|
|
1833
|
-
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
1834
|
-
_ts_decorate([
|
|
1835
|
-
gen(import_ast4.ConfigInvocationExpr),
|
|
1836
|
-
_ts_metadata("design:type", Function),
|
|
1837
|
-
_ts_metadata("design:paramtypes", [
|
|
1838
|
-
typeof import_ast4.ConfigInvocationExpr === "undefined" ? Object : import_ast4.ConfigInvocationExpr
|
|
1839
|
-
]),
|
|
1840
|
-
_ts_metadata("design:returntype", void 0)
|
|
1841
|
-
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
1842
|
-
_ts_decorate([
|
|
1843
|
-
gen(import_ast4.Plugin),
|
|
1844
|
-
_ts_metadata("design:type", Function),
|
|
1845
|
-
_ts_metadata("design:paramtypes", [
|
|
1846
|
-
typeof import_ast4.Plugin === "undefined" ? Object : import_ast4.Plugin
|
|
1847
|
-
]),
|
|
1848
|
-
_ts_metadata("design:returntype", void 0)
|
|
1849
|
-
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
1850
|
-
_ts_decorate([
|
|
1851
|
-
gen(import_ast4.PluginField),
|
|
1852
|
-
_ts_metadata("design:type", Function),
|
|
1853
|
-
_ts_metadata("design:paramtypes", [
|
|
1854
|
-
typeof import_ast4.PluginField === "undefined" ? Object : import_ast4.PluginField
|
|
1855
|
-
]),
|
|
1856
|
-
_ts_metadata("design:returntype", void 0)
|
|
1857
|
-
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
1858
|
-
_ts_decorate([
|
|
1859
|
-
gen(import_ast4.DataModel),
|
|
1860
|
-
_ts_metadata("design:type", Function),
|
|
1861
|
-
_ts_metadata("design:paramtypes", [
|
|
1862
|
-
typeof import_ast4.DataModel === "undefined" ? Object : import_ast4.DataModel
|
|
1863
|
-
]),
|
|
1864
|
-
_ts_metadata("design:returntype", void 0)
|
|
1865
|
-
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
1866
|
-
_ts_decorate([
|
|
1867
|
-
gen(import_ast4.DataField),
|
|
1868
|
-
_ts_metadata("design:type", Function),
|
|
1869
|
-
_ts_metadata("design:paramtypes", [
|
|
1870
|
-
typeof import_ast4.DataField === "undefined" ? Object : import_ast4.DataField
|
|
1871
|
-
]),
|
|
1872
|
-
_ts_metadata("design:returntype", void 0)
|
|
1873
|
-
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
1874
|
-
_ts_decorate([
|
|
1875
|
-
gen(import_ast4.DataModelAttribute),
|
|
1876
|
-
_ts_metadata("design:type", Function),
|
|
1877
|
-
_ts_metadata("design:paramtypes", [
|
|
1878
|
-
typeof import_ast4.DataModelAttribute === "undefined" ? Object : import_ast4.DataModelAttribute
|
|
1879
|
-
]),
|
|
1880
|
-
_ts_metadata("design:returntype", void 0)
|
|
1881
|
-
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
1882
|
-
_ts_decorate([
|
|
1883
|
-
gen(import_ast4.DataFieldAttribute),
|
|
1884
|
-
_ts_metadata("design:type", Function),
|
|
1885
|
-
_ts_metadata("design:paramtypes", [
|
|
1886
|
-
typeof import_ast4.DataFieldAttribute === "undefined" ? Object : import_ast4.DataFieldAttribute
|
|
1887
|
-
]),
|
|
1888
|
-
_ts_metadata("design:returntype", void 0)
|
|
1889
|
-
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
1890
|
-
_ts_decorate([
|
|
1891
|
-
gen(import_ast4.AttributeArg),
|
|
1892
|
-
_ts_metadata("design:type", Function),
|
|
1893
|
-
_ts_metadata("design:paramtypes", [
|
|
1894
|
-
typeof import_ast4.AttributeArg === "undefined" ? Object : import_ast4.AttributeArg
|
|
1895
|
-
]),
|
|
1896
|
-
_ts_metadata("design:returntype", void 0)
|
|
1897
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
1898
|
-
_ts_decorate([
|
|
1899
|
-
gen(import_ast4.ObjectExpr),
|
|
1900
|
-
_ts_metadata("design:type", Function),
|
|
1901
|
-
_ts_metadata("design:paramtypes", [
|
|
1902
|
-
typeof import_ast4.ObjectExpr === "undefined" ? Object : import_ast4.ObjectExpr
|
|
1903
|
-
]),
|
|
1904
|
-
_ts_metadata("design:returntype", void 0)
|
|
1905
|
-
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
1906
|
-
_ts_decorate([
|
|
1907
|
-
gen(import_ast4.ArrayExpr),
|
|
1908
|
-
_ts_metadata("design:type", Function),
|
|
1909
|
-
_ts_metadata("design:paramtypes", [
|
|
1910
|
-
typeof import_ast4.ArrayExpr === "undefined" ? Object : import_ast4.ArrayExpr
|
|
1911
|
-
]),
|
|
1912
|
-
_ts_metadata("design:returntype", void 0)
|
|
1913
|
-
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
1914
|
-
_ts_decorate([
|
|
1915
|
-
gen(import_ast4.StringLiteral),
|
|
1916
|
-
_ts_metadata("design:type", Function),
|
|
1917
|
-
_ts_metadata("design:paramtypes", [
|
|
1918
|
-
typeof import_ast4.LiteralExpr === "undefined" ? Object : import_ast4.LiteralExpr
|
|
1919
|
-
]),
|
|
1920
|
-
_ts_metadata("design:returntype", void 0)
|
|
1921
|
-
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
1922
|
-
_ts_decorate([
|
|
1923
|
-
gen(import_ast4.NumberLiteral),
|
|
1924
|
-
_ts_metadata("design:type", Function),
|
|
1925
|
-
_ts_metadata("design:paramtypes", [
|
|
1926
|
-
typeof import_ast4.NumberLiteral === "undefined" ? Object : import_ast4.NumberLiteral
|
|
1927
|
-
]),
|
|
1928
|
-
_ts_metadata("design:returntype", void 0)
|
|
1929
|
-
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
1930
|
-
_ts_decorate([
|
|
1931
|
-
gen(import_ast4.BooleanLiteral),
|
|
1932
|
-
_ts_metadata("design:type", Function),
|
|
1933
|
-
_ts_metadata("design:paramtypes", [
|
|
1934
|
-
typeof import_ast4.BooleanLiteral === "undefined" ? Object : import_ast4.BooleanLiteral
|
|
1935
|
-
]),
|
|
1936
|
-
_ts_metadata("design:returntype", void 0)
|
|
1937
|
-
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
1938
|
-
_ts_decorate([
|
|
1939
|
-
gen(import_ast4.UnaryExpr),
|
|
1940
|
-
_ts_metadata("design:type", Function),
|
|
1941
|
-
_ts_metadata("design:paramtypes", [
|
|
1942
|
-
typeof import_ast4.UnaryExpr === "undefined" ? Object : import_ast4.UnaryExpr
|
|
1943
|
-
]),
|
|
1944
|
-
_ts_metadata("design:returntype", void 0)
|
|
1945
|
-
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
1946
|
-
_ts_decorate([
|
|
1947
|
-
gen(import_ast4.BinaryExpr),
|
|
1948
|
-
_ts_metadata("design:type", Function),
|
|
1949
|
-
_ts_metadata("design:paramtypes", [
|
|
1950
|
-
typeof import_ast4.BinaryExpr === "undefined" ? Object : import_ast4.BinaryExpr
|
|
1951
|
-
]),
|
|
1952
|
-
_ts_metadata("design:returntype", void 0)
|
|
1953
|
-
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
1954
|
-
_ts_decorate([
|
|
1955
|
-
gen(import_ast4.ReferenceExpr),
|
|
1956
|
-
_ts_metadata("design:type", Function),
|
|
1957
|
-
_ts_metadata("design:paramtypes", [
|
|
1958
|
-
typeof import_ast4.ReferenceExpr === "undefined" ? Object : import_ast4.ReferenceExpr
|
|
1959
|
-
]),
|
|
1960
|
-
_ts_metadata("design:returntype", void 0)
|
|
1961
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
1962
|
-
_ts_decorate([
|
|
1963
|
-
gen(import_ast4.ReferenceArg),
|
|
1964
|
-
_ts_metadata("design:type", Function),
|
|
1965
|
-
_ts_metadata("design:paramtypes", [
|
|
1966
|
-
typeof import_ast4.ReferenceArg === "undefined" ? Object : import_ast4.ReferenceArg
|
|
1967
|
-
]),
|
|
1968
|
-
_ts_metadata("design:returntype", void 0)
|
|
1969
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
1970
|
-
_ts_decorate([
|
|
1971
|
-
gen(import_ast4.MemberAccessExpr),
|
|
1972
|
-
_ts_metadata("design:type", Function),
|
|
1973
|
-
_ts_metadata("design:paramtypes", [
|
|
1974
|
-
typeof import_ast4.MemberAccessExpr === "undefined" ? Object : import_ast4.MemberAccessExpr
|
|
1975
|
-
]),
|
|
1976
|
-
_ts_metadata("design:returntype", void 0)
|
|
1977
|
-
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
1978
|
-
_ts_decorate([
|
|
1979
|
-
gen(import_ast4.InvocationExpr),
|
|
1980
|
-
_ts_metadata("design:type", Function),
|
|
1981
|
-
_ts_metadata("design:paramtypes", [
|
|
1982
|
-
typeof import_ast4.InvocationExpr === "undefined" ? Object : import_ast4.InvocationExpr
|
|
1983
|
-
]),
|
|
1984
|
-
_ts_metadata("design:returntype", void 0)
|
|
1985
|
-
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
1986
|
-
_ts_decorate([
|
|
1987
|
-
gen(import_ast4.NullExpr),
|
|
1988
|
-
_ts_metadata("design:type", Function),
|
|
1989
|
-
_ts_metadata("design:paramtypes", []),
|
|
1990
|
-
_ts_metadata("design:returntype", void 0)
|
|
1991
|
-
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
1992
|
-
_ts_decorate([
|
|
1993
|
-
gen(import_ast4.ThisExpr),
|
|
1994
|
-
_ts_metadata("design:type", Function),
|
|
1995
|
-
_ts_metadata("design:paramtypes", []),
|
|
1996
|
-
_ts_metadata("design:returntype", void 0)
|
|
1997
|
-
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
1998
|
-
_ts_decorate([
|
|
1999
|
-
gen(import_ast4.Attribute),
|
|
2000
|
-
_ts_metadata("design:type", Function),
|
|
2001
|
-
_ts_metadata("design:paramtypes", [
|
|
2002
|
-
typeof import_ast4.Attribute === "undefined" ? Object : import_ast4.Attribute
|
|
2003
|
-
]),
|
|
2004
|
-
_ts_metadata("design:returntype", void 0)
|
|
2005
|
-
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
2006
|
-
_ts_decorate([
|
|
2007
|
-
gen(import_ast4.AttributeParam),
|
|
2008
|
-
_ts_metadata("design:type", Function),
|
|
2009
|
-
_ts_metadata("design:paramtypes", [
|
|
2010
|
-
typeof import_ast4.AttributeParam === "undefined" ? Object : import_ast4.AttributeParam
|
|
2011
|
-
]),
|
|
2012
|
-
_ts_metadata("design:returntype", void 0)
|
|
2013
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
2014
|
-
_ts_decorate([
|
|
2015
|
-
gen(import_ast4.AttributeParamType),
|
|
2016
|
-
_ts_metadata("design:type", Function),
|
|
2017
|
-
_ts_metadata("design:paramtypes", [
|
|
2018
|
-
typeof import_ast4.AttributeParamType === "undefined" ? Object : import_ast4.AttributeParamType
|
|
2019
|
-
]),
|
|
2020
|
-
_ts_metadata("design:returntype", void 0)
|
|
2021
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
2022
|
-
_ts_decorate([
|
|
2023
|
-
gen(import_ast4.FunctionDecl),
|
|
2024
|
-
_ts_metadata("design:type", Function),
|
|
2025
|
-
_ts_metadata("design:paramtypes", [
|
|
2026
|
-
typeof import_ast4.FunctionDecl === "undefined" ? Object : import_ast4.FunctionDecl
|
|
2027
|
-
]),
|
|
2028
|
-
_ts_metadata("design:returntype", void 0)
|
|
2029
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
2030
|
-
_ts_decorate([
|
|
2031
|
-
gen(import_ast4.FunctionParam),
|
|
2032
|
-
_ts_metadata("design:type", Function),
|
|
2033
|
-
_ts_metadata("design:paramtypes", [
|
|
2034
|
-
typeof import_ast4.FunctionParam === "undefined" ? Object : import_ast4.FunctionParam
|
|
2035
|
-
]),
|
|
2036
|
-
_ts_metadata("design:returntype", void 0)
|
|
2037
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
2038
|
-
_ts_decorate([
|
|
2039
|
-
gen(import_ast4.FunctionParamType),
|
|
2040
|
-
_ts_metadata("design:type", Function),
|
|
2041
|
-
_ts_metadata("design:paramtypes", [
|
|
2042
|
-
typeof import_ast4.FunctionParamType === "undefined" ? Object : import_ast4.FunctionParamType
|
|
2043
|
-
]),
|
|
2044
|
-
_ts_metadata("design:returntype", void 0)
|
|
2045
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
2046
|
-
_ts_decorate([
|
|
2047
|
-
gen(import_ast4.TypeDef),
|
|
2048
|
-
_ts_metadata("design:type", Function),
|
|
2049
|
-
_ts_metadata("design:paramtypes", [
|
|
2050
|
-
typeof import_ast4.TypeDef === "undefined" ? Object : import_ast4.TypeDef
|
|
2051
|
-
]),
|
|
2052
|
-
_ts_metadata("design:returntype", void 0)
|
|
2053
|
-
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
2054
1644
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2055
1645
|
0 && (module.exports = {
|
|
2056
1646
|
ModelUtils,
|
|
2057
1647
|
PrismaSchemaGenerator,
|
|
2058
|
-
TsSchemaGenerator
|
|
2059
|
-
ZModelCodeGenerator
|
|
1648
|
+
TsSchemaGenerator
|
|
2060
1649
|
});
|
|
2061
1650
|
//# sourceMappingURL=index.cjs.map
|