@zenstackhq/sdk 3.9.4-beta.1 → 3.9.5
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 +0 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -3
- package/dist/index.d.mts +0 -3
- package/dist/index.mjs +0 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -763,8 +763,6 @@ var TsSchemaGenerator = class {
|
|
|
763
763
|
...subModels.length > 0 ? [typescript.factory.createPropertyAssignment("subModels", typescript.factory.createArrayLiteralExpression(subModels.map((subModel) => typescript.factory.createStringLiteral(subModel))))] : [],
|
|
764
764
|
...dm.isView ? [typescript.factory.createPropertyAssignment("isView", typescript.factory.createTrue())] : []
|
|
765
765
|
];
|
|
766
|
-
const computedFields = allFields.filter((f) => hasAttribute(f, "@computed") && !getDelegateOriginModel(f, dm));
|
|
767
|
-
if (computedFields.length > 0) fields.push(typescript.factory.createPropertyAssignment("computedFields", this.createComputedFieldsObject(computedFields)));
|
|
768
766
|
return typescript.factory.createObjectLiteralExpression(fields, true);
|
|
769
767
|
}
|
|
770
768
|
getDelegateMapValue(dm) {
|
|
@@ -792,13 +790,6 @@ var TsSchemaGenerator = class {
|
|
|
792
790
|
if ((0, _zenstackhq_language_utils.getAllAttributes)(td).some((attr) => attr.decl.$refText === "@@strict")) fields.push(typescript.factory.createPropertyAssignment("strict", typescript.factory.createTrue()));
|
|
793
791
|
return typescript.factory.createObjectLiteralExpression(fields, true);
|
|
794
792
|
}
|
|
795
|
-
createComputedFieldsObject(fields) {
|
|
796
|
-
return typescript.factory.createObjectLiteralExpression(fields.map((field) => {
|
|
797
|
-
const params = [typescript.factory.createParameterDeclaration(void 0, void 0, "_context", void 0, typescript.factory.createTypeLiteralNode([typescript.factory.createPropertySignature(void 0, "modelAlias", void 0, typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword))]), void 0)];
|
|
798
|
-
if (field.params.length > 0) params.push(typescript.factory.createParameterDeclaration(void 0, void 0, "args", void 0, typescript.factory.createTypeLiteralNode(field.params.map((param) => typescript.factory.createPropertySignature(void 0, param.name, param.optional ? typescript.factory.createToken(typescript.SyntaxKind.QuestionToken) : void 0, typescript.factory.createTypeReferenceNode(this.mapFunctionParamTypeToTSType(param.type))))), void 0));
|
|
799
|
-
return typescript.factory.createMethodDeclaration(void 0, void 0, field.name, void 0, void 0, params, typescript.factory.createTypeReferenceNode(this.mapFieldTypeToTSType(field.type)), typescript.factory.createBlock([typescript.factory.createThrowStatement(typescript.factory.createNewExpression(typescript.factory.createIdentifier("Error"), void 0, [typescript.factory.createStringLiteral("This is a stub for computed field")]))], true));
|
|
800
|
-
}), true);
|
|
801
|
-
}
|
|
802
793
|
createFieldParamsObject(params) {
|
|
803
794
|
return typescript.factory.createObjectLiteralExpression(params.map((param) => typescript.factory.createPropertyAssignment(param.name, typescript.factory.createObjectLiteralExpression([
|
|
804
795
|
typescript.factory.createPropertyAssignment("name", typescript.factory.createStringLiteral(param.name)),
|
|
@@ -807,20 +798,9 @@ var TsSchemaGenerator = class {
|
|
|
807
798
|
typescript.factory.createPropertyAssignment("type", typescript.factory.createStringLiteral(param.type.type ?? param.type.reference.$refText))
|
|
808
799
|
]))), true);
|
|
809
800
|
}
|
|
810
|
-
mapFunctionParamTypeToTSType(type) {
|
|
811
|
-
let result = (0, ts_pattern.match)(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").with("DateTime", () => "Date").otherwise(() => "unknown");
|
|
812
|
-
if (type.array) result = `${result}[]`;
|
|
813
|
-
return result;
|
|
814
|
-
}
|
|
815
801
|
createUpdatedAtObject(ignoreArg) {
|
|
816
802
|
return typescript.factory.createObjectLiteralExpression([typescript.factory.createPropertyAssignment("ignore", typescript.factory.createArrayLiteralExpression(ignoreArg.value.items.map((item) => typescript.factory.createStringLiteral(item.target.$refText))))]);
|
|
817
803
|
}
|
|
818
|
-
mapFieldTypeToTSType(type) {
|
|
819
|
-
let result = (0, ts_pattern.match)(type.type).with("String", () => "string").with("Boolean", () => "boolean").with("Int", () => "number").with("Float", () => "number").with("BigInt", () => "bigint").with("Decimal", () => "number").otherwise(() => "unknown");
|
|
820
|
-
if (type.array) result = `${result}[]`;
|
|
821
|
-
if (type.optional) result = `${result} | null`;
|
|
822
|
-
return result;
|
|
823
|
-
}
|
|
824
804
|
createDataFieldObject(field, contextModel, lite) {
|
|
825
805
|
const objectFields = [typescript.factory.createPropertyAssignment("name", typescript.factory.createStringLiteral(field.name)), typescript.factory.createPropertyAssignment("type", this.generateFieldTypeLiteral(field))];
|
|
826
806
|
if (contextModel && isIdField(field, contextModel)) objectFields.push(typescript.factory.createPropertyAssignment("id", typescript.factory.createTrue()));
|