@sankhyalabs/sankhyablocks 1.0.10 → 1.1.13

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -26
  3. package/dist/cjs/index-d3250310.js +728 -0
  4. package/dist/cjs/index.cjs.js +2 -0
  5. package/dist/cjs/loader.cjs.js +21 -0
  6. package/dist/cjs/sankhyablocks.cjs.js +19 -0
  7. package/dist/cjs/snk-application.cjs.entry.js +7872 -0
  8. package/dist/collection/collection-manifest.json +12 -0
  9. package/dist/collection/components/snk-application/snk-application.css +5 -0
  10. package/dist/collection/components/snk-application/snk-application.js +450 -0
  11. package/dist/collection/index.js +1 -0
  12. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +158 -0
  13. package/dist/collection/lib/http/data-fetcher/fetchers/application-config-fetcher.js +23 -0
  14. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +157 -0
  15. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +2 -0
  16. package/dist/collection/lib/http/data-fetcher/fetchers/grid-config-fetcher.js +2 -0
  17. package/dist/collection/lib/http/data-fetcher/fetchers/parameters-fecher.js +59 -0
  18. package/dist/collection/lib/http/data-fetcher/state/LoadStateManager.js +66 -0
  19. package/dist/collection/lib/utils/urlutils.js +23 -0
  20. package/dist/collection/lib/workspace/workspace.js +7 -0
  21. package/dist/collection/temp/ApplicationUtils.js +31 -0
  22. package/dist/components/index.d.ts +26 -0
  23. package/dist/components/index.js +1 -0
  24. package/dist/components/snk-application.d.ts +11 -0
  25. package/dist/components/snk-application.js +7900 -0
  26. package/dist/esm/index-781079ed.js +702 -0
  27. package/dist/esm/index.js +1 -0
  28. package/dist/esm/loader.js +17 -0
  29. package/dist/esm/polyfills/core-js.js +11 -0
  30. package/dist/esm/polyfills/css-shim.js +1 -0
  31. package/dist/esm/polyfills/dom.js +79 -0
  32. package/dist/esm/polyfills/es5-html-element.js +1 -0
  33. package/dist/esm/polyfills/index.js +34 -0
  34. package/dist/esm/polyfills/system.js +6 -0
  35. package/dist/esm/sankhyablocks.js +17 -0
  36. package/dist/esm/snk-application.entry.js +7868 -0
  37. package/dist/index.cjs.js +1 -0
  38. package/dist/index.js +1 -9425
  39. package/dist/sankhyablocks/index.esm.js +0 -0
  40. package/dist/sankhyablocks/p-080303d6.entry.js +53 -0
  41. package/dist/sankhyablocks/p-83177bdc.js +1 -0
  42. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -0
  43. package/dist/types/components/snk-application/snk-application.d.ts +38 -0
  44. package/dist/types/components.d.ts +60 -0
  45. package/dist/types/index.d.ts +1 -5
  46. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +15 -0
  47. package/dist/types/lib/http/data-fetcher/fetchers/application-config-fetcher.d.ts +6 -0
  48. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +10 -0
  49. package/dist/types/{http → lib/http/data-fetcher}/fetchers/form-config-fetcher.d.ts +0 -0
  50. package/dist/types/{http → lib/http/data-fetcher}/fetchers/grid-config-fetcher.d.ts +0 -0
  51. package/dist/types/lib/http/data-fetcher/fetchers/parameters-fecher.d.ts +13 -0
  52. package/dist/types/lib/http/data-fetcher/state/LoadStateManager.d.ts +23 -0
  53. package/dist/types/lib/utils/urlutils.d.ts +4 -0
  54. package/dist/types/lib/workspace/workspace.d.ts +4 -0
  55. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  56. package/dist/types/temp/ApplicationUtils.d.ts +7 -0
  57. package/loader/cdn.js +3 -0
  58. package/loader/index.cjs.js +3 -0
  59. package/loader/index.d.ts +12 -0
  60. package/loader/index.es2017.js +3 -0
  61. package/loader/index.js +4 -0
  62. package/loader/package.json +10 -0
  63. package/package.json +44 -81
  64. package/react/components.d.ts +3 -0
  65. package/react/components.js +6 -0
  66. package/react/components.js.map +1 -0
  67. package/react/react-component-lib/createComponent.d.ts +10 -0
  68. package/react/react-component-lib/createComponent.js +75 -0
  69. package/react/react-component-lib/createComponent.js.map +1 -0
  70. package/react/react-component-lib/createOverlayComponent.d.ts +21 -0
  71. package/react/react-component-lib/createOverlayComponent.js +109 -0
  72. package/react/react-component-lib/createOverlayComponent.js.map +1 -0
  73. package/react/react-component-lib/index.d.ts +2 -0
  74. package/react/react-component-lib/index.js +3 -0
  75. package/react/react-component-lib/index.js.map +1 -0
  76. package/react/react-component-lib/interfaces.d.ts +29 -0
  77. package/react/react-component-lib/interfaces.js +1 -0
  78. package/react/react-component-lib/interfaces.js.map +1 -0
  79. package/react/react-component-lib/utils/attachProps.d.ts +12 -0
  80. package/react/react-component-lib/utils/attachProps.js +98 -0
  81. package/react/react-component-lib/utils/attachProps.js.map +1 -0
  82. package/react/react-component-lib/utils/case.d.ts +2 -0
  83. package/react/react-component-lib/utils/case.js +7 -0
  84. package/react/react-component-lib/utils/case.js.map +1 -0
  85. package/react/react-component-lib/utils/dev.d.ts +2 -0
  86. package/react/react-component-lib/utils/dev.js +13 -0
  87. package/react/react-component-lib/utils/dev.js.map +1 -0
  88. package/react/react-component-lib/utils/index.d.ts +10 -0
  89. package/react/react-component-lib/utils/index.js +34 -0
  90. package/react/react-component-lib/utils/index.js.map +1 -0
  91. package/dist/index.js.map +0 -1
  92. package/dist/types/application/AppParameterProvider.d.ts +0 -10
  93. package/dist/types/application/SankhyaAppProvider.d.ts +0 -16
  94. package/dist/types/http/fetchers/application-config-fetcher.d.ts +0 -6
  95. package/dist/types/http/fetchers/dataunit-fetcher.d.ts +0 -10
  96. package/dist/types/http/fetchers/parameters-fecher.d.ts +0 -13
  97. package/dist/types/utils/urlutils.d.ts +0 -4
  98. package/dist/types/workspace/workspace.d.ts +0 -4
  99. package/tsconfig.json +0 -17
  100. package/webpack.config.demo.js +0 -47
@@ -0,0 +1,12 @@
1
+ {
2
+ "entries": [
3
+ "./components/snk-application/snk-application.js"
4
+ ],
5
+ "compiler": {
6
+ "name": "@stencil/core",
7
+ "version": "2.15.2",
8
+ "typescriptVersion": "4.5.4"
9
+ },
10
+ "collections": [],
11
+ "bundles": []
12
+ }
@@ -0,0 +1,5 @@
1
+ :host {
2
+ display: flex;
3
+ flex-direction: column;
4
+ height: 100%;
5
+ }
@@ -0,0 +1,450 @@
1
+ import { Component, h, Method, Event } from "@stencil/core";
2
+ import DataUnitFetcher from "../../lib/http/data-fetcher/fetchers/dataunit-fetcher";
3
+ import UrlUtils from "../../lib/utils/urlutils";
4
+ import Workspace from "../../lib/workspace/workspace";
5
+ import ParametersFetcher from "../../lib/http/data-fetcher/fetchers/parameters-fecher";
6
+ //FIXME: temporariamente estamos compiando essa classe do ezui pois não conseguimos
7
+ //incluída no pacote. Isso deve ser resolvido nas proximas entregas e então ajustado aqui
8
+ import ApplicationUtils from "../../temp/ApplicationUtils";
9
+ export class SnkApplication {
10
+ get parameters() {
11
+ if (!this._parameters) {
12
+ this._parameters = new ParametersFetcher();
13
+ }
14
+ return this._parameters;
15
+ }
16
+ get resourceID() {
17
+ if (!this._resourceID) {
18
+ this._resourceID = this.urlParams.get("workspaceResourceID") ||
19
+ this.urlParams.get("resourceID") ||
20
+ Workspace.resourceID ||
21
+ "unknown.resource.id";
22
+ }
23
+ return this._resourceID;
24
+ }
25
+ async getStringParam(name) {
26
+ return this.parameters.asString(name, this.resourceID);
27
+ }
28
+ async getIntParam(name) {
29
+ return this.parameters.asInteger(name, this.resourceID);
30
+ }
31
+ async getFloatParam(name) {
32
+ return this.parameters.asFloat(name, this.resourceID);
33
+ }
34
+ async getBooleanParam(name) {
35
+ return this.parameters.asBoolean(name, this.resourceID);
36
+ }
37
+ async getDateParam(name) {
38
+ return this.parameters.asDate(name, this.resourceID);
39
+ }
40
+ async temOpcional(opcional) {
41
+ const opts = opcional.split(",");
42
+ return new Promise((resolve, reject) => {
43
+ this.getAttributeFromHTMLWrapper("opc0009")
44
+ .then(value => {
45
+ if (value === "1") {
46
+ resolve(true);
47
+ }
48
+ else {
49
+ Promise.all(opts.map(opt => this.getAttributeFromHTMLWrapper("opc" + opt)))
50
+ .then(result => {
51
+ resolve(result.includes("1"));
52
+ })
53
+ .catch(error => {
54
+ reject(error);
55
+ });
56
+ }
57
+ })
58
+ .catch(error => {
59
+ reject(error);
60
+ });
61
+ });
62
+ }
63
+ async getAttributeFromHTMLWrapper(attribName) {
64
+ return Promise.resolve(window[attribName]);
65
+ }
66
+ async openApp(resourceId, pkObject) {
67
+ Workspace.openAppActivity(resourceId, pkObject);
68
+ }
69
+ async createDataunit(entityName) {
70
+ return new Promise(resolve => {
71
+ const dataUnit = this.dataUnitFetcher.getDataUnit(entityName, this.resourceID);
72
+ dataUnit.loadMetadata();
73
+ resolve(dataUnit);
74
+ });
75
+ }
76
+ async getResourceID() {
77
+ return Promise.resolve(this.resourceID);
78
+ }
79
+ alert(title, message, icon) {
80
+ return ApplicationUtils.alert(title, message, icon);
81
+ }
82
+ error(title, message, icon) {
83
+ return ApplicationUtils.error(title, message, icon);
84
+ }
85
+ confirm(title, message, icon, critical) {
86
+ return ApplicationUtils.confirm(title, message, icon, critical);
87
+ }
88
+ info(message) {
89
+ return ApplicationUtils.info(message);
90
+ }
91
+ get urlParams() {
92
+ if (!this._urlParams) {
93
+ this._urlParams = UrlUtils.getQueryParams(location.search);
94
+ }
95
+ return this._urlParams;
96
+ }
97
+ get dataUnitFetcher() {
98
+ if (!this._dataUnitFetcher) {
99
+ this._dataUnitFetcher = new DataUnitFetcher();
100
+ }
101
+ return this._dataUnitFetcher;
102
+ }
103
+ componentDidLoad() {
104
+ this.applicationLoading.emit(true);
105
+ window.requestAnimationFrame(() => {
106
+ this.applicationLoaded.emit(true);
107
+ });
108
+ }
109
+ render() {
110
+ return (h("div", null));
111
+ }
112
+ static get is() { return "snk-application"; }
113
+ static get encapsulation() { return "scoped"; }
114
+ static get originalStyleUrls() { return {
115
+ "$": ["snk-application.css"]
116
+ }; }
117
+ static get styleUrls() { return {
118
+ "$": ["snk-application.css"]
119
+ }; }
120
+ static get events() { return [{
121
+ "method": "applicationLoaded",
122
+ "name": "applicationLoaded",
123
+ "bubbles": true,
124
+ "cancelable": true,
125
+ "composed": true,
126
+ "docs": {
127
+ "tags": [],
128
+ "text": "Evento disparado quando a aplica\u00E7\u00E3o for carregada."
129
+ },
130
+ "complexType": {
131
+ "original": "boolean",
132
+ "resolved": "boolean",
133
+ "references": {}
134
+ }
135
+ }, {
136
+ "method": "applicationLoading",
137
+ "name": "applicationLoading",
138
+ "bubbles": true,
139
+ "cancelable": true,
140
+ "composed": true,
141
+ "docs": {
142
+ "tags": [],
143
+ "text": "Evento"
144
+ },
145
+ "complexType": {
146
+ "original": "boolean",
147
+ "resolved": "boolean",
148
+ "references": {}
149
+ }
150
+ }]; }
151
+ static get methods() { return {
152
+ "getStringParam": {
153
+ "complexType": {
154
+ "signature": "(name: string) => Promise<string>",
155
+ "parameters": [{
156
+ "tags": [],
157
+ "text": ""
158
+ }],
159
+ "references": {
160
+ "Promise": {
161
+ "location": "global"
162
+ }
163
+ },
164
+ "return": "Promise<string>"
165
+ },
166
+ "docs": {
167
+ "text": "",
168
+ "tags": []
169
+ }
170
+ },
171
+ "getIntParam": {
172
+ "complexType": {
173
+ "signature": "(name: string) => Promise<number>",
174
+ "parameters": [{
175
+ "tags": [],
176
+ "text": ""
177
+ }],
178
+ "references": {
179
+ "Promise": {
180
+ "location": "global"
181
+ }
182
+ },
183
+ "return": "Promise<number>"
184
+ },
185
+ "docs": {
186
+ "text": "",
187
+ "tags": []
188
+ }
189
+ },
190
+ "getFloatParam": {
191
+ "complexType": {
192
+ "signature": "(name: string) => Promise<number>",
193
+ "parameters": [{
194
+ "tags": [],
195
+ "text": ""
196
+ }],
197
+ "references": {
198
+ "Promise": {
199
+ "location": "global"
200
+ }
201
+ },
202
+ "return": "Promise<number>"
203
+ },
204
+ "docs": {
205
+ "text": "",
206
+ "tags": []
207
+ }
208
+ },
209
+ "getBooleanParam": {
210
+ "complexType": {
211
+ "signature": "(name: string) => Promise<boolean>",
212
+ "parameters": [{
213
+ "tags": [],
214
+ "text": ""
215
+ }],
216
+ "references": {
217
+ "Promise": {
218
+ "location": "global"
219
+ }
220
+ },
221
+ "return": "Promise<boolean>"
222
+ },
223
+ "docs": {
224
+ "text": "",
225
+ "tags": []
226
+ }
227
+ },
228
+ "getDateParam": {
229
+ "complexType": {
230
+ "signature": "(name: string) => Promise<Date>",
231
+ "parameters": [{
232
+ "tags": [],
233
+ "text": ""
234
+ }],
235
+ "references": {
236
+ "Promise": {
237
+ "location": "global"
238
+ },
239
+ "Date": {
240
+ "location": "global"
241
+ }
242
+ },
243
+ "return": "Promise<Date>"
244
+ },
245
+ "docs": {
246
+ "text": "",
247
+ "tags": []
248
+ }
249
+ },
250
+ "temOpcional": {
251
+ "complexType": {
252
+ "signature": "(opcional: string) => Promise<boolean>",
253
+ "parameters": [{
254
+ "tags": [],
255
+ "text": ""
256
+ }],
257
+ "references": {
258
+ "Promise": {
259
+ "location": "global"
260
+ }
261
+ },
262
+ "return": "Promise<boolean>"
263
+ },
264
+ "docs": {
265
+ "text": "",
266
+ "tags": []
267
+ }
268
+ },
269
+ "getAttributeFromHTMLWrapper": {
270
+ "complexType": {
271
+ "signature": "(attribName: string) => Promise<string>",
272
+ "parameters": [{
273
+ "tags": [],
274
+ "text": ""
275
+ }],
276
+ "references": {
277
+ "Promise": {
278
+ "location": "global"
279
+ }
280
+ },
281
+ "return": "Promise<string>"
282
+ },
283
+ "docs": {
284
+ "text": "",
285
+ "tags": []
286
+ }
287
+ },
288
+ "openApp": {
289
+ "complexType": {
290
+ "signature": "(resourceId: string, pkObject: Object) => Promise<void>",
291
+ "parameters": [{
292
+ "tags": [],
293
+ "text": ""
294
+ }, {
295
+ "tags": [],
296
+ "text": ""
297
+ }],
298
+ "references": {
299
+ "Promise": {
300
+ "location": "global"
301
+ },
302
+ "Object": {
303
+ "location": "global"
304
+ }
305
+ },
306
+ "return": "Promise<void>"
307
+ },
308
+ "docs": {
309
+ "text": "",
310
+ "tags": []
311
+ }
312
+ },
313
+ "createDataunit": {
314
+ "complexType": {
315
+ "signature": "(entityName: string) => Promise<DataUnit>",
316
+ "parameters": [{
317
+ "tags": [],
318
+ "text": ""
319
+ }],
320
+ "references": {
321
+ "Promise": {
322
+ "location": "global"
323
+ },
324
+ "DataUnit": {
325
+ "location": "import",
326
+ "path": "@sankhyalabs/core"
327
+ }
328
+ },
329
+ "return": "Promise<DataUnit>"
330
+ },
331
+ "docs": {
332
+ "text": "",
333
+ "tags": []
334
+ }
335
+ },
336
+ "getResourceID": {
337
+ "complexType": {
338
+ "signature": "() => Promise<string>",
339
+ "parameters": [],
340
+ "references": {
341
+ "Promise": {
342
+ "location": "global"
343
+ }
344
+ },
345
+ "return": "Promise<string>"
346
+ },
347
+ "docs": {
348
+ "text": "",
349
+ "tags": []
350
+ }
351
+ },
352
+ "alert": {
353
+ "complexType": {
354
+ "signature": "(title: string, message: string, icon?: string) => Promise<boolean>",
355
+ "parameters": [{
356
+ "tags": [],
357
+ "text": ""
358
+ }, {
359
+ "tags": [],
360
+ "text": ""
361
+ }, {
362
+ "tags": [],
363
+ "text": ""
364
+ }],
365
+ "references": {
366
+ "Promise": {
367
+ "location": "global"
368
+ }
369
+ },
370
+ "return": "Promise<boolean>"
371
+ },
372
+ "docs": {
373
+ "text": "",
374
+ "tags": []
375
+ }
376
+ },
377
+ "error": {
378
+ "complexType": {
379
+ "signature": "(title: string, message: string, icon?: string) => Promise<boolean>",
380
+ "parameters": [{
381
+ "tags": [],
382
+ "text": ""
383
+ }, {
384
+ "tags": [],
385
+ "text": ""
386
+ }, {
387
+ "tags": [],
388
+ "text": ""
389
+ }],
390
+ "references": {
391
+ "Promise": {
392
+ "location": "global"
393
+ }
394
+ },
395
+ "return": "Promise<boolean>"
396
+ },
397
+ "docs": {
398
+ "text": "",
399
+ "tags": []
400
+ }
401
+ },
402
+ "confirm": {
403
+ "complexType": {
404
+ "signature": "(title: string, message: string, icon?: string, critical?: boolean) => Promise<boolean>",
405
+ "parameters": [{
406
+ "tags": [],
407
+ "text": ""
408
+ }, {
409
+ "tags": [],
410
+ "text": ""
411
+ }, {
412
+ "tags": [],
413
+ "text": ""
414
+ }, {
415
+ "tags": [],
416
+ "text": ""
417
+ }],
418
+ "references": {
419
+ "Promise": {
420
+ "location": "global"
421
+ }
422
+ },
423
+ "return": "Promise<boolean>"
424
+ },
425
+ "docs": {
426
+ "text": "",
427
+ "tags": []
428
+ }
429
+ },
430
+ "info": {
431
+ "complexType": {
432
+ "signature": "(message: string) => Promise<void>",
433
+ "parameters": [{
434
+ "tags": [],
435
+ "text": ""
436
+ }],
437
+ "references": {
438
+ "Promise": {
439
+ "location": "global"
440
+ }
441
+ },
442
+ "return": "Promise<void>"
443
+ },
444
+ "docs": {
445
+ "text": "",
446
+ "tags": []
447
+ }
448
+ }
449
+ }; }
450
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,158 @@
1
+ import { batchRequests } from 'graphql-request';
2
+ export class HttpFetcher {
3
+ constructor() {
4
+ this.watingRequestsById = new Map();
5
+ }
6
+ static get() {
7
+ if (!HttpFetcher.instance) {
8
+ HttpFetcher.instance = new HttpFetcher();
9
+ const application = document.querySelector(this.appTagName);
10
+ if (application === null) {
11
+ HttpFetcher.instance.resume();
12
+ }
13
+ else {
14
+ application.addEventListener('applicationLoading', () => HttpFetcher.instance.pause());
15
+ application.addEventListener('applicationLoaded', () => HttpFetcher.instance.resume());
16
+ }
17
+ }
18
+ return this.instance;
19
+ }
20
+ async callGraphQL(req) {
21
+ var _a;
22
+ const reqKey = this.getReqKey(req);
23
+ req.queryID = reqKey;
24
+ req.values.queryID = reqKey;
25
+ if (this.ready) {
26
+ return new Promise(async (resolve, reject) => {
27
+ let query = this.getQueryTemplate(req);
28
+ const res = await this.fecthGrapql([{ document: query, variables: req.values }]);
29
+ if (res.errors.length > 0) {
30
+ reject(res);
31
+ }
32
+ else {
33
+ //resolve(res);
34
+ //FIXME: Precisamos trabalhar melhor a resposta, quem chamou
35
+ //a API não pode ficar responsavel por desempacotar... fiz uma
36
+ //gambiarra aqui...
37
+ resolve(res.data[0][reqKey]);
38
+ }
39
+ });
40
+ }
41
+ else {
42
+ if (!this.watingRequestsById.has(reqKey)) {
43
+ this.watingRequestsById.set(reqKey, new WaitingRequest(req));
44
+ }
45
+ return (_a = this.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
46
+ }
47
+ }
48
+ getReqKey(req) {
49
+ return window.btoa(this.hashCode(`${req.query}${JSON.stringify(req.values || "")}`)).replace(/=/g, "");
50
+ }
51
+ getQueryTemplate(re) {
52
+ return (re.query || "").replaceAll("$queryAlias$", re.queryID);
53
+ }
54
+ getWatingRequest(reqID) {
55
+ return this.watingRequestsById.get(reqID);
56
+ }
57
+ pause() {
58
+ this.ready = false;
59
+ }
60
+ async resume() {
61
+ this.ready = true;
62
+ if (this.watingRequestsById.size > 0) {
63
+ const requestsBatch = [];
64
+ this.watingRequestsById.forEach(async (waitingReq) => {
65
+ let query = this.getQueryTemplate(waitingReq.request);
66
+ requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
67
+ });
68
+ let res = undefined;
69
+ let dataResponse = [];
70
+ let errorsResponse = [];
71
+ res = await this.fecthGrapql(requestsBatch);
72
+ dataResponse = res.data;
73
+ errorsResponse = res.errors;
74
+ //Reject promises with errors from query
75
+ errorsResponse.forEach((errorResponse) => {
76
+ Object.entries(errorResponse).forEach(([_key, val]) => {
77
+ var _a;
78
+ (((_a = this.getWatingRequest(val.request.variables[val.index].queryID)) === null || _a === void 0 ? void 0 : _a.reject) || Promise.reject)(val);
79
+ });
80
+ });
81
+ //Resolve promises with data from query
82
+ dataResponse.forEach((data) => {
83
+ Object.entries(data).forEach(([key, val]) => {
84
+ var _a;
85
+ (((_a = this.getWatingRequest(key)) === null || _a === void 0 ? void 0 : _a.resolve) || Promise.resolve)(val);
86
+ });
87
+ });
88
+ this.watingRequestsById.clear();
89
+ }
90
+ }
91
+ async fecthGrapql(request) {
92
+ let res = undefined;
93
+ let dataResponse = [];
94
+ let errorsResponse = [];
95
+ try {
96
+ res = await batchRequests('http://localhost:8082/', request);
97
+ res.forEach((resItem) => {
98
+ dataResponse.push(resItem.data);
99
+ });
100
+ }
101
+ catch (err) {
102
+ //TODO: Tratar erro quando não existir err.response
103
+ res = err.response;
104
+ const req = err.request;
105
+ Object.entries(res).forEach(([key, val]) => {
106
+ if (val.errors) {
107
+ errorsResponse.push(val.errors.map((item) => {
108
+ item.request = req;
109
+ item.index = Number(key);
110
+ return item;
111
+ }));
112
+ }
113
+ else if (val.data) {
114
+ dataResponse.push(val.data);
115
+ }
116
+ });
117
+ }
118
+ return { data: dataResponse, errors: errorsResponse };
119
+ }
120
+ //TODO: Mover este metodo para o @sankhyalabs/core classe string utils.
121
+ hashCode(txt) {
122
+ var hash = 0, i, chr;
123
+ if (txt.length === 0)
124
+ return hash.toString();
125
+ for (i = 0; i < txt.length; i++) {
126
+ chr = txt.charCodeAt(i);
127
+ hash = ((hash << 5) - hash) + chr;
128
+ hash |= 0; // Convert to 32bit integer
129
+ }
130
+ return hash.toString();
131
+ }
132
+ ;
133
+ }
134
+ HttpFetcher.appTagName = "snk-application";
135
+ class WaitingRequest {
136
+ constructor(req) {
137
+ this._resolve = () => { };
138
+ this._reject = () => { };
139
+ this._request = undefined;
140
+ this._request = req;
141
+ this._promisse = new Promise((resolve, reject) => {
142
+ this._resolve = resolve;
143
+ this._reject = reject;
144
+ });
145
+ }
146
+ get resolve() {
147
+ return this._resolve;
148
+ }
149
+ get reject() {
150
+ return this._reject;
151
+ }
152
+ get promise() {
153
+ return this._promisse;
154
+ }
155
+ get request() {
156
+ return this._request;
157
+ }
158
+ }
@@ -0,0 +1,23 @@
1
+ import { gql } from "graphql-request";
2
+ import { HttpFetcher } from "../DataFetcher";
3
+ export default class ApplicationConfigFetcher {
4
+ constructor() {
5
+ this.templateByQuery = new Map();
6
+ this.buldTemplates();
7
+ }
8
+ buldTemplates() {
9
+ this.templateByQuery.set("getResource", gql `query($name: String!) {
10
+ $queryAlias$: getResource(name: $name){
11
+ name
12
+ resource
13
+ }
14
+ }`);
15
+ }
16
+ getResource(name, resourceID) {
17
+ const completPath = `cfg://app/${resourceID}/${name}`;
18
+ return HttpFetcher.get().callGraphQL({
19
+ values: { name: completPath },
20
+ query: this.templateByQuery.get("getResource"),
21
+ });
22
+ }
23
+ }