@sankhyalabs/sankhyablocks 1.0.2 → 1.0.3

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/build/index.js CHANGED
@@ -8084,8 +8084,6 @@ var HttpFetcher_awaiter = (undefined && undefined.__awaiter) || function (thisAr
8084
8084
  };
8085
8085
 
8086
8086
 
8087
-
8088
-
8089
8087
  class HttpFetcher {
8090
8088
  constructor() {
8091
8089
  HttpFetcher.loadStateManager = LoadStateManager.get(LoadType.APP_LOAD);
@@ -8100,52 +8098,26 @@ class HttpFetcher {
8100
8098
  callGraphQL(req) {
8101
8099
  var _a;
8102
8100
  return HttpFetcher_awaiter(this, void 0, void 0, function* () {
8101
+ const reqKey = this.getReqKey(req);
8102
+ req.queryID = reqKey;
8103
+ req.values.queryID = reqKey;
8103
8104
  if (HttpFetcher.loadStateManager.isPreInitialize()) {
8104
- const reqKey = this.getReqKey(req);
8105
- req.queryID = reqKey;
8106
- req.values.queryID = reqKey;
8107
8105
  if (!HttpFetcher.watingRequestsById.has(reqKey)) {
8108
8106
  HttpFetcher.watingRequestsById.set(reqKey, new WaitingRequest(req));
8109
8107
  }
8110
8108
  return (_a = HttpFetcher.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
8111
8109
  }
8112
8110
  else {
8113
- //TODO: fazer chamada direta para graphQL
8114
- return new Promise(function (resolve) {
8115
- const md = {
8116
- name: "dd://br.com.sankhya.cad.parceiro/Parceiro",
8117
- label: "Parceiro",
8118
- fields: [
8119
- {
8120
- name: "CODPARC",
8121
- label: "Cód. Parceiro",
8122
- dataType: DataType.NUMBER
8123
- },
8124
- {
8125
- name: "NOMEPARC",
8126
- label: "Nome",
8127
- dataType: DataType.TEXT,
8128
- userInterface: UserInterface.LONGTEXT,
8129
- required: true
8130
- },
8131
- {
8132
- name: "P",
8133
- label: "pera",
8134
- dataType: DataType.TEXT,
8135
- userInterface: UserInterface.OPTIONSELECTOR,
8136
- properties: { options: `{"M": "Madura", "V": "Verde", "P": "Passada"}` }
8137
- },
8138
- {
8139
- name: "ME",
8140
- label: "ME",
8141
- dataType: DataType.NUMBER,
8142
- userInterface: UserInterface.DECIMALNUMBER,
8143
- properties: { precision: 4, prettyPrecision: 1 }
8144
- }
8145
- ]
8146
- };
8147
- setTimeout(() => resolve(md));
8148
- });
8111
+ return new Promise((resolve, reject) => HttpFetcher_awaiter(this, void 0, void 0, function* () {
8112
+ let query = HttpFetcher.getQueryTemplate(req);
8113
+ const res = yield HttpFetcher.fecthGrapql([{ document: query, variables: req.values }]);
8114
+ if (res.errors.length > 0) {
8115
+ reject(res);
8116
+ }
8117
+ else {
8118
+ resolve(res.data);
8119
+ }
8120
+ }));
8149
8121
  }
8150
8122
  });
8151
8123
  }
@@ -8160,16 +8132,43 @@ class HttpFetcher {
8160
8132
  }
8161
8133
  onApplicationLoaded() {
8162
8134
  return HttpFetcher_awaiter(this, void 0, void 0, function* () {
8163
- const requestsBatch = [];
8164
- HttpFetcher.watingRequestsById.forEach((waitingReq) => HttpFetcher_awaiter(this, void 0, void 0, function* () {
8165
- let query = HttpFetcher.getQueryTemplate(waitingReq.request);
8166
- requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
8167
- }));
8135
+ if (HttpFetcher.watingRequestsById.size > 0) {
8136
+ const requestsBatch = [];
8137
+ HttpFetcher.watingRequestsById.forEach((waitingReq) => HttpFetcher_awaiter(this, void 0, void 0, function* () {
8138
+ let query = HttpFetcher.getQueryTemplate(waitingReq.request);
8139
+ requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
8140
+ }));
8141
+ let res = undefined;
8142
+ let dataResponse = [];
8143
+ let errorsResponse = [];
8144
+ res = yield HttpFetcher.fecthGrapql(requestsBatch);
8145
+ dataResponse = res.data;
8146
+ errorsResponse = res.errors;
8147
+ //Reject promises with errors from query
8148
+ errorsResponse.forEach((errorResponse) => {
8149
+ Object.entries(errorResponse).forEach(([key, val]) => {
8150
+ var _a;
8151
+ (((_a = HttpFetcher.getWatingRequest(val.request.variables[val.index].queryID)) === null || _a === void 0 ? void 0 : _a.reject) || Promise.reject)(val);
8152
+ });
8153
+ });
8154
+ //Resolve promises with data from query
8155
+ dataResponse.forEach((data) => {
8156
+ Object.entries(data).forEach(([key, val]) => {
8157
+ var _a;
8158
+ (((_a = HttpFetcher.getWatingRequest(key)) === null || _a === void 0 ? void 0 : _a.resolve) || Promise.resolve)(val);
8159
+ });
8160
+ });
8161
+ HttpFetcher.watingRequestsById.clear();
8162
+ }
8163
+ });
8164
+ }
8165
+ static fecthGrapql(request) {
8166
+ return HttpFetcher_awaiter(this, void 0, void 0, function* () {
8168
8167
  let res = undefined;
8169
8168
  let dataResponse = [];
8170
8169
  let errorsResponse = [];
8171
8170
  try {
8172
- res = yield (0,dist.batchRequests)('http://localhost:8082/', requestsBatch);
8171
+ res = yield (0,dist.batchRequests)('http://localhost:8082/', request);
8173
8172
  res.forEach((resItem) => {
8174
8173
  dataResponse.push(resItem.data);
8175
8174
  });
@@ -8190,21 +8189,7 @@ class HttpFetcher {
8190
8189
  }
8191
8190
  });
8192
8191
  }
8193
- //Reject primises with errors from query
8194
- errorsResponse.forEach((errorResponse) => {
8195
- Object.entries(errorResponse).forEach(([key, val]) => {
8196
- var _a;
8197
- (((_a = HttpFetcher.getWatingRequest(val.request.variables[val.index].queryID)) === null || _a === void 0 ? void 0 : _a.reject) || Promise.reject)(val);
8198
- });
8199
- });
8200
- //Resolve primises with data from query
8201
- dataResponse.forEach((data) => {
8202
- Object.entries(data).forEach(([key, val]) => {
8203
- var _a;
8204
- (((_a = HttpFetcher.getWatingRequest(key)) === null || _a === void 0 ? void 0 : _a.resolve) || Promise.resolve)(val);
8205
- });
8206
- });
8207
- HttpFetcher.watingRequestsById.clear();
8192
+ return { data: dataResponse, errors: errorsResponse };
8208
8193
  });
8209
8194
  }
8210
8195
  //TODO: Mover este metodo para o @sankhyalabs/core classe string utils.