@zenstackhq/sdk 3.0.0-beta.26 → 3.0.0-beta.28
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 +26 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +26 -30
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -136,7 +136,8 @@ declare class TsSchemaGenerator {
|
|
|
136
136
|
private generateSchema;
|
|
137
137
|
private generateSchemaStatements;
|
|
138
138
|
private createExpressionUtilsCall;
|
|
139
|
-
private
|
|
139
|
+
private createSchemaClass;
|
|
140
|
+
private createAsConst;
|
|
140
141
|
private createProviderObject;
|
|
141
142
|
private createModelsObject;
|
|
142
143
|
private getAllDataModels;
|
package/dist/index.d.ts
CHANGED
|
@@ -136,7 +136,8 @@ declare class TsSchemaGenerator {
|
|
|
136
136
|
private generateSchema;
|
|
137
137
|
private generateSchemaStatements;
|
|
138
138
|
private createExpressionUtilsCall;
|
|
139
|
-
private
|
|
139
|
+
private createSchemaClass;
|
|
140
|
+
private createAsConst;
|
|
140
141
|
private createProviderObject;
|
|
141
142
|
private createModelsObject;
|
|
142
143
|
private getAllDataModels;
|
package/dist/index.js
CHANGED
|
@@ -869,8 +869,8 @@ var TsSchemaGenerator = class {
|
|
|
869
869
|
}
|
|
870
870
|
generateSchemaStatements(model, statements, lite) {
|
|
871
871
|
const hasComputedFields = model.declarations.some((d) => isDataModel3(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
|
|
872
|
-
const
|
|
873
|
-
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(
|
|
872
|
+
const schemaClass = this.createSchemaClass(model, lite);
|
|
873
|
+
const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
|
|
874
874
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
|
|
875
875
|
...hasComputedFields ? [
|
|
876
876
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
|
|
@@ -880,57 +880,53 @@ var TsSchemaGenerator = class {
|
|
|
880
880
|
] : []
|
|
881
881
|
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
882
882
|
statements.push(runtimeImportDecl);
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
], ts.NodeFlags.Const));
|
|
886
|
-
statements.push(_schemaDecl);
|
|
887
|
-
const brandedSchemaType = ts.factory.createTypeAliasDeclaration(void 0, "Schema", void 0, ts.factory.createIntersectionTypeNode([
|
|
888
|
-
ts.factory.createTypeQueryNode(ts.factory.createIdentifier("_schema")),
|
|
889
|
-
ts.factory.createTypeLiteralNode([
|
|
890
|
-
ts.factory.createPropertySignature(void 0, "__brand", ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("schema")))
|
|
891
|
-
])
|
|
892
|
-
]));
|
|
893
|
-
statements.push(brandedSchemaType);
|
|
894
|
-
const schemaExportDecl = ts.factory.createVariableStatement([
|
|
883
|
+
statements.push(schemaClass);
|
|
884
|
+
const schemaDecl = ts.factory.createVariableStatement([
|
|
895
885
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
896
886
|
], ts.factory.createVariableDeclarationList([
|
|
897
|
-
ts.factory.createVariableDeclaration("schema", void 0, ts.factory.
|
|
887
|
+
ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))
|
|
898
888
|
], ts.NodeFlags.Const));
|
|
899
|
-
statements.push(
|
|
900
|
-
const schemaTypeDeclaration = ts.factory.createTypeAliasDeclaration([
|
|
901
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
902
|
-
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("Schema"));
|
|
903
|
-
statements.push(schemaTypeDeclaration);
|
|
889
|
+
statements.push(schemaDecl);
|
|
904
890
|
}
|
|
905
891
|
createExpressionUtilsCall(method, args) {
|
|
906
892
|
this.usedExpressionUtils = true;
|
|
907
893
|
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
|
|
908
894
|
}
|
|
909
|
-
|
|
910
|
-
const
|
|
895
|
+
createSchemaClass(model, lite) {
|
|
896
|
+
const members = [
|
|
911
897
|
// provider
|
|
912
|
-
ts.factory.
|
|
898
|
+
ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
|
|
913
899
|
// models
|
|
914
|
-
ts.factory.
|
|
900
|
+
ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
|
|
915
901
|
// typeDefs
|
|
916
902
|
...model.declarations.some(isTypeDef3) ? [
|
|
917
|
-
ts.factory.
|
|
903
|
+
ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))
|
|
918
904
|
] : []
|
|
919
905
|
];
|
|
920
906
|
const enums = model.declarations.filter(isEnum);
|
|
921
907
|
if (enums.length > 0) {
|
|
922
|
-
|
|
908
|
+
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))));
|
|
923
909
|
}
|
|
924
910
|
const authType = getAuthDecl(model);
|
|
925
911
|
if (authType) {
|
|
926
|
-
|
|
912
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
|
|
927
913
|
}
|
|
928
914
|
const procedures = model.declarations.filter(isProcedure);
|
|
929
915
|
if (procedures.length > 0) {
|
|
930
|
-
|
|
916
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
|
|
931
917
|
}
|
|
932
|
-
|
|
933
|
-
|
|
918
|
+
members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
|
|
919
|
+
const schemaClass = ts.factory.createClassDeclaration([
|
|
920
|
+
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
921
|
+
], "SchemaType", void 0, [
|
|
922
|
+
ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
|
|
923
|
+
ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)
|
|
924
|
+
])
|
|
925
|
+
], members);
|
|
926
|
+
return schemaClass;
|
|
927
|
+
}
|
|
928
|
+
createAsConst(expr) {
|
|
929
|
+
return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
|
|
934
930
|
}
|
|
935
931
|
createProviderObject(model) {
|
|
936
932
|
const dsProvider = this.getDataSourceProvider(model);
|