@geekmidas/client 10.0.0-alpha.2 → 10.0.0-alpha.21

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 (103) hide show
  1. package/README.md +39 -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 +155 -3
  5. package/dist/auth-fetcher.d.cts.map +1 -0
  6. package/dist/auth-fetcher.d.mts +155 -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 +111 -3
  19. package/dist/fetcher.cjs.map +1 -0
  20. package/dist/fetcher.d.cts +23 -3
  21. package/dist/fetcher.d.cts.map +1 -0
  22. package/dist/fetcher.d.mts +23 -3
  23. package/dist/fetcher.d.mts.map +1 -0
  24. package/dist/fetcher.mjs +86 -2
  25. package/dist/fetcher.mjs.map +1 -0
  26. package/dist/index.cjs +9 -6
  27. package/dist/index.d.cts +6 -5
  28. package/dist/index.d.mts +6 -5
  29. package/dist/index.mjs +6 -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/types.cjs +0 -1
  65. package/dist/types.d.cts +114 -2
  66. package/dist/types.d.cts.map +1 -0
  67. package/dist/types.d.mts +114 -2
  68. package/dist/types.d.mts.map +1 -0
  69. package/dist/types.mjs +1 -1
  70. package/package.json +14 -14
  71. package/dist/auth-fetcher-CBYuL6rx.d.cts +0 -158
  72. package/dist/auth-fetcher-CBYuL6rx.d.cts.map +0 -1
  73. package/dist/auth-fetcher-DOj0iz21.mjs +0 -77
  74. package/dist/auth-fetcher-DOj0iz21.mjs.map +0 -1
  75. package/dist/auth-fetcher-DxS8zOLc.d.mts +0 -158
  76. package/dist/auth-fetcher-DxS8zOLc.d.mts.map +0 -1
  77. package/dist/auth-fetcher-HILABmws.cjs +0 -82
  78. package/dist/auth-fetcher-HILABmws.cjs.map +0 -1
  79. package/dist/chunk-CUT6urMc.cjs +0 -30
  80. package/dist/fetcher-C1xtCKpT.d.mts +0 -25
  81. package/dist/fetcher-C1xtCKpT.d.mts.map +0 -1
  82. package/dist/fetcher-CakjC9C7.mjs +0 -88
  83. package/dist/fetcher-CakjC9C7.mjs.map +0 -1
  84. package/dist/fetcher-CwnSqc4D.cjs +0 -100
  85. package/dist/fetcher-CwnSqc4D.cjs.map +0 -1
  86. package/dist/fetcher-cDrfwN-Y.d.cts +0 -25
  87. package/dist/fetcher-cDrfwN-Y.d.cts.map +0 -1
  88. package/dist/infer-6KKCgmg1.cjs +0 -0
  89. package/dist/infer-DfRq5kIb.d.cts +0 -133
  90. package/dist/infer-DfRq5kIb.d.cts.map +0 -1
  91. package/dist/infer-bTirNeNW.d.mts +0 -133
  92. package/dist/infer-bTirNeNW.d.mts.map +0 -1
  93. package/dist/infer-uCUq1whM.mjs +0 -0
  94. package/dist/openapi.cjs +0 -526
  95. package/dist/openapi.cjs.map +0 -1
  96. package/dist/openapi.mjs +0 -501
  97. package/dist/openapi.mjs.map +0 -1
  98. package/dist/types-BH8WgGrm.mjs +0 -0
  99. package/dist/types-BMGM6sZc.d.mts +0 -110
  100. package/dist/types-BMGM6sZc.d.mts.map +0 -1
  101. package/dist/types-DMQMHePI.d.cts +0 -110
  102. package/dist/types-DMQMHePI.d.cts.map +0 -1
  103. package/dist/types-a8gm_IaQ.cjs +0 -0
@@ -1,4 +1,78 @@
1
- import "./fetcher-CakjC9C7.mjs";
2
- import { createAuthAwareFetcher } from "./auth-fetcher-DOj0iz21.mjs";
1
+ import { methodCalls } from "./methods.mjs";
2
+ import { TypedFetcher } from "./fetcher.mjs";
3
+ //#region src/auth-fetcher.ts
4
+ /**
5
+ * Creates an auth-aware fetcher that automatically applies the correct
6
+ * authentication based on the endpoint being called.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { endpointAuth, securitySchemes, paths } from './openapi';
11
+ * import { TokenClient } from '@geekmidas/auth/client';
12
+ *
13
+ * const tokenClient = new TokenClient({ ... });
14
+ *
15
+ * const api = createAuthAwareFetcher<paths>({
16
+ * baseURL: 'https://api.example.com',
17
+ * endpointAuth,
18
+ * securitySchemes,
19
+ * authStrategies: {
20
+ * bearer: { type: 'bearer', tokenProvider: tokenClient },
21
+ * iam: { type: 'iam', signer: awsSigner },
22
+ * },
23
+ * });
24
+ *
25
+ * // Bearer auth automatically applied
26
+ * const user = await api('GET /users/{id}', { params: { id: '123' } });
27
+ *
28
+ * // IAM SigV4 auth automatically applied
29
+ * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
30
+ * ```
31
+ */
32
+ function createAuthAwareFetcher(options) {
33
+ const { endpointAuth, securitySchemes, authStrategies, onRequest: userOnRequest, ...fetcherOptions } = options;
34
+ const baseFetcher = new TypedFetcher({
35
+ ...fetcherOptions,
36
+ onRequest: userOnRequest
37
+ });
38
+ const fetcher = async (endpoint, config) => {
39
+ const schemeName = endpointAuth[endpoint];
40
+ let authHeaders = {};
41
+ if (schemeName) {
42
+ const scheme = securitySchemes[schemeName];
43
+ const strategy = authStrategies[schemeName];
44
+ if (strategy && scheme) authHeaders = await resolveAuthHeaders(strategy, scheme);
45
+ }
46
+ const existingHeaders = config && "headers" in config && config.headers ? config.headers : {};
47
+ const mergedConfig = {
48
+ ...config,
49
+ headers: {
50
+ ...authHeaders,
51
+ ...existingHeaders
52
+ }
53
+ };
54
+ return baseFetcher.request(endpoint, mergedConfig);
55
+ };
56
+ const api = fetcher;
57
+ return Object.assign(api, methodCalls(api));
58
+ }
59
+ /**
60
+ * Resolves auth headers based on the strategy and scheme.
61
+ */
62
+ async function resolveAuthHeaders(strategy, scheme) {
63
+ switch (strategy.type) {
64
+ case "bearer": return strategy.tokenProvider.createValidAuthHeaders();
65
+ case "apiKey": {
66
+ const apiKey = await strategy.apiKeyProvider.getApiKey();
67
+ const headerName = strategy.headerName || scheme.name || "X-API-Key";
68
+ if (scheme.in === "header" || !scheme.in) return { [headerName]: apiKey };
69
+ return {};
70
+ }
71
+ case "iam": return {};
72
+ default: return {};
73
+ }
74
+ }
75
+ //#endregion
76
+ export { createAuthAwareFetcher };
3
77
 
4
- export { createAuthAwareFetcher };
78
+ //# sourceMappingURL=auth-fetcher.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.mjs","names":[],"sources":["../src/auth-fetcher.ts"],"sourcesContent":["import { TypedFetcher } from './fetcher';\nimport { methodCalls } from './methods';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tTypedApiFunction,\n\tTypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } from './types';\n\n/**\n * Security scheme object matching OpenAPI 3.1 specification.\n */\nexport interface SecuritySchemeObject {\n\ttype: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';\n\tdescription?: string;\n\tname?: string;\n\tin?: 'query' | 'header' | 'cookie';\n\tscheme?: string;\n\tbearerFormat?: string;\n\tflows?: Record<string, unknown>;\n\topenIdConnectUrl?: string;\n\t[key: string]: unknown;\n}\n\n/**\n * Extract all non-null security scheme IDs that are actually used in the API.\n * This gives us the union of scheme names that endpoints require.\n */\nexport type UsedSecuritySchemes<\n\tEndpointAuth extends Record<string, string | null>,\n> = NonNullable<EndpointAuth[keyof EndpointAuth]>;\n\n/**\n * Interface for token storage and retrieval.\n * Compatible with @geekmidas/auth TokenClient.\n */\nexport interface TokenProvider {\n\t/**\n\t * Get a valid access token, refreshing if necessary.\n\t */\n\tgetValidAccessToken(): Promise<string | null>;\n\n\t/**\n\t * Create Authorization headers from the current token.\n\t */\n\tcreateValidAuthHeaders(): Promise<Record<string, string>>;\n}\n\n/**\n * Interface for API key providers.\n */\nexport interface ApiKeyProvider {\n\t/**\n\t * Get the API key value.\n\t */\n\tgetApiKey(): Promise<string> | string;\n}\n\n/**\n * Interface for AWS SigV4 request signing.\n */\nexport interface AwsSigner {\n\t/**\n\t * Sign a request with AWS SigV4.\n\t * @param url - The request URL\n\t * @param init - The request init object\n\t * @returns Headers to add to the request\n\t */\n\tsign(url: string, init: RequestInit): Promise<Record<string, string>>;\n}\n\n/**\n * Auth strategy configuration for a specific security scheme type.\n */\nexport type AuthStrategy =\n\t| { type: 'bearer'; tokenProvider: TokenProvider }\n\t| { type: 'apiKey'; apiKeyProvider: ApiKeyProvider; headerName?: string }\n\t| { type: 'iam'; signer: AwsSigner }\n\t| { type: 'none' };\n\n/**\n * Options for creating an auth-aware fetcher.\n *\n * @template EndpointAuth - Map of endpoint strings to their auth scheme (or null for public)\n * @template SecuritySchemes - Available security scheme definitions\n */\nexport interface AuthFetcherOptions<\n\tEndpointAuth extends Record<string, string | null>,\n\tSecuritySchemes extends Record<string, SecuritySchemeObject>,\n> extends Omit<FetcherOptions, 'onRequest'> {\n\t/**\n\t * Runtime map of endpoints to their required auth scheme.\n\t * Generated by `gkm openapi --ts`.\n\t */\n\tendpointAuth: EndpointAuth;\n\n\t/**\n\t * Security scheme definitions.\n\t * Generated by `gkm openapi --ts`.\n\t */\n\tsecuritySchemes: SecuritySchemes;\n\n\t/**\n\t * Auth strategies for security schemes that are actually used.\n\t * Only schemes referenced in endpointAuth are required.\n\t *\n\t * @example\n\t * ```typescript\n\t * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }\n\t * // Then authStrategies must include strategies for 'jwt' and 'iam'\n\t * authStrategies: {\n\t * jwt: { type: 'bearer', tokenProvider },\n\t * iam: { type: 'iam', signer: awsSigner },\n\t * }\n\t * ```\n\t */\n\tauthStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;\n\n\t/**\n\t * Optional request interceptor (runs after auth headers are added).\n\t */\n\tonRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;\n}\n\n/**\n * Creates an auth-aware fetcher that automatically applies the correct\n * authentication based on the endpoint being called.\n *\n * @example\n * ```typescript\n * import { endpointAuth, securitySchemes, paths } from './openapi';\n * import { TokenClient } from '@geekmidas/auth/client';\n *\n * const tokenClient = new TokenClient({ ... });\n *\n * const api = createAuthAwareFetcher<paths>({\n * baseURL: 'https://api.example.com',\n * endpointAuth,\n * securitySchemes,\n * authStrategies: {\n * bearer: { type: 'bearer', tokenProvider: tokenClient },\n * iam: { type: 'iam', signer: awsSigner },\n * },\n * });\n *\n * // Bearer auth automatically applied\n * const user = await api('GET /users/{id}', { params: { id: '123' } });\n *\n * // IAM SigV4 auth automatically applied\n * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });\n * ```\n */\nexport function createAuthAwareFetcher<\n\tPaths,\n\tEndpointAuth extends Record<string, string | null> = Record<\n\t\tstring,\n\t\tstring | null\n\t>,\n\tSecuritySchemes extends Record<string, SecuritySchemeObject> = Record<\n\t\tstring,\n\t\tSecuritySchemeObject\n\t>,\n>(\n\toptions: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n\t\tbaseURL: string;\n\t},\n): TypedApiFunction<Paths> {\n\tconst {\n\t\tendpointAuth,\n\t\tsecuritySchemes,\n\t\tauthStrategies,\n\t\tonRequest: userOnRequest,\n\t\t...fetcherOptions\n\t} = options;\n\n\t// Create base fetcher with user's onRequest if provided\n\tconst baseFetcher = new TypedFetcher<Paths>({\n\t\t...fetcherOptions,\n\t\tonRequest: userOnRequest,\n\t});\n\n\tconst fetcher = async <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> => {\n\t\t// Look up auth requirement for this endpoint\n\t\tconst schemeName = endpointAuth[endpoint as keyof EndpointAuth] as\n\t\t\t| string\n\t\t\t| null;\n\n\t\tlet authHeaders: Record<string, string> = {};\n\n\t\tif (schemeName) {\n\t\t\tconst scheme = securitySchemes[schemeName as keyof SecuritySchemes];\n\t\t\t// Since authStrategies is now required to have all used schemes,\n\t\t\t// we can safely access it - TypeScript ensures the strategy exists\n\t\t\tconst strategy =\n\t\t\t\tauthStrategies[schemeName as UsedSecuritySchemes<EndpointAuth>];\n\n\t\t\tif (strategy && scheme) {\n\t\t\t\tauthHeaders = await resolveAuthHeaders(strategy, scheme);\n\t\t\t}\n\t\t}\n\n\t\t// Merge auth headers with config headers\n\t\tconst existingHeaders =\n\t\t\tconfig && 'headers' in config && config.headers\n\t\t\t\t? (config.headers as Record<string, string>)\n\t\t\t\t: {};\n\n\t\tconst mergedConfig = {\n\t\t\t...config,\n\t\t\theaders: {\n\t\t\t\t...authHeaders,\n\t\t\t\t...existingHeaders,\n\t\t\t},\n\t\t} as unknown as FilteredRequestConfig<Paths, T>;\n\n\t\treturn baseFetcher.request(endpoint, mergedConfig);\n\t};\n\n\tconst api = fetcher as TypedApiFunction<Paths>;\n\treturn Object.assign(api, methodCalls<Paths>(api));\n}\n\n/**\n * Resolves auth headers based on the strategy and scheme.\n */\nasync function resolveAuthHeaders(\n\tstrategy: AuthStrategy,\n\tscheme: SecuritySchemeObject,\n): Promise<Record<string, string>> {\n\tswitch (strategy.type) {\n\t\tcase 'bearer': {\n\t\t\treturn strategy.tokenProvider.createValidAuthHeaders();\n\t\t}\n\n\t\tcase 'apiKey': {\n\t\t\tconst apiKey = await strategy.apiKeyProvider.getApiKey();\n\t\t\tconst headerName = strategy.headerName || scheme.name || 'X-API-Key';\n\n\t\t\tif (scheme.in === 'header' || !scheme.in) {\n\t\t\t\treturn { [headerName]: apiKey };\n\t\t\t}\n\t\t\t// Note: query and cookie API keys are handled differently\n\t\t\t// For now, we only support header-based API keys\n\t\t\treturn {};\n\t\t}\n\n\t\tcase 'iam': {\n\t\t\t// IAM signing requires the full URL and request config\n\t\t\t// This is a simplified version - full implementation would need\n\t\t\t// access to the complete request\n\t\t\t// For now, return empty - the actual signing should be done\n\t\t\t// in a custom onRequest interceptor if needed\n\t\t\treturn {};\n\t\t}\n\t\tdefault:\n\t\t\treturn {};\n\t}\n}\n\n/**\n * Type helper to extract the security scheme ID from an endpoint.\n */\nexport type GetEndpointAuth<\n\tEndpointAuth extends Record<string, string | null>,\n\tEndpoint extends keyof EndpointAuth,\n> = EndpointAuth[Endpoint];\n\n/**\n * Type helper to get all authenticated endpoints.\n */\nexport type AuthenticatedEndpoints<\n\tEndpointAuth extends Record<string, string | null>,\n> = {\n\t[K in keyof EndpointAuth]: EndpointAuth[K] extends null ? never : K;\n}[keyof EndpointAuth];\n\n/**\n * Type helper to get all public endpoints.\n */\nexport type PublicEndpoints<\n\tEndpointAuth extends Record<string, string | null>,\n> = {\n\t[K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never;\n}[keyof EndpointAuth];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,uBAWf,SAG0B;CAC1B,MAAM,EACL,cACA,iBACA,gBACA,WAAW,eACX,GAAG,mBACA;CAGJ,MAAM,cAAc,IAAI,aAAoB;EAC3C,GAAG;EACH,WAAW;CACZ,CAAC;CAED,MAAM,UAAU,OACf,UACA,WACgD;EAEhD,MAAM,aAAa,aAAa;EAIhC,IAAI,cAAsC,CAAC;EAE3C,IAAI,YAAY;GACf,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACL,eAAe;GAEhB,IAAI,YAAY,QACf,cAAc,MAAM,mBAAmB,UAAU,MAAM;EAEzD;EAGA,MAAM,kBACL,UAAU,aAAa,UAAU,OAAO,UACpC,OAAO,UACR,CAAC;EAEL,MAAM,eAAe;GACpB,GAAG;GACH,SAAS;IACR,GAAG;IACH,GAAG;GACJ;EACD;EAEA,OAAO,YAAY,QAAQ,UAAU,YAAY;CAClD;CAEA,MAAM,MAAM;CACZ,OAAO,OAAO,OAAO,KAAK,YAAmB,GAAG,CAAC;AAClD;;;;AAKA,eAAe,mBACd,UACA,QACkC;CAClC,QAAQ,SAAS,MAAjB;EACC,KAAK,UACJ,OAAO,SAAS,cAAc,uBAAuB;EAGtD,KAAK,UAAU;GACd,MAAM,SAAS,MAAM,SAAS,eAAe,UAAU;GACvD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;GAEzD,IAAI,OAAO,OAAO,YAAY,CAAC,OAAO,IACrC,OAAO,GAAG,aAAa,OAAO;GAI/B,OAAO,CAAC;EACT;EAEA,KAAK,OAMJ,OAAO,CAAC;EAET,SACC,OAAO,CAAC;CACV;AACD"}
@@ -1,7 +1,6 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
3
- const react = require_chunk.__toESM(require("react"));
4
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _tanstack_react_query = require("@tanstack/react-query");
3
+ let react = require("react");
5
4
  //#region src/endpoint-hooks.ts
6
5
  /**
7
6
  * Build query key from endpoint and config
@@ -43,7 +42,7 @@ function createEndpointHooks(fetcher, options = {}) {
43
42
  queryKey,
44
43
  queryOptions
45
44
  ]);
46
- return (0, __tanstack_react_query.useQuery)(memoizedOptions);
45
+ return (0, _tanstack_react_query.useQuery)(memoizedOptions);
47
46
  },
48
47
  useMutation: (endpoint, mutationOptions) => {
49
48
  const memoizedOptions = (0, react.useMemo)(() => ({
@@ -54,9 +53,9 @@ function createEndpointHooks(fetcher, options = {}) {
54
53
  fetcher,
55
54
  mutationOptions
56
55
  ]);
57
- return (0, __tanstack_react_query.useMutation)(memoizedOptions);
56
+ return (0, _tanstack_react_query.useMutation)(memoizedOptions);
58
57
  },
59
- useInfiniteQuery: (endpoint, options$1, config) => {
58
+ useInfiniteQuery: (endpoint, options, config) => {
60
59
  const queryKey = buildQueryKey(endpoint, config);
61
60
  const memoizedOptions = (0, react.useMemo)(() => ({
62
61
  queryKey,
@@ -71,21 +70,18 @@ function createEndpointHooks(fetcher, options = {}) {
71
70
  ...pageQuery
72
71
  }
73
72
  };
74
- } else if (pageParam !== void 0 && !config) {
75
- const pageQuery = typeof pageParam === "object" ? pageParam : { page: pageParam };
76
- mergedConfig = { query: pageQuery };
77
- }
73
+ } else if (pageParam !== void 0 && !config) mergedConfig = { query: typeof pageParam === "object" ? pageParam : { page: pageParam } };
78
74
  return fetcher(endpoint, mergedConfig);
79
75
  },
80
- ...options$1
76
+ ...options
81
77
  }), [
82
78
  endpoint,
83
79
  config,
84
80
  fetcher,
85
81
  queryKey,
86
- options$1
82
+ options
87
83
  ]);
88
- return (0, __tanstack_react_query.useInfiniteQuery)(memoizedOptions);
84
+ return (0, _tanstack_react_query.useInfiniteQuery)(memoizedOptions);
89
85
  },
90
86
  invalidateQueries: (endpoint, config) => {
91
87
  if (!options.queryClient) throw new Error("queryClient is required for invalidateQueries. Pass it to createEndpointHooks options.");
@@ -102,7 +98,7 @@ function createEndpointHooks(fetcher, options = {}) {
102
98
  buildQueryKey
103
99
  };
104
100
  }
105
-
106
101
  //#endregion
107
102
  exports.createEndpointHooks = createEndpointHooks;
103
+
108
104
  //# sourceMappingURL=endpoint-hooks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-hooks.cjs","names":["endpoint: T","config?: FilteredRequestConfig<Paths, T>","key: unknown[]","fetcher: TypedApiFunction<Paths>","options: CreateEndpointHooksOptions","mutationOptions?: Omit<\n\t\t\t\tUseMutationOptions<\n\t\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\t\tError,\n\t\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t\t>,\n\t\t\t\t'mutationFn'\n\t\t\t>","config: FilteredRequestConfig<Paths, T>","options: Omit<\n\t\t\t\tUseInfiniteQueryOptions<\n\t\t\t\t\tTPageData,\n\t\t\t\t\tError,\n\t\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\t\tunknown[],\n\t\t\t\t\tTPageParam\n\t\t\t\t>,\n\t\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t\t> & {\n\t\t\t\tgetNextPageParam: (\n\t\t\t\t\tlastPage: TPageData,\n\t\t\t\t\tallPages: TPageData[],\n\t\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\t\tallPageParams: TPageParam[],\n\t\t\t\t) => TPageParam | undefined;\n\t\t\t\tinitialPageParam: TPageParam;\n\t\t\t}","options"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseInfiniteQueryResult,\n\tUseMutationOptions,\n\tUseMutationResult,\n\tUseQueryOptions,\n\tUseQueryResult,\n} from '@tanstack/react-query';\nimport { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n\tExtractEndpointResponse,\n\tFilteredRequestConfig,\n\tIsConfigRequired,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n\tconst key: unknown[] = [endpoint];\n\n\tif (config && 'params' in config && config.params) {\n\t\tkey.push({ params: config.params });\n\t}\n\n\tif (config && 'query' in config && config.query) {\n\t\tkey.push({ query: config.query });\n\t}\n\n\treturn key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n\tqueryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n\tPaths,\n\tT\n> extends true\n\t? [\n\t\t\tconfig: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t]\n\t: [\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n\t/**\n\t * Use query hook for GET endpoints.\n\t * Config is required when endpoint has path params.\n\t */\n\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\t...args: UseQueryArgs<Paths, T>\n\t) => UseQueryResult<ExtractEndpointResponse<Paths, T>, Error>;\n\n\t/**\n\t * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n\t * Config with params/body is passed to mutate().\n\t */\n\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) => UseMutationResult<\n\t\tExtractEndpointResponse<Paths, T>,\n\t\tError,\n\t\tFilteredRequestConfig<Paths, T>\n\t>;\n\n\t/**\n\t * Use infinite query hook for paginated GET endpoints.\n\t */\n\tuseInfiniteQuery: <\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => UseInfiniteQueryResult<\n\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\tError\n\t>;\n\n\t/**\n\t * Invalidate queries for a specific endpoint.\n\t */\n\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => Promise<void>;\n\n\t/**\n\t * Invalidate all queries in the cache.\n\t */\n\tinvalidateAllQueries: () => Promise<void>;\n\n\t/**\n\t * Build a query key for manual cache operations\n\t */\n\tbuildQueryKey: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n\tfetcher: TypedApiFunction<Paths>,\n\toptions: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n\treturn {\n\t\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\t...args: UseQueryArgs<Paths, T>\n\t\t) => {\n\t\t\t// Parse args - config is first, options is second\n\t\t\tconst [config, queryOptions] = args as [\n\t\t\t\tFilteredRequestConfig<Paths, T> | undefined,\n\t\t\t\t(\n\t\t\t\t\t| Omit<\n\t\t\t\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t\t\t >\n\t\t\t\t\t| undefined\n\t\t\t\t),\n\t\t\t];\n\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: () =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...queryOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, queryOptions],\n\t\t\t);\n\n\t\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n\t\t\t\tmemoizedOptions,\n\t\t\t);\n\t\t},\n\n\t\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tmutationOptions?: Omit<\n\t\t\t\tUseMutationOptions<\n\t\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\t\tError,\n\t\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t\t>,\n\t\t\t\t'mutationFn'\n\t\t\t>,\n\t\t) => {\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...mutationOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, fetcher, mutationOptions],\n\t\t\t);\n\n\t\t\treturn useMutation<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tuseInfiniteQuery: <\n\t\t\tT extends QueryEndpoint<Paths>,\n\t\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\t\tTPageParam = unknown,\n\t\t>(\n\t\t\tendpoint: T,\n\t\t\toptions: Omit<\n\t\t\t\tUseInfiniteQueryOptions<\n\t\t\t\t\tTPageData,\n\t\t\t\t\tError,\n\t\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\t\tunknown[],\n\t\t\t\t\tTPageParam\n\t\t\t\t>,\n\t\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t\t> & {\n\t\t\t\tgetNextPageParam: (\n\t\t\t\t\tlastPage: TPageData,\n\t\t\t\t\tallPages: TPageData[],\n\t\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\t\tallPageParams: TPageParam[],\n\t\t\t\t) => TPageParam | undefined;\n\t\t\t\tinitialPageParam: TPageParam;\n\t\t\t},\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: ({\n\t\t\t\t\t\tpageParam,\n\t\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t\t} as any;\n\t\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t\t},\n\t\t\t\t\t...options,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, options],\n\t\t\t);\n\n\t\t\treturn useInfiniteQuery<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\t\t\treturn options.queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\tinvalidateAllQueries: () => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateAllQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn options.queryClient.invalidateQueries();\n\t\t},\n\n\t\tbuildQueryKey,\n\t};\n}\n"],"mappings":";;;;;;;;AAwBA,SAAS,cACRA,UACAC,QACY;CACZ,MAAMC,MAAiB,CAAC,QAAS;AAEjC,KAAI,UAAU,YAAY,UAAU,OAAO,OAC1C,KAAI,KAAK,E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Q,EAC9C;AAED,UAAO,6CAML,gBAAgB;EAClB;EAED,mBAAmB,CAClBR,UACAC,WACI;AACJ,QAAK,QAAQ,YACZ,OAAM,IAAI,MACT;GAGF,MAAM,WAAW,cAAc,UAAU,OAAO;AAChD,UAAO,QAAQ,YAAY,kBAAkB;IAC5C;IACA,SAAS;GACT,EAAC;EACF;EAED,sBAAsB,MAAM;AAC3B,QAAK,QAAQ,YACZ,OAAM,IAAI,MACT;AAGF,UAAO,QAAQ,YAAY,mBAAmB;EAC9C;EAED;CACA;AACD"}
1
+ {"version":3,"file":"endpoint-hooks.cjs","names":["useMemo","useQuery","useMutation","useInfiniteQuery"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseInfiniteQueryResult,\n\tUseMutationOptions,\n\tUseMutationResult,\n\tUseQueryOptions,\n\tUseQueryResult,\n} from '@tanstack/react-query';\nimport { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n\tExtractEndpointResponse,\n\tFilteredRequestConfig,\n\tIsConfigRequired,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n\tconst key: unknown[] = [endpoint];\n\n\tif (config && 'params' in config && config.params) {\n\t\tkey.push({ params: config.params });\n\t}\n\n\tif (config && 'query' in config && config.query) {\n\t\tkey.push({ query: config.query });\n\t}\n\n\treturn key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n\tqueryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n\tPaths,\n\tT\n> extends true\n\t? [\n\t\t\tconfig: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t]\n\t: [\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n\t/**\n\t * Use query hook for GET endpoints.\n\t * Config is required when endpoint has path params.\n\t */\n\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\t...args: UseQueryArgs<Paths, T>\n\t) => UseQueryResult<ExtractEndpointResponse<Paths, T>, Error>;\n\n\t/**\n\t * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n\t * Config with params/body is passed to mutate().\n\t */\n\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) => UseMutationResult<\n\t\tExtractEndpointResponse<Paths, T>,\n\t\tError,\n\t\tFilteredRequestConfig<Paths, T>\n\t>;\n\n\t/**\n\t * Use infinite query hook for paginated GET endpoints.\n\t */\n\tuseInfiniteQuery: <\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => UseInfiniteQueryResult<\n\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\tError\n\t>;\n\n\t/**\n\t * Invalidate queries for a specific endpoint.\n\t */\n\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => Promise<void>;\n\n\t/**\n\t * Invalidate all queries in the cache.\n\t */\n\tinvalidateAllQueries: () => Promise<void>;\n\n\t/**\n\t * Build a query key for manual cache operations\n\t */\n\tbuildQueryKey: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n\tfetcher: TypedApiFunction<Paths>,\n\toptions: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n\treturn {\n\t\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\t...args: UseQueryArgs<Paths, T>\n\t\t) => {\n\t\t\t// Parse args - config is first, options is second\n\t\t\tconst [config, queryOptions] = args as [\n\t\t\t\tFilteredRequestConfig<Paths, T> | undefined,\n\t\t\t\t(\n\t\t\t\t\t| Omit<\n\t\t\t\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t\t\t >\n\t\t\t\t\t| undefined\n\t\t\t\t),\n\t\t\t];\n\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: () =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...queryOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, queryOptions],\n\t\t\t);\n\n\t\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n\t\t\t\tmemoizedOptions,\n\t\t\t);\n\t\t},\n\n\t\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tmutationOptions?: Omit<\n\t\t\t\tUseMutationOptions<\n\t\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\t\tError,\n\t\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t\t>,\n\t\t\t\t'mutationFn'\n\t\t\t>,\n\t\t) => {\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...mutationOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, fetcher, mutationOptions],\n\t\t\t);\n\n\t\t\treturn useMutation<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tuseInfiniteQuery: <\n\t\t\tT extends QueryEndpoint<Paths>,\n\t\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\t\tTPageParam = unknown,\n\t\t>(\n\t\t\tendpoint: T,\n\t\t\toptions: Omit<\n\t\t\t\tUseInfiniteQueryOptions<\n\t\t\t\t\tTPageData,\n\t\t\t\t\tError,\n\t\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\t\tunknown[],\n\t\t\t\t\tTPageParam\n\t\t\t\t>,\n\t\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t\t> & {\n\t\t\t\tgetNextPageParam: (\n\t\t\t\t\tlastPage: TPageData,\n\t\t\t\t\tallPages: TPageData[],\n\t\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\t\tallPageParams: TPageParam[],\n\t\t\t\t) => TPageParam | undefined;\n\t\t\t\tinitialPageParam: TPageParam;\n\t\t\t},\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: ({\n\t\t\t\t\t\tpageParam,\n\t\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t\t} as any;\n\t\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t\t},\n\t\t\t\t\t...options,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, options],\n\t\t\t);\n\n\t\t\treturn useInfiniteQuery<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\t\t\treturn options.queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\tinvalidateAllQueries: () => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateAllQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn options.queryClient.invalidateQueries();\n\t\t},\n\n\t\tbuildQueryKey,\n\t};\n}\n"],"mappings":";;;;;;;AAwBA,SAAS,cACR,UACA,QACY;CACZ,MAAM,MAAiB,CAAC,QAAQ;CAEhC,IAAI,UAAU,YAAY,UAAU,OAAO,QAC1C,IAAI,KAAK,EAAE,QAAQ,OAAO,OAAO,CAAC;CAGnC,IAAI,UAAU,WAAW,UAAU,OAAO,OACzC,IAAI,KAAK,EAAE,OAAO,OAAO,MAAM,CAAC;CAGjC,OAAO;AACR;;;;;;;;;;;;;;;;AAsIA,SAAgB,oBACf,SACA,UAAsC,CAAC,GAChB;CACvB,OAAO;EACN,WACC,UACA,GAAG,SACC;GAEJ,MAAM,CAAC,QAAQ,gBAAgB;GAW/B,MAAM,WAAW,cAAc,UAAU,MAAM;GAE/C,MAAM,mBAAA,GAAkBA,MAAAA,QAAAA,QAChB;IACN;IACA,eAGE,QAIC,UAAU,MAAM;IACnB,GAAG;GACJ,IACA;IAAC;IAAU;IAAQ;IAAS;IAAU;GAAY,CACnD;GAEA,QAAA,GAAOC,sBAAAA,SAAAA,CACN,eACD;EACD;EAEA,cACC,UACA,oBAQI;GACJ,MAAM,mBAAA,GAAkBD,MAAAA,QAAAA,QAChB;IACN,aAAa,WAGX,QAIC,UAAU,MAAM;IACnB,GAAG;GACJ,IACA;IAAC;IAAU;IAAS;GAAe,CACpC;GAEA,QAAA,GAAOE,sBAAAA,YAAAA,CAIL,eAAe;EAClB;EAEA,mBAKC,UACA,SAkBA,WACI;GACJ,MAAM,WAAW,cAAc,UAAU,MAAM;GAE/C,MAAM,mBAAA,GAAkBF,MAAAA,QAAAA,QAChB;IACN;IACA,UAAU,EACT,gBACkD;KAClD,IAAI,eAAe;KACnB,IAAI,cAAc,KAAA,KAAa,QAAQ;MACtC,MAAM,YACL,OAAO,cAAc,WAAW,YAAY,EAAE,MAAM,UAAU;MAC/D,eAAe;OACd,GAAG;OACH,OAAO;QAAE,GAAI,OAAe;QAAO,GAAG;OAAU;MACjD;KACD,OAAO,IAAI,cAAc,KAAA,KAAa,CAAC,QAGtC,eAAe,EAAE,OADhB,OAAO,cAAc,WAAW,YAAY,EAAE,MAAM,UAAU,EAC7B;KAEnC,OACC,QAIC,UAAU,YAAY;IACzB;IACA,GAAG;GACJ,IACA;IAAC;IAAU;IAAQ;IAAS;IAAU;GAAO,CAC9C;GAEA,QAAA,GAAOG,sBAAAA,iBAAAA,CAML,eAAe;EAClB;EAEA,oBACC,UACA,WACI;GACJ,IAAI,CAAC,QAAQ,aACZ,MAAM,IAAI,MACT,wFACD;GAED,MAAM,WAAW,cAAc,UAAU,MAAM;GAC/C,OAAO,QAAQ,YAAY,kBAAkB;IAC5C;IACA,OAAO,CAAC,CAAC;GACV,CAAC;EACF;EAEA,4BAA4B;GAC3B,IAAI,CAAC,QAAQ,aACZ,MAAM,IAAI,MACT,2FACD;GAED,OAAO,QAAQ,YAAY,kBAAkB;EAC9C;EAEA;CACD;AACD"}
@@ -1,12 +1,10 @@
1
- import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-DMQMHePI.cjs";
1
+ import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types.cjs";
2
2
  import { QueryClient, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
3
-
4
3
  //#region src/endpoint-hooks.d.ts
5
-
6
4
  /**
7
5
  * Options for creating endpoint-based hooks
8
6
  */
9
- interface CreateEndpointHooksOptions {
7
+ export interface CreateEndpointHooksOptions {
10
8
  queryClient?: QueryClient;
11
9
  }
12
10
  /**
@@ -16,7 +14,7 @@ type UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<Path
16
14
  /**
17
15
  * Endpoint-based React Query hooks
18
16
  */
19
- interface EndpointHooks<Paths> {
17
+ export interface EndpointHooks<Paths> {
20
18
  /**
21
19
  * Use query hook for GET endpoints.
22
20
  * Config is required when endpoint has path params.
@@ -68,7 +66,6 @@ interface EndpointHooks<Paths> {
68
66
  * await mutation.mutateAsync({ body: { name: 'John' } });
69
67
  * ```
70
68
  */
71
- declare function createEndpointHooks<Paths>(fetcher: TypedApiFunction<Paths>, options?: CreateEndpointHooksOptions): EndpointHooks<Paths>;
69
+ export declare function createEndpointHooks<Paths>(fetcher: TypedApiFunction<Paths>, options?: CreateEndpointHooksOptions): EndpointHooks<Paths>;
72
70
  //#endregion
73
- export { CreateEndpointHooksOptions, EndpointHooks, createEndpointHooks };
74
71
  //# sourceMappingURL=endpoint-hooks.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-hooks.d.cts","names":[],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":[],"mappings":";;;;;;;AA4CA;AAOK,UAPY,0BAAA,CAOA;EAAA,WAAA,CAAA,EANF,WAME;;;;;KAAZ,YAAsD,CAAA,KAAA,EAAA,UAAxB,aAAwB,CAAV,KAAU,CAAA,CAAA,GAAA,gBAAA,CAC1D,KAD0D,EAE1D,CAF0D,CAAA,SAAA,IAAA,GAAA,CAAgB,MAK1C,EAAtB,qBAAsB,CAAA,KAAA,EAAO,CAAP,CAAA,EAAK,OAAE,GAC3B,IAD2B,CAEpC,eAFoC,CAEpB,uBAFoB,CAEI,KAFJ,EAEW,CAFX,CAAA,EAEe,KAFf,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAC,GAAA,CAAT,MAEY,GAKhC,qBALgC,CAKV,KALU,EAKH,CALG,CAAA,EAAK,OAAE,GAMtC,IANsC,CAO/C,eAP+C,CAO/B,uBAP+B,CAOP,KAPO,EAOA,CAPA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;;;KAMV,aAAa,OAAO,UAAU,cAAc,UAAU,iBAC1D,OACA,mBAGE,QAAQ,sBAAsB,OAAO,IACrC,UAAU,KACT,gBAAgB,wBAAwB,OAAO,IAAI,oCAKpD,SAAS,sBAAsB,OAAO,IACtC,UAAU,KACT,gBAAgB,wBAAwB,OAAO,IAAI;;;;iBAQtC,cAAc;;;;;EAK9B,WAAW,UAAU,cAAc,QAClC,UAAU,MACP,MAAM,aAAa,OAAO,OACzB,eAAe,wBAAwB,OAAO,IAAI;;;;;EAMvD,cAAc,UAAU,iBAAiB,QACxC,UAAU,GACV,UAAU,KACT,mBACC,wBAAwB,OAAO,IAC/B,OACA,sBAAsB,OAAO,uBAI3B,kBACJ,wBAAwB,OAAO,IAC/B,OACA,sBAAsB,OAAO;;;;EAM9B,mBACC,UAAU,cAAc,QACxB,YAAY,wBAAwB,OAAO,IAC3C,sBAEA,UAAU,GACV,SAAS,KACR,wBACC,WACA;IACE,OAAO;IAAa,YAAY;gBAElC;IAID,mBACC,UAAU,WACV,UAAU,aACV,eAAe,YACf,eAAe,iBACX;IACL,kBAAkB;KAEnB,SAAS,sBAAsB,OAAO,OAClC;IACF,OAAO;IAAa,YAAY;KAClC;;;;EAMD,oBAAoB,UAAU,cAAc,QAC3C,UAAU,GACV,SAAS,sBAAsB,OAAO,OAClC;;;;EAKL,4BAA4B;;;;EAK5B,gBAAgB,UAAU,cAAc,QACvC,UAAU,GACV,SAAS,sBAAsB,OAAO;;;;;;;;;;;;;;;;;wBAmBxB,oBAAoB,OACnC,SAAS,iBAAiB,QAC1B,UAAS,6BACP,cAAc"}
@@ -1,12 +1,10 @@
1
- import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-BMGM6sZc.mjs";
1
+ import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types.mjs";
2
2
  import { QueryClient, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
3
-
4
3
  //#region src/endpoint-hooks.d.ts
5
-
6
4
  /**
7
5
  * Options for creating endpoint-based hooks
8
6
  */
9
- interface CreateEndpointHooksOptions {
7
+ export interface CreateEndpointHooksOptions {
10
8
  queryClient?: QueryClient;
11
9
  }
12
10
  /**
@@ -16,7 +14,7 @@ type UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<Path
16
14
  /**
17
15
  * Endpoint-based React Query hooks
18
16
  */
19
- interface EndpointHooks<Paths> {
17
+ export interface EndpointHooks<Paths> {
20
18
  /**
21
19
  * Use query hook for GET endpoints.
22
20
  * Config is required when endpoint has path params.
@@ -68,7 +66,6 @@ interface EndpointHooks<Paths> {
68
66
  * await mutation.mutateAsync({ body: { name: 'John' } });
69
67
  * ```
70
68
  */
71
- declare function createEndpointHooks<Paths>(fetcher: TypedApiFunction<Paths>, options?: CreateEndpointHooksOptions): EndpointHooks<Paths>;
69
+ export declare function createEndpointHooks<Paths>(fetcher: TypedApiFunction<Paths>, options?: CreateEndpointHooksOptions): EndpointHooks<Paths>;
72
70
  //#endregion
73
- export { CreateEndpointHooksOptions, EndpointHooks, createEndpointHooks };
74
71
  //# sourceMappingURL=endpoint-hooks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-hooks.d.mts","names":[],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":[],"mappings":";;;;;;;AA4CA;AAOK,UAPY,0BAAA,CAOA;EAAA,WAAA,CAAA,EANF,WAME;;;;;KAAZ,YAAsD,CAAA,KAAA,EAAA,UAAxB,aAAwB,CAAV,KAAU,CAAA,CAAA,GAAA,gBAAA,CAC1D,KAD0D,EAE1D,CAF0D,CAAA,SAAA,IAAA,GAAA,CAAgB,MAK1C,EAAtB,qBAAsB,CAAA,KAAA,EAAO,CAAP,CAAA,EAAK,OAAE,GAC3B,IAD2B,CAEpC,eAFo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
@@ -1,6 +1,5 @@
1
1
  import { useInfiniteQuery, useMutation, useQuery } from "@tanstack/react-query";
2
2
  import { useMemo } from "react";
3
-
4
3
  //#region src/endpoint-hooks.ts
5
4
  /**
6
5
  * Build query key from endpoint and config
@@ -55,7 +54,7 @@ function createEndpointHooks(fetcher, options = {}) {
55
54
  ]);
56
55
  return useMutation(memoizedOptions);
57
56
  },
58
- useInfiniteQuery: (endpoint, options$1, config) => {
57
+ useInfiniteQuery: (endpoint, options, config) => {
59
58
  const queryKey = buildQueryKey(endpoint, config);
60
59
  const memoizedOptions = useMemo(() => ({
61
60
  queryKey,
@@ -70,19 +69,16 @@ function createEndpointHooks(fetcher, options = {}) {
70
69
  ...pageQuery
71
70
  }
72
71
  };
73
- } else if (pageParam !== void 0 && !config) {
74
- const pageQuery = typeof pageParam === "object" ? pageParam : { page: pageParam };
75
- mergedConfig = { query: pageQuery };
76
- }
72
+ } else if (pageParam !== void 0 && !config) mergedConfig = { query: typeof pageParam === "object" ? pageParam : { page: pageParam } };
77
73
  return fetcher(endpoint, mergedConfig);
78
74
  },
79
- ...options$1
75
+ ...options
80
76
  }), [
81
77
  endpoint,
82
78
  config,
83
79
  fetcher,
84
80
  queryKey,
85
- options$1
81
+ options
86
82
  ]);
87
83
  return useInfiniteQuery(memoizedOptions);
88
84
  },
@@ -101,7 +97,7 @@ function createEndpointHooks(fetcher, options = {}) {
101
97
  buildQueryKey
102
98
  };
103
99
  }
104
-
105
100
  //#endregion
106
101
  export { createEndpointHooks };
102
+
107
103
  //# sourceMappingURL=endpoint-hooks.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-hooks.mjs","names":["endpoint: T","config?: FilteredRequestConfig<Paths, T>","key: unknown[]","fetcher: TypedApiFunction<Paths>","options: CreateEndpointHooksOptions","mutationOptions?: Omit<\n\t\t\t\tUseMutationOptions<\n\t\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\t\tError,\n\t\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t\t>,\n\t\t\t\t'mutationFn'\n\t\t\t>","config: FilteredRequestConfig<Paths, T>","options: Omit<\n\t\t\t\tUseInfiniteQueryOptions<\n\t\t\t\t\tTPageData,\n\t\t\t\t\tError,\n\t\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\t\tunknown[],\n\t\t\t\t\tTPageParam\n\t\t\t\t>,\n\t\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t\t> & {\n\t\t\t\tgetNextPageParam: (\n\t\t\t\t\tlastPage: TPageData,\n\t\t\t\t\tallPages: TPageData[],\n\t\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\t\tallPageParams: TPageParam[],\n\t\t\t\t) => TPageParam | undefined;\n\t\t\t\tinitialPageParam: TPageParam;\n\t\t\t}","options"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseInfiniteQueryResult,\n\tUseMutationOptions,\n\tUseMutationResult,\n\tUseQueryOptions,\n\tUseQueryResult,\n} from '@tanstack/react-query';\nimport { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n\tExtractEndpointResponse,\n\tFilteredRequestConfig,\n\tIsConfigRequired,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n\tconst key: unknown[] = [endpoint];\n\n\tif (config && 'params' in config && config.params) {\n\t\tkey.push({ params: config.params });\n\t}\n\n\tif (config && 'query' in config && config.query) {\n\t\tkey.push({ query: config.query });\n\t}\n\n\treturn key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n\tqueryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n\tPaths,\n\tT\n> extends true\n\t? [\n\t\t\tconfig: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t]\n\t: [\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n\t/**\n\t * Use query hook for GET endpoints.\n\t * Config is required when endpoint has path params.\n\t */\n\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\t...args: UseQueryArgs<Paths, T>\n\t) => UseQueryResult<ExtractEndpointResponse<Paths, T>, Error>;\n\n\t/**\n\t * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n\t * Config with params/body is passed to mutate().\n\t */\n\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) => UseMutationResult<\n\t\tExtractEndpointResponse<Paths, T>,\n\t\tError,\n\t\tFilteredRequestConfig<Paths, T>\n\t>;\n\n\t/**\n\t * Use infinite query hook for paginated GET endpoints.\n\t */\n\tuseInfiniteQuery: <\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => UseInfiniteQueryResult<\n\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\tError\n\t>;\n\n\t/**\n\t * Invalidate queries for a specific endpoint.\n\t */\n\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => Promise<void>;\n\n\t/**\n\t * Invalidate all queries in the cache.\n\t */\n\tinvalidateAllQueries: () => Promise<void>;\n\n\t/**\n\t * Build a query key for manual cache operations\n\t */\n\tbuildQueryKey: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n\tfetcher: TypedApiFunction<Paths>,\n\toptions: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n\treturn {\n\t\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\t...args: UseQueryArgs<Paths, T>\n\t\t) => {\n\t\t\t// Parse args - config is first, options is second\n\t\t\tconst [config, queryOptions] = args as [\n\t\t\t\tFilteredRequestConfig<Paths, T> | undefined,\n\t\t\t\t(\n\t\t\t\t\t| Omit<\n\t\t\t\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t\t\t >\n\t\t\t\t\t| undefined\n\t\t\t\t),\n\t\t\t];\n\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: () =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...queryOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, queryOptions],\n\t\t\t);\n\n\t\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n\t\t\t\tmemoizedOptions,\n\t\t\t);\n\t\t},\n\n\t\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tmutationOptions?: Omit<\n\t\t\t\tUseMutationOptions<\n\t\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\t\tError,\n\t\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t\t>,\n\t\t\t\t'mutationFn'\n\t\t\t>,\n\t\t) => {\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...mutationOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, fetcher, mutationOptions],\n\t\t\t);\n\n\t\t\treturn useMutation<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tuseInfiniteQuery: <\n\t\t\tT extends QueryEndpoint<Paths>,\n\t\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\t\tTPageParam = unknown,\n\t\t>(\n\t\t\tendpoint: T,\n\t\t\toptions: Omit<\n\t\t\t\tUseInfiniteQueryOptions<\n\t\t\t\t\tTPageData,\n\t\t\t\t\tError,\n\t\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\t\tunknown[],\n\t\t\t\t\tTPageParam\n\t\t\t\t>,\n\t\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t\t> & {\n\t\t\t\tgetNextPageParam: (\n\t\t\t\t\tlastPage: TPageData,\n\t\t\t\t\tallPages: TPageData[],\n\t\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\t\tallPageParams: TPageParam[],\n\t\t\t\t) => TPageParam | undefined;\n\t\t\t\tinitialPageParam: TPageParam;\n\t\t\t},\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: ({\n\t\t\t\t\t\tpageParam,\n\t\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t\t} as any;\n\t\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t\t},\n\t\t\t\t\t...options,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, options],\n\t\t\t);\n\n\t\t\treturn useInfiniteQuery<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\t\t\treturn options.queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\tinvalidateAllQueries: () => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateAllQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn options.queryClient.invalidateQueries();\n\t\t},\n\n\t\tbuildQueryKey,\n\t};\n}\n"],"mappings":";;;;;;;AAwBA,SAAS,cACRA,UACAC,QACY;CACZ,MAAMC,MAAiB,CAAC,QAAS;AAEjC,KAAI,UAAU,YAAY,UAAU,OAAO,OAC1C,KAAI,KAAK,EAAE,QAAQ,OAAO,OAAQ,EAAC;AAGpC,KAAI,UAAU,WAAW,UAAU,OAAO,MACzC,KAAI,KAAK,EAAE,OAAO,OAAO,MAAO,EAAC;AAGlC,QAAO;AACP;;;;;;;;;;;;;;;;AAsID,SAAgB,oBACfC,SACAC,UAAsC,CAAE,GACjB;AACvB,QAAO;EACN,UAAU,CACTJ,UACA,GAAG,SACC;GAEJ,MAAM,CAAC,QAAQ,aAAa,GAAG;GAW/B,MAAM,WAAW,cAAc,UAAU,OAAO;GAEhD,MAAM,kBAAkB,QACvB,OAAO;IACN;IACA,SAAS,MAER,AACC,QAIC,UAAU,OAAO;IACpB,GAAG;GACH,IACD;IAAC;IAAU;IAAQ;IAAS;IAAU;GAAa,EACnD;AAED,UAAO,SACN,gBACA;EACD;EAED,aAAa,CACZA,UACAK,oBAQI;GACJ,MAAM,kBAAkB,QACvB,OAAO;IACN,YAAY,CAACC,WAEZ,AACC,QAIC,UAAU,OAAO;IACpB,GAAG;GACH,IACD;IAAC;IAAU;IAAS;GAAgB,EACpC;AAED,UAAO,YAIL,gBAAgB;EAClB;EAED,kBAAkB,CAKjBN,UACAO,WAkBAN,WACI;GACJ,MAAM,WAAW,cAAc,UAAU,OAAO;GAEhD,MAAM,kBAAkB,QACvB,OAAO;IACN;IACA,SAAS,CAAC,EACT,WAC6C,KAAK;KAClD,IAAI,eAAe;AACnB,SAAI,wBAA2B,QAAQ;MACtC,MAAM,mBACE,cAAc,WAAW,YAAY,EAAE,MAAM,UAAW;AAChE,qBAAe;OACd,GAAG;OACH,OAAO;QAAE,GAAI,OAAe;QAAO,GAAG;OAAW;MACjD;KACD,WAAU,yBAA4B,QAAQ;MAC9C,MAAM,mBACE,cAAc,WAAW,YAAY,EAAE,MAAM,UAAW;AAChE,qBAAe,EAAE,OAAO,UAAW;KACnC;AACD,YAAO,AACN,QAIC,UAAU,aAAa;IACzB;IACD,GAAGO;GACH,IACD;IAAC;IAAU;IAAQ;IAAS;IAAUA;GAAQ,EAC9C;AAED,UAAO,iBAML,gBAAgB;EAClB;EAED,mBAAmB,CAClBR,UACAC,WACI;AACJ,QAAK,QAAQ,YACZ,OAAM,IAAI,MACT;GAGF,MAAM,WAAW,cAAc,UAAU,OAAO;AAChD,UAAO,QAAQ,YAAY,kBAAkB;IAC5C;IACA,SAAS;GACT,EAAC;EACF;EAED,sBAAsB,MAAM;AAC3B,QAAK,QAAQ,YACZ,OAAM,IAAI,MACT;AAGF,UAAO,QAAQ,YAAY,mBAAmB;EAC9C;EAED;CACA;AACD"}
1
+ {"version":3,"file":"endpoint-hooks.mjs","names":[],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseInfiniteQueryResult,\n\tUseMutationOptions,\n\tUseMutationResult,\n\tUseQueryOptions,\n\tUseQueryResult,\n} from '@tanstack/react-query';\nimport { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n\tExtractEndpointResponse,\n\tFilteredRequestConfig,\n\tIsConfigRequired,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n\tconst key: unknown[] = [endpoint];\n\n\tif (config && 'params' in config && config.params) {\n\t\tkey.push({ params: config.params });\n\t}\n\n\tif (config && 'query' in config && config.query) {\n\t\tkey.push({ query: config.query });\n\t}\n\n\treturn key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n\tqueryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n\tPaths,\n\tT\n> extends true\n\t? [\n\t\t\tconfig: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t]\n\t: [\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t\toptions?: Omit<\n\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t>,\n\t\t];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n\t/**\n\t * Use query hook for GET endpoints.\n\t * Config is required when endpoint has path params.\n\t */\n\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\t...args: UseQueryArgs<Paths, T>\n\t) => UseQueryResult<ExtractEndpointResponse<Paths, T>, Error>;\n\n\t/**\n\t * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n\t * Config with params/body is passed to mutate().\n\t */\n\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) => UseMutationResult<\n\t\tExtractEndpointResponse<Paths, T>,\n\t\tError,\n\t\tFilteredRequestConfig<Paths, T>\n\t>;\n\n\t/**\n\t * Use infinite query hook for paginated GET endpoints.\n\t */\n\tuseInfiniteQuery: <\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => UseInfiniteQueryResult<\n\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\tError\n\t>;\n\n\t/**\n\t * Invalidate queries for a specific endpoint.\n\t */\n\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => Promise<void>;\n\n\t/**\n\t * Invalidate all queries in the cache.\n\t */\n\tinvalidateAllQueries: () => Promise<void>;\n\n\t/**\n\t * Build a query key for manual cache operations\n\t */\n\tbuildQueryKey: <T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n\tfetcher: TypedApiFunction<Paths>,\n\toptions: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n\treturn {\n\t\tuseQuery: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\t...args: UseQueryArgs<Paths, T>\n\t\t) => {\n\t\t\t// Parse args - config is first, options is second\n\t\t\tconst [config, queryOptions] = args as [\n\t\t\t\tFilteredRequestConfig<Paths, T> | undefined,\n\t\t\t\t(\n\t\t\t\t\t| Omit<\n\t\t\t\t\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n\t\t\t\t\t\t\t'queryKey' | 'queryFn'\n\t\t\t\t\t >\n\t\t\t\t\t| undefined\n\t\t\t\t),\n\t\t\t];\n\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: () =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...queryOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, queryOptions],\n\t\t\t);\n\n\t\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n\t\t\t\tmemoizedOptions,\n\t\t\t);\n\t\t},\n\n\t\tuseMutation: <T extends MutationEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tmutationOptions?: Omit<\n\t\t\t\tUseMutationOptions<\n\t\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\t\tError,\n\t\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t\t>,\n\t\t\t\t'mutationFn'\n\t\t\t>,\n\t\t) => {\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\t\t// Type assertion needed due to complex conditional types\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, config),\n\t\t\t\t\t...mutationOptions,\n\t\t\t\t}),\n\t\t\t\t[endpoint, fetcher, mutationOptions],\n\t\t\t);\n\n\t\t\treturn useMutation<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tError,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tuseInfiniteQuery: <\n\t\t\tT extends QueryEndpoint<Paths>,\n\t\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\t\tTPageParam = unknown,\n\t\t>(\n\t\t\tendpoint: T,\n\t\t\toptions: Omit<\n\t\t\t\tUseInfiniteQueryOptions<\n\t\t\t\t\tTPageData,\n\t\t\t\t\tError,\n\t\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\t\tunknown[],\n\t\t\t\t\tTPageParam\n\t\t\t\t>,\n\t\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t\t> & {\n\t\t\t\tgetNextPageParam: (\n\t\t\t\t\tlastPage: TPageData,\n\t\t\t\t\tallPages: TPageData[],\n\t\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\t\tallPageParams: TPageParam[],\n\t\t\t\t) => TPageParam | undefined;\n\t\t\t\tinitialPageParam: TPageParam;\n\t\t\t},\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\n\t\t\tconst memoizedOptions = useMemo(\n\t\t\t\t() => ({\n\t\t\t\t\tqueryKey,\n\t\t\t\t\tqueryFn: ({\n\t\t\t\t\t\tpageParam,\n\t\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t\t} as any;\n\t\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tfetcher as (\n\t\t\t\t\t\t\t\tendpoint: T,\n\t\t\t\t\t\t\t\tconfig?: unknown,\n\t\t\t\t\t\t\t) => Promise<ExtractEndpointResponse<Paths, T>>\n\t\t\t\t\t\t)(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t\t},\n\t\t\t\t\t...options,\n\t\t\t\t}),\n\t\t\t\t[endpoint, config, fetcher, queryKey, options],\n\t\t\t);\n\n\t\t\treturn useInfiniteQuery<\n\t\t\t\tTPageData,\n\t\t\t\tError,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>(memoizedOptions);\n\t\t},\n\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst queryKey = buildQueryKey(endpoint, config);\n\t\t\treturn options.queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\tinvalidateAllQueries: () => {\n\t\t\tif (!options.queryClient) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'queryClient is required for invalidateAllQueries. Pass it to createEndpointHooks options.',\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn options.queryClient.invalidateQueries();\n\t\t},\n\n\t\tbuildQueryKey,\n\t};\n}\n"],"mappings":";;;;;;AAwBA,SAAS,cACR,UACA,QACY;CACZ,MAAM,MAAiB,CAAC,QAAQ;CAEhC,IAAI,UAAU,YAAY,UAAU,OAAO,QAC1C,IAAI,KAAK,EAAE,QAAQ,OAAO,OAAO,CAAC;CAGnC,IAAI,UAAU,WAAW,UAAU,OAAO,OACzC,IAAI,KAAK,EAAE,OAAO,OAAO,MAAM,CAAC;CAGjC,OAAO;AACR;;;;;;;;;;;;;;;;AAsIA,SAAgB,oBACf,SACA,UAAsC,CAAC,GAChB;CACvB,OAAO;EACN,WACC,UACA,GAAG,SACC;GAEJ,MAAM,CAAC,QAAQ,gBAAgB;GAW/B,MAAM,WAAW,cAAc,UAAU,MAAM;GAE/C,MAAM,kBAAkB,eAChB;IACN;IACA,eAGE,QAIC,UAAU,MAAM;IACnB,GAAG;GACJ,IACA;IAAC;IAAU;IAAQ;IAAS;IAAU;GAAY,CACnD;GAEA,OAAO,SACN,eACD;EACD;EAEA,cACC,UACA,oBAQI;GACJ,MAAM,kBAAkB,eAChB;IACN,aAAa,WAGX,QAIC,UAAU,MAAM;IACnB,GAAG;GACJ,IACA;IAAC;IAAU;IAAS;GAAe,CACpC;GAEA,OAAO,YAIL,eAAe;EAClB;EAEA,mBAKC,UACA,SAkBA,WACI;GACJ,MAAM,WAAW,cAAc,UAAU,MAAM;GAE/C,MAAM,kBAAkB,eAChB;IACN;IACA,UAAU,EACT,gBACkD;KAClD,IAAI,eAAe;KACnB,IAAI,cAAc,KAAA,KAAa,QAAQ;MACtC,MAAM,YACL,OAAO,cAAc,WAAW,YAAY,EAAE,MAAM,UAAU;MAC/D,eAAe;OACd,GAAG;OACH,OAAO;QAAE,GAAI,OAAe;QAAO,GAAG;OAAU;MACjD;KACD,OAAO,IAAI,cAAc,KAAA,KAAa,CAAC,QAGtC,eAAe,EAAE,OADhB,OAAO,cAAc,WAAW,YAAY,EAAE,MAAM,UAAU,EAC7B;KAEnC,OACC,QAIC,UAAU,YAAY;IACzB;IACA,GAAG;GACJ,IACA;IAAC;IAAU;IAAQ;IAAS;IAAU;GAAO,CAC9C;GAEA,OAAO,iBAML,eAAe;EAClB;EAEA,oBACC,UACA,WACI;GACJ,IAAI,CAAC,QAAQ,aACZ,MAAM,IAAI,MACT,wFACD;GAED,MAAM,WAAW,cAAc,UAAU,MAAM;GAC/C,OAAO,QAAQ,YAAY,kBAAkB;IAC5C;IACA,OAAO,CAAC,CAAC;GACV,CAAC;EACF;EAEA,4BAA4B;GAC3B,IAAI,CAAC,QAAQ,aACZ,MAAM,IAAI,MACT,2FACD;GAED,OAAO,QAAQ,YAAY,kBAAkB;EAC9C;EAEA;CACD;AACD"}
package/dist/fetcher.cjs CHANGED
@@ -1,4 +1,112 @@
1
- const require_fetcher = require('./fetcher-CwnSqc4D.cjs');
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
+ let qs = require("qs");
26
+ qs = __toESM(qs, 1);
27
+ //#region src/fetcher.ts
28
+ var TypedFetcher = class TypedFetcher {
29
+ baseURL;
30
+ defaultHeaders;
31
+ options;
32
+ fetchFn;
33
+ static getFetchFn(fn) {
34
+ if (fn) return fn;
35
+ if (typeof window !== "undefined" && typeof window.fetch === "function") return window.fetch.bind(window);
36
+ if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") return globalThis.fetch.bind(globalThis);
37
+ throw new Error("No fetch implementation found");
38
+ }
39
+ constructor(options = {}) {
40
+ this.baseURL = options.baseURL || "";
41
+ this.defaultHeaders = options.headers || {};
42
+ this.options = options;
43
+ this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
44
+ }
45
+ async request(endpoint, config) {
46
+ const { method, route } = this.parseEndpoint(endpoint);
47
+ let url = route;
48
+ if (config && "params" in config && config.params) Object.entries(config.params).forEach(([key, value]) => {
49
+ url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
50
+ });
51
+ if (config && "query" in config && config.query) {
52
+ const queryString = qs.default.stringify(config.query, {
53
+ encode: true,
54
+ arrayFormat: "brackets",
55
+ skipNulls: true
56
+ });
57
+ if (queryString) url += `?${queryString}`;
58
+ }
59
+ let requestConfig = {
60
+ method: method.toUpperCase(),
61
+ headers: {
62
+ ...this.defaultHeaders,
63
+ ...config && "headers" in config && config.headers || {}
64
+ }
65
+ };
66
+ if (config && "body" in config && config.body) {
67
+ requestConfig.body = JSON.stringify(config.body);
68
+ requestConfig.headers = {
69
+ ...requestConfig.headers,
70
+ "Content-Type": "application/json"
71
+ };
72
+ }
73
+ if (this.options.onRequest) requestConfig = await this.options.onRequest(requestConfig);
74
+ try {
75
+ let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
76
+ if (this.options.onResponse) response = await this.options.onResponse(response);
77
+ if (!response.ok) throw response;
78
+ if (response.status === 204 || response.headers.get("content-length") === "0") return;
79
+ return await response.json();
80
+ } catch (error) {
81
+ if (this.options.onError) await this.options.onError(error);
82
+ throw error;
83
+ }
84
+ }
85
+ wrap(onError) {
86
+ return (endpoint, config) => this.request(endpoint, config).then((data) => ({
87
+ ok: true,
88
+ data
89
+ }), async (error) => ({
90
+ ok: false,
91
+ error: onError ? await onError(error) : error
92
+ }));
93
+ }
94
+ parseEndpoint(endpoint) {
95
+ const [method, ...routeParts] = endpoint.split(" ");
96
+ const route = routeParts.join(" ");
97
+ return {
98
+ method: method?.toLowerCase() ?? "",
99
+ route
100
+ };
101
+ }
102
+ };
103
+ function createTypedFetcher(options) {
104
+ const fetcher = new TypedFetcher(options);
105
+ const fn = (endpoint, config) => fetcher.request(endpoint, config);
106
+ return Object.assign(fn, require_methods.methodCalls(fn), { wrap: (onError) => Object.assign(fetcher.wrap(onError), fn, { wrap: void 0 }) });
107
+ }
108
+ //#endregion
109
+ exports.TypedFetcher = TypedFetcher;
110
+ exports.createTypedFetcher = createTypedFetcher;
2
111
 
3
- exports.TypedFetcher = require_fetcher.TypedFetcher;
4
- exports.createTypedFetcher = require_fetcher.createTypedFetcher;
112
+ //# sourceMappingURL=fetcher.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.cjs","names":["methodCalls"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport { methodCalls } from './methods';\nimport type {\n\tEndpointString,\n\tErrorTransformer,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedApiFunction,\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, methodCalls<Paths>(fn as TypedApiFunction<Paths>), {\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,IAAa,eAAb,MAAa,aAAoB;CAChC;CACA;CACA;CACA;CAEA,OAAO,WAAW,IAAuB;EACxC,IAAI,IACH,OAAO;EAGR,IAAI,OAAO,WAAW,eAAe,OAAO,OAAO,UAAU,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xE,IAAI,KAAK,QAAQ,YAChB,WAAW,MAAM,KAAK,QAAQ,WAAW,QAAQ;GAIlD,IAAI,CAAC,SAAS,IACb,MAAM;GAIP,IACC,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,gBAAgB,MAAM,KAE3C;GAKD,OAAO,MADY,SAAS,KAAK;EAElC,SAAS,OAAO;GAEf,IAAI,KAAK,QAAQ,SAEhB,MAAM,KAAK,QAAQ,QAAQ,KAAK;GAEjC,MAAM;EACP;CACD;CAEA,KAAkB,SAA+B;EAChD,QACC,UACA,WAEA,KAAK,QAAQ,UAAU,MAAM,CAAC,CAAC,MAC7B,UAAU;GAAE,IAAI;GAAe;EAAK,IACrC,OAAO,WAAW;GACjB,IAAI;GACJ,OAAO,UAAU,MAAM,QAAQ,KAAK,IAAK;EAC1C,EACD;CACF;CAEA,cACC,UACmB;EACnB,MAAM,CAAC,QAAQ,GAAG,cAAc,SAAS,MAAM,GAAG;EAClD,MAAM,QAAQ,WAAW,KAAK,GAAG;EACjC,OAAO;GAAE,QAAQ,QAAQ,YAAY,KAAK;GAAI;EAAM;CACrD;AACD;AAEA,SAAgB,mBAA0B,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB,OAAO;CAC/C,MAAM,MACL,UACA,WACI,QAAQ,QAAQ,UAAU,MAAM;CAErC,OAAO,OAAO,OAAO,IAAIA,gBAAAA,YAAmB,EAA6B,GAAG,EAC3E,OAAoB,YACnB,OAAO,OAAO,QAAQ,KAAK,OAAO,GAAG,IAAI,EACxC,MAAM,KAAA,EACP,CAAC,EACH,CAAC;AACF"}
@@ -1,3 +1,23 @@
1
- import { FetcherOptions, WrappedResult } from "./types-DMQMHePI.cjs";
2
- import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher-cDrfwN-Y.cjs";
3
- export { FetchFn, FetcherOptions, TypedFetcher, WrappedResult, createTypedFetcher };
1
+ import { ErrorTransformer, ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types.cjs";
2
+ import { MethodCalls } from "./methods.cjs";
3
+ //#region src/fetcher.d.ts
4
+ export 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
+ export declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & MethodCalls<Paths> & {
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
+ export type FetchFn = typeof fetch;
21
+ //#endregion
22
+ export type { FetcherOptions, WrappedResult };
23
+ //# sourceMappingURL=fetcher.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.cts","names":["_$__methods0.MethodCalls"],"sources":["../src/fetcher.ts"],"mappings":";;;qBAgBa,aAAa;UACjB;UACA;UACA;UACA;SAED,WAAW,KAAK,UAAU;EAmBjC,YAAY,UAAS;EAOf,QAAQ,UAAU,cAAc,QACrC,UAAU,GACV,SAAS,sBAAsB,OAAO,KACpC,QAAQ,wBAAwB,OAAO;EAmF1C,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"}