@zenstackhq/sdk 3.0.0-beta.3 → 3.0.0-beta.31
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 +251 -613
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -71
- package/dist/index.d.ts +21 -71
- package/dist/index.js +259 -620
- package/dist/index.js.map +1 -1
- package/package.json +7 -17
- 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,9 +120,9 @@ 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
|
-
found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.name === "User");
|
|
125
|
+
found = model.declarations.find((d) => ((0, import_ast.isDataModel)(d) || (0, import_ast.isTypeDef)(d)) && d.name === "User");
|
|
127
126
|
}
|
|
128
127
|
return found;
|
|
129
128
|
}
|
|
@@ -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");
|
|
@@ -567,10 +570,13 @@ var PrismaSchemaGenerator = class {
|
|
|
567
570
|
break;
|
|
568
571
|
}
|
|
569
572
|
}
|
|
573
|
+
if (!this.zmodel.declarations.some(import_ast2.isGeneratorDecl)) {
|
|
574
|
+
this.generateDefaultGenerator(prisma);
|
|
575
|
+
}
|
|
570
576
|
return this.PRELUDE + prisma.toString();
|
|
571
577
|
}
|
|
572
578
|
generateDataSource(prisma, dataSource) {
|
|
573
|
-
const fields = dataSource.fields.map((f) => ({
|
|
579
|
+
const fields = dataSource.fields.filter((f) => !NON_PRISMA_DATASOURCE_FIELDS.includes(f.name)).map((f) => ({
|
|
574
580
|
name: f.name,
|
|
575
581
|
text: this.configExprToText(f.value)
|
|
576
582
|
}));
|
|
@@ -607,6 +613,21 @@ var PrismaSchemaGenerator = class {
|
|
|
607
613
|
text: this.configExprToText(f.value)
|
|
608
614
|
})));
|
|
609
615
|
}
|
|
616
|
+
generateDefaultGenerator(prisma) {
|
|
617
|
+
const gen = prisma.addGenerator("client", [
|
|
618
|
+
{
|
|
619
|
+
name: "provider",
|
|
620
|
+
text: '"prisma-client-js"'
|
|
621
|
+
}
|
|
622
|
+
]);
|
|
623
|
+
const dataSource = this.zmodel.declarations.find(import_ast2.isDataSource);
|
|
624
|
+
if (dataSource?.fields.some((f) => f.name === "extensions")) {
|
|
625
|
+
gen.fields.push({
|
|
626
|
+
name: "previewFeatures",
|
|
627
|
+
text: '["postgresqlExtensions"]'
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
610
631
|
generateModel(prisma, decl) {
|
|
611
632
|
const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
|
|
612
633
|
const allFields = (0, import_utils2.getAllFields)(decl, true);
|
|
@@ -618,14 +639,30 @@ var PrismaSchemaGenerator = class {
|
|
|
618
639
|
this.generateModelField(model, field, decl);
|
|
619
640
|
}
|
|
620
641
|
}
|
|
621
|
-
const allAttributes = (0, import_utils2.getAllAttributes)(decl);
|
|
622
|
-
for (const attr of allAttributes
|
|
642
|
+
const allAttributes = (0, import_utils2.getAllAttributes)(decl).filter((attr) => this.isPrismaAttribute(attr));
|
|
643
|
+
for (const attr of allAttributes) {
|
|
623
644
|
this.generateContainerAttribute(model, attr);
|
|
624
645
|
}
|
|
646
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
647
|
+
model.addAttribute("@@schema", [
|
|
648
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
649
|
+
]);
|
|
650
|
+
}
|
|
625
651
|
decl.comments.forEach((c) => model.addComment(c));
|
|
626
652
|
this.generateDelegateRelationForBase(model, decl);
|
|
627
653
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
628
654
|
}
|
|
655
|
+
getDatasourceField(zmodel, fieldName) {
|
|
656
|
+
const dataSource = zmodel.declarations.find(import_ast2.isDataSource);
|
|
657
|
+
return dataSource?.fields.find((f) => f.name === fieldName);
|
|
658
|
+
}
|
|
659
|
+
datasourceHasSchemasSetting(zmodel) {
|
|
660
|
+
return !!this.getDatasourceField(zmodel, "schemas");
|
|
661
|
+
}
|
|
662
|
+
getDefaultPostgresSchemaName(zmodel) {
|
|
663
|
+
const defaultSchemaField = this.getDatasourceField(zmodel, "defaultSchema");
|
|
664
|
+
return (0, import_utils2.getStringLiteral)(defaultSchemaField?.value) ?? "public";
|
|
665
|
+
}
|
|
629
666
|
isPrismaAttribute(attr) {
|
|
630
667
|
if (!attr.decl.ref) {
|
|
631
668
|
return false;
|
|
@@ -634,7 +671,7 @@ var PrismaSchemaGenerator = class {
|
|
|
634
671
|
}
|
|
635
672
|
getUnsupportedFieldType(fieldType) {
|
|
636
673
|
if (fieldType.unsupported) {
|
|
637
|
-
const value =
|
|
674
|
+
const value = (0, import_utils2.getStringLiteral)(fieldType.unsupported.value);
|
|
638
675
|
if (value) {
|
|
639
676
|
return `Unsupported("${value}")`;
|
|
640
677
|
} else {
|
|
@@ -644,9 +681,6 @@ var PrismaSchemaGenerator = class {
|
|
|
644
681
|
return void 0;
|
|
645
682
|
}
|
|
646
683
|
}
|
|
647
|
-
getStringLiteral(node) {
|
|
648
|
-
return (0, import_ast2.isStringLiteral)(node) ? node.value : void 0;
|
|
649
|
-
}
|
|
650
684
|
generateModelField(model, field, contextModel, addToFront = false) {
|
|
651
685
|
let fieldType;
|
|
652
686
|
if (field.type.type) {
|
|
@@ -671,7 +705,7 @@ var PrismaSchemaGenerator = class {
|
|
|
671
705
|
(0, import_ast2.isTypeDef)(field.type.reference?.ref) ? false : field.type.array
|
|
672
706
|
);
|
|
673
707
|
const type = new ModelFieldType(fieldType, isArray, field.type.optional);
|
|
674
|
-
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.
|
|
708
|
+
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.isDefaultWithAuthInvocation(attr)).filter((attr) => (
|
|
675
709
|
// when building physical schema, exclude `@default` for id fields inherited from delegate base
|
|
676
710
|
!(model_utils_exports.isIdField(field, contextModel) && this.isInheritedFromDelegate(field, contextModel) && attr.decl.$refText === "@default")
|
|
677
711
|
)).map((attr) => this.makeFieldAttribute(attr));
|
|
@@ -681,7 +715,7 @@ var PrismaSchemaGenerator = class {
|
|
|
681
715
|
const result = model.addField(field.name, type, attributes, docs, addToFront);
|
|
682
716
|
return result;
|
|
683
717
|
}
|
|
684
|
-
|
|
718
|
+
isDefaultWithAuthInvocation(attr) {
|
|
685
719
|
if (attr.decl.ref?.name !== "@default") {
|
|
686
720
|
return false;
|
|
687
721
|
}
|
|
@@ -689,11 +723,7 @@ var PrismaSchemaGenerator = class {
|
|
|
689
723
|
if (!expr) {
|
|
690
724
|
return false;
|
|
691
725
|
}
|
|
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");
|
|
726
|
+
return import_langium.AstUtils.streamAst(expr).some(import_utils2.isAuthInvocation);
|
|
697
727
|
}
|
|
698
728
|
isInheritedFromDelegate(field, contextModel) {
|
|
699
729
|
return field.$container !== contextModel && model_utils_exports.isDelegateModel(field.$container);
|
|
@@ -720,7 +750,7 @@ var PrismaSchemaGenerator = class {
|
|
|
720
750
|
}
|
|
721
751
|
}
|
|
722
752
|
exprToText(expr) {
|
|
723
|
-
return new ZModelCodeGenerator({
|
|
753
|
+
return new import_language.ZModelCodeGenerator({
|
|
724
754
|
quote: "double"
|
|
725
755
|
}).generate(expr);
|
|
726
756
|
}
|
|
@@ -741,9 +771,15 @@ var PrismaSchemaGenerator = class {
|
|
|
741
771
|
for (const field of decl.fields) {
|
|
742
772
|
this.generateEnumField(_enum, field);
|
|
743
773
|
}
|
|
744
|
-
|
|
774
|
+
const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
|
|
775
|
+
for (const attr of allAttributes) {
|
|
745
776
|
this.generateContainerAttribute(_enum, attr);
|
|
746
777
|
}
|
|
778
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
779
|
+
_enum.addAttribute("@@schema", [
|
|
780
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
781
|
+
]);
|
|
782
|
+
}
|
|
747
783
|
decl.comments.forEach((c) => _enum.addComment(c));
|
|
748
784
|
}
|
|
749
785
|
generateEnumField(_enum, field) {
|
|
@@ -821,86 +857,127 @@ var TsSchemaGenerator = class {
|
|
|
821
857
|
static {
|
|
822
858
|
__name(this, "TsSchemaGenerator");
|
|
823
859
|
}
|
|
824
|
-
|
|
825
|
-
|
|
860
|
+
usedExpressionUtils = false;
|
|
861
|
+
async generate(model, options) {
|
|
862
|
+
import_node_fs.default.mkdirSync(options.outDir, {
|
|
826
863
|
recursive: true
|
|
827
864
|
});
|
|
828
|
-
this.
|
|
829
|
-
this.
|
|
830
|
-
this.
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
865
|
+
this.usedExpressionUtils = false;
|
|
866
|
+
this.generateSchema(model, options);
|
|
867
|
+
this.generateModelsAndTypeDefs(model, options);
|
|
868
|
+
this.generateInputTypes(model, options);
|
|
869
|
+
}
|
|
870
|
+
generateSchema(model, options) {
|
|
871
|
+
const targets = [];
|
|
872
|
+
if (!options.liteOnly) {
|
|
873
|
+
targets.push({
|
|
874
|
+
lite: false,
|
|
875
|
+
file: "schema.ts"
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
if (options.lite || options.liteOnly) {
|
|
879
|
+
targets.push({
|
|
880
|
+
lite: true,
|
|
881
|
+
file: "schema-lite.ts"
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
for (const { lite, file } of targets) {
|
|
885
|
+
const statements = [];
|
|
886
|
+
this.generateSchemaStatements(model, statements, lite);
|
|
887
|
+
this.generateBannerComments(statements);
|
|
888
|
+
const schemaOutputFile = import_node_path.default.join(options.outDir, file);
|
|
889
|
+
const sourceFile = ts.createSourceFile(schemaOutputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
890
|
+
const printer = ts.createPrinter();
|
|
891
|
+
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
892
|
+
import_node_fs.default.writeFileSync(schemaOutputFile, result);
|
|
893
|
+
}
|
|
841
894
|
}
|
|
842
|
-
generateSchemaStatements(model, statements) {
|
|
895
|
+
generateSchemaStatements(model, statements, lite) {
|
|
843
896
|
const hasComputedFields = model.declarations.some((d) => (0, import_ast3.isDataModel)(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
844
|
-
const
|
|
897
|
+
const schemaClass = this.createSchemaClass(model, lite);
|
|
898
|
+
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
|
|
845
899
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
846
900
|
...hasComputedFields ? [
|
|
847
901
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
848
902
|
] : [],
|
|
849
|
-
|
|
850
|
-
|
|
903
|
+
...this.usedExpressionUtils ? [
|
|
904
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
|
|
905
|
+
] : []
|
|
906
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
851
907
|
statements.push(runtimeImportDecl);
|
|
852
|
-
|
|
908
|
+
statements.push(schemaClass);
|
|
909
|
+
const schemaDecl = ts.factory.createVariableStatement([
|
|
853
910
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
854
911
|
], ts.factory.createVariableDeclarationList([
|
|
855
|
-
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.
|
|
912
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))
|
|
856
913
|
], ts.NodeFlags.Const));
|
|
857
|
-
statements.push(
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
914
|
+
statements.push(schemaDecl);
|
|
915
|
+
}
|
|
916
|
+
createExpressionUtilsCall(method, args) {
|
|
917
|
+
this.usedExpressionUtils = true;
|
|
918
|
+
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
862
919
|
}
|
|
863
|
-
|
|
864
|
-
const
|
|
920
|
+
createSchemaClass(model, lite) {
|
|
921
|
+
const members = [
|
|
865
922
|
// provider
|
|
866
|
-
ts.factory.
|
|
923
|
+
ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
|
|
867
924
|
// models
|
|
868
|
-
ts.factory.
|
|
925
|
+
ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
|
|
869
926
|
// typeDefs
|
|
870
927
|
...model.declarations.some(import_ast3.isTypeDef) ? [
|
|
871
|
-
ts.factory.
|
|
928
|
+
ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))
|
|
872
929
|
] : []
|
|
873
930
|
];
|
|
874
931
|
const enums = model.declarations.filter(import_ast3.isEnum);
|
|
875
932
|
if (enums.length > 0) {
|
|
876
|
-
|
|
933
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "enums", void 0, void 0, this.createAsConst(ts.factory.createObjectLiteralExpression(enums.map((e) => ts.factory.createPropertyAssignment(e.name, this.createEnumObject(e))), true))));
|
|
877
934
|
}
|
|
878
935
|
const authType = getAuthDecl(model);
|
|
879
936
|
if (authType) {
|
|
880
|
-
|
|
937
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
|
|
881
938
|
}
|
|
882
939
|
const procedures = model.declarations.filter(import_ast3.isProcedure);
|
|
883
940
|
if (procedures.length > 0) {
|
|
884
|
-
|
|
941
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
|
|
885
942
|
}
|
|
886
|
-
|
|
887
|
-
|
|
943
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
|
|
944
|
+
const schemaClass = ts.factory.createClassDeclaration([
|
|
945
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
946
|
+
], "SchemaType", void 0, [
|
|
947
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
|
|
948
|
+
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)
|
|
949
|
+
])
|
|
950
|
+
], members);
|
|
951
|
+
return schemaClass;
|
|
952
|
+
}
|
|
953
|
+
createAsConst(expr) {
|
|
954
|
+
return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
|
|
888
955
|
}
|
|
889
956
|
createProviderObject(model) {
|
|
890
957
|
const dsProvider = this.getDataSourceProvider(model);
|
|
958
|
+
const defaultSchema = this.getDataSourceDefaultSchema(model);
|
|
891
959
|
return ts.factory.createObjectLiteralExpression([
|
|
892
|
-
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider
|
|
960
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider)),
|
|
961
|
+
...defaultSchema ? [
|
|
962
|
+
ts.factory.createPropertyAssignment("defaultSchema", ts.factory.createStringLiteral(defaultSchema))
|
|
963
|
+
] : []
|
|
893
964
|
], true);
|
|
894
965
|
}
|
|
895
|
-
createModelsObject(model) {
|
|
896
|
-
return ts.factory.createObjectLiteralExpression(
|
|
966
|
+
createModelsObject(model, lite) {
|
|
967
|
+
return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
|
|
968
|
+
}
|
|
969
|
+
getAllDataModels(model) {
|
|
970
|
+
return model.declarations.filter((d) => (0, import_ast3.isDataModel)(d) && !hasAttribute(d, "@@ignore"));
|
|
897
971
|
}
|
|
898
|
-
|
|
899
|
-
return
|
|
972
|
+
getAllTypeDefs(model) {
|
|
973
|
+
return model.declarations.filter((d) => (0, import_ast3.isTypeDef)(d) && !hasAttribute(d, "@@ignore"));
|
|
900
974
|
}
|
|
901
|
-
|
|
975
|
+
createTypeDefsObject(model, lite) {
|
|
976
|
+
return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
|
|
977
|
+
}
|
|
978
|
+
createDataModelObject(dm, lite) {
|
|
902
979
|
const allFields = (0, import_utils3.getAllFields)(dm);
|
|
903
|
-
const allAttributes = (0, import_utils3.getAllAttributes)(dm).filter((attr) => {
|
|
980
|
+
const allAttributes = lite ? [] : (0, import_utils3.getAllAttributes)(dm).filter((attr) => {
|
|
904
981
|
if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) {
|
|
905
982
|
return false;
|
|
906
983
|
}
|
|
@@ -915,7 +992,7 @@ var TsSchemaGenerator = class {
|
|
|
915
992
|
ts.factory.createPropertyAssignment("baseModel", ts.factory.createStringLiteral(dm.baseModel.$refText))
|
|
916
993
|
] : [],
|
|
917
994
|
// fields
|
|
918
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm))), true)),
|
|
995
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm, lite))), true)),
|
|
919
996
|
// attributes
|
|
920
997
|
...allAttributes.length > 0 ? [
|
|
921
998
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -931,6 +1008,9 @@ var TsSchemaGenerator = class {
|
|
|
931
1008
|
// subModels
|
|
932
1009
|
...subModels.length > 0 ? [
|
|
933
1010
|
ts.factory.createPropertyAssignment("subModels", ts.factory.createArrayLiteralExpression(subModels.map((subModel) => ts.factory.createStringLiteral(subModel))))
|
|
1011
|
+
] : [],
|
|
1012
|
+
...dm.isView ? [
|
|
1013
|
+
ts.factory.createPropertyAssignment("isView", ts.factory.createTrue())
|
|
934
1014
|
] : []
|
|
935
1015
|
];
|
|
936
1016
|
const computedFields = dm.fields.filter((f) => hasAttribute(f, "@computed"));
|
|
@@ -942,14 +1022,14 @@ var TsSchemaGenerator = class {
|
|
|
942
1022
|
getSubModels(dm) {
|
|
943
1023
|
return dm.$container.declarations.filter(import_ast3.isDataModel).filter((d) => d.baseModel?.ref === dm).map((d) => d.name);
|
|
944
1024
|
}
|
|
945
|
-
createTypeDefObject(td) {
|
|
1025
|
+
createTypeDefObject(td, lite) {
|
|
946
1026
|
const allFields = (0, import_utils3.getAllFields)(td);
|
|
947
1027
|
const allAttributes = (0, import_utils3.getAllAttributes)(td);
|
|
948
1028
|
const fields = [
|
|
949
1029
|
// name
|
|
950
1030
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
|
|
951
1031
|
// fields
|
|
952
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0))), true)),
|
|
1032
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
|
|
953
1033
|
// attributes
|
|
954
1034
|
...allAttributes.length > 0 ? [
|
|
955
1035
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -959,9 +1039,9 @@ var TsSchemaGenerator = class {
|
|
|
959
1039
|
}
|
|
960
1040
|
createComputedFieldsObject(fields) {
|
|
961
1041
|
return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [
|
|
962
|
-
// parameter: `context: {
|
|
1042
|
+
// parameter: `context: { modelAlias: string }`
|
|
963
1043
|
ts.factory.createParameterDeclaration(void 0, void 0, "_context", void 0, ts.factory.createTypeLiteralNode([
|
|
964
|
-
ts.factory.createPropertySignature(void 0, "
|
|
1044
|
+
ts.factory.createPropertySignature(void 0, "modelAlias", void 0, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))
|
|
965
1045
|
]), void 0)
|
|
966
1046
|
], ts.factory.createTypeReferenceNode("OperandExpression", [
|
|
967
1047
|
ts.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type))
|
|
@@ -981,7 +1061,7 @@ var TsSchemaGenerator = class {
|
|
|
981
1061
|
}
|
|
982
1062
|
return result;
|
|
983
1063
|
}
|
|
984
|
-
createDataFieldObject(field, contextModel) {
|
|
1064
|
+
createDataFieldObject(field, contextModel, lite) {
|
|
985
1065
|
const objectFields = [
|
|
986
1066
|
// name
|
|
987
1067
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
@@ -1003,6 +1083,9 @@ var TsSchemaGenerator = class {
|
|
|
1003
1083
|
if (hasAttribute(field, "@updatedAt")) {
|
|
1004
1084
|
objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
|
|
1005
1085
|
}
|
|
1086
|
+
if (hasAttribute(field, "@omit")) {
|
|
1087
|
+
objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
|
|
1088
|
+
}
|
|
1006
1089
|
if (contextModel && // id fields are duplicated in inherited models
|
|
1007
1090
|
!isIdField(field, contextModel) && field.$container !== contextModel && isDelegateModel(field.$container)) {
|
|
1008
1091
|
objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(field.$container.name)));
|
|
@@ -1010,22 +1093,24 @@ var TsSchemaGenerator = class {
|
|
|
1010
1093
|
if (this.isDiscriminatorField(field)) {
|
|
1011
1094
|
objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
|
|
1012
1095
|
}
|
|
1013
|
-
if (field.attributes.length > 0) {
|
|
1096
|
+
if (!lite && field.attributes.length > 0) {
|
|
1014
1097
|
objectFields.push(ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr)))));
|
|
1015
1098
|
}
|
|
1016
1099
|
const defaultValue = this.getFieldMappedDefault(field);
|
|
1017
1100
|
if (defaultValue !== void 0) {
|
|
1018
1101
|
if (typeof defaultValue === "object" && !Array.isArray(defaultValue)) {
|
|
1019
1102
|
if ("call" in defaultValue) {
|
|
1020
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
1103
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("call", [
|
|
1021
1104
|
ts.factory.createStringLiteral(defaultValue.call),
|
|
1022
1105
|
...defaultValue.args.length > 0 ? [
|
|
1023
|
-
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.
|
|
1106
|
+
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createExpressionUtilsCall("literal", [
|
|
1107
|
+
this.createLiteralNode(arg)
|
|
1108
|
+
])))
|
|
1024
1109
|
] : []
|
|
1025
1110
|
])));
|
|
1026
1111
|
} else if ("authMember" in defaultValue) {
|
|
1027
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
1028
|
-
|
|
1112
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("member", [
|
|
1113
|
+
this.createExpressionUtilsCall("call", [
|
|
1029
1114
|
ts.factory.createStringLiteral("auth")
|
|
1030
1115
|
]),
|
|
1031
1116
|
ts.factory.createArrayLiteralExpression(defaultValue.authMember.map((m) => ts.factory.createStringLiteral(m)))
|
|
@@ -1061,11 +1146,18 @@ var TsSchemaGenerator = class {
|
|
|
1061
1146
|
const dataSource = model.declarations.find(import_ast3.isDataSource);
|
|
1062
1147
|
(0, import_common_helpers2.invariant)(dataSource, "No data source found in the model");
|
|
1063
1148
|
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
|
-
|
|
1149
|
+
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(providerExpr) && typeof providerExpr.value === "string", "Provider must be a string literal");
|
|
1150
|
+
return providerExpr.value;
|
|
1151
|
+
}
|
|
1152
|
+
getDataSourceDefaultSchema(model) {
|
|
1153
|
+
const dataSource = model.declarations.find(import_ast3.isDataSource);
|
|
1154
|
+
(0, import_common_helpers2.invariant)(dataSource, "No data source found in the model");
|
|
1155
|
+
const defaultSchemaExpr = dataSource.fields.find((f) => f.name === "defaultSchema")?.value;
|
|
1156
|
+
if (!defaultSchemaExpr) {
|
|
1157
|
+
return void 0;
|
|
1158
|
+
}
|
|
1159
|
+
(0, import_common_helpers2.invariant)((0, import_ast3.isLiteralExpr)(defaultSchemaExpr) && typeof defaultSchemaExpr.value === "string", "Default schema must be a string literal");
|
|
1160
|
+
return defaultSchemaExpr.value;
|
|
1069
1161
|
}
|
|
1070
1162
|
getFieldMappedDefault(field) {
|
|
1071
1163
|
const defaultAttr = getAttribute(field, "@default");
|
|
@@ -1135,12 +1227,16 @@ var TsSchemaGenerator = class {
|
|
|
1135
1227
|
relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
|
|
1136
1228
|
}
|
|
1137
1229
|
const relation = getAttribute(field, "@relation");
|
|
1230
|
+
const fkFields = [];
|
|
1138
1231
|
if (relation) {
|
|
1139
1232
|
for (const arg of relation.args) {
|
|
1140
1233
|
const param = arg.$resolvedParam.name;
|
|
1141
1234
|
if (param === "fields" || param === "references") {
|
|
1142
1235
|
const fieldNames = this.getReferenceNames(arg.value);
|
|
1143
1236
|
if (fieldNames) {
|
|
1237
|
+
if (param === "fields") {
|
|
1238
|
+
fkFields.push(...fieldNames);
|
|
1239
|
+
}
|
|
1144
1240
|
relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
|
|
1145
1241
|
}
|
|
1146
1242
|
}
|
|
@@ -1150,6 +1246,15 @@ var TsSchemaGenerator = class {
|
|
|
1150
1246
|
}
|
|
1151
1247
|
}
|
|
1152
1248
|
}
|
|
1249
|
+
if (fkFields.length > 0) {
|
|
1250
|
+
const allHaveDefault = fkFields.every((fieldName) => {
|
|
1251
|
+
const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
|
|
1252
|
+
return fieldDef && hasAttribute(fieldDef, "@default");
|
|
1253
|
+
});
|
|
1254
|
+
if (allHaveDefault) {
|
|
1255
|
+
relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1153
1258
|
return ts.factory.createObjectLiteralExpression(relationFields);
|
|
1154
1259
|
}
|
|
1155
1260
|
getReferenceNames(expr) {
|
|
@@ -1218,7 +1323,11 @@ var TsSchemaGenerator = class {
|
|
|
1218
1323
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1219
1324
|
for (const attr of allAttributes) {
|
|
1220
1325
|
if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
|
|
1221
|
-
const
|
|
1326
|
+
const fieldsArg = (0, import_utils3.getAttributeArg)(attr, "fields");
|
|
1327
|
+
if (!fieldsArg) {
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
const fieldNames = this.getReferenceNames(fieldsArg);
|
|
1222
1331
|
if (!fieldNames) {
|
|
1223
1332
|
continue;
|
|
1224
1333
|
}
|
|
@@ -1257,7 +1366,21 @@ var TsSchemaGenerator = class {
|
|
|
1257
1366
|
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
1367
|
}
|
|
1259
1368
|
createEnumObject(e) {
|
|
1260
|
-
return ts.factory.createObjectLiteralExpression(
|
|
1369
|
+
return ts.factory.createObjectLiteralExpression([
|
|
1370
|
+
ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
|
|
1371
|
+
// only generate `fields` if there are attributes on the fields
|
|
1372
|
+
...e.fields.some((f) => f.attributes.length > 0) ? [
|
|
1373
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([
|
|
1374
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
1375
|
+
...field.attributes.length > 0 ? [
|
|
1376
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes?.map((attr) => this.createAttributeObject(attr)) ?? [], true))
|
|
1377
|
+
] : []
|
|
1378
|
+
], true))), true))
|
|
1379
|
+
] : [],
|
|
1380
|
+
...e.attributes.length > 0 ? [
|
|
1381
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(e.attributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
1382
|
+
] : []
|
|
1383
|
+
], true);
|
|
1261
1384
|
}
|
|
1262
1385
|
getLiteral(expr) {
|
|
1263
1386
|
if (!(0, import_ast3.isLiteralExpr)(expr)) {
|
|
@@ -1274,7 +1397,10 @@ var TsSchemaGenerator = class {
|
|
|
1274
1397
|
}
|
|
1275
1398
|
}
|
|
1276
1399
|
createLiteralNode(arg) {
|
|
1277
|
-
return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ?
|
|
1400
|
+
return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ? this.createNumberLiteral(arg) : arg === true ? ts.factory.createTrue() : arg === false ? ts.factory.createFalse() : void 0;
|
|
1401
|
+
}
|
|
1402
|
+
createNumberLiteral(arg) {
|
|
1403
|
+
return arg < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-arg)) : ts.factory.createNumericLiteral(arg);
|
|
1278
1404
|
}
|
|
1279
1405
|
createProceduresObject(procedures) {
|
|
1280
1406
|
return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
|
|
@@ -1339,7 +1465,7 @@ var TsSchemaGenerator = class {
|
|
|
1339
1465
|
});
|
|
1340
1466
|
}
|
|
1341
1467
|
createThisExpression() {
|
|
1342
|
-
return
|
|
1468
|
+
return this.createExpressionUtilsCall("_this");
|
|
1343
1469
|
}
|
|
1344
1470
|
createMemberExpression(expr) {
|
|
1345
1471
|
const members = [];
|
|
@@ -1353,32 +1479,32 @@ var TsSchemaGenerator = class {
|
|
|
1353
1479
|
this.createExpression(receiver),
|
|
1354
1480
|
ts.factory.createArrayLiteralExpression(members.map((m) => ts.factory.createStringLiteral(m)))
|
|
1355
1481
|
];
|
|
1356
|
-
return
|
|
1482
|
+
return this.createExpressionUtilsCall("member", args);
|
|
1357
1483
|
}
|
|
1358
1484
|
createNullExpression() {
|
|
1359
|
-
return
|
|
1485
|
+
return this.createExpressionUtilsCall("_null");
|
|
1360
1486
|
}
|
|
1361
1487
|
createBinaryExpression(expr) {
|
|
1362
|
-
return
|
|
1488
|
+
return this.createExpressionUtilsCall("binary", [
|
|
1363
1489
|
this.createExpression(expr.left),
|
|
1364
1490
|
this.createLiteralNode(expr.operator),
|
|
1365
1491
|
this.createExpression(expr.right)
|
|
1366
1492
|
]);
|
|
1367
1493
|
}
|
|
1368
1494
|
createUnaryExpression(expr) {
|
|
1369
|
-
return
|
|
1495
|
+
return this.createExpressionUtilsCall("unary", [
|
|
1370
1496
|
this.createLiteralNode(expr.operator),
|
|
1371
1497
|
this.createExpression(expr.operand)
|
|
1372
1498
|
]);
|
|
1373
1499
|
}
|
|
1374
1500
|
createArrayExpression(expr) {
|
|
1375
|
-
return
|
|
1501
|
+
return this.createExpressionUtilsCall("array", [
|
|
1376
1502
|
ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))
|
|
1377
1503
|
]);
|
|
1378
1504
|
}
|
|
1379
1505
|
createRefExpression(expr) {
|
|
1380
1506
|
if ((0, import_ast3.isDataField)(expr.target.ref)) {
|
|
1381
|
-
return
|
|
1507
|
+
return this.createExpressionUtilsCall("field", [
|
|
1382
1508
|
this.createLiteralNode(expr.target.$refText)
|
|
1383
1509
|
]);
|
|
1384
1510
|
} else if ((0, import_ast3.isEnumField)(expr.target.ref)) {
|
|
@@ -1388,7 +1514,7 @@ var TsSchemaGenerator = class {
|
|
|
1388
1514
|
}
|
|
1389
1515
|
}
|
|
1390
1516
|
createCallExpression(expr) {
|
|
1391
|
-
return
|
|
1517
|
+
return this.createExpressionUtilsCall("call", [
|
|
1392
1518
|
ts.factory.createStringLiteral(expr.function.$refText),
|
|
1393
1519
|
...expr.args.length > 0 ? [
|
|
1394
1520
|
ts.factory.createArrayLiteralExpression(expr.args.map((arg) => this.createExpression(arg.value)))
|
|
@@ -1396,26 +1522,26 @@ var TsSchemaGenerator = class {
|
|
|
1396
1522
|
]);
|
|
1397
1523
|
}
|
|
1398
1524
|
createLiteralExpression(type, value) {
|
|
1399
|
-
return (0, import_ts_pattern2.match)(type).with("BooleanLiteral", () =>
|
|
1525
|
+
return (0, import_ts_pattern2.match)(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1400
1526
|
this.createLiteralNode(value)
|
|
1401
|
-
])).with("NumberLiteral", () =>
|
|
1527
|
+
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1402
1528
|
ts.factory.createIdentifier(value)
|
|
1403
|
-
])).with("StringLiteral", () =>
|
|
1529
|
+
])).with("StringLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1404
1530
|
this.createLiteralNode(value)
|
|
1405
1531
|
])).otherwise(() => {
|
|
1406
1532
|
throw new Error(`Unsupported literal type: ${type}`);
|
|
1407
1533
|
});
|
|
1408
1534
|
}
|
|
1409
|
-
generateModelsAndTypeDefs(model,
|
|
1535
|
+
generateModelsAndTypeDefs(model, options) {
|
|
1410
1536
|
const statements = [];
|
|
1411
|
-
statements.push(this.generateSchemaImport(model, true, true));
|
|
1537
|
+
statements.push(this.generateSchemaImport(model, true, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1412
1538
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
1413
1539
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)),
|
|
1414
1540
|
...model.declarations.some(import_ast3.isTypeDef) ? [
|
|
1415
1541
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1416
1542
|
] : []
|
|
1417
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1418
|
-
const dataModels =
|
|
1543
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1544
|
+
const dataModels = this.getAllDataModels(model);
|
|
1419
1545
|
for (const dm of dataModels) {
|
|
1420
1546
|
let modelType = ts.factory.createTypeAliasDeclaration([
|
|
1421
1547
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1428,7 +1554,7 @@ var TsSchemaGenerator = class {
|
|
|
1428
1554
|
}
|
|
1429
1555
|
statements.push(modelType);
|
|
1430
1556
|
}
|
|
1431
|
-
const typeDefs =
|
|
1557
|
+
const typeDefs = this.getAllTypeDefs(model);
|
|
1432
1558
|
for (const td of typeDefs) {
|
|
1433
1559
|
let typeDef = ts.factory.createTypeAliasDeclaration([
|
|
1434
1560
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1446,7 +1572,7 @@ var TsSchemaGenerator = class {
|
|
|
1446
1572
|
let enumDecl = ts.factory.createVariableStatement([
|
|
1447
1573
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1448
1574
|
], 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)))
|
|
1575
|
+
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
1576
|
], ts.NodeFlags.Const));
|
|
1451
1577
|
if (e.comments.length > 0) {
|
|
1452
1578
|
enumDecl = this.generateDocs(enumDecl, e);
|
|
@@ -1461,13 +1587,13 @@ var TsSchemaGenerator = class {
|
|
|
1461
1587
|
statements.push(typeAlias);
|
|
1462
1588
|
}
|
|
1463
1589
|
this.generateBannerComments(statements);
|
|
1464
|
-
const outputFile = import_node_path.default.join(
|
|
1590
|
+
const outputFile = import_node_path.default.join(options.outDir, "models.ts");
|
|
1465
1591
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1466
1592
|
const printer = ts.createPrinter();
|
|
1467
1593
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1468
1594
|
import_node_fs.default.writeFileSync(outputFile, result);
|
|
1469
1595
|
}
|
|
1470
|
-
generateSchemaImport(model, schemaObject, schemaType) {
|
|
1596
|
+
generateSchemaImport(model, schemaObject, schemaType, useLite, importWithFileExtension) {
|
|
1471
1597
|
const importSpecifiers = [];
|
|
1472
1598
|
if (schemaObject) {
|
|
1473
1599
|
if (model.declarations.some(import_ast3.isEnum)) {
|
|
@@ -1477,17 +1603,21 @@ var TsSchemaGenerator = class {
|
|
|
1477
1603
|
if (schemaType) {
|
|
1478
1604
|
importSpecifiers.push(ts.factory.createImportSpecifier(true, ts.factory.createIdentifier("SchemaType"), ts.factory.createIdentifier("$Schema")));
|
|
1479
1605
|
}
|
|
1480
|
-
|
|
1606
|
+
let importFrom = useLite ? "./schema-lite" : "./schema";
|
|
1607
|
+
if (importWithFileExtension) {
|
|
1608
|
+
importFrom += importWithFileExtension.startsWith(".") ? importWithFileExtension : `.${importWithFileExtension}`;
|
|
1609
|
+
}
|
|
1610
|
+
return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral(importFrom));
|
|
1481
1611
|
}
|
|
1482
1612
|
generateDocs(tsDecl, decl) {
|
|
1483
1613
|
return ts.addSyntheticLeadingComment(tsDecl, ts.SyntaxKind.MultiLineCommentTrivia, `*
|
|
1484
1614
|
* ${decl.comments.map((c) => c.replace(/^\s*\/*\s*/, "")).join("\n * ")}
|
|
1485
1615
|
`, true);
|
|
1486
1616
|
}
|
|
1487
|
-
generateInputTypes(model,
|
|
1488
|
-
const dataModels =
|
|
1617
|
+
generateInputTypes(model, options) {
|
|
1618
|
+
const dataModels = this.getAllDataModels(model);
|
|
1489
1619
|
const statements = [];
|
|
1490
|
-
statements.push(this.generateSchemaImport(model, false, true));
|
|
1620
|
+
statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1491
1621
|
const inputTypes = [
|
|
1492
1622
|
"FindManyArgs",
|
|
1493
1623
|
"FindUniqueArgs",
|
|
@@ -1514,11 +1644,14 @@ var TsSchemaGenerator = class {
|
|
|
1514
1644
|
IncludeInput: "Include",
|
|
1515
1645
|
OmitInput: "Omit"
|
|
1516
1646
|
};
|
|
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/runtime")));
|
|
1518
1647
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1519
|
-
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(
|
|
1648
|
+
...inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))),
|
|
1649
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("QueryOptions as $QueryOptions"))
|
|
1650
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1651
|
+
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1652
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedPlainResult as $Result")),
|
|
1520
1653
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
|
|
1521
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1654
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1522
1655
|
for (const dm of dataModels) {
|
|
1523
1656
|
for (const inputType of inputTypes) {
|
|
1524
1657
|
const exportName = inputTypeNameFixes[inputType] ? `${dm.name}${inputTypeNameFixes[inputType]}` : `${dm.name}${inputType}`;
|
|
@@ -1536,526 +1669,31 @@ var TsSchemaGenerator = class {
|
|
|
1536
1669
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1537
1670
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1538
1671
|
ts.factory.createLiteralTypeNode(ts.factory.createTrue())
|
|
1672
|
+
])),
|
|
1673
|
+
ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1674
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1675
|
+
]), ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1676
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1539
1677
|
]))
|
|
1540
|
-
], ts.factory.createTypeReferenceNode("$
|
|
1678
|
+
], ts.factory.createTypeReferenceNode("$Result", [
|
|
1541
1679
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1542
1680
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1543
|
-
ts.factory.createTypeReferenceNode("Args")
|
|
1681
|
+
ts.factory.createTypeReferenceNode("Args"),
|
|
1682
|
+
ts.factory.createTypeReferenceNode("Options")
|
|
1544
1683
|
])));
|
|
1545
1684
|
}
|
|
1546
1685
|
this.generateBannerComments(statements);
|
|
1547
|
-
const outputFile = import_node_path.default.join(
|
|
1686
|
+
const outputFile = import_node_path.default.join(options.outDir, "input.ts");
|
|
1548
1687
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1549
1688
|
const printer = ts.createPrinter();
|
|
1550
1689
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1551
1690
|
import_node_fs.default.writeFileSync(outputFile, result);
|
|
1552
1691
|
}
|
|
1553
1692
|
};
|
|
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
1693
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2055
1694
|
0 && (module.exports = {
|
|
2056
1695
|
ModelUtils,
|
|
2057
1696
|
PrismaSchemaGenerator,
|
|
2058
|
-
TsSchemaGenerator
|
|
2059
|
-
ZModelCodeGenerator
|
|
1697
|
+
TsSchemaGenerator
|
|
2060
1698
|
});
|
|
2061
1699
|
//# sourceMappingURL=index.cjs.map
|