@zenstackhq/sdk 3.0.0-beta.27 → 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 CHANGED
@@ -901,8 +901,8 @@ var TsSchemaGenerator = class {
901
901
  }
902
902
  generateSchemaStatements(model, statements, lite) {
903
903
  const hasComputedFields = model.declarations.some((d) => (0, import_ast3.isDataModel)(d) && d.fields.some((f) => hasAttribute(f, "@computed")));
904
- const schemaObject = this.createSchemaObject(model, lite);
905
- const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
904
+ const schemaClass = this.createSchemaClass(model, lite);
905
+ const runtimeImportDecl = ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(void 0, void 0, ts.factory.createNamedImports([
906
906
  ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("SchemaDef")),
907
907
  ...hasComputedFields ? [
908
908
  ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier("OperandExpression"))
@@ -912,57 +912,53 @@ var TsSchemaGenerator = class {
912
912
  ] : []
913
913
  ])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
914
914
  statements.push(runtimeImportDecl);
915
- const _schemaDecl = ts.factory.createVariableStatement([], ts.factory.createVariableDeclarationList([
916
- ts.factory.createVariableDeclaration("_schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(schemaObject, ts.factory.createTypeReferenceNode("const")), ts.factory.createTypeReferenceNode("SchemaDef")))
917
- ], ts.NodeFlags.Const));
918
- statements.push(_schemaDecl);
919
- const brandedSchemaType = ts.factory.createTypeAliasDeclaration(void 0, "Schema", void 0, ts.factory.createIntersectionTypeNode([
920
- ts.factory.createTypeQueryNode(ts.factory.createIdentifier("_schema")),
921
- ts.factory.createTypeLiteralNode([
922
- ts.factory.createPropertySignature(void 0, "__brand", ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("schema")))
923
- ])
924
- ]));
925
- statements.push(brandedSchemaType);
926
- const schemaExportDecl = ts.factory.createVariableStatement([
915
+ statements.push(schemaClass);
916
+ const schemaDecl = ts.factory.createVariableStatement([
927
917
  ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
928
918
  ], ts.factory.createVariableDeclarationList([
929
- ts.factory.createVariableDeclaration("schema", void 0, ts.factory.createTypeReferenceNode("Schema"), ts.factory.createIdentifier("_schema"))
919
+ ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("SchemaType"), void 0, []))
930
920
  ], ts.NodeFlags.Const));
931
- statements.push(schemaExportDecl);
932
- const schemaTypeDeclaration = ts.factory.createTypeAliasDeclaration([
933
- ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
934
- ], "SchemaType", void 0, ts.factory.createTypeReferenceNode("Schema"));
935
- statements.push(schemaTypeDeclaration);
921
+ statements.push(schemaDecl);
936
922
  }
937
923
  createExpressionUtilsCall(method, args) {
938
924
  this.usedExpressionUtils = true;
939
925
  return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("ExpressionUtils"), method), void 0, args || []);
940
926
  }
941
- createSchemaObject(model, lite) {
942
- const properties = [
927
+ createSchemaClass(model, lite) {
928
+ const members = [
943
929
  // provider
944
- ts.factory.createPropertyAssignment("provider", this.createProviderObject(model)),
930
+ ts.factory.createPropertyDeclaration(void 0, "provider", void 0, void 0, this.createAsConst(this.createProviderObject(model))),
945
931
  // models
946
- ts.factory.createPropertyAssignment("models", this.createModelsObject(model, lite)),
932
+ ts.factory.createPropertyDeclaration(void 0, "models", void 0, void 0, this.createAsConst(this.createModelsObject(model, lite))),
947
933
  // typeDefs
948
934
  ...model.declarations.some(import_ast3.isTypeDef) ? [
949
- ts.factory.createPropertyAssignment("typeDefs", this.createTypeDefsObject(model, lite))
935
+ ts.factory.createPropertyDeclaration(void 0, "typeDefs", void 0, void 0, this.createAsConst(this.createTypeDefsObject(model, lite)))
950
936
  ] : []
951
937
  ];
952
938
  const enums = model.declarations.filter(import_ast3.isEnum);
953
939
  if (enums.length > 0) {
954
- properties.push(ts.factory.createPropertyAssignment("enums", ts.factory.createObjectLiteralExpression(enums.map((e) => ts.factory.createPropertyAssignment(e.name, this.createEnumObject(e))), true)));
940
+ 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))));
955
941
  }
956
942
  const authType = getAuthDecl(model);
957
943
  if (authType) {
958
- properties.push(ts.factory.createPropertyAssignment("authType", this.createLiteralNode(authType.name)));
944
+ members.push(ts.factory.createPropertyDeclaration(void 0, "authType", void 0, void 0, this.createAsConst(this.createLiteralNode(authType.name))));
959
945
  }
960
946
  const procedures = model.declarations.filter(import_ast3.isProcedure);
961
947
  if (procedures.length > 0) {
962
- properties.push(ts.factory.createPropertyAssignment("procedures", this.createProceduresObject(procedures)));
948
+ members.push(ts.factory.createPropertyDeclaration(void 0, "procedures", void 0, void 0, this.createAsConst(this.createProceduresObject(procedures))));
963
949
  }
964
- properties.push(ts.factory.createPropertyAssignment("plugins", ts.factory.createObjectLiteralExpression([], true)));
965
- return ts.factory.createObjectLiteralExpression(properties, true);
950
+ members.push(ts.factory.createPropertyDeclaration(void 0, "plugins", void 0, void 0, ts.factory.createObjectLiteralExpression([], true)));
951
+ const schemaClass = ts.factory.createClassDeclaration([
952
+ ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
953
+ ], "SchemaType", void 0, [
954
+ ts.factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
955
+ ts.factory.createExpressionWithTypeArguments(ts.factory.createIdentifier("SchemaDef"), void 0)
956
+ ])
957
+ ], members);
958
+ return schemaClass;
959
+ }
960
+ createAsConst(expr) {
961
+ return ts.factory.createAsExpression(expr, ts.factory.createTypeReferenceNode("const"));
966
962
  }
967
963
  createProviderObject(model) {
968
964
  const dsProvider = this.getDataSourceProvider(model);