@furo/open-models 1.2.2 → 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.
@@ -175448,6 +175448,21 @@
175448
175448
  }
175449
175449
  ]
175450
175450
  },
175451
+ {
175452
+ "kind": "method",
175453
+ "name": "spliceT",
175454
+ "parameters": [
175455
+ {
175456
+ "name": "start"
175457
+ },
175458
+ {
175459
+ "name": "deleteCount"
175460
+ },
175461
+ {
175462
+ "name": "items"
175463
+ }
175464
+ ]
175465
+ },
175451
175466
  {
175452
175467
  "kind": "method",
175453
175468
  "name": "unshift",
package/dist/Fetcher.d.ts CHANGED
@@ -105,7 +105,7 @@ export declare class Fetcher<REQ, RES> {
105
105
  */
106
106
  setHandlers(handlers: Handlers<REQ, RES>): void;
107
107
  abortPendingRequest(reason: any): void;
108
- invoke(rqo: REQ, options?: RequestInit): void;
108
+ invoke(rqo: REQ, options?: RequestInit): Promise<RES>;
109
109
  /**
110
110
  * Succeeded is true if the request succeeded. The request succeeded if it
111
111
  * loaded without error, wasn't aborted, and the status code is ≥ 200, and
@@ -118,7 +118,7 @@ export declare class Fetcher<REQ, RES> {
118
118
  * Dispatches event `response-error` and a specific error event with status code
119
119
  * @private
120
120
  */
121
- _reworkRequest(response: Response): void;
121
+ _reworkRequest(response: Response): Promise<RES>;
122
122
  /**
123
123
  * parses response object according to lastRequest heaader informationen `content-type`
124
124
  * you will find the supported content-types in the declaration area
package/dist/Fetcher.js CHANGED
@@ -69,65 +69,69 @@ export class Fetcher {
69
69
  }
70
70
  }
71
71
  invoke(rqo, options) {
72
- // abort old request if it is still running
73
- if (this.isLoading) {
74
- this.abortPendingRequest('invoke triggered before response');
75
- }
76
- this.abortController = new AbortController();
77
- const { signal } = this.abortController;
78
- this.requestInit = {
79
- method: this.method,
80
- signal,
81
- headers: this.API_OPTIONS.headers,
82
- };
83
- if (options) {
84
- this.setRequestOptions(options);
85
- }
86
- this.isLoading = true;
87
- const { evaluatedPath, evaluatedBody } = this.buildPathAndBodyfield(this.path, this.bodyField, rqo);
88
- if (evaluatedBody) {
89
- this.requestInit.body = evaluatedBody;
90
- }
91
- clearTimeout(this.timeoutId);
92
- const request = new Request(evaluatedPath, this.requestInit);
93
- this.timeoutId = setTimeout(() => {
94
- this.abortController.abort(`Timeout of ${this.timeout}ms reached`);
95
- if (this.onRequestAborted) {
96
- this.onRequestAborted(rqo);
72
+ return new Promise((resolve, reject) => {
73
+ // abort old request if it is still running
74
+ if (this.isLoading) {
75
+ this.abortPendingRequest('invoke triggered before response');
97
76
  }
98
- // eslint-disable-next-line no-console
99
- console.error(`RequestService fetch aborted: Timeout of ${this.timeout}ms reached`);
100
- }, this.timeout);
101
- if (this.onRequestStarted) {
102
- this.onRequestStarted(rqo);
103
- }
104
- fetch(request)
105
- .then(response => {
106
- this._reworkRequest(response);
107
- if (this.onRequestFinished) {
108
- this.onRequestFinished(rqo);
77
+ this.abortController = new AbortController();
78
+ const { signal } = this.abortController;
79
+ this.requestInit = {
80
+ method: this.method,
81
+ signal,
82
+ headers: this.API_OPTIONS.headers,
83
+ };
84
+ if (options) {
85
+ this.setRequestOptions(options);
109
86
  }
110
- })
111
- .catch(err => {
112
- this.isLoading = false;
113
- if (err.name === 'AbortError') {
87
+ this.isLoading = true;
88
+ const { evaluatedPath, evaluatedBody } = this.buildPathAndBodyfield(this.path, this.bodyField, rqo);
89
+ if (evaluatedBody) {
90
+ this.requestInit.body = evaluatedBody;
91
+ }
92
+ clearTimeout(this.timeoutId);
93
+ const request = new Request(evaluatedPath, this.requestInit);
94
+ this.timeoutId = setTimeout(() => {
95
+ this.abortController.abort(`Timeout of ${this.timeout}ms reached`);
114
96
  if (this.onRequestAborted) {
115
97
  this.onRequestAborted(rqo);
116
98
  }
117
- if (this.onRequestFinished) {
118
- this.onRequestFinished(rqo);
119
- }
120
99
  // eslint-disable-next-line no-console
121
- console.error('RequestService fetch aborted: ', err);
100
+ console.error(`RequestService fetch aborted: Timeout of ${this.timeout}ms reached`);
101
+ reject(rqo);
102
+ }, this.timeout);
103
+ if (this.onRequestStarted) {
104
+ this.onRequestStarted(rqo);
122
105
  }
123
- else {
106
+ fetch(request)
107
+ .then(response => {
108
+ this._reworkRequest(response).then(resolve).catch(reject);
124
109
  if (this.onRequestFinished) {
125
110
  this.onRequestFinished(rqo);
126
111
  }
127
- if (this.onFatalError) {
128
- this.onFatalError(err);
112
+ })
113
+ .catch(err => {
114
+ this.isLoading = false;
115
+ if (err.name === 'AbortError') {
116
+ if (this.onRequestAborted) {
117
+ this.onRequestAborted(rqo);
118
+ }
119
+ if (this.onRequestFinished) {
120
+ this.onRequestFinished(rqo);
121
+ }
122
+ // eslint-disable-next-line no-console
123
+ console.error('RequestService fetch aborted: ', err);
129
124
  }
130
- }
125
+ else {
126
+ if (this.onRequestFinished) {
127
+ this.onRequestFinished(rqo);
128
+ }
129
+ if (this.onFatalError) {
130
+ this.onFatalError(err);
131
+ }
132
+ }
133
+ reject(err);
134
+ });
131
135
  });
132
136
  }
133
137
  /**
@@ -143,64 +147,70 @@ export class Fetcher {
143
147
  * @private
144
148
  */
145
149
  _reworkRequest(response) {
146
- /**
147
- * The status code 0 is accepted as a success because some schemes - e.g.
148
- * file:// - don't provide status codes.
149
- */
150
- this.isLoading = false;
151
- clearTimeout(this.timeoutId);
152
- const status = response.status || 0;
153
- if (status === 0 || (status >= 200 && status < 300)) {
154
- /**
155
- * Loaded without error, fires event `response` with full response object
156
- */
157
- this.lastResponse = response;
158
- if (this.onResponseRaw) {
159
- this.onResponseRaw(response);
160
- }
150
+ return new Promise((resolve, reject) => {
161
151
  /**
162
- * parses response object according to response heaader informationen `content-type`
163
- * you will find the supported content-types in the declaration area
152
+ * The status code 0 is accepted as a success because some schemes - e.g.
153
+ * file:// - don't provide status codes.
164
154
  */
165
- this._parseResponse(response)
166
- .then(r => {
167
- if (this.onResponse) {
168
- this.onResponse(r, response);
169
- }
170
- })
171
- .catch(error => {
172
- if (this.onResponseParseError) {
173
- this.onResponseParseError(error, response);
155
+ this.isLoading = false;
156
+ clearTimeout(this.timeoutId);
157
+ const status = response.status || 0;
158
+ if (status === 0 || (status >= 200 && status < 300)) {
159
+ /**
160
+ * Loaded without error, fires event `response` with full response object
161
+ */
162
+ this.lastResponse = response;
163
+ if (this.onResponseRaw) {
164
+ this.onResponseRaw(response);
174
165
  }
175
- });
176
- }
177
- else {
178
- /**
179
- * Error detected
180
- */
181
- this.lastResponse = response;
182
- if (this.onResponseErrorRaw) {
183
- this.onResponseErrorRaw(response);
166
+ /**
167
+ * parses response object according to response heaader informationen `content-type`
168
+ * you will find the supported content-types in the declaration area
169
+ */
170
+ this._parseResponse(response)
171
+ .then(r => {
172
+ if (this.onResponse) {
173
+ this.onResponse(r, response);
174
+ resolve(r);
175
+ }
176
+ })
177
+ .catch(error => {
178
+ if (this.onResponseParseError) {
179
+ this.onResponseParseError(error, response);
180
+ reject(error);
181
+ }
182
+ });
184
183
  }
185
- /**
186
- * parses response object according to response heaader `content-type`
187
- */
188
- this._parseResponse(response)
189
- .then(r => {
190
- if (this.onResponseError) {
191
- this.onResponseError(r, response);
192
- }
193
- })
184
+ else {
194
185
  /**
195
- * error parsing is not possible, empty response
196
- * the dispatched event will have the raw error object in the event detail
186
+ * Error detected
197
187
  */
198
- .catch(error => {
199
- if (this.onResponseErrorParseError) {
200
- this.onResponseErrorParseError(error, response);
188
+ this.lastResponse = response;
189
+ if (this.onResponseErrorRaw) {
190
+ this.onResponseErrorRaw(response);
201
191
  }
202
- });
203
- }
192
+ /**
193
+ * parses response object according to response heaader `content-type`
194
+ */
195
+ this._parseResponse(response)
196
+ .then(r => {
197
+ if (this.onResponseError) {
198
+ this.onResponseError(r, response);
199
+ }
200
+ reject(r);
201
+ })
202
+ /**
203
+ * error parsing is not possible, empty response
204
+ * the dispatched event will have the raw error object in the event detail
205
+ */
206
+ .catch(error => {
207
+ if (this.onResponseErrorParseError) {
208
+ this.onResponseErrorParseError(error, response);
209
+ }
210
+ reject(error);
211
+ });
212
+ }
213
+ });
204
214
  }
205
215
  /**
206
216
  * parses response object according to lastRequest heaader informationen `content-type`
@@ -1 +1 @@
1
- {"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AA0FlB,MAAM,OAAO,OAAO;IAgClB;;;;;;OAMG;IACH,YACE,OAAoB;IACpB,SAAS;IACT,MAAc;IACd,eAAe;IACf,IAAY,EACZ,SAA2B;QArC7B;;WAEG;QACI,cAAS,GAAY,KAAK,CAAC;QAQ1B,oBAAe,GAAuC,IAAI,GAAG,EAGlE,CAAC;QAyBF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM;YACN,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO;YACjC,QAAQ,EAAC,QAAQ;SAClB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,yBAAyB;IAC9E,CAAC;IAEM,iBAAiB,CAAC,EAAe;QACtC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO;YACjC,MAAM;YACN,GAAG,E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,SAAS,EAAE,CAAC;gBAC5B,aAAa,GAAG,IAAI,CAAC,SAAS,CAC5B,IAAI,CAAC,WAAW,CAAC,kBAAkB;oBACjC,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBACzC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,aAAa,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,aAAa,EAAE,CAAC;QAE/F,OAAO;YACL,aAAa;YACb,aAAa;SACd,CAAC;IACJ,CAAC;CA+EF","sourcesContent":["import {\n deepJsonNameToProtoName,\n deepProtoNameToJsonName,\n protoNameToJsonName,\n} from './Mapper';\n\nexport interface IApiOptions {\n // leave empty to connect to the same host which delivers your files, otherwise set something like http://localhost:3000\n serverAddr: string;\n ApiBaseURL: string;\n headers?: Headers;\n timeout?: number;\n PreserveProtoNames: boolean;\n}\n\ninterface Handlers<REQ, RES> {\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n\nexport class Fetcher<REQ, RES> {\n public timeout: number;\n\n /**\n * Contains the response from the last request. Also on errors.\n */\n public lastResponse: Response | undefined;\n\n /**\n * Indicator for a pending request. Maybe you are also interested on the `onRequestStarted` and `onRequestFinished` callback methods.\n */\n public isLoading: boolean = false;\n\n private path: string;\n\n private requestInit: RequestInit;\n\n private method: string;\n\n private responseHandler: Map<string, (r: Response) => void> = new Map<\n string,\n (r: Response) => void\n >();\n\n private abortController: AbortController;\n\n private timeoutId: ReturnType<typeof setTimeout> | number | undefined;\n\n private bodyField: keyof REQ | '*' | undefined;\n\n private API_OPTIONS: IApiOptions;\n\n /**\n *\n * @param options\n * @param method\n * @param path\n * @param bodyField\n */\n constructor(\n options: IApiOptions,\n // method\n method: string,\n // options path\n path: string,\n bodyField?: keyof REQ | '*',\n ) {\n this.API_OPTIONS = options;\n this.path = path;\n this.bodyField = bodyField;\n this.method = method;\n\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n redirect:'follow'\n };\n\n this.timeout = this.API_OPTIONS.timeout || 300000; // chrome default timeout\n }\n\n public setRequestOptions(ri: RequestInit) {\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n headers: this.API_OPTIONS.headers,\n signal,\n ...ri,\n };\n }\n\n /**\n * setHandlers let you bind all handlers at once.\n * @param handlers\n */\n public setHandlers(handlers: Handlers<REQ, RES>) {\n this.onResponse = handlers.onResponse;\n this.onResponseError = handlers.onResponseError;\n this.onRequestStarted = handlers.onRequestStarted;\n this.onRequestFinished = handlers.onRequestFinished;\n this.onRequestAborted = handlers.onRequestAborted;\n this.onResponseRaw = handlers.onResponseRaw;\n this.onResponseErrorRaw = handlers.onResponseErrorRaw;\n this.onResponseParseError = handlers.onResponseParseError;\n this.onResponseErrorParseError = handlers.onResponseErrorParseError;\n this.onFatalError = handlers.onFatalError;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public abortPendingRequest(reason: any): void {\n if (!this.isLoading) {\n return;\n }\n clearTimeout(this.timeoutId);\n this.isLoading = false;\n this.abortController.abort(reason);\n\n if (this.onRequestAborted) {\n this.onRequestAborted(reason);\n }\n }\n\n public invoke(rqo: REQ, options?: RequestInit) {\n // abort old request if it is still running\n if (this.isLoading) {\n this.abortPendingRequest('invoke triggered before response');\n }\n\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n };\n\n if (options) {\n this.setRequestOptions(options);\n }\n\n\n this.isLoading = true;\n\n const { evaluatedPath, evaluatedBody } = this.buildPathAndBodyfield(\n this.path,\n this.bodyField,\n rqo,\n );\n if (evaluatedBody) {\n this.requestInit.body = evaluatedBody;\n }\n\n clearTimeout(this.timeoutId);\n const request = new Request(evaluatedPath, this.requestInit);\n this.timeoutId = setTimeout(() => {\n this.abortController.abort(`Timeout of ${this.timeout}ms reached`);\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n // eslint-disable-next-line no-console\n console.error(\n `RequestService fetch aborted: Timeout of ${this.timeout}ms reached`,\n );\n }, this.timeout);\n\n if (this.onRequestStarted) {\n this.onRequestStarted(rqo);\n }\n\n fetch(request)\n .then(response => {\n this._reworkRequest(response);\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n })\n .catch(err => {\n this.isLoading = false;\n\n if (err.name === 'AbortError') {\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n // eslint-disable-next-line no-console\n console.error('RequestService fetch aborted: ', err);\n } else {\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n\n if (this.onFatalError) {\n this.onFatalError(err);\n }\n }\n });\n }\n\n /**\n * Succeeded is true if the request succeeded. The request succeeded if it\n * loaded without error, wasn't aborted, and the status code is ≥ 200, and\n * < 300, or if the status code is 0.\n */\n\n /**\n * Errorhandling according to Google rest-api-v3 Status Codes\n * (https://developers.google.com/maps-booking/reference/rest-api-v3/status_codes)\n *\n * Dispatches event `response-error` and a specific error event with status code\n * @private\n */\n _reworkRequest(response: Response) {\n /**\n * The status code 0 is accepted as a success because some schemes - e.g.\n * file:// - don't provide status codes.\n */\n this.isLoading = false;\n clearTimeout(this.timeoutId);\n const status = response.status || 0;\n\n if (status === 0 || (status >= 200 && status < 300)) {\n /**\n * Loaded without error, fires event `response` with full response object\n */\n this.lastResponse = response;\n\n if (this.onResponseRaw) {\n this.onResponseRaw(response);\n }\n\n /**\n * parses response object according to response heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n */\n\n this._parseResponse(response)\n .then(r => {\n if (this.onResponse) {\n this.onResponse(r as RES, response);\n }\n })\n .catch(error => {\n if (this.onResponseParseError) {\n this.onResponseParseError(error, response);\n }\n });\n } else {\n /**\n * Error detected\n */\n this.lastResponse = response;\n if (this.onResponseErrorRaw) {\n this.onResponseErrorRaw(response);\n }\n\n /**\n * parses response object according to response heaader `content-type`\n */\n this._parseResponse(response)\n .then(r => {\n if (this.onResponseError) {\n this.onResponseError(r, response);\n }\n })\n /**\n * error parsing is not possible, empty response\n * the dispatched event will have the raw error object in the event detail\n */\n .catch(error => {\n if (this.onResponseErrorParseError) {\n this.onResponseErrorParseError(error, response);\n }\n });\n }\n }\n\n /**\n * parses response object according to lastRequest heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n * response Fetch API response object [https://developer.mozilla.org/en-US/docs/Web/API/Response]\n * Default response handler is json!\n * @param response\n * @private\n */\n // eslint-disable-next-line class-methods-use-this\n _parseResponse(response: Response) {\n return new Promise((resolve, reject) => {\n if (response) {\n this.responseHandler.set('text/plain', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n this.responseHandler.set('text/html', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/json', r => {\n r.json()\n .then(json => {\n // convert to literal type when needed\n resolve(\n this.API_OPTIONS.PreserveProtoNames\n ? deepProtoNameToJsonName(json)\n : json,\n );\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/octet-stream', r => {\n r.arrayBuffer()\n .then(buffer => {\n resolve(buffer);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/pdf', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('image/jpeg', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n const contentType = response.headers.get('content-type');\n let handler = contentType?.split(';')[0].trim();\n if (handler === undefined) {\n handler = 'application/json';\n }\n let typeHandler = this.responseHandler.get(handler);\n\n if (typeHandler === undefined) {\n // eslint-disable-next-line no-console\n console.error('No parser for', handler);\n typeHandler = this.responseHandler.get('application/json');\n }\n\n if (typeHandler) {\n typeHandler(response);\n }\n } else {\n reject(new Error('no response'));\n }\n });\n }\n\n private buildPathAndBodyfield(\n path: string,\n bodyField: keyof REQ | '*' | undefined,\n rqo: REQ,\n ): {\n evaluatedPath: string;\n evaluatedBody: string | undefined;\n } {\n // use the rules specified here https://docs.solo.io/gloo-edge/latest/reference/api/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk/\n // find all fields in path\n let evaluatedPath = path;\n let evaluatedBody;\n\n const keysForBodyOrQueryParams: Map<string, keyof REQ> = new Map();\n Object.keys(rqo as object).forEach(key => {\n keysForBodyOrQueryParams.set(key, key as keyof REQ);\n });\n\n const fields = [...path.matchAll(/\\{([^}]+)}/g)];\n // replace url templates with values\n // /v1/cube/{id} => /v1/cube/12\n fields.forEach(field => {\n // TODO: check if qp is always set as proto name\n const rqoKey = protoNameToJsonName(field[1]) as keyof REQ;\n const rqoValue = rqo[rqoKey];\n evaluatedPath = evaluatedPath.replace(field[0], `${rqoValue}`);\n keysForBodyOrQueryParams.delete(rqoKey as string);\n });\n\n if (bodyField === '*') {\n // build body object\n const body: { [key: string]: unknown } = {};\n keysForBodyOrQueryParams.forEach(key => {\n body[key as string] = rqo[key];\n });\n evaluatedBody = JSON.stringify(body);\n } else {\n // build query params\n const params: string[] = [];\n if (bodyField !== undefined) {\n keysForBodyOrQueryParams.delete(bodyField as string);\n }\n keysForBodyOrQueryParams.forEach(key => {\n if (Array.isArray(rqo[key])) {\n (rqo[key] as unknown[]).forEach(e => {\n params.push(`${key as string}=${e}`);\n });\n } else {\n params.push(`${key as string}=${rqo[key]}`);\n }\n });\n if (params.length) {\n evaluatedPath = `${evaluatedPath}?${params.join('&')}`;\n }\n\n if (bodyField !== undefined) {\n evaluatedBody = JSON.stringify(\n this.API_OPTIONS.PreserveProtoNames\n ? deepJsonNameToProtoName(rqo[bodyField])\n : rqo[bodyField],\n );\n }\n }\n\n evaluatedPath = `${this.API_OPTIONS.serverAddr}${this.API_OPTIONS.ApiBaseURL}${evaluatedPath}`;\n\n return {\n evaluatedPath,\n evaluatedBody,\n };\n }\n\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n"]}
1
+ {"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AA0FlB,MAAM,OAAO,OAAO;IAgClB;;;;;;O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G,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAC9C,CAAC;YACH,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,aAAa,GAAG,GAAG,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,CAAC;YAED,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,aAAa,GAAG,IAAI,CAAC,SAAS,CAC5B,IAAI,CAAC,WAAW,CAAC,kBAAkB;oBACjC,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBACzC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,aAAa,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,aAAa,EAAE,CAAC;QAE/F,OAAO;YACL,aAAa;YACb,aAAa;SACd,CAAC;IACJ,CAAC;CA+EF","sourcesContent":["import {\n deepJsonNameToProtoName,\n deepProtoNameToJsonName,\n protoNameToJsonName,\n} from './Mapper';\n\nexport interface IApiOptions {\n // leave empty to connect to the same host which delivers your files, otherwise set something like http://localhost:3000\n serverAddr: string;\n ApiBaseURL: string;\n headers?: Headers;\n timeout?: number;\n PreserveProtoNames: boolean;\n}\n\ninterface Handlers<REQ, RES> {\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n\nexport class Fetcher<REQ, RES> {\n public timeout: number;\n\n /**\n * Contains the response from the last request. Also on errors.\n */\n public lastResponse: Response | undefined;\n\n /**\n * Indicator for a pending request. Maybe you are also interested on the `onRequestStarted` and `onRequestFinished` callback methods.\n */\n public isLoading: boolean = false;\n\n private path: string;\n\n private requestInit: RequestInit;\n\n private method: string;\n\n private responseHandler: Map<string, (r: Response) => void> = new Map<\n string,\n (r: Response) => void\n >();\n\n private abortController: AbortController;\n\n private timeoutId: ReturnType<typeof setTimeout> | number | undefined;\n\n private bodyField: keyof REQ | '*' | undefined;\n\n private API_OPTIONS: IApiOptions;\n\n /**\n *\n * @param options\n * @param method\n * @param path\n * @param bodyField\n */\n constructor(\n options: IApiOptions,\n // method\n method: string,\n // options path\n path: string,\n bodyField?: keyof REQ | '*',\n ) {\n this.API_OPTIONS = options;\n this.path = path;\n this.bodyField = bodyField;\n this.method = method;\n\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n redirect:'follow'\n };\n\n this.timeout = this.API_OPTIONS.timeout || 300000; // chrome default timeout\n }\n\n public setRequestOptions(ri: RequestInit) {\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n headers: this.API_OPTIONS.headers,\n signal,\n ...ri,\n };\n }\n\n /**\n * setHandlers let you bind all handlers at once.\n * @param handlers\n */\n public setHandlers(handlers: Handlers<REQ, RES>) {\n this.onResponse = handlers.onResponse;\n this.onResponseError = handlers.onResponseError;\n this.onRequestStarted = handlers.onRequestStarted;\n this.onRequestFinished = handlers.onRequestFinished;\n this.onRequestAborted = handlers.onRequestAborted;\n this.onResponseRaw = handlers.onResponseRaw;\n this.onResponseErrorRaw = handlers.onResponseErrorRaw;\n this.onResponseParseError = handlers.onResponseParseError;\n this.onResponseErrorParseError = handlers.onResponseErrorParseError;\n this.onFatalError = handlers.onFatalError;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public abortPendingRequest(reason: any): void {\n if (!this.isLoading) {\n return;\n }\n clearTimeout(this.timeoutId);\n this.isLoading = false;\n this.abortController.abort(reason);\n\n if (this.onRequestAborted) {\n this.onRequestAborted(reason);\n }\n }\n\n public invoke(rqo: REQ, options?: RequestInit):Promise<RES> {\n return new Promise((resolve, reject) => {\n // abort old request if it is still running\n if (this.isLoading) {\n this.abortPendingRequest('invoke triggered before response');\n }\n\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n };\n\n if (options) {\n this.setRequestOptions(options);\n }\n\n\n this.isLoading = true;\n\n const { evaluatedPath, evaluatedBody } = this.buildPathAndBodyfield(\n this.path,\n this.bodyField,\n rqo,\n );\n if (evaluatedBody) {\n this.requestInit.body = evaluatedBody;\n }\n\n clearTimeout(this.timeoutId);\n const request = new Request(evaluatedPath, this.requestInit);\n this.timeoutId = setTimeout(() => {\n this.abortController.abort(`Timeout of ${this.timeout}ms reached`);\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n // eslint-disable-next-line no-console\n console.error(\n `RequestService fetch aborted: Timeout of ${this.timeout}ms reached`,\n );\n reject(rqo)\n }, this.timeout);\n\n if (this.onRequestStarted) {\n this.onRequestStarted(rqo);\n }\n\n fetch(request)\n .then(response => {\n this._reworkRequest(response).then(resolve).catch(reject);\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n })\n .catch(err => {\n this.isLoading = false;\n\n if (err.name === 'AbortError') {\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n // eslint-disable-next-line no-console\n console.error('RequestService fetch aborted: ', err);\n } else {\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n\n if (this.onFatalError) {\n this.onFatalError(err);\n }\n }\n reject(err)\n });\n })\n\n }\n\n /**\n * Succeeded is true if the request succeeded. The request succeeded if it\n * loaded without error, wasn't aborted, and the status code is ≥ 200, and\n * < 300, or if the status code is 0.\n */\n\n /**\n * Errorhandling according to Google rest-api-v3 Status Codes\n * (https://developers.google.com/maps-booking/reference/rest-api-v3/status_codes)\n *\n * Dispatches event `response-error` and a specific error event with status code\n * @private\n */\n _reworkRequest(response: Response): Promise<RES> {\n return new Promise((resolve, reject) => {\n /**\n * The status code 0 is accepted as a success because some schemes - e.g.\n * file:// - don't provide status codes.\n */\n this.isLoading = false;\n clearTimeout(this.timeoutId);\n const status = response.status || 0;\n\n if (status === 0 || (status >= 200 && status < 300)) {\n /**\n * Loaded without error, fires event `response` with full response object\n */\n this.lastResponse = response;\n\n if (this.onResponseRaw) {\n this.onResponseRaw(response);\n }\n\n /**\n * parses response object according to response heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n */\n\n this._parseResponse(response)\n .then(r => {\n if (this.onResponse) {\n this.onResponse(r as RES, response);\n resolve(r as RES);\n }\n })\n .catch(error => {\n if (this.onResponseParseError) {\n this.onResponseParseError(error, response);\n reject(error);\n }\n });\n } else {\n /**\n * Error detected\n */\n this.lastResponse = response;\n if (this.onResponseErrorRaw) {\n this.onResponseErrorRaw(response);\n }\n\n /**\n * parses response object according to response heaader `content-type`\n */\n this._parseResponse(response)\n .then(r => {\n if (this.onResponseError) {\n this.onResponseError(r, response);\n }\n reject(r);\n })\n /**\n * error parsing is not possible, empty response\n * the dispatched event will have the raw error object in the event detail\n */\n .catch(error => {\n if (this.onResponseErrorParseError) {\n this.onResponseErrorParseError(error, response);\n }\n reject(error);\n });\n }\n })\n\n }\n\n /**\n * parses response object according to lastRequest heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n * response Fetch API response object [https://developer.mozilla.org/en-US/docs/Web/API/Response]\n * Default response handler is json!\n * @param response\n * @private\n */\n // eslint-disable-next-line class-methods-use-this\n _parseResponse(response: Response) {\n return new Promise((resolve, reject) => {\n if (response) {\n this.responseHandler.set('text/plain', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n this.responseHandler.set('text/html', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/json', r => {\n r.json()\n .then(json => {\n // convert to literal type when needed\n resolve(\n this.API_OPTIONS.PreserveProtoNames\n ? deepProtoNameToJsonName(json)\n : json,\n );\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/octet-stream', r => {\n r.arrayBuffer()\n .then(buffer => {\n resolve(buffer);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/pdf', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('image/jpeg', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n const contentType = response.headers.get('content-type');\n let handler = contentType?.split(';')[0].trim();\n if (handler === undefined) {\n handler = 'application/json';\n }\n let typeHandler = this.responseHandler.get(handler);\n\n if (typeHandler === undefined) {\n // eslint-disable-next-line no-console\n console.error('No parser for', handler);\n typeHandler = this.responseHandler.get('application/json');\n }\n\n if (typeHandler) {\n typeHandler(response);\n }\n } else {\n reject(new Error('no response'));\n }\n });\n }\n\n private buildPathAndBodyfield(\n path: string,\n bodyField: keyof REQ | '*' | undefined,\n rqo: REQ,\n ): {\n evaluatedPath: string;\n evaluatedBody: string | undefined;\n } {\n // use the rules specified here https://docs.solo.io/gloo-edge/latest/reference/api/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk/\n // find all fields in path\n let evaluatedPath = path;\n let evaluatedBody;\n\n const keysForBodyOrQueryParams: Map<string, keyof REQ> = new Map();\n Object.keys(rqo as object).forEach(key => {\n keysForBodyOrQueryParams.set(key, key as keyof REQ);\n });\n\n const fields = [...path.matchAll(/\\{([^}]+)}/g)];\n // replace url templates with values\n // /v1/cube/{id} => /v1/cube/12\n fields.forEach(field => {\n // TODO: check if qp is always set as proto name\n const rqoKey = protoNameToJsonName(field[1]) as keyof REQ;\n const rqoValue = rqo[rqoKey];\n evaluatedPath = evaluatedPath.replace(field[0], `${rqoValue}`);\n keysForBodyOrQueryParams.delete(rqoKey as string);\n });\n\n if (bodyField === '*') {\n // build body object\n const body: { [key: string]: unknown } = {};\n keysForBodyOrQueryParams.forEach(key => {\n body[key as string] = rqo[key];\n });\n evaluatedBody = JSON.stringify(body);\n } else {\n // build query params\n const params: string[] = [];\n if (bodyField !== undefined) {\n keysForBodyOrQueryParams.delete(bodyField as string);\n }\n keysForBodyOrQueryParams.forEach(key => {\n if (Array.isArray(rqo[key])) {\n (rqo[key] as unknown[]).forEach(e => {\n params.push(`${key as string}=${e}`);\n });\n } else {\n params.push(`${key as string}=${rqo[key]}`);\n }\n });\n if (params.length) {\n evaluatedPath = `${evaluatedPath}?${params.join('&')}`;\n }\n\n if (bodyField !== undefined) {\n evaluatedBody = JSON.stringify(\n this.API_OPTIONS.PreserveProtoNames\n ? deepJsonNameToProtoName(rqo[bodyField])\n : rqo[bodyField],\n );\n }\n }\n\n evaluatedPath = `${this.API_OPTIONS.serverAddr}${this.API_OPTIONS.ApiBaseURL}${evaluatedPath}`;\n\n return {\n evaluatedPath,\n evaluatedBody,\n };\n }\n\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n"]}
package/dist/FieldNode.js CHANGED
@@ -378,7 +378,7 @@ export class FieldNode {
378
378
  const validStateBefore = fn.__meta.isValid;
379
379
  fn.__meta.valueState = state.state;
380
380
  fn.__meta.stateMessage = state.message;
381
- fn.__meta.isValid = state.state !== ValueState.Error;
381
+ fn.__meta.isValid = state.state !== ValueState.Negative;
382
382
  fn.__meta.businessVaueState = state.state;
383
383
  if (fn.__meta.isValid !== validStateBefore) {
384
384
  fn.__dispatchEvent(new CustomEvent('validity-changed', {
@@ -590,7 +590,7 @@ export class FieldNode {
590
590
  node.__setValueState(ValueState.None, ['']);
591
591
  }
592
592
  if (constraintMessage !== undefined) {
593
- node.__setValueState(ValueState.Error, constraintMessage);
593
+ node.__setValueState(ValueState.Negative, constraintMessage);
594
594
  }
595
595
  }
596
596
  else {
@@ -621,7 +621,7 @@ export class FieldNode {
621
621
  this.__meta.stateMessage = OPEN_MODELS_OPTIONS.valueStateMessageFormatter(message[0], ...message.slice(1));
622
622
  // set invalid on error state
623
623
  // the event is sent from ...
624
- this.__meta.isValid = state !== ValueState.Error;
624
+ this.__meta.isValid = state !== ValueState.Negative;
625
625
  this.__dispatchEvent(new CustomEvent('state-changed', {
626
626
  detail: this,
627
627
  bubbles: false,