erpnext-queue-client 1.39.2 → 2.0.0-beta.1

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.
Files changed (138) hide show
  1. package/dist/client.js +3 -6
  2. package/dist/constants.d.ts +1 -1
  3. package/dist/constants.js +16 -2
  4. package/dist/erpnext/doctypeResourceRequest.d.ts +12 -11
  5. package/dist/erpnext/doctypeResourceRequest.js +3 -2
  6. package/dist/erpnext/doctypeSubmittableResourceRequest.d.ts +161 -4
  7. package/dist/erpnext/doctypeSubmittableResourceRequest.js +16 -1
  8. package/dist/erpnext/doctypes/address.d.ts +160 -225
  9. package/dist/erpnext/doctypes/address.js +0 -2
  10. package/dist/erpnext/doctypes/contact.d.ts +157 -314
  11. package/dist/erpnext/doctypes/contact.js +1 -1
  12. package/dist/erpnext/doctypes/deliveryNote.d.ts +705 -505
  13. package/dist/erpnext/doctypes/deliveryNote.js +4 -10
  14. package/dist/erpnext/doctypes/item.d.ts +231 -324
  15. package/dist/erpnext/doctypes/paymentEntry.d.ts +820 -0
  16. package/dist/erpnext/doctypes/paymentEntry.js +72 -0
  17. package/dist/erpnext/doctypes/productBundle.d.ts +48 -58
  18. package/dist/erpnext/doctypes/purchaseInvoice.d.ts +717 -745
  19. package/dist/erpnext/doctypes/purchaseReceipt.d.ts +282 -332
  20. package/dist/erpnext/doctypes/salesInvoice.d.ts +3334 -0
  21. package/dist/erpnext/doctypes/salesInvoice.js +72 -0
  22. package/dist/erpnext/doctypes/servicecase.d.ts +191 -134
  23. package/dist/erpnext/doctypes/servicecase.js +4 -6
  24. package/dist/erpnext/doctypes/shipment.d.ts +193 -251
  25. package/dist/erpnext/doctypes/tags.d.ts +10 -0
  26. package/dist/erpnext/doctypes/tags.js +102 -0
  27. package/dist/erpnext/model/Account.d.ts +0 -33
  28. package/dist/erpnext/model/Account.js +0 -11
  29. package/dist/erpnext/model/Address.d.ts +112 -233
  30. package/dist/erpnext/model/Address.js +11 -49
  31. package/dist/erpnext/model/Attachment.d.ts +0 -3
  32. package/dist/erpnext/model/Attachment.js +0 -1
  33. package/dist/erpnext/model/Boolean.d.ts +4 -0
  34. package/dist/erpnext/model/Boolean.js +9 -0
  35. package/dist/erpnext/model/Compliance.d.ts +0 -112
  36. package/dist/erpnext/model/Compliance.js +0 -19
  37. package/dist/erpnext/model/ConsolidatedCustomsInvoice.d.ts +26 -138
  38. package/dist/erpnext/model/ConsolidatedCustomsInvoice.js +0 -19
  39. package/dist/erpnext/model/Contact.d.ts +166 -416
  40. package/dist/erpnext/model/Contact.js +16 -69
  41. package/dist/erpnext/model/Country.d.ts +0 -64
  42. package/dist/erpnext/model/Country.js +0 -10
  43. package/dist/erpnext/model/Customer.d.ts +39 -64
  44. package/dist/erpnext/model/Customer.js +11 -25
  45. package/dist/erpnext/model/DeliveryNote.d.ts +125 -1168
  46. package/dist/erpnext/model/DeliveryNote.js +5 -51
  47. package/dist/erpnext/model/DispatchRun.d.ts +4 -110
  48. package/dist/erpnext/model/DispatchRun.js +1 -30
  49. package/dist/erpnext/model/DispatcherPreset.d.ts +0 -119
  50. package/dist/erpnext/model/DispatcherPreset.js +1 -27
  51. package/dist/erpnext/model/DocInfo.d.ts +41 -339
  52. package/dist/erpnext/model/DocInfo.js +5 -6
  53. package/dist/erpnext/model/DocTypeHelpers.d.ts +160 -2
  54. package/dist/erpnext/model/DocTypeHelpers.js +124 -1
  55. package/dist/erpnext/model/ERPNextDocTypeMeta.d.ts +137 -0
  56. package/dist/erpnext/model/ERPNextDocTypeMeta.js +42 -0
  57. package/dist/erpnext/model/ERPNextRequest.d.ts +5 -5
  58. package/dist/erpnext/model/File.d.ts +0 -48
  59. package/dist/erpnext/model/File.js +0 -8
  60. package/dist/erpnext/model/Fulfiller.d.ts +0 -121
  61. package/dist/erpnext/model/Fulfiller.js +1 -56
  62. package/dist/erpnext/model/FulfillerSettings.d.ts +0 -39
  63. package/dist/erpnext/model/FulfillerSettings.js +0 -6
  64. package/dist/erpnext/model/InternalReasons.d.ts +0 -3
  65. package/dist/erpnext/model/InternalReasons.js +0 -1
  66. package/dist/erpnext/model/Item.d.ts +488 -1847
  67. package/dist/erpnext/model/Item.js +18 -142
  68. package/dist/erpnext/model/ItemTaxTemplate.d.ts +57 -0
  69. package/dist/erpnext/model/ItemTaxTemplate.js +25 -0
  70. package/dist/erpnext/model/Logs.d.ts +0 -9
  71. package/dist/erpnext/model/Logs.js +0 -3
  72. package/dist/erpnext/model/PartList.d.ts +0 -15
  73. package/dist/erpnext/model/PartList.js +0 -5
  74. package/dist/erpnext/model/PaymentEntry.d.ts +302 -122
  75. package/dist/erpnext/model/PaymentEntry.js +52 -48
  76. package/dist/erpnext/model/Permissions.d.ts +3 -3
  77. package/dist/erpnext/model/Permissions.js +1 -1
  78. package/dist/erpnext/model/ProductBundle.d.ts +6 -107
  79. package/dist/erpnext/model/ProductBundle.js +0 -17
  80. package/dist/erpnext/model/PurchaseInvoice.d.ts +319 -389
  81. package/dist/erpnext/model/PurchaseInvoice.js +5 -24
  82. package/dist/erpnext/model/PurchaseOrder.d.ts +38 -184
  83. package/dist/erpnext/model/PurchaseOrder.js +0 -34
  84. package/dist/erpnext/model/Receipt.d.ts +32 -123
  85. package/dist/erpnext/model/Receipt.js +2 -25
  86. package/dist/erpnext/model/ReceiptDraft.d.ts +28 -70
  87. package/dist/erpnext/model/ReceiptDraft.js +2 -12
  88. package/dist/erpnext/model/Report.d.ts +0 -40
  89. package/dist/erpnext/model/Report.js +0 -8
  90. package/dist/erpnext/model/SalesInvoice.d.ts +2445 -0
  91. package/dist/erpnext/model/SalesInvoice.js +330 -0
  92. package/dist/erpnext/model/SalesOrder.d.ts +1061 -0
  93. package/dist/erpnext/model/SalesOrder.js +272 -0
  94. package/dist/erpnext/model/SalesTaxesAndCharges.d.ts +47 -0
  95. package/dist/erpnext/model/SalesTaxesAndCharges.js +30 -0
  96. package/dist/erpnext/model/Servicecase.d.ts +283 -728
  97. package/dist/erpnext/model/Servicecase.js +30 -108
  98. package/dist/erpnext/model/ServicecaseReason.d.ts +0 -8
  99. package/dist/erpnext/model/ServicecaseReason.js +0 -2
  100. package/dist/erpnext/model/ServicecaseSolution.d.ts +0 -3
  101. package/dist/erpnext/model/ServicecaseSolution.js +0 -1
  102. package/dist/erpnext/model/ServiceportalProductConfiguration.d.ts +27 -452
  103. package/dist/erpnext/model/ServiceportalProductConfiguration.js +16 -47
  104. package/dist/erpnext/model/Shipment.d.ts +18 -715
  105. package/dist/erpnext/model/Shipment.js +1 -69
  106. package/dist/erpnext/model/ShippingFees.d.ts +2 -2
  107. package/dist/erpnext/model/ShippingLabel.d.ts +0 -32
  108. package/dist/erpnext/model/ShippingLabel.js +0 -8
  109. package/dist/erpnext/model/ShippingProvider.d.ts +6 -87
  110. package/dist/erpnext/model/ShippingProvider.js +3 -6
  111. package/dist/erpnext/model/Stock.d.ts +0 -40
  112. package/dist/erpnext/model/Stock.js +0 -8
  113. package/dist/erpnext/model/StockEntry.d.ts +14 -47
  114. package/dist/erpnext/model/StockEntry.js +0 -11
  115. package/dist/erpnext/model/StockReconciliation.d.ts +5 -32
  116. package/dist/erpnext/model/StockReconciliation.js +0 -10
  117. package/dist/erpnext/model/Supplier.d.ts +0 -79
  118. package/dist/erpnext/model/Supplier.js +0 -8
  119. package/dist/erpnext/model/TaxCategory.d.ts +20 -0
  120. package/dist/erpnext/model/TaxCategory.js +16 -0
  121. package/dist/erpnext/model/Version.d.ts +0 -9
  122. package/dist/erpnext/model/Version.js +0 -3
  123. package/dist/erpnext/model/Waitlist.d.ts +0 -3
  124. package/dist/erpnext/model/Waitlist.js +0 -1
  125. package/dist/erpnext/model/WarehouseCategory.d.ts +0 -11
  126. package/dist/erpnext/model/WarehouseCategory.js +1 -7
  127. package/dist/erpnext/reports.js +3 -7
  128. package/dist/erpnext/resourceRequest.d.ts +13 -11
  129. package/dist/erpnext/resourceRequest.js +34 -23
  130. package/dist/index.d.ts +23 -11
  131. package/dist/index.js +31 -12
  132. package/dist/index.test.d.ts +1 -0
  133. package/dist/index.test.js +261 -0
  134. package/dist/utils/utils.d.ts +3 -0
  135. package/dist/utils/zodContextOptionals.d.ts +14 -0
  136. package/dist/utils/zodContextOptionals.js +45 -0
  137. package/dist/utils/zodUtils.js +16 -3
  138. package/package.json +6 -1
@@ -11,14 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ERPNextResourceRequest = void 0;
13
13
  const zod_1 = require("zod");
14
+ const logger_1 = require("../utils/logger");
15
+ const utils_1 = require("../utils/utils");
14
16
  const zodUtils_1 = require("../utils/zodUtils");
17
+ const DocTypeHelpers_1 = require("./model/DocTypeHelpers");
15
18
  const ERPNextResponse_1 = require("./model/ERPNextResponse");
16
- const utils_1 = require("../utils/utils");
17
- const logger_1 = require("../utils/logger");
19
+ const zodContextOptionals_1 = require("../utils/zodContextOptionals");
18
20
  class ERPNextResourceRequest {
19
21
  constructor(temporalClient) {
20
22
  this.getParams = (fields, filters, asDict, params) => {
21
- const fieldsParams = fields ? { fields: JSON.stringify(fields) } : {};
23
+ const fieldsParams = fields
24
+ ? { fields: `[${fields.map((fi) => `"${fi}"`).join(",")}]` }
25
+ : {};
22
26
  const filtersParams = filters
23
27
  ? {
24
28
  filters: `[${filters
@@ -36,7 +40,9 @@ class ERPNextResourceRequest {
36
40
  return __awaiter(this, arguments, void 0, function* ({ resourceName, fields, filters, resourceModel, skip, limit, priority = 5, asDict, params, }) {
37
41
  if (resourceModel && !resourceModel.description)
38
42
  throw new Error("Resource model must have a description");
39
- const erpNextFields = (fields === null || fields === void 0 ? void 0 : fields.length) ? fields : ["name"];
43
+ const erpNextFields = (fields === null || fields === void 0 ? void 0 : fields.length)
44
+ ? fields
45
+ : ["name"]; // default field is name
40
46
  const schema = asDict === false
41
47
  ? zod_1.z
42
48
  .object({
@@ -48,13 +54,14 @@ class ERPNextResourceRequest {
48
54
  : resourceModel
49
55
  ? (fields === null || fields === void 0 ? void 0 : fields[0]) === "*"
50
56
  ? zod_1.z
51
- .object({ data: zod_1.z.array(resourceModel.omit({ doctype: true })) })
52
- .describe(`${resourceModel.description} List`)
57
+ .object({ data: zod_1.z.array((0, DocTypeHelpers_1.DocModelListEntry)(resourceModel)) })
58
+ .describe(`${resourceName} List with all fields`)
53
59
  : zod_1.z
54
60
  .object({
55
- data: zod_1.z.array((0, zodUtils_1.pickFromSchema)(resourceModel, erpNextFields)),
61
+ data: zod_1.z.array((0, zodUtils_1.pickFromSchema)((0, DocTypeHelpers_1.DocModelListEntry)(resourceModel), erpNextFields.filter((f) => f !== "*") // filter out * when other fields are present
62
+ )),
56
63
  })
57
- .describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields)}`)
64
+ .describe(`${resourceModel.description} List with fields ${JSON.stringify(erpNextFields.filter((f) => f !== "*"))}`)
58
65
  : zod_1.z.any().describe("Any response");
59
66
  const defaultPaginationSize = 500;
60
67
  let loopLimit = defaultPaginationSize;
@@ -67,7 +74,7 @@ class ERPNextResourceRequest {
67
74
  logger_1.lg.info("AUTO PAGINATE");
68
75
  do {
69
76
  // use limit & skip whenever it is directly provided. In other cases use loopLimit & loopSkip to remove pagination
70
- const paramsString = (0, utils_1.paramsToString)(Object.assign(Object.assign(Object.assign({}, this.getParams(fields, filters, asDict, params)), (limit === undefined && !autoPaginate
77
+ const paramsString = (0, utils_1.paramsToString)(Object.assign(Object.assign(Object.assign({}, this.getParams(erpNextFields, filters, asDict, params)), (limit === undefined && !autoPaginate
71
78
  ? {}
72
79
  : { limit: String(limit !== null && limit !== void 0 ? limit : loopLimit) })), (skip === undefined && !autoPaginate
73
80
  ? {}
@@ -91,25 +98,29 @@ class ERPNextResourceRequest {
91
98
  throw new Error("Resource model must have a description");
92
99
  if (!resourceId)
93
100
  throw new Error("Resource id is required");
94
- const result = yield this.temporalClient.executeERPNextRequestWorkflow(`GET-${resourceName}-${resourceId}`, {
101
+ const result = yield this.temporalClient
102
+ .executeERPNextRequestWorkflow(`GET-${resourceName}-${resourceId}`, {
95
103
  requestMethod: "GET",
96
104
  resourceName,
97
105
  resourceId,
98
106
  responseValidationModel: resourceModel
99
107
  ? zod_1.z
100
- .object({ data: resourceModel })
101
- .describe(resourceModel.description)
108
+ .object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) })
109
+ .describe(resourceName + " Response")
102
110
  : undefined,
103
- }, "erpnext", priority);
104
- if (!result.data)
105
- throw new Error(`Resource ${resourceName} with id ${resourceId} not found`);
106
- return result.data;
111
+ }, "erpnext", priority)
112
+ .catch((err) => {
113
+ if (err.message.includes("Error 404")) {
114
+ logger_1.lg.error(`Resource ${resourceName} with id ${resourceId} not found`);
115
+ return;
116
+ }
117
+ throw err;
118
+ });
119
+ return result === null || result === void 0 ? void 0 : result.data;
107
120
  });
108
121
  }
109
122
  updateById(_a) {
110
123
  return __awaiter(this, arguments, void 0, function* ({ resourceName, resourceId, inputValidationModel, resourceModel, body, priority = 5, }) {
111
- if (resourceModel && !resourceModel.description)
112
- throw new Error("Resource model must have a description");
113
124
  // accept partial input while enforcing allowed keys
114
125
  const partialInputValidationModel = inputValidationModel && inputValidationModel instanceof zod_1.ZodObject
115
126
  ? inputValidationModel.partial().strict()
@@ -120,9 +131,7 @@ class ERPNextResourceRequest {
120
131
  resourceName,
121
132
  inputValidationModel: partialInputValidationModel,
122
133
  responseValidationModel: resourceModel
123
- ? zod_1.z
124
- .object({ data: resourceModel })
125
- .describe(resourceModel.description)
134
+ ? zod_1.z.object({ data: (0, DocTypeHelpers_1.DocModel)(resourceModel) }).describe(resourceName)
126
135
  : undefined,
127
136
  body,
128
137
  }, "erpnext", priority);
@@ -136,10 +145,12 @@ class ERPNextResourceRequest {
136
145
  const result = yield this.temporalClient.executeERPNextRequestWorkflow(`POST-${resourceName}`, {
137
146
  requestMethod: "POST",
138
147
  resourceName,
139
- inputValidationModel,
148
+ inputValidationModel: inputValidationModel !== null && inputValidationModel !== void 0 ? inputValidationModel : (resourceModel ? (0, zodContextOptionals_1.ResourceInput)(resourceModel) : undefined),
140
149
  responseValidationModel: resourceModel
141
150
  ? zod_1.z
142
- .object({ data: resourceModel })
151
+ .object({
152
+ data: (0, DocTypeHelpers_1.DocModel)(resourceModel),
153
+ })
143
154
  .describe(resourceModel.description)
144
155
  : undefined,
145
156
  params: (0, utils_1.paramsToString)(params),
package/dist/index.d.ts CHANGED
@@ -4,36 +4,41 @@ import { ERPNextAddress } from "./erpnext/doctypes/address";
4
4
  import { ERPNextContact } from "./erpnext/doctypes/contact";
5
5
  import { ERPNextDeliveryNote } from "./erpnext/doctypes/deliveryNote";
6
6
  import { ERPNextItem } from "./erpnext/doctypes/item";
7
+ import { ERPNextPaymentEntry } from "./erpnext/doctypes/paymentEntry";
8
+ import { ERPNextProductBundle } from "./erpnext/doctypes/productBundle";
7
9
  import { ERPNextPurchaseInvoice } from "./erpnext/doctypes/purchaseInvoice";
8
10
  import { ERPNextPurchaseReceipt } from "./erpnext/doctypes/purchaseReceipt";
11
+ import { ERPNextSalesInvoice } from "./erpnext/doctypes/salesInvoice";
12
+ import { ERPNextServicecase } from "./erpnext/doctypes/servicecase";
9
13
  import { ERPNextShipment } from "./erpnext/doctypes/shipment";
10
- import { ERPNextProductBundle } from "./erpnext/doctypes/productBundle";
11
14
  import { ERPNextStock } from "./erpnext/doctypes/stock";
15
+ import { ERPNextTags } from "./erpnext/doctypes/tags";
12
16
  import { ERPNextDoctypeSubmittableResourceRequest } from "./erpnext/doctypeSubmittableResourceRequest";
13
17
  import { ERPNextFileRequests } from "./erpnext/fileRequests";
14
18
  import { ERPNextMethodRequest } from "./erpnext/methodRequest";
15
19
  import { Compliance } from "./erpnext/model/Compliance";
20
+ import { ConsolidatedCustomsInvoice } from "./erpnext/model/ConsolidatedCustomsInvoice";
16
21
  import { Country } from "./erpnext/model/Country";
17
22
  import { Customer } from "./erpnext/model/Customer";
18
23
  import { ERPNextQueueClientContructorOptions } from "./erpnext/model/ERPNextQueue";
24
+ import { ERPNextFile } from "./erpnext/model/File";
25
+ import { InternalReason } from "./erpnext/model/InternalReasons";
26
+ import { ItemTaxTemplate } from "./erpnext/model/ItemTaxTemplate";
19
27
  import { PartList } from "./erpnext/model/PartList";
20
- import { PaymentEntry } from "./erpnext/model/PaymentEntry";
21
28
  import { PurchaseOrder } from "./erpnext/model/PurchaseOrder";
29
+ import { SalesOrder } from "./erpnext/model/SalesOrder";
30
+ import { ServicecaseReason } from "./erpnext/model/ServicecaseReason";
31
+ import { ServiceCaseSolution } from "./erpnext/model/ServicecaseSolution";
32
+ import { ServiceportalProductConfiguration } from "./erpnext/model/ServiceportalProductConfiguration";
33
+ import { ShippingLabel } from "./erpnext/model/ShippingLabel";
22
34
  import { ShippingProvider } from "./erpnext/model/ShippingProvider";
23
35
  import { StockEntry } from "./erpnext/model/StockEntry";
24
36
  import { StockReconciliation } from "./erpnext/model/StockReconciliation";
25
37
  import { Supplier } from "./erpnext/model/Supplier";
38
+ import { TaxCategory } from "./erpnext/model/TaxCategory";
26
39
  import { Waitlist } from "./erpnext/model/Waitlist";
27
40
  import { ERPNextReports } from "./erpnext/reports";
28
41
  import { ERPNextResourceRequest } from "./erpnext/resourceRequest";
29
- import { ERPNextServicecase } from "./erpnext/doctypes/servicecase";
30
- import { ServiceportalProductConfiguration } from "./erpnext/model/ServiceportalProductConfiguration";
31
- import { ShippingLabel } from "./erpnext/model/ShippingLabel";
32
- import { ServicecaseReason } from "./erpnext/model/ServicecaseReason";
33
- import { ServiceCaseSolution } from "./erpnext/model/ServicecaseSolution";
34
- import { InternalReason } from "./erpnext/model/InternalReasons";
35
- import { ERPNextFile } from "./erpnext/model/File";
36
- import { ConsolidatedCustomsInvoice } from "./erpnext/model/ConsolidatedCustomsInvoice";
37
42
  export declare class ERPNextQueueClient {
38
43
  temporalClient: TemporalClient;
39
44
  private credentials?;
@@ -55,12 +60,14 @@ export declare class ERPNextQueueClient {
55
60
  waitlist: ERPNextDoctypeResourceRequest<typeof Waitlist>;
56
61
  stockEntry: ERPNextDoctypeSubmittableResourceRequest<typeof StockEntry>;
57
62
  supplier: ERPNextDoctypeResourceRequest<typeof Supplier>;
58
- paymentEntry: ERPNextDoctypeSubmittableResourceRequest<typeof PaymentEntry>;
63
+ paymentEntry: ERPNextPaymentEntry;
59
64
  stockReconciliation: ERPNextDoctypeSubmittableResourceRequest<typeof StockReconciliation>;
60
65
  stock: ERPNextStock;
61
66
  reports: ERPNextReports;
62
67
  compliance: ERPNextDoctypeResourceRequest<typeof Compliance>;
63
68
  partList: ERPNextDoctypeResourceRequest<typeof PartList>;
69
+ salesOrder: ERPNextDoctypeSubmittableResourceRequest<typeof SalesOrder>;
70
+ salesInvoice: ERPNextSalesInvoice;
64
71
  servicecase: ERPNextServicecase;
65
72
  serviceportalProductConfiguration: ERPNextDoctypeResourceRequest<typeof ServiceportalProductConfiguration>;
66
73
  servicecaseReason: ERPNextDoctypeResourceRequest<typeof ServicecaseReason>;
@@ -69,6 +76,9 @@ export declare class ERPNextQueueClient {
69
76
  shippingLabel: ERPNextDoctypeResourceRequest<typeof ShippingLabel>;
70
77
  file: ERPNextDoctypeResourceRequest<typeof ERPNextFile>;
71
78
  consolidatedCustomsInvoice: ERPNextDoctypeSubmittableResourceRequest<typeof ConsolidatedCustomsInvoice>;
79
+ itemTaxTemplate: ERPNextDoctypeResourceRequest<typeof ItemTaxTemplate>;
80
+ taxCategory: ERPNextDoctypeResourceRequest<typeof TaxCategory>;
81
+ tags: ERPNextTags;
72
82
  /**
73
83
  * @description Provide either a temporal client or connection details to create a new client
74
84
  */
@@ -79,3 +89,5 @@ export declare class ERPNextQueueClient {
79
89
  }
80
90
  export { ERPNextMethodResponse, ERPNextMethodResponseType, ERPNextResourceResponse, ERPNextResourceResponseType, } from "./erpnext/model/ERPNextResponse";
81
91
  export { pickFromSchema } from "./utils/zodUtils";
92
+ export { AugmentChildTableArrays, CreateChildTableEntrySchema, DocTypeList, LoadDocumentWrapper, } from "./erpnext/model/DocTypeHelpers";
93
+ export { DocTypeChildTableEntryMeta, DocTypeMeta, DocTypeNested, } from "./erpnext/model/ERPNextDocTypeMeta";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pickFromSchema = exports.ERPNextResourceResponse = exports.ERPNextMethodResponse = exports.ERPNextQueueClient = void 0;
3
+ exports.DocTypeNested = exports.DocTypeMeta = exports.DocTypeChildTableEntryMeta = exports.LoadDocumentWrapper = exports.DocTypeList = exports.CreateChildTableEntrySchema = exports.AugmentChildTableArrays = exports.pickFromSchema = exports.ERPNextResourceResponse = exports.ERPNextMethodResponse = exports.ERPNextQueueClient = void 0;
4
4
  const client_1 = require("./client");
5
5
  const decryptFromErpNext_server_1 = require("./erpnext/decryptFromErpNext.server");
6
6
  const doctypeResourceRequest_1 = require("./erpnext/doctypeResourceRequest");
@@ -8,35 +8,40 @@ const address_1 = require("./erpnext/doctypes/address");
8
8
  const contact_1 = require("./erpnext/doctypes/contact");
9
9
  const deliveryNote_1 = require("./erpnext/doctypes/deliveryNote");
10
10
  const item_1 = require("./erpnext/doctypes/item");
11
+ const paymentEntry_1 = require("./erpnext/doctypes/paymentEntry");
12
+ const productBundle_1 = require("./erpnext/doctypes/productBundle");
11
13
  const purchaseInvoice_1 = require("./erpnext/doctypes/purchaseInvoice");
12
14
  const purchaseReceipt_1 = require("./erpnext/doctypes/purchaseReceipt");
15
+ const salesInvoice_1 = require("./erpnext/doctypes/salesInvoice");
16
+ const servicecase_1 = require("./erpnext/doctypes/servicecase");
13
17
  const shipment_1 = require("./erpnext/doctypes/shipment");
14
- const productBundle_1 = require("./erpnext/doctypes/productBundle");
15
18
  const stock_1 = require("./erpnext/doctypes/stock");
19
+ const tags_1 = require("./erpnext/doctypes/tags");
16
20
  const doctypeSubmittableResourceRequest_1 = require("./erpnext/doctypeSubmittableResourceRequest");
17
21
  const fileRequests_1 = require("./erpnext/fileRequests");
18
22
  const methodRequest_1 = require("./erpnext/methodRequest");
19
23
  const Compliance_1 = require("./erpnext/model/Compliance");
24
+ const ConsolidatedCustomsInvoice_1 = require("./erpnext/model/ConsolidatedCustomsInvoice");
20
25
  const Country_1 = require("./erpnext/model/Country");
21
26
  const Customer_1 = require("./erpnext/model/Customer");
27
+ const File_1 = require("./erpnext/model/File");
28
+ const InternalReasons_1 = require("./erpnext/model/InternalReasons");
29
+ const ItemTaxTemplate_1 = require("./erpnext/model/ItemTaxTemplate");
22
30
  const PartList_1 = require("./erpnext/model/PartList");
23
- const PaymentEntry_1 = require("./erpnext/model/PaymentEntry");
24
31
  const PurchaseOrder_1 = require("./erpnext/model/PurchaseOrder");
32
+ const SalesOrder_1 = require("./erpnext/model/SalesOrder");
33
+ const ServicecaseReason_1 = require("./erpnext/model/ServicecaseReason");
34
+ const ServicecaseSolution_1 = require("./erpnext/model/ServicecaseSolution");
35
+ const ServiceportalProductConfiguration_1 = require("./erpnext/model/ServiceportalProductConfiguration");
36
+ const ShippingLabel_1 = require("./erpnext/model/ShippingLabel");
25
37
  const ShippingProvider_1 = require("./erpnext/model/ShippingProvider");
26
38
  const StockEntry_1 = require("./erpnext/model/StockEntry");
27
39
  const StockReconciliation_1 = require("./erpnext/model/StockReconciliation");
28
40
  const Supplier_1 = require("./erpnext/model/Supplier");
41
+ const TaxCategory_1 = require("./erpnext/model/TaxCategory");
29
42
  const Waitlist_1 = require("./erpnext/model/Waitlist");
30
43
  const reports_1 = require("./erpnext/reports");
31
44
  const resourceRequest_1 = require("./erpnext/resourceRequest");
32
- const servicecase_1 = require("./erpnext/doctypes/servicecase");
33
- const ServiceportalProductConfiguration_1 = require("./erpnext/model/ServiceportalProductConfiguration");
34
- const ShippingLabel_1 = require("./erpnext/model/ShippingLabel");
35
- const ServicecaseReason_1 = require("./erpnext/model/ServicecaseReason");
36
- const ServicecaseSolution_1 = require("./erpnext/model/ServicecaseSolution");
37
- const InternalReasons_1 = require("./erpnext/model/InternalReasons");
38
- const File_1 = require("./erpnext/model/File");
39
- const ConsolidatedCustomsInvoice_1 = require("./erpnext/model/ConsolidatedCustomsInvoice");
40
45
  class ERPNextQueueClient {
41
46
  /**
42
47
  * @description Provide either a temporal client or connection details to create a new client
@@ -67,8 +72,10 @@ class ERPNextQueueClient {
67
72
  this.waitlist = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Waitlist", Waitlist_1.Waitlist);
68
73
  this.stockEntry = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Stock Entry", StockEntry_1.StockEntry);
69
74
  this.supplier = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Supplier", Supplier_1.Supplier);
70
- this.paymentEntry = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Payment Entry", PaymentEntry_1.PaymentEntry);
75
+ this.paymentEntry = new paymentEntry_1.ERPNextPaymentEntry(this.temporalClient);
71
76
  this.stockReconciliation = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Stock Reconciliation", StockReconciliation_1.StockReconciliation);
77
+ this.salesOrder = new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Sales Order", SalesOrder_1.SalesOrder);
78
+ this.salesInvoice = new salesInvoice_1.ERPNextSalesInvoice(this.temporalClient);
72
79
  this.reports = new reports_1.ERPNextReports(this.temporalClient);
73
80
  this.stock = new stock_1.ERPNextStock(this.temporalClient);
74
81
  this.compliance = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Compliance", Compliance_1.Compliance);
@@ -81,6 +88,9 @@ class ERPNextQueueClient {
81
88
  this.shippingLabel = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Shipping Label", ShippingLabel_1.ShippingLabel);
82
89
  this.consolidatedCustomsInvoice =
83
90
  new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest(this.temporalClient, "Consolidated Customs Invoice", ConsolidatedCustomsInvoice_1.ConsolidatedCustomsInvoice);
91
+ this.itemTaxTemplate = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Item Tax Template", ItemTaxTemplate_1.ItemTaxTemplate);
92
+ this.taxCategory = new doctypeResourceRequest_1.ERPNextDoctypeResourceRequest(this.temporalClient, "Tax Category", TaxCategory_1.TaxCategory);
93
+ this.tags = new tags_1.ERPNextTags(this.temporalClient);
84
94
  }
85
95
  }
86
96
  exports.ERPNextQueueClient = ERPNextQueueClient;
@@ -89,3 +99,12 @@ Object.defineProperty(exports, "ERPNextMethodResponse", { enumerable: true, get:
89
99
  Object.defineProperty(exports, "ERPNextResourceResponse", { enumerable: true, get: function () { return ERPNextResponse_1.ERPNextResourceResponse; } });
90
100
  var zodUtils_1 = require("./utils/zodUtils");
91
101
  Object.defineProperty(exports, "pickFromSchema", { enumerable: true, get: function () { return zodUtils_1.pickFromSchema; } });
102
+ var DocTypeHelpers_1 = require("./erpnext/model/DocTypeHelpers");
103
+ Object.defineProperty(exports, "AugmentChildTableArrays", { enumerable: true, get: function () { return DocTypeHelpers_1.AugmentChildTableArrays; } });
104
+ Object.defineProperty(exports, "CreateChildTableEntrySchema", { enumerable: true, get: function () { return DocTypeHelpers_1.CreateChildTableEntrySchema; } });
105
+ Object.defineProperty(exports, "DocTypeList", { enumerable: true, get: function () { return DocTypeHelpers_1.DocTypeList; } });
106
+ Object.defineProperty(exports, "LoadDocumentWrapper", { enumerable: true, get: function () { return DocTypeHelpers_1.LoadDocumentWrapper; } });
107
+ var ERPNextDocTypeMeta_1 = require("./erpnext/model/ERPNextDocTypeMeta");
108
+ Object.defineProperty(exports, "DocTypeChildTableEntryMeta", { enumerable: true, get: function () { return ERPNextDocTypeMeta_1.DocTypeChildTableEntryMeta; } });
109
+ Object.defineProperty(exports, "DocTypeMeta", { enumerable: true, get: function () { return ERPNextDocTypeMeta_1.DocTypeMeta; } });
110
+ Object.defineProperty(exports, "DocTypeNested", { enumerable: true, get: function () { return ERPNextDocTypeMeta_1.DocTypeNested; } });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const zod_1 = __importDefault(require("zod"));
16
+ const _1 = require(".");
17
+ const constants_1 = require("./constants");
18
+ const Address_1 = require("./erpnext/model/Address");
19
+ const zodContextOptionals_1 = require("./utils/zodContextOptionals");
20
+ const Item_1 = require("./erpnext/model/Item");
21
+ // Most tests are wrapped in async function blocks so they are declared statically but not run as tests.
22
+ // If we wanted to run the tests, a mocking system would need to be implemented.
23
+ describe.skipIf(constants_1.constants.TEMPORAL_HOST === "test")("Type tests", () => __awaiter(void 0, void 0, void 0, function* () {
24
+ const erp = new _1.ERPNextQueueClient({
25
+ temporalCredentials: {
26
+ temporalHost: constants_1.constants.TEMPORAL_HOST,
27
+ temporalNamespace: constants_1.constants.TEMPORAL_NAMESPACE,
28
+ temporalCert: constants_1.constants.TEMPORAL_CRT,
29
+ temporalKey: constants_1.constants.TEMPORAL_KEY,
30
+ },
31
+ });
32
+ test("Single item fetch", () => __awaiter(void 0, void 0, void 0, function* () {
33
+ // We use expect-error to statically test negative cases in typescript
34
+ () => __awaiter(void 0, void 0, void 0, function* () {
35
+ var _a;
36
+ const items = yield erp.item.getList({ limit: 1 });
37
+ const item = yield erp.item.getById({ resourceId: items[0].name });
38
+ expect(item === null || item === void 0 ? void 0 : item.name).toBeTypeOf("string");
39
+ expect(item === null || item === void 0 ? void 0 : item.doctype).toBeTypeOf("string");
40
+ expect(item === null || item === void 0 ? void 0 : item.description).toBeTypeOf("string");
41
+ expect((_a = item === null || item === void 0 ? void 0 : item.barcodes.at(0)) === null || _a === void 0 ? void 0 : _a.idx).toBeTypeOf("number");
42
+ });
43
+ }));
44
+ test("List with aliases", () => __awaiter(void 0, void 0, void 0, function* () {
45
+ var _a, _b, _c;
46
+ const items = yield erp.resourceRequest.getList({
47
+ resourceName: "Item",
48
+ resourceModel: Item_1.Item.merge(zod_1.default.object({
49
+ "`tabItem Supplier`.supplier as supplier": zod_1.default
50
+ .string()
51
+ .optional()
52
+ .nullable(),
53
+ "item_name as item_title": zod_1.default.string().optional().nullable(),
54
+ })).describe("Item with supplier and title"),
55
+ filters: [["name", "=", "8721225924026FBP"]],
56
+ fields: [
57
+ "name",
58
+ "`tabItem Supplier`.supplier as supplier",
59
+ "item_name as item_title",
60
+ ],
61
+ });
62
+ expect((_a = items.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
63
+ expect((_b = items.at(0)) === null || _b === void 0 ? void 0 : _b.supplier).toBeTypeOf("string");
64
+ expect((_c = items.at(0)) === null || _c === void 0 ? void 0 : _c.item_title).toBeTypeOf("string");
65
+ }));
66
+ test("Item List with field description", () => __awaiter(void 0, void 0, void 0, function* () {
67
+ () => __awaiter(void 0, void 0, void 0, function* () {
68
+ var _a, _b, _c, _d, _e, _f;
69
+ // get list with field defined
70
+ const itemsOnlyFieldDescription = yield erp.item.getList({
71
+ fields: ["description"],
72
+ limit: 10,
73
+ });
74
+ expect(
75
+ // @ts-expect-error
76
+ (_c = (_b = (_a = itemsOnlyFieldDescription.at(0)) === null || _a === void 0 ? void 0 : _a.barcodes) === null || _b === void 0 ? void 0 : _b.at(0)) === null || _c === void 0 ? void 0 : _c.idx).toBeUndefined();
77
+ expect((_d = itemsOnlyFieldDescription.at(0)) === null || _d === void 0 ? void 0 : _d.description).toBeTypeOf("string");
78
+ // @ts-expect-error
79
+ expect((_e = itemsOnlyFieldDescription.at(0)) === null || _e === void 0 ? void 0 : _e.name).toBeUndefined(); // name not valid here
80
+ // @ts-expect-error
81
+ expect((_f = itemsOnlyFieldDescription.at(0)) === null || _f === void 0 ? void 0 : _f.barcodes).toBeUndefined(); // barcodes not valid here}
82
+ });
83
+ }));
84
+ test("Item List with default field 'name'", () => __awaiter(void 0, void 0, void 0, function* () {
85
+ () => __awaiter(void 0, void 0, void 0, function* () {
86
+ var _a, _b;
87
+ // get list without fields defined
88
+ const items2 = yield erp.item.getList({ limit: 10 });
89
+ expect((_a = items2.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
90
+ // @ts-expect-error
91
+ expect((_b = items2.at(0)) === null || _b === void 0 ? void 0 : _b.item_code).toBeUndefined(); // item_code not valid here
92
+ });
93
+ }));
94
+ test("Item List with all fields", () => __awaiter(void 0, void 0, void 0, function* () {
95
+ () => __awaiter(void 0, void 0, void 0, function* () {
96
+ var _a, _b, _c, _d;
97
+ // get list without fields defined
98
+ const itemsWithAllFields = yield erp.item.getList({
99
+ fields: ["*"],
100
+ limit: 10,
101
+ });
102
+ expect((_a = itemsWithAllFields.at(0)) === null || _a === void 0 ? void 0 : _a.name).toBeTypeOf("string");
103
+ // @ts-expect-error
104
+ expect((_b = itemsWithAllFields.at(0)) === null || _b === void 0 ? void 0 : _b.doctype).toBeUndefined(); // doctype omitted in list entries
105
+ expect((_c = itemsWithAllFields.at(0)) === null || _c === void 0 ? void 0 : _c.item_code).toBeTypeOf("string");
106
+ // @ts-expect-error
107
+ expect((_d = itemsWithAllFields.at(0)) === null || _d === void 0 ? void 0 : _d.barcodes).toBeUndefined();
108
+ });
109
+ }));
110
+ test("Submittable DocType", () => __awaiter(void 0, void 0, void 0, function* () {
111
+ () => __awaiter(void 0, void 0, void 0, function* () {
112
+ const dns = yield erp.deliveryNote.getList({ limit: 1 });
113
+ if (!dns[0])
114
+ throw new Error("No Delivery Notes found in test instance");
115
+ const dn = yield erp.deliveryNote.getById({
116
+ resourceId: dns[0].name,
117
+ });
118
+ dn === null || dn === void 0 ? void 0 : dn.amended_from; // for static type analysis}
119
+ });
120
+ }));
121
+ test("Get Address by Supplier", () => __awaiter(void 0, void 0, void 0, function* () {
122
+ () => __awaiter(void 0, void 0, void 0, function* () {
123
+ const sup = yield erp.supplier.getList({ limit: 1 });
124
+ const address = yield erp.address.getAddressesBySupplier(sup[0].name);
125
+ expect(address[0].city).toBeTypeOf("string");
126
+ });
127
+ }));
128
+ test("Item List with invalid field list", () => __awaiter(void 0, void 0, void 0, function* () {
129
+ // don't execute, this is just for type testing statically
130
+ () => erp.item.getList({
131
+ // @ts-expect-error
132
+ fields: ["name", "barcode"],
133
+ limit: 10,
134
+ });
135
+ }));
136
+ test("Create with DocModel Metafields should fail", () => __awaiter(void 0, void 0, void 0, function* () {
137
+ // SHOULD NOT BE EXECUTED, ONLY FOR STATIC TYPE TESTING
138
+ // We use expect-error to statically test negative cases in typescript
139
+ () => erp.item.create({
140
+ body: {
141
+ // @ts-expect-error
142
+ name: "TEST", // name and other metafields should not be set on create
143
+ },
144
+ });
145
+ () => erp.resourceRequest.create({
146
+ // @ts-expect-error - mandatory is missing, we expect an error here
147
+ body: {
148
+ optional: "string",
149
+ },
150
+ resourceName: "TEST",
151
+ resourceModel: zod_1.default.object({
152
+ mandatory: zod_1.default.string(),
153
+ optional: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
154
+ }),
155
+ });
156
+ // should have no errors since the optional key is input-optional
157
+ () => erp.resourceRequest.create({
158
+ body: {
159
+ mandatory: "string",
160
+ },
161
+ resourceName: "TEST",
162
+ resourceModel: zod_1.default.object({
163
+ mandatory: zod_1.default.string(),
164
+ optional: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
165
+ }),
166
+ });
167
+ () => erp.paymentEntry.create({
168
+ body: {
169
+ naming_series: "PAY-.#",
170
+ paid_amount: 12,
171
+ party: "test",
172
+ party_type: "Customer",
173
+ payment_type: "Receive",
174
+ reference_no: "REF",
175
+ reference_date: "2025-01-01",
176
+ },
177
+ });
178
+ () => erp.salesOrder.create({
179
+ // @ts-expect-error should not be empty
180
+ body: {},
181
+ });
182
+ }));
183
+ test("Static Types with Input Optional", () => __awaiter(void 0, void 0, void 0, function* () {
184
+ // DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
185
+ // We use expect-error to statically test negative cases in typescript
186
+ const testModel = zod_1.default.object({
187
+ mandatory: zod_1.default.string(),
188
+ optionalInInput: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
189
+ });
190
+ const inputModel = (0, zodContextOptionals_1.ResourceInput)(testModel);
191
+ const testInputWrongType = {
192
+ mandatory: "TEST",
193
+ // @ts-expect-error because type is set incorrectly
194
+ optionalInInput: 1,
195
+ };
196
+ const testInputCorrect = {
197
+ mandatory: "TEST",
198
+ };
199
+ // @ts-expect-error because output should contain optionalInInput
200
+ const testOutput = {
201
+ mandatory: "TEST",
202
+ };
203
+ }));
204
+ test("Static Types with Nested Array Input Optional", () => __awaiter(void 0, void 0, void 0, function* () {
205
+ // DO NOT EXECUTE, ONLY FOR STATIC TYPE TESTING
206
+ // We use expect-error to statically test negative cases in typescript
207
+ const testModel = zod_1.default.object({
208
+ mandatory: zod_1.default.string(),
209
+ subarray: zod_1.default.array(zod_1.default.object({
210
+ mandatoryElement: zod_1.default.string(),
211
+ inputOptionalSubarrayElement: (0, zodContextOptionals_1.optionalForInput)(zod_1.default.string()),
212
+ })),
213
+ });
214
+ const inputModel = (0, zodContextOptionals_1.ResourceInput)(testModel);
215
+ const testInputWrongType = {
216
+ mandatory: "TEST",
217
+ subarray: [
218
+ {
219
+ mandatoryElement: "test",
220
+ // @ts-expect-error because type is set incorrectly
221
+ inputOptionalSubarrayElement: 1,
222
+ },
223
+ ],
224
+ };
225
+ const testInputCorrect = {
226
+ mandatory: "TEST",
227
+ subarray: [
228
+ {
229
+ mandatoryElement: "test",
230
+ },
231
+ ],
232
+ };
233
+ const testOutput = {
234
+ mandatory: "TEST",
235
+ subarray: [
236
+ // @ts-expect-error because output should contain inputOptionalSubarrayElement
237
+ {
238
+ mandatoryElement: "test",
239
+ },
240
+ ],
241
+ };
242
+ }));
243
+ test("Input for updateById function", () => __awaiter(void 0, void 0, void 0, function* () {
244
+ () => __awaiter(void 0, void 0, void 0, function* () {
245
+ // This static type test ensures, that Input as inferred here
246
+ // conformes to the expected input type defined in doctypeResourceRequest -> updateById()
247
+ const AddressInput = (0, zodContextOptionals_1.ResourceInput)(Address_1.Address);
248
+ const typedInputBody = {
249
+ address_line1: "test",
250
+ address_type: "TEST",
251
+ city: "CITY",
252
+ country: "Country",
253
+ pincode: "1234",
254
+ };
255
+ yield erp.address.updateById({
256
+ resourceId: "TEST",
257
+ body: typedInputBody,
258
+ });
259
+ });
260
+ }));
261
+ }));
@@ -1,3 +1,6 @@
1
+ export type Prettify<T> = {
2
+ [K in keyof T]: T[K];
3
+ } & {};
1
4
  export declare function addDays(date: string | number | Date, days: number): Date;
2
5
  export declare function addMinutes(date: Date, minutes: number): Date;
3
6
  export declare function timeout(ms: number): Promise<void>;
@@ -0,0 +1,14 @@
1
+ import { AnyZodObject, z, ZodArray, ZodObject, ZodRawShape } from "zod";
2
+ type MarkedInputOptional<T extends z.ZodTypeAny> = T & {
3
+ __optionalForInput: true;
4
+ };
5
+ export declare function optionalForInput<T extends z.ZodTypeAny>(schema: T): MarkedInputOptional<T>;
6
+ type TransformInnerShape<S extends ZodRawShape> = {
7
+ [P in keyof S]: S[P] extends MarkedInputOptional<infer U> ? z.ZodOptional<U> : S[P];
8
+ };
9
+ type TransformOneLevel<V> = V extends MarkedInputOptional<infer U> ? z.ZodOptional<U> : V extends ZodObject<infer S extends ZodRawShape> ? ZodObject<TransformInnerShape<S>> : V extends ZodArray<infer Elem> ? Elem extends ZodObject<infer S2 extends ZodRawShape> ? ZodArray<ZodObject<TransformInnerShape<S2>>> : V : V;
10
+ export type ResourceInputType<T extends AnyZodObject> = ZodObject<{
11
+ [K in keyof T["shape"]]: TransformOneLevel<T["shape"][K]>;
12
+ }>;
13
+ export declare function ResourceInput<T extends ZodRawShape>(schema: z.ZodObject<T>): ResourceInputType<z.ZodObject<T>>;
14
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optionalForInput = optionalForInput;
4
+ exports.ResourceInput = ResourceInput;
5
+ const zod_1 = require("zod");
6
+ // Helper to mark a field as optional for input
7
+ function optionalForInput(schema) {
8
+ return Object.assign(schema, {
9
+ __optionalForInput: true,
10
+ });
11
+ }
12
+ // Helper to check if field is marked
13
+ function isMarkedOptionalForInput(schema) {
14
+ return "__optionalForInput" in schema && schema.__optionalForInput === true;
15
+ }
16
+ // schema transformation
17
+ function ResourceInput(schema) {
18
+ var _a;
19
+ const shape = schema.shape;
20
+ function makeMarkedKeysOptional(shape) {
21
+ const newShape = zod_1.z.object({}).shape;
22
+ for (const [key, value] of Object.entries(shape)) {
23
+ if (isMarkedOptionalForInput(value)) {
24
+ newShape[key] = value.optional();
25
+ }
26
+ else {
27
+ newShape[key] = value;
28
+ }
29
+ // Recurse one level into nested objects to apply the same optionalization
30
+ if (value instanceof zod_1.z.ZodObject) {
31
+ const innerShape = value.shape;
32
+ newShape[key] = zod_1.z.object(makeMarkedKeysOptional(innerShape));
33
+ }
34
+ else if (value instanceof zod_1.ZodArray) {
35
+ const arrayElementShape = value.element
36
+ .shape;
37
+ newShape[key] = zod_1.z.array(zod_1.z.object(makeMarkedKeysOptional(arrayElementShape)));
38
+ }
39
+ }
40
+ return newShape;
41
+ }
42
+ return zod_1.z
43
+ .object(makeMarkedKeysOptional(shape))
44
+ .describe(((_a = schema.description) !== null && _a !== void 0 ? _a : "Unnamed Model") + " Input");
45
+ }