@zenstackhq/sdk 3.0.0-beta.3 → 3.0.0-beta.30
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.js
CHANGED
|
@@ -20,7 +20,7 @@ __export(model_utils_exports, {
|
|
|
20
20
|
isUniqueField: () => isUniqueField,
|
|
21
21
|
resolved: () => resolved
|
|
22
22
|
});
|
|
23
|
-
import { isDataModel, isLiteralExpr, isModel } from "@zenstackhq/language/ast";
|
|
23
|
+
import { isDataModel, isLiteralExpr, isModel, isTypeDef } from "@zenstackhq/language/ast";
|
|
24
24
|
import { getAllFields, getModelIdFields, getModelUniqueFields } from "@zenstackhq/language/utils";
|
|
25
25
|
function isIdField(field, contextModel) {
|
|
26
26
|
if (hasAttribute(field, "@id")) {
|
|
@@ -88,9 +88,9 @@ function resolved(ref) {
|
|
|
88
88
|
}
|
|
89
89
|
__name(resolved, "resolved");
|
|
90
90
|
function getAuthDecl(model) {
|
|
91
|
-
let found = model.declarations.find((d) => isDataModel(d) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
91
|
+
let found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
92
92
|
if (!found) {
|
|
93
|
-
found = model.declarations.find((d) => isDataModel(d) && d.name === "User");
|
|
93
|
+
found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.name === "User");
|
|
94
94
|
}
|
|
95
95
|
return found;
|
|
96
96
|
}
|
|
@@ -103,8 +103,9 @@ var DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
|
|
|
103
103
|
|
|
104
104
|
// src/prisma/prisma-schema-generator.ts
|
|
105
105
|
import { lowerCaseFirst } from "@zenstackhq/common-helpers";
|
|
106
|
-
import {
|
|
107
|
-
import {
|
|
106
|
+
import { ZModelCodeGenerator } from "@zenstackhq/language";
|
|
107
|
+
import { BooleanLiteral, DataModel, DataSource as DataSource2, Enum as Enum2, GeneratorDecl, isArrayExpr, isDataModel as isDataModel2, isDataSource, isGeneratorDecl, isInvocationExpr, isLiteralExpr as isLiteralExpr2, isNullExpr, isReferenceExpr, isStringLiteral, isTypeDef as isTypeDef2, NumberLiteral, StringLiteral } from "@zenstackhq/language/ast";
|
|
108
|
+
import { getAllAttributes, getAllFields as getAllFields2, getStringLiteral, isAuthInvocation, isDelegateModel as isDelegateModel2 } from "@zenstackhq/language/utils";
|
|
108
109
|
import { AstUtils } from "langium";
|
|
109
110
|
import { match } from "ts-pattern";
|
|
110
111
|
|
|
@@ -500,6 +501,9 @@ var EnumField = class extends DeclarationBase {
|
|
|
500
501
|
|
|
501
502
|
// src/prisma/prisma-schema-generator.ts
|
|
502
503
|
var IDENTIFIER_NAME_MAX_LENGTH = 50 - DELEGATE_AUX_RELATION_PREFIX.length;
|
|
504
|
+
var NON_PRISMA_DATASOURCE_FIELDS = [
|
|
505
|
+
"defaultSchema"
|
|
506
|
+
];
|
|
503
507
|
var PrismaSchemaGenerator = class {
|
|
504
508
|
static {
|
|
505
509
|
__name(this, "PrismaSchemaGenerator");
|
|
@@ -534,10 +538,13 @@ var PrismaSchemaGenerator = class {
|
|
|
534
538
|
break;
|
|
535
539
|
}
|
|
536
540
|
}
|
|
541
|
+
if (!this.zmodel.declarations.some(isGeneratorDecl)) {
|
|
542
|
+
this.generateDefaultGenerator(prisma);
|
|
543
|
+
}
|
|
537
544
|
return this.PRELUDE + prisma.toString();
|
|
538
545
|
}
|
|
539
546
|
generateDataSource(prisma, dataSource) {
|
|
540
|
-
const fields = dataSource.fields.map((f) => ({
|
|
547
|
+
const fields = dataSource.fields.filter((f) => !NON_PRISMA_DATASOURCE_FIELDS.includes(f.name)).map((f) => ({
|
|
541
548
|
name: f.name,
|
|
542
549
|
text: this.configExprToText(f.value)
|
|
543
550
|
}));
|
|
@@ -574,6 +581,21 @@ var PrismaSchemaGenerator = class {
|
|
|
574
581
|
text: this.configExprToText(f.value)
|
|
575
582
|
})));
|
|
576
583
|
}
|
|
584
|
+
generateDefaultGenerator(prisma) {
|
|
585
|
+
const gen = prisma.addGenerator("client", [
|
|
586
|
+
{
|
|
587
|
+
name: "provider",
|
|
588
|
+
text: '"prisma-client-js"'
|
|
589
|
+
}
|
|
590
|
+
]);
|
|
591
|
+
const dataSource = this.zmodel.declarations.find(isDataSource);
|
|
592
|
+
if (dataSource?.fields.some((f) => f.name === "extensions")) {
|
|
593
|
+
gen.fields.push({
|
|
594
|
+
name: "previewFeatures",
|
|
595
|
+
text: '["postgresqlExtensions"]'
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
577
599
|
generateModel(prisma, decl) {
|
|
578
600
|
const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
|
|
579
601
|
const allFields = getAllFields2(decl, true);
|
|
@@ -585,14 +607,30 @@ var PrismaSchemaGenerator = class {
|
|
|
585
607
|
this.generateModelField(model, field, decl);
|
|
586
608
|
}
|
|
587
609
|
}
|
|
588
|
-
const allAttributes = getAllAttributes(decl);
|
|
589
|
-
for (const attr of allAttributes
|
|
610
|
+
const allAttributes = getAllAttributes(decl).filter((attr) => this.isPrismaAttribute(attr));
|
|
611
|
+
for (const attr of allAttributes) {
|
|
590
612
|
this.generateContainerAttribute(model, attr);
|
|
591
613
|
}
|
|
614
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
615
|
+
model.addAttribute("@@schema", [
|
|
616
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
617
|
+
]);
|
|
618
|
+
}
|
|
592
619
|
decl.comments.forEach((c) => model.addComment(c));
|
|
593
620
|
this.generateDelegateRelationForBase(model, decl);
|
|
594
621
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
595
622
|
}
|
|
623
|
+
getDatasourceField(zmodel, fieldName) {
|
|
624
|
+
const dataSource = zmodel.declarations.find(isDataSource);
|
|
625
|
+
return dataSource?.fields.find((f) => f.name === fieldName);
|
|
626
|
+
}
|
|
627
|
+
datasourceHasSchemasSetting(zmodel) {
|
|
628
|
+
return !!this.getDatasourceField(zmodel, "schemas");
|
|
629
|
+
}
|
|
630
|
+
getDefaultPostgresSchemaName(zmodel) {
|
|
631
|
+
const defaultSchemaField = this.getDatasourceField(zmodel, "defaultSchema");
|
|
632
|
+
return getStringLiteral(defaultSchemaField?.value) ?? "public";
|
|
633
|
+
}
|
|
596
634
|
isPrismaAttribute(attr) {
|
|
597
635
|
if (!attr.decl.ref) {
|
|
598
636
|
return false;
|
|
@@ -601,7 +639,7 @@ var PrismaSchemaGenerator = class {
|
|
|
601
639
|
}
|
|
602
640
|
getUnsupportedFieldType(fieldType) {
|
|
603
641
|
if (fieldType.unsupported) {
|
|
604
|
-
const value =
|
|
642
|
+
const value = getStringLiteral(fieldType.unsupported.value);
|
|
605
643
|
if (value) {
|
|
606
644
|
return `Unsupported("${value}")`;
|
|
607
645
|
} else {
|
|
@@ -611,15 +649,12 @@ var PrismaSchemaGenerator = class {
|
|
|
611
649
|
return void 0;
|
|
612
650
|
}
|
|
613
651
|
}
|
|
614
|
-
getStringLiteral(node) {
|
|
615
|
-
return isStringLiteral(node) ? node.value : void 0;
|
|
616
|
-
}
|
|
617
652
|
generateModelField(model, field, contextModel, addToFront = false) {
|
|
618
653
|
let fieldType;
|
|
619
654
|
if (field.type.type) {
|
|
620
655
|
fieldType = field.type.type;
|
|
621
656
|
} else if (field.type.reference?.ref) {
|
|
622
|
-
if (
|
|
657
|
+
if (isTypeDef2(field.type.reference.ref)) {
|
|
623
658
|
fieldType = "Json";
|
|
624
659
|
} else {
|
|
625
660
|
fieldType = field.type.reference.ref.name;
|
|
@@ -635,10 +670,10 @@ var PrismaSchemaGenerator = class {
|
|
|
635
670
|
}
|
|
636
671
|
const isArray = (
|
|
637
672
|
// typed-JSON fields should be translated to scalar Json type
|
|
638
|
-
|
|
673
|
+
isTypeDef2(field.type.reference?.ref) ? false : field.type.array
|
|
639
674
|
);
|
|
640
675
|
const type = new ModelFieldType(fieldType, isArray, field.type.optional);
|
|
641
|
-
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.
|
|
676
|
+
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.isDefaultWithAuthInvocation(attr)).filter((attr) => (
|
|
642
677
|
// when building physical schema, exclude `@default` for id fields inherited from delegate base
|
|
643
678
|
!(model_utils_exports.isIdField(field, contextModel) && this.isInheritedFromDelegate(field, contextModel) && attr.decl.$refText === "@default")
|
|
644
679
|
)).map((attr) => this.makeFieldAttribute(attr));
|
|
@@ -648,7 +683,7 @@ var PrismaSchemaGenerator = class {
|
|
|
648
683
|
const result = model.addField(field.name, type, attributes, docs, addToFront);
|
|
649
684
|
return result;
|
|
650
685
|
}
|
|
651
|
-
|
|
686
|
+
isDefaultWithAuthInvocation(attr) {
|
|
652
687
|
if (attr.decl.ref?.name !== "@default") {
|
|
653
688
|
return false;
|
|
654
689
|
}
|
|
@@ -656,11 +691,7 @@ var PrismaSchemaGenerator = class {
|
|
|
656
691
|
if (!expr) {
|
|
657
692
|
return false;
|
|
658
693
|
}
|
|
659
|
-
return AstUtils.streamAst(expr).some(
|
|
660
|
-
}
|
|
661
|
-
isFromPlugin(node) {
|
|
662
|
-
const model = AstUtils.getContainerOfType(node, isModel2);
|
|
663
|
-
return !!model && !!model.$document && model.$document.uri.path.endsWith("plugin.zmodel");
|
|
694
|
+
return AstUtils.streamAst(expr).some(isAuthInvocation);
|
|
664
695
|
}
|
|
665
696
|
isInheritedFromDelegate(field, contextModel) {
|
|
666
697
|
return field.$container !== contextModel && model_utils_exports.isDelegateModel(field.$container);
|
|
@@ -708,9 +739,15 @@ var PrismaSchemaGenerator = class {
|
|
|
708
739
|
for (const field of decl.fields) {
|
|
709
740
|
this.generateEnumField(_enum, field);
|
|
710
741
|
}
|
|
711
|
-
|
|
742
|
+
const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
|
|
743
|
+
for (const attr of allAttributes) {
|
|
712
744
|
this.generateContainerAttribute(_enum, attr);
|
|
713
745
|
}
|
|
746
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
747
|
+
_enum.addAttribute("@@schema", [
|
|
748
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
749
|
+
]);
|
|
750
|
+
}
|
|
714
751
|
decl.comments.forEach((c) => _enum.addComment(c));
|
|
715
752
|
}
|
|
716
753
|
generateEnumField(_enum, field) {
|
|
@@ -778,8 +815,8 @@ var PrismaSchemaGenerator = class {
|
|
|
778
815
|
|
|
779
816
|
// src/ts-schema-generator.ts
|
|
780
817
|
import { invariant } from "@zenstackhq/common-helpers";
|
|
781
|
-
import { isArrayExpr as isArrayExpr2, isBinaryExpr, isDataField, isDataModel as isDataModel3, isDataSource, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as
|
|
782
|
-
import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, isDataFieldReference } from "@zenstackhq/language/utils";
|
|
818
|
+
import { isArrayExpr as isArrayExpr2, isBinaryExpr, isDataField, isDataModel as isDataModel3, isDataSource as isDataSource2, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as isTypeDef3, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
819
|
+
import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, getAttributeArg, isDataFieldReference } from "@zenstackhq/language/utils";
|
|
783
820
|
import fs from "fs";
|
|
784
821
|
import path from "path";
|
|
785
822
|
import { match as match2 } from "ts-pattern";
|
|
@@ -788,86 +825,127 @@ var TsSchemaGenerator = class {
|
|
|
788
825
|
static {
|
|
789
826
|
__name(this, "TsSchemaGenerator");
|
|
790
827
|
}
|
|
791
|
-
|
|
792
|
-
|
|
828
|
+
usedExpressionUtils = false;
|
|
829
|
+
async generate(model, options) {
|
|
830
|
+
fs.mkdirSync(options.outDir, {
|
|
793
831
|
recursive: true
|
|
794
832
|
});
|
|
795
|
-
this.
|
|
796
|
-
this.
|
|
797
|
-
this.
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
833
|
+
this.usedExpressionUtils = false;
|
|
834
|
+
this.generateSchema(model, options);
|
|
835
|
+
this.generateModelsAndTypeDefs(model, options);
|
|
836
|
+
this.generateInputTypes(model, options);
|
|
837
|
+
}
|
|
838
|
+
generateSchema(model, options) {
|
|
839
|
+
const targets = [];
|
|
840
|
+
if (!options.liteOnly) {
|
|
841
|
+
targets.push({
|
|
842
|
+
lite: false,
|
|
843
|
+
file: "schema.ts"
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
if (options.lite || options.liteOnly) {
|
|
847
|
+
targets.push({
|
|
848
|
+
lite: true,
|
|
849
|
+
file: "schema-lite.ts"
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
for (const { lite, file } of targets) {
|
|
853
|
+
const statements = [];
|
|
854
|
+
this.generateSchemaStatements(model, statements, lite);
|
|
855
|
+
this.generateBannerComments(statements);
|
|
856
|
+
const schemaOutputFile = path.join(options.outDir, file);
|
|
857
|
+
const sourceFile = ts.createSourceFile(schemaOutputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
858
|
+
const printer = ts.createPrinter();
|
|
859
|
+
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
860
|
+
fs.writeFileSync(schemaOutputFile, result);
|
|
861
|
+
}
|
|
808
862
|
}
|
|
809
|
-
generateSchemaStatements(model, statements) {
|
|
863
|
+
generateSchemaStatements(model, statements, lite) {
|
|
810
864
|
const hasComputedFields = model.declarations.some((d) => isDataModel3(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
811
|
-
const
|
|
865
|
+
const schemaClass = this.createSchemaClass(model, lite);
|
|
866
|
+
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
|
|
812
867
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
813
868
|
...hasComputedFields ? [
|
|
814
869
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
815
870
|
] : [],
|
|
816
|
-
|
|
817
|
-
|
|
871
|
+
...this.usedExpressionUtils ? [
|
|
872
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
|
|
873
|
+
] : []
|
|
874
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
818
875
|
statements.push(runtimeImportDecl);
|
|
819
|
-
|
|
876
|
+
statements.push(schemaClass);
|
|
877
|
+
const schemaDecl = ts.factory.createVariableStatement([
|
|
820
878
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
821
879
|
], ts.factory.createVariableDeclarationList([
|
|
822
|
-
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.
|
|
880
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))
|
|
823
881
|
], ts.NodeFlags.Const));
|
|
824
|
-
statements.push(
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
882
|
+
statements.push(schemaDecl);
|
|
883
|
+
}
|
|
884
|
+
createExpressionUtilsCall(method, args) {
|
|
885
|
+
this.usedExpressionUtils = true;
|
|
886
|
+
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
829
887
|
}
|
|
830
|
-
|
|
831
|
-
const
|
|
888
|
+
createSchemaClass(model, lite) {
|
|
889
|
+
const members = [
|
|
832
890
|
// provider
|
|
833
|
-
ts.factory.
|
|
891
|
+
ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
|
|
834
892
|
// models
|
|
835
|
-
ts.factory.
|
|
893
|
+
ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
|
|
836
894
|
// typeDefs
|
|
837
|
-
...model.declarations.some(
|
|
838
|
-
ts.factory.
|
|
895
|
+
...model.declarations.some(isTypeDef3) ? [
|
|
896
|
+
ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))
|
|
839
897
|
] : []
|
|
840
898
|
];
|
|
841
899
|
const enums = model.declarations.filter(isEnum);
|
|
842
900
|
if (enums.length > 0) {
|
|
843
|
-
|
|
901
|
+
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))));
|
|
844
902
|
}
|
|
845
903
|
const authType = getAuthDecl(model);
|
|
846
904
|
if (authType) {
|
|
847
|
-
|
|
905
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
|
|
848
906
|
}
|
|
849
907
|
const procedures = model.declarations.filter(isProcedure);
|
|
850
908
|
if (procedures.length > 0) {
|
|
851
|
-
|
|
909
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
|
|
852
910
|
}
|
|
853
|
-
|
|
854
|
-
|
|
911
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
|
|
912
|
+
const schemaClass = ts.factory.createClassDeclaration([
|
|
913
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
914
|
+
], "SchemaType", void 0, [
|
|
915
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
|
|
916
|
+
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)
|
|
917
|
+
])
|
|
918
|
+
], members);
|
|
919
|
+
return schemaClass;
|
|
920
|
+
}
|
|
921
|
+
createAsConst(expr) {
|
|
922
|
+
return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
|
|
855
923
|
}
|
|
856
924
|
createProviderObject(model) {
|
|
857
925
|
const dsProvider = this.getDataSourceProvider(model);
|
|
926
|
+
const defaultSchema = this.getDataSourceDefaultSchema(model);
|
|
858
927
|
return ts.factory.createObjectLiteralExpression([
|
|
859
|
-
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider
|
|
928
|
+
ts.factory.createPropertyAssignment("type", ts.factory.createStringLiteral(dsProvider)),
|
|
929
|
+
...defaultSchema ? [
|
|
930
|
+
ts.factory.createPropertyAssignment("defaultSchema", ts.factory.createStringLiteral(defaultSchema))
|
|
931
|
+
] : []
|
|
860
932
|
], true);
|
|
861
933
|
}
|
|
862
|
-
createModelsObject(model) {
|
|
863
|
-
return ts.factory.createObjectLiteralExpression(
|
|
934
|
+
createModelsObject(model, lite) {
|
|
935
|
+
return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
|
|
936
|
+
}
|
|
937
|
+
getAllDataModels(model) {
|
|
938
|
+
return model.declarations.filter((d) => isDataModel3(d) && !hasAttribute(d, "@@ignore"));
|
|
864
939
|
}
|
|
865
|
-
|
|
866
|
-
return
|
|
940
|
+
getAllTypeDefs(model) {
|
|
941
|
+
return model.declarations.filter((d) => isTypeDef3(d) && !hasAttribute(d, "@@ignore"));
|
|
867
942
|
}
|
|
868
|
-
|
|
943
|
+
createTypeDefsObject(model, lite) {
|
|
944
|
+
return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
|
|
945
|
+
}
|
|
946
|
+
createDataModelObject(dm, lite) {
|
|
869
947
|
const allFields = getAllFields3(dm);
|
|
870
|
-
const allAttributes = getAllAttributes2(dm).filter((attr) => {
|
|
948
|
+
const allAttributes = lite ? [] : getAllAttributes2(dm).filter((attr) => {
|
|
871
949
|
if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) {
|
|
872
950
|
return false;
|
|
873
951
|
}
|
|
@@ -882,7 +960,7 @@ var TsSchemaGenerator = class {
|
|
|
882
960
|
ts.factory.createPropertyAssignment("baseModel", ts.factory.createStringLiteral(dm.baseModel.$refText))
|
|
883
961
|
] : [],
|
|
884
962
|
// fields
|
|
885
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm))), true)),
|
|
963
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, dm, lite))), true)),
|
|
886
964
|
// attributes
|
|
887
965
|
...allAttributes.length > 0 ? [
|
|
888
966
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -898,6 +976,9 @@ var TsSchemaGenerator = class {
|
|
|
898
976
|
// subModels
|
|
899
977
|
...subModels.length > 0 ? [
|
|
900
978
|
ts.factory.createPropertyAssignment("subModels", ts.factory.createArrayLiteralExpression(subModels.map((subModel) => ts.factory.createStringLiteral(subModel))))
|
|
979
|
+
] : [],
|
|
980
|
+
...dm.isView ? [
|
|
981
|
+
ts.factory.createPropertyAssignment("isView", ts.factory.createTrue())
|
|
901
982
|
] : []
|
|
902
983
|
];
|
|
903
984
|
const computedFields = dm.fields.filter((f) => hasAttribute(f, "@computed"));
|
|
@@ -909,14 +990,14 @@ var TsSchemaGenerator = class {
|
|
|
909
990
|
getSubModels(dm) {
|
|
910
991
|
return dm.$container.declarations.filter(isDataModel3).filter((d) => d.baseModel?.ref === dm).map((d) => d.name);
|
|
911
992
|
}
|
|
912
|
-
createTypeDefObject(td) {
|
|
993
|
+
createTypeDefObject(td, lite) {
|
|
913
994
|
const allFields = getAllFields3(td);
|
|
914
995
|
const allAttributes = getAllAttributes2(td);
|
|
915
996
|
const fields = [
|
|
916
997
|
// name
|
|
917
998
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
|
|
918
999
|
// fields
|
|
919
|
-
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0))), true)),
|
|
1000
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
|
|
920
1001
|
// attributes
|
|
921
1002
|
...allAttributes.length > 0 ? [
|
|
922
1003
|
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(allAttributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
@@ -926,9 +1007,9 @@ var TsSchemaGenerator = class {
|
|
|
926
1007
|
}
|
|
927
1008
|
createComputedFieldsObject(fields) {
|
|
928
1009
|
return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [
|
|
929
|
-
// parameter: `context: {
|
|
1010
|
+
// parameter: `context: { modelAlias: string }`
|
|
930
1011
|
ts.factory.createParameterDeclaration(void 0, void 0, "_context", void 0, ts.factory.createTypeLiteralNode([
|
|
931
|
-
ts.factory.createPropertySignature(void 0, "
|
|
1012
|
+
ts.factory.createPropertySignature(void 0, "modelAlias", void 0, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))
|
|
932
1013
|
]), void 0)
|
|
933
1014
|
], ts.factory.createTypeReferenceNode("OperandExpression", [
|
|
934
1015
|
ts.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type))
|
|
@@ -948,7 +1029,7 @@ var TsSchemaGenerator = class {
|
|
|
948
1029
|
}
|
|
949
1030
|
return result;
|
|
950
1031
|
}
|
|
951
|
-
createDataFieldObject(field, contextModel) {
|
|
1032
|
+
createDataFieldObject(field, contextModel, lite) {
|
|
952
1033
|
const objectFields = [
|
|
953
1034
|
// name
|
|
954
1035
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
@@ -970,6 +1051,9 @@ var TsSchemaGenerator = class {
|
|
|
970
1051
|
if (hasAttribute(field, "@updatedAt")) {
|
|
971
1052
|
objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
|
|
972
1053
|
}
|
|
1054
|
+
if (hasAttribute(field, "@omit")) {
|
|
1055
|
+
objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
|
|
1056
|
+
}
|
|
973
1057
|
if (contextModel && // id fields are duplicated in inherited models
|
|
974
1058
|
!isIdField(field, contextModel) && field.$container !== contextModel && isDelegateModel(field.$container)) {
|
|
975
1059
|
objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(field.$container.name)));
|
|
@@ -977,22 +1061,24 @@ var TsSchemaGenerator = class {
|
|
|
977
1061
|
if (this.isDiscriminatorField(field)) {
|
|
978
1062
|
objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
|
|
979
1063
|
}
|
|
980
|
-
if (field.attributes.length > 0) {
|
|
1064
|
+
if (!lite && field.attributes.length > 0) {
|
|
981
1065
|
objectFields.push(ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes.map((attr) => this.createAttributeObject(attr)))));
|
|
982
1066
|
}
|
|
983
1067
|
const defaultValue = this.getFieldMappedDefault(field);
|
|
984
1068
|
if (defaultValue !== void 0) {
|
|
985
1069
|
if (typeof defaultValue === "object" && !Array.isArray(defaultValue)) {
|
|
986
1070
|
if ("call" in defaultValue) {
|
|
987
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
1071
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("call", [
|
|
988
1072
|
ts.factory.createStringLiteral(defaultValue.call),
|
|
989
1073
|
...defaultValue.args.length > 0 ? [
|
|
990
|
-
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.
|
|
1074
|
+
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createExpressionUtilsCall("literal", [
|
|
1075
|
+
this.createLiteralNode(arg)
|
|
1076
|
+
])))
|
|
991
1077
|
] : []
|
|
992
1078
|
])));
|
|
993
1079
|
} else if ("authMember" in defaultValue) {
|
|
994
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
995
|
-
|
|
1080
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("member", [
|
|
1081
|
+
this.createExpressionUtilsCall("call", [
|
|
996
1082
|
ts.factory.createStringLiteral("auth")
|
|
997
1083
|
]),
|
|
998
1084
|
ts.factory.createArrayLiteralExpression(defaultValue.authMember.map((m) => ts.factory.createStringLiteral(m)))
|
|
@@ -1025,14 +1111,21 @@ var TsSchemaGenerator = class {
|
|
|
1025
1111
|
return getAttribute(origin, "@@delegate")?.args.some((arg) => arg.$resolvedParam.name === "discriminator" && isDataFieldReference(arg.value) && arg.value.target.ref === field);
|
|
1026
1112
|
}
|
|
1027
1113
|
getDataSourceProvider(model) {
|
|
1028
|
-
const dataSource = model.declarations.find(
|
|
1114
|
+
const dataSource = model.declarations.find(isDataSource2);
|
|
1029
1115
|
invariant(dataSource, "No data source found in the model");
|
|
1030
1116
|
const providerExpr = dataSource.fields.find((f) => f.name === "provider")?.value;
|
|
1031
|
-
invariant(isLiteralExpr3(providerExpr), "Provider must be a literal");
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1117
|
+
invariant(isLiteralExpr3(providerExpr) && typeof providerExpr.value === "string", "Provider must be a string literal");
|
|
1118
|
+
return providerExpr.value;
|
|
1119
|
+
}
|
|
1120
|
+
getDataSourceDefaultSchema(model) {
|
|
1121
|
+
const dataSource = model.declarations.find(isDataSource2);
|
|
1122
|
+
invariant(dataSource, "No data source found in the model");
|
|
1123
|
+
const defaultSchemaExpr = dataSource.fields.find((f) => f.name === "defaultSchema")?.value;
|
|
1124
|
+
if (!defaultSchemaExpr) {
|
|
1125
|
+
return void 0;
|
|
1126
|
+
}
|
|
1127
|
+
invariant(isLiteralExpr3(defaultSchemaExpr) && typeof defaultSchemaExpr.value === "string", "Default schema must be a string literal");
|
|
1128
|
+
return defaultSchemaExpr.value;
|
|
1036
1129
|
}
|
|
1037
1130
|
getFieldMappedDefault(field) {
|
|
1038
1131
|
const defaultAttr = getAttribute(field, "@default");
|
|
@@ -1102,12 +1195,16 @@ var TsSchemaGenerator = class {
|
|
|
1102
1195
|
relationFields.push(ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(relationName)));
|
|
1103
1196
|
}
|
|
1104
1197
|
const relation = getAttribute(field, "@relation");
|
|
1198
|
+
const fkFields = [];
|
|
1105
1199
|
if (relation) {
|
|
1106
1200
|
for (const arg of relation.args) {
|
|
1107
1201
|
const param = arg.$resolvedParam.name;
|
|
1108
1202
|
if (param === "fields" || param === "references") {
|
|
1109
1203
|
const fieldNames = this.getReferenceNames(arg.value);
|
|
1110
1204
|
if (fieldNames) {
|
|
1205
|
+
if (param === "fields") {
|
|
1206
|
+
fkFields.push(...fieldNames);
|
|
1207
|
+
}
|
|
1111
1208
|
relationFields.push(ts.factory.createPropertyAssignment(param, ts.factory.createArrayLiteralExpression(fieldNames.map((el) => ts.factory.createStringLiteral(el)))));
|
|
1112
1209
|
}
|
|
1113
1210
|
}
|
|
@@ -1117,6 +1214,15 @@ var TsSchemaGenerator = class {
|
|
|
1117
1214
|
}
|
|
1118
1215
|
}
|
|
1119
1216
|
}
|
|
1217
|
+
if (fkFields.length > 0) {
|
|
1218
|
+
const allHaveDefault = fkFields.every((fieldName) => {
|
|
1219
|
+
const fieldDef = field.$container.fields.find((f) => f.name === fieldName);
|
|
1220
|
+
return fieldDef && hasAttribute(fieldDef, "@default");
|
|
1221
|
+
});
|
|
1222
|
+
if (allHaveDefault) {
|
|
1223
|
+
relationFields.push(ts.factory.createPropertyAssignment("hasDefault", ts.factory.createTrue()));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1120
1226
|
return ts.factory.createObjectLiteralExpression(relationFields);
|
|
1121
1227
|
}
|
|
1122
1228
|
getReferenceNames(expr) {
|
|
@@ -1185,7 +1291,11 @@ var TsSchemaGenerator = class {
|
|
|
1185
1291
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1186
1292
|
for (const attr of allAttributes) {
|
|
1187
1293
|
if (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@unique") {
|
|
1188
|
-
const
|
|
1294
|
+
const fieldsArg = getAttributeArg(attr, "fields");
|
|
1295
|
+
if (!fieldsArg) {
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
const fieldNames = this.getReferenceNames(fieldsArg);
|
|
1189
1299
|
if (!fieldNames) {
|
|
1190
1300
|
continue;
|
|
1191
1301
|
}
|
|
@@ -1224,7 +1334,21 @@ var TsSchemaGenerator = class {
|
|
|
1224
1334
|
return field.type.type ? ts.factory.createStringLiteral(field.type.type) : field.type.reference ? ts.factory.createStringLiteral(field.type.reference.$refText) : ts.factory.createStringLiteral("Unsupported");
|
|
1225
1335
|
}
|
|
1226
1336
|
createEnumObject(e) {
|
|
1227
|
-
return ts.factory.createObjectLiteralExpression(
|
|
1337
|
+
return ts.factory.createObjectLiteralExpression([
|
|
1338
|
+
ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
|
|
1339
|
+
// only generate `fields` if there are attributes on the fields
|
|
1340
|
+
...e.fields.some((f) => f.attributes.length > 0) ? [
|
|
1341
|
+
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(e.fields.map((field) => ts.factory.createPropertyAssignment(field.name, ts.factory.createObjectLiteralExpression([
|
|
1342
|
+
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(field.name)),
|
|
1343
|
+
...field.attributes.length > 0 ? [
|
|
1344
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(field.attributes?.map((attr) => this.createAttributeObject(attr)) ?? [], true))
|
|
1345
|
+
] : []
|
|
1346
|
+
], true))), true))
|
|
1347
|
+
] : [],
|
|
1348
|
+
...e.attributes.length > 0 ? [
|
|
1349
|
+
ts.factory.createPropertyAssignment("attributes", ts.factory.createArrayLiteralExpression(e.attributes.map((attr) => this.createAttributeObject(attr)), true))
|
|
1350
|
+
] : []
|
|
1351
|
+
], true);
|
|
1228
1352
|
}
|
|
1229
1353
|
getLiteral(expr) {
|
|
1230
1354
|
if (!isLiteralExpr3(expr)) {
|
|
@@ -1241,7 +1365,10 @@ var TsSchemaGenerator = class {
|
|
|
1241
1365
|
}
|
|
1242
1366
|
}
|
|
1243
1367
|
createLiteralNode(arg) {
|
|
1244
|
-
return arg === null ? ts.factory.createNull() : typeof arg === "string" ? ts.factory.createStringLiteral(arg) : typeof arg === "number" ?
|
|
1368
|
+
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;
|
|
1369
|
+
}
|
|
1370
|
+
createNumberLiteral(arg) {
|
|
1371
|
+
return arg < 0 ? ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(-arg)) : ts.factory.createNumericLiteral(arg);
|
|
1245
1372
|
}
|
|
1246
1373
|
createProceduresObject(procedures) {
|
|
1247
1374
|
return ts.factory.createObjectLiteralExpression(procedures.map((proc) => ts.factory.createPropertyAssignment(proc.name, this.createProcedureObject(proc))), true);
|
|
@@ -1306,7 +1433,7 @@ var TsSchemaGenerator = class {
|
|
|
1306
1433
|
});
|
|
1307
1434
|
}
|
|
1308
1435
|
createThisExpression() {
|
|
1309
|
-
return
|
|
1436
|
+
return this.createExpressionUtilsCall("_this");
|
|
1310
1437
|
}
|
|
1311
1438
|
createMemberExpression(expr) {
|
|
1312
1439
|
const members = [];
|
|
@@ -1320,32 +1447,32 @@ var TsSchemaGenerator = class {
|
|
|
1320
1447
|
this.createExpression(receiver),
|
|
1321
1448
|
ts.factory.createArrayLiteralExpression(members.map((m) => ts.factory.createStringLiteral(m)))
|
|
1322
1449
|
];
|
|
1323
|
-
return
|
|
1450
|
+
return this.createExpressionUtilsCall("member", args);
|
|
1324
1451
|
}
|
|
1325
1452
|
createNullExpression() {
|
|
1326
|
-
return
|
|
1453
|
+
return this.createExpressionUtilsCall("_null");
|
|
1327
1454
|
}
|
|
1328
1455
|
createBinaryExpression(expr) {
|
|
1329
|
-
return
|
|
1456
|
+
return this.createExpressionUtilsCall("binary", [
|
|
1330
1457
|
this.createExpression(expr.left),
|
|
1331
1458
|
this.createLiteralNode(expr.operator),
|
|
1332
1459
|
this.createExpression(expr.right)
|
|
1333
1460
|
]);
|
|
1334
1461
|
}
|
|
1335
1462
|
createUnaryExpression(expr) {
|
|
1336
|
-
return
|
|
1463
|
+
return this.createExpressionUtilsCall("unary", [
|
|
1337
1464
|
this.createLiteralNode(expr.operator),
|
|
1338
1465
|
this.createExpression(expr.operand)
|
|
1339
1466
|
]);
|
|
1340
1467
|
}
|
|
1341
1468
|
createArrayExpression(expr) {
|
|
1342
|
-
return
|
|
1469
|
+
return this.createExpressionUtilsCall("array", [
|
|
1343
1470
|
ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))
|
|
1344
1471
|
]);
|
|
1345
1472
|
}
|
|
1346
1473
|
createRefExpression(expr) {
|
|
1347
1474
|
if (isDataField(expr.target.ref)) {
|
|
1348
|
-
return
|
|
1475
|
+
return this.createExpressionUtilsCall("field", [
|
|
1349
1476
|
this.createLiteralNode(expr.target.$refText)
|
|
1350
1477
|
]);
|
|
1351
1478
|
} else if (isEnumField(expr.target.ref)) {
|
|
@@ -1355,7 +1482,7 @@ var TsSchemaGenerator = class {
|
|
|
1355
1482
|
}
|
|
1356
1483
|
}
|
|
1357
1484
|
createCallExpression(expr) {
|
|
1358
|
-
return
|
|
1485
|
+
return this.createExpressionUtilsCall("call", [
|
|
1359
1486
|
ts.factory.createStringLiteral(expr.function.$refText),
|
|
1360
1487
|
...expr.args.length > 0 ? [
|
|
1361
1488
|
ts.factory.createArrayLiteralExpression(expr.args.map((arg) => this.createExpression(arg.value)))
|
|
@@ -1363,26 +1490,26 @@ var TsSchemaGenerator = class {
|
|
|
1363
1490
|
]);
|
|
1364
1491
|
}
|
|
1365
1492
|
createLiteralExpression(type, value) {
|
|
1366
|
-
return match2(type).with("BooleanLiteral", () =>
|
|
1493
|
+
return match2(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1367
1494
|
this.createLiteralNode(value)
|
|
1368
|
-
])).with("NumberLiteral", () =>
|
|
1495
|
+
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1369
1496
|
ts.factory.createIdentifier(value)
|
|
1370
|
-
])).with("StringLiteral", () =>
|
|
1497
|
+
])).with("StringLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1371
1498
|
this.createLiteralNode(value)
|
|
1372
1499
|
])).otherwise(() => {
|
|
1373
1500
|
throw new Error(`Unsupported literal type: ${type}`);
|
|
1374
1501
|
});
|
|
1375
1502
|
}
|
|
1376
|
-
generateModelsAndTypeDefs(model,
|
|
1503
|
+
generateModelsAndTypeDefs(model, options) {
|
|
1377
1504
|
const statements = [];
|
|
1378
|
-
statements.push(this.generateSchemaImport(model, true, true));
|
|
1505
|
+
statements.push(this.generateSchemaImport(model, true, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1379
1506
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
1380
1507
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)),
|
|
1381
|
-
...model.declarations.some(
|
|
1508
|
+
...model.declarations.some(isTypeDef3) ? [
|
|
1382
1509
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1383
1510
|
] : []
|
|
1384
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1385
|
-
const dataModels =
|
|
1511
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1512
|
+
const dataModels = this.getAllDataModels(model);
|
|
1386
1513
|
for (const dm of dataModels) {
|
|
1387
1514
|
let modelType = ts.factory.createTypeAliasDeclaration([
|
|
1388
1515
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1395,7 +1522,7 @@ var TsSchemaGenerator = class {
|
|
|
1395
1522
|
}
|
|
1396
1523
|
statements.push(modelType);
|
|
1397
1524
|
}
|
|
1398
|
-
const typeDefs =
|
|
1525
|
+
const typeDefs = this.getAllTypeDefs(model);
|
|
1399
1526
|
for (const td of typeDefs) {
|
|
1400
1527
|
let typeDef = ts.factory.createTypeAliasDeclaration([
|
|
1401
1528
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1413,7 +1540,7 @@ var TsSchemaGenerator = class {
|
|
|
1413
1540
|
let enumDecl = ts.factory.createVariableStatement([
|
|
1414
1541
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1415
1542
|
], ts.factory.createVariableDeclarationList([
|
|
1416
|
-
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)))
|
|
1543
|
+
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")))
|
|
1417
1544
|
], ts.NodeFlags.Const));
|
|
1418
1545
|
if (e.comments.length > 0) {
|
|
1419
1546
|
enumDecl = this.generateDocs(enumDecl, e);
|
|
@@ -1428,13 +1555,13 @@ var TsSchemaGenerator = class {
|
|
|
1428
1555
|
statements.push(typeAlias);
|
|
1429
1556
|
}
|
|
1430
1557
|
this.generateBannerComments(statements);
|
|
1431
|
-
const outputFile = path.join(
|
|
1558
|
+
const outputFile = path.join(options.outDir, "models.ts");
|
|
1432
1559
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1433
1560
|
const printer = ts.createPrinter();
|
|
1434
1561
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1435
1562
|
fs.writeFileSync(outputFile, result);
|
|
1436
1563
|
}
|
|
1437
|
-
generateSchemaImport(model, schemaObject, schemaType) {
|
|
1564
|
+
generateSchemaImport(model, schemaObject, schemaType, useLite, importWithFileExtension) {
|
|
1438
1565
|
const importSpecifiers = [];
|
|
1439
1566
|
if (schemaObject) {
|
|
1440
1567
|
if (model.declarations.some(isEnum)) {
|
|
@@ -1444,17 +1571,21 @@ var TsSchemaGenerator = class {
|
|
|
1444
1571
|
if (schemaType) {
|
|
1445
1572
|
importSpecifiers.push(ts.factory.createImportSpecifier(true, ts.factory.createIdentifier("SchemaType"), ts.factory.createIdentifier("$Schema")));
|
|
1446
1573
|
}
|
|
1447
|
-
|
|
1574
|
+
let importFrom = useLite ? "./schema-lite" : "./schema";
|
|
1575
|
+
if (importWithFileExtension) {
|
|
1576
|
+
importFrom += importWithFileExtension.startsWith(".") ? importWithFileExtension : `.${importWithFileExtension}`;
|
|
1577
|
+
}
|
|
1578
|
+
return ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(importSpecifiers)), ts.factory.createStringLiteral(importFrom));
|
|
1448
1579
|
}
|
|
1449
1580
|
generateDocs(tsDecl, decl) {
|
|
1450
1581
|
return ts.addSyntheticLeadingComment(tsDecl, ts.SyntaxKind.MultiLineCommentTrivia, `*
|
|
1451
1582
|
* ${decl.comments.map((c) => c.replace(/^\s*\/*\s*/, "")).join("\n * ")}
|
|
1452
1583
|
`, true);
|
|
1453
1584
|
}
|
|
1454
|
-
generateInputTypes(model,
|
|
1455
|
-
const dataModels =
|
|
1585
|
+
generateInputTypes(model, options) {
|
|
1586
|
+
const dataModels = this.getAllDataModels(model);
|
|
1456
1587
|
const statements = [];
|
|
1457
|
-
statements.push(this.generateSchemaImport(model, false, true));
|
|
1588
|
+
statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1458
1589
|
const inputTypes = [
|
|
1459
1590
|
"FindManyArgs",
|
|
1460
1591
|
"FindUniqueArgs",
|
|
@@ -1481,11 +1612,14 @@ var TsSchemaGenerator = class {
|
|
|
1481
1612
|
IncludeInput: "Include",
|
|
1482
1613
|
OmitInput: "Omit"
|
|
1483
1614
|
};
|
|
1484
|
-
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")));
|
|
1485
1615
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1486
|
-
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(
|
|
1616
|
+
...inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))),
|
|
1617
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("QueryOptions as $QueryOptions"))
|
|
1618
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1619
|
+
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1620
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedPlainResult as $Result")),
|
|
1487
1621
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
|
|
1488
|
-
])), ts.factory.createStringLiteral("@zenstackhq/
|
|
1622
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1489
1623
|
for (const dm of dataModels) {
|
|
1490
1624
|
for (const inputType of inputTypes) {
|
|
1491
1625
|
const exportName = inputTypeNameFixes[inputType] ? `${dm.name}${inputTypeNameFixes[inputType]}` : `${dm.name}${inputType}`;
|
|
@@ -1503,525 +1637,30 @@ var TsSchemaGenerator = class {
|
|
|
1503
1637
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1504
1638
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1505
1639
|
ts.factory.createLiteralTypeNode(ts.factory.createTrue())
|
|
1640
|
+
])),
|
|
1641
|
+
ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1642
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1643
|
+
]), ts.factory.createTypeReferenceNode("$QueryOptions", [
|
|
1644
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1506
1645
|
]))
|
|
1507
|
-
], ts.factory.createTypeReferenceNode("$
|
|
1646
|
+
], ts.factory.createTypeReferenceNode("$Result", [
|
|
1508
1647
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1509
1648
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1510
|
-
ts.factory.createTypeReferenceNode("Args")
|
|
1649
|
+
ts.factory.createTypeReferenceNode("Args"),
|
|
1650
|
+
ts.factory.createTypeReferenceNode("Options")
|
|
1511
1651
|
])));
|
|
1512
1652
|
}
|
|
1513
1653
|
this.generateBannerComments(statements);
|
|
1514
|
-
const outputFile = path.join(
|
|
1654
|
+
const outputFile = path.join(options.outDir, "input.ts");
|
|
1515
1655
|
const sourceFile = ts.createSourceFile(outputFile, "", ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
|
|
1516
1656
|
const printer = ts.createPrinter();
|
|
1517
1657
|
const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile);
|
|
1518
1658
|
fs.writeFileSync(outputFile, result);
|
|
1519
1659
|
}
|
|
1520
1660
|
};
|
|
1521
|
-
|
|
1522
|
-
// src/zmodel-code-generator.ts
|
|
1523
|
-
import { ArrayExpr, Attribute, AttributeArg as AttributeArg2, AttributeParam, AttributeParamType, BinaryExpr, BinaryExprOperatorPriority, BooleanLiteral as BooleanLiteral2, ConfigArrayExpr, ConfigField, ConfigInvocationExpr, DataField, DataFieldAttribute, DataModel as DataModel2, DataModelAttribute, DataSource as DataSource3, Enum as Enum3, EnumField as EnumField2, FunctionDecl, FunctionParam, FunctionParamType, GeneratorDecl as GeneratorDecl2, InvocationExpr, LiteralExpr, MemberAccessExpr, Model as Model2, NullExpr, NumberLiteral as NumberLiteral2, ObjectExpr, Plugin, PluginField, ReferenceArg, ReferenceExpr, StringLiteral as StringLiteral2, ThisExpr, TypeDef, UnaryExpr } from "@zenstackhq/language/ast";
|
|
1524
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
1525
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1526
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1527
|
-
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;
|
|
1528
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1529
|
-
}
|
|
1530
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
1531
|
-
function _ts_metadata(k, v) {
|
|
1532
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1533
|
-
}
|
|
1534
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
1535
|
-
var generationHandlers = /* @__PURE__ */ new Map();
|
|
1536
|
-
function gen(name) {
|
|
1537
|
-
return function(_target, _propertyKey, descriptor) {
|
|
1538
|
-
if (!generationHandlers.get(name)) {
|
|
1539
|
-
generationHandlers.set(name, descriptor);
|
|
1540
|
-
}
|
|
1541
|
-
return descriptor;
|
|
1542
|
-
};
|
|
1543
|
-
}
|
|
1544
|
-
__name(gen, "gen");
|
|
1545
|
-
var ZModelCodeGenerator = class {
|
|
1546
|
-
static {
|
|
1547
|
-
__name(this, "ZModelCodeGenerator");
|
|
1548
|
-
}
|
|
1549
|
-
options;
|
|
1550
|
-
constructor(options) {
|
|
1551
|
-
this.options = {
|
|
1552
|
-
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
1553
|
-
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
1554
|
-
indent: options?.indent ?? 4,
|
|
1555
|
-
quote: options?.quote ?? "single"
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Generates ZModel source code from AST.
|
|
1560
|
-
*/
|
|
1561
|
-
generate(ast) {
|
|
1562
|
-
const handler = generationHandlers.get(ast.$type);
|
|
1563
|
-
if (!handler) {
|
|
1564
|
-
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
1565
|
-
}
|
|
1566
|
-
return handler.value.call(this, ast);
|
|
1567
|
-
}
|
|
1568
|
-
_generateModel(ast) {
|
|
1569
|
-
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
1570
|
-
}
|
|
1571
|
-
_generateDataSource(ast) {
|
|
1572
|
-
return `datasource ${ast.name} {
|
|
1573
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1574
|
-
}`;
|
|
1575
|
-
}
|
|
1576
|
-
_generateEnum(ast) {
|
|
1577
|
-
return `enum ${ast.name} {
|
|
1578
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1579
|
-
}`;
|
|
1580
|
-
}
|
|
1581
|
-
_generateEnumField(ast) {
|
|
1582
|
-
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1583
|
-
}
|
|
1584
|
-
_generateGenerator(ast) {
|
|
1585
|
-
return `generator ${ast.name} {
|
|
1586
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1587
|
-
}`;
|
|
1588
|
-
}
|
|
1589
|
-
_generateConfigField(ast) {
|
|
1590
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1591
|
-
}
|
|
1592
|
-
_generateConfigArrayExpr(ast) {
|
|
1593
|
-
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
1594
|
-
}
|
|
1595
|
-
_generateConfigInvocationExpr(ast) {
|
|
1596
|
-
if (ast.args.length === 0) {
|
|
1597
|
-
return ast.name;
|
|
1598
|
-
} else {
|
|
1599
|
-
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
_generatePlugin(ast) {
|
|
1603
|
-
return `plugin ${ast.name} {
|
|
1604
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
1605
|
-
}`;
|
|
1606
|
-
}
|
|
1607
|
-
_generatePluginField(ast) {
|
|
1608
|
-
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
1609
|
-
}
|
|
1610
|
-
_generateDataModel(ast) {
|
|
1611
|
-
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.ref?.name).join(", ") : ""} {
|
|
1612
|
-
${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") : ""}
|
|
1613
|
-
}`;
|
|
1614
|
-
}
|
|
1615
|
-
_generateDataField(ast) {
|
|
1616
|
-
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
1617
|
-
}
|
|
1618
|
-
fieldType(type) {
|
|
1619
|
-
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
1620
|
-
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
1621
|
-
}
|
|
1622
|
-
_generateDataModelAttribute(ast) {
|
|
1623
|
-
return this.attribute(ast);
|
|
1624
|
-
}
|
|
1625
|
-
_generateDataFieldAttribute(ast) {
|
|
1626
|
-
return this.attribute(ast);
|
|
1627
|
-
}
|
|
1628
|
-
attribute(ast) {
|
|
1629
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
1630
|
-
return `${resolved(ast.decl).name}${args}`;
|
|
1631
|
-
}
|
|
1632
|
-
_generateAttributeArg(ast) {
|
|
1633
|
-
if (ast.name) {
|
|
1634
|
-
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
1635
|
-
} else {
|
|
1636
|
-
return this.generate(ast.value);
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
_generateObjectExpr(ast) {
|
|
1640
|
-
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
1641
|
-
}
|
|
1642
|
-
objectField(field) {
|
|
1643
|
-
return `${field.name}: ${this.generate(field.value)}`;
|
|
1644
|
-
}
|
|
1645
|
-
_generateArrayExpr(ast) {
|
|
1646
|
-
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
1647
|
-
}
|
|
1648
|
-
_generateLiteralExpr(ast) {
|
|
1649
|
-
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
1650
|
-
}
|
|
1651
|
-
_generateNumberLiteral(ast) {
|
|
1652
|
-
return ast.value.toString();
|
|
1653
|
-
}
|
|
1654
|
-
_generateBooleanLiteral(ast) {
|
|
1655
|
-
return ast.value.toString();
|
|
1656
|
-
}
|
|
1657
|
-
_generateUnaryExpr(ast) {
|
|
1658
|
-
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
1659
|
-
}
|
|
1660
|
-
_generateBinaryExpr(ast) {
|
|
1661
|
-
const operator = ast.operator;
|
|
1662
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
1663
|
-
const rightExpr = this.generate(ast.right);
|
|
1664
|
-
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
1665
|
-
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
1666
|
-
}
|
|
1667
|
-
_generateReferenceExpr(ast) {
|
|
1668
|
-
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
1669
|
-
return `${ast.target.ref?.name}${args}`;
|
|
1670
|
-
}
|
|
1671
|
-
_generateReferenceArg(ast) {
|
|
1672
|
-
return `${ast.name}:${this.generate(ast.value)}`;
|
|
1673
|
-
}
|
|
1674
|
-
_generateMemberExpr(ast) {
|
|
1675
|
-
return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
|
|
1676
|
-
}
|
|
1677
|
-
_generateInvocationExpr(ast) {
|
|
1678
|
-
return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
1679
|
-
}
|
|
1680
|
-
_generateNullExpr() {
|
|
1681
|
-
return "null";
|
|
1682
|
-
}
|
|
1683
|
-
_generateThisExpr() {
|
|
1684
|
-
return "this";
|
|
1685
|
-
}
|
|
1686
|
-
_generateAttribute(ast) {
|
|
1687
|
-
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
1688
|
-
}
|
|
1689
|
-
_generateAttributeParam(ast) {
|
|
1690
|
-
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
1691
|
-
}
|
|
1692
|
-
_generateAttributeParamType(ast) {
|
|
1693
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
1694
|
-
}
|
|
1695
|
-
_generateFunctionDecl(ast) {
|
|
1696
|
-
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
1697
|
-
}
|
|
1698
|
-
_generateFunctionParam(ast) {
|
|
1699
|
-
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
1700
|
-
}
|
|
1701
|
-
_generateFunctionParamType(ast) {
|
|
1702
|
-
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
1703
|
-
}
|
|
1704
|
-
_generateTypeDef(ast) {
|
|
1705
|
-
return `type ${ast.name} {
|
|
1706
|
-
${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") : ""}
|
|
1707
|
-
}`;
|
|
1708
|
-
}
|
|
1709
|
-
argument(ast) {
|
|
1710
|
-
return this.generate(ast.value);
|
|
1711
|
-
}
|
|
1712
|
-
get binaryExprSpace() {
|
|
1713
|
-
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
1714
|
-
}
|
|
1715
|
-
get unaryExprSpace() {
|
|
1716
|
-
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
1717
|
-
}
|
|
1718
|
-
get indent() {
|
|
1719
|
-
return " ".repeat(this.options.indent);
|
|
1720
|
-
}
|
|
1721
|
-
isParenthesesNeededForBinaryExpr(ast) {
|
|
1722
|
-
const result = {
|
|
1723
|
-
left: false,
|
|
1724
|
-
right: false
|
|
1725
|
-
};
|
|
1726
|
-
const operator = ast.operator;
|
|
1727
|
-
const isCollectionPredicate = this.isCollectionPredicateOperator(operator);
|
|
1728
|
-
const currentPriority = BinaryExprOperatorPriority[operator];
|
|
1729
|
-
if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
1730
|
-
result.left = true;
|
|
1731
|
-
}
|
|
1732
|
-
if (!isCollectionPredicate && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
1733
|
-
result.right = true;
|
|
1734
|
-
}
|
|
1735
|
-
return result;
|
|
1736
|
-
}
|
|
1737
|
-
isCollectionPredicateOperator(op) {
|
|
1738
|
-
return [
|
|
1739
|
-
"?",
|
|
1740
|
-
"!",
|
|
1741
|
-
"^"
|
|
1742
|
-
].includes(op);
|
|
1743
|
-
}
|
|
1744
|
-
};
|
|
1745
|
-
_ts_decorate([
|
|
1746
|
-
gen(Model2),
|
|
1747
|
-
_ts_metadata("design:type", Function),
|
|
1748
|
-
_ts_metadata("design:paramtypes", [
|
|
1749
|
-
typeof Model2 === "undefined" ? Object : Model2
|
|
1750
|
-
]),
|
|
1751
|
-
_ts_metadata("design:returntype", void 0)
|
|
1752
|
-
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
1753
|
-
_ts_decorate([
|
|
1754
|
-
gen(DataSource3),
|
|
1755
|
-
_ts_metadata("design:type", Function),
|
|
1756
|
-
_ts_metadata("design:paramtypes", [
|
|
1757
|
-
typeof DataSource3 === "undefined" ? Object : DataSource3
|
|
1758
|
-
]),
|
|
1759
|
-
_ts_metadata("design:returntype", void 0)
|
|
1760
|
-
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
1761
|
-
_ts_decorate([
|
|
1762
|
-
gen(Enum3),
|
|
1763
|
-
_ts_metadata("design:type", Function),
|
|
1764
|
-
_ts_metadata("design:paramtypes", [
|
|
1765
|
-
typeof Enum3 === "undefined" ? Object : Enum3
|
|
1766
|
-
]),
|
|
1767
|
-
_ts_metadata("design:returntype", void 0)
|
|
1768
|
-
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
1769
|
-
_ts_decorate([
|
|
1770
|
-
gen(EnumField2),
|
|
1771
|
-
_ts_metadata("design:type", Function),
|
|
1772
|
-
_ts_metadata("design:paramtypes", [
|
|
1773
|
-
typeof EnumField2 === "undefined" ? Object : EnumField2
|
|
1774
|
-
]),
|
|
1775
|
-
_ts_metadata("design:returntype", void 0)
|
|
1776
|
-
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
1777
|
-
_ts_decorate([
|
|
1778
|
-
gen(GeneratorDecl2),
|
|
1779
|
-
_ts_metadata("design:type", Function),
|
|
1780
|
-
_ts_metadata("design:paramtypes", [
|
|
1781
|
-
typeof GeneratorDecl2 === "undefined" ? Object : GeneratorDecl2
|
|
1782
|
-
]),
|
|
1783
|
-
_ts_metadata("design:returntype", void 0)
|
|
1784
|
-
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
1785
|
-
_ts_decorate([
|
|
1786
|
-
gen(ConfigField),
|
|
1787
|
-
_ts_metadata("design:type", Function),
|
|
1788
|
-
_ts_metadata("design:paramtypes", [
|
|
1789
|
-
typeof ConfigField === "undefined" ? Object : ConfigField
|
|
1790
|
-
]),
|
|
1791
|
-
_ts_metadata("design:returntype", void 0)
|
|
1792
|
-
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
1793
|
-
_ts_decorate([
|
|
1794
|
-
gen(ConfigArrayExpr),
|
|
1795
|
-
_ts_metadata("design:type", Function),
|
|
1796
|
-
_ts_metadata("design:paramtypes", [
|
|
1797
|
-
typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
|
|
1798
|
-
]),
|
|
1799
|
-
_ts_metadata("design:returntype", void 0)
|
|
1800
|
-
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
1801
|
-
_ts_decorate([
|
|
1802
|
-
gen(ConfigInvocationExpr),
|
|
1803
|
-
_ts_metadata("design:type", Function),
|
|
1804
|
-
_ts_metadata("design:paramtypes", [
|
|
1805
|
-
typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
|
|
1806
|
-
]),
|
|
1807
|
-
_ts_metadata("design:returntype", void 0)
|
|
1808
|
-
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
1809
|
-
_ts_decorate([
|
|
1810
|
-
gen(Plugin),
|
|
1811
|
-
_ts_metadata("design:type", Function),
|
|
1812
|
-
_ts_metadata("design:paramtypes", [
|
|
1813
|
-
typeof Plugin === "undefined" ? Object : Plugin
|
|
1814
|
-
]),
|
|
1815
|
-
_ts_metadata("design:returntype", void 0)
|
|
1816
|
-
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
1817
|
-
_ts_decorate([
|
|
1818
|
-
gen(PluginField),
|
|
1819
|
-
_ts_metadata("design:type", Function),
|
|
1820
|
-
_ts_metadata("design:paramtypes", [
|
|
1821
|
-
typeof PluginField === "undefined" ? Object : PluginField
|
|
1822
|
-
]),
|
|
1823
|
-
_ts_metadata("design:returntype", void 0)
|
|
1824
|
-
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
1825
|
-
_ts_decorate([
|
|
1826
|
-
gen(DataModel2),
|
|
1827
|
-
_ts_metadata("design:type", Function),
|
|
1828
|
-
_ts_metadata("design:paramtypes", [
|
|
1829
|
-
typeof DataModel2 === "undefined" ? Object : DataModel2
|
|
1830
|
-
]),
|
|
1831
|
-
_ts_metadata("design:returntype", void 0)
|
|
1832
|
-
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
1833
|
-
_ts_decorate([
|
|
1834
|
-
gen(DataField),
|
|
1835
|
-
_ts_metadata("design:type", Function),
|
|
1836
|
-
_ts_metadata("design:paramtypes", [
|
|
1837
|
-
typeof DataField === "undefined" ? Object : DataField
|
|
1838
|
-
]),
|
|
1839
|
-
_ts_metadata("design:returntype", void 0)
|
|
1840
|
-
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
1841
|
-
_ts_decorate([
|
|
1842
|
-
gen(DataModelAttribute),
|
|
1843
|
-
_ts_metadata("design:type", Function),
|
|
1844
|
-
_ts_metadata("design:paramtypes", [
|
|
1845
|
-
typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
|
|
1846
|
-
]),
|
|
1847
|
-
_ts_metadata("design:returntype", void 0)
|
|
1848
|
-
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
1849
|
-
_ts_decorate([
|
|
1850
|
-
gen(DataFieldAttribute),
|
|
1851
|
-
_ts_metadata("design:type", Function),
|
|
1852
|
-
_ts_metadata("design:paramtypes", [
|
|
1853
|
-
typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
|
|
1854
|
-
]),
|
|
1855
|
-
_ts_metadata("design:returntype", void 0)
|
|
1856
|
-
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
1857
|
-
_ts_decorate([
|
|
1858
|
-
gen(AttributeArg2),
|
|
1859
|
-
_ts_metadata("design:type", Function),
|
|
1860
|
-
_ts_metadata("design:paramtypes", [
|
|
1861
|
-
typeof AttributeArg2 === "undefined" ? Object : AttributeArg2
|
|
1862
|
-
]),
|
|
1863
|
-
_ts_metadata("design:returntype", void 0)
|
|
1864
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
1865
|
-
_ts_decorate([
|
|
1866
|
-
gen(ObjectExpr),
|
|
1867
|
-
_ts_metadata("design:type", Function),
|
|
1868
|
-
_ts_metadata("design:paramtypes", [
|
|
1869
|
-
typeof ObjectExpr === "undefined" ? Object : ObjectExpr
|
|
1870
|
-
]),
|
|
1871
|
-
_ts_metadata("design:returntype", void 0)
|
|
1872
|
-
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
1873
|
-
_ts_decorate([
|
|
1874
|
-
gen(ArrayExpr),
|
|
1875
|
-
_ts_metadata("design:type", Function),
|
|
1876
|
-
_ts_metadata("design:paramtypes", [
|
|
1877
|
-
typeof ArrayExpr === "undefined" ? Object : ArrayExpr
|
|
1878
|
-
]),
|
|
1879
|
-
_ts_metadata("design:returntype", void 0)
|
|
1880
|
-
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
1881
|
-
_ts_decorate([
|
|
1882
|
-
gen(StringLiteral2),
|
|
1883
|
-
_ts_metadata("design:type", Function),
|
|
1884
|
-
_ts_metadata("design:paramtypes", [
|
|
1885
|
-
typeof LiteralExpr === "undefined" ? Object : LiteralExpr
|
|
1886
|
-
]),
|
|
1887
|
-
_ts_metadata("design:returntype", void 0)
|
|
1888
|
-
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
1889
|
-
_ts_decorate([
|
|
1890
|
-
gen(NumberLiteral2),
|
|
1891
|
-
_ts_metadata("design:type", Function),
|
|
1892
|
-
_ts_metadata("design:paramtypes", [
|
|
1893
|
-
typeof NumberLiteral2 === "undefined" ? Object : NumberLiteral2
|
|
1894
|
-
]),
|
|
1895
|
-
_ts_metadata("design:returntype", void 0)
|
|
1896
|
-
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
1897
|
-
_ts_decorate([
|
|
1898
|
-
gen(BooleanLiteral2),
|
|
1899
|
-
_ts_metadata("design:type", Function),
|
|
1900
|
-
_ts_metadata("design:paramtypes", [
|
|
1901
|
-
typeof BooleanLiteral2 === "undefined" ? Object : BooleanLiteral2
|
|
1902
|
-
]),
|
|
1903
|
-
_ts_metadata("design:returntype", void 0)
|
|
1904
|
-
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
1905
|
-
_ts_decorate([
|
|
1906
|
-
gen(UnaryExpr),
|
|
1907
|
-
_ts_metadata("design:type", Function),
|
|
1908
|
-
_ts_metadata("design:paramtypes", [
|
|
1909
|
-
typeof UnaryExpr === "undefined" ? Object : UnaryExpr
|
|
1910
|
-
]),
|
|
1911
|
-
_ts_metadata("design:returntype", void 0)
|
|
1912
|
-
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
1913
|
-
_ts_decorate([
|
|
1914
|
-
gen(BinaryExpr),
|
|
1915
|
-
_ts_metadata("design:type", Function),
|
|
1916
|
-
_ts_metadata("design:paramtypes", [
|
|
1917
|
-
typeof BinaryExpr === "undefined" ? Object : BinaryExpr
|
|
1918
|
-
]),
|
|
1919
|
-
_ts_metadata("design:returntype", void 0)
|
|
1920
|
-
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
1921
|
-
_ts_decorate([
|
|
1922
|
-
gen(ReferenceExpr),
|
|
1923
|
-
_ts_metadata("design:type", Function),
|
|
1924
|
-
_ts_metadata("design:paramtypes", [
|
|
1925
|
-
typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
|
|
1926
|
-
]),
|
|
1927
|
-
_ts_metadata("design:returntype", void 0)
|
|
1928
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
1929
|
-
_ts_decorate([
|
|
1930
|
-
gen(ReferenceArg),
|
|
1931
|
-
_ts_metadata("design:type", Function),
|
|
1932
|
-
_ts_metadata("design:paramtypes", [
|
|
1933
|
-
typeof ReferenceArg === "undefined" ? Object : ReferenceArg
|
|
1934
|
-
]),
|
|
1935
|
-
_ts_metadata("design:returntype", void 0)
|
|
1936
|
-
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
1937
|
-
_ts_decorate([
|
|
1938
|
-
gen(MemberAccessExpr),
|
|
1939
|
-
_ts_metadata("design:type", Function),
|
|
1940
|
-
_ts_metadata("design:paramtypes", [
|
|
1941
|
-
typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
|
|
1942
|
-
]),
|
|
1943
|
-
_ts_metadata("design:returntype", void 0)
|
|
1944
|
-
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
1945
|
-
_ts_decorate([
|
|
1946
|
-
gen(InvocationExpr),
|
|
1947
|
-
_ts_metadata("design:type", Function),
|
|
1948
|
-
_ts_metadata("design:paramtypes", [
|
|
1949
|
-
typeof InvocationExpr === "undefined" ? Object : InvocationExpr
|
|
1950
|
-
]),
|
|
1951
|
-
_ts_metadata("design:returntype", void 0)
|
|
1952
|
-
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
1953
|
-
_ts_decorate([
|
|
1954
|
-
gen(NullExpr),
|
|
1955
|
-
_ts_metadata("design:type", Function),
|
|
1956
|
-
_ts_metadata("design:paramtypes", []),
|
|
1957
|
-
_ts_metadata("design:returntype", void 0)
|
|
1958
|
-
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
1959
|
-
_ts_decorate([
|
|
1960
|
-
gen(ThisExpr),
|
|
1961
|
-
_ts_metadata("design:type", Function),
|
|
1962
|
-
_ts_metadata("design:paramtypes", []),
|
|
1963
|
-
_ts_metadata("design:returntype", void 0)
|
|
1964
|
-
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
1965
|
-
_ts_decorate([
|
|
1966
|
-
gen(Attribute),
|
|
1967
|
-
_ts_metadata("design:type", Function),
|
|
1968
|
-
_ts_metadata("design:paramtypes", [
|
|
1969
|
-
typeof Attribute === "undefined" ? Object : Attribute
|
|
1970
|
-
]),
|
|
1971
|
-
_ts_metadata("design:returntype", void 0)
|
|
1972
|
-
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
1973
|
-
_ts_decorate([
|
|
1974
|
-
gen(AttributeParam),
|
|
1975
|
-
_ts_metadata("design:type", Function),
|
|
1976
|
-
_ts_metadata("design:paramtypes", [
|
|
1977
|
-
typeof AttributeParam === "undefined" ? Object : AttributeParam
|
|
1978
|
-
]),
|
|
1979
|
-
_ts_metadata("design:returntype", void 0)
|
|
1980
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
1981
|
-
_ts_decorate([
|
|
1982
|
-
gen(AttributeParamType),
|
|
1983
|
-
_ts_metadata("design:type", Function),
|
|
1984
|
-
_ts_metadata("design:paramtypes", [
|
|
1985
|
-
typeof AttributeParamType === "undefined" ? Object : AttributeParamType
|
|
1986
|
-
]),
|
|
1987
|
-
_ts_metadata("design:returntype", void 0)
|
|
1988
|
-
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
1989
|
-
_ts_decorate([
|
|
1990
|
-
gen(FunctionDecl),
|
|
1991
|
-
_ts_metadata("design:type", Function),
|
|
1992
|
-
_ts_metadata("design:paramtypes", [
|
|
1993
|
-
typeof FunctionDecl === "undefined" ? Object : FunctionDecl
|
|
1994
|
-
]),
|
|
1995
|
-
_ts_metadata("design:returntype", void 0)
|
|
1996
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
1997
|
-
_ts_decorate([
|
|
1998
|
-
gen(FunctionParam),
|
|
1999
|
-
_ts_metadata("design:type", Function),
|
|
2000
|
-
_ts_metadata("design:paramtypes", [
|
|
2001
|
-
typeof FunctionParam === "undefined" ? Object : FunctionParam
|
|
2002
|
-
]),
|
|
2003
|
-
_ts_metadata("design:returntype", void 0)
|
|
2004
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
2005
|
-
_ts_decorate([
|
|
2006
|
-
gen(FunctionParamType),
|
|
2007
|
-
_ts_metadata("design:type", Function),
|
|
2008
|
-
_ts_metadata("design:paramtypes", [
|
|
2009
|
-
typeof FunctionParamType === "undefined" ? Object : FunctionParamType
|
|
2010
|
-
]),
|
|
2011
|
-
_ts_metadata("design:returntype", void 0)
|
|
2012
|
-
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
2013
|
-
_ts_decorate([
|
|
2014
|
-
gen(TypeDef),
|
|
2015
|
-
_ts_metadata("design:type", Function),
|
|
2016
|
-
_ts_metadata("design:paramtypes", [
|
|
2017
|
-
typeof TypeDef === "undefined" ? Object : TypeDef
|
|
2018
|
-
]),
|
|
2019
|
-
_ts_metadata("design:returntype", void 0)
|
|
2020
|
-
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
2021
1661
|
export {
|
|
2022
1662
|
model_utils_exports as ModelUtils,
|
|
2023
1663
|
PrismaSchemaGenerator,
|
|
2024
|
-
TsSchemaGenerator
|
|
2025
|
-
ZModelCodeGenerator
|
|
1664
|
+
TsSchemaGenerator
|
|
2026
1665
|
};
|
|
2027
1666
|
//# sourceMappingURL=index.js.map
|