@furo/open-models 1.11.0 → 1.11.2
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/custom-elements.json +4521 -1330
- package/dist/Fetcher.d.ts +1 -1
- package/dist/Fetcher.js +35 -32
- package/dist/Fetcher.js.map +1 -1
- package/dist/FieldNode.d.ts +12 -1
- package/dist/FieldNode.js +42 -28
- package/dist/FieldNode.js.map +1 -1
- package/dist/primitives/FLOAT.js +2 -2
- package/dist/primitives/FLOAT.js.map +1 -1
- package/dist/proxies/ARRAY.js +8 -6
- package/dist/proxies/ARRAY.js.map +1 -1
- package/package.json +3 -3
package/dist/Fetcher.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export declare class Fetcher<REQ, RES> {
|
|
|
120
120
|
*/
|
|
121
121
|
_reworkRequest(response: Response): Promise<RES>;
|
|
122
122
|
/**
|
|
123
|
-
* parses response object according to lastRequest
|
|
123
|
+
* parses response object according to lastRequest header informationen `content-type`
|
|
124
124
|
* you will find the supported content-types in the declaration area
|
|
125
125
|
* response Fetch API response object [https://developer.mozilla.org/en-US/docs/Web/API/Response]
|
|
126
126
|
* Default response handler is json!
|
package/dist/Fetcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepJsonNameToProtoName, deepProtoNameToJsonName,
|
|
1
|
+
import { deepJsonNameToProtoName, deepProtoNameToJsonName, jsonNameToProtoName, protoNameToJsonName } from './Mapper.js';
|
|
2
2
|
export class Fetcher {
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
@@ -105,9 +105,11 @@ export class Fetcher {
|
|
|
105
105
|
}
|
|
106
106
|
fetch(request)
|
|
107
107
|
.then(response => {
|
|
108
|
-
this._reworkRequest(response)
|
|
108
|
+
this._reworkRequest(response)
|
|
109
|
+
.then(data => {
|
|
109
110
|
resolve(data);
|
|
110
|
-
})
|
|
111
|
+
})
|
|
112
|
+
.catch(reject);
|
|
111
113
|
if (this.onRequestFinished) {
|
|
112
114
|
this.onRequestFinished(rqo);
|
|
113
115
|
}
|
|
@@ -215,7 +217,7 @@ export class Fetcher {
|
|
|
215
217
|
});
|
|
216
218
|
}
|
|
217
219
|
/**
|
|
218
|
-
* parses response object according to lastRequest
|
|
220
|
+
* parses response object according to lastRequest header informationen `content-type`
|
|
219
221
|
* you will find the supported content-types in the declaration area
|
|
220
222
|
* response Fetch API response object [https://developer.mozilla.org/en-US/docs/Web/API/Response]
|
|
221
223
|
* Default response handler is json!
|
|
@@ -224,8 +226,6 @@ export class Fetcher {
|
|
|
224
226
|
*/
|
|
225
227
|
// eslint-disable-next-line class-methods-use-this
|
|
226
228
|
_parseResponse(response) {
|
|
227
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
228
|
-
const self = this;
|
|
229
229
|
return new Promise((resolve, reject) => {
|
|
230
230
|
if (response) {
|
|
231
231
|
this.responseHandler.set('text/plain', r => {
|
|
@@ -237,8 +237,30 @@ export class Fetcher {
|
|
|
237
237
|
reject(err);
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
|
-
this.responseHandler.set('
|
|
241
|
-
|
|
240
|
+
this.responseHandler.set('text/html', r => {
|
|
241
|
+
r.text()
|
|
242
|
+
.then(text => {
|
|
243
|
+
resolve(text);
|
|
244
|
+
})
|
|
245
|
+
.catch(err => {
|
|
246
|
+
reject(err);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
this.responseHandler.set('application/json', r => {
|
|
250
|
+
r.json()
|
|
251
|
+
.then(json => {
|
|
252
|
+
// convert to literal type when needed
|
|
253
|
+
resolve(this.API_OPTIONS.PreserveProtoNames
|
|
254
|
+
? deepProtoNameToJsonName(json)
|
|
255
|
+
: json);
|
|
256
|
+
})
|
|
257
|
+
.catch(err => {
|
|
258
|
+
reject(err);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
this.responseHandler.set('application/x-ndjson', r => {
|
|
262
|
+
const preserveProtoNames = this.API_OPTIONS.PreserveProtoNames;
|
|
263
|
+
const reader = r.body?.getReader();
|
|
242
264
|
if (!reader) {
|
|
243
265
|
throw new Error('NDJSON response has no readable body');
|
|
244
266
|
}
|
|
@@ -272,7 +294,9 @@ export class Fetcher {
|
|
|
272
294
|
// Here we simply rethrow to fail fast.
|
|
273
295
|
throw new Error(`Failed to parse NDJSON line: ${trimmed}`);
|
|
274
296
|
}
|
|
275
|
-
yield
|
|
297
|
+
yield preserveProtoNames
|
|
298
|
+
? deepProtoNameToJsonName(parsed)
|
|
299
|
+
: parsed;
|
|
276
300
|
}
|
|
277
301
|
}
|
|
278
302
|
// Emit any remaining data after the last chunk.
|
|
@@ -290,27 +314,6 @@ export class Fetcher {
|
|
|
290
314
|
// as unknown as AsyncIterable<RES>
|
|
291
315
|
resolve(iterator);
|
|
292
316
|
});
|
|
293
|
-
this.responseHandler.set('text/html', r => {
|
|
294
|
-
r.text()
|
|
295
|
-
.then(text => {
|
|
296
|
-
resolve(text);
|
|
297
|
-
})
|
|
298
|
-
.catch(err => {
|
|
299
|
-
reject(err);
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
this.responseHandler.set('application/json', r => {
|
|
303
|
-
r.json()
|
|
304
|
-
.then(json => {
|
|
305
|
-
// convert to literal type when needed
|
|
306
|
-
resolve(this.API_OPTIONS.PreserveProtoNames
|
|
307
|
-
? deepProtoNameToJsonName(json)
|
|
308
|
-
: json);
|
|
309
|
-
})
|
|
310
|
-
.catch(err => {
|
|
311
|
-
reject(err);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
317
|
this.responseHandler.set('application/octet-stream', r => {
|
|
315
318
|
r.arrayBuffer()
|
|
316
319
|
.then(buffer => {
|
|
@@ -394,11 +397,11 @@ export class Fetcher {
|
|
|
394
397
|
keysForBodyOrQueryParams.forEach(key => {
|
|
395
398
|
if (Array.isArray(rqo[key])) {
|
|
396
399
|
rqo[key].forEach(e => {
|
|
397
|
-
params.push(`${key}=${e}`);
|
|
400
|
+
params.push(`${this.API_OPTIONS.PreserveProtoNames ? jsonNameToProtoName(key) : key}=${e}`);
|
|
398
401
|
});
|
|
399
402
|
}
|
|
400
403
|
else {
|
|
401
|
-
params.push(`${key}=${rqo[key]}`);
|
|
404
|
+
params.push(`${this.API_OPTIONS.PreserveProtoNames ? jsonNameToProtoName(key) : key}=${rqo[key]}`);
|
|
402
405
|
}
|
|
403
406
|
});
|
|
404
407
|
if (params.length) {
|
package/dist/Fetcher.js.map
CHANGED
|
@@ -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,EAAE,QAAQ;SACnB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,yBAAyB;IAC9E,CAAC;IAEM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AM,CAAC;oBACN,MAAM,CAAC,IAAI,CAAC,GAAG,GAAa,IAAI,GAAG,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\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 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(\n (data)=>{\n resolve(data);\n }\n\n ).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 * 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 * 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 resolve(r as RES);\n if (this.onResponse) {\n this.onResponse(r as RES, response);\n }\n })\n .catch(error => {\n reject(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 reject(r);\n if (this.onResponseError) {\n this.onResponseError(r, response);\n }\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 reject(error);\n if (this.onResponseErrorParseError) {\n this.onResponseErrorParseError(error, response);\n }\n });\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 // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n\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('application/x-ndjson', response => {\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('NDJSON response has no readable body');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n // Async generator that yields parsed NDJSON objects.\n const iterator = {\n async *[Symbol.asyncIterator](): AsyncGenerator<RES> {\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Split the buffer into lines. The last line may be incomplete.\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (trimmed === ''){\n // eslint-disable-next-line no-continue\n continue; // skip empty lines\n }\n\n // Parse the JSON line and yield the result.\n let parsed: RES;\n try {\n parsed = JSON.parse(trimmed) as RES;\n } catch (e) {\n // If parsing fails, we can choose to throw, skip, or yield an error object.\n // Here we simply rethrow to fail fast.\n throw new Error(`Failed to parse NDJSON line: ${trimmed}`);\n }\n\n yield self.API_OPTIONS.PreserveProtoNames ? deepProtoNameToJsonName(parsed) as RES : parsed;\n }\n }\n\n // Emit any remaining data after the last chunk.\n if (buffer.trim() !== '') {\n try {\n yield JSON.parse(buffer.trim()) as RES;\n } catch (e) {\n throw new Error(`Failed to parse final NDJSON line: ${buffer.trim()}`);\n }\n }\n },\n };\n\n // Return the async iterator that satisfies the Symbol.asyncIterator contract.\n // as unknown as AsyncIterable<RES>\n resolve( iterator );\n\n\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"]}
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ACH,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, jsonNameToProtoName,\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 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)\n .then(data => {\n resolve(data);\n })\n .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 * 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 * 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 resolve(r as RES);\n if (this.onResponse) {\n this.onResponse(r as RES, response);\n }\n })\n .catch(error => {\n reject(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 reject(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 reject(error);\n if (this.onResponseErrorParseError) {\n this.onResponseErrorParseError(error, response);\n }\n });\n }\n });\n }\n\n /**\n * parses response object according to lastRequest header 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\n this.responseHandler.set('application/x-ndjson', r => {\n const preserveProtoNames = this.API_OPTIONS.PreserveProtoNames;\n\n const reader = r.body?.getReader();\n if (!reader) {\n throw new Error('NDJSON response has no readable body');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n // Async generator that yields parsed NDJSON objects.\n const iterator = {\n async *[Symbol.asyncIterator](): AsyncGenerator<RES> {\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Split the buffer into lines. The last line may be incomplete.\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (trimmed === '') {\n // eslint-disable-next-line no-continue\n continue; // skip empty lines\n }\n\n // Parse the JSON line and yield the result.\n let parsed: RES;\n try {\n parsed = JSON.parse(trimmed) as RES;\n } catch (e) {\n // If parsing fails, we can choose to throw, skip, or yield an error object.\n // Here we simply rethrow to fail fast.\n throw new Error(`Failed to parse NDJSON line: ${trimmed}`);\n }\n\n yield preserveProtoNames\n ? (deepProtoNameToJsonName(parsed) as RES)\n : parsed;\n }\n }\n\n // Emit any remaining data after the last chunk.\n if (buffer.trim() !== '') {\n try {\n yield JSON.parse(buffer.trim()) as RES;\n } catch (e) {\n throw new Error(\n `Failed to parse final NDJSON line: ${buffer.trim()}`,\n );\n }\n }\n },\n };\n\n // Return the async iterator that satisfies the Symbol.asyncIterator contract.\n // as unknown as AsyncIterable<RES>\n resolve(iterator);\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(`${this.API_OPTIONS.PreserveProtoNames? jsonNameToProtoName(key as string):(key as string)}=${e}`);\n });\n } else {\n\n params.push(`${this.API_OPTIONS.PreserveProtoNames? jsonNameToProtoName(key as string):(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.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { ValueState } from './ValueState.js';
|
|
5
5
|
import { FieldConstraints } from './FieldConstraints.js';
|
|
6
|
-
type EventType = 'field-value-changed' | 'this-field-value-changed' | 'field-value-updated' | 'this-state-changed' | 'state-changed' | 'validity-changed' | 'array-changed' | 'this-array-changed' | 'map-changed' | 'this-map-changed' | 'model-injected';
|
|
6
|
+
type EventType = 'field-value-changed' | 'this-field-value-changed' | 'field-value-updated' | 'this-state-changed' | 'state-changed' | 'validity-changed' | 'array-changed' | 'this-array-changed' | 'map-changed' | 'this-map-changed' | 'parent-readonly-set' | 'parent-readonly-unset' | 'model-injected';
|
|
7
7
|
type Meta = {
|
|
8
8
|
businessVaueState: ValueState;
|
|
9
9
|
index?: number;
|
|
@@ -101,6 +101,17 @@ export declare abstract class FieldNode {
|
|
|
101
101
|
* @param {string} deepPath - Path of the field.
|
|
102
102
|
*/
|
|
103
103
|
__getFieldNodeByPath(deepPath?: string): FieldNode | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Check if the node is "readonly"
|
|
106
|
+
*
|
|
107
|
+
* When any this node or any parent is *ro*, this will return false.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
__isLogicalReadonly(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Set the readonly state
|
|
113
|
+
* @param v
|
|
114
|
+
*/
|
|
104
115
|
set __readonly(v: boolean);
|
|
105
116
|
get __readonly(): boolean;
|
|
106
117
|
/**
|
package/dist/FieldNode.js
CHANGED
|
@@ -61,7 +61,7 @@ export class FieldNode {
|
|
|
61
61
|
isArrayNode: false,
|
|
62
62
|
isRecursionNode: false,
|
|
63
63
|
isAnyNode: false,
|
|
64
|
-
eventListener: new Map()
|
|
64
|
+
eventListener: new Map()
|
|
65
65
|
};
|
|
66
66
|
this.___readonlyState = new Map();
|
|
67
67
|
this.__parentNode = parent;
|
|
@@ -104,22 +104,33 @@ export class FieldNode {
|
|
|
104
104
|
}
|
|
105
105
|
return undefined;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if the node is "readonly"
|
|
109
|
+
*
|
|
110
|
+
* When any this node or any parent is *ro*, this will return false.
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
__isLogicalReadonly() {
|
|
114
|
+
if (this.__readonly) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
if (this.__parentNode) {
|
|
118
|
+
return this.__parentNode.__isLogicalReadonly();
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Set the readonly state
|
|
124
|
+
* @param v
|
|
125
|
+
*/
|
|
107
126
|
set __readonly(v) {
|
|
127
|
+
// to save resources, we could check for __isReadonly and fire the event based on this
|
|
108
128
|
this.__meta.readonly = v;
|
|
109
129
|
// dispatch to children
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (cro === undefined) {
|
|
115
|
-
this.___readonlyState.set(child, child.__readonly);
|
|
116
|
-
}
|
|
117
|
-
if (!child.__readonly && v) {
|
|
118
|
-
// eslint-disable-next-line no-param-reassign
|
|
119
|
-
child.__readonly = v;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
130
|
+
this.__broadcastEvent(new CustomEvent(v ? 'parent-readonly-set' : 'parent-readonly-unset', {
|
|
131
|
+
detail: this,
|
|
132
|
+
bubbles: false
|
|
133
|
+
}));
|
|
123
134
|
}
|
|
124
135
|
get __readonly() {
|
|
125
136
|
return this.__meta.readonly;
|
|
@@ -135,7 +146,7 @@ export class FieldNode {
|
|
|
135
146
|
this.__dispatchEvent(new CustomEvent('model-injected', {
|
|
136
147
|
composed: true,
|
|
137
148
|
bubbles: false,
|
|
138
|
-
detail: this
|
|
149
|
+
detail: this
|
|
139
150
|
}));
|
|
140
151
|
this.__meta.isPristine = true;
|
|
141
152
|
// this.__notifyFieldValueChange(true);
|
|
@@ -331,7 +342,7 @@ export class FieldNode {
|
|
|
331
342
|
carrier.push({
|
|
332
343
|
field: this.__fieldPath,
|
|
333
344
|
state: this.__meta.valueState,
|
|
334
|
-
message: this.__meta.stateMessage
|
|
345
|
+
message: this.__meta.stateMessage
|
|
335
346
|
});
|
|
336
347
|
}
|
|
337
348
|
this.__childNodes.forEach(child => {
|
|
@@ -354,7 +365,7 @@ export class FieldNode {
|
|
|
354
365
|
});
|
|
355
366
|
this.__dispatchEvent(new CustomEvent('state-changed', {
|
|
356
367
|
detail: this,
|
|
357
|
-
bubbles: false
|
|
368
|
+
bubbles: false
|
|
358
369
|
}));
|
|
359
370
|
}
|
|
360
371
|
/**
|
|
@@ -384,12 +395,12 @@ export class FieldNode {
|
|
|
384
395
|
if (fn.__meta.isValid !== validStateBefore) {
|
|
385
396
|
fn.__dispatchEvent(new CustomEvent('validity-changed', {
|
|
386
397
|
detail: fn,
|
|
387
|
-
bubbles: true
|
|
398
|
+
bubbles: true
|
|
388
399
|
}));
|
|
389
400
|
}
|
|
390
401
|
fn.__dispatchEvent(new CustomEvent('state-changed', {
|
|
391
402
|
detail: fn,
|
|
392
|
-
bubbles: false
|
|
403
|
+
bubbles: false
|
|
393
404
|
}));
|
|
394
405
|
}
|
|
395
406
|
});
|
|
@@ -513,7 +524,7 @@ export class FieldNode {
|
|
|
513
524
|
if (this.__meta.isValid !== validStateBefore) {
|
|
514
525
|
this.__dispatchEvent(new CustomEvent('validity-changed', {
|
|
515
526
|
detail: this,
|
|
516
|
-
bubbles: false
|
|
527
|
+
bubbles: false
|
|
517
528
|
}));
|
|
518
529
|
}
|
|
519
530
|
}
|
|
@@ -547,7 +558,7 @@ export class FieldNode {
|
|
|
547
558
|
if (this.__meta.isValid !== validStateBefore) {
|
|
548
559
|
this.__dispatchEvent(new CustomEvent('validity-changed', {
|
|
549
560
|
detail: this,
|
|
550
|
-
bubbles: false
|
|
561
|
+
bubbles: false
|
|
551
562
|
}));
|
|
552
563
|
}
|
|
553
564
|
if (this.__parentNode) {
|
|
@@ -618,15 +629,18 @@ export class FieldNode {
|
|
|
618
629
|
* @param {string[]} messageAndParams - Description for the formatter.
|
|
619
630
|
*/
|
|
620
631
|
__setValueState(state, messageAndParams) {
|
|
632
|
+
const shouldNotify = (this.__meta.valueState !== state);
|
|
621
633
|
this.__meta.valueState = state;
|
|
622
634
|
this.__meta.stateMessage = OPEN_MODELS_OPTIONS.valueStateMessageFormatter(messageAndParams[0], ...messageAndParams.slice(1));
|
|
623
635
|
// set invalid on error state
|
|
624
636
|
// the event is sent from ...
|
|
625
637
|
this.__meta.isValid = state !== ValueState.Negative;
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
638
|
+
if (shouldNotify) {
|
|
639
|
+
this.__dispatchEvent(new CustomEvent('state-changed', {
|
|
640
|
+
detail: this,
|
|
641
|
+
bubbles: false
|
|
642
|
+
}));
|
|
643
|
+
}
|
|
630
644
|
}
|
|
631
645
|
/**
|
|
632
646
|
* Resets the node to the last inserted literal or to the initial state.
|
|
@@ -708,7 +722,7 @@ export class FieldNode {
|
|
|
708
722
|
__notifyFieldValueChange(bubbles) {
|
|
709
723
|
this.__dispatchEvent(new CustomEvent('this-field-value-changed', {
|
|
710
724
|
detail: this,
|
|
711
|
-
bubbles: false
|
|
725
|
+
bubbles: false
|
|
712
726
|
}));
|
|
713
727
|
if (bubbles) {
|
|
714
728
|
this.__rootNode.__meta.isPristine = false;
|
|
@@ -718,14 +732,14 @@ export class FieldNode {
|
|
|
718
732
|
// console.log('bubble', this.__meta.typeName)
|
|
719
733
|
this.__dispatchEvent(new CustomEvent('field-value-changed', {
|
|
720
734
|
detail: this,
|
|
721
|
-
bubbles: true
|
|
735
|
+
bubbles: true
|
|
722
736
|
}));
|
|
723
737
|
}
|
|
724
738
|
else {
|
|
725
739
|
// triggered on clear or fromLiteral
|
|
726
740
|
this.__dispatchEvent(new CustomEvent('field-value-updated', {
|
|
727
741
|
detail: this,
|
|
728
|
-
bubbles: false
|
|
742
|
+
bubbles: false
|
|
729
743
|
}));
|
|
730
744
|
}
|
|
731
745
|
}
|