@zenstackhq/sdk 3.9.1 → 3.9.3
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 +6 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
2
|
import { BooleanLiteral, DataModel, DataSource, Enum, GeneratorDecl, NumberLiteral, StringLiteral, isArrayExpr, isBinaryExpr, isCollectionPredicateBinding, isDataField, isDataModel, isDataSource, isEnum, isEnumField, isGeneratorDecl, isInvocationExpr, isLiteralExpr, isMemberAccessExpr, isModel, isNullExpr, isProcedure, isReferenceExpr, isStringLiteral, isThisExpr, isTypeDef, isUnaryExpr } from "@zenstackhq/language/ast";
|
|
3
|
-
import { getAllAttributes, getAllFields, getAttributeArg, getModelIdFields, getModelUniqueFields, getStringLiteral, isAuthInvocation, isDataFieldReference, isDelegateModel } from "@zenstackhq/language/utils";
|
|
3
|
+
import { getAllAttributes, getAllFields, getAttributeArg, getModelIdFields, getModelUniqueFields, getStringLiteral, isAuthInvocation, isDataFieldReference, isDelegateModel, isLiteAttribute } from "@zenstackhq/language/utils";
|
|
4
4
|
import { invariant, lowerCaseFirst } from "@zenstackhq/common-helpers";
|
|
5
5
|
import { ZModelCodeGenerator } from "@zenstackhq/language";
|
|
6
6
|
import { AstUtils } from "langium";
|
|
@@ -708,7 +708,7 @@ var TsSchemaGenerator = class {
|
|
|
708
708
|
}
|
|
709
709
|
createDataModelObject(dm, lite) {
|
|
710
710
|
const allFields = getAllFields(dm);
|
|
711
|
-
const allAttributes = lite ?
|
|
711
|
+
const allAttributes = lite ? getAllAttributes(dm).filter((attr) => isLiteAttribute(attr.decl.ref)) : getAllAttributes(dm).filter((attr) => {
|
|
712
712
|
if (attr.decl.$refText === "@@delegate" && attr.$container !== dm) return false;
|
|
713
713
|
return true;
|
|
714
714
|
});
|
|
@@ -749,12 +749,13 @@ var TsSchemaGenerator = class {
|
|
|
749
749
|
}
|
|
750
750
|
createTypeDefObject(td, lite) {
|
|
751
751
|
const allFields = getAllFields(td);
|
|
752
|
-
const
|
|
752
|
+
const attributes = lite ? getAllAttributes(td).filter((attr) => isLiteAttribute(attr.decl.ref)) : getAllAttributes(td);
|
|
753
753
|
const fields = [
|
|
754
754
|
ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(td.name)),
|
|
755
755
|
ts.factory.createPropertyAssignment("fields", ts.factory.createObjectLiteralExpression(allFields.map((field) => ts.factory.createPropertyAssignment(field.name, this.createDataFieldObject(field, void 0, lite))), true)),
|
|
756
|
-
...
|
|
756
|
+
...attributes.length > 0 ? [ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(attributes.map((attr) => this.createAttributeObject(attr)), true)))] : []
|
|
757
757
|
];
|
|
758
|
+
if (getAllAttributes(td).some((attr) => attr.decl.$refText === "@@strict")) fields.push(ts.factory.createPropertyAssignment("strict", ts.factory.createTrue()));
|
|
758
759
|
return ts.factory.createObjectLiteralExpression(fields, true);
|
|
759
760
|
}
|
|
760
761
|
createComputedFieldsObject(fields) {
|
|
@@ -805,7 +806,8 @@ var TsSchemaGenerator = class {
|
|
|
805
806
|
if (delegateOrigin) objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(delegateOrigin)));
|
|
806
807
|
}
|
|
807
808
|
if (this.isDiscriminatorField(field)) objectFields.push(ts.factory.createPropertyAssignment("isDiscriminator", ts.factory.createTrue()));
|
|
808
|
-
|
|
809
|
+
const attributes = lite ? field.attributes.filter((attr) => isLiteAttribute(attr.decl.ref)) : field.attributes;
|
|
810
|
+
if (attributes.length > 0) objectFields.push(ts.factory.createPropertyAssignment("attributes", this.createAttributesTypeAssertion(ts.factory.createArrayLiteralExpression(attributes.map((attr) => this.createAttributeObject(attr))))));
|
|
809
811
|
const defaultValue = this.getFieldMappedDefault(field);
|
|
810
812
|
if (defaultValue !== void 0) {
|
|
811
813
|
let defaultExpr;
|