@zenstackhq/sdk 3.3.0-beta.2 → 3.3.0-beta.4

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.js CHANGED
@@ -815,7 +815,7 @@ var PrismaSchemaGenerator = class {
815
815
 
816
816
  // src/ts-schema-generator.ts
817
817
  import { invariant } from "@zenstackhq/common-helpers";
818
- import { isArrayExpr as isArrayExpr2, isBinaryExpr, isDataField, isDataModel as isDataModel3, isDataSource as isDataSource2, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as isTypeDef3, isUnaryExpr } from "@zenstackhq/language/ast";
818
+ import { isArrayExpr as isArrayExpr2, isBinaryExpr, isCollectionPredicateBinding, isDataField, isDataModel as isDataModel3, isDataSource as isDataSource2, isEnum, isEnumField, isInvocationExpr as isInvocationExpr2, isLiteralExpr as isLiteralExpr3, isMemberAccessExpr, isNullExpr as isNullExpr2, isProcedure, isReferenceExpr as isReferenceExpr2, isThisExpr, isTypeDef as isTypeDef3, isUnaryExpr } from "@zenstackhq/language/ast";
819
819
  import { getAllAttributes as getAllAttributes2, getAllFields as getAllFields3, getAttributeArg, isDataFieldReference } from "@zenstackhq/language/utils";
820
820
  import fs from "fs";
821
821
  import path from "path";
@@ -1339,6 +1339,7 @@ var TsSchemaGenerator = class {
1339
1339
  }
1340
1340
  createEnumObject(e) {
1341
1341
  return ts.factory.createObjectLiteralExpression([
1342
+ ts.factory.createPropertyAssignment("name", ts.factory.createStringLiteral(e.name)),
1342
1343
  ts.factory.createPropertyAssignment("values", ts.factory.createObjectLiteralExpression(e.fields.map((f) => ts.factory.createPropertyAssignment(f.name, ts.factory.createStringLiteral(f.name))), true)),
1343
1344
  // only generate `fields` if there are attributes on the fields
1344
1345
  ...e.fields.some((f) => f.attributes.length > 0) ? [
@@ -1454,11 +1455,15 @@ var TsSchemaGenerator = class {
1454
1455
  return this.createExpressionUtilsCall("_null");
1455
1456
  }
1456
1457
  createBinaryExpression(expr) {
1457
- return this.createExpressionUtilsCall("binary", [
1458
+ const args = [
1458
1459
  this.createExpression(expr.left),
1459
1460
  this.createLiteralNode(expr.operator),
1460
1461
  this.createExpression(expr.right)
1461
- ]);
1462
+ ];
1463
+ if (expr.binding) {
1464
+ args.push(this.createLiteralNode(expr.binding.name));
1465
+ }
1466
+ return this.createExpressionUtilsCall("binary", args);
1462
1467
  }
1463
1468
  createUnaryExpression(expr) {
1464
1469
  return this.createExpressionUtilsCall("unary", [
@@ -1467,20 +1472,23 @@ var TsSchemaGenerator = class {
1467
1472
  ]);
1468
1473
  }
1469
1474
  createArrayExpression(expr) {
1475
+ const arrayResolved = expr.$resolvedType?.decl;
1476
+ const arrayType = typeof arrayResolved === "string" ? arrayResolved : arrayResolved?.name;
1477
+ invariant(arrayType, "Array type must be resolved to a string or declaration");
1470
1478
  return this.createExpressionUtilsCall("array", [
1479
+ this.createLiteralNode(arrayType),
1471
1480
  ts.factory.createArrayLiteralExpression(expr.items.map((item) => this.createExpression(item)))
1472
1481
  ]);
1473
1482
  }
1474
1483
  createRefExpression(expr) {
1475
- if (isDataField(expr.target.ref)) {
1476
- return this.createExpressionUtilsCall("field", [
1477
- this.createLiteralNode(expr.target.$refText)
1478
- ]);
1479
- } else if (isEnumField(expr.target.ref)) {
1480
- return this.createLiteralExpression("StringLiteral", expr.target.$refText);
1481
- } else {
1482
- throw new Error(`Unsupported reference type: ${expr.target.$refText}`);
1483
- }
1484
+ const target = expr.target.ref;
1485
+ return match2(target).when(isDataField, () => this.createExpressionUtilsCall("field", [
1486
+ this.createLiteralNode(expr.target.$refText)
1487
+ ])).when(isEnumField, () => this.createLiteralExpression("StringLiteral", expr.target.$refText)).when(isCollectionPredicateBinding, () => this.createExpressionUtilsCall("binding", [
1488
+ this.createLiteralNode(expr.target.$refText)
1489
+ ])).otherwise(() => {
1490
+ throw Error(`Unsupported reference type: ${expr.target.$refText}`);
1491
+ });
1484
1492
  }
1485
1493
  createCallExpression(expr) {
1486
1494
  return this.createExpressionUtilsCall("call", [