@furo/open-models 1.16.3 → 1.18.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.
Files changed (83) hide show
  1. package/custom-elements.json +7257 -3068
  2. package/dist/API_OPTIONS.d.ts +1 -1
  3. package/dist/API_OPTIONS.js +5 -4
  4. package/dist/API_OPTIONS.js.map +1 -1
  5. package/dist/CustomPrototypes.js.map +1 -1
  6. package/dist/Fetcher.d.ts +2 -1
  7. package/dist/Fetcher.js +5 -5
  8. package/dist/Fetcher.js.map +1 -1
  9. package/dist/FieldNode.d.ts +31 -1
  10. package/dist/FieldNode.js +98 -0
  11. package/dist/FieldNode.js.map +1 -1
  12. package/dist/Mapper.js +6 -8
  13. package/dist/Mapper.js.map +1 -1
  14. package/dist/OPEN_MODELS_OPTIONS.js +2 -2
  15. package/dist/OPEN_MODELS_OPTIONS.js.map +1 -1
  16. package/dist/StrictFetcher.d.ts +58 -0
  17. package/dist/StrictFetcher.js +420 -0
  18. package/dist/StrictFetcher.js.map +1 -0
  19. package/dist/Validator.d.ts +1 -1
  20. package/dist/Validator.js.map +1 -1
  21. package/dist/ValueState.js.map +1 -1
  22. package/dist/index.d.ts +49 -47
  23. package/dist/index.js +41 -40
  24. package/dist/index.js.map +1 -1
  25. package/dist/primitives/BOOLEAN.d.ts +1 -1
  26. package/dist/primitives/BOOLEAN.js +9 -13
  27. package/dist/primitives/BOOLEAN.js.map +1 -1
  28. package/dist/primitives/DOUBLE.d.ts +2 -2
  29. package/dist/primitives/DOUBLE.js +17 -24
  30. package/dist/primitives/DOUBLE.js.map +1 -1
  31. package/dist/primitives/ENUM.d.ts +1 -1
  32. package/dist/primitives/ENUM.js +6 -9
  33. package/dist/primitives/ENUM.js.map +1 -1
  34. package/dist/primitives/FLOAT.d.ts +2 -2
  35. package/dist/primitives/FLOAT.js +17 -24
  36. package/dist/primitives/FLOAT.js.map +1 -1
  37. package/dist/primitives/INT32.d.ts +2 -2
  38. package/dist/primitives/INT32.js +17 -18
  39. package/dist/primitives/INT32.js.map +1 -1
  40. package/dist/primitives/SINT32.d.ts +2 -2
  41. package/dist/primitives/SINT32.js +17 -18
  42. package/dist/primitives/SINT32.js.map +1 -1
  43. package/dist/primitives/UINT32.d.ts +2 -2
  44. package/dist/primitives/UINT32.js +17 -18
  45. package/dist/primitives/UINT32.js.map +1 -1
  46. package/dist/web-components/furo-type-renderer.d.ts +2 -2
  47. package/dist/web-components/furo-type-renderer.js +2 -2
  48. package/dist/web-components/furo-type-renderer.js.map +1 -1
  49. package/dist/web-components/impl/TypeRenderer/index.d.ts +2 -2
  50. package/dist/web-components/impl/TypeRenderer/index.js +2 -2
  51. package/dist/web-components/impl/TypeRenderer/index.js.map +1 -1
  52. package/dist/well_known/BoolValue.d.ts +2 -2
  53. package/dist/well_known/BoolValue.js +12 -16
  54. package/dist/well_known/BoolValue.js.map +1 -1
  55. package/dist/well_known/BytesValue.d.ts +2 -2
  56. package/dist/well_known/BytesValue.js +21 -25
  57. package/dist/well_known/BytesValue.js.map +1 -1
  58. package/dist/well_known/DoubleValue.d.ts +1 -1
  59. package/dist/well_known/DoubleValue.js +23 -37
  60. package/dist/well_known/DoubleValue.js.map +1 -1
  61. package/dist/well_known/Duration.d.ts +2 -2
  62. package/dist/well_known/Duration.js +15 -19
  63. package/dist/well_known/Duration.js.map +1 -1
  64. package/dist/well_known/FieldMask.d.ts +2 -2
  65. package/dist/well_known/FieldMask.js +15 -19
  66. package/dist/well_known/FieldMask.js.map +1 -1
  67. package/dist/well_known/FloatValue.d.ts +2 -2
  68. package/dist/well_known/FloatValue.js +4 -4
  69. package/dist/well_known/FloatValue.js.map +1 -1
  70. package/dist/well_known/Int32Value.d.ts +2 -2
  71. package/dist/well_known/Int32Value.js +23 -31
  72. package/dist/well_known/Int32Value.js.map +1 -1
  73. package/dist/well_known/Timestamp.d.ts +2 -2
  74. package/dist/well_known/Timestamp.js +15 -19
  75. package/dist/well_known/Timestamp.js.map +1 -1
  76. package/dist/well_known/UInt32Value.d.ts +2 -2
  77. package/dist/well_known/UInt32Value.js +23 -31
  78. package/dist/well_known/UInt32Value.js.map +1 -1
  79. package/dist/well_known/UInt64Value.d.ts +2 -2
  80. package/dist/well_known/UInt64Value.js +23 -34
  81. package/dist/well_known/UInt64Value.js.map +1 -1
  82. package/package.json +3 -13
  83. package/web-types.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { IApiOptions } from './Fetcher.js';
1
+ import type { IApiOptions } from "./Fetcher.js";
2
2
  /**
3
3
  * To set the API OPTIONS you should update this const, before you create new services
4
4
  */
@@ -2,10 +2,11 @@
2
2
  * To set the API OPTIONS you should update this const, before you create new services
3
3
  */
4
4
  export const API_OPTIONS = {
5
- serverAddr: '',
6
- ApiBaseURL: '/api',
7
- headers: new Headers({ 'Content-Type': 'application/json' }),
5
+ serverAddr: "",
6
+ ApiBaseURL: "/api",
7
+ headers: new Headers({ "Content-Type": "application/json" }),
8
8
  // timeout: 3000
9
- PreserveProtoNames: false,
9
+ UseProtoNames: true, // server uses proto names
10
+ UseProtoNamesForQueryParams: true,
10
11
  };
11
12
  //# sourceMappingURL=API_OPTIONS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"API_OPTIONS.js","sourceRoot":"","sources":["../src/API_OPTIONS.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAgB;IACtC,UAAU,EAAE,EAAE;IACd,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;IAC5D,gBAAgB;IAChB,kBAAkB,EAAE,KAAK;CAC1B,CAAC","sourcesContent":["import type { IApiOptions } from './Fetcher';\n\n/**\n * To set the API OPTIONS you should update this const, before you create new services\n */\nexport const API_OPTIONS: IApiOptions = {\n serverAddr: '',\n ApiBaseURL: '/api',\n headers: new Headers({ 'Content-Type': 'application/json' }),\n // timeout: 3000\n PreserveProtoNames: false,\n};\n"]}
1
+ {"version":3,"file":"API_OPTIONS.js","sourceRoot":"","sources":["../src/API_OPTIONS.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAgB;IACtC,UAAU,EAAE,EAAE;IACd,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;IAC5D,gBAAgB;IAChB,aAAa,EAAE,IAAI,EAAE,0BAA0B;IAC/C,2BAA2B,EAAE,IAAI;CAClC,CAAC","sourcesContent":["import type { IApiOptions } from \"./Fetcher\";\n\n/**\n * To set the API OPTIONS you should update this const, before you create new services\n */\nexport const API_OPTIONS: IApiOptions = {\n serverAddr: \"\",\n ApiBaseURL: \"/api\",\n headers: new Headers({ \"Content-Type\": \"application/json\" }),\n // timeout: 3000\n UseProtoNames: true, // server uses proto names\n UseProtoNamesForQueryParams: true,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CustomPrototypes.js","sourceRoot":"","sources":["../src/CustomPrototypes.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,QAAQ,GAAuB,IAAI,GAAG,EAAiB,CAAC;AACrE,MAAM,CAAC,MAAM,OAAO,GAAsB,IAAI,GAAG,EAAgB,CAAC","sourcesContent":["\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype str = (d: any) => string;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype nr = (d: any) => number;\n\n// Full qualified type name\ntype typeName = string;\n\nexport const ToString: Map<typeName, str> = new Map<typeName, str>();\nexport const ValueOf: Map<typeName, nr> = new Map<typeName, nr>();\n"]}
1
+ {"version":3,"file":"CustomPrototypes.js","sourceRoot":"","sources":["../src/CustomPrototypes.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,QAAQ,GAAuB,IAAI,GAAG,EAAiB,CAAC;AACrE,MAAM,CAAC,MAAM,OAAO,GAAsB,IAAI,GAAG,EAAgB,CAAC","sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype str = (d: any) => string;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype nr = (d: any) => number;\n\n// Full qualified type name\ntype typeName = string;\n\nexport const ToString: Map<typeName, str> = new Map<typeName, str>();\nexport const ValueOf: Map<typeName, nr> = new Map<typeName, nr>();\n"]}
package/dist/Fetcher.d.ts CHANGED
@@ -3,7 +3,8 @@ export interface IApiOptions {
3
3
  ApiBaseURL: string;
4
4
  headers?: Headers;
5
5
  timeout?: number;
6
- PreserveProtoNames: boolean;
6
+ UseProtoNames: boolean;
7
+ UseProtoNamesForQueryParams: boolean;
7
8
  }
8
9
  interface Handlers<REQ, RES> {
9
10
  /**
package/dist/Fetcher.js CHANGED
@@ -255,7 +255,7 @@ export class Fetcher {
255
255
  r.json()
256
256
  .then(json => {
257
257
  // convert to literal type when needed
258
- resolve(this.API_OPTIONS.PreserveProtoNames ? deepProtoNameToJsonName(json) : json);
258
+ resolve(this.API_OPTIONS.UseProtoNames ? deepProtoNameToJsonName(json) : json);
259
259
  })
260
260
  .catch((err) => {
261
261
  // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers
@@ -263,7 +263,7 @@ export class Fetcher {
263
263
  });
264
264
  });
265
265
  this.responseHandler.set("application/x-ndjson", r => {
266
- const preserveProtoNames = this.API_OPTIONS.PreserveProtoNames;
266
+ const preserveProtoNames = this.API_OPTIONS.UseProtoNames;
267
267
  const reader = r.body?.getReader();
268
268
  if (!reader) {
269
269
  throw new Error("NDJSON response has no readable body");
@@ -397,18 +397,18 @@ export class Fetcher {
397
397
  keysForBodyOrQueryParams.forEach(key => {
398
398
  if (Array.isArray(rqo[key])) {
399
399
  rqo[key].forEach(e => {
400
- params.push(`${this.API_OPTIONS.PreserveProtoNames ? jsonNameToProtoName(key) : key}=${String(e)}`);
400
+ params.push(`${this.API_OPTIONS.UseProtoNames ? jsonNameToProtoName(key) : key}=${String(e)}`);
401
401
  });
402
402
  }
403
403
  else {
404
- params.push(`${this.API_OPTIONS.PreserveProtoNames ? jsonNameToProtoName(key) : key}=${String(rqo[key])}`);
404
+ params.push(`${this.API_OPTIONS.UseProtoNames ? jsonNameToProtoName(key) : key}=${String(rqo[key])}`);
405
405
  }
406
406
  });
407
407
  if (params.length) {
408
408
  evaluatedPath = `${evaluatedPath}?${params.join("&")}`;
409
409
  }
410
410
  if (bodyField !== undefined) {
411
- evaluatedBody = JSON.stringify(this.API_OPTIONS.PreserveProtoNames ? deepJsonNameToProtoName(rqo[bodyField]) : rqo[bodyField]);
411
+ evaluatedBody = JSON.stringify(this.API_OPTIONS.UseProtoNames ? deepJsonNameToProtoName(rqo[bodyField]) : rqo[bodyField]);
412
412
  }
413
413
  }
414
414
  evaluatedPath = `${this.API_OPTIONS.serverAddr}${this.API_OPTIONS.ApiBaseURL}${evaluatedPath}`;
@@ -1 +1 @@
1
- {"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAuFtH,MAAM,OAAO,OAAO;IA6BlB;;;;;;OAMG;IACH,YACE,OAAoB;IACpB,SAAS;IACT,MAAc;IACd,eAAe;IACf,IAAY,EACZ,SAA2B;QAlC7B;;WAEG;QACI,cAAS,GAAG,KAAK,CAAC;QAQjB,oBAAe,GAAuC,IAAI,GAAG,EAAiC,CAAC;QAyBrG,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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,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,aAAa,EAAE,CAAC;QAE/F,OAAO;YACL,aAAa;YACb,aAAa;SACd,CAAC;IACJ,CAAC;CA4EF","sourcesContent":["import { deepJsonNameToProtoName, deepProtoNameToJsonName, jsonNameToProtoName, protoNameToJsonName } 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?: (error: unknown, serverResponse: Response) => 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 = 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<string, (r: Response) => void>();\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 as REQ);\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(this.path, this.bodyField, rqo);\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 ${String(this.timeout)}ms reached`);\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n\n console.error(`RequestService fetch aborted: Timeout of ${String(this.timeout)}ms reached`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n this.isLoading = false;\n\n if (err instanceof Error && err.name === \"AbortError\") {\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n\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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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;\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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\n _parseResponse(response: Response) {\n return new Promise((resolve, reject) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime data may not match types (REST API input)\n if (response) {\n this.responseHandler.set(\"text/plain\", r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch((err: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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(this.API_OPTIONS.PreserveProtoNames ? deepProtoNameToJsonName(json) : json);\n })\n .catch((err: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- loop exits via break on done\n while (true) {\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 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 {\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 ? (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 {\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 this.responseHandler.set(\"application/octet-stream\", r => {\n r.arrayBuffer()\n .then(buffer => {\n resolve(buffer);\n })\n .catch((err: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\n reject(err);\n });\n });\n\n const contentType = response.headers.get(\"content-type\");\n let handler = contentType?.split(\";\")[0].trim();\n handler ??= \"application/json\";\n let typeHandler = this.responseHandler.get(handler);\n\n if (typeHandler === undefined) {\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 = new Map<string, keyof REQ>();\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 const rqoKey = protoNameToJsonName(field[1]) as keyof REQ;\n const rqoValue = rqo[rqoKey];\n evaluatedPath = evaluatedPath.replace(field[0], String(rqoValue));\n keysForBodyOrQueryParams.delete(rqoKey as string);\n });\n\n if (bodyField === \"*\") {\n // build body object\n const body: Record<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)}=${String(e)}`);\n });\n } else {\n params.push(`${this.API_OPTIONS.PreserveProtoNames ? jsonNameToProtoName(key as string) : (key as string)}=${String(rqo[key])}`);\n }\n });\n if (params.length) {\n evaluatedPath = `${evaluatedPath}?${params.join(\"&\")}`;\n }\n\n if (bodyField !== undefined) {\n evaluatedBody = JSON.stringify(this.API_OPTIONS.PreserveProtoNames ? deepJsonNameToProtoName(rqo[bodyField]) : rqo[bodyField]);\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?: (error: unknown, serverResponse: Response) => 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,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAwFtH,MAAM,OAAO,OAAO;IA6BlB;;;;;;OAMG;IACH,YACE,OAAoB;IACpB,SAAS;IACT,MAAc;IACd,eAAe;IACf,IAAY,EACZ,SAA2B;QAlC7B;;WAEG;QACI,cAAS,GAAG,KAAK,CAAC;QAQjB,oBAAe,GAAuC,IAAI,GAAG,EAAiC,CAAC;QAyBrG,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,iBAAiB,CAAC,EAAe;QACtC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG;YACjB,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a,CAAC,CAAC,CAAC,CAAE,GAAc,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;oBACvH,CAAC,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAa,CAAC,CAAC,CAAC,CAAE,GAAc,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC9H,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,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;YAC5H,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;CA4EF","sourcesContent":["import { deepJsonNameToProtoName, deepProtoNameToJsonName, jsonNameToProtoName, protoNameToJsonName } 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 UseProtoNames: boolean; // server uses proto names on the transport layer\n UseProtoNamesForQueryParams: 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?: (error: unknown, serverResponse: Response) => 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 = 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<string, (r: Response) => void>();\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 as REQ);\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(this.path, this.bodyField, rqo);\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 ${String(this.timeout)}ms reached`);\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n\n console.error(`RequestService fetch aborted: Timeout of ${String(this.timeout)}ms reached`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n this.isLoading = false;\n\n if (err instanceof Error && err.name === \"AbortError\") {\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n\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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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;\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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 // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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\n _parseResponse(response: Response) {\n return new Promise((resolve, reject) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- runtime data may not match types (REST API input)\n if (response) {\n this.responseHandler.set(\"text/plain\", r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch((err: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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(this.API_OPTIONS.UseProtoNames ? deepProtoNameToJsonName(json) : json);\n })\n .catch((err: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\n reject(err);\n });\n });\n\n this.responseHandler.set(\"application/x-ndjson\", r => {\n const preserveProtoNames = this.API_OPTIONS.UseProtoNames;\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- loop exits via break on done\n while (true) {\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 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 {\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 ? (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 {\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 this.responseHandler.set(\"application/octet-stream\", r => {\n r.arrayBuffer()\n .then(buffer => {\n resolve(buffer);\n })\n .catch((err: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\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: unknown) => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- changing rejection types would break downstream error handlers\n reject(err);\n });\n });\n\n const contentType = response.headers.get(\"content-type\");\n let handler = contentType?.split(\";\")[0].trim();\n handler ??= \"application/json\";\n let typeHandler = this.responseHandler.get(handler);\n\n if (typeHandler === undefined) {\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 = new Map<string, keyof REQ>();\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 const rqoKey = protoNameToJsonName(field[1]) as keyof REQ;\n const rqoValue = rqo[rqoKey];\n evaluatedPath = evaluatedPath.replace(field[0], String(rqoValue));\n keysForBodyOrQueryParams.delete(rqoKey as string);\n });\n\n if (bodyField === \"*\") {\n // build body object\n const body: Record<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.UseProtoNames ? jsonNameToProtoName(key as string) : (key as string)}=${String(e)}`);\n });\n } else {\n params.push(`${this.API_OPTIONS.UseProtoNames ? jsonNameToProtoName(key as string) : (key as string)}=${String(rqo[key])}`);\n }\n });\n if (params.length) {\n evaluatedPath = `${evaluatedPath}?${params.join(\"&\")}`;\n }\n\n if (bodyField !== undefined) {\n evaluatedBody = JSON.stringify(this.API_OPTIONS.UseProtoNames ? deepJsonNameToProtoName(rqo[bodyField]) : rqo[bodyField]);\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?: (error: unknown, serverResponse: Response) => 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,6 +1,6 @@
1
1
  import type { FieldConstraints } from "./FieldConstraints.js";
2
2
  import { ValueState } from "./ValueState.js";
3
- export type ModelEventType = "update" | "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";
3
+ export type ModelEventType = "update" | "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" | "oneof-changed";
4
4
  interface Meta {
5
5
  businessVaueState: ValueState;
6
6
  index?: number;
@@ -11,6 +11,7 @@ interface Meta {
11
11
  valueState: ValueState;
12
12
  stateMessage: string;
13
13
  nodeFields: FieldDescriptor[];
14
+ oneofGroups: Map<string, string | undefined>;
14
15
  readonly: boolean;
15
16
  required: boolean;
16
17
  isArrayNode: boolean;
@@ -39,6 +40,7 @@ export interface FieldDescriptor {
39
40
  ValueConstructor?: new () => FieldNode;
40
41
  constraints?: FieldConstraints;
41
42
  description?: string;
43
+ oneofGroup?: string;
42
44
  }
43
45
  export interface ValueStateSummary {
44
46
  /**
@@ -299,6 +301,34 @@ export declare abstract class FieldNode {
299
301
  * A cleared field is not populated on `__toLiteral` or `__toJson` when the option `EmitUnpopulated` or `EmitDefaultValues` is set to false.
300
302
  */
301
303
  __clear(withoutNotification?: boolean): void;
304
+ /**
305
+ * Clears sibling fields in the same oneof group when a field is set.
306
+ * @param targetNode - The field being set
307
+ */
308
+ private __clearOneofSiblings;
309
+ /**
310
+ * Returns the active field name in a oneof group.
311
+ * @param groupName - The name of the oneof group
312
+ */
313
+ __whichOneof(groupName: string): string | undefined;
314
+ /**
315
+ * Returns the FieldNode of the active oneof field.
316
+ * @param groupName - The name of the oneof group
317
+ */
318
+ __getOneofFieldNode(groupName: string): FieldNode | undefined;
319
+ /**
320
+ * Explicitly clears a oneof group so no field is active.
321
+ * @param groupName - The name of the oneof group
322
+ */
323
+ __clearOneof(groupName: string): void;
324
+ /**
325
+ * Returns the oneof group name this field belongs to, if any.
326
+ */
327
+ get __oneofGroup(): string | undefined;
328
+ /**
329
+ * Returns true if this field is the active member of its oneof group.
330
+ */
331
+ get __isActiveOneofField(): boolean;
302
332
  /**
303
333
  * Helper method to update a skalar / primitive field of a type. Used by the generated models.
304
334
  * Triggers also the validation and clearance, if needed.
package/dist/FieldNode.js CHANGED
@@ -60,6 +60,7 @@ export class FieldNode {
60
60
  stateMessage: "",
61
61
  typeName: "",
62
62
  nodeFields: [],
63
+ oneofGroups: new Map(),
63
64
  isArrayNode: false,
64
65
  isRecursionNode: false,
65
66
  isAnyNode: false,
@@ -186,6 +187,10 @@ export class FieldNode {
186
187
  }
187
188
  return;
188
189
  }
190
+ // track oneof group state from incoming data
191
+ if (field.oneofGroup) {
192
+ this.__meta.oneofGroups.set(field.oneofGroup, field.fieldName);
193
+ }
189
194
  this[`_${field.fieldName}`].__updateWithLiteral(data[field.fieldName]);
190
195
  this[`_${field.fieldName}`].__meta.isPristine = false;
191
196
  });
@@ -204,6 +209,10 @@ export class FieldNode {
204
209
  __toJson() {
205
210
  const d = {};
206
211
  this.__meta.nodeFields.forEach(f => {
212
+ // skip inactive oneof fields (proto3 JSON spec: only active member is serialized)
213
+ if (f.oneofGroup && this.__meta.oneofGroups.get(f.oneofGroup) !== f.fieldName) {
214
+ return null;
215
+ }
207
216
  // use jsonName if UseProtoNames is set, otherwise convert to lowerCamel without X prefix
208
217
  const jsonName = OPEN_MODELS_OPTIONS.UseProtoNames ? f.protoName : this.__toLowerCamelCaseWithoutXPrefix(f.protoName);
209
218
  if (OPEN_MODELS_OPTIONS.EmitUnpopulated) {
@@ -257,6 +266,10 @@ export class FieldNode {
257
266
  __toLiteral() {
258
267
  const d = {};
259
268
  this.__meta.nodeFields.forEach(f => {
269
+ // skip inactive oneof fields (proto3 JSON spec: only active member is serialized)
270
+ if (f.oneofGroup && this.__meta.oneofGroups.get(f.oneofGroup) !== f.fieldName) {
271
+ return null;
272
+ }
260
273
  if (this[`_${f.fieldName}`] &&
261
274
  (!this[`_${f.fieldName}`].__isEmpty || this[`_${f.fieldName}`].__meta.required)) {
262
275
  d[f.fieldName] = this[`_${f.fieldName}`].__toLiteral();
@@ -648,6 +661,10 @@ export class FieldNode {
648
661
  */
649
662
  __clear(withoutNotification = false) {
650
663
  this.__isEmpty = true;
664
+ // reset oneof group state
665
+ this.__meta.oneofGroups.forEach((_v, key) => {
666
+ this.__meta.oneofGroups.set(key, undefined);
667
+ });
651
668
  // __clear every childNode too
652
669
  this.__meta.nodeFields.forEach(descriptor => {
653
670
  this[`_${descriptor.fieldName}`].__clear(withoutNotification);
@@ -659,6 +676,85 @@ export class FieldNode {
659
676
  // todo: set state to None
660
677
  // todo: set valid to true
661
678
  }
679
+ /**
680
+ * Clears sibling fields in the same oneof group when a field is set.
681
+ * @param targetNode - The field being set
682
+ */
683
+ __clearOneofSiblings(targetNode) {
684
+ const fieldName = targetNode.__meta.fieldName;
685
+ if (!fieldName)
686
+ return;
687
+ const descriptor = this.__meta.nodeFields.find(f => f.fieldName === fieldName);
688
+ if (!descriptor?.oneofGroup)
689
+ return;
690
+ const groupName = descriptor.oneofGroup;
691
+ const previousActive = this.__meta.oneofGroups.get(groupName);
692
+ // Clear all OTHER fields in the same oneof group (silently)
693
+ this.__meta.nodeFields
694
+ .filter(f => f.oneofGroup === groupName && f.fieldName !== fieldName)
695
+ .forEach(f => {
696
+ this[`_${f.fieldName}`].__clear(true);
697
+ });
698
+ // Mark this field as active
699
+ this.__meta.oneofGroups.set(groupName, fieldName);
700
+ targetNode.__isEmpty = false;
701
+ // Emit event if active field changed
702
+ if (previousActive !== fieldName) {
703
+ this.__dispatchEvent(new CustomEvent("oneof-changed", {
704
+ detail: { group: groupName, activeField: fieldName, previousField: previousActive },
705
+ bubbles: true,
706
+ }));
707
+ }
708
+ }
709
+ /**
710
+ * Returns the active field name in a oneof group.
711
+ * @param groupName - The name of the oneof group
712
+ */
713
+ __whichOneof(groupName) {
714
+ return this.__meta.oneofGroups.get(groupName);
715
+ }
716
+ /**
717
+ * Returns the FieldNode of the active oneof field.
718
+ * @param groupName - The name of the oneof group
719
+ */
720
+ __getOneofFieldNode(groupName) {
721
+ const activeField = this.__meta.oneofGroups.get(groupName);
722
+ if (!activeField)
723
+ return undefined;
724
+ return this[`_${activeField}`];
725
+ }
726
+ /**
727
+ * Explicitly clears a oneof group so no field is active.
728
+ * @param groupName - The name of the oneof group
729
+ */
730
+ __clearOneof(groupName) {
731
+ this.__meta.nodeFields
732
+ .filter(f => f.oneofGroup === groupName)
733
+ .forEach(f => {
734
+ this[`_${f.fieldName}`].__clear(true);
735
+ });
736
+ this.__meta.oneofGroups.set(groupName, undefined);
737
+ }
738
+ /**
739
+ * Returns the oneof group name this field belongs to, if any.
740
+ */
741
+ get __oneofGroup() {
742
+ if (!this.__meta.fieldName || !this.__parentNode)
743
+ return undefined;
744
+ const descriptor = this.__parentNode.__meta.nodeFields.find(f => f.fieldName === this.__meta.fieldName);
745
+ return descriptor?.oneofGroup;
746
+ }
747
+ /**
748
+ * Returns true if this field is the active member of its oneof group.
749
+ */
750
+ get __isActiveOneofField() {
751
+ if (!this.__meta.fieldName || !this.__parentNode)
752
+ return false;
753
+ const descriptor = this.__parentNode.__meta.nodeFields.find(f => f.fieldName === this.__meta.fieldName);
754
+ if (!descriptor?.oneofGroup)
755
+ return false;
756
+ return this.__parentNode.__meta.oneofGroups.get(descriptor.oneofGroup) === this.__meta.fieldName;
757
+ }
662
758
  /**
663
759
  * Helper method to update a skalar / primitive field of a type. Used by the generated models.
664
760
  * Triggers also the validation and clearance, if needed.
@@ -668,6 +764,7 @@ export class FieldNode {
668
764
  * @protected
669
765
  */
670
766
  __PrimitivesSetter(targetNode, value) {
767
+ this.__clearOneofSiblings(targetNode);
671
768
  // do not do anything if current value equals val
672
769
  if (targetNode._value !== value) {
673
770
  targetNode._value = value;
@@ -685,6 +782,7 @@ export class FieldNode {
685
782
  * @protected
686
783
  */
687
784
  __TypeSetter(targetNode, literalData) {
785
+ this.__clearOneofSiblings(targetNode);
688
786
  if (literalData === undefined || literalData === null) {
689
787
  targetNode.__clear();
690
788
  this.__validateBottomUp(targetNode);