@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.cjs +25 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -122,7 +122,7 @@ __name(resolved, "resolved");
|
|
|
122
122
|
function getAuthDecl(model) {
|
|
123
123
|
let found = model.declarations.find((d) => ((0, import_ast.isDataModel)(d) || (0, import_ast.isTypeDef)(d)) && d.attributes.some((attr) => attr.decl.$refText === "@@auth"));
|
|
124
124
|
if (!found) {
|
|
125
|
-
found = model.declarations.find((d) => (0, import_ast.isDataModel)(d) && d.name === "User");
|
|
125
|
+
found = model.declarations.find((d) => ((0, import_ast.isDataModel)(d) || (0, import_ast.isTypeDef)(d)) && d.name === "User");
|
|
126
126
|
}
|
|
127
127
|
return found;
|
|
128
128
|
}
|
|
@@ -975,10 +975,16 @@ var TsSchemaGenerator = class {
|
|
|
975
975
|
], true);
|
|
976
976
|
}
|
|
977
977
|
createModelsObject(model, lite) {
|
|
978
|
-
return ts.factory.createObjectLiteralExpression(
|
|
978
|
+
return ts.factory.createObjectLiteralExpression(this.getAllDataModels(model).map((dm) => ts.factory.createPropertyAssignment(dm.name, this.createDataModelObject(dm, lite))), true);
|
|
979
|
+
}
|
|
980
|
+
getAllDataModels(model) {
|
|
981
|
+
return model.declarations.filter((d) => (0, import_ast3.isDataModel)(d) && !hasAttribute(d, "@@ignore"));
|
|
982
|
+
}
|
|
983
|
+
getAllTypeDefs(model) {
|
|
984
|
+
return model.declarations.filter((d) => (0, import_ast3.isTypeDef)(d) && !hasAttribute(d, "@@ignore"));
|
|
979
985
|
}
|
|
980
986
|
createTypeDefsObject(model, lite) {
|
|
981
|
-
return ts.factory.createObjectLiteralExpression(
|
|
987
|
+
return ts.factory.createObjectLiteralExpression(this.getAllTypeDefs(model).map((td) => ts.factory.createPropertyAssignment(td.name, this.createTypeDefObject(td, lite))), true);
|
|
982
988
|
}
|
|
983
989
|
createDataModelObject(dm, lite) {
|
|
984
990
|
const allFields = (0, import_utils3.getAllFields)(dm);
|
|
@@ -1088,6 +1094,9 @@ var TsSchemaGenerator = class {
|
|
|
1088
1094
|
if (hasAttribute(field, "@updatedAt")) {
|
|
1089
1095
|
objectFields.push(ts.factory.createPropertyAssignment("updatedAt", ts.factory.createTrue()));
|
|
1090
1096
|
}
|
|
1097
|
+
if (hasAttribute(field, "@omit")) {
|
|
1098
|
+
objectFields.push(ts.factory.createPropertyAssignment("omit", ts.factory.createTrue()));
|
|
1099
|
+
}
|
|
1091
1100
|
if (contextModel && // id fields are duplicated in inherited models
|
|
1092
1101
|
!isIdField(field, contextModel) && field.$container !== contextModel && isDelegateModel(field.$container)) {
|
|
1093
1102
|
objectFields.push(ts.factory.createPropertyAssignment("originModel", ts.factory.createStringLiteral(field.$container.name)));
|
|
@@ -1543,7 +1552,7 @@ var TsSchemaGenerator = class {
|
|
|
1543
1552
|
ts.factory.createImportSpecifier(true, void 0, ts.factory.createIdentifier(`TypeDefResult as $TypeDefResult`))
|
|
1544
1553
|
] : []
|
|
1545
1554
|
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1546
|
-
const dataModels =
|
|
1555
|
+
const dataModels = this.getAllDataModels(model);
|
|
1547
1556
|
for (const dm of dataModels) {
|
|
1548
1557
|
let modelType = ts.factory.createTypeAliasDeclaration([
|
|
1549
1558
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1556,7 +1565,7 @@ var TsSchemaGenerator = class {
|
|
|
1556
1565
|
}
|
|
1557
1566
|
statements.push(modelType);
|
|
1558
1567
|
}
|
|
1559
|
-
const typeDefs =
|
|
1568
|
+
const typeDefs = this.getAllTypeDefs(model);
|
|
1560
1569
|
for (const td of typeDefs) {
|
|
1561
1570
|
let typeDef = ts.factory.createTypeAliasDeclaration([
|
|
1562
1571
|
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
@@ -1617,7 +1626,7 @@ var TsSchemaGenerator = class {
|
|
|
1617
1626
|
`, true);
|
|
1618
1627
|
}
|
|
1619
1628
|
generateInputTypes(model, options) {
|
|
1620
|
-
const dataModels =
|
|
1629
|
+
const dataModels = this.getAllDataModels(model);
|
|
1621
1630
|
const statements = [];
|
|
1622
1631
|
statements.push(this.generateSchemaImport(model, false, true, !!(options.lite || options.liteOnly), options.importWithFileExtension));
|
|
1623
1632
|
const inputTypes = [
|
|
@@ -1646,7 +1655,10 @@ var TsSchemaGenerator = class {
|
|
|
1646
1655
|
IncludeInput: "Include",
|
|
1647
1656
|
OmitInput: "Omit"
|
|
1648
1657
|
};
|
|
1649
|
-
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports(
|
|
1658
|
+
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1659
|
+
...inputTypes.map((inputType) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(`${inputType} as $${inputType}`))),
|
|
1660
|
+
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("ClientOptions as $ClientOptions"))
|
|
1661
|
+
])), ts.factory.createStringLiteral("@zenstackhq/orm")));
|
|
1650
1662
|
statements.push(ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(true, void 0, ts.factory.createNamedImports([
|
|
1651
1663
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SimplifiedModelResult as $SimplifiedModelResult")),
|
|
1652
1664
|
ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier("SelectIncludeOmit as $SelectIncludeOmit"))
|
|
@@ -1668,10 +1680,16 @@ var TsSchemaGenerator = class {
|
|
|
1668
1680
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1669
1681
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1670
1682
|
ts.factory.createLiteralTypeNode(ts.factory.createTrue())
|
|
1683
|
+
])),
|
|
1684
|
+
ts.factory.createTypeParameterDeclaration(void 0, "Options", ts.factory.createTypeReferenceNode("$ClientOptions", [
|
|
1685
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1686
|
+
]), ts.factory.createTypeReferenceNode("$ClientOptions", [
|
|
1687
|
+
ts.factory.createTypeReferenceNode("$Schema")
|
|
1671
1688
|
]))
|
|
1672
1689
|
], ts.factory.createTypeReferenceNode("$SimplifiedModelResult", [
|
|
1673
1690
|
ts.factory.createTypeReferenceNode("$Schema"),
|
|
1674
1691
|
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)),
|
|
1692
|
+
ts.factory.createTypeReferenceNode("Options"),
|
|
1675
1693
|
ts.factory.createTypeReferenceNode("Args")
|
|
1676
1694
|
])));
|
|
1677
1695
|
}
|