katanakit-js 5.2.0 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -26
- package/dist/adapters/angular/fetch.js +1 -1
- package/dist/adapters/angular/fetch.js.map +1 -1
- package/dist/adapters/bun/dummyjson.service.d.ts +28 -5
- package/dist/adapters/bun/dummyjson.service.d.ts.map +1 -1
- package/dist/adapters/bun/dummyjson.service.js +22 -18
- package/dist/adapters/bun/dummyjson.service.js.map +1 -1
- package/dist/adapters/bun/main.js +3 -2
- package/dist/adapters/bun/main.js.map +1 -1
- package/dist/adapters/bun/server.d.ts +3 -2
- package/dist/adapters/bun/server.d.ts.map +1 -1
- package/dist/adapters/bun/server.js +3 -2
- package/dist/adapters/bun/server.js.map +1 -1
- package/dist/adapters/insforge/index.d.ts +1 -1
- package/dist/adapters/insforge/index.d.ts.map +1 -1
- package/dist/adapters/insforge/index.js +1 -1
- package/dist/adapters/insforge/index.js.map +1 -1
- package/dist/adapters/insforge/insforge.service.d.ts +32 -1
- package/dist/adapters/insforge/insforge.service.d.ts.map +1 -1
- package/dist/adapters/insforge/insforge.service.js +38 -1
- package/dist/adapters/insforge/insforge.service.js.map +1 -1
- package/dist/adapters/notion/index.d.ts +1 -1
- package/dist/adapters/notion/index.d.ts.map +1 -1
- package/dist/adapters/notion/index.js +1 -1
- package/dist/adapters/notion/index.js.map +1 -1
- package/dist/adapters/notion/notion.service.d.ts +30 -1
- package/dist/adapters/notion/notion.service.d.ts.map +1 -1
- package/dist/adapters/notion/notion.service.js +36 -1
- package/dist/adapters/notion/notion.service.js.map +1 -1
- package/dist/adapters/react/fetch.js +1 -1
- package/dist/adapters/react/fetch.js.map +1 -1
- package/dist/adapters/solid/fetch.js +1 -1
- package/dist/adapters/solid/fetch.js.map +1 -1
- package/dist/adapters/svelte/fetch.js +1 -1
- package/dist/adapters/svelte/fetch.js.map +1 -1
- package/dist/adapters/telegram/index.d.ts +1 -1
- package/dist/adapters/telegram/index.d.ts.map +1 -1
- package/dist/adapters/telegram/index.js +1 -1
- package/dist/adapters/telegram/index.js.map +1 -1
- package/dist/adapters/telegram/telegram.service.d.ts +25 -1
- package/dist/adapters/telegram/telegram.service.d.ts.map +1 -1
- package/dist/adapters/telegram/telegram.service.js +28 -1
- package/dist/adapters/telegram/telegram.service.js.map +1 -1
- package/dist/adapters/vue/vue.service.js +1 -1
- package/dist/adapters/vue/vue.service.js.map +1 -1
- package/dist/adapters/whatsapp/index.d.ts +1 -1
- package/dist/adapters/whatsapp/index.d.ts.map +1 -1
- package/dist/adapters/whatsapp/index.js +1 -1
- package/dist/adapters/whatsapp/index.js.map +1 -1
- package/dist/adapters/whatsapp/whatsapp.service.d.ts +30 -1
- package/dist/adapters/whatsapp/whatsapp.service.d.ts.map +1 -1
- package/dist/adapters/whatsapp/whatsapp.service.js +33 -1
- package/dist/adapters/whatsapp/whatsapp.service.js.map +1 -1
- package/dist/adapters/wordpress/index.d.ts +1 -1
- package/dist/adapters/wordpress/index.d.ts.map +1 -1
- package/dist/adapters/wordpress/index.js +1 -1
- package/dist/adapters/wordpress/index.js.map +1 -1
- package/dist/adapters/wordpress/wordpress.service.d.ts +34 -1
- package/dist/adapters/wordpress/wordpress.service.d.ts.map +1 -1
- package/dist/adapters/wordpress/wordpress.service.js +40 -1
- package/dist/adapters/wordpress/wordpress.service.js.map +1 -1
- package/dist/core/services/http.service.d.ts +85 -35
- package/dist/core/services/http.service.d.ts.map +1 -1
- package/dist/core/services/http.service.js +168 -49
- package/dist/core/services/http.service.js.map +1 -1
- package/dist/core/services/query.service.d.ts +1 -1
- package/dist/core/services/query.service.js +1 -1
- package/dist/core/services/utils.service.d.ts +27 -0
- package/dist/core/services/utils.service.d.ts.map +1 -1
- package/dist/core/services/utils.service.js +37 -0
- package/dist/core/services/utils.service.js.map +1 -1
- package/dist/types/index.d.ts +95 -4
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -9
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { useTryJsonParse } from "./result.service.js";
|
|
2
|
+
import { useSplitConfig } from "./utils.service.js";
|
|
2
3
|
/** Module-level API registry. */
|
|
3
4
|
let apis = {};
|
|
5
|
+
/**
|
|
6
|
+
* Internal: narrows an unknown literal entry to an {@link ApiEntry}.
|
|
7
|
+
*
|
|
8
|
+
* @param value - A non-method value from a `defineApiConfig` literal.
|
|
9
|
+
* @returns `true` when the value looks like a registered API entry.
|
|
10
|
+
*/
|
|
11
|
+
function isApiEntry(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && "baseUri" in value && "endpoints" in value;
|
|
13
|
+
}
|
|
4
14
|
/**
|
|
5
15
|
* Internal: retrieves a registered API entry or throws.
|
|
6
16
|
*
|
|
@@ -61,9 +71,59 @@ function serializeBody(body) {
|
|
|
61
71
|
body: JSON.stringify(body),
|
|
62
72
|
};
|
|
63
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Declares the API registry in a single call — the config-file entry point.
|
|
76
|
+
*
|
|
77
|
+
* Registers every {@link ApiEntry} you list and returns them alongside the
|
|
78
|
+
* props, flags and methods declared on the same literal, so one `export default`
|
|
79
|
+
* is the whole setup: no second `useInitApis(...)` step.
|
|
80
|
+
*
|
|
81
|
+
* Only object entries shaped like `{ baseUri, endpoints }` reach the registry;
|
|
82
|
+
* boolean flags are kept on `config` for your own methods to read.
|
|
83
|
+
*
|
|
84
|
+
* @typeParam T - The literal passed in.
|
|
85
|
+
* @param input - API entries, flags and methods in one object literal.
|
|
86
|
+
* @returns The registered config plus the declared methods (see {@link ConfigFacade}).
|
|
87
|
+
* @throws {Error} If a non-method value is an object that is not an API entry.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { defineApiConfig } from "katanakit-js";
|
|
92
|
+
*
|
|
93
|
+
* export default defineApiConfig({
|
|
94
|
+
* pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { byId: "/pokemon/:id/" } },
|
|
95
|
+
* debug: true,
|
|
96
|
+
* getPokemon: async function () {
|
|
97
|
+
* return useFetch("pokeapi", "byId", { params: { id: 25 } });
|
|
98
|
+
* },
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @remarks Methods must be written with `function`, not as arrows — `this.config`
|
|
103
|
+
* is undefined inside an arrow function.
|
|
104
|
+
*/
|
|
105
|
+
export function defineApiConfig(input) {
|
|
106
|
+
const { config, methods } = useSplitConfig(input);
|
|
107
|
+
const registered = {};
|
|
108
|
+
for (const [name, value] of Object.entries(config)) {
|
|
109
|
+
if (isApiEntry(value)) {
|
|
110
|
+
registered[name] = value;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (typeof value === "object" && value !== null) {
|
|
114
|
+
throw new Error(`[FetchApiManager] defineApiConfig: "${name}" is not an API entry ` +
|
|
115
|
+
`(expected an object with baseUri and endpoints).`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
useInitApis(registered);
|
|
119
|
+
// `methods` is a generic spread, so TS cannot prove the exact facade shape.
|
|
120
|
+
return { config, ...methods };
|
|
121
|
+
}
|
|
64
122
|
/**
|
|
65
123
|
* Registers (merges) API definitions into the client registry.
|
|
66
|
-
*
|
|
124
|
+
*
|
|
125
|
+
* @deprecated Use {@link defineApiConfig}, which registers the config and
|
|
126
|
+
* returns it with any methods declared on the same literal.
|
|
67
127
|
*
|
|
68
128
|
* @param apisConfig - The API definitions to merge into the registry.
|
|
69
129
|
*
|
|
@@ -85,6 +145,9 @@ export function useInit(apisConfig) {
|
|
|
85
145
|
/**
|
|
86
146
|
* Registers (merges) API definitions into the client registry.
|
|
87
147
|
*
|
|
148
|
+
* @deprecated Use {@link defineApiConfig}, which registers the config and
|
|
149
|
+
* returns it with any methods declared on the same literal.
|
|
150
|
+
*
|
|
88
151
|
* @param apisConfig - The API definitions to merge into the registry.
|
|
89
152
|
*
|
|
90
153
|
* @example
|
|
@@ -134,41 +197,42 @@ export function useGetApisConfig() {
|
|
|
134
197
|
return useGetApis();
|
|
135
198
|
}
|
|
136
199
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* -
|
|
146
|
-
* -
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @param
|
|
151
|
-
* @
|
|
152
|
-
* @
|
|
200
|
+
* Returns the URL of a registered endpoint **without calling `fetch`**.
|
|
201
|
+
*
|
|
202
|
+
* It builds the same URL {@link useFetch} would request — same registry, same
|
|
203
|
+
* `:param` substitution, same `query` merge with `defaultQueryParams`, same
|
|
204
|
+
* http(s) guard — then stops and hands you the string.
|
|
205
|
+
*
|
|
206
|
+
* Use it when you need the **address**, not the response:
|
|
207
|
+
*
|
|
208
|
+
* - `<a href>` / `<img src>` — links and media built from an endpoint name
|
|
209
|
+
* - libraries that fetch on their own (charts, maps, analytics)
|
|
210
|
+
* - logging the exact URL you are about to request
|
|
211
|
+
* - SSR / prerender, where nothing should be requested
|
|
212
|
+
*
|
|
213
|
+
* @param apiName - Registered API key (from {@link defineApiConfig}).
|
|
214
|
+
* @param endpointName - Endpoint key inside that API.
|
|
215
|
+
* @param options - `params` fills `:placeholders`, `query` becomes the search string.
|
|
216
|
+
* @returns The fully built URL.
|
|
217
|
+
* @throws {Error} Unknown API, unknown endpoint, or a scheme that is not http(s).
|
|
153
218
|
*
|
|
154
219
|
* @example
|
|
155
220
|
* ```ts
|
|
156
221
|
* import { useBuildUrl } from "katanakit-js";
|
|
157
222
|
*
|
|
158
|
-
*
|
|
159
|
-
* const url = useBuildUrl("pokeapi", "pokemonById", { params: { id: 25 } });
|
|
223
|
+
* useBuildUrl("pokeapi", "pokemonById", { params: { id: 25 } });
|
|
160
224
|
* // → "https://pokeapi.co/api/v2/pokemon/25"
|
|
161
225
|
*
|
|
162
|
-
*
|
|
163
|
-
* const download = useBuildUrl("myApi", "export", { query: { format: "pdf" } });
|
|
226
|
+
* useBuildUrl("myApi", "export", { query: { format: "pdf" } });
|
|
164
227
|
* // → "https://api.myapp.com/v1/export?format=pdf"
|
|
165
228
|
*
|
|
166
|
-
* // Use in a template
|
|
167
229
|
* <a href={useBuildUrl("myApi", "download", { params: { id: 42 } })}>Download</a>
|
|
168
|
-
*
|
|
169
|
-
* // Debug before fetching
|
|
170
|
-
* console.log("Will fetch:", useBuildUrl("myApi", "users", { query: { page: 1 } }));
|
|
171
230
|
* ```
|
|
231
|
+
*
|
|
232
|
+
* @remarks Synchronous, so it **throws** instead of returning a Safe Result —
|
|
233
|
+
* Safe Result covers fallible async work, and this never leaves the process.
|
|
234
|
+
* To see the URL a request actually used, read `result.url` off a `useFetch`
|
|
235
|
+
* result instead.
|
|
172
236
|
*/
|
|
173
237
|
export function useBuildUrl(apiName, endpointName, options = {}) {
|
|
174
238
|
const { params, query, ignoreDefaultQuery = false } = options;
|
|
@@ -200,7 +264,9 @@ export function useBuildUrl(apiName, endpointName, options = {}) {
|
|
|
200
264
|
}
|
|
201
265
|
/**
|
|
202
266
|
* Builds a safe http(s) URL from a registered API + endpoint.
|
|
203
|
-
*
|
|
267
|
+
*
|
|
268
|
+
* @deprecated Use {@link useBuildUrl}. This is a behaviourally identical wrapper around it and
|
|
269
|
+
* exists only for backwards compatibility — scheduled for removal in the next major.
|
|
204
270
|
*
|
|
205
271
|
* @param apiName - The registered API key.
|
|
206
272
|
* @param endpointName - The endpoint key within the API.
|
|
@@ -217,29 +283,70 @@ export function useBuildUrl(apiName, endpointName, options = {}) {
|
|
|
217
283
|
export function useBuildApiUrl(apiName, endpointName, options = {}) {
|
|
218
284
|
return useBuildUrl(apiName, endpointName, options);
|
|
219
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Picks the URL-building keys out of an options bag so nothing else leaks into
|
|
288
|
+
* the `RequestInit` handed to `fetch`.
|
|
289
|
+
*
|
|
290
|
+
* `useGet`/`usePost`/… accept `UrlOptions`, but JS callers can stuff arbitrary
|
|
291
|
+
* keys in there; spreading the whole bag would let a stray `method`, `headers`
|
|
292
|
+
* or `body` silently override what the wrapper already set.
|
|
293
|
+
*
|
|
294
|
+
* @param urlOptions - Legacy URL options, if any.
|
|
295
|
+
* @returns Only `params`, `query` and `ignoreDefaultQuery`, when defined.
|
|
296
|
+
*/
|
|
297
|
+
function pickUrl(urlOptions) {
|
|
298
|
+
if (!urlOptions)
|
|
299
|
+
return {};
|
|
300
|
+
const { params, query, ignoreDefaultQuery } = urlOptions;
|
|
301
|
+
return {
|
|
302
|
+
...(params !== undefined && { params }),
|
|
303
|
+
...(query !== undefined && { query }),
|
|
304
|
+
...(ignoreDefaultQuery !== undefined && { ignoreDefaultQuery }),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
220
307
|
/**
|
|
221
308
|
* Fetches a registered endpoint and returns a Safe Result.
|
|
222
309
|
*
|
|
310
|
+
* URL options sit at the top level, next to `method`/`headers`/`body` — no
|
|
311
|
+
* nesting, same shape as `useGet` and Nuxt's `useFetch`.
|
|
312
|
+
*
|
|
223
313
|
* @param apiName - The registered API key.
|
|
224
314
|
* @param endpointName - The endpoint key within the API.
|
|
225
|
-
* @param options -
|
|
226
|
-
* @returns A {@link FetchResult} with data or error.
|
|
315
|
+
* @param options - Fetch options: `params`, `query`, `transform` and any `RequestInit` field.
|
|
316
|
+
* @returns A {@link FetchResult} with data or error. Never throws — a failing
|
|
317
|
+
* `transform` comes back as an error result too.
|
|
227
318
|
*
|
|
228
319
|
* @example
|
|
229
320
|
* ```ts
|
|
230
321
|
* import { useFetch } from "katanakit-js";
|
|
231
322
|
*
|
|
232
|
-
* const result = await useFetch("pokeapi", "
|
|
323
|
+
* const result = await useFetch<{ results: unknown[] }>("pokeapi", "pokemons", {
|
|
233
324
|
* method: "GET",
|
|
234
|
-
*
|
|
325
|
+
* query: { limit: 2 },
|
|
326
|
+
* transform: (body) => ({ results: (body as { results: unknown[] }).results }),
|
|
235
327
|
* });
|
|
236
|
-
* if (result.ok) console.log(result.data);
|
|
328
|
+
* if (result.ok) console.log(result.data.results);
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @example Legacy nested form (deprecated)
|
|
332
|
+
* ```ts
|
|
333
|
+
* useFetch("pokeapi", "pokemonById", { urlOptions: { params: { id: 25 } } });
|
|
237
334
|
* ```
|
|
238
335
|
*/
|
|
239
|
-
export async function useFetch(apiName, endpointName, { urlOptions, ...init } = {}) {
|
|
336
|
+
export async function useFetch(apiName, endpointName, { params, query, ignoreDefaultQuery, urlOptions, transform, ...init } = {}) {
|
|
240
337
|
let url = "";
|
|
338
|
+
// The flat keys and the deprecated `urlOptions` nest describe the same
|
|
339
|
+
// thing; the flat form wins. `undefined` means "not given", so it must not
|
|
340
|
+
// overwrite a value coming from the legacy nest.
|
|
341
|
+
const buildOptions = { ...urlOptions };
|
|
342
|
+
if (params !== undefined)
|
|
343
|
+
buildOptions.params = params;
|
|
344
|
+
if (query !== undefined)
|
|
345
|
+
buildOptions.query = query;
|
|
346
|
+
if (ignoreDefaultQuery !== undefined)
|
|
347
|
+
buildOptions.ignoreDefaultQuery = ignoreDefaultQuery;
|
|
241
348
|
try {
|
|
242
|
-
url = useBuildUrl(apiName, endpointName,
|
|
349
|
+
url = useBuildUrl(apiName, endpointName, buildOptions);
|
|
243
350
|
}
|
|
244
351
|
catch (err) {
|
|
245
352
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -274,18 +381,30 @@ export async function useFetch(apiName, endpointName, { urlOptions, ...init } =
|
|
|
274
381
|
};
|
|
275
382
|
}
|
|
276
383
|
// 204 No Content and empty bodies are valid success responses.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
384
|
+
const body = response.status === 204 ? null : await readBody(response);
|
|
385
|
+
let data = body;
|
|
386
|
+
if (transform) {
|
|
387
|
+
try {
|
|
388
|
+
data = await transform(body);
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
// A failing transform is still a failed request — return it as a
|
|
392
|
+
// Safe Result instead of letting it escape `useFetch`.
|
|
393
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
394
|
+
return {
|
|
395
|
+
data: null,
|
|
396
|
+
error: {
|
|
397
|
+
message: `Transform Error: ${message}`,
|
|
398
|
+
status: response.status,
|
|
399
|
+
},
|
|
400
|
+
url: response.url || url,
|
|
401
|
+
status: response.status,
|
|
402
|
+
ok: false,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
285
405
|
}
|
|
286
|
-
const body = await readBody(response);
|
|
287
406
|
return {
|
|
288
|
-
data:
|
|
407
|
+
data: data,
|
|
289
408
|
error: null,
|
|
290
409
|
url: response.url || url,
|
|
291
410
|
status: response.status,
|
|
@@ -321,7 +440,7 @@ export async function useFetch(apiName, endpointName, { urlOptions, ...init } =
|
|
|
321
440
|
*
|
|
322
441
|
* const result = await useFetchApi("pokeapi", "pokemonById", {
|
|
323
442
|
* method: "GET",
|
|
324
|
-
*
|
|
443
|
+
* params: { id: 25 },
|
|
325
444
|
* });
|
|
326
445
|
* if (result.ok) console.log(result.data);
|
|
327
446
|
* ```
|
|
@@ -347,7 +466,7 @@ export async function useFetchApi(apiName, endpointName, options) {
|
|
|
347
466
|
* ```
|
|
348
467
|
*/
|
|
349
468
|
export async function useGet(apiName, endpointName, urlOptions) {
|
|
350
|
-
return useFetch(apiName, endpointName, { method: "GET", urlOptions });
|
|
469
|
+
return useFetch(apiName, endpointName, { method: "GET", ...pickUrl(urlOptions) });
|
|
351
470
|
}
|
|
352
471
|
/**
|
|
353
472
|
* GET helper over a registered API endpoint.
|
|
@@ -390,7 +509,7 @@ export async function usePost(apiName, endpointName, body, urlOptions) {
|
|
|
390
509
|
return useFetch(apiName, endpointName, {
|
|
391
510
|
method: "POST",
|
|
392
511
|
...serializeBody(body),
|
|
393
|
-
urlOptions,
|
|
512
|
+
...pickUrl(urlOptions),
|
|
394
513
|
});
|
|
395
514
|
}
|
|
396
515
|
/**
|
|
@@ -413,7 +532,7 @@ export async function usePut(apiName, endpointName, body, urlOptions) {
|
|
|
413
532
|
return useFetch(apiName, endpointName, {
|
|
414
533
|
method: "PUT",
|
|
415
534
|
...serializeBody(body),
|
|
416
|
-
urlOptions,
|
|
535
|
+
...pickUrl(urlOptions),
|
|
417
536
|
});
|
|
418
537
|
}
|
|
419
538
|
/**
|
|
@@ -436,7 +555,7 @@ export async function usePatch(apiName, endpointName, body, urlOptions) {
|
|
|
436
555
|
return useFetch(apiName, endpointName, {
|
|
437
556
|
method: "PATCH",
|
|
438
557
|
...serializeBody(body),
|
|
439
|
-
urlOptions,
|
|
558
|
+
...pickUrl(urlOptions),
|
|
440
559
|
});
|
|
441
560
|
}
|
|
442
561
|
/**
|
|
@@ -457,7 +576,7 @@ export async function usePatch(apiName, endpointName, body, urlOptions) {
|
|
|
457
576
|
export async function useDelete(apiName, endpointName, urlOptions) {
|
|
458
577
|
return useFetch(apiName, endpointName, {
|
|
459
578
|
method: "DELETE",
|
|
460
|
-
urlOptions,
|
|
579
|
+
...pickUrl(urlOptions),
|
|
461
580
|
});
|
|
462
581
|
}
|
|
463
582
|
//# sourceMappingURL=http.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.service.js","sourceRoot":"","sources":["../../../src/core/services/http.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.service.js","sourceRoot":"","sources":["../../../src/core/services/http.service.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,iCAAiC;AACjC,IAAI,IAAI,GAAe,EAAE,CAAC;AAE1B;;;;;GAKG;AACH,SAAS,UAAU,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAA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;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,OAAe,EACf,YAAoB,EACpB,IAAc,EACd,UAAuB;IAEvB,OAAO,QAAQ,CAAI,OAAO,EAAE,YAAY,EAAE;QACzC,MAAM,EAAE,OAAO;QACf,GAAG,aAAa,CAAC,IAAI,CAAC;QACtB,GAAG,OAAO,CAAC,UAAU,CAAC;KACtB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,OAAe,EACf,YAAoB,EACpB,UAAuB;IAEvB,OAAO,QAAQ,CAAI,OAAO,EAAE,YAAY,EAAE;QACzC,MAAM,EAAE,QAAQ;QAChB,GAAG,OAAO,CAAC,UAAU,CAAC;KACtB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -85,7 +85,7 @@ export declare function useInitQueryClient(config?: QueryClientConfig): QueryCli
|
|
|
85
85
|
*
|
|
86
86
|
* // With cancellation: forward TanStack's AbortSignal into the request.
|
|
87
87
|
* queryFn: useSafeQueryFn(({ signal }) =>
|
|
88
|
-
* useFetch("pokeapi", "pokemonById", { method: "GET",
|
|
88
|
+
* useFetch("pokeapi", "pokemonById", { method: "GET", params: { id }, signal }),
|
|
89
89
|
* )
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
@@ -94,7 +94,7 @@ export function useInitQueryClient(config = {}) {
|
|
|
94
94
|
*
|
|
95
95
|
* // With cancellation: forward TanStack's AbortSignal into the request.
|
|
96
96
|
* queryFn: useSafeQueryFn(({ signal }) =>
|
|
97
|
-
* useFetch("pokeapi", "pokemonById", { method: "GET",
|
|
97
|
+
* useFetch("pokeapi", "pokemonById", { method: "GET", params: { id }, signal }),
|
|
98
98
|
* )
|
|
99
99
|
* ```
|
|
100
100
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConfigData, ConfigMethodEntries } from "../../types/index.js";
|
|
1
2
|
/**
|
|
2
3
|
* Returns a new array with duplicate values removed, preserving first-seen order.
|
|
3
4
|
*
|
|
@@ -226,4 +227,30 @@ export declare function useRound(value: string | number, decimals?: number): num
|
|
|
226
227
|
* ```
|
|
227
228
|
*/
|
|
228
229
|
export declare function useAverage(numbers: number[]): number;
|
|
230
|
+
/**
|
|
231
|
+
* Splits a `define*Config` literal into its config half (props and booleans)
|
|
232
|
+
* and its method half (values declared with `function`).
|
|
233
|
+
*
|
|
234
|
+
* Shared by every `define*Config` so they all read the same way: register
|
|
235
|
+
* `config`, then return `{ config, ...methods }` as a {@link ConfigFacade}.
|
|
236
|
+
*
|
|
237
|
+
* @typeParam T - The literal passed to a `define*Config` call.
|
|
238
|
+
* @param input - Object literal holding props, booleans and methods.
|
|
239
|
+
* @returns The config entries and the method entries, split apart.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* const { config, methods } = useSplitConfig({
|
|
244
|
+
* token: "abc",
|
|
245
|
+
* debug: true,
|
|
246
|
+
* send: async function () {},
|
|
247
|
+
* });
|
|
248
|
+
* // config → { token: "abc", debug: true }
|
|
249
|
+
* // methods → { send }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare function useSplitConfig<T extends object>(input: T): {
|
|
253
|
+
config: ConfigData<T>;
|
|
254
|
+
methods: ConfigMethodEntries<T>;
|
|
255
|
+
};
|
|
229
256
|
//# sourceMappingURL=utils.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/utils.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAE5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI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AAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAUvE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOzE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM,CAKrE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAIpD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC9C,KAAK,EAAE,CAAC,GACN;IACF,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;CAChC,CAcA"}
|
|
@@ -323,4 +323,41 @@ export function useAverage(numbers) {
|
|
|
323
323
|
const sum = numbers.reduce((acc, n) => acc + n, 0);
|
|
324
324
|
return sum / numbers.length;
|
|
325
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Splits a `define*Config` literal into its config half (props and booleans)
|
|
328
|
+
* and its method half (values declared with `function`).
|
|
329
|
+
*
|
|
330
|
+
* Shared by every `define*Config` so they all read the same way: register
|
|
331
|
+
* `config`, then return `{ config, ...methods }` as a {@link ConfigFacade}.
|
|
332
|
+
*
|
|
333
|
+
* @typeParam T - The literal passed to a `define*Config` call.
|
|
334
|
+
* @param input - Object literal holding props, booleans and methods.
|
|
335
|
+
* @returns The config entries and the method entries, split apart.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* const { config, methods } = useSplitConfig({
|
|
340
|
+
* token: "abc",
|
|
341
|
+
* debug: true,
|
|
342
|
+
* send: async function () {},
|
|
343
|
+
* });
|
|
344
|
+
* // config → { token: "abc", debug: true }
|
|
345
|
+
* // methods → { send }
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export function useSplitConfig(input) {
|
|
349
|
+
const config = {};
|
|
350
|
+
const methods = {};
|
|
351
|
+
for (const [key, value] of Object.entries(input)) {
|
|
352
|
+
if (typeof value === "function")
|
|
353
|
+
methods[key] = value;
|
|
354
|
+
else
|
|
355
|
+
config[key] = value;
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
// The split is structural, so TS cannot relate either half back to `T`.
|
|
359
|
+
config: config,
|
|
360
|
+
methods: methods,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
326
363
|
//# sourceMappingURL=utils.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.service.js","sourceRoot":"","sources":["../../../src/core/services/utils.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.service.js","sourceRoot":"","sources":["../../../src/core/services/utils.service.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAI,KAAU;IACtC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAI,KAAU,EAAE,IAAY;IACnD,IAAI,IAAI,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACpE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACtE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CACtC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqB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;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;;YACjD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,OAAO;QACN,wEAAwE;QACxE,MAAM,EAAE,MAAuB;QAC/B,OAAO,EAAE,OAAiC;KAC1C,CAAC;AACH,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -139,9 +139,38 @@ export interface ApiEntry {
|
|
|
139
139
|
defaultQueryParams?: Record<string, QueryParams>;
|
|
140
140
|
}
|
|
141
141
|
export type ApisConfig = Record<string, ApiEntry>;
|
|
142
|
-
/**
|
|
143
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Options passed when executing a fetch request.
|
|
144
|
+
*
|
|
145
|
+
* URL building lives **at the top level** — the same shape as `useGet`,
|
|
146
|
+
* `useRequest` and Nuxt's `useFetch` — so nothing has to be nested:
|
|
147
|
+
*
|
|
148
|
+
* ```ts
|
|
149
|
+
* useFetch("api", "byId", { method: "GET", params: { id: 25 }, query: { limit: 2 } });
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @typeParam T - The type {@link FetchOptions.transform} resolves to. Defaults
|
|
153
|
+
* to `any` on purpose: with `unknown` a bare `FetchOptions` (or one stored in
|
|
154
|
+
* a variable / passed through a wrapper) would no longer be assignable to
|
|
155
|
+
* `FetchOptions<T>`, which is a type-level break for existing callers.
|
|
156
|
+
*/
|
|
157
|
+
export interface FetchOptions<T = any> extends RequestInit {
|
|
158
|
+
/** Path params substituted into `:name` placeholders of the endpoint. */
|
|
159
|
+
params?: PathParams;
|
|
160
|
+
/** Query-string params appended to the URL. */
|
|
161
|
+
query?: QueryParams;
|
|
162
|
+
/** Skip the endpoint's `defaultQueryParams` instead of merging them. */
|
|
163
|
+
ignoreDefaultQuery?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Nested form of {@link FetchOptions.params}, {@link FetchOptions.query} and
|
|
166
|
+
* {@link FetchOptions.ignoreDefaultQuery}.
|
|
167
|
+
*
|
|
168
|
+
* @deprecated Pass them at the top level instead. Kept for backwards
|
|
169
|
+
* compatibility and scheduled for removal in the next major.
|
|
170
|
+
*/
|
|
144
171
|
urlOptions?: UrlOptions;
|
|
172
|
+
/** Maps the parsed response body to `T` before it is returned. */
|
|
173
|
+
transform?: (input: unknown) => T | Promise<T>;
|
|
145
174
|
}
|
|
146
175
|
/** Structure of the safe error returned on non-2xx or network failures. */
|
|
147
176
|
export type ApiError = z.infer<typeof ApiErrorSchema>;
|
|
@@ -179,14 +208,17 @@ export type FetchResult<T = unknown> = {
|
|
|
179
208
|
};
|
|
180
209
|
/** Contract of the fetch facade. */
|
|
181
210
|
export interface IFetchApiManager {
|
|
211
|
+
/** @deprecated Use `defineApiConfig`. */
|
|
182
212
|
useInit(apis: ApisConfig): void;
|
|
213
|
+
/** @deprecated Use `defineApiConfig`. */
|
|
183
214
|
useInitApis(apis: ApisConfig): void;
|
|
184
215
|
useGetApis(): ApisConfig;
|
|
185
216
|
useGetApisConfig(): ApisConfig;
|
|
186
217
|
useBuildUrl(apiName: string, endpointName: string, options?: UrlOptions): string;
|
|
218
|
+
/** @deprecated Use `useBuildUrl`. */
|
|
187
219
|
useBuildApiUrl(apiName: string, endpointName: string, options?: UrlOptions): string;
|
|
188
|
-
useFetch<T = unknown>(apiName: string, endpointName: string, options?: FetchOptions): Promise<FetchResult<T>>;
|
|
189
|
-
useFetchApi<T = unknown>(apiName: string, endpointName: string, options?: FetchOptions): Promise<FetchResult<T>>;
|
|
220
|
+
useFetch<T = unknown>(apiName: string, endpointName: string, options?: FetchOptions<T>): Promise<FetchResult<T>>;
|
|
221
|
+
useFetchApi<T = unknown>(apiName: string, endpointName: string, options?: FetchOptions<T>): Promise<FetchResult<T>>;
|
|
190
222
|
useGet<T = unknown>(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise<FetchResult<T>>;
|
|
191
223
|
useGetApi<T = unknown>(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise<FetchResult<T>>;
|
|
192
224
|
usePost<T = unknown>(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise<FetchResult<T>>;
|
|
@@ -596,6 +628,7 @@ export type NotionSearchQuery = z.infer<typeof NotionSearchQuerySchema>;
|
|
|
596
628
|
export type NotionSearchResult = z.infer<typeof NotionSearchResultSchema>;
|
|
597
629
|
/** Contract of the Notion adapter facade. */
|
|
598
630
|
export interface INotionService {
|
|
631
|
+
/** @deprecated Use `defineNotionConfig`. */
|
|
599
632
|
useInitNotion(config: NotionConfig): void;
|
|
600
633
|
useNotionGetPage(pageId: string): Promise<FetchResult<NotionPage>>;
|
|
601
634
|
useNotionCreatePage(parent: NotionParent, properties: Record<string, unknown>, children?: unknown[]): Promise<FetchResult<NotionPage>>;
|
|
@@ -718,6 +751,7 @@ export type WpBatchOperation = z.infer<typeof WpBatchOperationSchema>;
|
|
|
718
751
|
export type WpBatchResult = z.infer<typeof WpBatchResultSchema>;
|
|
719
752
|
/** Contract of the WordPress adapter facade. */
|
|
720
753
|
export interface IWordPressService {
|
|
754
|
+
/** @deprecated Use `defineWordPressConfig`. */
|
|
721
755
|
useInitWordPress(config: WordPressConfig): void;
|
|
722
756
|
useWpGetPosts(options?: WpQueryParams): Promise<FetchResult<WpPost[]>>;
|
|
723
757
|
useWpGetPost(id: number, options?: WpQueryParams): Promise<FetchResult<WpPost>>;
|
|
@@ -815,4 +849,61 @@ export type YoutubeChannelsResponse = z.infer<typeof YoutubeChannelsResponseSche
|
|
|
815
849
|
export type YoutubePlaylistItemsResponse = z.infer<typeof YoutubePlaylistItemsResponseSchema>;
|
|
816
850
|
/** Minimal `videos.list` shape (only what the service reads). */
|
|
817
851
|
export type YoutubeVideosResponse = z.infer<typeof YoutubeVideosResponseSchema>;
|
|
852
|
+
/**
|
|
853
|
+
* Any method a consumer declares inline in a `define*Config` literal.
|
|
854
|
+
* Written with `function` (never an arrow) so `this` resolves to the facade.
|
|
855
|
+
*/
|
|
856
|
+
export type ConfigMethod = (...args: never[]) => unknown;
|
|
857
|
+
/**
|
|
858
|
+
* Keys of `T` whose value is a {@link ConfigMethod}. Methods declared as
|
|
859
|
+
* optional are still detected (`NonNullable`), so they are split out of the
|
|
860
|
+
* config half rather than leaking into it.
|
|
861
|
+
*/
|
|
862
|
+
export type ConfigMethodKeys<T> = {
|
|
863
|
+
[K in keyof T]-?: NonNullable<T[K]> extends ConfigMethod ? K : never;
|
|
864
|
+
}[keyof T];
|
|
865
|
+
/** The props/booleans half of a `define*Config` literal — the config data. */
|
|
866
|
+
export type ConfigData<T> = Omit<T, ConfigMethodKeys<T>>;
|
|
867
|
+
/** The methods half of a `define*Config` literal. */
|
|
868
|
+
export type ConfigMethodEntries<T> = Pick<T, ConfigMethodKeys<T>>;
|
|
869
|
+
/**
|
|
870
|
+
* What every `define*Config` returns: the registered config under `config`,
|
|
871
|
+
* plus the methods declared alongside it so `this.config` resolves inside them.
|
|
872
|
+
*
|
|
873
|
+
* @typeParam T - The literal passed to the `define*Config` call.
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```ts
|
|
877
|
+
* const api = defineApiConfig({
|
|
878
|
+
* pokeapi: { baseUri: "…", endpoints: { users: "/users" } },
|
|
879
|
+
* debug: true,
|
|
880
|
+
* getUsers: async function () {
|
|
881
|
+
* return this.config.debug;
|
|
882
|
+
* },
|
|
883
|
+
* });
|
|
884
|
+
*
|
|
885
|
+
* api.config.pokeapi; // ApiEntry
|
|
886
|
+
* await api.getUsers();
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
export type ConfigFacade<T> = {
|
|
890
|
+
/** Props and booleans declared in the literal (methods stripped out). */
|
|
891
|
+
config: ConfigData<T>;
|
|
892
|
+
} & ConfigMethodEntries<T>;
|
|
893
|
+
/**
|
|
894
|
+
* Constrains every non-method entry of a `define*Config` literal to `V`, while
|
|
895
|
+
* leaving method entries untouched. Pair with `NoInfer<T>` in the signature so
|
|
896
|
+
* it validates without stealing inference from the literal.
|
|
897
|
+
*
|
|
898
|
+
* @typeParam T - The literal being validated.
|
|
899
|
+
* @typeParam V - The type every non-method value must satisfy.
|
|
900
|
+
*/
|
|
901
|
+
export type ConfigValues<T, V> = {
|
|
902
|
+
[K in keyof T]: K extends ConfigMethodKeys<T> ? T[K] : V;
|
|
903
|
+
};
|
|
904
|
+
/**
|
|
905
|
+
* Values accepted by {@link defineApiConfig}: an {@link ApiEntry}, a boolean
|
|
906
|
+
* flag (kept on `config` only — never registered as an API) or a method.
|
|
907
|
+
*/
|
|
908
|
+
export type ApiConfigValue = ApiEntry | boolean | ConfigMethod;
|
|
818
909
|
//# sourceMappingURL=index.d.ts.map
|