tally-xml-tdl 1.6.3 → 1.13.2
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/index.d.ts +5 -0
- package/package.json +11 -4
- package/src/index.js +2 -2
- package/src/v13/body.json +78 -0
- package/src/v13/body.xml +25 -0
- package/src/v13/company.js +30 -0
- package/src/v13/core/buildXml.js +9 -0
- package/src/v13/core/changeType/v1/changeTypeString.js +111 -0
- package/src/v13/core/changeType/v2/changeTypeString.js +111 -0
- package/src/v13/core/changeType/v3/alterLeaf.js +45 -0
- package/src/v13/core/changeType/v3/changeTypeString.js +21 -0
- package/src/v13/core/changeType/v3/forArray/v1/index.js +17 -0
- package/src/v13/core/changeType/v3/forObject/v1/index.js +19 -0
- package/src/v13/core/changeType/v3/guards.js +26 -0
- package/src/v13/core/changeType/v3/traverse.js +47 -0
- package/src/v13/core/cleanTallyResponse.js +58 -0
- package/src/v13/core/execute/executeBody.js +23 -0
- package/src/v13/core/execute/executeXml.js +16 -0
- package/src/v13/core/execute/executeXmlAndClean.js +15 -0
- package/src/v13/core/execute/index.js +3 -0
- package/src/v13/core/index.js +20 -0
- package/src/v13/core/request/envelope.js +86 -0
- package/src/v13/core/request/index.js +6 -0
- package/src/v13/core/request/jsonToXml.js +19 -0
- package/src/v13/core/response/index.js +2 -0
- package/src/v13/core/response/xmlToJson.js +18 -0
- package/src/v13/core/transport/http.js +40 -0
- package/src/v13/core/transport/index.js +1 -0
- package/src/v13/daybook/body copy.xml +16 -0
- package/src/v13/daybook/body.xml +30 -0
- package/src/v13/fromJson.js +86 -0
- package/src/v13/fromXml.js +30 -0
- package/src/v13/index.d.ts +13 -0
- package/src/v13/index.js +92 -0
- package/src/v13/main.d.ts +2 -0
- package/src/v13/main.js +4 -0
- package/src/v13/purc/body.json +36 -0
- package/src/v13/purc/body.xml +28 -0
- package/src/v13/purchases/v1.xml +30 -0
- package/src/v13/purchases.js +30 -0
- package/src/v6/index.js +0 -5
package/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export function company(showLog?: boolean): Promise<any>;
|
|
2
|
+
export default company;
|
|
3
|
+
|
|
1
4
|
export interface V6Options {
|
|
2
5
|
company: string;
|
|
3
6
|
jsonId: string;
|
|
@@ -8,3 +11,5 @@ export function get<T = any>(options?: V6Options): Promise<T>;
|
|
|
8
11
|
export function clean<T = any>(options?: V6Options): Promise<T>;
|
|
9
12
|
|
|
10
13
|
export * as v6 from "./src/v6/index.js";
|
|
14
|
+
export * as v13 from "./src/v13/main.js";
|
|
15
|
+
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tally-xml-tdl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.2",
|
|
4
4
|
"description": "Simple, clean TDL and XML extraction and manipulation tools for Tally",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
6
|
+
"main": "src/v13/main.js",
|
|
7
|
+
"module": "./src/v13/main.js",
|
|
7
8
|
"types": "index.d.ts",
|
|
8
9
|
"sideEffects": false,
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"types": "./index.d.ts",
|
|
12
|
-
"import": "./
|
|
13
|
-
"default": "./
|
|
13
|
+
"import": "./src/v13/main.js",
|
|
14
|
+
"default": "./src/v13/main.js"
|
|
15
|
+
},
|
|
16
|
+
"./v13": {
|
|
17
|
+
"types": "./src/v13/main.d.ts",
|
|
18
|
+
"import": "./src/v13/main.js",
|
|
19
|
+
"default": "./src/v13/main.js"
|
|
14
20
|
},
|
|
15
21
|
"./v6": {
|
|
16
22
|
"types": "./src/v6/index.d.ts",
|
|
@@ -19,6 +25,7 @@
|
|
|
19
25
|
}
|
|
20
26
|
},
|
|
21
27
|
"files": [
|
|
28
|
+
"src/v13",
|
|
22
29
|
"src/v6",
|
|
23
30
|
"src/index.js",
|
|
24
31
|
"index.js",
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * as
|
|
1
|
+
export * from "./v13/main.js";
|
|
2
|
+
export * as v13 from "./v13/main.js";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"company": {
|
|
3
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
4
|
+
"tdlMessage": "<TYPE>Company</TYPE><FETCH>$$Alias:Name</FETCH>"
|
|
5
|
+
},
|
|
6
|
+
"uom": {
|
|
7
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
8
|
+
"tdlMessage": "<TYPE>Unit</TYPE><FETCH>$$Alias:Name</FETCH>"
|
|
9
|
+
},
|
|
10
|
+
"stockItems": {
|
|
11
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
12
|
+
"tdlMessage": "<TYPE>StockItem</TYPE><FETCH>$$Alias:Name</FETCH>"
|
|
13
|
+
},
|
|
14
|
+
"stockItemsWithBaseUnits": {
|
|
15
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
16
|
+
"tdlMessage": "<TYPE>StockItem</TYPE><FETCH>$$Alias:Name</FETCH><FETCH>BaseUnits</FETCH>"
|
|
17
|
+
},
|
|
18
|
+
"ledgerNames": {
|
|
19
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
20
|
+
"tdlMessage": "<TYPE>Ledger</TYPE><FETCH>$$Alias:Name</FETCH>"
|
|
21
|
+
},
|
|
22
|
+
"ledgerNamesWithDetails": {
|
|
23
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
24
|
+
"tdlMessage": "<TYPE>Ledger</TYPE><FETCH>$$Alias:Name</FETCH><FETCH>GSTRegistrationType</FETCH><FETCH>GSTIN</FETCH>"
|
|
25
|
+
},
|
|
26
|
+
"ledgerNamesMoreDetails": {
|
|
27
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
28
|
+
"tdlMessage": "<TYPE>Ledger</TYPE><FETCH>$$Alias:Name</FETCH><FETCH>LEDGSTREGDETAILS.LIST</FETCH>"
|
|
29
|
+
},
|
|
30
|
+
"stockGroups": {
|
|
31
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
32
|
+
"tdlMessage": "<TYPE>StockGroup</TYPE><FETCH>$$Alias:Name</FETCH>"
|
|
33
|
+
},
|
|
34
|
+
"stockGroupsAndParent": {
|
|
35
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
36
|
+
"tdlMessage": "<TYPE>StockGroup</TYPE><FETCH>$$Alias:Name</FETCH><FETCH>Parent</FETCH>"
|
|
37
|
+
},
|
|
38
|
+
"purchases1": {
|
|
39
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>30-Apr-2026</SVTODATE>",
|
|
40
|
+
"tdlMessage": "<TYPE>Voucher</TYPE><FILTER>$$IsPurchase:$VoucherTypeName</FILTER><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH><FETCH>PartyLedgerName</FETCH><FETCH>Amount</FETCH>"
|
|
41
|
+
},
|
|
42
|
+
"purchases2": {
|
|
43
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>30-Apr-2026</SVTODATE>",
|
|
44
|
+
"tdlMessage": "<TYPE>Vouchers:VoucherType</TYPE><CHILDOF>$$VchTypePurchase</CHILDOF><BELONGSTO>Yes</BELONGSTO><FETCH>Date, VoucherNumber, VoucherTypeName, PartyLedgerName, AllInventoryEntries</FETCH>"
|
|
45
|
+
},
|
|
46
|
+
"purchases3": {
|
|
47
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>1-Apr-2026</SVTODATE>",
|
|
48
|
+
"tdlMessage": "<TYPE>Voucher</TYPE><SYSTEM TYPE=\"Formulae\" NAME=\"DateFilter\">$Date >= ##SVFROMDATE AND $Date <= ##SVTODATE</SYSTEM><FILTER>DateFilter</FILTER><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH><FETCH>PartyLedgerName</FETCH><FETCH>AllInventoryEntries</FETCH>"
|
|
49
|
+
},
|
|
50
|
+
"purchases4": {
|
|
51
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>1-Apr-2026</SVTODATE>",
|
|
52
|
+
"tdlMessage": "<SYSTEM TYPE=\"Formula\" NAME=\"DateFilter\">$Date >= ##SVFROMDATE AND $Date <= ##SVTODATE</SYSTEM><COLLECTION NAME=\"KeshavPurchases\"><TYPE>Voucher</TYPE><FILTER>DateFilter</FILTER><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH><FETCH>PartyLedgerName</FETCH><FETCH>AllInventoryEntries</FETCH></COLLECTION>"
|
|
53
|
+
},
|
|
54
|
+
"purchases5": {
|
|
55
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>1-Apr-2026</SVTODATE>",
|
|
56
|
+
"tdlMessage": "<SYSTEM TYPE=\"Formulae\" NAME=\"DateFilter\">$Date >= ##SVFROMDATE AND $Date <= ##SVTODATE</SYSTEM><COLLECTION NAME=\"KeshavPurchases\"><TYPE>Voucher</TYPE><FILTER>DateFilter</FILTER><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH><FETCH>PartyLedgerName</FETCH><FETCH>AllInventoryEntries</FETCH></COLLECTION>"
|
|
57
|
+
},
|
|
58
|
+
"purchases6": {
|
|
59
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>1-Apr-2026</SVTODATE>",
|
|
60
|
+
"tdlMessage": "<COLLECTION NAME=\"KeshavPurchases\"><TYPE>Voucher</TYPE><FILTERS>DateFilter</FILTERS><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH><FETCH>PartyLedgerName</FETCH><FETCH>AllInventoryEntries</FETCH></COLLECTION><SYSTEM TYPE=\"Formulae\" NAME=\"DateFilter\">$Date >= ##SVFROMDATE AND $Date <= ##SVTODATE</SYSTEM>"
|
|
61
|
+
},
|
|
62
|
+
"purchases7": {
|
|
63
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE>1-Apr-2026</SVFROMDATE><SVTODATE>1-Apr-2026</SVTODATE>",
|
|
64
|
+
"tdlMessage": "<COLLECTION NAME=\"KeshavPurchases\"><TYPE>Voucher</TYPE><FILTERS>DateFilter</FILTERS><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH><FETCH>PartyLedgerName</FETCH><FETCH>AllInventoryEntries</FETCH></COLLECTION><SYSTEM TYPE=\"Formulae\" NAME=\"DateFilter\">$Date >= ##SVFROMDATE AND $Date <= ##SVTODATE</SYSTEM>"
|
|
65
|
+
},
|
|
66
|
+
"purchases8": {
|
|
67
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
68
|
+
"tdlMessage": "<COLLECTION NAME=\"KeshavPurchases\"><TYPE>Voucher</TYPE><FETCH>Date</FETCH><FETCH>VoucherNumber</FETCH><FETCH>VoucherTypeName</FETCH></COLLECTION>"
|
|
69
|
+
},
|
|
70
|
+
"purchases9": {
|
|
71
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>",
|
|
72
|
+
"tdlMessage": "<COLLECTION NAME=\"KeshavPurchaseInventory\"><TYPE>Vouchers:VoucherType</TYPE><CHILDOF>$$VchTypePurchase</CHILDOF><BELONGSTO>Yes</BELONGSTO><FETCH>Date, VoucherNumber, VoucherTypeName, PartyLedgerName, AllInventoryEntries</FETCH></COLLECTION>"
|
|
73
|
+
},
|
|
74
|
+
"purchases": {
|
|
75
|
+
"staticVariables": "<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE TYPE=\"Date\">4-Sep-2026</SVFROMDATE><SVTODATE TYPE=\"Date\">4-Sep-2026</SVTODATE>",
|
|
76
|
+
"tdlMessage": "<TYPE>Vouchers:VoucherType</TYPE><CHILDOF>$$VchTypePurchase</CHILDOF><BELONGSTO>Yes</BELONGSTO><FETCH>AllInventoryEntries</FETCH><FETCH>Date</FETCH>"
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/v13/body.xml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<ENVELOPE>
|
|
2
|
+
<HEADER>
|
|
3
|
+
<VERSION>1</VERSION>
|
|
4
|
+
<TALLYREQUEST>Export</TALLYREQUEST>
|
|
5
|
+
<TYPE>Collection</TYPE>
|
|
6
|
+
<ID>TDLID</ID>
|
|
7
|
+
</HEADER>
|
|
8
|
+
|
|
9
|
+
<BODY>
|
|
10
|
+
<DESC>
|
|
11
|
+
<STATICVARIABLES>
|
|
12
|
+
<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
|
|
13
|
+
{{STATICVARIABLES}}
|
|
14
|
+
</STATICVARIABLES>
|
|
15
|
+
|
|
16
|
+
<TDL>
|
|
17
|
+
<TDLMESSAGE>
|
|
18
|
+
<COLLECTION NAME="TDLID">
|
|
19
|
+
{{TDLMESSAGE}}
|
|
20
|
+
</COLLECTION>
|
|
21
|
+
</TDLMESSAGE>
|
|
22
|
+
</TDL>
|
|
23
|
+
</DESC>
|
|
24
|
+
</BODY>
|
|
25
|
+
</ENVELOPE>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
import { executeXmlAndClean } from "./core/index.js";
|
|
6
|
+
import { buildXml } from "./core/buildXml.js";
|
|
7
|
+
import bodyJson from "./body.json" with {type: "json"};
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const body = fs.readFileSync(path.join(__dirname, "body.xml"), "utf8");
|
|
11
|
+
|
|
12
|
+
const startFunc = async (showLog = false) => {
|
|
13
|
+
const jsonId = "company";
|
|
14
|
+
|
|
15
|
+
const { tdlMessage } = bodyJson[jsonId];
|
|
16
|
+
if (showLog) console.log("tdlMessage : ", tdlMessage);
|
|
17
|
+
|
|
18
|
+
const xml = buildXml(body, {
|
|
19
|
+
tdlMessage
|
|
20
|
+
});
|
|
21
|
+
if (showLog) console.log("xml : ", xml);
|
|
22
|
+
const jsonToReturn = await executeXmlAndClean(xml);
|
|
23
|
+
if (showLog) console.log("jsonToReturn : ", jsonToReturn);
|
|
24
|
+
// const firstRow = jsonToReturn[0];
|
|
25
|
+
// const { "@_NAME": name, "@_RESERVEDNAME": reservedName } = firstRow;
|
|
26
|
+
|
|
27
|
+
return jsonToReturn;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default startFunc;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Story of Tally Type Conversion:
|
|
3
|
+
*
|
|
4
|
+
* Act 1 - The XML Artifacts:
|
|
5
|
+
* Tally XML represents typed primitive fields with attributes such as `@_TYPE="String"`,
|
|
6
|
+
* `@_TYPE="Date"`, or `@_TYPE="Logical"`. The XML parser converts these tags into
|
|
7
|
+
* objects where `#text` holds the actual content and `@_TYPE` holds the data type.
|
|
8
|
+
* Tags with empty content (e.g. <SERIALMASTER TYPE="String"/>) result in objects
|
|
9
|
+
* containing only `@_TYPE` without a `#text` key.
|
|
10
|
+
*
|
|
11
|
+
* Act 2 - The String Story:
|
|
12
|
+
* When `@_TYPE === "String"`, we extract `#text` as a clean string.
|
|
13
|
+
* If `#text` is missing (empty element), we normalize it to an empty string `""`
|
|
14
|
+
* rather than keeping the unparsed metadata object.
|
|
15
|
+
*
|
|
16
|
+
* Act 3 - The Date Story:
|
|
17
|
+
* When `@_TYPE === "Date"`, Tally returns dates in YYYYMMDD format (e.g., 20260904).
|
|
18
|
+
* XML parsers often parse this as a numeric literal (20260904). We safely normalize
|
|
19
|
+
* this into a clean string representation `'20260904'` for consistent date formatting.
|
|
20
|
+
*
|
|
21
|
+
* Act 4 - Logical & Other Primitives:
|
|
22
|
+
* When `@_TYPE === "Logical"` (values like 'Yes' / 'No') or other typed fields,
|
|
23
|
+
* we unwrap `#text` to its plain scalar value while leaving nested child arrays
|
|
24
|
+
* (e.g., inventory lines, ledger entries) intact.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes a single field value based on its Tally XML type.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} params
|
|
31
|
+
* @param {*} params.inValue - The field value to inspect and transform.
|
|
32
|
+
* @returns {*} The cleaned scalar or original complex structure.
|
|
33
|
+
*/
|
|
34
|
+
const handleValue = ({ inValue }) => {
|
|
35
|
+
const localValue = inValue;
|
|
36
|
+
|
|
37
|
+
// Preserve null, undefined, primitives, and nested arrays (e.g. ALLINVENTORYENTRIES.LIST)
|
|
38
|
+
if (!localValue || typeof localValue !== "object" || Array.isArray(localValue)) {
|
|
39
|
+
return localValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Process Tally typed objects with @_TYPE
|
|
43
|
+
if ("@_TYPE" in localValue) {
|
|
44
|
+
const type = localValue["@_TYPE"];
|
|
45
|
+
const hasText = "#text" in localValue;
|
|
46
|
+
const rawText = localValue["#text"];
|
|
47
|
+
|
|
48
|
+
// Act 2 fallback: Empty tags (<FIELD TYPE="..."/>) have no #text
|
|
49
|
+
if (!hasText) {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
switch (type) {
|
|
54
|
+
// Act 2: String types
|
|
55
|
+
case "String":
|
|
56
|
+
return String(rawText);
|
|
57
|
+
|
|
58
|
+
// Act 3: Date types (normalize numbers like 20260904 to string '20260904')
|
|
59
|
+
case "Date":
|
|
60
|
+
return String(rawText);
|
|
61
|
+
|
|
62
|
+
// Act 4: Logical types ('Yes' / 'No')
|
|
63
|
+
case "Logical":
|
|
64
|
+
return String(rawText);
|
|
65
|
+
|
|
66
|
+
// Other types (Number, Amount, Rate, etc.)
|
|
67
|
+
default:
|
|
68
|
+
return rawText;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return localValue;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Transforms an array of rows by converting Tally typed objects into clean values.
|
|
77
|
+
*
|
|
78
|
+
* @param {object|Array} input - Either { inArray: Array } or positional Array.
|
|
79
|
+
* @returns {Array} Array of cleaned rows.
|
|
80
|
+
*/
|
|
81
|
+
const changeTypeString = (input) => {
|
|
82
|
+
// Supports both { inArray } parameter convention and direct array argument
|
|
83
|
+
let localArray = Array.isArray(input) ? input : input?.inArray;
|
|
84
|
+
|
|
85
|
+
if (!localArray) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!Array.isArray(localArray)) {
|
|
90
|
+
localArray = [localArray];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const newArray = localArray.map(row => {
|
|
94
|
+
if (!row || typeof row !== "object") {
|
|
95
|
+
return row;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const result = {};
|
|
99
|
+
|
|
100
|
+
for (const [key, value] of Object.entries(row)) {
|
|
101
|
+
result[key] = handleValue({ inValue: value });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return result;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return newArray;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default changeTypeString;
|
|
111
|
+
export { changeTypeString };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Story of Tally Type Conversion:
|
|
3
|
+
*
|
|
4
|
+
* Act 1 - The XML Artifacts:
|
|
5
|
+
* Tally XML represents typed primitive fields with attributes such as `@_TYPE="String"`,
|
|
6
|
+
* `@_TYPE="Date"`, or `@_TYPE="Logical"`. The XML parser converts these tags into
|
|
7
|
+
* objects where `#text` holds the actual content and `@_TYPE` holds the data type.
|
|
8
|
+
* Tags with empty content (e.g. <SERIALMASTER TYPE="String"/>) result in objects
|
|
9
|
+
* containing only `@_TYPE` without a `#text` key.
|
|
10
|
+
*
|
|
11
|
+
* Act 2 - The String Story:
|
|
12
|
+
* When `@_TYPE === "String"`, we extract `#text` as a clean string.
|
|
13
|
+
* If `#text` is missing (empty element), we normalize it to an empty string `""`
|
|
14
|
+
* rather than keeping the unparsed metadata object.
|
|
15
|
+
*
|
|
16
|
+
* Act 3 - The Date Story:
|
|
17
|
+
* When `@_TYPE === "Date"`, Tally returns dates in YYYYMMDD format (e.g., 20260904).
|
|
18
|
+
* XML parsers often parse this as a numeric literal (20260904). We safely normalize
|
|
19
|
+
* this into a clean string representation `'20260904'` for consistent date formatting.
|
|
20
|
+
*
|
|
21
|
+
* Act 4 - Logical & Other Primitives:
|
|
22
|
+
* When `@_TYPE === "Logical"` (values like 'Yes' / 'No') or other typed fields,
|
|
23
|
+
* we unwrap `#text` to its plain scalar value while leaving nested child arrays
|
|
24
|
+
* (e.g., inventory lines, ledger entries) intact.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes a single field value based on its Tally XML type.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} params
|
|
31
|
+
* @param {*} params.inValue - The field value to inspect and transform.
|
|
32
|
+
* @returns {*} The cleaned scalar or original complex structure.
|
|
33
|
+
*/
|
|
34
|
+
const handleValue = ({ inValue }) => {
|
|
35
|
+
const localValue = inValue;
|
|
36
|
+
|
|
37
|
+
// Preserve null, undefined, primitives, and nested arrays (e.g. ALLINVENTORYENTRIES.LIST)
|
|
38
|
+
if (!localValue || typeof localValue !== "object" || Array.isArray(localValue)) {
|
|
39
|
+
return localValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Process Tally typed objects with @_TYPE
|
|
43
|
+
if ("@_TYPE" in localValue) {
|
|
44
|
+
const type = localValue["@_TYPE"];
|
|
45
|
+
const hasText = "#text" in localValue;
|
|
46
|
+
const rawText = localValue["#text"];
|
|
47
|
+
|
|
48
|
+
// Act 2 fallback: Empty tags (<FIELD TYPE="..."/>) have no #text
|
|
49
|
+
if (!hasText) {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
switch (type) {
|
|
54
|
+
// Act 2: String types
|
|
55
|
+
case "String":
|
|
56
|
+
return String(rawText);
|
|
57
|
+
|
|
58
|
+
// Act 3: Date types (normalize numbers like 20260904 to string '20260904')
|
|
59
|
+
case "Date":
|
|
60
|
+
return String(rawText);
|
|
61
|
+
|
|
62
|
+
// Act 4: Logical types ('Yes' / 'No')
|
|
63
|
+
case "Logical":
|
|
64
|
+
return String(rawText);
|
|
65
|
+
|
|
66
|
+
// Other types (Number, Amount, Rate, etc.)
|
|
67
|
+
default:
|
|
68
|
+
return rawText;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return localValue;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Transforms an array of rows by converting Tally typed objects into clean values.
|
|
77
|
+
*
|
|
78
|
+
* @param {object|Array} input - Either { inArray: Array } or positional Array.
|
|
79
|
+
* @returns {Array} Array of cleaned rows.
|
|
80
|
+
*/
|
|
81
|
+
const changeTypeString = (input) => {
|
|
82
|
+
// Supports both { inArray } parameter convention and direct array argument
|
|
83
|
+
let localArray = Array.isArray(input) ? input : input?.inArray;
|
|
84
|
+
|
|
85
|
+
if (!localArray) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!Array.isArray(localArray)) {
|
|
90
|
+
localArray = [localArray];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const newArray = localArray.map(row => {
|
|
94
|
+
if (!row || typeof row !== "object") {
|
|
95
|
+
return row;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const result = {};
|
|
99
|
+
|
|
100
|
+
for (const [key, value] of Object.entries(row)) {
|
|
101
|
+
result[key] = handleValue({ inValue: value });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return result;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return newArray;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default changeTypeString;
|
|
111
|
+
export { changeTypeString };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unwraps Tally XML typed objects and normalizes them into clean scalars.
|
|
3
|
+
*
|
|
4
|
+
* Removes @_TYPE (String, Date, Number, Logical, Rate, etc.) and extracts #text.
|
|
5
|
+
* Empty tags (<TAG TYPE="..."/>) without #text normalize to empty string "".
|
|
6
|
+
*
|
|
7
|
+
* @param {object} params
|
|
8
|
+
* @param {object} params.inValue - Typed object containing @_TYPE.
|
|
9
|
+
* @returns {*} Clean scalar value.
|
|
10
|
+
*/
|
|
11
|
+
const alterLeaf = ({ inValue }) => {
|
|
12
|
+
const localValue = inValue;
|
|
13
|
+
|
|
14
|
+
if (!localValue || typeof localValue !== "object") {
|
|
15
|
+
return localValue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if ("@_TYPE" in localValue) {
|
|
19
|
+
const type = String(localValue["@_TYPE"] || "").toLowerCase();
|
|
20
|
+
const hasText = "#text" in localValue;
|
|
21
|
+
const rawText = localValue["#text"];
|
|
22
|
+
|
|
23
|
+
if (!hasText || rawText === undefined || rawText === null) {
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
switch (type) {
|
|
28
|
+
case "string":
|
|
29
|
+
case "date":
|
|
30
|
+
case "logical":
|
|
31
|
+
case "rate":
|
|
32
|
+
return String(rawText);
|
|
33
|
+
case "number":
|
|
34
|
+
case "amount":
|
|
35
|
+
case "quantity":
|
|
36
|
+
return rawText;
|
|
37
|
+
default:
|
|
38
|
+
return rawText;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return localValue;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default alterLeaf;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import traverse from "./traverse.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Traverses an array of Tally collection rows recursively to remove all @_TYPE
|
|
5
|
+
* objects (Date, String, Number, Logical, Rate, etc.) throughout the entire tree.
|
|
6
|
+
*
|
|
7
|
+
* @param {object|Array} input - Either { inArray: Array } or Array directly.
|
|
8
|
+
* @returns {Array} Fully cleaned array of rows.
|
|
9
|
+
*/
|
|
10
|
+
const changeTypeString = (input) => {
|
|
11
|
+
const localArray = Array.isArray(input) ? input : (input?.inArray ?? input);
|
|
12
|
+
|
|
13
|
+
if (!localArray) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return traverse({ inData: localArray });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default changeTypeString;
|
|
21
|
+
export { changeTypeString };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import traverse from "../../traverse.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ inDataAsArray }) => {
|
|
4
|
+
const localDataAsArray = inDataAsArray;
|
|
5
|
+
|
|
6
|
+
if (!Array.isArray(localDataAsArray)) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const childrenArray = localDataAsArray.map(element => {
|
|
11
|
+
return traverse({ inData: element });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return childrenArray;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default startFunc;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import traverse from "../../traverse.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ inDataAsObject }) => {
|
|
4
|
+
const localDataAsObject = inDataAsObject;
|
|
5
|
+
|
|
6
|
+
if (localDataAsObject === null || typeof localDataAsObject !== "object") {
|
|
7
|
+
return localDataAsObject;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const result = {};
|
|
11
|
+
|
|
12
|
+
for (const [key, value] of Object.entries(localDataAsObject)) {
|
|
13
|
+
result[key] = traverse({ inData: value });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default startFunc;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const isNullOrUndefined = ({ inData }) => {
|
|
2
|
+
const localData = inData;
|
|
3
|
+
return localData === null || localData === undefined;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const isArray = ({ inData }) => {
|
|
7
|
+
const localData = inData;
|
|
8
|
+
return Array.isArray(localData);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const isObject = ({ inData }) => {
|
|
12
|
+
const localData = inData;
|
|
13
|
+
return localData !== null && typeof localData === "object" && !Array.isArray(localData);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const isTallyType = ({ inData }) => {
|
|
17
|
+
const localData = inData;
|
|
18
|
+
return isObject({ inData: localData }) && "@_TYPE" in localData;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
isNullOrUndefined,
|
|
23
|
+
isArray,
|
|
24
|
+
isObject,
|
|
25
|
+
isTallyType
|
|
26
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isNullOrUndefined,
|
|
3
|
+
isArray,
|
|
4
|
+
isObject,
|
|
5
|
+
isTallyType
|
|
6
|
+
} from "./guards.js";
|
|
7
|
+
import forArray from "./forArray/v1/index.js";
|
|
8
|
+
import forObject from "./forObject/v1/index.js";
|
|
9
|
+
import alterLeaf from "./alterLeaf.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Central recursive dispatcher adapted from jsonToSpec traversal architecture.
|
|
13
|
+
*
|
|
14
|
+
* Recursively walks JSON trees of arbitrary depth.
|
|
15
|
+
* Leaf nodes containing Tally type wrappers (@_TYPE) are unwrapped and normalized.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} params
|
|
18
|
+
* @param {*} params.inData - Node or subtree to traverse.
|
|
19
|
+
* @returns {*} Cleaned node or subtree.
|
|
20
|
+
*/
|
|
21
|
+
const traverse = ({ inData }) => {
|
|
22
|
+
const localData = inData;
|
|
23
|
+
|
|
24
|
+
if (isNullOrUndefined({ inData: localData })) {
|
|
25
|
+
return localData;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Leaf node: Tally typed object with @_TYPE
|
|
29
|
+
if (isTallyType({ inData: localData })) {
|
|
30
|
+
return alterLeaf({ inValue: localData });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Branch node: Array
|
|
34
|
+
if (isArray({ inData: localData })) {
|
|
35
|
+
return forArray({ inDataAsArray: localData });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Branch node: Object
|
|
39
|
+
if (isObject({ inData: localData })) {
|
|
40
|
+
return forObject({ inDataAsObject: localData });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Primitive values (string, number, boolean)
|
|
44
|
+
return localData;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default traverse;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import changeTypeString from "./changeType/v3/changeTypeString.js";
|
|
2
|
+
|
|
3
|
+
const showLog = true;
|
|
4
|
+
|
|
5
|
+
const pullKey = (inCollection) => {
|
|
6
|
+
let collection = inCollection;
|
|
7
|
+
// console.log("collection : ", collection);
|
|
8
|
+
|
|
9
|
+
if (!collection || typeof collection !== "object") {
|
|
10
|
+
return { key: undefined, rows: undefined };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const [key, rows] = Object.entries(collection).find(
|
|
14
|
+
([key, value]) =>
|
|
15
|
+
!key.startsWith("@") &&
|
|
16
|
+
Array.isArray(value)
|
|
17
|
+
) ?? [];
|
|
18
|
+
|
|
19
|
+
return { key, rows };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const cleanTallyResponse = (json) => {
|
|
23
|
+
// console.log("json : ", json);
|
|
24
|
+
|
|
25
|
+
const data = json?.ENVELOPE?.BODY?.DATA;
|
|
26
|
+
if (showLog) console.log("data : ", data);
|
|
27
|
+
|
|
28
|
+
let collection = data?.COLLECTION;
|
|
29
|
+
if (showLog) console.log("collection1 : ", collection);
|
|
30
|
+
|
|
31
|
+
const originalKeys = Object.keys(collection);
|
|
32
|
+
|
|
33
|
+
if (originalKeys.length === 1) {
|
|
34
|
+
collection[originalKeys[0]] = [collection[originalKeys[0]]];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (showLog) console.log("originalKeys : ", originalKeys);
|
|
38
|
+
|
|
39
|
+
const { key, rows } = pullKey(collection);
|
|
40
|
+
if (showLog) console.log("collection1 : ", key, rows);
|
|
41
|
+
const neededArray = rows;
|
|
42
|
+
// console.log("neededArray : ", neededArray[1]);
|
|
43
|
+
|
|
44
|
+
if (!Array.isArray(neededArray)) {
|
|
45
|
+
return neededArray;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const changedArray = changeTypeString(neededArray);
|
|
49
|
+
|
|
50
|
+
if (changedArray?.[1]?.["ALLINVENTORYENTRIES.LIST"]?.[0]?.["BATCHALLOCATIONS.LIST"]) {
|
|
51
|
+
console.log("changedArray=-------- : ", changedArray[1]["ALLINVENTORYENTRIES.LIST"][0]["BATCHALLOCATIONS.LIST"]);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return changedArray;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default cleanTallyResponse;
|
|
58
|
+
export { cleanTallyResponse };
|