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
@@ -7,17 +7,16 @@ const Logs_1 = require("./Logs");
7
7
  const Version_1 = require("./Version");
8
8
  const Attachment_1 = require("./Attachment");
9
9
  const Permissions_1 = require("./Permissions");
10
+ const DocTypeHelpers_1 = require("./DocTypeHelpers");
10
11
  const DocInfo = zod_1.z
11
12
  .object({
12
- doctype: zod_1.z.string(),
13
- name: zod_1.z.string(),
14
13
  user_info: zod_1.z.record(zod_1.z.string(), User_1.UserInfo),
15
14
  attachments: zod_1.z.array(Attachment_1.Attachment),
16
15
  attachment_logs: zod_1.z.array(Logs_1.LogEntry).optional().nullable(),
17
16
  communications: zod_1.z.array(zod_1.z.unknown()),
18
17
  automated_messages: zod_1.z.array(zod_1.z.unknown()),
19
18
  comments: zod_1.z.array(zod_1.z.unknown()),
20
- total_comments: zod_1.z.number(),
19
+ total_comments: zod_1.z.number().optional().nullable(),
21
20
  versions: zod_1.z.array(Version_1.Version),
22
21
  assignments: zod_1.z.array(zod_1.z.unknown()),
23
22
  assignment_logs: zod_1.z.array(Logs_1.LogEntry).optional().nullable(),
@@ -36,11 +35,11 @@ const DocInfo = zod_1.z
36
35
  document_email: zod_1.z.string().optional().nullable(),
37
36
  })
38
37
  .describe("DocInfo");
39
- const GetDocResponse = (DocModel) => zod_1.z
38
+ const GetDocResponse = (InputDocModel) => zod_1.z
40
39
  .object({
41
- docs: zod_1.z.array(DocModel),
40
+ docs: zod_1.z.array((0, DocTypeHelpers_1.DocModel)(InputDocModel)),
42
41
  docinfo: DocInfo,
43
42
  _link_titles: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
44
43
  })
45
- .describe("GetDocResponse " + DocModel.description);
44
+ .describe("GetDocResponse " + InputDocModel.description);
46
45
  exports.GetDocResponse = GetDocResponse;
@@ -1,2 +1,160 @@
1
- import { ZodObject } from "zod";
2
- export declare const LoadDocumentWrapper: (BaseModel: ZodObject<any>) => ZodObject<any>;
1
+ import { AnyZodObject, z, ZodArray, ZodObject, ZodRawShape } from "zod";
2
+ import { Prettify } from "../../utils/utils";
3
+ import { KeysOf } from "../../utils/zodUtils";
4
+ import { DocTypeChildTableEntryMeta, DocTypeMeta } from "./ERPNextDocTypeMeta";
5
+ export type KeysOfModel<T> = KeysOf<T extends AnyZodObject ? DocModelListEntryType<T> : never>;
6
+ /**
7
+ * Extracts the alias from a field name if it contains " as ".
8
+ * For example: "`tabItemTaxTemplateDetail`.rate as rate" -> "rate"
9
+ * If no " as " is found, returns the original string.
10
+ */
11
+ type ExtractAlias<T extends string> = T extends `${infer _Before} as ${infer Alias}` ? Alias : T;
12
+ /**
13
+ * Creates a mapped type that picks fields from TModel using aliases extracted from TFields.
14
+ * For fields with " as ", uses the alias; otherwise uses the original field name.
15
+ */
16
+ type PickWithAliases<TModel extends AnyZodObject, TFields extends readonly string[]> = {
17
+ [K in TFields[number] as ExtractAlias<K>]: ExtractAlias<K> extends keyof z.infer<DocModelListEntryType<TModel>> ? z.infer<DocModelListEntryType<TModel>>[ExtractAlias<K>] : never;
18
+ };
19
+ export type GetListReturnValue<TModel, TFieldOptions extends KeysOfModel<TModel>, TSelectedFields extends TFieldOptions[] | readonly ["*"] | undefined, TAsDict> = Prettify<TAsDict extends false ? Array<Array<string>> : TModel extends AnyZodObject ? TSelectedFields extends undefined ? Array<{
20
+ name: string;
21
+ }> : TSelectedFields extends readonly ["*"] ? Array<z.infer<DocModelListEntryType<TModel>>> : TSelectedFields extends TFieldOptions[] ? Array<PickWithAliases<TModel, TSelectedFields>> : any : any>;
22
+ export declare const LoadDocumentWrapper: <T extends AnyZodObject>(BaseModel: T) => z.ZodObject<{
23
+ [x: string]: any;
24
+ } & {
25
+ __onload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
26
+ }, any, any, {
27
+ [x: string]: any;
28
+ __onload?: unknown;
29
+ }, {
30
+ [x: string]: any;
31
+ __onload?: unknown;
32
+ }>;
33
+ /**
34
+ * Transforms a base model into a DocType by:
35
+ * 1. Merging with DocTypeMeta (adds metadata fields)
36
+ * 2. Augmenting all array fields with DocTypeChildTableEntry metadata
37
+ *
38
+ * @param BaseModel - The base Zod object schema
39
+ * @returns A properly typed DocType schema with metadata and augmented arrays
40
+ */
41
+ type AugmentArrayFields<T extends AnyZodObject> = {
42
+ [K in keyof T["shape"]]: T["shape"][K] extends ZodArray<infer Element> ? Element extends ZodObject<infer ElementShape extends ZodRawShape> ? ZodArray<ZodObject<ElementShape & typeof DocTypeChildTableEntryMeta.shape>> : T["shape"][K] : T["shape"][K];
43
+ };
44
+ export type DocModelType<T extends AnyZodObject> = ZodObject<AugmentArrayFields<T> & typeof DocTypeMeta.shape>;
45
+ export declare const DocModel: <T extends ZodRawShape>(BaseModel: ZodObject<T>) => DocModelType<ZodObject<T>>;
46
+ /**
47
+ * Creates a list model by removing all array fields from a base DocType model.
48
+ * This is useful for list endpoints where child tables are not included.
49
+ * Returns a wrapped array schema with the name "DocTypeList".
50
+ *
51
+ * @param BaseModel - The Zod object schema to create a list model from
52
+ * @returns A Zod array schema containing the base model without array fields
53
+ *
54
+ * @example
55
+ * const Item = z.object({
56
+ * item_code: z.string(),
57
+ * item_name: z.string(),
58
+ * barcodes: z.array(Barcode),
59
+ * uoms: z.array(Uom),
60
+ * });
61
+ * const ItemList = DocTypeList(Item);
62
+ * ItemList is z.array of Item without barcodes and uoms fields
63
+ */
64
+ type OmitArrayFields<T extends AnyZodObject> = ZodObject<{
65
+ [K in keyof T["shape"] as T["shape"][K] extends ZodArray<any> ? never : K extends "doctype" ? never : K]: T["shape"][K];
66
+ }>;
67
+ export type DocModelListEntryType<T extends AnyZodObject> = OmitArrayFields<DocModelType<T>>;
68
+ export declare const DocModelListEntry: <T extends ZodRawShape>(BaseModel: ZodObject<T>) => DocModelListEntryType<ZodObject<T>>;
69
+ export declare const DocTypeList: <T extends AnyZodObject>(BaseModel: T) => z.ZodArray<any, "many">;
70
+ /**
71
+ * Augments all array fields in a Zod object schema that contain object schemas
72
+ * with DocTypeChildTableEntry metadata fields (name, owner, creation, etc.)
73
+ *
74
+ * This is useful for ERPNext child table entries which need to include
75
+ * metadata fields like parenttype, parentfield, etc.
76
+ *
77
+ * @param BaseModel - The Zod object schema to augment
78
+ * @returns A new Zod object schema with augmented array fields
79
+ *
80
+ * @example
81
+ * const Item = z.object({
82
+ * name: z.string(),
83
+ * barcodes: z.array(BarcodeSchema),
84
+ * });
85
+ * const AugmentedItem = AugmentChildTableArrays(Item);
86
+ * Now barcodes array items will include DocTypeChildTableEntry fields
87
+ */
88
+ export declare const AugmentChildTableArrays: <T extends ZodRawShape>(BaseModel: ZodObject<T>) => z.ZodObject<z.ZodRawShape, "strip", z.ZodTypeAny, {
89
+ [x: string]: any;
90
+ }, {
91
+ [x: string]: any;
92
+ }>;
93
+ /**
94
+ * Creates a child table entry schema by merging business fields with DocTypeChildTableEntry metadata.
95
+ * This is the recommended way to define child table schemas for ERPNext resource models.
96
+ *
97
+ * @param businessFieldsSchema - The Zod object schema containing only business-specific fields
98
+ * @param description - Optional description for the resulting schema
99
+ * @returns A new Zod object schema with both business fields and child table metadata
100
+ *
101
+ * @example
102
+ * const BarcodeBusinessFields = z.object({
103
+ * barcode: z.string(),
104
+ * barcode_type: z.string(),
105
+ * });
106
+ * const Barcode = CreateChildTableEntrySchema(BarcodeBusinessFields, "Item Barcode");
107
+ *
108
+ * // Can then be used in parent model:
109
+ * const Item = z.object({
110
+ * item_code: z.string(),
111
+ * barcodes: z.array(Barcode),
112
+ * });
113
+ */
114
+ export declare const CreateChildTableEntrySchema: <T extends ZodRawShape>(businessFieldsSchema: ZodObject<T>, description?: string) => z.ZodObject<z.objectUtil.extendShape<T, {
115
+ name: z.ZodString;
116
+ owner: z.ZodString;
117
+ creation: z.ZodString;
118
+ modified: z.ZodString;
119
+ modified_by: z.ZodString;
120
+ idx: z.ZodNumber;
121
+ docstatus: z.ZodDefault<z.ZodNumber> & {
122
+ __optionalForInput: true;
123
+ };
124
+ doctype: z.ZodString;
125
+ _user_tags: z.ZodNullable<z.ZodOptional<z.ZodString>>;
126
+ } & {
127
+ parenttype: z.ZodString;
128
+ parentfield: z.ZodString;
129
+ }>, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
130
+ name: z.ZodString;
131
+ owner: z.ZodString;
132
+ creation: z.ZodString;
133
+ modified: z.ZodString;
134
+ modified_by: z.ZodString;
135
+ idx: z.ZodNumber;
136
+ docstatus: z.ZodDefault<z.ZodNumber> & {
137
+ __optionalForInput: true;
138
+ };
139
+ doctype: z.ZodString;
140
+ _user_tags: z.ZodNullable<z.ZodOptional<z.ZodString>>;
141
+ } & {
142
+ parenttype: z.ZodString;
143
+ parentfield: z.ZodString;
144
+ }>>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<T, {
145
+ name: z.ZodString;
146
+ owner: z.ZodString;
147
+ creation: z.ZodString;
148
+ modified: z.ZodString;
149
+ modified_by: z.ZodString;
150
+ idx: z.ZodNumber;
151
+ docstatus: z.ZodDefault<z.ZodNumber> & {
152
+ __optionalForInput: true;
153
+ };
154
+ doctype: z.ZodString;
155
+ _user_tags: z.ZodNullable<z.ZodOptional<z.ZodString>>;
156
+ } & {
157
+ parenttype: z.ZodString;
158
+ parentfield: z.ZodString;
159
+ }>> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
160
+ export {};
@@ -1,6 +1,129 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LoadDocumentWrapper = void 0;
3
+ exports.CreateChildTableEntrySchema = exports.AugmentChildTableArrays = exports.DocTypeList = exports.DocModelListEntry = exports.DocModel = exports.LoadDocumentWrapper = void 0;
4
4
  const zod_1 = require("zod");
5
+ const ERPNextDocTypeMeta_1 = require("./ERPNextDocTypeMeta");
5
6
  const LoadDocumentWrapper = (BaseModel) => BaseModel.extend({ __onload: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()) }).describe(BaseModel.description + " with __onload");
6
7
  exports.LoadDocumentWrapper = LoadDocumentWrapper;
8
+ const DocModel = (BaseModel) => {
9
+ var _a, _b;
10
+ // First merge with DocTypeMeta to add metadata fields
11
+ const withMeta = BaseModel.merge(ERPNextDocTypeMeta_1.DocTypeMeta).describe(((_a = BaseModel.description) !== null && _a !== void 0 ? _a : "Unnamed Model") + " Doc");
12
+ // Then augment array fields with child table metadata
13
+ const shape = withMeta.shape;
14
+ const newShape = {};
15
+ for (const [key, value] of Object.entries(shape)) {
16
+ if (value instanceof zod_1.ZodArray) {
17
+ const arrayElement = value._def.type;
18
+ // Check if the array contains a ZodObject
19
+ if (arrayElement instanceof zod_1.ZodObject) {
20
+ // Augment the array element with DocTypeChildTableEntry
21
+ const augmentedElement = arrayElement.merge(ERPNextDocTypeMeta_1.DocTypeChildTableEntryMeta);
22
+ newShape[key] = zod_1.z.array(augmentedElement);
23
+ }
24
+ else {
25
+ // Keep the original array as-is for non-object arrays
26
+ newShape[key] = value;
27
+ }
28
+ }
29
+ else {
30
+ // Keep non-array fields as-is
31
+ newShape[key] = value;
32
+ }
33
+ }
34
+ return zod_1.z
35
+ .object(newShape)
36
+ .describe((_b = BaseModel.description) !== null && _b !== void 0 ? _b : "Unnamed DocType Model");
37
+ };
38
+ exports.DocModel = DocModel;
39
+ const DocModelListEntry = (BaseModel) => {
40
+ const model = (0, exports.DocModel)(BaseModel);
41
+ const shape = model.shape;
42
+ const newShape = {};
43
+ // Filter out all array fields and the doctype field
44
+ for (const [key, value] of Object.entries(shape)) {
45
+ if (!(value instanceof zod_1.ZodArray) && key !== "doctype") {
46
+ newShape[key] = value;
47
+ }
48
+ }
49
+ return zod_1.z
50
+ .object(newShape)
51
+ .describe(`${BaseModel.description || "DocType"} List Item`);
52
+ };
53
+ exports.DocModelListEntry = DocModelListEntry;
54
+ const DocTypeList = (BaseModel) => {
55
+ return zod_1.z
56
+ .array(BaseModel)
57
+ .describe(`${BaseModel.description || "DocType List"}`.replace("List Item", "List"));
58
+ };
59
+ exports.DocTypeList = DocTypeList;
60
+ /**
61
+ * Augments all array fields in a Zod object schema that contain object schemas
62
+ * with DocTypeChildTableEntry metadata fields (name, owner, creation, etc.)
63
+ *
64
+ * This is useful for ERPNext child table entries which need to include
65
+ * metadata fields like parenttype, parentfield, etc.
66
+ *
67
+ * @param BaseModel - The Zod object schema to augment
68
+ * @returns A new Zod object schema with augmented array fields
69
+ *
70
+ * @example
71
+ * const Item = z.object({
72
+ * name: z.string(),
73
+ * barcodes: z.array(BarcodeSchema),
74
+ * });
75
+ * const AugmentedItem = AugmentChildTableArrays(Item);
76
+ * Now barcodes array items will include DocTypeChildTableEntry fields
77
+ */
78
+ const AugmentChildTableArrays = (BaseModel) => {
79
+ const shape = BaseModel.shape;
80
+ const newShape = {};
81
+ for (const [key, value] of Object.entries(shape)) {
82
+ if (value instanceof zod_1.ZodArray) {
83
+ const arrayElement = value._def.type;
84
+ // Check if the array contains a ZodObject
85
+ if (arrayElement instanceof zod_1.ZodObject) {
86
+ // Augment the array element with DocTypeChildTableEntry
87
+ const augmentedElement = arrayElement.merge(ERPNextDocTypeMeta_1.DocTypeChildTableEntryMeta);
88
+ newShape[key] = zod_1.z.array(augmentedElement);
89
+ }
90
+ else {
91
+ // Keep the original array as-is for non-object arrays
92
+ newShape[key] = value;
93
+ }
94
+ }
95
+ else {
96
+ // Keep non-array fields as-is
97
+ newShape[key] = value;
98
+ }
99
+ }
100
+ return zod_1.z.object(newShape).describe(BaseModel.description || "");
101
+ };
102
+ exports.AugmentChildTableArrays = AugmentChildTableArrays;
103
+ /**
104
+ * Creates a child table entry schema by merging business fields with DocTypeChildTableEntry metadata.
105
+ * This is the recommended way to define child table schemas for ERPNext resource models.
106
+ *
107
+ * @param businessFieldsSchema - The Zod object schema containing only business-specific fields
108
+ * @param description - Optional description for the resulting schema
109
+ * @returns A new Zod object schema with both business fields and child table metadata
110
+ *
111
+ * @example
112
+ * const BarcodeBusinessFields = z.object({
113
+ * barcode: z.string(),
114
+ * barcode_type: z.string(),
115
+ * });
116
+ * const Barcode = CreateChildTableEntrySchema(BarcodeBusinessFields, "Item Barcode");
117
+ *
118
+ * // Can then be used in parent model:
119
+ * const Item = z.object({
120
+ * item_code: z.string(),
121
+ * barcodes: z.array(Barcode),
122
+ * });
123
+ */
124
+ const CreateChildTableEntrySchema = (businessFieldsSchema, description) => {
125
+ return businessFieldsSchema
126
+ .merge(ERPNextDocTypeMeta_1.DocTypeChildTableEntryMeta)
127
+ .describe(description || businessFieldsSchema.description || "");
128
+ };
129
+ exports.CreateChildTableEntrySchema = CreateChildTableEntrySchema;
@@ -0,0 +1,137 @@
1
+ import { z } from "zod";
2
+ export declare const Docstatus: z.ZodDefault<z.ZodNumber>;
3
+ export type DocstatusType = z.infer<typeof Docstatus>;
4
+ export declare const SubmittableMeta: z.ZodObject<{
5
+ amended_from: z.ZodNullable<z.ZodOptional<z.ZodString>>;
6
+ docstatus: z.ZodDefault<z.ZodNumber> & {
7
+ __optionalForInput: true;
8
+ };
9
+ }, "strip", z.ZodTypeAny, {
10
+ docstatus: number;
11
+ amended_from?: string | null | undefined;
12
+ }, {
13
+ amended_from?: string | null | undefined;
14
+ docstatus?: number | undefined;
15
+ }>;
16
+ export declare const DocTypeMeta: z.ZodObject<{
17
+ name: z.ZodString;
18
+ owner: z.ZodString;
19
+ creation: z.ZodString;
20
+ modified: z.ZodString;
21
+ modified_by: z.ZodString;
22
+ idx: z.ZodNumber;
23
+ docstatus: z.ZodDefault<z.ZodNumber> & {
24
+ __optionalForInput: true;
25
+ };
26
+ doctype: z.ZodString;
27
+ _user_tags: z.ZodNullable<z.ZodOptional<z.ZodString>>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ docstatus: number;
30
+ name: string;
31
+ owner: string;
32
+ creation: string;
33
+ modified: string;
34
+ modified_by: string;
35
+ idx: number;
36
+ doctype: string;
37
+ _user_tags?: string | null | undefined;
38
+ }, {
39
+ name: string;
40
+ owner: string;
41
+ creation: string;
42
+ modified: string;
43
+ modified_by: string;
44
+ idx: number;
45
+ doctype: string;
46
+ docstatus?: number | undefined;
47
+ _user_tags?: string | null | undefined;
48
+ }>;
49
+ export type DocTypeMetaType = z.infer<typeof DocTypeMeta>;
50
+ export declare const DocTypeChildTableEntryMeta: z.ZodObject<{
51
+ name: z.ZodString;
52
+ owner: z.ZodString;
53
+ creation: z.ZodString;
54
+ modified: z.ZodString;
55
+ modified_by: z.ZodString;
56
+ idx: z.ZodNumber;
57
+ docstatus: z.ZodDefault<z.ZodNumber> & {
58
+ __optionalForInput: true;
59
+ };
60
+ doctype: z.ZodString;
61
+ _user_tags: z.ZodNullable<z.ZodOptional<z.ZodString>>;
62
+ } & {
63
+ parenttype: z.ZodString;
64
+ parentfield: z.ZodString;
65
+ }, "strip", z.ZodTypeAny, {
66
+ docstatus: number;
67
+ name: string;
68
+ owner: string;
69
+ creation: string;
70
+ modified: string;
71
+ modified_by: string;
72
+ idx: number;
73
+ doctype: string;
74
+ parenttype: string;
75
+ parentfield: string;
76
+ _user_tags?: string | null | undefined;
77
+ }, {
78
+ name: string;
79
+ owner: string;
80
+ creation: string;
81
+ modified: string;
82
+ modified_by: string;
83
+ idx: number;
84
+ doctype: string;
85
+ parenttype: string;
86
+ parentfield: string;
87
+ docstatus?: number | undefined;
88
+ _user_tags?: string | null | undefined;
89
+ }>;
90
+ export type DocTypeChildTableEntryMetaType = z.infer<typeof DocTypeChildTableEntryMeta>;
91
+ export declare const DocTypeNested: z.ZodObject<{
92
+ name: z.ZodString;
93
+ owner: z.ZodString;
94
+ creation: z.ZodString;
95
+ modified: z.ZodString;
96
+ modified_by: z.ZodString;
97
+ docstatus: z.ZodDefault<z.ZodNumber> & {
98
+ __optionalForInput: true;
99
+ };
100
+ doctype: z.ZodString;
101
+ _user_tags: z.ZodNullable<z.ZodOptional<z.ZodString>>;
102
+ } & {
103
+ old_parent: z.ZodString;
104
+ is_group: z.ZodNumber;
105
+ lft: z.ZodNumber;
106
+ rgt: z.ZodNumber;
107
+ idx: z.ZodNumber;
108
+ }, "strip", z.ZodTypeAny, {
109
+ docstatus: number;
110
+ name: string;
111
+ owner: string;
112
+ creation: string;
113
+ modified: string;
114
+ modified_by: string;
115
+ idx: number;
116
+ doctype: string;
117
+ old_parent: string;
118
+ is_group: number;
119
+ lft: number;
120
+ rgt: number;
121
+ _user_tags?: string | null | undefined;
122
+ }, {
123
+ name: string;
124
+ owner: string;
125
+ creation: string;
126
+ modified: string;
127
+ modified_by: string;
128
+ idx: number;
129
+ doctype: string;
130
+ old_parent: string;
131
+ is_group: number;
132
+ lft: number;
133
+ rgt: number;
134
+ docstatus?: number | undefined;
135
+ _user_tags?: string | null | undefined;
136
+ }>;
137
+ export type DocTypeNestedType = z.infer<typeof DocTypeNested>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocTypeNested = exports.DocTypeChildTableEntryMeta = exports.DocTypeMeta = exports.SubmittableMeta = exports.Docstatus = void 0;
4
+ const zod_1 = require("zod");
5
+ const zodContextOptionals_1 = require("../../utils/zodContextOptionals");
6
+ exports.Docstatus = zod_1.z.number().int().min(0).max(2).default(0);
7
+ exports.SubmittableMeta = zod_1.z
8
+ .object({
9
+ amended_from: zod_1.z.string().optional().nullable(),
10
+ docstatus: (0, zodContextOptionals_1.optionalForInput)(exports.Docstatus),
11
+ })
12
+ .describe("Submittable Meta");
13
+ exports.DocTypeMeta = zod_1.z
14
+ .object({
15
+ name: zod_1.z.string(),
16
+ owner: zod_1.z.string(),
17
+ creation: zod_1.z.string(),
18
+ modified: zod_1.z.string(),
19
+ modified_by: zod_1.z.string(),
20
+ idx: zod_1.z.number(),
21
+ docstatus: (0, zodContextOptionals_1.optionalForInput)(exports.Docstatus),
22
+ doctype: zod_1.z.string(),
23
+ _user_tags: zod_1.z.string().optional().nullable(),
24
+ })
25
+ .describe("Sales Order");
26
+ const ChildTableEntryFieldsMeta = zod_1.z
27
+ .object({
28
+ parenttype: zod_1.z.string(),
29
+ parentfield: zod_1.z.string(),
30
+ })
31
+ .describe("Sales Order");
32
+ exports.DocTypeChildTableEntryMeta = exports.DocTypeMeta.merge(ChildTableEntryFieldsMeta).describe("Doc Type Child Table Entry Meta");
33
+ const DocTypeNestedMeta = zod_1.z
34
+ .object({
35
+ old_parent: zod_1.z.string(),
36
+ is_group: zod_1.z.number(),
37
+ lft: zod_1.z.number(),
38
+ rgt: zod_1.z.number(),
39
+ idx: zod_1.z.number(),
40
+ })
41
+ .describe("Sales Order");
42
+ exports.DocTypeNested = exports.DocTypeMeta.merge(DocTypeNestedMeta).describe("Doc Type Nested Meta");
@@ -1,5 +1,5 @@
1
1
  import { TypeOf, ZodTypeAny } from "zod";
2
- interface ERPNextResourceGenericRequestOptions<T extends ZodTypeAny, K extends ZodTypeAny> {
2
+ interface ERPNextResourceGenericRequestOptions<T extends ZodTypeAny> {
3
3
  resourceName: string;
4
4
  resourceId: string;
5
5
  requestMethod: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
@@ -8,7 +8,7 @@ interface ERPNextResourceGenericRequestOptions<T extends ZodTypeAny, K extends Z
8
8
  headers?: Record<string, string>;
9
9
  url?: string;
10
10
  }
11
- interface ERPNextResourceGetRequestOptions<T extends ZodTypeAny, K extends ZodTypeAny> {
11
+ interface ERPNextResourceGetRequestOptions<T extends ZodTypeAny> {
12
12
  resourceName: string;
13
13
  resourceId: string;
14
14
  requestMethod: "GET";
@@ -16,7 +16,7 @@ interface ERPNextResourceGetRequestOptions<T extends ZodTypeAny, K extends ZodTy
16
16
  responseValidationModel?: T | undefined;
17
17
  headers?: Record<string, string>;
18
18
  }
19
- interface ERPNextResourceGetListRequestOptions<T extends ZodTypeAny, K extends ZodTypeAny> {
19
+ interface ERPNextResourceGetListRequestOptions<T extends ZodTypeAny> {
20
20
  resourceName: string;
21
21
  requestMethod: "GET";
22
22
  responseValidationModel?: T | undefined;
@@ -42,7 +42,7 @@ export interface ERPNextResourcePutRequestOptions<T extends ZodTypeAny, K extend
42
42
  body: K extends undefined ? Partial<TypeOf<T>> : TypeOf<K>;
43
43
  headers?: Record<string, string>;
44
44
  }
45
- export interface ERPNextResourceDeleteRequestOptions<T extends ZodTypeAny, K extends ZodTypeAny> {
45
+ export interface ERPNextResourceDeleteRequestOptions<T extends ZodTypeAny> {
46
46
  resourceName: string;
47
47
  resourceId?: string;
48
48
  requestMethod: "DELETE";
@@ -59,5 +59,5 @@ export interface ERPNextMethodRequestOptions<T extends ZodTypeAny, K extends Zod
59
59
  params?: string;
60
60
  headers?: Record<string, string>;
61
61
  }
62
- export type ERPNextRequestOptions<T extends ZodTypeAny, K extends ZodTypeAny> = ERPNextResourceGetRequestOptions<T, K> | ERPNextResourceGetListRequestOptions<T, K> | ERPNextResourcePostRequestOptions<T, K> | ERPNextResourcePutRequestOptions<T, K> | ERPNextResourceDeleteRequestOptions<T, K> | ERPNextMethodRequestOptions<T, K> | ERPNextResourceGenericRequestOptions<T, K>;
62
+ export type ERPNextRequestOptions<T extends ZodTypeAny, K extends ZodTypeAny> = ERPNextResourceGetRequestOptions<T> | ERPNextResourceGetListRequestOptions<T> | ERPNextResourcePostRequestOptions<T, K> | ERPNextResourcePutRequestOptions<T, K> | ERPNextResourceDeleteRequestOptions<T> | ERPNextMethodRequestOptions<T, K> | ERPNextResourceGenericRequestOptions<T>;
63
63
  export {};
@@ -1,12 +1,5 @@
1
1
  import { z } from "zod";
2
2
  export declare const ERPNextFile: z.ZodObject<{
3
- name: z.ZodString;
4
- owner: z.ZodString;
5
- creation: z.ZodString;
6
- modified: z.ZodString;
7
- modified_by: z.ZodString;
8
- idx: z.ZodNumber;
9
- docstatus: z.ZodNumber;
10
3
  file_name: z.ZodNullable<z.ZodOptional<z.ZodString>>;
11
4
  is_private: z.ZodNumber;
12
5
  is_home_folder: z.ZodNumber;
@@ -21,16 +14,7 @@ export declare const ERPNextFile: z.ZodObject<{
21
14
  s3_file_key: z.ZodNullable<z.ZodOptional<z.ZodString>>;
22
15
  uploaded_to_dropbox: z.ZodNumber;
23
16
  uploaded_to_google_drive: z.ZodNumber;
24
- doctype: z.ZodString;
25
17
  }, "strip", z.ZodTypeAny, {
26
- name: string;
27
- doctype: string;
28
- owner: string;
29
- creation: string;
30
- modified: string;
31
- modified_by: string;
32
- idx: number;
33
- docstatus: number;
34
18
  is_private: number;
35
19
  is_home_folder: number;
36
20
  is_attachments_folder: number;
@@ -46,14 +30,6 @@ export declare const ERPNextFile: z.ZodObject<{
46
30
  content_hash?: string | null | undefined;
47
31
  s3_file_key?: string | null | undefined;
48
32
  }, {
49
- name: string;
50
- doctype: string;
51
- owner: string;
52
- creation: string;
53
- modified: string;
54
- modified_by: string;
55
- idx: number;
56
- docstatus: number;
57
33
  is_private: number;
58
34
  is_home_folder: number;
59
35
  is_attachments_folder: number;
@@ -71,13 +47,6 @@ export declare const ERPNextFile: z.ZodObject<{
71
47
  }>;
72
48
  export type ERPNextFileType = z.infer<typeof ERPNextFile>;
73
49
  export declare const ERPNextValidatedFile: z.ZodObject<Omit<{
74
- name: z.ZodString;
75
- owner: z.ZodString;
76
- creation: z.ZodString;
77
- modified: z.ZodString;
78
- modified_by: z.ZodString;
79
- idx: z.ZodNumber;
80
- docstatus: z.ZodNumber;
81
50
  file_name: z.ZodNullable<z.ZodOptional<z.ZodString>>;
82
51
  is_private: z.ZodNumber;
83
52
  is_home_folder: z.ZodNumber;
@@ -92,19 +61,10 @@ export declare const ERPNextValidatedFile: z.ZodObject<Omit<{
92
61
  s3_file_key: z.ZodNullable<z.ZodOptional<z.ZodString>>;
93
62
  uploaded_to_dropbox: z.ZodNumber;
94
63
  uploaded_to_google_drive: z.ZodNumber;
95
- doctype: z.ZodString;
96
64
  }, "file_name" | "file_url"> & {
97
65
  file_name: z.ZodString;
98
66
  file_url: z.ZodString;
99
67
  }, "strip", z.ZodTypeAny, {
100
- name: string;
101
- doctype: string;
102
- owner: string;
103
- creation: string;
104
- modified: string;
105
- modified_by: string;
106
- idx: number;
107
- docstatus: number;
108
68
  file_name: string;
109
69
  file_url: string;
110
70
  is_private: number;
@@ -120,14 +80,6 @@ export declare const ERPNextValidatedFile: z.ZodObject<Omit<{
120
80
  content_hash?: string | null | undefined;
121
81
  s3_file_key?: string | null | undefined;
122
82
  }, {
123
- name: string;
124
- doctype: string;
125
- owner: string;
126
- creation: string;
127
- modified: string;
128
- modified_by: string;
129
- idx: number;
130
- docstatus: number;
131
83
  file_name: string;
132
84
  file_url: string;
133
85
  is_private: number;
@@ -4,13 +4,6 @@ exports.ERPNextValidatedFile = exports.ERPNextFile = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.ERPNextFile = zod_1.z
6
6
  .object({
7
- name: zod_1.z.string(),
8
- owner: zod_1.z.string(),
9
- creation: zod_1.z.string(),
10
- modified: zod_1.z.string(),
11
- modified_by: zod_1.z.string(),
12
- idx: zod_1.z.number(),
13
- docstatus: zod_1.z.number(),
14
7
  file_name: zod_1.z.string().optional().nullable(),
15
8
  is_private: zod_1.z.number(),
16
9
  is_home_folder: zod_1.z.number(),
@@ -25,7 +18,6 @@ exports.ERPNextFile = zod_1.z
25
18
  s3_file_key: zod_1.z.string().optional().nullable(),
26
19
  uploaded_to_dropbox: zod_1.z.number(),
27
20
  uploaded_to_google_drive: zod_1.z.number(),
28
- doctype: zod_1.z.string(),
29
21
  })
30
22
  .describe("ERPNextFile");
31
23
  exports.ERPNextValidatedFile = exports.ERPNextFile.omit({