@zenstackhq/sdk 3.0.0-beta.24 → 3.0.0-beta.26

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.d.cts CHANGED
@@ -139,6 +139,8 @@ declare class TsSchemaGenerator {
139
139
  private createSchemaObject;
140
140
  private createProviderObject;
141
141
  private createModelsObject;
142
+ private getAllDataModels;
143
+ private getAllTypeDefs;
142
144
  private createTypeDefsObject;
143
145
  private createDataModelObject;
144
146
  private getSubModels;
package/dist/index.d.ts CHANGED
@@ -139,6 +139,8 @@ declare class TsSchemaGenerator {
139
139
  private createSchemaObject;
140
140
  private createProviderObject;
141
141
  private createModelsObject;
142
+ private getAllDataModels;
143
+ private getAllTypeDefs;
142
144
  private createTypeDefsObject;
143
145
  private createDataModelObject;
144
146
  private getSubModels;
package/dist/index.js CHANGED
@@ -90,7 +90,7 @@ __name(resolved, "resolved");
90
90
  function getAuthDecl(model) {
91
91
  let found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
92
92
  if (!found) {
93
- found = model.declarations.find((d) => isDataModel(d) && d.name === "User");
93
+ found = model.declarations.find((d) => (isDataModel(d) || isTypeDef(d)) && d.name === "User");
94
94
  }
95
95
  return found;
96
96
  }
@@ -943,10 +943,16 @@ var TsSchemaGenerator = class {
943
943
  ], true);
944
944
  }
945
945
  createModelsObject(model, lite) {
946
- return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => isDataModel3(d) && !hasAttribute(d, "@@ignore")).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
946
+ return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
947
+ }
948
+ getAllDataModels(model) {
949
+ return model.declarations.filter((d) => isDataModel3(d) && !hasAttribute(d, "@@ignore"));
950
+ }
951
+ getAllTypeDefs(model) {
952
+ return model.declarations.filter((d) => isTypeDef3(d) && !hasAttribute(d, "@@ignore"));
947
953
  }
948
954
  createTypeDefsObject(model, lite) {
949
- return ts.factory.createObjectLiteralExpression(model.declarations.filter((d) => isTypeDef3(d)).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
955
+ return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
950
956
  }
951
957
  createDataModelObject(dm, lite) {
952
958
  const allFields = getAllFields3(dm);
@@ -1056,6 +1062,9 @@ var TsSchemaGenerator = class {
1056
1062
  if (hasAttribute(field, "@updatedAt")) {
1057
1063
  objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
1058
1064
  }
1065
+ if (hasAttribute(field, "@omit")) {
1066
+ objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
1067
+ }
1059
1068
  if (contextModel && // id fields are duplicated in inherited models
1060
1069
  !isIdField(field, contextModel) && field.$container !== contextModel && isDelegateModel(field.$container)) {
1061
1070
  objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(field.$container.name)));
@@ -1511,7 +1520,7 @@ var TsSchemaGenerator = class {
1511
1520
  ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
1512
1521
  ] : []
1513
1522
  ])), ts.factory.createStringLiteral("@zenstackhq/orm")));
1514
- const dataModels = model.declarations.filter(isDataModel3);
1523
+ const dataModels = this.getAllDataModels(model);
1515
1524
  for (const dm of dataModels) {
1516
1525
  let modelType = ts.factory.createTypeAliasDeclaration([
1517
1526
  ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
@@ -1524,7 +1533,7 @@ var TsSchemaGenerator = class {
1524
1533
  }
1525
1534
  statements.push(modelType);
1526
1535
  }
1527
- const typeDefs = model.declarations.filter(isTypeDef3);
1536
+ const typeDefs = this.getAllTypeDefs(model);
1528
1537
  for (const td of typeDefs) {
1529
1538
  let typeDef = ts.factory.createTypeAliasDeclaration([
1530
1539
  ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
@@ -1585,7 +1594,7 @@ var TsSchemaGenerator = class {
1585
1594
  `, true);
1586
1595
  }
1587
1596
  generateInputTypes(model, options) {
1588
- const dataModels = model.declarations.filter(isDataModel3);
1597
+ const dataModels = this.getAllDataModels(model);
1589
1598
  const statements = [];
1590
1599
  statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
1591
1600
  const inputTypes = [
@@ -1614,7 +1623,10 @@ var TsSchemaGenerator = class {
1614
1623
  IncludeInput: "Include",
1615
1624
  OmitInput: "Omit"
1616
1625
  };
1617
- statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports(inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))))), ts.factory.createStringLiteral("@zenstackhq/orm")));
1626
+ statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
1627
+ ...inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))),
1628
+ ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ClientOptions as $ClientOptions"))
1629
+ ])), ts.factory.createStringLiteral("@zenstackhq/orm")));
1618
1630
  statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
1619
1631
  ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedModelResult as $SimplifiedModelResult")),
1620
1632
  ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
@@ -1636,10 +1648,16 @@ var TsSchemaGenerator = class {
1636
1648
  ts.factory.createTypeReferenceNode("$Schema"),
1637
1649
  ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
1638
1650
  ts.factory.createLiteralTypeNode(ts.factory.createTrue())
1651
+ ])),
1652
+ ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$ClientOptions", [
1653
+ ts.factory.createTypeReferenceNode("$Schema")
1654
+ ]), ts.factory.createTypeReferenceNode("$ClientOptions", [
1655
+ ts.factory.createTypeReferenceNode("$Schema")
1639
1656
  ]))
1640
1657
  ], ts.factory.createTypeReferenceNode("$SimplifiedModelResult", [
1641
1658
  ts.factory.createTypeReferenceNode("$Schema"),
1642
1659
  ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
1660
+ ts.factory.createTypeReferenceNode("Options"),
1643
1661
  ts.factory.createTypeReferenceNode("Args")
1644
1662
  ])));
1645
1663
  }