jsf.js_next_gen 4.0.1-beta.5 → 4.0.1-beta.6

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 (40) hide show
  1. package/dist/window/faces-development.js +92 -63
  2. package/dist/window/faces-development.js.br +0 -0
  3. package/dist/window/faces-development.js.gz +0 -0
  4. package/dist/window/faces-development.js.map +1 -1
  5. package/dist/window/faces.js +1 -1
  6. package/dist/window/faces.js.br +0 -0
  7. package/dist/window/faces.js.gz +0 -0
  8. package/dist/window/faces.js.map +1 -1
  9. package/dist/window/jsf-development.js +92 -63
  10. package/dist/window/jsf-development.js.br +0 -0
  11. package/dist/window/jsf-development.js.gz +0 -0
  12. package/dist/window/jsf-development.js.map +1 -1
  13. package/dist/window/jsf.js +1 -1
  14. package/dist/window/jsf.js.br +0 -0
  15. package/dist/window/jsf.js.gz +0 -0
  16. package/dist/window/jsf.js.map +1 -1
  17. package/package.json +1 -1
  18. package/src/main/typescript/impl/util/XhrQueueController.ts +3 -17
  19. package/src/main/typescript/impl/xhrCore/XhrRequest.ts +95 -52
  20. package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +40 -0
  21. package/src/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.ts +7 -0
  22. package/src/main/typescript/test/myfaces/{OnLoadSpec.ts → OnLoad.spec.ts} +2 -2
  23. package/src/main/typescript/test/xhrCore/ErrorChainTest.spec.ts +113 -0
  24. package/src/main/typescript/test/xhrCore/NamespacesRequestTest.spec.ts +9 -12
  25. package/target/impl/util/XhrQueueController.js +3 -18
  26. package/target/impl/util/XhrQueueController.js.map +1 -1
  27. package/target/impl/xhrCore/XhrRequest.js +89 -45
  28. package/target/impl/xhrCore/XhrRequest.js.map +1 -1
  29. package/target/test/frameworkBase/_ext/shared/StandardInits.js +39 -0
  30. package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
  31. package/target/test/frameworkBase/_ext/shared/XmlResponses.js +4 -0
  32. package/target/test/frameworkBase/_ext/shared/XmlResponses.js.map +1 -1
  33. package/target/test/myfaces/OnLoad.spec.js +57 -0
  34. package/target/test/myfaces/OnLoad.spec.js.map +1 -0
  35. package/target/test/myfaces/OnLoadSpec.js +2 -2
  36. package/target/test/myfaces/OnLoadSpec.js.map +1 -1
  37. package/target/test/xhrCore/ErrorChainTest.spec.js +135 -0
  38. package/target/test/xhrCore/ErrorChainTest.spec.js.map +1 -0
  39. package/target/test/xhrCore/NamespacesRequestTest.spec.js +8 -5
  40. package/target/test/xhrCore/NamespacesRequestTest.spec.js.map +1 -1
@@ -6570,14 +6570,9 @@ class XhrQueueController {
6570
6570
  * and clear the queue (theoretically this
6571
6571
  * would work with any promise)
6572
6572
  */
6573
- try {
6574
- return asyncRunnable
6575
- .then(() => this.next())
6576
- .catch((e) => this.handleError(e));
6577
- }
6578
- catch (e) {
6579
- this.handleError(e);
6580
- }
6573
+ return asyncRunnable
6574
+ .then(() => this.next())
6575
+ .catch(() => this.clear());
6581
6576
  }
6582
6577
  /**
6583
6578
  * alerts the queue that a task is running
@@ -6594,16 +6589,6 @@ class XhrQueueController {
6594
6589
  updateTaskRunning() {
6595
6590
  this.taskRunning = !this.isEmpty;
6596
6591
  }
6597
- /**
6598
- * standard error handling
6599
- * we clear the queue and then bomb out
6600
- * @param e
6601
- * @private
6602
- */
6603
- handleError(e) {
6604
- this.clear();
6605
- throw e;
6606
- }
6607
6592
  }
6608
6593
  exports.XhrQueueController = XhrQueueController;
6609
6594
 
@@ -8046,8 +8031,10 @@ class XhrRequest extends AsyncRunnable_1.AsyncRunnable {
8046
8031
  this.sendRequest(formData);
8047
8032
  }
8048
8033
  catch (e) {
8049
- // _onError
8050
- this.handleError(e);
8034
+ // this happens usually in a client side condition, hence we have to deal in with it in a client
8035
+ // side manner
8036
+ this.handleErrorAndClearQueue(e);
8037
+ throw e;
8051
8038
  }
8052
8039
  return this;
8053
8040
  }
@@ -8071,102 +8058,138 @@ class XhrRequest extends AsyncRunnable_1.AsyncRunnable {
8071
8058
  registerXhrCallbacks(resolve, reject) {
8072
8059
  const xhrObject = this.xhrObject;
8073
8060
  xhrObject.onabort = () => {
8074
- this.onAbort(reject);
8061
+ this.onAbort(resolve, reject);
8075
8062
  };
8076
8063
  xhrObject.ontimeout = () => {
8077
- this.onTimeout(reject);
8064
+ this.onTimeout(resolve, reject);
8078
8065
  };
8079
8066
  xhrObject.onload = () => {
8080
- this.onSuccess(resolve);
8067
+ this.onResponseReceived(resolve);
8081
8068
  };
8082
8069
  xhrObject.onloadend = () => {
8083
- this.onDone(this.xhrObject, resolve);
8070
+ this.onResponseProcessed(this.xhrObject, resolve);
8084
8071
  };
8085
8072
  xhrObject.onerror = (errorData) => {
8086
- // some browsers trigger an error when cancelling a request internally, or when
8087
- // cancel is called from outside
8073
+ // Safari in rare cases triggers an error when cancelling a request internally, or when
8088
8074
  // in this case we simply ignore the request and clear up the queue, because
8089
8075
  // it is not safe anymore to proceed with the current queue
8090
8076
  // This bypasses a Safari issue where it keeps requests hanging after page unload
8091
8077
  // and then triggers a cancel error on then instead of just stopping
8092
8078
  // and clearing the code
8079
+ // in a page unload case it is safe to clear the queue
8080
+ // in the exact safari case any request after this one in the queue is invalid
8081
+ // because the queue references xhr requests to a page which already is gone!
8093
8082
  if (this.isCancelledResponse(this.xhrObject)) {
8094
8083
  /*
8095
8084
  * this triggers the catch chain and after that finally
8096
8085
  */
8097
- reject();
8098
8086
  this.stopProgress = true;
8087
+ reject();
8099
8088
  return;
8100
8089
  }
8101
- this.onError(errorData, reject);
8090
+ // error already processed somewhere else
8091
+ if (this.stopProgress) {
8092
+ return;
8093
+ }
8094
+ this.handleError(errorData);
8102
8095
  };
8103
8096
  }
8104
8097
  isCancelledResponse(currentTarget) {
8105
- return (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.status) === 0 && // cancelled by browser
8098
+ return (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.status) === 0 && // cancelled internally by browser
8106
8099
  (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.readyState) === 4 &&
8107
8100
  (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.responseText) === '' &&
8108
8101
  (currentTarget === null || currentTarget === void 0 ? void 0 : currentTarget.responseXML) === null;
8109
8102
  }
8110
8103
  /*
8111
- * xhr processing callbacks
8112
- *
8113
- * Those methods are the callbacks called by
8114
- * the xhr object depending on its own state
8115
- */
8116
- onAbort(reject) {
8117
- reject();
8104
+ * xhr processing callbacks
8105
+ *
8106
+ * Those methods are the callbacks called by
8107
+ * the xhr object depending on its own state
8108
+ */
8109
+ /**
8110
+ * client side abort... also here for now we clean the queue
8111
+ *
8112
+ * @param resolve
8113
+ * @param reject
8114
+ * @private
8115
+ */
8116
+ onAbort(resolve, reject) {
8117
+ // reject means clear queue, in this case we abort entirely the processing
8118
+ // does not happen yet, we have to probably rethink this strategy in the future
8119
+ // when we introduce cancel functionality
8120
+ this.handleGenericError(reject);
8118
8121
  }
8119
- onTimeout(reject) {
8122
+ /**
8123
+ * request timeout, this must be handled like a generic server error per spec
8124
+ * unfortunately, so we have to jump to the next item (we cancelled before)
8125
+ * @param resolve
8126
+ * @param reject
8127
+ * @private
8128
+ */
8129
+ onTimeout(resolve, reject) {
8130
+ // timeout also means we we probably should clear the queue,
8131
+ // the state is unsafe for the next requests
8120
8132
  this.sendEvent(Const_1.STATE_EVT_TIMEOUT);
8121
- reject();
8133
+ this.handleGenericError(resolve);
8122
8134
  }
8123
- onSuccess(resolve) {
8124
- var _a, _b;
8135
+ /**
8136
+ * the response is received and normally is a normal response
8137
+ * but also can be some kind of error (http code >= 300)
8138
+ * In any case the response will be resolved either as error or response
8139
+ * and the next item in the queue will be processed
8140
+ * @param resolve
8141
+ * @private
8142
+ */
8143
+ onResponseReceived(resolve) {
8144
+ var _a, _b, _c, _d;
8125
8145
  this.sendEvent(Const_1.COMPLETE);
8126
- // malformed responses always result in empty response xml
8127
- // per spec a valid response cannot be empty
8128
- if (!((_a = this === null || this === void 0 ? void 0 : this.xhrObject) === null || _a === void 0 ? void 0 : _a.responseXML)) {
8129
- this.handleMalFormedXML(resolve);
8146
+ /*
8147
+ * second on error path
8148
+ */
8149
+ if (((_b = (_a = this.xhrObject) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 0) >= 300 || !((_c = this === null || this === void 0 ? void 0 : this.xhrObject) === null || _c === void 0 ? void 0 : _c.responseXML)) {
8150
+ // all errors from the server are resolved without interfering in the queue
8151
+ this.handleGenericError(resolve);
8130
8152
  return;
8131
8153
  }
8132
- (0, Const_1.$faces)().ajax.response(this.xhrObject, (_b = this.responseContext.value) !== null && _b !== void 0 ? _b : {});
8154
+ (0, Const_1.$faces)().ajax.response(this.xhrObject, (_d = this.responseContext.value) !== null && _d !== void 0 ? _d : {});
8133
8155
  }
8134
- handleMalFormedXML(resolve) {
8135
- var _a;
8156
+ handleGenericError(resolveOrReject) {
8157
+ var _a, _b, _c, _d;
8136
8158
  this.stopProgress = true;
8137
8159
  const errorData = {
8138
8160
  type: Const_1.ERROR,
8139
8161
  status: Const_1.MALFORMEDXML,
8140
- responseCode: 200,
8141
- responseText: (_a = this.xhrObject) === null || _a === void 0 ? void 0 : _a.responseText,
8162
+ responseCode: (_b = (_a = this.xhrObject) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 400,
8163
+ responseText: (_d = (_c = this.xhrObject) === null || _c === void 0 ? void 0 : _c.responseText) !== null && _d !== void 0 ? _d : "Error",
8142
8164
  source: this.internalContext.getIf(Const_1.CTX_PARAM_SRC_CTL_ID).value
8143
8165
  };
8144
8166
  try {
8145
8167
  this.handleError(errorData, true);
8146
8168
  }
8147
8169
  finally {
8148
- // we issue a resolve in this case to allow the system to recover
8170
+ // we issue a resolveOrReject in this case to allow the system to recover
8149
8171
  // reject would clean up the queue
8150
- resolve(errorData);
8172
+ // resolve would trigger the next element in the queue to be processed
8173
+ resolveOrReject(errorData);
8151
8174
  }
8152
8175
  // non blocking non clearing
8153
8176
  }
8154
- onDone(data, resolve) {
8155
- // if stop progress a special handling including resolve is already performed
8177
+ /**
8178
+ * last minute cleanup, the request now either is fully done
8179
+ * or not by having had a cancel or error event be
8180
+ * @param data
8181
+ * @param resolve
8182
+ * @private
8183
+ */
8184
+ onResponseProcessed(data, resolve) {
8185
+ // if stop progress true, the cleanup already has been performed
8156
8186
  if (this.stopProgress) {
8157
8187
  return;
8158
8188
  }
8159
- /**
8160
- * now call the then chain
8161
- */
8162
- resolve(data);
8163
- }
8164
- onError(errorData, reject) {
8165
- this.handleError(errorData);
8166
8189
  /*
8167
- * this triggers the catch chain and after that finally
8190
+ * normal case, cleanup == next item if possible
8168
8191
  */
8169
- reject();
8192
+ resolve(data);
8170
8193
  }
8171
8194
  sendRequest(formData) {
8172
8195
  const isPost = this.ajaxType != Const_1.REQ_TYPE_GET;
@@ -8195,10 +8218,16 @@ class XhrRequest extends AsyncRunnable_1.AsyncRunnable {
8195
8218
  }
8196
8219
  catch (e) {
8197
8220
  e.source = (_a = e === null || e === void 0 ? void 0 : e.source) !== null && _a !== void 0 ? _a : this.requestContext.getIf(Const_1.SOURCE).value;
8198
- this.handleError(e);
8221
+ // this is a client error, no save state anymore for queue processing!
8222
+ this.handleErrorAndClearQueue(e);
8223
+ // we forward the error upward like all client side errors
8199
8224
  throw e;
8200
8225
  }
8201
8226
  }
8227
+ handleErrorAndClearQueue(e, responseFormatError = false) {
8228
+ this.handleError(e, responseFormatError);
8229
+ this.reject(e);
8230
+ }
8202
8231
  handleError(exception, responseFormatError = false) {
8203
8232
  const errorData = (responseFormatError) ? ErrorData_1.ErrorData.fromHttpConnection(exception.source, exception.type, exception.status, exception.responseText, exception.responseCode, exception.status) : ErrorData_1.ErrorData.fromClient(exception);
8204
8233
  const eventHandler = (0, RequestDataResolver_1.resolveHandlerFunc)(this.requestContext, this.responseContext, Const_1.ON_ERROR);
Binary file
Binary file