@zenstackhq/sdk 3.0.0-beta.1 → 3.0.0-beta.10
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 +45 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +55 -38
- package/dist/index.js.map +1 -1
- package/dist/schema.d.cts +1 -0
- package/dist/schema.d.ts +1 -0
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -100,12 +100,12 @@ declare class PrismaSchemaGenerator {
|
|
|
100
100
|
private literalToText;
|
|
101
101
|
private generateGenerator;
|
|
102
102
|
private generateModel;
|
|
103
|
+
private isInheritedMapAttribute;
|
|
103
104
|
private isPrismaAttribute;
|
|
104
105
|
private getUnsupportedFieldType;
|
|
105
106
|
private getStringLiteral;
|
|
106
107
|
private generateModelField;
|
|
107
|
-
private
|
|
108
|
-
private isFromPlugin;
|
|
108
|
+
private isDefaultWithAuthInvocation;
|
|
109
109
|
private isInheritedFromDelegate;
|
|
110
110
|
private makeFieldAttribute;
|
|
111
111
|
private makeAttributeArg;
|
|
@@ -122,9 +122,11 @@ declare class PrismaSchemaGenerator {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
declare class TsSchemaGenerator {
|
|
125
|
+
private usedExpressionUtils;
|
|
125
126
|
generate(model: Model, outputDir: string): Promise<void>;
|
|
126
127
|
private generateSchema;
|
|
127
128
|
private generateSchemaStatements;
|
|
129
|
+
private createExpressionUtilsCall;
|
|
128
130
|
private createSchemaObject;
|
|
129
131
|
private createProviderObject;
|
|
130
132
|
private createModelsObject;
|
package/dist/index.d.ts
CHANGED
|
@@ -100,12 +100,12 @@ declare class PrismaSchemaGenerator {
|
|
|
100
100
|
private literalToText;
|
|
101
101
|
private generateGenerator;
|
|
102
102
|
private generateModel;
|
|
103
|
+
private isInheritedMapAttribute;
|
|
103
104
|
private isPrismaAttribute;
|
|
104
105
|
private getUnsupportedFieldType;
|
|
105
106
|
private getStringLiteral;
|
|
106
107
|
private generateModelField;
|
|
107
|
-
private
|
|
108
|
-
private isFromPlugin;
|
|
108
|
+
private isDefaultWithAuthInvocation;
|
|
109
109
|
private isInheritedFromDelegate;
|
|
110
110
|
private makeFieldAttribute;
|
|
111
111
|
private makeAttributeArg;
|
|
@@ -122,9 +122,11 @@ declare class PrismaSchemaGenerator {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
declare class TsSchemaGenerator {
|
|
125
|
+
private usedExpressionUtils;
|
|
125
126
|
generate(model: Model, outputDir: string): Promise<void>;
|
|
126
127
|
private generateSchema;
|
|
127
128
|
private generateSchemaStatements;
|
|
129
|
+
private createExpressionUtilsCall;
|
|
128
130
|
private createSchemaObject;
|
|
129
131
|
private createProviderObject;
|
|
130
132
|
private createModelsObject;
|
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,7 +88,7 @@ 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
93
|
found = model.declarations.find((d) => isDataModel(d) && d.name === "User");
|
|
94
94
|
}
|
|
@@ -103,8 +103,8 @@ 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 { BooleanLiteral, DataModel, DataSource as DataSource2, Enum as Enum2, GeneratorDecl, isArrayExpr, isDataModel as isDataModel2, isInvocationExpr, isLiteralExpr as isLiteralExpr2,
|
|
107
|
-
import { getAllAttributes, getAllFields as getAllFields2, isDelegateModel as isDelegateModel2 } from "@zenstackhq/language/utils";
|
|
106
|
+
import { BooleanLiteral, DataModel, DataSource as DataSource2, Enum as Enum2, GeneratorDecl, isArrayExpr, isDataModel as isDataModel2, isInvocationExpr, isLiteralExpr as isLiteralExpr2, isNullExpr, isReferenceExpr, isStringLiteral, isTypeDef as isTypeDef2, NumberLiteral, StringLiteral } from "@zenstackhq/language/ast";
|
|
107
|
+
import { getAllAttributes, getAllFields as getAllFields2, isAuthInvocation, isDelegateModel as isDelegateModel2 } from "@zenstackhq/language/utils";
|
|
108
108
|
import { AstUtils } from "langium";
|
|
109
109
|
import { match } from "ts-pattern";
|
|
110
110
|
|
|
@@ -586,13 +586,20 @@ var PrismaSchemaGenerator = class {
|
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
const allAttributes = getAllAttributes(decl);
|
|
589
|
-
for (const attr of allAttributes.filter((attr2) => this.isPrismaAttribute(attr2))) {
|
|
589
|
+
for (const attr of allAttributes.filter((attr2) => this.isPrismaAttribute(attr2) && !this.isInheritedMapAttribute(attr2, decl))) {
|
|
590
590
|
this.generateContainerAttribute(model, attr);
|
|
591
591
|
}
|
|
592
592
|
decl.comments.forEach((c) => model.addComment(c));
|
|
593
593
|
this.generateDelegateRelationForBase(model, decl);
|
|
594
594
|
this.generateDelegateRelationForConcrete(model, decl);
|
|
595
595
|
}
|
|
596
|
+
isInheritedMapAttribute(attr, contextModel) {
|
|
597
|
+
if (attr.$container === contextModel) {
|
|
598
|
+
return false;
|
|
599
|
+
}
|
|
600
|
+
const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
|
|
601
|
+
return attrName === "@@map";
|
|
602
|
+
}
|
|
596
603
|
isPrismaAttribute(attr) {
|
|
597
604
|
if (!attr.decl.ref) {
|
|
598
605
|
return false;
|
|
@@ -619,7 +626,7 @@ var PrismaSchemaGenerator = class {
|
|
|
619
626
|
if (field.type.type) {
|
|
620
627
|
fieldType = field.type.type;
|
|
621
628
|
} else if (field.type.reference?.ref) {
|
|
622
|
-
if (
|
|
629
|
+
if (isTypeDef2(field.type.reference.ref)) {
|
|
623
630
|
fieldType = "Json";
|
|
624
631
|
} else {
|
|
625
632
|
fieldType = field.type.reference.ref.name;
|
|
@@ -635,10 +642,10 @@ var PrismaSchemaGenerator = class {
|
|
|
635
642
|
}
|
|
636
643
|
const isArray = (
|
|
637
644
|
// typed-JSON fields should be translated to scalar Json type
|
|
638
|
-
|
|
645
|
+
isTypeDef2(field.type.reference?.ref) ? false : field.type.array
|
|
639
646
|
);
|
|
640
647
|
const type = new ModelFieldType(fieldType, isArray, field.type.optional);
|
|
641
|
-
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.
|
|
648
|
+
const attributes = field.attributes.filter((attr) => this.isPrismaAttribute(attr)).filter((attr) => !this.isDefaultWithAuthInvocation(attr)).filter((attr) => (
|
|
642
649
|
// when building physical schema, exclude `@default` for id fields inherited from delegate base
|
|
643
650
|
!(model_utils_exports.isIdField(field, contextModel) && this.isInheritedFromDelegate(field, contextModel) && attr.decl.$refText === "@default")
|
|
644
651
|
)).map((attr) => this.makeFieldAttribute(attr));
|
|
@@ -648,7 +655,7 @@ var PrismaSchemaGenerator = class {
|
|
|
648
655
|
const result = model.addField(field.name, type, attributes, docs, addToFront);
|
|
649
656
|
return result;
|
|
650
657
|
}
|
|
651
|
-
|
|
658
|
+
isDefaultWithAuthInvocation(attr) {
|
|
652
659
|
if (attr.decl.ref?.name !== "@default") {
|
|
653
660
|
return false;
|
|
654
661
|
}
|
|
@@ -656,11 +663,7 @@ var PrismaSchemaGenerator = class {
|
|
|
656
663
|
if (!expr) {
|
|
657
664
|
return false;
|
|
658
665
|
}
|
|
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");
|
|
666
|
+
return AstUtils.streamAst(expr).some(isAuthInvocation);
|
|
664
667
|
}
|
|
665
668
|
isInheritedFromDelegate(field, contextModel) {
|
|
666
669
|
return field.$container !== contextModel && model_utils_exports.isDelegateModel(field.$container);
|
|
@@ -778,7 +781,7 @@ var PrismaSchemaGenerator = class {
|
|
|
778
781
|
|
|
779
782
|
// src/ts-schema-generator.ts
|
|
780
783
|
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
|
|
784
|
+
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 isTypeDef3, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
782
785
|
import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, isDataFieldReference } from "@zenstackhq/language/utils";
|
|
783
786
|
import fs from "fs";
|
|
784
787
|
import path from "path";
|
|
@@ -788,10 +791,12 @@ var TsSchemaGenerator = class {
|
|
|
788
791
|
static {
|
|
789
792
|
__name(this, "TsSchemaGenerator");
|
|
790
793
|
}
|
|
794
|
+
usedExpressionUtils = false;
|
|
791
795
|
async generate(model, outputDir) {
|
|
792
796
|
fs.mkdirSync(outputDir, {
|
|
793
797
|
recursive: true
|
|
794
798
|
});
|
|
799
|
+
this.usedExpressionUtils = false;
|
|
795
800
|
this.generateSchema(model, outputDir);
|
|
796
801
|
this.generateModelsAndTypeDefs(model, outputDir);
|
|
797
802
|
this.generateInputTypes(model, outputDir);
|
|
@@ -808,18 +813,21 @@ var TsSchemaGenerator = class {
|
|
|
808
813
|
}
|
|
809
814
|
generateSchemaStatements(model, statements) {
|
|
810
815
|
const hasComputedFields = model.declarations.some((d) => isDataModel3(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
816
|
+
const schemaObject = this.createSchemaObject(model);
|
|
811
817
|
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
812
818
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
813
819
|
...hasComputedFields ? [
|
|
814
820
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
815
821
|
] : [],
|
|
816
|
-
|
|
822
|
+
...this.usedExpressionUtils ? [
|
|
823
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ExpressionUtils"))
|
|
824
|
+
] : []
|
|
817
825
|
])), ts.factory.createStringLiteral("@zenstackhq/runtime/schema"));
|
|
818
826
|
statements.push(runtimeImportDecl);
|
|
819
827
|
const declaration = ts.factory.createVariableStatement([
|
|
820
828
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
821
829
|
], ts.factory.createVariableDeclarationList([
|
|
822
|
-
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(
|
|
830
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(schemaObject, ts.factory.createTypeReferenceNode("const")), ts.factory.createTypeReferenceNode("SchemaDef")))
|
|
823
831
|
], ts.NodeFlags.Const));
|
|
824
832
|
statements.push(declaration);
|
|
825
833
|
const typeDeclaration = ts.factory.createTypeAliasDeclaration([
|
|
@@ -827,6 +835,10 @@ var TsSchemaGenerator = class {
|
|
|
827
835
|
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("typeof schema"));
|
|
828
836
|
statements.push(typeDeclaration);
|
|
829
837
|
}
|
|
838
|
+
createExpressionUtilsCall(method, args) {
|
|
839
|
+
this.usedExpressionUtils = true;
|
|
840
|
+
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
841
|
+
}
|
|
830
842
|
createSchemaObject(model) {
|
|
831
843
|
const properties = [
|
|
832
844
|
// provider
|
|
@@ -834,7 +846,7 @@ var TsSchemaGenerator = class {
|
|
|
834
846
|
// models
|
|
835
847
|
ts.factory.createPropertyAssignment("models", this.createModelsObject(model)),
|
|
836
848
|
// typeDefs
|
|
837
|
-
...model.declarations.some(
|
|
849
|
+
...model.declarations.some(isTypeDef3) ? [
|
|
838
850
|
ts.factory.createPropertyAssignment("typeDefs", this.createTypeDefsObject(model))
|
|
839
851
|
] : []
|
|
840
852
|
];
|
|
@@ -863,7 +875,7 @@ var TsSchemaGenerator = class {
|
|
|
863
875
|
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => isDataModel3(d) && !hasAttribute(d, "@@ignore")).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm))), true);
|
|
864
876
|
}
|
|
865
877
|
createTypeDefsObject(model) {
|
|
866
|
-
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) =>
|
|
878
|
+
return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => isTypeDef3(d)).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td))), true);
|
|
867
879
|
}
|
|
868
880
|
createDataModelObject(dm) {
|
|
869
881
|
const allFields = getAllFields3(dm);
|
|
@@ -898,6 +910,9 @@ var TsSchemaGenerator = class {
|
|
|
898
910
|
// subModels
|
|
899
911
|
...subModels.length > 0 ? [
|
|
900
912
|
ts.factory.createPropertyAssignment("subModels", ts.factory.createArrayLiteralExpression(subModels.map((subModel) => ts.factory.createStringLiteral(subModel))))
|
|
913
|
+
] : [],
|
|
914
|
+
...dm.isView ? [
|
|
915
|
+
ts.factory.createPropertyAssignment("isView", ts.factory.createTrue())
|
|
901
916
|
] : []
|
|
902
917
|
];
|
|
903
918
|
const computedFields = dm.fields.filter((f) => hasAttribute(f, "@computed"));
|
|
@@ -926,9 +941,9 @@ var TsSchemaGenerator = class {
|
|
|
926
941
|
}
|
|
927
942
|
createComputedFieldsObject(fields) {
|
|
928
943
|
return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [
|
|
929
|
-
// parameter: `context: {
|
|
944
|
+
// parameter: `context: { modelAlias: string }`
|
|
930
945
|
ts.factory.createParameterDeclaration(void 0, void 0, "_context", void 0, ts.factory.createTypeLiteralNode([
|
|
931
|
-
ts.factory.createPropertySignature(void 0, "
|
|
946
|
+
ts.factory.createPropertySignature(void 0, "modelAlias", void 0, ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))
|
|
932
947
|
]), void 0)
|
|
933
948
|
], ts.factory.createTypeReferenceNode("OperandExpression", [
|
|
934
949
|
ts.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type))
|
|
@@ -984,15 +999,17 @@ var TsSchemaGenerator = class {
|
|
|
984
999
|
if (defaultValue !== void 0) {
|
|
985
1000
|
if (typeof defaultValue === "object" && !Array.isArray(defaultValue)) {
|
|
986
1001
|
if ("call" in defaultValue) {
|
|
987
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
1002
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("call", [
|
|
988
1003
|
ts.factory.createStringLiteral(defaultValue.call),
|
|
989
1004
|
...defaultValue.args.length > 0 ? [
|
|
990
|
-
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.
|
|
1005
|
+
ts.factory.createArrayLiteralExpression(defaultValue.args.map((arg) => this.createExpressionUtilsCall("literal", [
|
|
1006
|
+
this.createLiteralNode(arg)
|
|
1007
|
+
])))
|
|
991
1008
|
] : []
|
|
992
1009
|
])));
|
|
993
1010
|
} else if ("authMember" in defaultValue) {
|
|
994
|
-
objectFields.push(ts.factory.createPropertyAssignment("default",
|
|
995
|
-
|
|
1011
|
+
objectFields.push(ts.factory.createPropertyAssignment("default", this.createExpressionUtilsCall("member", [
|
|
1012
|
+
this.createExpressionUtilsCall("call", [
|
|
996
1013
|
ts.factory.createStringLiteral("auth")
|
|
997
1014
|
]),
|
|
998
1015
|
ts.factory.createArrayLiteralExpression(defaultValue.authMember.map((m) => ts.factory.createStringLiteral(m)))
|
|
@@ -1306,7 +1323,7 @@ var TsSchemaGenerator = class {
|
|
|
1306
1323
|
});
|
|
1307
1324
|
}
|
|
1308
1325
|
createThisExpression() {
|
|
1309
|
-
return
|
|
1326
|
+
return this.createExpressionUtilsCall("_this");
|
|
1310
1327
|
}
|
|
1311
1328
|
createMemberExpression(expr) {
|
|
1312
1329
|
const members = [];
|
|
@@ -1320,32 +1337,32 @@ var TsSchemaGenerator = class {
|
|
|
1320
1337
|
this.createExpression(receiver),
|
|
1321
1338
|
ts.factory.createArrayLiteralExpression(members.map((m) => ts.factory.createStringLiteral(m)))
|
|
1322
1339
|
];
|
|
1323
|
-
return
|
|
1340
|
+
return this.createExpressionUtilsCall("member", args);
|
|
1324
1341
|
}
|
|
1325
1342
|
createNullExpression() {
|
|
1326
|
-
return
|
|
1343
|
+
return this.createExpressionUtilsCall("_null");
|
|
1327
1344
|
}
|
|
1328
1345
|
createBinaryExpression(expr) {
|
|
1329
|
-
return
|
|
1346
|
+
return this.createExpressionUtilsCall("binary", [
|
|
1330
1347
|
this.createExpression(expr.left),
|
|
1331
1348
|
this.createLiteralNode(expr.operator),
|
|
1332
1349
|
this.createExpression(expr.right)
|
|
1333
1350
|
]);
|
|
1334
1351
|
}
|
|
1335
1352
|
createUnaryExpression(expr) {
|
|
1336
|
-
return
|
|
1353
|
+
return this.createExpressionUtilsCall("unary", [
|
|
1337
1354
|
this.createLiteralNode(expr.operator),
|
|
1338
1355
|
this.createExpression(expr.operand)
|
|
1339
1356
|
]);
|
|
1340
1357
|
}
|
|
1341
1358
|
createArrayExpression(expr) {
|
|
1342
|
-
return
|
|
1359
|
+
return this.createExpressionUtilsCall("array", [
|
|
1343
1360
|
ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))
|
|
1344
1361
|
]);
|
|
1345
1362
|
}
|
|
1346
1363
|
createRefExpression(expr) {
|
|
1347
1364
|
if (isDataField(expr.target.ref)) {
|
|
1348
|
-
return
|
|
1365
|
+
return this.createExpressionUtilsCall("field", [
|
|
1349
1366
|
this.createLiteralNode(expr.target.$refText)
|
|
1350
1367
|
]);
|
|
1351
1368
|
} else if (isEnumField(expr.target.ref)) {
|
|
@@ -1355,7 +1372,7 @@ var TsSchemaGenerator = class {
|
|
|
1355
1372
|
}
|
|
1356
1373
|
}
|
|
1357
1374
|
createCallExpression(expr) {
|
|
1358
|
-
return
|
|
1375
|
+
return this.createExpressionUtilsCall("call", [
|
|
1359
1376
|
ts.factory.createStringLiteral(expr.function.$refText),
|
|
1360
1377
|
...expr.args.length > 0 ? [
|
|
1361
1378
|
ts.factory.createArrayLiteralExpression(expr.args.map((arg) => this.createExpression(arg.value)))
|
|
@@ -1363,11 +1380,11 @@ var TsSchemaGenerator = class {
|
|
|
1363
1380
|
]);
|
|
1364
1381
|
}
|
|
1365
1382
|
createLiteralExpression(type, value) {
|
|
1366
|
-
return match2(type).with("BooleanLiteral", () =>
|
|
1383
|
+
return match2(type).with("BooleanLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1367
1384
|
this.createLiteralNode(value)
|
|
1368
|
-
])).with("NumberLiteral", () =>
|
|
1385
|
+
])).with("NumberLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1369
1386
|
ts.factory.createIdentifier(value)
|
|
1370
|
-
])).with("StringLiteral", () =>
|
|
1387
|
+
])).with("StringLiteral", () => this.createExpressionUtilsCall("literal", [
|
|
1371
1388
|
this.createLiteralNode(value)
|
|
1372
1389
|
])).otherwise(() => {
|
|
1373
1390
|
throw new Error(`Unsupported literal type: ${type}`);
|
|
@@ -1378,7 +1395,7 @@ var TsSchemaGenerator = class {
|
|
|
1378
1395
|
statements.push(this.generateSchemaImport(model, true, true));
|
|
1379
1396
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
|
|
1380
1397
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`ModelResult as $ModelResult`)),
|
|
1381
|
-
...model.declarations.some(
|
|
1398
|
+
...model.declarations.some(isTypeDef3) ? [
|
|
1382
1399
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1383
1400
|
] : []
|
|
1384
1401
|
])), ts.factory.createStringLiteral("@zenstackhq/runtime")));
|
|
@@ -1395,7 +1412,7 @@ var TsSchemaGenerator = class {
|
|
|
1395
1412
|
}
|
|
1396
1413
|
statements.push(modelType);
|
|
1397
1414
|
}
|
|
1398
|
-
const typeDefs = model.declarations.filter(
|
|
1415
|
+
const typeDefs = model.declarations.filter(isTypeDef3);
|
|
1399
1416
|
for (const td of typeDefs) {
|
|
1400
1417
|
let typeDef = ts.factory.createTypeAliasDeclaration([
|
|
1401
1418
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|