@sankhyalabs/sankhyablocks 1.1.27 → 1.3.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 (237) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +75 -75
  3. package/dist/cjs/index-4720dab8.js +735 -0
  4. package/dist/cjs/loader.cjs.js +3 -3
  5. package/dist/cjs/sankhyablocks.cjs.js +3 -3
  6. package/dist/cjs/snk-application.cjs.entry.js +954 -656
  7. package/dist/collection/collection-manifest.json +6 -35
  8. package/dist/collection/components/snk-application/snk-application.css +5 -5
  9. package/dist/collection/components/snk-application/snk-application.js +492 -495
  10. package/dist/collection/index.js +1 -1
  11. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +158 -158
  12. package/dist/collection/lib/http/data-fetcher/fetchers/application-config-fetcher.js +23 -23
  13. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +188 -188
  14. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +25 -25
  15. package/dist/collection/lib/http/data-fetcher/fetchers/grid-config-fetcher.js +2 -2
  16. package/dist/collection/lib/http/data-fetcher/fetchers/parameters-fecher.js +59 -59
  17. package/dist/collection/lib/http/data-fetcher/fetchers/resource-fetcher.js +30 -30
  18. package/dist/collection/lib/http/data-fetcher/state/LoadStateManager.js +66 -66
  19. package/dist/collection/lib/utils/pesquisa.js +16 -16
  20. package/dist/collection/lib/utils/urlutils.js +23 -23
  21. package/dist/collection/lib/workspace/workspace.js +7 -7
  22. package/dist/components/snk-application.js +945 -647
  23. package/dist/esm/index-72d4e2e0.js +709 -0
  24. package/dist/esm/loader.js +3 -3
  25. package/dist/esm/polyfills/core-js.js +0 -0
  26. package/dist/esm/polyfills/dom.js +0 -0
  27. package/dist/esm/polyfills/es5-html-element.js +0 -0
  28. package/dist/esm/polyfills/index.js +0 -0
  29. package/dist/esm/polyfills/system.js +0 -0
  30. package/dist/esm/sankhyablocks.js +3 -3
  31. package/dist/esm/snk-application.entry.js +916 -618
  32. package/dist/sankhyablocks/p-5d8ddbda.entry.js +57 -0
  33. package/dist/sankhyablocks/p-a33afc3b.js +2 -0
  34. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  35. package/dist/types/components/snk-application/snk-application.d.ts +44 -44
  36. package/dist/types/components.d.ts +6 -2
  37. package/dist/types/index.d.ts +1 -1
  38. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +15 -15
  39. package/dist/types/lib/http/data-fetcher/fetchers/application-config-fetcher.d.ts +6 -6
  40. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +12 -12
  41. package/dist/types/lib/http/data-fetcher/fetchers/form-config-fetcher.d.ts +5 -5
  42. package/dist/types/lib/http/data-fetcher/fetchers/grid-config-fetcher.d.ts +2 -2
  43. package/dist/types/lib/http/data-fetcher/fetchers/parameters-fecher.d.ts +13 -13
  44. package/dist/types/lib/http/data-fetcher/fetchers/resource-fetcher.d.ts +6 -6
  45. package/dist/types/lib/http/data-fetcher/state/LoadStateManager.d.ts +23 -23
  46. package/dist/types/lib/utils/pesquisa.d.ts +2 -2
  47. package/dist/types/lib/utils/urlutils.d.ts +4 -4
  48. package/dist/types/lib/workspace/workspace.d.ts +4 -4
  49. package/package.json +63 -52
  50. package/react/.keepfolder +1 -0
  51. package/react/components.d.ts +3 -32
  52. package/react/components.js +5 -34
  53. package/react/components.js.map +1 -1
  54. package/react/react-component-lib/createComponent.d.ts +10 -10
  55. package/react/react-component-lib/createComponent.js +58 -74
  56. package/react/react-component-lib/createComponent.js.map +1 -1
  57. package/react/react-component-lib/createOverlayComponent.d.ts +20 -21
  58. package/react/react-component-lib/createOverlayComponent.js +88 -108
  59. package/react/react-component-lib/createOverlayComponent.js.map +1 -1
  60. package/react/react-component-lib/index.d.ts +2 -2
  61. package/react/react-component-lib/index.js +2 -2
  62. package/react/react-component-lib/interfaces.d.ts +29 -29
  63. package/react/react-component-lib/utils/attachProps.d.ts +12 -12
  64. package/react/react-component-lib/utils/attachProps.js +95 -97
  65. package/react/react-component-lib/utils/attachProps.js.map +1 -1
  66. package/react/react-component-lib/utils/case.d.ts +2 -2
  67. package/react/react-component-lib/utils/case.js +6 -6
  68. package/react/react-component-lib/utils/dev.d.ts +2 -2
  69. package/react/react-component-lib/utils/dev.js +12 -12
  70. package/react/react-component-lib/utils/index.d.ts +7 -10
  71. package/react/react-component-lib/utils/index.js +20 -33
  72. package/react/react-component-lib/utils/index.js.map +1 -1
  73. package/dist/cjs/ApplicationUtils-05b74ee9.js +0 -39
  74. package/dist/cjs/AssetsUtils-bd004f63.js +0 -24
  75. package/dist/cjs/CSSVarsUtils-75ca9c64.js +0 -19
  76. package/dist/cjs/_commonjsHelpers-537d719a.js +0 -20
  77. package/dist/cjs/ez-action-chip.cjs.entry.js +0 -27
  78. package/dist/cjs/ez-application.cjs.entry.js +0 -26
  79. package/dist/cjs/ez-button_4.cjs.entry.js +0 -660
  80. package/dist/cjs/ez-calendar.cjs.entry.js +0 -223
  81. package/dist/cjs/ez-collapsible-box.cjs.entry.js +0 -47
  82. package/dist/cjs/ez-combo-box.cjs.entry.js +0 -278
  83. package/dist/cjs/ez-date-input.cjs.entry.js +0 -102
  84. package/dist/cjs/ez-date-time-input.cjs.entry.js +0 -145
  85. package/dist/cjs/ez-dialog.cjs.entry.js +0 -89
  86. package/dist/cjs/ez-form.cjs.entry.js +0 -785
  87. package/dist/cjs/ez-grid.cjs.entry.js +0 -110485
  88. package/dist/cjs/ez-icon.cjs.entry.js +0 -41
  89. package/dist/cjs/ez-label-chip.cjs.entry.js +0 -104
  90. package/dist/cjs/ez-modal_2.cjs.entry.js +0 -316
  91. package/dist/cjs/ez-number-input.cjs.entry.js +0 -86
  92. package/dist/cjs/ez-popover.cjs.entry.js +0 -120
  93. package/dist/cjs/ez-popup.cjs.entry.js +0 -48
  94. package/dist/cjs/ez-search.cjs.entry.js +0 -64
  95. package/dist/cjs/ez-tabselector.cjs.entry.js +0 -198
  96. package/dist/cjs/ez-text-area.cjs.entry.js +0 -114
  97. package/dist/cjs/ez-text-input.cjs.entry.js +0 -201
  98. package/dist/cjs/ez-time-input.cjs.entry.js +0 -118
  99. package/dist/cjs/ez-toast.cjs.entry.js +0 -44
  100. package/dist/cjs/ez-upload.cjs.entry.js +0 -356
  101. package/dist/cjs/index-6ac5268e.js +0 -1769
  102. package/dist/cjs/test-du.cjs.entry.js +0 -76
  103. package/dist/components/ApplicationUtils.js +0 -37
  104. package/dist/components/AssetsUtils.js +0 -22
  105. package/dist/components/CSSVarsUtils.js +0 -17
  106. package/dist/components/_commonjsHelpers.js +0 -17
  107. package/dist/components/ez-action-chip.js +0 -44
  108. package/dist/components/ez-application.js +0 -39
  109. package/dist/components/ez-button.js +0 -6
  110. package/dist/components/ez-button2.js +0 -105
  111. package/dist/components/ez-calendar.js +0 -6
  112. package/dist/components/ez-calendar2.js +0 -242
  113. package/dist/components/ez-check.js +0 -6
  114. package/dist/components/ez-check2.js +0 -94
  115. package/dist/components/ez-collapsible-box.js +0 -67
  116. package/dist/components/ez-combo-box.js +0 -6
  117. package/dist/components/ez-combo-box2.js +0 -311
  118. package/dist/components/ez-date-input.js +0 -135
  119. package/dist/components/ez-date-time-input.js +0 -179
  120. package/dist/components/ez-dialog.js +0 -124
  121. package/dist/components/ez-form.js +0 -6
  122. package/dist/components/ez-form2.js +0 -807
  123. package/dist/components/ez-grid.js +0 -110576
  124. package/dist/components/ez-icon.js +0 -6
  125. package/dist/components/ez-icon2.js +0 -56
  126. package/dist/components/ez-label-chip.js +0 -125
  127. package/dist/components/ez-list.js +0 -6
  128. package/dist/components/ez-list2.js +0 -523
  129. package/dist/components/ez-modal.js +0 -6
  130. package/dist/components/ez-modal2.js +0 -82
  131. package/dist/components/ez-number-input.js +0 -115
  132. package/dist/components/ez-popover.js +0 -145
  133. package/dist/components/ez-popup.js +0 -67
  134. package/dist/components/ez-search.js +0 -100
  135. package/dist/components/ez-tabselector.js +0 -6
  136. package/dist/components/ez-tabselector2.js +0 -213
  137. package/dist/components/ez-text-area.js +0 -137
  138. package/dist/components/ez-text-input.js +0 -6
  139. package/dist/components/ez-text-input2.js +0 -223
  140. package/dist/components/ez-time-input.js +0 -153
  141. package/dist/components/ez-toast.js +0 -64
  142. package/dist/components/ez-upload.js +0 -382
  143. package/dist/components/grid-config.js +0 -6
  144. package/dist/components/grid-config2.js +0 -318
  145. package/dist/components/select-box.js +0 -6
  146. package/dist/components/select-box2.js +0 -47
  147. package/dist/components/test-du.js +0 -101
  148. package/dist/esm/ApplicationUtils-e0b6d857.js +0 -37
  149. package/dist/esm/AssetsUtils-98074c9c.js +0 -22
  150. package/dist/esm/CSSVarsUtils-0787c3f3.js +0 -17
  151. package/dist/esm/_commonjsHelpers-9943807e.js +0 -17
  152. package/dist/esm/ez-action-chip.entry.js +0 -23
  153. package/dist/esm/ez-application.entry.js +0 -22
  154. package/dist/esm/ez-button_4.entry.js +0 -653
  155. package/dist/esm/ez-calendar.entry.js +0 -219
  156. package/dist/esm/ez-collapsible-box.entry.js +0 -43
  157. package/dist/esm/ez-combo-box.entry.js +0 -274
  158. package/dist/esm/ez-date-input.entry.js +0 -98
  159. package/dist/esm/ez-date-time-input.entry.js +0 -141
  160. package/dist/esm/ez-dialog.entry.js +0 -85
  161. package/dist/esm/ez-form.entry.js +0 -781
  162. package/dist/esm/ez-grid.entry.js +0 -110481
  163. package/dist/esm/ez-icon.entry.js +0 -37
  164. package/dist/esm/ez-label-chip.entry.js +0 -100
  165. package/dist/esm/ez-modal_2.entry.js +0 -311
  166. package/dist/esm/ez-number-input.entry.js +0 -82
  167. package/dist/esm/ez-popover.entry.js +0 -116
  168. package/dist/esm/ez-popup.entry.js +0 -44
  169. package/dist/esm/ez-search.entry.js +0 -60
  170. package/dist/esm/ez-tabselector.entry.js +0 -194
  171. package/dist/esm/ez-text-area.entry.js +0 -110
  172. package/dist/esm/ez-text-input.entry.js +0 -197
  173. package/dist/esm/ez-time-input.entry.js +0 -114
  174. package/dist/esm/ez-toast.entry.js +0 -40
  175. package/dist/esm/ez-upload.entry.js +0 -352
  176. package/dist/esm/index-df166135.js +0 -1738
  177. package/dist/esm/test-du.entry.js +0 -72
  178. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-action-chip/ez-action-chip.css +0 -67
  179. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-application/ez-application.css +0 -3
  180. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-button/ez-button.css +0 -180
  181. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-calendar/ez-calendar.css +0 -319
  182. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-check/ez-check.css +0 -327
  183. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-collapsible-box/ez-collapsible-box.css +0 -162
  184. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-combo-box/ez-combo-box.css +0 -217
  185. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-input/ez-date-input.css +0 -49
  186. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-time-input/ez-date-time-input.css +0 -44
  187. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-dialog/ez-dialog.css +0 -527
  188. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-form/ez-form.css +0 -5
  189. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/ez-grid.css +0 -31
  190. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.css +0 -129
  191. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/select-box/select-box.css +0 -10
  192. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-icon/ez-icon.css +0 -176
  193. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-label-chip/ez-label-chip.css +0 -139
  194. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-list/ez-list.css +0 -335
  195. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-modal/ez-modal.css +0 -358
  196. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-number-input/ez-number-input.css +0 -4
  197. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popover/ez-popover.css +0 -44
  198. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popup/ez-popup.css +0 -405
  199. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-search/ez-search.css +0 -3
  200. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-tabselector/ez-tabselector.css +0 -138
  201. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-area/ez-text-area.css +0 -165
  202. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-input/ez-text-input.css +0 -196
  203. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-time-input/ez-time-input.css +0 -10
  204. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-toast/ez-toast.css +0 -127
  205. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-upload/ez-upload.css +0 -568
  206. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/test-du/test-du.css +0 -3
  207. package/dist/sankhyablocks/p-08e1cded.entry.js +0 -1
  208. package/dist/sankhyablocks/p-0a77ac95.entry.js +0 -57
  209. package/dist/sankhyablocks/p-112455b1.js +0 -1
  210. package/dist/sankhyablocks/p-126c4aaa.entry.js +0 -1
  211. package/dist/sankhyablocks/p-1421b89a.entry.js +0 -1
  212. package/dist/sankhyablocks/p-1beadcaf.entry.js +0 -1
  213. package/dist/sankhyablocks/p-1c423f5d.entry.js +0 -1
  214. package/dist/sankhyablocks/p-28a0dbf0.entry.js +0 -1
  215. package/dist/sankhyablocks/p-4763d5c2.js +0 -1
  216. package/dist/sankhyablocks/p-4c66200a.entry.js +0 -1
  217. package/dist/sankhyablocks/p-5dc772be.entry.js +0 -1
  218. package/dist/sankhyablocks/p-5ff3e300.entry.js +0 -1
  219. package/dist/sankhyablocks/p-7122cec4.entry.js +0 -1
  220. package/dist/sankhyablocks/p-811b4b9d.js +0 -1
  221. package/dist/sankhyablocks/p-813fe4f7.js +0 -1
  222. package/dist/sankhyablocks/p-9b33a005.entry.js +0 -1
  223. package/dist/sankhyablocks/p-9e22ec87.entry.js +0 -1
  224. package/dist/sankhyablocks/p-9f7239df.entry.js +0 -1
  225. package/dist/sankhyablocks/p-9f7e6e48.js +0 -1
  226. package/dist/sankhyablocks/p-a47e0537.entry.js +0 -1
  227. package/dist/sankhyablocks/p-a9aba60a.entry.js +0 -1
  228. package/dist/sankhyablocks/p-afda7940.entry.js +0 -1
  229. package/dist/sankhyablocks/p-b3a83eaf.entry.js +0 -1
  230. package/dist/sankhyablocks/p-b96a8d40.entry.js +0 -1
  231. package/dist/sankhyablocks/p-c61c0e40.entry.js +0 -1
  232. package/dist/sankhyablocks/p-ca29d028.entry.js +0 -1
  233. package/dist/sankhyablocks/p-cd17abb1.entry.js +0 -1
  234. package/dist/sankhyablocks/p-d3a5366d.entry.js +0 -369
  235. package/dist/sankhyablocks/p-d5703a41.entry.js +0 -1
  236. package/dist/sankhyablocks/p-e5f77a59.entry.js +0 -1
  237. package/dist/sankhyablocks/p-e9e94d51.entry.js +0 -1
@@ -1,188 +1,188 @@
1
- import { DataUnit, ChangeOperation, } from "@sankhyalabs/core";
2
- import { HttpFetcher } from "../DataFetcher";
3
- import { gql } from "graphql-request";
4
- export default class DataUnitFetcher {
5
- constructor() {
6
- this.templateByQuery = new Map();
7
- this.buldTemplates();
8
- }
9
- buldTemplates() {
10
- this.templateByQuery.set("fetchDataUnit", gql `query($name: String!) {
11
- $queryAlias$: fetchDataUnit(name: $name){
12
- name
13
- fields{
14
- name
15
- defaultValue
16
- label
17
- readOnly
18
- required
19
- dataType
20
- userInterface
21
- properties{
22
- name
23
- value
24
- }
25
- dependencies{
26
- masterFields
27
- type
28
- expression
29
- }
30
- }
31
- }
32
- }`);
33
- this.templateByQuery.set("fetchData", gql `query($dataunit: String! $first: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
34
- $queryAlias$: fetchDataUnit(name: $dataunit){
35
- data(first: $first offset: $offset filters: $filter sort: $sort){
36
- first
37
- offset
38
- total
39
- hasMore
40
- records{
41
- id
42
- fields {
43
- name
44
- value
45
- }
46
- }
47
- }
48
- }
49
- }`);
50
- this.templateByQuery.set("saveData", gql `mutation($changes: [Change!]!) {
51
- $queryAlias$: saveDataUnitChanges(changes: $changes){
52
- oldId
53
- id
54
- fields {
55
- name
56
- value
57
- }
58
- }
59
- }`);
60
- }
61
- getDataUnit(entityName, resourceID) {
62
- const dataUnit = new DataUnit(`dd://${entityName}/${resourceID}`);
63
- dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
64
- dataUnit.dataLoader = (dataUnit, sort, filters) => this.loadData(dataUnit, sort, filters);
65
- dataUnit.saveLoader = (dataUnit, changes) => this.saveData(dataUnit, changes);
66
- dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
67
- return dataUnit;
68
- }
69
- loadMetadata(dataUnit) {
70
- return new Promise((resolve, reject) => {
71
- HttpFetcher.get()
72
- .callGraphQL({
73
- values: { name: dataUnit.name },
74
- query: this.templateByQuery.get("fetchDataUnit"),
75
- })
76
- .then((resp) => {
77
- var _a;
78
- const metadata = {
79
- name: resp.name,
80
- label: resp.name,
81
- fields: [],
82
- };
83
- (_a = resp.fields) === null || _a === void 0 ? void 0 : _a.forEach((source) => {
84
- let properties = undefined;
85
- if (Array.isArray(source.properties)) {
86
- properties = {};
87
- source.properties.forEach((prop) => (properties[prop.name] = prop.value));
88
- }
89
- metadata.fields.push(Object.assign(Object.assign({}, source), { properties }));
90
- });
91
- resolve(metadata);
92
- })
93
- .catch((error) => {
94
- reject(error);
95
- });
96
- });
97
- }
98
- loadData(dataUnit, sort, filters) {
99
- return new Promise((resolve, reject) => {
100
- HttpFetcher.get()
101
- .callGraphQL({
102
- values: { dataunit: dataUnit.name, sort, filters },
103
- query: this.templateByQuery.get("fetchData"),
104
- })
105
- .then((resp) => {
106
- const result = resp.data;
107
- const dataUnitRecords = [];
108
- result.records.forEach((responseRecord) => {
109
- const duRecord = { __record__id__: responseRecord.id };
110
- responseRecord.fields.forEach(({ name, value }) => {
111
- duRecord[name] = dataUnit.valueFromString(name, value);
112
- });
113
- dataUnitRecords.push(duRecord);
114
- });
115
- resolve(dataUnitRecords);
116
- })
117
- .catch((error) => {
118
- reject(error);
119
- });
120
- });
121
- }
122
- saveData(dataUnit, duChanges) {
123
- const changes = duChanges.map((change) => {
124
- const { dataUnit: changeDU, record, updatingFields, operation } = change;
125
- const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
126
- return { fieldName, value: this.formatValueToServer(value) };
127
- });
128
- return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
129
- });
130
- return new Promise((resolve, reject) => {
131
- HttpFetcher.get()
132
- .callGraphQL({
133
- values: { changes: changes },
134
- query: this.templateByQuery.get("saveData"),
135
- })
136
- .then((resp) => {
137
- const dataUnitRecords = [];
138
- resp === null || resp === void 0 ? void 0 : resp.forEach((responseRecord) => {
139
- const duRecord = { __record__id__: responseRecord.id };
140
- if (responseRecord.oldId) {
141
- duRecord.__old__id__ = responseRecord.oldId;
142
- }
143
- responseRecord.fields.forEach(({ name, value }) => {
144
- duRecord[name] = dataUnit.valueFromString(name, value);
145
- });
146
- dataUnitRecords.push(duRecord);
147
- });
148
- resolve(dataUnitRecords);
149
- })
150
- .catch((error) => {
151
- reject(error);
152
- });
153
- });
154
- }
155
- formatValueToServer(value) {
156
- if (value === undefined)
157
- return value;
158
- try {
159
- if (value instanceof Date) {
160
- return value.toString();
161
- }
162
- //Any others objects
163
- value = JSON.stringify(value);
164
- }
165
- catch (_a) {
166
- value = value.toString();
167
- }
168
- return value;
169
- }
170
- removeRecords(dataUnit, recordIds) {
171
- const changes = recordIds.map((recordId) => {
172
- return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
173
- });
174
- return new Promise((resolve, reject) => {
175
- HttpFetcher.get()
176
- .callGraphQL({
177
- values: { changes: changes },
178
- query: this.templateByQuery.get("saveData"),
179
- })
180
- .then((_resp) => {
181
- resolve(recordIds);
182
- })
183
- .catch((error) => {
184
- reject(error);
185
- });
186
- });
187
- }
188
- }
1
+ import { DataUnit, ChangeOperation, } from "@sankhyalabs/core";
2
+ import { HttpFetcher } from "../DataFetcher";
3
+ import { gql } from "graphql-request";
4
+ export default class DataUnitFetcher {
5
+ constructor() {
6
+ this.templateByQuery = new Map();
7
+ this.buldTemplates();
8
+ }
9
+ buldTemplates() {
10
+ this.templateByQuery.set("fetchDataUnit", gql `query($name: String!) {
11
+ $queryAlias$: fetchDataUnit(name: $name){
12
+ name
13
+ fields{
14
+ name
15
+ defaultValue
16
+ label
17
+ readOnly
18
+ required
19
+ dataType
20
+ userInterface
21
+ properties{
22
+ name
23
+ value
24
+ }
25
+ dependencies{
26
+ masterFields
27
+ type
28
+ expression
29
+ }
30
+ }
31
+ }
32
+ }`);
33
+ this.templateByQuery.set("fetchData", gql `query($dataunit: String! $first: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
34
+ $queryAlias$: fetchDataUnit(name: $dataunit){
35
+ data(first: $first offset: $offset filters: $filter sort: $sort){
36
+ first
37
+ offset
38
+ total
39
+ hasMore
40
+ records{
41
+ id
42
+ fields {
43
+ name
44
+ value
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }`);
50
+ this.templateByQuery.set("saveData", gql `mutation($changes: [Change!]!) {
51
+ $queryAlias$: saveDataUnitChanges(changes: $changes){
52
+ oldId
53
+ id
54
+ fields {
55
+ name
56
+ value
57
+ }
58
+ }
59
+ }`);
60
+ }
61
+ getDataUnit(entityName, resourceID) {
62
+ const dataUnit = new DataUnit(`dd://${entityName}/${resourceID}`);
63
+ dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
64
+ dataUnit.dataLoader = (dataUnit, sort, filters) => this.loadData(dataUnit, sort, filters);
65
+ dataUnit.saveLoader = (dataUnit, changes) => this.saveData(dataUnit, changes);
66
+ dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
67
+ return dataUnit;
68
+ }
69
+ loadMetadata(dataUnit) {
70
+ return new Promise((resolve, reject) => {
71
+ HttpFetcher.get()
72
+ .callGraphQL({
73
+ values: { name: dataUnit.name },
74
+ query: this.templateByQuery.get("fetchDataUnit"),
75
+ })
76
+ .then((resp) => {
77
+ var _a;
78
+ const metadata = {
79
+ name: resp.name,
80
+ label: resp.name,
81
+ fields: [],
82
+ };
83
+ (_a = resp.fields) === null || _a === void 0 ? void 0 : _a.forEach((source) => {
84
+ let properties = undefined;
85
+ if (Array.isArray(source.properties)) {
86
+ properties = {};
87
+ source.properties.forEach((prop) => (properties[prop.name] = prop.value));
88
+ }
89
+ metadata.fields.push(Object.assign(Object.assign({}, source), { properties }));
90
+ });
91
+ resolve(metadata);
92
+ })
93
+ .catch((error) => {
94
+ reject(error);
95
+ });
96
+ });
97
+ }
98
+ loadData(dataUnit, sort, filters) {
99
+ return new Promise((resolve, reject) => {
100
+ HttpFetcher.get()
101
+ .callGraphQL({
102
+ values: { dataunit: dataUnit.name, sort, filters },
103
+ query: this.templateByQuery.get("fetchData"),
104
+ })
105
+ .then((resp) => {
106
+ const result = resp.data;
107
+ const dataUnitRecords = [];
108
+ result.records.forEach((responseRecord) => {
109
+ const duRecord = { __record__id__: responseRecord.id };
110
+ responseRecord.fields.forEach(({ name, value }) => {
111
+ duRecord[name] = dataUnit.valueFromString(name, value);
112
+ });
113
+ dataUnitRecords.push(duRecord);
114
+ });
115
+ resolve(dataUnitRecords);
116
+ })
117
+ .catch((error) => {
118
+ reject(error);
119
+ });
120
+ });
121
+ }
122
+ saveData(dataUnit, duChanges) {
123
+ const changes = duChanges.map((change) => {
124
+ const { dataUnit: changeDU, record, updatingFields, operation } = change;
125
+ const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
126
+ return { fieldName, value: this.formatValueToServer(value) };
127
+ });
128
+ return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
129
+ });
130
+ return new Promise((resolve, reject) => {
131
+ HttpFetcher.get()
132
+ .callGraphQL({
133
+ values: { changes: changes },
134
+ query: this.templateByQuery.get("saveData"),
135
+ })
136
+ .then((resp) => {
137
+ const dataUnitRecords = [];
138
+ resp === null || resp === void 0 ? void 0 : resp.forEach((responseRecord) => {
139
+ const duRecord = { __record__id__: responseRecord.id };
140
+ if (responseRecord.oldId) {
141
+ duRecord.__old__id__ = responseRecord.oldId;
142
+ }
143
+ responseRecord.fields.forEach(({ name, value }) => {
144
+ duRecord[name] = dataUnit.valueFromString(name, value);
145
+ });
146
+ dataUnitRecords.push(duRecord);
147
+ });
148
+ resolve(dataUnitRecords);
149
+ })
150
+ .catch((error) => {
151
+ reject(error);
152
+ });
153
+ });
154
+ }
155
+ formatValueToServer(value) {
156
+ if (value === undefined)
157
+ return value;
158
+ try {
159
+ if (value instanceof Date) {
160
+ return value.toString();
161
+ }
162
+ //Any others objects
163
+ value = JSON.stringify(value);
164
+ }
165
+ catch (_a) {
166
+ value = value.toString();
167
+ }
168
+ return value;
169
+ }
170
+ removeRecords(dataUnit, recordIds) {
171
+ const changes = recordIds.map((recordId) => {
172
+ return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
173
+ });
174
+ return new Promise((resolve, reject) => {
175
+ HttpFetcher.get()
176
+ .callGraphQL({
177
+ values: { changes: changes },
178
+ query: this.templateByQuery.get("saveData"),
179
+ })
180
+ .then((_resp) => {
181
+ resolve(recordIds);
182
+ })
183
+ .catch((error) => {
184
+ reject(error);
185
+ });
186
+ });
187
+ }
188
+ }
@@ -1,25 +1,25 @@
1
- import { ResourceFetcher } from "./resource-fetcher";
2
- export class FormConfigFetcher extends ResourceFetcher {
3
- loadFormConfig(formName, resourceID) {
4
- return new Promise((accept, reject) => {
5
- this.loadResource(`cfg://form/${resourceID}/${formName}`)
6
- .then((configAsString) => {
7
- if (configAsString) {
8
- const config = JSON.parse(configAsString);
9
- const { tabs, fields } = config;
10
- if (tabs) {
11
- const allTabs = new Map(tabs.map(t => [t.label, t]));
12
- fields.forEach(f => f.tab = allTabs.get(f.tab));
13
- }
14
- accept(fields);
15
- }
16
- else {
17
- reject(`Sem configuração pro formulário "${formName}".`);
18
- }
19
- })
20
- .catch((error) => {
21
- reject(error);
22
- });
23
- });
24
- }
25
- }
1
+ import { ResourceFetcher } from "./resource-fetcher";
2
+ export class FormConfigFetcher extends ResourceFetcher {
3
+ loadFormConfig(formName, resourceID) {
4
+ return new Promise((accept, reject) => {
5
+ this.loadResource(`cfg://form/${resourceID}/${formName}`)
6
+ .then((configAsString) => {
7
+ if (configAsString) {
8
+ const config = JSON.parse(configAsString);
9
+ const { tabs, fields } = config;
10
+ if (tabs) {
11
+ const allTabs = new Map(tabs.map(t => [t.label, t]));
12
+ fields.forEach(f => f.tab = allTabs.get(f.tab));
13
+ }
14
+ accept(fields);
15
+ }
16
+ else {
17
+ reject(`Sem configuração pro formulário "${formName}".`);
18
+ }
19
+ })
20
+ .catch((error) => {
21
+ reject(error);
22
+ });
23
+ });
24
+ }
25
+ }
@@ -1,2 +1,2 @@
1
- export class GridConfigFetcher {
2
- }
1
+ export class GridConfigFetcher {
2
+ }
@@ -1,59 +1,59 @@
1
- import { gql } from "graphql-request";
2
- import { DateUtils, StringUtils } from "@sankhyalabs/core";
3
- import { HttpFetcher } from "../DataFetcher";
4
- export default class ParametersFetcher {
5
- constructor() {
6
- this.templateByQuery = new Map();
7
- this.buldTemplates();
8
- }
9
- buldTemplates() {
10
- this.templateByQuery.set("fetchParam", gql `query($name: String!) {
11
- $queryAlias$: fetchResource(name: $name){
12
- name
13
- resource
14
- }
15
- }`);
16
- }
17
- async getParam(name, resourceID) {
18
- const completPath = `param://${resourceID}?params=${window.btoa(name)}`;
19
- return HttpFetcher.get().callGraphQL({
20
- values: { name: completPath },
21
- query: this.templateByQuery.get("fetchParam"),
22
- });
23
- }
24
- async asString(name, resourceID) {
25
- const paramArr = await this.getParam(name, resourceID);
26
- return this.getValue(paramArr);
27
- }
28
- async asInteger(name, resourceID) {
29
- const paramArr = await this.getParam(name, resourceID);
30
- return parseInt(this.getValue(paramArr));
31
- }
32
- async asFloat(name, resourceID) {
33
- const paramArr = await this.getParam(name, resourceID);
34
- return parseFloat(this.getValue(paramArr));
35
- }
36
- async asBoolean(name, resourceID) {
37
- const paramArr = await this.getParam(name, resourceID);
38
- return this.getValue(paramArr) == "S";
39
- }
40
- async asDate(name, resourceID) {
41
- const paramArr = await this.getParam(name, resourceID);
42
- return DateUtils.strToDate(this.getValue(paramArr));
43
- }
44
- async getBatchParams(names, resourceID) {
45
- const paramArr = await this.getParam(names.join(","), resourceID);
46
- //TODO: try to typed params val?
47
- const response = {};
48
- paramArr.forEach((param) => (response[param.name] = param.resource));
49
- return response;
50
- }
51
- getValue(obj = {}) {
52
- if (Array.isArray(obj) && obj.length > 0) {
53
- obj = obj[0];
54
- }
55
- if (StringUtils.isEmpty(obj.resource))
56
- return "";
57
- return obj.resource;
58
- }
59
- }
1
+ import { gql } from "graphql-request";
2
+ import { DateUtils, StringUtils } from "@sankhyalabs/core";
3
+ import { HttpFetcher } from "../DataFetcher";
4
+ export default class ParametersFetcher {
5
+ constructor() {
6
+ this.templateByQuery = new Map();
7
+ this.buldTemplates();
8
+ }
9
+ buldTemplates() {
10
+ this.templateByQuery.set("fetchParam", gql `query($name: String!) {
11
+ $queryAlias$: fetchResource(name: $name){
12
+ name
13
+ resource
14
+ }
15
+ }`);
16
+ }
17
+ async getParam(name, resourceID) {
18
+ const completPath = `param://${resourceID}?params=${window.btoa(name)}`;
19
+ return HttpFetcher.get().callGraphQL({
20
+ values: { name: completPath },
21
+ query: this.templateByQuery.get("fetchParam"),
22
+ });
23
+ }
24
+ async asString(name, resourceID) {
25
+ const paramArr = await this.getParam(name, resourceID);
26
+ return this.getValue(paramArr);
27
+ }
28
+ async asInteger(name, resourceID) {
29
+ const paramArr = await this.getParam(name, resourceID);
30
+ return parseInt(this.getValue(paramArr));
31
+ }
32
+ async asFloat(name, resourceID) {
33
+ const paramArr = await this.getParam(name, resourceID);
34
+ return parseFloat(this.getValue(paramArr));
35
+ }
36
+ async asBoolean(name, resourceID) {
37
+ const paramArr = await this.getParam(name, resourceID);
38
+ return this.getValue(paramArr) == "S";
39
+ }
40
+ async asDate(name, resourceID) {
41
+ const paramArr = await this.getParam(name, resourceID);
42
+ return DateUtils.strToDate(this.getValue(paramArr));
43
+ }
44
+ async getBatchParams(names, resourceID) {
45
+ const paramArr = await this.getParam(names.join(","), resourceID);
46
+ //TODO: try to typed params val?
47
+ const response = {};
48
+ paramArr.forEach((param) => (response[param.name] = param.resource));
49
+ return response;
50
+ }
51
+ getValue(obj = {}) {
52
+ if (Array.isArray(obj) && obj.length > 0) {
53
+ obj = obj[0];
54
+ }
55
+ if (StringUtils.isEmpty(obj.resource))
56
+ return "";
57
+ return obj.resource;
58
+ }
59
+ }
@@ -1,30 +1,30 @@
1
- import { gql } from "graphql-request";
2
- import { HttpFetcher } from "../DataFetcher";
3
- export class ResourceFetcher {
4
- constructor() {
5
- this.templateByQuery = new Map();
6
- this.buldTemplates();
7
- }
8
- buldTemplates() {
9
- this.templateByQuery.set("fetchResource", gql `query($name: String!) {
10
- $queryAlias$: fetchResource(name: $name){
11
- resource
12
- }
13
- }`);
14
- }
15
- loadResource(name) {
16
- return new Promise((resolve, reject) => {
17
- HttpFetcher.get()
18
- .callGraphQL({
19
- values: { name },
20
- query: this.templateByQuery.get("fetchResource"),
21
- })
22
- .then((result) => {
23
- resolve(result === null || result === void 0 ? void 0 : result.resource);
24
- })
25
- .catch((error) => {
26
- reject(error);
27
- });
28
- });
29
- }
30
- }
1
+ import { gql } from "graphql-request";
2
+ import { HttpFetcher } from "../DataFetcher";
3
+ export class ResourceFetcher {
4
+ constructor() {
5
+ this.templateByQuery = new Map();
6
+ this.buldTemplates();
7
+ }
8
+ buldTemplates() {
9
+ this.templateByQuery.set("fetchResource", gql `query($name: String!) {
10
+ $queryAlias$: fetchResource(name: $name){
11
+ resource
12
+ }
13
+ }`);
14
+ }
15
+ loadResource(name) {
16
+ return new Promise((resolve, reject) => {
17
+ HttpFetcher.get()
18
+ .callGraphQL({
19
+ values: { name },
20
+ query: this.templateByQuery.get("fetchResource"),
21
+ })
22
+ .then((result) => {
23
+ resolve(result === null || result === void 0 ? void 0 : result.resource);
24
+ })
25
+ .catch((error) => {
26
+ reject(error);
27
+ });
28
+ });
29
+ }
30
+ }