@bizone-ai/json-transform-utils 1.10.0

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 (160) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -0
  3. package/dist/ParseContext.d.ts +23 -0
  4. package/dist/ParseContext.d.ts.map +1 -0
  5. package/dist/ParseContext.js +69 -0
  6. package/dist/ParseContext.js.map +1 -0
  7. package/dist/__tests__/functions/functionsParser.test.d.ts +2 -0
  8. package/dist/__tests__/functions/functionsParser.test.d.ts.map +1 -0
  9. package/dist/__tests__/functions/functionsParser.test.js +787 -0
  10. package/dist/__tests__/functions/functionsParser.test.js.map +1 -0
  11. package/dist/__tests__/jsonpath/jsonpathJoin.test.d.ts +2 -0
  12. package/dist/__tests__/jsonpath/jsonpathJoin.test.d.ts.map +1 -0
  13. package/dist/__tests__/jsonpath/jsonpathJoin.test.js +27 -0
  14. package/dist/__tests__/jsonpath/jsonpathJoin.test.js.map +1 -0
  15. package/dist/__tests__/parse.test.d.ts +2 -0
  16. package/dist/__tests__/parse.test.d.ts.map +1 -0
  17. package/dist/__tests__/parse.test.js +22 -0
  18. package/dist/__tests__/parse.test.js.map +1 -0
  19. package/dist/__tests__/utils/convert.test.d.ts +2 -0
  20. package/dist/__tests__/utils/convert.test.d.ts.map +1 -0
  21. package/dist/__tests__/utils/convert.test.js +181 -0
  22. package/dist/__tests__/utils/convert.test.js.map +1 -0
  23. package/dist/functions/ContextVariablesSchemas.d.ts +3 -0
  24. package/dist/functions/ContextVariablesSchemas.d.ts.map +1 -0
  25. package/dist/functions/ContextVariablesSchemas.js +9 -0
  26. package/dist/functions/ContextVariablesSchemas.js.map +1 -0
  27. package/dist/functions/definitions.d.ts +4 -0
  28. package/dist/functions/definitions.d.ts.map +1 -0
  29. package/dist/functions/definitions.js +2090 -0
  30. package/dist/functions/definitions.js.map +1 -0
  31. package/dist/functions/examples/and.json +44 -0
  32. package/dist/functions/examples/at.json +156 -0
  33. package/dist/functions/examples/avg.json +78 -0
  34. package/dist/functions/examples/base64.json +368 -0
  35. package/dist/functions/examples/boolean.json +236 -0
  36. package/dist/functions/examples/coalesce.json +58 -0
  37. package/dist/functions/examples/concat.json +70 -0
  38. package/dist/functions/examples/contains.json +61 -0
  39. package/dist/functions/examples/csv.json +116 -0
  40. package/dist/functions/examples/csvparse.json +97 -0
  41. package/dist/functions/examples/date.json +389 -0
  42. package/dist/functions/examples/decimal.json +102 -0
  43. package/dist/functions/examples/digest.json +125 -0
  44. package/dist/functions/examples/distinct.json +142 -0
  45. package/dist/functions/examples/entries.json +88 -0
  46. package/dist/functions/examples/eval.json +72 -0
  47. package/dist/functions/examples/every.json +96 -0
  48. package/dist/functions/examples/filter.json +51 -0
  49. package/dist/functions/examples/find.json +51 -0
  50. package/dist/functions/examples/findindex.json +61 -0
  51. package/dist/functions/examples/flat.json +74 -0
  52. package/dist/functions/examples/flatten.json +76 -0
  53. package/dist/functions/examples/form.json +60 -0
  54. package/dist/functions/examples/formparse.json +62 -0
  55. package/dist/functions/examples/group.json +208 -0
  56. package/dist/functions/examples/if.json +294 -0
  57. package/dist/functions/examples/indexof.json +48 -0
  58. package/dist/functions/examples/is.json +512 -0
  59. package/dist/functions/examples/isnull.json +51 -0
  60. package/dist/functions/examples/join.json +221 -0
  61. package/dist/functions/examples/jsonparse.json +101 -0
  62. package/dist/functions/examples/jsonpatch.json +30 -0
  63. package/dist/functions/examples/jsonpath.json +62 -0
  64. package/dist/functions/examples/jsonpointer.json +77 -0
  65. package/dist/functions/examples/jwtparse.json +54 -0
  66. package/dist/functions/examples/length.json +202 -0
  67. package/dist/functions/examples/long.json +53 -0
  68. package/dist/functions/examples/lookup.json +223 -0
  69. package/dist/functions/examples/lower.json +24 -0
  70. package/dist/functions/examples/map.json +188 -0
  71. package/dist/functions/examples/match.json +62 -0
  72. package/dist/functions/examples/matchall.json +62 -0
  73. package/dist/functions/examples/math.json +1073 -0
  74. package/dist/functions/examples/max.json +104 -0
  75. package/dist/functions/examples/merge.json +173 -0
  76. package/dist/functions/examples/min.json +104 -0
  77. package/dist/functions/examples/normalize.json +142 -0
  78. package/dist/functions/examples/not.json +99 -0
  79. package/dist/functions/examples/numberformat.json +162 -0
  80. package/dist/functions/examples/numberparse.json +72 -0
  81. package/dist/functions/examples/object.json +148 -0
  82. package/dist/functions/examples/or.json +102 -0
  83. package/dist/functions/examples/pad.json +102 -0
  84. package/dist/functions/examples/partition.json +32 -0
  85. package/dist/functions/examples/range.json +188 -0
  86. package/dist/functions/examples/raw.json +58 -0
  87. package/dist/functions/examples/reduce.json +79 -0
  88. package/dist/functions/examples/repeat.json +59 -0
  89. package/dist/functions/examples/replace.json +92 -0
  90. package/dist/functions/examples/reverse.json +94 -0
  91. package/dist/functions/examples/slice.json +360 -0
  92. package/dist/functions/examples/some.json +96 -0
  93. package/dist/functions/examples/sort.json +353 -0
  94. package/dist/functions/examples/split.json +52 -0
  95. package/dist/functions/examples/string.json +95 -0
  96. package/dist/functions/examples/substring.json +82 -0
  97. package/dist/functions/examples/sum.json +108 -0
  98. package/dist/functions/examples/switch.json +78 -0
  99. package/dist/functions/examples/template.json +125 -0
  100. package/dist/functions/examples/test.json +82 -0
  101. package/dist/functions/examples/transform.json +58 -0
  102. package/dist/functions/examples/trim.json +44 -0
  103. package/dist/functions/examples/unflatten.json +97 -0
  104. package/dist/functions/examples/upper.json +24 -0
  105. package/dist/functions/examples/uriparse.json +52 -0
  106. package/dist/functions/examples/urldecode.json +42 -0
  107. package/dist/functions/examples/urlencode.json +43 -0
  108. package/dist/functions/examples/uuid.json +142 -0
  109. package/dist/functions/examples/value.json +87 -0
  110. package/dist/functions/examples/wrap.json +122 -0
  111. package/dist/functions/examples/xml.json +142 -0
  112. package/dist/functions/examples/xmlparse.json +161 -0
  113. package/dist/functions/examples/xor.json +166 -0
  114. package/dist/functions/examples/yaml.json +196 -0
  115. package/dist/functions/examples/yamlparse.json +150 -0
  116. package/dist/functions/examples.d.ts +4 -0
  117. package/dist/functions/examples.d.ts.map +1 -0
  118. package/dist/functions/examples.js +178 -0
  119. package/dist/functions/examples.js.map +1 -0
  120. package/dist/functions/functions.d.ts +3 -0
  121. package/dist/functions/functions.d.ts.map +1 -0
  122. package/dist/functions/functions.js +9 -0
  123. package/dist/functions/functions.js.map +1 -0
  124. package/dist/functions/functionsParser.d.ts +45 -0
  125. package/dist/functions/functionsParser.d.ts.map +1 -0
  126. package/dist/functions/functionsParser.js +207 -0
  127. package/dist/functions/functionsParser.js.map +1 -0
  128. package/dist/functions/parseDefinitions.d.ts +4 -0
  129. package/dist/functions/parseDefinitions.d.ts.map +1 -0
  130. package/dist/functions/parseDefinitions.js +56 -0
  131. package/dist/functions/parseDefinitions.js.map +1 -0
  132. package/dist/functions/types.d.ts +163 -0
  133. package/dist/functions/types.d.ts.map +1 -0
  134. package/dist/functions/types.js +93 -0
  135. package/dist/functions/types.js.map +1 -0
  136. package/dist/index.d.ts +14 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +36 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/jsonpath/jsonpathFunctions.d.ts +4 -0
  141. package/dist/jsonpath/jsonpathFunctions.d.ts.map +1 -0
  142. package/dist/jsonpath/jsonpathFunctions.js +26 -0
  143. package/dist/jsonpath/jsonpathFunctions.js.map +1 -0
  144. package/dist/jsonpath/jsonpathJoin.d.ts +3 -0
  145. package/dist/jsonpath/jsonpathJoin.d.ts.map +1 -0
  146. package/dist/jsonpath/jsonpathJoin.js +15 -0
  147. package/dist/jsonpath/jsonpathJoin.js.map +1 -0
  148. package/dist/parse.d.ts +12 -0
  149. package/dist/parse.d.ts.map +1 -0
  150. package/dist/parse.js +522 -0
  151. package/dist/parse.js.map +1 -0
  152. package/dist/transformUtils.d.ts +40 -0
  153. package/dist/transformUtils.d.ts.map +1 -0
  154. package/dist/transformUtils.js +89 -0
  155. package/dist/transformUtils.js.map +1 -0
  156. package/dist/utils/convert.d.ts +3 -0
  157. package/dist/utils/convert.d.ts.map +1 -0
  158. package/dist/utils/convert.js +163 -0
  159. package/dist/utils/convert.js.map +1 -0
  160. package/package.json +44 -0
@@ -0,0 +1,70 @@
1
+ [
2
+ {
3
+ "name": "object - 2 arrays",
4
+ "given": {
5
+ "input": [["a", "b", "c"], ["d", "e", "f"]],
6
+ "definition": { "$$concat": ["$[0]", "$[1]"] }
7
+ },
8
+ "expect": {
9
+ "equal": ["a", "b", "c", "d", "e", "f"]
10
+ }
11
+ },
12
+ {
13
+ "name": "object - keep nulls",
14
+ "given": {
15
+ "input": [["a", "b", "c"], ["d", "e", "f"]],
16
+ "definition": {
17
+ "$$concat": [
18
+ ["a", null, "c"],
19
+ ["d", "e", null]
20
+ ]
21
+ }
22
+ },
23
+ "expect": {
24
+ "equal": ["a", null, "c", "d", "e", null]
25
+ }
26
+ },
27
+ {
28
+ "name": "object - skip nulls",
29
+ "given": {
30
+ "input": null,
31
+ "definition": {
32
+ "$$concat": [
33
+ [
34
+ "a",
35
+ "b",
36
+ "c"
37
+ ],
38
+ null
39
+ ]
40
+ }
41
+ },
42
+ "expect": {
43
+ "equal": [
44
+ "a",
45
+ "b",
46
+ "c"
47
+ ]
48
+ }
49
+ },
50
+ {
51
+ "name": "object - append non nulls",
52
+ "given": {
53
+ "input": null,
54
+ "definition": { "$$concat": [["a", "b", "c"], "d", ["e"]] }
55
+ },
56
+ "expect": {
57
+ "equal": ["a", "b", "c", "d", "e"]
58
+ }
59
+ },
60
+ {
61
+ "name": "object - blind concat",
62
+ "given": {
63
+ "input": [["a", "b", "c"], "d", ["e"]],
64
+ "definition": { "$$concat": "$" }
65
+ },
66
+ "expect": {
67
+ "equal": ["a", "b", "c", "d", "e"]
68
+ }
69
+ }
70
+ ]
@@ -0,0 +1,61 @@
1
+ [
2
+ {
3
+ "name": "object - positive",
4
+ "given": {
5
+ "input": [0, [], "a"],
6
+ "definition": {
7
+ "$$contains": "$",
8
+ "that": "a"
9
+ }
10
+ },
11
+ "expect": {
12
+ "equal": true
13
+ }
14
+ },
15
+ {
16
+ "name": "object - positive (with transformation)",
17
+ "given": {
18
+ "input": "a",
19
+ "definition": {
20
+ "$$contains": ["b", "$"],
21
+ "that": "a"
22
+ }
23
+ },
24
+ "expect": {
25
+ "equal": true
26
+ }
27
+ },
28
+ {
29
+ "name": "object - negative",
30
+ "given": {
31
+ "input": [0, [], "a"],
32
+ "definition": {
33
+ "$$contains": "$",
34
+ "that": "b"
35
+ }
36
+ },
37
+ "expect": {
38
+ "equal": false
39
+ }
40
+ },
41
+ {
42
+ "name": "inline - positive",
43
+ "given": {
44
+ "input": [0, [], "a"],
45
+ "definition": "$$contains(a):$"
46
+ },
47
+ "expect": {
48
+ "equal": true
49
+ }
50
+ },
51
+ {
52
+ "name": "inline - negative",
53
+ "given": {
54
+ "input": [0, [], "a"],
55
+ "definition": "$$contains(b):$"
56
+ },
57
+ "expect": {
58
+ "equal": false
59
+ }
60
+ }
61
+ ]
@@ -0,0 +1,116 @@
1
+ [
2
+ {
3
+ "name": "inline - with headers",
4
+ "given": {
5
+ "input": [
6
+ { "a": "A", "b": 1 },
7
+ { "a": "C", "b": 2 }
8
+ ],
9
+ "definition": "$$csv:$"
10
+ },
11
+ "expect": {
12
+ "equal": "a,b\nA,1\nC,2\n",
13
+ "format": "csv"
14
+ }
15
+ },
16
+ {
17
+ "name": "inline - no headers",
18
+ "given": {
19
+ "input": [
20
+ { "a": "A", "b": 1 },
21
+ { "a": "C", "b": 2 }
22
+ ],
23
+ "definition": "$$csv(true):$"
24
+ },
25
+ "expect": {
26
+ "equal": "A,1\nC,2\n",
27
+ "format": "csv"
28
+ }
29
+ },
30
+ {
31
+ "name": "object - with headers",
32
+ "given": {
33
+ "input": [
34
+ { "a": "A", "b": 1 },
35
+ { "a": "C", "b": 2 }
36
+ ],
37
+ "definition": {
38
+ "$$csv": "$"
39
+ }
40
+ },
41
+ "expect": {
42
+ "equal": "a,b\nA,1\nC,2\n",
43
+ "format": "csv"
44
+ }
45
+ },
46
+ {
47
+ "name": "object - no headers",
48
+ "given": {
49
+ "input": [
50
+ { "a": "A", "b": 1 },
51
+ { "a": "C", "b": 2 }
52
+ ],
53
+ "definition": {
54
+ "$$csv": "$",
55
+ "no_headers": true
56
+ }
57
+ },
58
+ "expect": {
59
+ "equal": "A,1\nC,2\n",
60
+ "format": "csv"
61
+ }
62
+ },
63
+ {
64
+ "name": "object - arrays input with names",
65
+ "given": {
66
+ "input": [
67
+ [1, 2],
68
+ [3, 4]
69
+ ],
70
+ "definition": {
71
+ "$$csv": "$",
72
+ "names": ["a", "b"]
73
+ }
74
+ },
75
+ "expect": {
76
+ "equal": "a,b\n1,2\n3,4\n",
77
+ "format": "csv"
78
+ }
79
+ },
80
+ {
81
+ "name": "object - arrays input, without names",
82
+ "given": {
83
+ "input": [
84
+ [1, 2],
85
+ [3, 4]
86
+ ],
87
+ "definition": {
88
+ "$$csv": "$"
89
+ }
90
+ },
91
+ "expect": {
92
+ "equal": "1,2\n3,4\n",
93
+ "format": "csv"
94
+ }
95
+ },
96
+ {
97
+ "name": "inline - no_headers and force_quote",
98
+ "given": {
99
+ "input": [
100
+ {
101
+ "a": "A",
102
+ "b": 1
103
+ },
104
+ {
105
+ "a": "C",
106
+ "b": 2
107
+ }
108
+ ],
109
+ "definition": "$$csv(true, true):$"
110
+ },
111
+ "expect": {
112
+ "equal": "\"A\",\"1\"\n\"C\",\"2\"\n",
113
+ "format": "csv"
114
+ }
115
+ }
116
+ ]
@@ -0,0 +1,97 @@
1
+ [
2
+ {
3
+ "name": "Inline - parse CSV with comma as a value",
4
+ "given": {
5
+ "input": "a\n\",\"",
6
+ "inputFormat": "csv",
7
+ "definition": "$$csvparse:$"
8
+ },
9
+ "expect": {
10
+ "equal": [
11
+ {
12
+ "a": ","
13
+ }
14
+ ]
15
+ }
16
+ },
17
+ {
18
+ "name": "Inline - parse CSV with escaped double quotes",
19
+ "given": {
20
+ "input": "a\n\"\"\"\"",
21
+ "inputFormat": "csv",
22
+ "definition": "$$csvparse:$"
23
+ },
24
+ "expect": {
25
+ "equal": [
26
+ {
27
+ "a": "\""
28
+ }
29
+ ]
30
+ }
31
+ },
32
+ {
33
+ "name": "Inline - parse CSV into array format",
34
+ "given": {
35
+ "input": "1,2\n3,4",
36
+ "inputFormat": "csv",
37
+ "definition": "$$csvparse(true):$"
38
+ },
39
+ "expect": {
40
+ "equal": [
41
+ ["1", "2"],
42
+ ["3", "4"]
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "name": "Object - parse CSV with comma as a value",
48
+ "given": {
49
+ "input": "a\n\",\"",
50
+ "inputFormat": "csv",
51
+ "definition": {
52
+ "$$csvparse": "$"
53
+ }
54
+ },
55
+ "expect": {
56
+ "equal": [
57
+ {
58
+ "a": ","
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ {
64
+ "name": "Object - parse CSV with escaped double quotes",
65
+ "given": {
66
+ "input": "a\n\"\"\"\"",
67
+ "inputFormat": "csv",
68
+ "definition": {
69
+ "$$csvparse": "$"
70
+ }
71
+ },
72
+ "expect": {
73
+ "equal": [
74
+ {
75
+ "a": "\""
76
+ }
77
+ ]
78
+ }
79
+ },
80
+ {
81
+ "name": "Object - parse CSV with escaped double quotes",
82
+ "given": {
83
+ "input": "1,2\n3,4",
84
+ "inputFormat": "csv",
85
+ "definition": {
86
+ "$$csvparse": "$",
87
+ "no_headers": true
88
+ }
89
+ },
90
+ "expect": {
91
+ "equal": [
92
+ ["1", "2"],
93
+ ["3", "4"]
94
+ ]
95
+ }
96
+ }
97
+ ]