@geekmidas/client 10.0.0-alpha.99 → 10.0.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 (116) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/README.md +57 -40
  3. package/dist/auth-fetcher.cjs +5 -7
  4. package/dist/auth-fetcher.cjs.map +1 -1
  5. package/dist/auth-fetcher.d.cts +17 -15
  6. package/dist/auth-fetcher.d.cts.map +1 -1
  7. package/dist/auth-fetcher.d.mts +17 -15
  8. package/dist/auth-fetcher.d.mts.map +1 -1
  9. package/dist/auth-fetcher.mjs +5 -6
  10. package/dist/auth-fetcher.mjs.map +1 -1
  11. package/dist/chunk-CUT6urMc.cjs +30 -0
  12. package/dist/endpoint-hooks.cjs +15 -11
  13. package/dist/endpoint-hooks.cjs.map +1 -1
  14. package/dist/endpoint-hooks.d.cts +7 -4
  15. package/dist/endpoint-hooks.d.cts.map +1 -1
  16. package/dist/endpoint-hooks.d.mts +7 -4
  17. package/dist/endpoint-hooks.d.mts.map +1 -1
  18. package/dist/endpoint-hooks.mjs +9 -5
  19. package/dist/endpoint-hooks.mjs.map +1 -1
  20. package/dist/fetcher-CakjC9C7.mjs +88 -0
  21. package/dist/fetcher-CakjC9C7.mjs.map +1 -0
  22. package/dist/fetcher-CwnSqc4D.cjs +100 -0
  23. package/dist/fetcher-CwnSqc4D.cjs.map +1 -0
  24. package/dist/fetcher.cjs +3 -115
  25. package/dist/fetcher.d.cts +8 -7
  26. package/dist/fetcher.d.cts.map +1 -1
  27. package/dist/fetcher.d.mts +8 -7
  28. package/dist/fetcher.d.mts.map +1 -1
  29. package/dist/fetcher.mjs +2 -90
  30. package/dist/infer.d.cts +13 -10
  31. package/dist/infer.d.cts.map +1 -1
  32. package/dist/infer.d.mts +13 -10
  33. package/dist/infer.d.mts.map +1 -1
  34. package/dist/infer.mjs +0 -1
  35. package/dist/openapi-hooks.cjs +16 -13
  36. package/dist/openapi-hooks.cjs.map +1 -1
  37. package/dist/openapi-hooks.d.cts +11 -8
  38. package/dist/openapi-hooks.d.cts.map +1 -1
  39. package/dist/openapi-hooks.d.mts +11 -8
  40. package/dist/openapi-hooks.d.mts.map +1 -1
  41. package/dist/openapi-hooks.mjs +12 -9
  42. package/dist/openapi-hooks.mjs.map +1 -1
  43. package/dist/openapi-types.d.cts +6 -5
  44. package/dist/openapi-types.d.cts.map +1 -1
  45. package/dist/openapi-types.d.mts +6 -5
  46. package/dist/openapi-types.d.mts.map +1 -1
  47. package/dist/openapi.cjs +526 -0
  48. package/dist/openapi.cjs.map +1 -0
  49. package/dist/openapi.mjs +501 -0
  50. package/dist/openapi.mjs.map +1 -0
  51. package/dist/react-query.cjs +16 -17
  52. package/dist/react-query.cjs.map +1 -1
  53. package/dist/react-query.d.cts +17 -12
  54. package/dist/react-query.d.cts.map +1 -1
  55. package/dist/react-query.d.mts +17 -12
  56. package/dist/react-query.d.mts.map +1 -1
  57. package/dist/react-query.mjs +9 -10
  58. package/dist/react-query.mjs.map +1 -1
  59. package/dist/types-D8Jrl4o3.d.mts +110 -0
  60. package/dist/types-D8Jrl4o3.d.mts.map +1 -0
  61. package/dist/types-DMQMHePI.d.cts +110 -0
  62. package/dist/types-DMQMHePI.d.cts.map +1 -0
  63. package/dist/types.d.cts +2 -122
  64. package/dist/types.d.mts +2 -122
  65. package/dist/types.mjs +0 -1
  66. package/package.json +15 -31
  67. package/src/__tests__/auth-fetcher.spec.ts +505 -0
  68. package/src/__tests__/endpoint-hooks.spec.tsx +374 -0
  69. package/src/__tests__/fetcher.spec.ts +580 -0
  70. package/src/__tests__/infer.integration.spec.ts +188 -0
  71. package/src/__tests__/infer.spec.ts +189 -0
  72. package/src/__tests__/method-restrictions.spec.tsx +227 -0
  73. package/src/__tests__/mutation-inference.spec.tsx +343 -0
  74. package/src/__tests__/openapi-hooks.spec.tsx +557 -0
  75. package/src/__tests__/react-query-infinite.spec.tsx +1003 -0
  76. package/src/__tests__/react-query-invalidation.spec.tsx +239 -0
  77. package/src/__tests__/react-query.spec.tsx +582 -0
  78. package/src/__tests__/setup.ts +281 -0
  79. package/src/__tests__/types.spec.ts +134 -0
  80. package/src/__tests__/url-parsing.spec.ts +196 -0
  81. package/src/auth-fetcher.ts +288 -0
  82. package/src/endpoint-hooks.ts +346 -0
  83. package/src/fetcher.ts +171 -0
  84. package/src/infer.ts +162 -0
  85. package/src/openapi-hooks.ts +193 -0
  86. package/src/openapi-types.d.ts +440 -0
  87. package/src/openapi.json +595 -0
  88. package/src/react-query.ts +341 -0
  89. package/src/types.ts +226 -0
  90. package/tsconfig.json +12 -0
  91. package/dist/fetcher.cjs.map +0 -1
  92. package/dist/fetcher.mjs.map +0 -1
  93. package/dist/index.cjs +0 -15
  94. package/dist/index.d.cts +0 -7
  95. package/dist/index.d.mts +0 -7
  96. package/dist/index.mjs +0 -7
  97. package/dist/methods.cjs +0 -21
  98. package/dist/methods.cjs.map +0 -1
  99. package/dist/methods.d.cts +0 -23
  100. package/dist/methods.d.cts.map +0 -1
  101. package/dist/methods.d.mts +0 -23
  102. package/dist/methods.d.mts.map +0 -1
  103. package/dist/methods.mjs +0 -19
  104. package/dist/methods.mjs.map +0 -1
  105. package/dist/telemetry-g3BE86Wd.d.cts +0 -68
  106. package/dist/telemetry-g3BE86Wd.d.cts.map +0 -1
  107. package/dist/telemetry-g3BE86Wd.d.mts +0 -68
  108. package/dist/telemetry-g3BE86Wd.d.mts.map +0 -1
  109. package/dist/telemetry.cjs +0 -128
  110. package/dist/telemetry.cjs.map +0 -1
  111. package/dist/telemetry.d.cts +0 -2
  112. package/dist/telemetry.d.mts +0 -2
  113. package/dist/telemetry.mjs +0 -125
  114. package/dist/telemetry.mjs.map +0 -1
  115. package/dist/types.d.cts.map +0 -1
  116. package/dist/types.d.mts.map +0 -1
@@ -0,0 +1,100 @@
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
@@ -0,0 +1 @@
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\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,KAAK,WAAW;AAGzC,QAAM,IAAI,MAAM;CAChB;CAED,YAAYC,UAA0B,CAAE,GAAE;AACzC,OAAK,UAAU,QAAQ,WAAW;AAClC,OAAK,iBAAiB,QAAQ,WAAW,CAAE;AAC3C,OAAK,UAAU;AACf,OAAK,UAAU,aAAa,WAAW,QAAQ,MAAM;CACrD;CAED,MAAM,QACLC,UACAC,QAC6C;EAC7C,MAAM,EAAE,QAAQ,OAAO,GAAG,KAAK,cAAc,SAAS;EAGtD,IAAI,MAAM;AACV,MAAI,UAAU,YAAY,UAAU,OAAO,OAC1C,QAAO,QAAQ,OAAO,OAAkC,CAAC,QACxD,CAAC,CAAC,KAAK,MAAM,KAAK;AACjB,SAAM,IAAI,SAAS,GAAG,IAAI,IAAI,mBAAmB,OAAO,MAAM,CAAC,CAAC;E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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"}
package/dist/fetcher.cjs CHANGED
@@ -1,116 +1,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
- //#endregion
24
- const require_methods = require("./methods.cjs");
25
- const require_telemetry = require("./telemetry.cjs");
26
- let qs = require("qs");
27
- qs = __toESM(qs, 1);
28
- //#region src/fetcher.ts
29
- var TypedFetcher = class TypedFetcher {
30
- baseURL;
31
- defaultHeaders;
32
- options;
33
- fetchFn;
34
- injectTraceContext;
35
- static getFetchFn(fn) {
36
- if (fn) return fn;
37
- if (typeof window !== "undefined" && typeof window.fetch === "function") return window.fetch.bind(window);
38
- if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") return globalThis.fetch.bind(globalThis);
39
- throw new Error("No fetch implementation found");
40
- }
41
- constructor(options = {}) {
42
- this.baseURL = options.baseURL || "";
43
- this.defaultHeaders = options.headers || {};
44
- this.options = options;
45
- this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
46
- this.injectTraceContext = require_telemetry.traceContextInjector(this.baseURL, options.telemetry);
47
- }
48
- async request(endpoint, config) {
49
- const { method, route } = this.parseEndpoint(endpoint);
50
- let url = route;
51
- if (config && "params" in config && config.params) Object.entries(config.params).forEach(([key, value]) => {
52
- url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
53
- });
54
- if (config && "query" in config && config.query) {
55
- const queryString = qs.default.stringify(config.query, {
56
- encode: true,
57
- arrayFormat: "brackets",
58
- skipNulls: true
59
- });
60
- if (queryString) url += `?${queryString}`;
61
- }
62
- let requestConfig = {
63
- method: method.toUpperCase(),
64
- headers: {
65
- ...this.defaultHeaders,
66
- ...config && "headers" in config && config.headers || {}
67
- }
68
- };
69
- if (config && "body" in config && config.body) {
70
- requestConfig.body = JSON.stringify(config.body);
71
- requestConfig.headers = {
72
- ...requestConfig.headers,
73
- "Content-Type": "application/json"
74
- };
75
- }
76
- this.injectTraceContext?.(`${this.baseURL}${url}`, requestConfig.headers);
77
- if (this.options.onRequest) requestConfig = await this.options.onRequest(requestConfig);
78
- try {
79
- let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
80
- if (this.options.onResponse) response = await this.options.onResponse(response);
81
- if (!response.ok) throw response;
82
- if (response.status === 204 || response.headers.get("content-length") === "0") return;
83
- return await response.json();
84
- } catch (error) {
85
- if (this.options.onError) await this.options.onError(error);
86
- throw error;
87
- }
88
- }
89
- wrap(onError) {
90
- return (endpoint, config) => this.request(endpoint, config).then((data) => ({
91
- ok: true,
92
- data
93
- }), async (error) => ({
94
- ok: false,
95
- error: onError ? await onError(error) : error
96
- }));
97
- }
98
- parseEndpoint(endpoint) {
99
- const [method, ...routeParts] = endpoint.split(" ");
100
- const route = routeParts.join(" ");
101
- return {
102
- method: method?.toLowerCase() ?? "",
103
- route
104
- };
105
- }
106
- };
107
- function createTypedFetcher(options) {
108
- const fetcher = new TypedFetcher(options);
109
- const fn = (endpoint, config) => fetcher.request(endpoint, config);
110
- return Object.assign(fn, require_methods.methodCalls(fn), { wrap: (onError) => Object.assign(fetcher.wrap(onError), fn, { wrap: void 0 }) });
111
- }
112
- //#endregion
113
- exports.TypedFetcher = TypedFetcher;
114
- exports.createTypedFetcher = createTypedFetcher;
1
+ const require_fetcher = require('./fetcher-CwnSqc4D.cjs');
115
2
 
116
- //# sourceMappingURL=fetcher.cjs.map
3
+ exports.TypedFetcher = require_fetcher.TypedFetcher;
4
+ exports.createTypedFetcher = require_fetcher.createTypedFetcher;
@@ -1,24 +1,25 @@
1
- import { ErrorTransformer, ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types.cjs";
2
- import { MethodCalls } from "./methods.cjs";
1
+ import { ErrorTransformer, ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types-DMQMHePI.cjs";
2
+
3
3
  //#region src/fetcher.d.ts
4
- export declare class TypedFetcher<Paths> {
4
+ declare class TypedFetcher<Paths> {
5
5
  private baseURL;
6
6
  private defaultHeaders;
7
7
  private options;
8
8
  private fetchFn;
9
- private injectTraceContext;
10
9
  static getFetchFn(fn?: FetchFn): FetchFn;
11
10
  constructor(options?: FetcherOptions);
12
11
  request<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
13
12
  wrap<E = unknown>(onError?: ErrorTransformer<E>): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>;
14
13
  private parseEndpoint;
15
14
  }
16
- export declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & MethodCalls<Paths> & {
15
+ declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & {
17
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>>) & {
18
17
  wrap: undefined;
19
18
  };
20
19
  };
21
- export type FetchFn = typeof fetch;
20
+ type FetchFn = typeof fetch;
21
+ //# sourceMappingURL=fetcher.d.ts.map
22
+
22
23
  //#endregion
23
- export type { FetcherOptions, WrappedResult };
24
+ export { FetchFn, FetcherOptions, TypedFetcher, WrappedResult, createTypedFetcher };
24
25
  //# sourceMappingURL=fetcher.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.cts","names":["_$__methods0.MethodCalls"],"sources":["../src/fetcher.ts"],"mappings":";;;qBAiBa,aAAa;UACjB;UACA;UACA;UACA;UACA;SAED,WAAW,KAAK,UAAU;EAmBjC,YAAY,UAAS;EAWf,QAAQ,UAAU,cAAc,QACrC,UAAU,GACV,SAAS,sBAAsB,OAAO,KACpC,QAAQ,wBAAwB,OAAO;EAyF1C,KAAK,aAAa,UAAU,iBAAiB,MACpC,UAAU,cAAc,QAAM,UAC3B,GA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equestConfig, TypedEndpoint, WrappedResult } from "./types.mjs";
2
- import { MethodCalls } from "./methods.mjs";
1
+ import { ErrorTransformer, ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types-D8Jrl4o3.mjs";
2
+
3
3
  //#region src/fetcher.d.ts
4
- export declare class TypedFetcher<Paths> {
4
+ declare class TypedFetcher<Paths> {
5
5
  private baseURL;
6
6
  private defaultHeaders;
7
7
  private options;
8
8
  private fetchFn;
9
- private injectTraceContext;
10
9
  static getFetchFn(fn?: FetchFn): FetchFn;
11
10
  constructor(options?: FetcherOptions);
12
11
  request<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
13
12
  wrap<E = unknown>(onError?: ErrorTransformer<E>): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>;
14
13
  private parseEndpoint;
15
14
  }
16
- export declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & MethodCalls<Paths> & {
15
+ declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & {
17
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>>) & {
18
17
  wrap: undefined;
19
18
  };
20
19
  };
21
- export type FetchFn = typeof fetch;
20
+ type FetchFn = typeof fetch;
21
+ //# sourceMappingURL=fetcher.d.ts.map
22
+
22
23
  //#endregion
23
- export type { FetcherOptions, WrappedResult };
24
+ export { FetchFn, FetcherOptions, TypedFetcher, WrappedResult, createTypedFetcher };
24
25
  //# sourceMappingURL=fetcher.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.mts","names":["_$__methods0.MethodCalls"],"sources":["../src/fetcher.ts"],"mappings":";;;qBAiBa,aAAa;UACjB;UACA;UACA;UACA;UACA;SAED,WAAW,KAAK,UAAU;EAmBjC,YAAY,UAAS;EAWf,QAAQ,UAAU,cAAc,QACrC,UAAU,GACV,SAAS,sBAAsB,OAAO,KACpC,QAAQ,wBAAwB,OAAO;EAyF1C,KAAK,aAAa,UAAU,iBAAiB,MACpC,UAAU,cAAc,QAAM,UAC3B,GAAC,SACF,sBAAsB,OAAO,OACpC,QAAQ,cAAc,wBAAwB,OAAO,IAAI;UAUrD;;wBASO,mBAAmB,OAAO,UAAU,mBAEvC,UAAU,cAAc,QAAM,UAC/B,GAAC,SACF,sBAAsB,OAAO,OAAE,QAAA,wBAAA,OAAA,OAAAA,YAAA;EAIjC,OAAA,aAAW,UAAY,iBAAiB,SA9BvC,UAAU,cAAa,QAAO,UAAA,GAAA,SAAA,sBAAA,OAAA,mBAAA,QAAA,cAAA,wBAAA,OAAA,IAAA,SAwB3B,UAAU,cAAc,QAAM,UAC/B,GAAC,SACF,sBAAsB,OAAO,OAAE,QAAA,wBAAA,OAAA;;;;YAW9B,iBAAiB"}
1
+ {"version":3,"file":"fetcher.d.mts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;cAca;EAAA,QAAA,OAAY;EAAA,QAAA,cAAA;EAAA,QAMD,OAAA;EAAO,QAAG,OAAA;EAAO,OAmBnB,UAAA,CAAA,EAAA,CAAA,EAnBE,OAmBF,CAAA,EAnBY,OAmBZ;EAAmB,WAOF,CAAA,OAAA,CAAA,EAPjB,cAOiB;EAAK,OAAnB,CAAA,UAAA,aAA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yB,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"}
package/dist/fetcher.mjs CHANGED
@@ -1,91 +1,3 @@
1
- import { methodCalls } from "./methods.mjs";
2
- import { traceContextInjector } from "./telemetry.mjs";
3
- import qs from "qs";
4
- //#region src/fetcher.ts
5
- var TypedFetcher = class TypedFetcher {
6
- baseURL;
7
- defaultHeaders;
8
- options;
9
- fetchFn;
10
- injectTraceContext;
11
- static getFetchFn(fn) {
12
- if (fn) return fn;
13
- if (typeof window !== "undefined" && typeof window.fetch === "function") return window.fetch.bind(window);
14
- if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") return globalThis.fetch.bind(globalThis);
15
- throw new Error("No fetch implementation found");
16
- }
17
- constructor(options = {}) {
18
- this.baseURL = options.baseURL || "";
19
- this.defaultHeaders = options.headers || {};
20
- this.options = options;
21
- this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
22
- this.injectTraceContext = traceContextInjector(this.baseURL, options.telemetry);
23
- }
24
- async request(endpoint, config) {
25
- const { method, route } = this.parseEndpoint(endpoint);
26
- let url = route;
27
- if (config && "params" in config && config.params) Object.entries(config.params).forEach(([key, value]) => {
28
- url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
29
- });
30
- if (config && "query" in config && config.query) {
31
- const queryString = qs.stringify(config.query, {
32
- encode: true,
33
- arrayFormat: "brackets",
34
- skipNulls: true
35
- });
36
- if (queryString) url += `?${queryString}`;
37
- }
38
- let requestConfig = {
39
- method: method.toUpperCase(),
40
- headers: {
41
- ...this.defaultHeaders,
42
- ...config && "headers" in config && config.headers || {}
43
- }
44
- };
45
- if (config && "body" in config && config.body) {
46
- requestConfig.body = JSON.stringify(config.body);
47
- requestConfig.headers = {
48
- ...requestConfig.headers,
49
- "Content-Type": "application/json"
50
- };
51
- }
52
- this.injectTraceContext?.(`${this.baseURL}${url}`, requestConfig.headers);
53
- if (this.options.onRequest) requestConfig = await this.options.onRequest(requestConfig);
54
- try {
55
- let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
56
- if (this.options.onResponse) response = await this.options.onResponse(response);
57
- if (!response.ok) throw response;
58
- if (response.status === 204 || response.headers.get("content-length") === "0") return;
59
- return await response.json();
60
- } catch (error) {
61
- if (this.options.onError) await this.options.onError(error);
62
- throw error;
63
- }
64
- }
65
- wrap(onError) {
66
- return (endpoint, config) => this.request(endpoint, config).then((data) => ({
67
- ok: true,
68
- data
69
- }), async (error) => ({
70
- ok: false,
71
- error: onError ? await onError(error) : error
72
- }));
73
- }
74
- parseEndpoint(endpoint) {
75
- const [method, ...routeParts] = endpoint.split(" ");
76
- const route = routeParts.join(" ");
77
- return {
78
- method: method?.toLowerCase() ?? "",
79
- route
80
- };
81
- }
82
- };
83
- function createTypedFetcher(options) {
84
- const fetcher = new TypedFetcher(options);
85
- const fn = (endpoint, config) => fetcher.request(endpoint, config);
86
- return Object.assign(fn, methodCalls(fn), { wrap: (onError) => Object.assign(fetcher.wrap(onError), fn, { wrap: void 0 }) });
87
- }
88
- //#endregion
89
- export { TypedFetcher, createTypedFetcher };
1
+ import { TypedFetcher, createTypedFetcher } from "./fetcher-CakjC9C7.mjs";
90
2
 
91
- //# sourceMappingURL=fetcher.mjs.map
3
+ export { TypedFetcher, createTypedFetcher };
package/dist/infer.d.cts CHANGED
@@ -1,13 +1,15 @@
1
- import { ConvertRouteParams, Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
1
+ import { Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
2
2
  import { HttpMethod } from "@geekmidas/constructs/types";
3
- import { InferStandardSchema, InferStandardSchemaInput } from "@geekmidas/schema";
3
+ import { InferStandardSchema } from "@geekmidas/schema";
4
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
5
+
5
6
  //#region src/infer.d.ts
7
+
6
8
  /**
7
9
  * Infers path parameters from a route string as an object
8
10
  * @example '/users/{id}/posts/{postId}' -> { id: string, postId: string }
9
11
  */
10
- type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string; } & InferPathParams<Rest> : {};
12
+ type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string } & InferPathParams<Rest> : {};
11
13
  /**
12
14
  * Converts an HTTP method to lowercase for TypedFetcher compatibility
13
15
  */
@@ -27,7 +29,7 @@ type InferOperationParameters<TInput extends EndpointSchemas> = TInput extends {
27
29
  query: infer Q;
28
30
  } ? {
29
31
  parameters: {
30
- query: InferStandardSchemaInput<Q>;
32
+ query: InferStandardSchema<Q>;
31
33
  };
32
34
  } : {};
33
35
  /**
@@ -38,7 +40,7 @@ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSche
38
40
  body: infer B;
39
41
  } ? {
40
42
  content: {
41
- 'application/json': InferStandardSchemaInput<B>;
43
+ 'application/json': InferStandardSchema<B>;
42
44
  };
43
45
  } : never;
44
46
  responses: {
@@ -58,7 +60,7 @@ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSche
58
60
  *
59
61
  * @example
60
62
  * ```typescript
61
- * import { api } from './constructs/api.js';
63
+ * import { e } from '@geekmidas/constructs';
62
64
  * import { createTypedFetcher, type InferOpenApiFromEndpoint } from '@geekmidas/client';
63
65
  * import { z } from 'zod';
64
66
  *
@@ -73,8 +75,8 @@ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSche
73
75
  * const user = await client('GET /users/{id}', { params: { id: '123' } });
74
76
  * ```
75
77
  */
76
- export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer TMethod, infer TInput, infer TOutput, any, any, any> ? {
77
- paths: { [K in ConvertRouteParams<TRoute>]: InferRouteParameters<ConvertRouteParams<TRoute>> & { [M in LowercaseMethod<TMethod>]: InferOperation<TInput, TOutput>; }; };
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> } };
78
80
  } : never;
79
81
  /**
80
82
  * Infers TypedFetcher-compatible paths structure from multiple endpoints
@@ -84,7 +86,7 @@ export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer
84
86
  *
85
87
  * @example
86
88
  * ```typescript
87
- * import { api } from './constructs/api.js';
89
+ * import { e } from '@geekmidas/constructs';
88
90
  * import { createTypedFetcher, type InferOpenApi } from '@geekmidas/client';
89
91
  * import { z } from 'zod';
90
92
  *
@@ -113,7 +115,7 @@ export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer
113
115
  * const newUser = await client('POST /users', { body: { name: 'Jane' } });
114
116
  * ```
115
117
  */
116
- export type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
118
+ type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
117
119
  paths: infer P1;
118
120
  } ? Rest extends [] ? {
119
121
  paths: P1;
@@ -127,4 +129,5 @@ export type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends
127
129
  paths: {};
128
130
  };
129
131
  //#endregion
132
+ export { InferOpenApi, InferOpenApiFromEndpoint };
130
133
  //# sourceMappingURL=infer.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"infer.d.cts","names":[],"sources":["../src/infer.ts"],"mappings":";;;;;;;;;KAgBK,gBAAgB,yBACpB,kCAAkC,eAAe,YAC3C,KAAK,oBAAmB,gBAAgB;;;;KAM1C,gBAAgB,UAAU,cAAc,UAAU;;;;KAKlD,qBAAqB,yBACzB,gBAAgB,gBAAgB;EAG7B;IACC,MAAM,gBAAgB;;;;;;KAOtB,yBAAyB,eAAe,mBAAmB;EAC/D,aAAa;;EAGX;IAMC,OAAO,yBAAyB;;;;;;KAQ/B,eACJ,eAAe,iBACf,gBAAgB,gCACb,yBAAyB;EAC5B,cAAc;IAAiB,YAAY;;IAExC;MAKC,oBAAoB,yBAAyB;;;EAIjD;IACC;MACC,SAAS,gBAAgB;QAEtB,oBAAoB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+BlC,yBAAyB,KACpC,UAAU,eACH,cACA,eACA,cACA;EAUJ,UACE,KAAK,mBAAmB,UAAU,qBAClC,mBAAmB,cAElB,KAAK,gBAAgB,WAAW,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA2ClD,aAAa,qCACxB,mCAAmC,gBAAgB,QAChD,yBAAyB;EAAiB,aAAa;IACtD;EACG,OAAO;IACT,aAAa;EAAgB,aAAa;;EACvC,OAAO,KAAK;;EACZ,OAAO;IACX,aAAa;EACZ"}
1
+ {"version":3,"file":"infer.d.cts","names":[],"sources":["../src/infer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAM8D;;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,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
@@ -1,13 +1,15 @@
1
- import { ConvertRouteParams, Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
1
+ import { Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
2
2
  import { HttpMethod } from "@geekmidas/constructs/types";
3
- import { InferStandardSchema, InferStandardSchemaInput } from "@geekmidas/schema";
3
+ import { InferStandardSchema } from "@geekmidas/schema";
4
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
5
+
5
6
  //#region src/infer.d.ts
7
+
6
8
  /**
7
9
  * Infers path parameters from a route string as an object
8
10
  * @example '/users/{id}/posts/{postId}' -> { id: string, postId: string }
9
11
  */
10
- type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string; } & InferPathParams<Rest> : {};
12
+ type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string } & InferPathParams<Rest> : {};
11
13
  /**
12
14
  * Converts an HTTP method to lowercase for TypedFetcher compatibility
13
15
  */
@@ -27,7 +29,7 @@ type InferOperationParameters<TInput extends EndpointSchemas> = TInput extends {
27
29
  query: infer Q;
28
30
  } ? {
29
31
  parameters: {
30
- query: InferStandardSchemaInput<Q>;
32
+ query: InferStandardSchema<Q>;
31
33
  };
32
34
  } : {};
33
35
  /**
@@ -38,7 +40,7 @@ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSche
38
40
  body: infer B;
39
41
  } ? {
40
42
  content: {
41
- 'application/json': InferStandardSchemaInput<B>;
43
+ 'application/json': InferStandardSchema<B>;
42
44
  };
43
45
  } : never;
44
46
  responses: {
@@ -58,7 +60,7 @@ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSche
58
60
  *
59
61
  * @example
60
62
  * ```typescript
61
- * import { api } from './constructs/api.js';
63
+ * import { e } from '@geekmidas/constructs';
62
64
  * import { createTypedFetcher, type InferOpenApiFromEndpoint } from '@geekmidas/client';
63
65
  * import { z } from 'zod';
64
66
  *
@@ -73,8 +75,8 @@ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSche
73
75
  * const user = await client('GET /users/{id}', { params: { id: '123' } });
74
76
  * ```
75
77
  */
76
- export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer TMethod, infer TInput, infer TOutput, any, any, any> ? {
77
- paths: { [K in ConvertRouteParams<TRoute>]: InferRouteParameters<ConvertRouteParams<TRoute>> & { [M in LowercaseMethod<TMethod>]: InferOperation<TInput, TOutput>; }; };
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> } };
78
80
  } : never;
79
81
  /**
80
82
  * Infers TypedFetcher-compatible paths structure from multiple endpoints
@@ -84,7 +86,7 @@ export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer
84
86
  *
85
87
  * @example
86
88
  * ```typescript
87
- * import { api } from './constructs/api.js';
89
+ * import { e } from '@geekmidas/constructs';
88
90
  * import { createTypedFetcher, type InferOpenApi } from '@geekmidas/client';
89
91
  * import { z } from 'zod';
90
92
  *
@@ -113,7 +115,7 @@ export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer
113
115
  * const newUser = await client('POST /users', { body: { name: 'Jane' } });
114
116
  * ```
115
117
  */
116
- export type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
118
+ type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
117
119
  paths: infer P1;
118
120
  } ? Rest extends [] ? {
119
121
  paths: P1;
@@ -127,4 +129,5 @@ export type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends
127
129
  paths: {};
128
130
  };
129
131
  //#endregion
132
+ export { InferOpenApi, InferOpenApiFromEndpoint };
130
133
  //# sourceMappingURL=infer.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"infer.d.mts","names":[],"sources":["../src/infer.ts"],"mappings":";;;;;;;;;KAgBK,gBAAgB,yBACpB,kCAAkC,eAAe,YAC3C,KAAK,oBAAmB,gBAAgB;;;;KAM1C,gBAAgB,UAAU,cAAc,UAAU;;;;KAKlD,qBAAqB,yBACzB,gBAAgB,gBAAgB;EAG7B;IACC,MAAM,gBAAgB;;;;;;KAOtB,yBAAyB,eAAe,mBAAmB;EAC/D,aAAa;;EAGX;IAMC,OAAO,yBAAyB;;;;;;KAQ/B,eACJ,eAAe,iBACf,gBAAgB,gCACb,yBAAyB;EAC5B,cAAc;IAAiB,YAAY;;IAExC;MAKC,oBAAoB,yBAAyB;;;EAIjD;IACC;MACC,SAAS,gBAAgB;QAEtB,oBAAoB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+BlC,yBAAyB,KACpC,UAAU,eACH,cACA,eACA,cACA;EAUJ,UACE,KAAK,mBAAmB,UAAU,qBAClC,mBAAmB,cAElB,KAAK,gBAAgB,WAAW,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA2ClD,aAAa,qCACxB,mCAAmC,gBAAgB,QAChD,yBAAyB;EAAiB,aAAa;IACtD;EACG,OAAO;IACT,aAAa;EAAgB,aAAa;;EACvC,OAAO,KAAK;;EACZ,OAAO;IACX,aAAa;EACZ"}
1
+ {"version":3,"file":"infer.d.mts","names":[],"sources":["../src/infer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAM8D;;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;KAM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