@zenstackhq/sdk 3.0.0-beta.21 → 3.0.0-beta.23

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.d.cts CHANGED
@@ -99,6 +99,7 @@ declare class PrismaSchemaGenerator {
99
99
  private configInvocationArgToText;
100
100
  private literalToText;
101
101
  private generateGenerator;
102
+ private generateDefaultGenerator;
102
103
  private generateModel;
103
104
  private getDatasourceField;
104
105
  private datasourceHasSchemasSetting;
package/dist/index.d.ts CHANGED
@@ -99,6 +99,7 @@ declare class PrismaSchemaGenerator {
99
99
  private configInvocationArgToText;
100
100
  private literalToText;
101
101
  private generateGenerator;
102
+ private generateDefaultGenerator;
102
103
  private generateModel;
103
104
  private getDatasourceField;
104
105
  private datasourceHasSchemasSetting;
package/dist/index.js CHANGED
@@ -104,7 +104,7 @@ var DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
104
104
  // src/prisma/prisma-schema-generator.ts
105
105
  import { lowerCaseFirst } from "@zenstackhq/common-helpers";
106
106
  import { ZModelCodeGenerator } from "@zenstackhq/language";
107
- import { BooleanLiteral, DataModel, DataSource as DataSource2, Enum as Enum2, GeneratorDecl, isArrayExpr, isDataModel as isDataModel2, isDataSource, isInvocationExpr, isLiteralExpr as isLiteralExpr2, isNullExpr, isReferenceExpr, isStringLiteral, isTypeDef as isTypeDef2, NumberLiteral, StringLiteral } from "@zenstackhq/language/ast";
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
108
  import { getAllAttributes, getAllFields as getAllFields2, getStringLiteral, isAuthInvocation, isDelegateModel as isDelegateModel2 } from "@zenstackhq/language/utils";
109
109
  import { AstUtils } from "langium";
110
110
  import { match } from "ts-pattern";
@@ -538,6 +538,9 @@ var PrismaSchemaGenerator = class {
538
538
  break;
539
539
  }
540
540
  }
541
+ if (!this.zmodel.declarations.some(isGeneratorDecl)) {
542
+ this.generateDefaultGenerator(prisma);
543
+ }
541
544
  return this.PRELUDE + prisma.toString();
542
545
  }
543
546
  generateDataSource(prisma, dataSource) {
@@ -578,6 +581,21 @@ var PrismaSchemaGenerator = class {
578
581
  text: this.configExprToText(f.value)
579
582
  })));
580
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
+ }
581
599
  generateModel(prisma, decl) {
582
600
  const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
583
601
  const allFields = getAllFields2(decl, true);
@@ -728,9 +746,15 @@ var PrismaSchemaGenerator = class {
728
746
  for (const field of decl.fields) {
729
747
  this.generateEnumField(_enum, field);
730
748
  }
731
- for (const attr of decl.attributes.filter((attr2) => this.isPrismaAttribute(attr2))) {
749
+ const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
750
+ for (const attr of allAttributes) {
732
751
  this.generateContainerAttribute(_enum, attr);
733
752
  }
753
+ if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
754
+ _enum.addAttribute("@@schema", [
755
+ new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
756
+ ]);
757
+ }
734
758
  decl.comments.forEach((c) => _enum.addComment(c));
735
759
  }
736
760
  generateEnumField(_enum, field) {
@@ -856,16 +880,27 @@ var TsSchemaGenerator = class {
856
880
  ] : []
857
881
  ])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
858
882
  statements.push(runtimeImportDecl);
859
- const declaration = ts.factory.createVariableStatement([
883
+ const _schemaDecl = ts.factory.createVariableStatement([], ts.factory.createVariableDeclarationList([
884
+ ts.factory.createVariableDeclaration("_schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(schemaObject, ts.factory.createTypeReferenceNode("const")), ts.factory.createTypeReferenceNode("SchemaDef")))
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([
860
895
  ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
861
896
  ], ts.factory.createVariableDeclarationList([
862
- ts.factory.createVariableDeclaration("schema", void 0, void 0, ts.factory.createSatisfiesExpression(ts.factory.createAsExpression(schemaObject, ts.factory.createTypeReferenceNode("const")), ts.factory.createTypeReferenceNode("SchemaDef")))
897
+ ts.factory.createVariableDeclaration("schema", void 0, ts.factory.createTypeReferenceNode("Schema"), ts.factory.createIdentifier("_schema"))
863
898
  ], ts.NodeFlags.Const));
864
- statements.push(declaration);
865
- const typeDeclaration = ts.factory.createTypeAliasDeclaration([
899
+ statements.push(schemaExportDecl);
900
+ const schemaTypeDeclaration = ts.factory.createTypeAliasDeclaration([
866
901
  ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
867
- ], "SchemaType", void 0, ts.factory.createTypeReferenceNode("typeof schema"));
868
- statements.push(typeDeclaration);
902
+ ], "SchemaType", void 0, ts.factory.createTypeReferenceNode("Schema"));
903
+ statements.push(schemaTypeDeclaration);
869
904
  }
870
905
  createExpressionUtilsCall(method, args) {
871
906
  this.usedExpressionUtils = true;