@zenstackhq/sdk 3.0.0-alpha.3 → 3.0.0-alpha.6
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 +27 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +22 -14
- package/dist/index.js.map +1 -1
- package/package.json +9 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _zenstackhq_language_ast from '@zenstackhq/language/ast';
|
|
2
2
|
import { DataModelField, DataModel, TypeDef, Enum, EnumField, FunctionDecl, Attribute, AttributeParam, TypeDefField, DataModelFieldAttribute, DataModelAttribute, AstNode, Model, Reference, InvocationExpr } from '@zenstackhq/language/ast';
|
|
3
|
+
import { MaybePromise } from 'langium';
|
|
3
4
|
|
|
4
5
|
declare function isIdField(field: DataModelField): boolean;
|
|
5
6
|
declare function hasAttribute(decl: DataModel | TypeDef | DataModelField | Enum | EnumField | FunctionDecl | Attribute | AttributeParam, name: string): boolean;
|
|
@@ -36,6 +37,13 @@ declare namespace modelUtils {
|
|
|
36
37
|
export { modelUtils_getAttribute as getAttribute, modelUtils_getAuthDecl as getAuthDecl, modelUtils_getContainingModel as getContainingModel, modelUtils_getModelIdFields as getModelIdFields, modelUtils_getModelUniqueFields as getModelUniqueFields, modelUtils_getRecursiveBases as getRecursiveBases, modelUtils_hasAttribute as hasAttribute, modelUtils_isDelegateModel as isDelegateModel, modelUtils_isFromStdlib as isFromStdlib, modelUtils_isIdField as isIdField, modelUtils_isUniqueField as isUniqueField, modelUtils_resolved as resolved };
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
type CliGeneratorContext = {
|
|
41
|
+
model: Model;
|
|
42
|
+
outputPath: string;
|
|
43
|
+
tsSchemaFile: string;
|
|
44
|
+
};
|
|
45
|
+
type CliGenerator = (context: CliGeneratorContext) => MaybePromise<void>;
|
|
46
|
+
|
|
39
47
|
declare class FunctionCall {
|
|
40
48
|
func: string;
|
|
41
49
|
args: FunctionCallArg[];
|
|
@@ -92,7 +100,7 @@ declare class TsSchemaGenerator {
|
|
|
92
100
|
private createModelsObject;
|
|
93
101
|
private createDataModelObject;
|
|
94
102
|
private createComputedFieldsObject;
|
|
95
|
-
private
|
|
103
|
+
private mapFieldTypeToTSType;
|
|
96
104
|
private createDataModelFieldObject;
|
|
97
105
|
private getDataSourceProvider;
|
|
98
106
|
private getMappedDefault;
|
|
@@ -192,4 +200,4 @@ declare class ZModelCodeGenerator {
|
|
|
192
200
|
private isCollectionPredicateOperator;
|
|
193
201
|
}
|
|
194
202
|
|
|
195
|
-
export { modelUtils as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, ZModelCodeGenerator, type ZModelCodeOptions };
|
|
203
|
+
export { type CliGenerator, type CliGeneratorContext, modelUtils as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, ZModelCodeGenerator, type ZModelCodeOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _zenstackhq_language_ast from '@zenstackhq/language/ast';
|
|
2
2
|
import { DataModelField, DataModel, TypeDef, Enum, EnumField, FunctionDecl, Attribute, AttributeParam, TypeDefField, DataModelFieldAttribute, DataModelAttribute, AstNode, Model, Reference, InvocationExpr } from '@zenstackhq/language/ast';
|
|
3
|
+
import { MaybePromise } from 'langium';
|
|
3
4
|
|
|
4
5
|
declare function isIdField(field: DataModelField): boolean;
|
|
5
6
|
declare function hasAttribute(decl: DataModel | TypeDef | DataModelField | Enum | EnumField | FunctionDecl | Attribute | AttributeParam, name: string): boolean;
|
|
@@ -36,6 +37,13 @@ declare namespace modelUtils {
|
|
|
36
37
|
export { modelUtils_getAttribute as getAttribute, modelUtils_getAuthDecl as getAuthDecl, modelUtils_getContainingModel as getContainingModel, modelUtils_getModelIdFields as getModelIdFields, modelUtils_getModelUniqueFields as getModelUniqueFields, modelUtils_getRecursiveBases as getRecursiveBases, modelUtils_hasAttribute as hasAttribute, modelUtils_isDelegateModel as isDelegateModel, modelUtils_isFromStdlib as isFromStdlib, modelUtils_isIdField as isIdField, modelUtils_isUniqueField as isUniqueField, modelUtils_resolved as resolved };
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
type CliGeneratorContext = {
|
|
41
|
+
model: Model;
|
|
42
|
+
outputPath: string;
|
|
43
|
+
tsSchemaFile: string;
|
|
44
|
+
};
|
|
45
|
+
type CliGenerator = (context: CliGeneratorContext) => MaybePromise<void>;
|
|
46
|
+
|
|
39
47
|
declare class FunctionCall {
|
|
40
48
|
func: string;
|
|
41
49
|
args: FunctionCallArg[];
|
|
@@ -92,7 +100,7 @@ declare class TsSchemaGenerator {
|
|
|
92
100
|
private createModelsObject;
|
|
93
101
|
private createDataModelObject;
|
|
94
102
|
private createComputedFieldsObject;
|
|
95
|
-
private
|
|
103
|
+
private mapFieldTypeToTSType;
|
|
96
104
|
private createDataModelFieldObject;
|
|
97
105
|
private getDataSourceProvider;
|
|
98
106
|
private getMappedDefault;
|
|
@@ -192,4 +200,4 @@ declare class ZModelCodeGenerator {
|
|
|
192
200
|
private isCollectionPredicateOperator;
|
|
193
201
|
}
|
|
194
202
|
|
|
195
|
-
export { modelUtils as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, ZModelCodeGenerator, type ZModelCodeOptions };
|
|
203
|
+
export { type CliGenerator, type CliGeneratorContext, modelUtils as ModelUtils, PrismaSchemaGenerator, TsSchemaGenerator, ZModelCodeGenerator, type ZModelCodeOptions };
|
package/dist/index.js
CHANGED
|
@@ -285,9 +285,9 @@ var Model = class extends ContainerDeclaration {
|
|
|
285
285
|
}
|
|
286
286
|
name;
|
|
287
287
|
isView;
|
|
288
|
-
fields;
|
|
288
|
+
fields = [];
|
|
289
289
|
constructor(name, isView, documentations = []) {
|
|
290
|
-
super(documentations), this.name = name, this.isView = isView
|
|
290
|
+
super(documentations), this.name = name, this.isView = isView;
|
|
291
291
|
}
|
|
292
292
|
addField(name, type, attributes = [], documentations = [], addToFront = false) {
|
|
293
293
|
const field = new ModelField(name, type, attributes, documentations);
|
|
@@ -507,9 +507,9 @@ var Enum = class extends ContainerDeclaration {
|
|
|
507
507
|
__name(this, "Enum");
|
|
508
508
|
}
|
|
509
509
|
name;
|
|
510
|
-
fields;
|
|
510
|
+
fields = [];
|
|
511
511
|
constructor(name, documentations = []) {
|
|
512
|
-
super(documentations), this.name = name
|
|
512
|
+
super(documentations), this.name = name;
|
|
513
513
|
}
|
|
514
514
|
addField(name, attributes = [], documentations = []) {
|
|
515
515
|
const field = new EnumField(name, attributes, documentations);
|
|
@@ -558,15 +558,14 @@ var PrismaSchemaGenerator = class {
|
|
|
558
558
|
__name(this, "PrismaSchemaGenerator");
|
|
559
559
|
}
|
|
560
560
|
zmodel;
|
|
561
|
-
PRELUDE
|
|
562
|
-
constructor(zmodel) {
|
|
563
|
-
this.zmodel = zmodel;
|
|
564
|
-
this.PRELUDE = `//////////////////////////////////////////////////////////////////////////////////////////////
|
|
561
|
+
PRELUDE = `//////////////////////////////////////////////////////////////////////////////////////////////
|
|
565
562
|
// DO NOT MODIFY THIS FILE //
|
|
566
563
|
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
|
|
567
564
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
568
565
|
|
|
569
566
|
`;
|
|
567
|
+
constructor(zmodel) {
|
|
568
|
+
this.zmodel = zmodel;
|
|
570
569
|
}
|
|
571
570
|
async generate() {
|
|
572
571
|
const prisma = new PrismaModel();
|
|
@@ -777,11 +776,11 @@ var PrismaSchemaGenerator = class {
|
|
|
777
776
|
};
|
|
778
777
|
|
|
779
778
|
// src/ts-schema-generator.ts
|
|
779
|
+
import { invariant } from "@zenstackhq/common-helpers";
|
|
780
780
|
import { loadDocument } from "@zenstackhq/language";
|
|
781
781
|
import { isArrayExpr as isArrayExpr3, isBinaryExpr, isDataModel as isDataModel2, isDataModelField, isDataSource, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr3, isThisExpr, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
782
|
-
import fs from "
|
|
783
|
-
import path from "
|
|
784
|
-
import invariant from "tiny-invariant";
|
|
782
|
+
import fs from "fs";
|
|
783
|
+
import path from "path";
|
|
785
784
|
import { match as match2 } from "ts-pattern";
|
|
786
785
|
import * as ts from "typescript";
|
|
787
786
|
var TsSchemaGenerator = class {
|
|
@@ -882,15 +881,22 @@ var TsSchemaGenerator = class {
|
|
|
882
881
|
}
|
|
883
882
|
createComputedFieldsObject(fields) {
|
|
884
883
|
return ts.factory.createObjectLiteralExpression(fields.map((field) => ts.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, [], ts.factory.createTypeReferenceNode("OperandExpression", [
|
|
885
|
-
ts.factory.
|
|
884
|
+
ts.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type))
|
|
886
885
|
]), ts.factory.createBlock([
|
|
887
886
|
ts.factory.createThrowStatement(ts.factory.createNewExpression(ts.factory.createIdentifier("Error"), void 0, [
|
|
888
887
|
ts.factory.createStringLiteral("This is a stub for computed field")
|
|
889
888
|
]))
|
|
890
889
|
], true))), true);
|
|
891
890
|
}
|
|
892
|
-
|
|
893
|
-
|
|
891
|
+
mapFieldTypeToTSType(type) {
|
|
892
|
+
let result = match2(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").otherwise(() => "unknown");
|
|
893
|
+
if (type.array) {
|
|
894
|
+
result = `${result}[]`;
|
|
895
|
+
}
|
|
896
|
+
if (type.optional) {
|
|
897
|
+
result = `${result} | null`;
|
|
898
|
+
}
|
|
899
|
+
return result;
|
|
894
900
|
}
|
|
895
901
|
createDataModelFieldObject(field) {
|
|
896
902
|
const objectFields = [
|
|
@@ -1197,6 +1203,8 @@ var TsSchemaGenerator = class {
|
|
|
1197
1203
|
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
|
|
1198
1204
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
1199
1205
|
|
|
1206
|
+
/* eslint-disable */
|
|
1207
|
+
|
|
1200
1208
|
`;
|
|
1201
1209
|
ts.addSyntheticLeadingComment(statements[0], ts.SyntaxKind.SingleLineCommentTrivia, banner);
|
|
1202
1210
|
}
|