@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.cjs +42 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -570,6 +570,9 @@ var PrismaSchemaGenerator = class {
|
|
|
570
570
|
break;
|
|
571
571
|
}
|
|
572
572
|
}
|
|
573
|
+
if (!this.zmodel.declarations.some(import_ast2.isGeneratorDecl)) {
|
|
574
|
+
this.generateDefaultGenerator(prisma);
|
|
575
|
+
}
|
|
573
576
|
return this.PRELUDE + prisma.toString();
|
|
574
577
|
}
|
|
575
578
|
generateDataSource(prisma, dataSource) {
|
|
@@ -610,6 +613,21 @@ var PrismaSchemaGenerator = class {
|
|
|
610
613
|
text: this.configExprToText(f.value)
|
|
611
614
|
})));
|
|
612
615
|
}
|
|
616
|
+
generateDefaultGenerator(prisma) {
|
|
617
|
+
const gen = prisma.addGenerator("client", [
|
|
618
|
+
{
|
|
619
|
+
name: "provider",
|
|
620
|
+
text: '"prisma-client-js"'
|
|
621
|
+
}
|
|
622
|
+
]);
|
|
623
|
+
const dataSource = this.zmodel.declarations.find(import_ast2.isDataSource);
|
|
624
|
+
if (dataSource?.fields.some((f) => f.name === "extensions")) {
|
|
625
|
+
gen.fields.push({
|
|
626
|
+
name: "previewFeatures",
|
|
627
|
+
text: '["postgresqlExtensions"]'
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
613
631
|
generateModel(prisma, decl) {
|
|
614
632
|
const model = decl.isView ? prisma.addView(decl.name) : prisma.addModel(decl.name);
|
|
615
633
|
const allFields = (0, import_utils2.getAllFields)(decl, true);
|
|
@@ -760,9 +778,15 @@ var PrismaSchemaGenerator = class {
|
|
|
760
778
|
for (const field of decl.fields) {
|
|
761
779
|
this.generateEnumField(_enum, field);
|
|
762
780
|
}
|
|
763
|
-
|
|
781
|
+
const allAttributes = decl.attributes.filter((attr) => this.isPrismaAttribute(attr));
|
|
782
|
+
for (const attr of allAttributes) {
|
|
764
783
|
this.generateContainerAttribute(_enum, attr);
|
|
765
784
|
}
|
|
785
|
+
if (this.datasourceHasSchemasSetting(decl.$container) && !allAttributes.some((attr) => attr.decl.ref?.name === "@@schema")) {
|
|
786
|
+
_enum.addAttribute("@@schema", [
|
|
787
|
+
new AttributeArg(void 0, new AttributeArgValue("String", this.getDefaultPostgresSchemaName(decl.$container)))
|
|
788
|
+
]);
|
|
789
|
+
}
|
|
766
790
|
decl.comments.forEach((c) => _enum.addComment(c));
|
|
767
791
|
}
|
|
768
792
|
generateEnumField(_enum, field) {
|
|
@@ -888,16 +912,27 @@ var TsSchemaGenerator = class {
|
|
|
888
912
|
] : []
|
|
889
913
|
])), ts.factory.createStringLiteral("@zenstackhq/orm/schema"));
|
|
890
914
|
statements.push(runtimeImportDecl);
|
|
891
|
-
const
|
|
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([
|
|
892
927
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
893
928
|
], ts.factory.createVariableDeclarationList([
|
|
894
|
-
ts.factory.createVariableDeclaration("schema", void 0,
|
|
929
|
+
ts.factory.createVariableDeclaration("schema", void 0, ts.factory.createTypeReferenceNode("Schema"), ts.factory.createIdentifier("_schema"))
|
|
895
930
|
], ts.NodeFlags.Const));
|
|
896
|
-
statements.push(
|
|
897
|
-
const
|
|
931
|
+
statements.push(schemaExportDecl);
|
|
932
|
+
const schemaTypeDeclaration = ts.factory.createTypeAliasDeclaration([
|
|
898
933
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
899
|
-
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("
|
|
900
|
-
statements.push(
|
|
934
|
+
], "SchemaType", void 0, ts.factory.createTypeReferenceNode("Schema"));
|
|
935
|
+
statements.push(schemaTypeDeclaration);
|
|
901
936
|
}
|
|
902
937
|
createExpressionUtilsCall(method, args) {
|
|
903
938
|
this.usedExpressionUtils = true;
|