@geekmidas/client 10.0.0-alpha.12 → 10.0.0-alpha.121

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 (113) hide show
  1. package/README.md +40 -57
  2. package/dist/auth-fetcher.cjs +78 -3
  3. package/dist/auth-fetcher.cjs.map +1 -0
  4. package/dist/auth-fetcher.d.cts +156 -3
  5. package/dist/auth-fetcher.d.cts.map +1 -0
  6. package/dist/auth-fetcher.d.mts +156 -3
  7. package/dist/auth-fetcher.d.mts.map +1 -0
  8. package/dist/auth-fetcher.mjs +77 -3
  9. package/dist/auth-fetcher.mjs.map +1 -0
  10. package/dist/endpoint-hooks.cjs +11 -15
  11. package/dist/endpoint-hooks.cjs.map +1 -1
  12. package/dist/endpoint-hooks.d.cts +4 -7
  13. package/dist/endpoint-hooks.d.cts.map +1 -1
  14. package/dist/endpoint-hooks.d.mts +4 -7
  15. package/dist/endpoint-hooks.d.mts.map +1 -1
  16. package/dist/endpoint-hooks.mjs +5 -9
  17. package/dist/endpoint-hooks.mjs.map +1 -1
  18. package/dist/fetcher.cjs +115 -3
  19. package/dist/fetcher.cjs.map +1 -0
  20. package/dist/fetcher.d.cts +24 -3
  21. package/dist/fetcher.d.cts.map +1 -0
  22. package/dist/fetcher.d.mts +24 -3
  23. package/dist/fetcher.d.mts.map +1 -0
  24. package/dist/fetcher.mjs +90 -2
  25. package/dist/fetcher.mjs.map +1 -0
  26. package/dist/index.cjs +13 -6
  27. package/dist/index.d.cts +7 -5
  28. package/dist/index.d.mts +7 -5
  29. package/dist/index.mjs +7 -6
  30. package/dist/infer.cjs +0 -1
  31. package/dist/infer.d.cts +130 -2
  32. package/dist/infer.d.cts.map +1 -0
  33. package/dist/infer.d.mts +130 -2
  34. package/dist/infer.d.mts.map +1 -0
  35. package/dist/infer.mjs +1 -1
  36. package/dist/methods.cjs +21 -0
  37. package/dist/methods.cjs.map +1 -0
  38. package/dist/methods.d.cts +23 -0
  39. package/dist/methods.d.cts.map +1 -0
  40. package/dist/methods.d.mts +23 -0
  41. package/dist/methods.d.mts.map +1 -0
  42. package/dist/methods.mjs +19 -0
  43. package/dist/methods.mjs.map +1 -0
  44. package/dist/openapi-hooks.cjs +13 -16
  45. package/dist/openapi-hooks.cjs.map +1 -1
  46. package/dist/openapi-hooks.d.cts +8 -11
  47. package/dist/openapi-hooks.d.cts.map +1 -1
  48. package/dist/openapi-hooks.d.mts +8 -11
  49. package/dist/openapi-hooks.d.mts.map +1 -1
  50. package/dist/openapi-hooks.mjs +9 -12
  51. package/dist/openapi-hooks.mjs.map +1 -1
  52. package/dist/openapi-types.d.cts +5 -6
  53. package/dist/openapi-types.d.cts.map +1 -1
  54. package/dist/openapi-types.d.mts +5 -6
  55. package/dist/openapi-types.d.mts.map +1 -1
  56. package/dist/react-query.cjs +17 -16
  57. package/dist/react-query.cjs.map +1 -1
  58. package/dist/react-query.d.cts +12 -17
  59. package/dist/react-query.d.cts.map +1 -1
  60. package/dist/react-query.d.mts +12 -17
  61. package/dist/react-query.d.mts.map +1 -1
  62. package/dist/react-query.mjs +10 -9
  63. package/dist/react-query.mjs.map +1 -1
  64. package/dist/telemetry-g3BE86Wd.d.cts +68 -0
  65. package/dist/telemetry-g3BE86Wd.d.cts.map +1 -0
  66. package/dist/telemetry-g3BE86Wd.d.mts +68 -0
  67. package/dist/telemetry-g3BE86Wd.d.mts.map +1 -0
  68. package/dist/telemetry.cjs +128 -0
  69. package/dist/telemetry.cjs.map +1 -0
  70. package/dist/telemetry.d.cts +2 -0
  71. package/dist/telemetry.d.mts +2 -0
  72. package/dist/telemetry.mjs +125 -0
  73. package/dist/telemetry.mjs.map +1 -0
  74. package/dist/types.cjs +0 -1
  75. package/dist/types.d.cts +122 -2
  76. package/dist/types.d.cts.map +1 -0
  77. package/dist/types.d.mts +122 -2
  78. package/dist/types.d.mts.map +1 -0
  79. package/dist/types.mjs +1 -1
  80. package/package.json +22 -9
  81. package/dist/auth-fetcher-CBYuL6rx.d.cts +0 -158
  82. package/dist/auth-fetcher-CBYuL6rx.d.cts.map +0 -1
  83. package/dist/auth-fetcher-DOj0iz21.mjs +0 -77
  84. package/dist/auth-fetcher-DOj0iz21.mjs.map +0 -1
  85. package/dist/auth-fetcher-DxS8zOLc.d.mts +0 -158
  86. package/dist/auth-fetcher-DxS8zOLc.d.mts.map +0 -1
  87. package/dist/auth-fetcher-HILABmws.cjs +0 -82
  88. package/dist/auth-fetcher-HILABmws.cjs.map +0 -1
  89. package/dist/chunk-CUT6urMc.cjs +0 -30
  90. package/dist/fetcher-C1xtCKpT.d.mts +0 -25
  91. package/dist/fetcher-C1xtCKpT.d.mts.map +0 -1
  92. package/dist/fetcher-CakjC9C7.mjs +0 -88
  93. package/dist/fetcher-CakjC9C7.mjs.map +0 -1
  94. package/dist/fetcher-CwnSqc4D.cjs +0 -100
  95. package/dist/fetcher-CwnSqc4D.cjs.map +0 -1
  96. package/dist/fetcher-cDrfwN-Y.d.cts +0 -25
  97. package/dist/fetcher-cDrfwN-Y.d.cts.map +0 -1
  98. package/dist/infer-6KKCgmg1.cjs +0 -0
  99. package/dist/infer-CPRqfabW.d.cts +0 -133
  100. package/dist/infer-CPRqfabW.d.cts.map +0 -1
  101. package/dist/infer-D9CgpOuc.d.mts +0 -133
  102. package/dist/infer-D9CgpOuc.d.mts.map +0 -1
  103. package/dist/infer-uCUq1whM.mjs +0 -0
  104. package/dist/openapi.cjs +0 -526
  105. package/dist/openapi.cjs.map +0 -1
  106. package/dist/openapi.mjs +0 -501
  107. package/dist/openapi.mjs.map +0 -1
  108. package/dist/types-BH8WgGrm.mjs +0 -0
  109. package/dist/types-BMGM6sZc.d.mts +0 -110
  110. package/dist/types-BMGM6sZc.d.mts.map +0 -1
  111. package/dist/types-DMQMHePI.d.cts +0 -110
  112. package/dist/types-DMQMHePI.d.cts.map +0 -1
  113. package/dist/types-a8gm_IaQ.cjs +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetcher-C1xtCKpT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OAAA,CAAA,CAAA,OAAA,CAAA,EAkHJ,gBAlHI,CAkHa,CAlHb,CAAA,EAAA,GAAA,CAAA,CAAA,UAoFzB,aApFyB,CAoFzB,KApFyB,CAAA,CAAA,CAAA,QAAA,EAoFzB,CApFyB,EAAA,MAAA,CAAA,EAoFzB,qBApFyB,CAoFzB,KApFyB,EAoFzB,CApFyB,CAAA,GAAA,SAAA,EAAA,GAoFzB,OApFyB,CAoFzB,aApFyB,CAoFzB,uBApFyB,CAoFzB,KApFyB,EAoFzB,CApFyB,CAAA,EAoFzB,CApFyB,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,UA4Gb,aA5Ga,CA4GC,KA5GD,CAAA,CAAA,CAAA,QAAA,EA6GxB,CA7GwB,EAAA,MAAA,CAAA,EA8GzB,qBA9GyB,CA8GH,KA9GG,EA8GI,CA9GJ,CAAA,EAAA,GA8GM,OA9GN,CA8GM,uBA9GN,CA8GM,KA9GN,EA8GM,CA9GN,CAAA,CAAA,CAAA,GAAA;IAAO,IAAA,EAAA,SAAA;EAAC,CAAA;CAAT;AAmFW,KAsClC,OAAA,GAtCkC,OAsCjB,KAtCiB"}
@@ -1,88 +0,0 @@
1
- import qs from "qs";
2
-
3
- //#region src/fetcher.ts
4
- var TypedFetcher = class TypedFetcher {
5
- baseURL;
6
- defaultHeaders;
7
- options;
8
- fetchFn;
9
- static getFetchFn(fn) {
10
- if (fn) return fn;
11
- if (typeof window !== "undefined" && typeof window.fetch === "function") return window.fetch.bind(window);
12
- if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") return globalThis.fetch.bind(globalThis);
13
- throw new Error("No fetch implementation found");
14
- }
15
- constructor(options = {}) {
16
- this.baseURL = options.baseURL || "";
17
- this.defaultHeaders = options.headers || {};
18
- this.options = options;
19
- this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
20
- }
21
- async request(endpoint, config) {
22
- const { method, route } = this.parseEndpoint(endpoint);
23
- let url = route;
24
- if (config && "params" in config && config.params) Object.entries(config.params).forEach(([key, value]) => {
25
- url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
26
- });
27
- if (config && "query" in config && config.query) {
28
- const queryString = qs.stringify(config.query, {
29
- encode: true,
30
- arrayFormat: "brackets",
31
- skipNulls: true
32
- });
33
- if (queryString) url += `?${queryString}`;
34
- }
35
- let requestConfig = {
36
- method: method.toUpperCase(),
37
- headers: {
38
- ...this.defaultHeaders,
39
- ...config && "headers" in config && config.headers || {}
40
- }
41
- };
42
- if (config && "body" in config && config.body) {
43
- requestConfig.body = JSON.stringify(config.body);
44
- requestConfig.headers = {
45
- ...requestConfig.headers,
46
- "Content-Type": "application/json"
47
- };
48
- }
49
- if (this.options.onRequest) requestConfig = await this.options.onRequest(requestConfig);
50
- try {
51
- let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
52
- if (this.options.onResponse) response = await this.options.onResponse(response);
53
- if (!response.ok) throw response;
54
- if (response.status === 204 || response.headers.get("content-length") === "0") return void 0;
55
- const data = await response.json();
56
- return data;
57
- } catch (error) {
58
- if (this.options.onError) await this.options.onError(error);
59
- throw error;
60
- }
61
- }
62
- wrap(onError) {
63
- return (endpoint, config) => this.request(endpoint, config).then((data) => ({
64
- ok: true,
65
- data
66
- }), async (error) => ({
67
- ok: false,
68
- error: onError ? await onError(error) : error
69
- }));
70
- }
71
- parseEndpoint(endpoint) {
72
- const [method, ...routeParts] = endpoint.split(" ");
73
- const route = routeParts.join(" ");
74
- return {
75
- method: method?.toLowerCase() ?? "",
76
- route
77
- };
78
- }
79
- };
80
- function createTypedFetcher(options) {
81
- const fetcher = new TypedFetcher(options);
82
- const fn = (endpoint, config) => fetcher.request(endpoint, config);
83
- return Object.assign(fn, { wrap: (onError) => Object.assign(fetcher.wrap(onError), fn, { wrap: void 0 }) });
84
- }
85
-
86
- //#endregion
87
- export { TypedFetcher, createTypedFetcher };
88
- //# sourceMappingURL=fetcher-CakjC9C7.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetcher-CakjC9C7.mjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","requestConfig: RequestInit","onError?: ErrorTransformer<E>","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport type {\n\tEndpointString,\n\tErrorTransformer,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedEndpoint,\n\tWrappedResult,\n} from './types';\n\nexport type { FetcherOptions, WrappedResult } from './types';\n\nexport class TypedFetcher<Paths> {\n\tprivate baseURL: string;\n\tprivate defaultHeaders: Record<string, string>;\n\tprivate options: FetcherOptions;\n\tprivate fetchFn: FetchFn;\n\n\tstatic getFetchFn(fn?: FetchFn): FetchFn {\n\t\tif (fn) {\n\t\t\treturn fn;\n\t\t}\n\n\t\tif (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n\t\t\treturn window.fetch.bind(window);\n\t\t}\n\n\t\tif (\n\t\t\ttypeof globalThis !== 'undefined' &&\n\t\t\ttypeof globalThis.fetch === 'function'\n\t\t) {\n\t\t\treturn globalThis.fetch.bind(globalThis);\n\t\t}\n\n\t\tthrow new Error('No fetch implementation found');\n\t}\n\n\tconstructor(options: FetcherOptions = {}) {\n\t\tthis.baseURL = options.baseURL || '';\n\t\tthis.defaultHeaders = options.headers || {};\n\t\tthis.options = options;\n\t\tthis.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n\t}\n\n\tasync request<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> {\n\t\tconst { method, route } = this.parseEndpoint(endpoint);\n\n\t\t// Replace path parameters\n\t\tlet url = route;\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tObject.entries(config.params as Record<string, unknown>).forEach(\n\t\t\t\t([key, value]) => {\n\t\t\t\t\turl = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Add query parameters\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tconst queryString = qs.stringify(config.query, {\n\t\t\t\tencode: true,\n\t\t\t\tarrayFormat: 'brackets',\n\t\t\t\tskipNulls: true,\n\t\t\t});\n\t\t\tif (queryString) {\n\t\t\t\turl += `?${queryString}`;\n\t\t\t}\n\t\t}\n\n\t\t// Build request configuration\n\t\tlet requestConfig: RequestInit = {\n\t\t\tmethod: method.toUpperCase(),\n\t\t\theaders: {\n\t\t\t\t...this.defaultHeaders,\n\t\t\t\t...((config && 'headers' in config && config.headers) || {}),\n\t\t\t},\n\t\t};\n\n\t\t// Add body if present\n\t\tif (config && 'body' in config && config.body) {\n\t\t\trequestConfig.body = JSON.stringify(config.body);\n\t\t\trequestConfig.headers = {\n\t\t\t\t...requestConfig.headers,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t};\n\t\t}\n\n\t\t// Apply request interceptor\n\t\tif (this.options.onRequest) {\n\t\t\trequestConfig = await this.options.onRequest(requestConfig);\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request\n\t\t\tlet response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n\t\t\t// Apply response interceptor\n\t\t\tif (this.options.onResponse) {\n\t\t\t\tresponse = await this.options.onResponse(response);\n\t\t\t}\n\n\t\t\t// Handle errors\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow response;\n\t\t\t}\n\n\t\t\t// Handle empty responses (204 No Content, etc.)\n\t\t\tif (\n\t\t\t\tresponse.status === 204 ||\n\t\t\t\tresponse.headers.get('content-length') === '0'\n\t\t\t) {\n\t\t\t\treturn undefined as ExtractEndpointResponse<Paths, T>;\n\t\t\t}\n\n\t\t\t// Parse JSON response\n\t\t\tconst data = await response.json();\n\t\t\treturn data as ExtractEndpointResponse<Paths, T>;\n\t\t} catch (error) {\n\t\t\t// Apply error handler\n\t\t\tif (this.options.onError) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tawait this.options.onError(error);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\twrap<E = unknown>(onError?: ErrorTransformer<E>) {\n\t\treturn <T extends TypedEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ ok: true as const, data }),\n\t\t\t\tasync (error) => ({\n\t\t\t\t\tok: false as const,\n\t\t\t\t\terror: onError ? await onError(error) : (error as E),\n\t\t\t\t}),\n\t\t\t);\n\t}\n\n\tprivate parseEndpoint<T extends EndpointString>(\n\t\tendpoint: T,\n\t): ParseEndpoint<T> {\n\t\tconst [method, ...routeParts] = endpoint.split(' ');\n\t\tconst route = routeParts.join(' ');\n\t\treturn { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n\t}\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n\tconst fetcher = new TypedFetcher<Paths>(options);\n\tconst fn = <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n\n\treturn Object.assign(fn, {\n\t\twrap: <E = unknown>(onError?: ErrorTransformer<E>) =>\n\t\t\tObject.assign(fetcher.wrap(onError), fn, {\n\t\t\t\twrap: undefined,\n\t\t\t}),\n\t});\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;AAcA,IAAa,eAAb,MAAa,aAAoB;CAChC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACxC,MAAI,GACH,QAAO;AAGR,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC5D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGjC,aACQ,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM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AM;AAIP,OACC,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,KAAK,IAE3C;GAID,MAAM,OAAO,MAAM,SAAS,MAAM;AAClC,UAAO;EACP,SAAQ,OAAO;AAEf,OAAI,KAAK,QAAQ,QAEhB,OAAM,KAAK,QAAQ,QAAQ,MAAM;AAElC,SAAM;EACN;CACD;CAED,KAAkBC,SAA+B;AAChD,SAAO,CACNH,UACAC,WAEA,KAAK,QAAQ,UAAU,OAAO,CAAC,KAC9B,CAAC,UAAU;GAAE,IAAI;GAAe;EAAM,IACtC,OAAO,WAAW;GACjB,IAAI;GACJ,OAAO,UAAU,MAAM,QAAQ,MAAM,GAAI;EACzC,GACD;CACF;CAED,AAAQ,cACPD,UACmB;EACnB,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,SAAS,MAAM,IAAI;EACnD,MAAM,QAAQ,WAAW,KAAK,IAAI;AAClC,SAAO;GAAE,QAAQ,QAAQ,aAAa,IAAI;GAAI;EAAO;CACrD;AACD;AAED,SAAgB,mBAA0BI,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB;CACxC,MAAM,KAAK,CACVJ,UACAC,WACI,QAAQ,QAAQ,UAAU,OAAO;AAEtC,QAAO,OAAO,OAAO,IAAI,EACxB,MAAM,CAAcE,YACnB,OAAO,OAAO,QAAQ,KAAK,QAAQ,EAAE,IAAI,EACxC,aACA,EAAC,CACH,EAAC;AACF"}
@@ -1,100 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const qs = require_chunk.__toESM(require("qs"));
3
-
4
- //#region src/fetcher.ts
5
- var TypedFetcher = class TypedFetcher {
6
- baseURL;
7
- defaultHeaders;
8
- options;
9
- fetchFn;
10
- static getFetchFn(fn) {
11
- if (fn) return fn;
12
- if (typeof window !== "undefined" && typeof window.fetch === "function") return window.fetch.bind(window);
13
- if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") return globalThis.fetch.bind(globalThis);
14
- throw new Error("No fetch implementation found");
15
- }
16
- constructor(options = {}) {
17
- this.baseURL = options.baseURL || "";
18
- this.defaultHeaders = options.headers || {};
19
- this.options = options;
20
- this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
21
- }
22
- async request(endpoint, config) {
23
- const { method, route } = this.parseEndpoint(endpoint);
24
- let url = route;
25
- if (config && "params" in config && config.params) Object.entries(config.params).forEach(([key, value]) => {
26
- url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
27
- });
28
- if (config && "query" in config && config.query) {
29
- const queryString = qs.default.stringify(config.query, {
30
- encode: true,
31
- arrayFormat: "brackets",
32
- skipNulls: true
33
- });
34
- if (queryString) url += `?${queryString}`;
35
- }
36
- let requestConfig = {
37
- method: method.toUpperCase(),
38
- headers: {
39
- ...this.defaultHeaders,
40
- ...config && "headers" in config && config.headers || {}
41
- }
42
- };
43
- if (config && "body" in config && config.body) {
44
- requestConfig.body = JSON.stringify(config.body);
45
- requestConfig.headers = {
46
- ...requestConfig.headers,
47
- "Content-Type": "application/json"
48
- };
49
- }
50
- if (this.options.onRequest) requestConfig = await this.options.onRequest(requestConfig);
51
- try {
52
- let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
53
- if (this.options.onResponse) response = await this.options.onResponse(response);
54
- if (!response.ok) throw response;
55
- if (response.status === 204 || response.headers.get("content-length") === "0") return void 0;
56
- const data = await response.json();
57
- return data;
58
- } catch (error) {
59
- if (this.options.onError) await this.options.onError(error);
60
- throw error;
61
- }
62
- }
63
- wrap(onError) {
64
- return (endpoint, config) => this.request(endpoint, config).then((data) => ({
65
- ok: true,
66
- data
67
- }), async (error) => ({
68
- ok: false,
69
- error: onError ? await onError(error) : error
70
- }));
71
- }
72
- parseEndpoint(endpoint) {
73
- const [method, ...routeParts] = endpoint.split(" ");
74
- const route = routeParts.join(" ");
75
- return {
76
- method: method?.toLowerCase() ?? "",
77
- route
78
- };
79
- }
80
- };
81
- function createTypedFetcher(options) {
82
- const fetcher = new TypedFetcher(options);
83
- const fn = (endpoint, config) => fetcher.request(endpoint, config);
84
- return Object.assign(fn, { wrap: (onError) => Object.assign(fetcher.wrap(onError), fn, { wrap: void 0 }) });
85
- }
86
-
87
- //#endregion
88
- Object.defineProperty(exports, 'TypedFetcher', {
89
- enumerable: true,
90
- get: function () {
91
- return TypedFetcher;
92
- }
93
- });
94
- Object.defineProperty(exports, 'createTypedFetcher', {
95
- enumerable: true,
96
- get: function () {
97
- return createTypedFetcher;
98
- }
99
- });
100
- //# sourceMappingURL=fetcher-CwnSqc4D.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetcher-CwnSqc4D.cjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","requestConfig: RequestInit","onError?: ErrorTransformer<E>","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport type {\n\tEndpointString,\n\tErrorTransformer,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedEndpoint,\n\tWrappedResult,\n} from './types';\n\nexport type { FetcherOptions, WrappedResult } from './types';\n\nexport class TypedFetcher<Paths> {\n\tprivate baseURL: string;\n\tprivate defaultHeaders: Record<string, string>;\n\tprivate options: FetcherOptions;\n\tprivate fetchFn: FetchFn;\n\n\tstatic getFetchFn(fn?: FetchFn): FetchFn {\n\t\tif (fn) {\n\t\t\treturn fn;\n\t\t}\n\n\t\tif (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n\t\t\treturn window.fetch.bind(window);\n\t\t}\n\n\t\tif (\n\t\t\ttypeof globalThis !== 'undefined' &&\n\t\t\ttypeof globalThis.fetch === 'function'\n\t\t) {\n\t\t\treturn globalThis.fetch.bind(globalThis);\n\t\t}\n\n\t\tthrow new Error('No fetch implementation found');\n\t}\n\n\tconstructor(options: FetcherOptions = {}) {\n\t\tthis.baseURL = options.baseURL || '';\n\t\tthis.defaultHeaders = options.headers || {};\n\t\tthis.options = options;\n\t\tthis.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n\t}\n\n\tasync request<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> {\n\t\tconst { method, route } = this.parseEndpoint(endpoint);\n\n\t\t// Replace path parameters\n\t\tlet url = route;\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tObject.entries(config.params as Record<string, unknown>).forEach(\n\t\t\t\t([key, value]) => {\n\t\t\t\t\turl = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Add query parameters\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tconst queryString = qs.stringify(config.query, {\n\t\t\t\tencode: true,\n\t\t\t\tarrayFormat: 'brackets',\n\t\t\t\tskipNulls: true,\n\t\t\t});\n\t\t\tif (queryString) {\n\t\t\t\turl += `?${queryString}`;\n\t\t\t}\n\t\t}\n\n\t\t// Build request configuration\n\t\tlet requestConfig: RequestInit = {\n\t\t\tmethod: method.toUpperCase(),\n\t\t\theaders: {\n\t\t\t\t...this.defaultHeaders,\n\t\t\t\t...((config && 'headers' in config && config.headers) || {}),\n\t\t\t},\n\t\t};\n\n\t\t// Add body if present\n\t\tif (config && 'body' in config && config.body) {\n\t\t\trequestConfig.body = JSON.stringify(config.body);\n\t\t\trequestConfig.headers = {\n\t\t\t\t...requestConfig.headers,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t};\n\t\t}\n\n\t\t// Apply request interceptor\n\t\tif (this.options.onRequest) {\n\t\t\trequestConfig = await this.options.onRequest(requestConfig);\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request\n\t\t\tlet response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n\t\t\t// Apply response interceptor\n\t\t\tif (this.options.onResponse) {\n\t\t\t\tresponse = await this.options.onResponse(response);\n\t\t\t}\n\n\t\t\t// Handle errors\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow response;\n\t\t\t}\n\n\t\t\t// Handle empty responses (204 No Content, etc.)\n\t\t\tif (\n\t\t\t\tresponse.status === 204 ||\n\t\t\t\tresponse.headers.get('content-length') === '0'\n\t\t\t) {\n\t\t\t\treturn undefined as ExtractEndpointResponse<Paths, T>;\n\t\t\t}\n\n\t\t\t// Parse JSON response\n\t\t\tconst data = await response.json();\n\t\t\treturn data as ExtractEndpointResponse<Paths, T>;\n\t\t} catch (error) {\n\t\t\t// Apply error handler\n\t\t\tif (this.options.onError) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tawait this.options.onError(error);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\twrap<E = unknown>(onError?: ErrorTransformer<E>) {\n\t\treturn <T extends TypedEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ ok: true as const, data }),\n\t\t\t\tasync (error) => ({\n\t\t\t\t\tok: false as const,\n\t\t\t\t\terror: onError ? await onError(error) : (error as E),\n\t\t\t\t}),\n\t\t\t);\n\t}\n\n\tprivate parseEndpoint<T extends EndpointString>(\n\t\tendpoint: T,\n\t): ParseEndpoint<T> {\n\t\tconst [method, ...routeParts] = endpoint.split(' ');\n\t\tconst route = routeParts.join(' ');\n\t\treturn { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n\t}\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n\tconst fetcher = new TypedFetcher<Paths>(options);\n\tconst fn = <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n\n\treturn Object.assign(fn, {\n\t\twrap: <E = unknown>(onError?: ErrorTransformer<E>) =>\n\t\t\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C,aACA,EAAC,CACH,EAAC;AACF"}
@@ -1,25 +0,0 @@
1
- import { ErrorTransformer, ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types-DMQMHePI.cjs";
2
-
3
- //#region src/fetcher.d.ts
4
- declare class TypedFetcher<Paths> {
5
- private baseURL;
6
- private defaultHeaders;
7
- private options;
8
- private fetchFn;
9
- static getFetchFn(fn?: FetchFn): FetchFn;
10
- constructor(options?: FetcherOptions);
11
- request<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
12
- wrap<E = unknown>(onError?: ErrorTransformer<E>): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>;
13
- private parseEndpoint;
14
- }
15
- declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & {
16
- wrap: <E = unknown>(onError?: ErrorTransformer<E>) => (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T> | undefined) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>) & (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & {
17
- wrap: undefined;
18
- };
19
- };
20
- type FetchFn = typeof fetch;
21
- //# sourceMappingURL=fetcher.d.ts.map
22
-
23
- //#endregion
24
- export { FetchFn, TypedFetcher, createTypedFetcher };
25
- //# sourceMappingURL=fetcher-cDrfwN-Y.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetcher-cDrfwN-Y.d.cts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;cAca;EAAA,QAAA,OAAY;EAAA,QAAA,cAAA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oFzB,aApFyB,CAoFzB,KApFyB,CAAA,CAAA,CAAA,QAAA,EAoFzB,CApFyB,EAAA,MAAA,CAAA,EAoFzB,qBApFyB,CAoFzB,KApFyB,EAoFzB,CApFyB,CAAA,GAAA,SAAA,EAAA,GAoFzB,OApFyB,CAoFzB,aApFyB,CAoFzB,uBApFyB,CAoFzB,KApFyB,EAoFzB,CApFyB,CAAA,EAoFzB,CApFyB,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,UA4Gb,aA5Ga,CA4GC,KA5GD,CAAA,CAAA,CAAA,QAAA,EA6GxB,CA7GwB,EAAA,MAAA,CAAA,EA8GzB,qBA9GyB,CA8GH,KA9GG,EA8GI,CA9GJ,CAAA,EAAA,GA8GM,OA9GN,CA8GM,uBA9GN,CA8GM,KA9GN,EA8GM,CA9GN,CAAA,CAAA,CAAA,GAAA;IAAO,IAAA,EAAA,SAAA;EAAC,CAAA;CAAT;AAmFW,KAsClC,OAAA,GAtCkC,OAsCjB,KAtCiB"}
File without changes
@@ -1,133 +0,0 @@
1
- import { Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
2
- import { HttpMethod } from "@geekmidas/constructs/types";
3
- import { InferStandardSchema, InferStandardSchemaInput } from "@geekmidas/schema";
4
- import { StandardSchemaV1 } from "@standard-schema/spec";
5
-
6
- //#region src/infer.d.ts
7
-
8
- /**
9
- * Infers path parameters from a route string as an object
10
- * @example '/users/{id}/posts/{postId}' -> { id: string, postId: string }
11
- */
12
- type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string } & InferPathParams<Rest> : {};
13
- /**
14
- * Converts an HTTP method to lowercase for TypedFetcher compatibility
15
- */
16
- type LowercaseMethod<T extends HttpMethod> = Lowercase<T>;
17
- /**
18
- * Infers route-level parameters (path params)
19
- */
20
- type InferRouteParameters<TRoute extends string> = InferPathParams<TRoute> extends Record<string, never> ? {} : {
21
- parameters: {
22
- path: InferPathParams<TRoute>;
23
- };
24
- };
25
- /**
26
- * Infers operation-level parameters (query params)
27
- */
28
- type InferOperationParameters<TInput extends EndpointSchemas> = TInput extends {
29
- query: infer Q;
30
- } ? {
31
- parameters: {
32
- query: InferStandardSchemaInput<Q>;
33
- };
34
- } : {};
35
- /**
36
- * Infers the operation object compatible with TypedFetcher
37
- */
38
- type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSchemaV1 | undefined> = InferOperationParameters<TInput> & {
39
- requestBody?: TInput extends {
40
- body: infer B;
41
- } ? {
42
- content: {
43
- 'application/json': InferStandardSchemaInput<B>;
44
- };
45
- } : never;
46
- responses: {
47
- 200: {
48
- content: TOutput extends StandardSchemaV1 ? {
49
- 'application/json': InferStandardSchema<TOutput>;
50
- } : never;
51
- };
52
- };
53
- };
54
- /**
55
- * Infers the TypedFetcher-compatible paths structure from a single endpoint
56
- *
57
- * This generates a structure compatible with @geekmidas/client TypedFetcher,
58
- * allowing you to create a typed client directly from endpoint definitions
59
- * without needing OpenAPI JSON + codegen.
60
- *
61
- * @example
62
- * ```typescript
63
- * import { api } from './constructs/api.js';
64
- * import { createTypedFetcher, type InferOpenApiFromEndpoint } from '@geekmidas/client';
65
- * import { z } from 'zod';
66
- *
67
- * const endpoint = e
68
- * .get('/users/{id}')
69
- * .params(z.object({ id: z.string() }))
70
- * .output(z.object({ id: z.string(), name: z.string() }))
71
- * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
72
- *
73
- * type Paths = InferOpenApiFromEndpoint<typeof endpoint>['paths'];
74
- * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
75
- * const user = await client('GET /users/{id}', { params: { id: '123' } });
76
- * ```
77
- */
78
- type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer TMethod, infer TInput, infer TOutput, any, any, any> ? {
79
- paths: { [K in TRoute]: InferRouteParameters<TRoute> & { [M in LowercaseMethod<TMethod>]: InferOperation<TInput, TOutput> } };
80
- } : never;
81
- /**
82
- * Infers TypedFetcher-compatible paths structure from multiple endpoints
83
- *
84
- * Merges multiple endpoint definitions into a single paths object that can be
85
- * used with @geekmidas/client TypedFetcher for fully type-safe API calls.
86
- *
87
- * @example
88
- * ```typescript
89
- * import { api } from './constructs/api.js';
90
- * import { createTypedFetcher, type InferOpenApi } from '@geekmidas/client';
91
- * import { z } from 'zod';
92
- *
93
- * // Define endpoints
94
- * const getUserEndpoint = e
95
- * .get('/users/{id}')
96
- * .params(z.object({ id: z.string() }))
97
- * .output(z.object({ id: z.string(), name: z.string() }))
98
- * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
99
- *
100
- * const createUserEndpoint = e
101
- * .post('/users')
102
- * .body(z.object({ name: z.string() }))
103
- * .output(z.object({ id: z.string(), name: z.string() }))
104
- * .handle(async ({ body }) => ({ id: '123', name: body.name }));
105
- *
106
- * // Export for client
107
- * export const endpoints = [getUserEndpoint, createUserEndpoint] as const;
108
- * export type Paths = InferOpenApi<typeof endpoints>['paths'];
109
- *
110
- * // Client usage
111
- * import type { Paths } from './endpoints';
112
- * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
113
- *
114
- * const user = await client('GET /users/{id}', { params: { id: '123' } });
115
- * const newUser = await client('POST /users', { body: { name: 'Jane' } });
116
- * ```
117
- */
118
- type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
119
- paths: infer P1;
120
- } ? Rest extends [] ? {
121
- paths: P1;
122
- } : InferOpenApi<Rest> extends {
123
- paths: infer P2;
124
- } ? {
125
- paths: P1 & P2;
126
- } : {
127
- paths: P1;
128
- } : InferOpenApi<Rest> : {
129
- paths: {};
130
- };
131
- //#endregion
132
- export { InferOpenApi, InferOpenApiFromEndpoint };
133
- //# sourceMappingURL=infer-CPRqfabW.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"infer-CPRqfabW.d.cts","names":[],"sources":["../src/infer.ts"],"sourcesContent":[],"mappings":";;;;;;;;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;;;;;;;AAYmD;AA2CrD;;;;;;;;;;;;;;AAQiB;KAhEL,8BACX,UAAU;iBAWA,SAAS,qBAAqB,kBAC7B,gBAAgB,WAAW,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2ClD,kDACX,2DACG,yBAAyB;;IACxB;SACU;IACT,aAAa;;;SACH,KAAK;;SACL;IACX,aAAa"}
@@ -1,133 +0,0 @@
1
- import { Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
2
- import { HttpMethod } from "@geekmidas/constructs/types";
3
- import { InferStandardSchema, InferStandardSchemaInput } from "@geekmidas/schema";
4
- import { StandardSchemaV1 } from "@standard-schema/spec";
5
-
6
- //#region src/infer.d.ts
7
-
8
- /**
9
- * Infers path parameters from a route string as an object
10
- * @example '/users/{id}/posts/{postId}' -> { id: string, postId: string }
11
- */
12
- type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string } & InferPathParams<Rest> : {};
13
- /**
14
- * Converts an HTTP method to lowercase for TypedFetcher compatibility
15
- */
16
- type LowercaseMethod<T extends HttpMethod> = Lowercase<T>;
17
- /**
18
- * Infers route-level parameters (path params)
19
- */
20
- type InferRouteParameters<TRoute extends string> = InferPathParams<TRoute> extends Record<string, never> ? {} : {
21
- parameters: {
22
- path: InferPathParams<TRoute>;
23
- };
24
- };
25
- /**
26
- * Infers operation-level parameters (query params)
27
- */
28
- type InferOperationParameters<TInput extends EndpointSchemas> = TInput extends {
29
- query: infer Q;
30
- } ? {
31
- parameters: {
32
- query: InferStandardSchemaInput<Q>;
33
- };
34
- } : {};
35
- /**
36
- * Infers the operation object compatible with TypedFetcher
37
- */
38
- type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSchemaV1 | undefined> = InferOperationParameters<TInput> & {
39
- requestBody?: TInput extends {
40
- body: infer B;
41
- } ? {
42
- content: {
43
- 'application/json': InferStandardSchemaInput<B>;
44
- };
45
- } : never;
46
- responses: {
47
- 200: {
48
- content: TOutput extends StandardSchemaV1 ? {
49
- 'application/json': InferStandardSchema<TOutput>;
50
- } : never;
51
- };
52
- };
53
- };
54
- /**
55
- * Infers the TypedFetcher-compatible paths structure from a single endpoint
56
- *
57
- * This generates a structure compatible with @geekmidas/client TypedFetcher,
58
- * allowing you to create a typed client directly from endpoint definitions
59
- * without needing OpenAPI JSON + codegen.
60
- *
61
- * @example
62
- * ```typescript
63
- * import { api } from './constructs/api.js';
64
- * import { createTypedFetcher, type InferOpenApiFromEndpoint } from '@geekmidas/client';
65
- * import { z } from 'zod';
66
- *
67
- * const endpoint = e
68
- * .get('/users/{id}')
69
- * .params(z.object({ id: z.string() }))
70
- * .output(z.object({ id: z.string(), name: z.string() }))
71
- * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
72
- *
73
- * type Paths = InferOpenApiFromEndpoint<typeof endpoint>['paths'];
74
- * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
75
- * const user = await client('GET /users/{id}', { params: { id: '123' } });
76
- * ```
77
- */
78
- type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer TMethod, infer TInput, infer TOutput, any, any, any> ? {
79
- paths: { [K in TRoute]: InferRouteParameters<TRoute> & { [M in LowercaseMethod<TMethod>]: InferOperation<TInput, TOutput> } };
80
- } : never;
81
- /**
82
- * Infers TypedFetcher-compatible paths structure from multiple endpoints
83
- *
84
- * Merges multiple endpoint definitions into a single paths object that can be
85
- * used with @geekmidas/client TypedFetcher for fully type-safe API calls.
86
- *
87
- * @example
88
- * ```typescript
89
- * import { api } from './constructs/api.js';
90
- * import { createTypedFetcher, type InferOpenApi } from '@geekmidas/client';
91
- * import { z } from 'zod';
92
- *
93
- * // Define endpoints
94
- * const getUserEndpoint = e
95
- * .get('/users/{id}')
96
- * .params(z.object({ id: z.string() }))
97
- * .output(z.object({ id: z.string(), name: z.string() }))
98
- * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
99
- *
100
- * const createUserEndpoint = e
101
- * .post('/users')
102
- * .body(z.object({ name: z.string() }))
103
- * .output(z.object({ id: z.string(), name: z.string() }))
104
- * .handle(async ({ body }) => ({ id: '123', name: body.name }));
105
- *
106
- * // Export for client
107
- * export const endpoints = [getUserEndpoint, createUserEndpoint] as const;
108
- * export type Paths = InferOpenApi<typeof endpoints>['paths'];
109
- *
110
- * // Client usage
111
- * import type { Paths } from './endpoints';
112
- * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
113
- *
114
- * const user = await client('GET /users/{id}', { params: { id: '123' } });
115
- * const newUser = await client('POST /users', { body: { name: 'Jane' } });
116
- * ```
117
- */
118
- type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
119
- paths: infer P1;
120
- } ? Rest extends [] ? {
121
- paths: P1;
122
- } : InferOpenApi<Rest> extends {
123
- paths: infer P2;
124
- } ? {
125
- paths: P1 & P2;
126
- } : {
127
- paths: P1;
128
- } : InferOpenApi<Rest> : {
129
- paths: {};
130
- };
131
- //#endregion
132
- export { InferOpenApi, InferOpenApiFromEndpoint };
133
- //# sourceMappingURL=infer-D9CgpOuc.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"infer-D9CgpOuc.d.mts","names":[],"sources":["../src/infer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAS8D;;KAMzD,eACJ,CAAA,eAAA,MAAA,CAAA,GAAA,MAAA,SAAA,GAAA,MAAA,IAAA,KAAA,MAAA,IAAA,KAAA,KAAA,EAAA,GAAA,QACW,KAAA,GAAA,MAAA,EAAK,GAAc,eAAgB,CAAA,IAAA,CAAA,GAAA,CAAA,CAAA;;AAAD;AAAA;KAMzC,eAAe,CAAA,UAAW,UAAX,CAAA,GAAyB,SAAzB,CAAmC,CAAnC,CAAA;;;;AAAkC,KAKjD,oBALiD,CAAA,eAAA,MAAA,CAAA,GAMrD,eANqD,CAMrC,MANqC,CAAA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