katanakit-js 5.0.1 → 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 +243 -33
- 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 +3 -0
- package/dist/adapters/insforge/index.d.ts.map +1 -0
- package/dist/adapters/insforge/index.js +2 -0
- package/dist/adapters/insforge/index.js.map +1 -0
- package/dist/adapters/insforge/insforge.service.d.ts +147 -0
- package/dist/adapters/insforge/insforge.service.d.ts.map +1 -0
- package/dist/adapters/insforge/insforge.service.js +474 -0
- package/dist/adapters/insforge/insforge.service.js.map +1 -0
- 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 +107 -54
- 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 +203 -86
- package/dist/adapters/wordpress/wordpress.service.js.map +1 -1
- package/dist/config/seo.service.d.ts.map +1 -1
- package/dist/config/seo.service.js +42 -4
- package/dist/config/seo.service.js.map +1 -1
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/services/error.service.d.ts +21 -1
- package/dist/core/services/error.service.d.ts.map +1 -1
- package/dist/core/services/error.service.js +39 -0
- package/dist/core/services/error.service.js.map +1 -1
- package/dist/core/services/faker.service.d.ts +160 -0
- package/dist/core/services/faker.service.d.ts.map +1 -0
- package/dist/core/services/faker.service.js +235 -0
- package/dist/core/services/faker.service.js.map +1 -0
- 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 +178 -65
- package/dist/core/services/http.service.js.map +1 -1
- package/dist/core/services/media.service.d.ts +97 -0
- package/dist/core/services/media.service.d.ts.map +1 -0
- package/dist/core/services/media.service.js +239 -0
- package/dist/core/services/media.service.js.map +1 -0
- package/dist/core/services/query.service.d.ts +1 -1
- package/dist/core/services/query.service.js +1 -1
- package/dist/core/services/reactive.service.d.ts.map +1 -1
- package/dist/core/services/reactive.service.js +5 -14
- package/dist/core/services/reactive.service.js.map +1 -1
- package/dist/core/services/result.service.d.ts +41 -0
- package/dist/core/services/result.service.d.ts.map +1 -0
- package/dist/core/services/result.service.js +60 -0
- package/dist/core/services/result.service.js.map +1 -0
- 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/core/services/validation.service.d.ts +22 -0
- package/dist/core/services/validation.service.d.ts.map +1 -0
- package/dist/core/services/validation.service.js +41 -0
- package/dist/core/services/validation.service.js.map +1 -0
- package/dist/core/services/youtube.service.d.ts +79 -0
- package/dist/core/services/youtube.service.d.ts.map +1 -0
- package/dist/core/services/youtube.service.js +388 -0
- package/dist/core/services/youtube.service.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/filesystem/filesystem.service.d.ts +267 -0
- package/dist/infrastructure/filesystem/filesystem.service.d.ts.map +1 -0
- package/dist/infrastructure/filesystem/filesystem.service.js +453 -0
- package/dist/infrastructure/filesystem/filesystem.service.js.map +1 -0
- package/dist/infrastructure/filesystem/path.service.d.ts +115 -0
- package/dist/infrastructure/filesystem/path.service.d.ts.map +1 -0
- package/dist/infrastructure/filesystem/path.service.js +154 -0
- package/dist/infrastructure/filesystem/path.service.js.map +1 -0
- package/dist/infrastructure/index.d.ts +3 -0
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/infrastructure/index.js +3 -0
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/infrastructure/media/media.service.d.ts +15 -0
- package/dist/infrastructure/media/media.service.d.ts.map +1 -0
- package/dist/infrastructure/media/media.service.js +44 -0
- package/dist/infrastructure/media/media.service.js.map +1 -0
- package/dist/infrastructure/storage/storage.service.d.ts.map +1 -1
- package/dist/infrastructure/storage/storage.service.js +10 -8
- package/dist/infrastructure/storage/storage.service.js.map +1 -1
- package/dist/schemas/access.schema.d.ts +69 -0
- package/dist/schemas/access.schema.d.ts.map +1 -0
- package/dist/schemas/access.schema.js +36 -0
- package/dist/schemas/access.schema.js.map +1 -0
- package/dist/schemas/ai.schema.d.ts +53 -0
- package/dist/schemas/ai.schema.d.ts.map +1 -0
- package/dist/schemas/ai.schema.js +34 -0
- package/dist/schemas/ai.schema.js.map +1 -0
- package/dist/schemas/common.schema.d.ts +49 -0
- package/dist/schemas/common.schema.d.ts.map +1 -0
- package/dist/schemas/common.schema.js +23 -0
- package/dist/schemas/common.schema.js.map +1 -0
- package/dist/schemas/core.schema.d.ts +164 -0
- package/dist/schemas/core.schema.d.ts.map +1 -0
- package/dist/schemas/core.schema.js +109 -0
- package/dist/schemas/core.schema.js.map +1 -0
- package/dist/schemas/faker.schema.d.ts +12 -0
- package/dist/schemas/faker.schema.d.ts.map +1 -0
- package/dist/schemas/faker.schema.js +12 -0
- package/dist/schemas/faker.schema.js.map +1 -0
- package/dist/schemas/filesystem.schema.d.ts +71 -0
- package/dist/schemas/filesystem.schema.d.ts.map +1 -0
- package/dist/schemas/filesystem.schema.js +56 -0
- package/dist/schemas/filesystem.schema.js.map +1 -0
- package/dist/schemas/index.d.ts +13 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +13 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/insforge.schema.d.ts +69 -0
- package/dist/schemas/insforge.schema.d.ts.map +1 -0
- package/dist/schemas/insforge.schema.js +82 -0
- package/dist/schemas/insforge.schema.js.map +1 -0
- package/dist/schemas/media.schema.d.ts +51 -0
- package/dist/schemas/media.schema.d.ts.map +1 -0
- package/dist/schemas/media.schema.js +50 -0
- package/dist/schemas/media.schema.js.map +1 -0
- package/dist/schemas/notion.schema.d.ts +1058 -0
- package/dist/schemas/notion.schema.d.ts.map +1 -0
- package/dist/schemas/notion.schema.js +248 -0
- package/dist/schemas/notion.schema.js.map +1 -0
- package/dist/schemas/rss.schema.d.ts +35 -0
- package/dist/schemas/rss.schema.d.ts.map +1 -0
- package/dist/schemas/rss.schema.js +44 -0
- package/dist/schemas/rss.schema.js.map +1 -0
- package/dist/schemas/wordpress.schema.d.ts +1304 -0
- package/dist/schemas/wordpress.schema.d.ts.map +1 -0
- package/dist/schemas/wordpress.schema.js +404 -0
- package/dist/schemas/wordpress.schema.js.map +1 -0
- package/dist/schemas/youtube.schema.d.ts +122 -0
- package/dist/schemas/youtube.schema.d.ts.map +1 -0
- package/dist/schemas/youtube.schema.js +113 -0
- package/dist/schemas/youtube.schema.js.map +1 -0
- package/dist/types/index.d.ts +286 -804
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +42 -23
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A sharp, framework-agnostic TypeScript service toolkit organized with hexagonal
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install katanakit-js
|
|
9
9
|
# or
|
|
10
|
-
|
|
10
|
+
pnpm add katanakit-js
|
|
11
11
|
# or
|
|
12
12
|
bun add katanakit-js
|
|
13
13
|
```
|
|
@@ -18,7 +18,7 @@ In the browser, use jsDelivr **`/+esm`** so named exports and dependencies resol
|
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
20
|
<script type="module">
|
|
21
|
-
import { useLogger, useGetApi,
|
|
21
|
+
import { useLogger, useGetApi, defineApiConfig } from "https://cdn.jsdelivr.net/npm/katanakit-js/+esm";
|
|
22
22
|
useLogger("ready");
|
|
23
23
|
</script>
|
|
24
24
|
```
|
|
@@ -29,17 +29,18 @@ In the browser, use jsDelivr **`/+esm`** so named exports and dependencies resol
|
|
|
29
29
|
| **esm.sh** | `https://esm.sh/katanakit-js` |
|
|
30
30
|
| **Raw ESM file** | `https://cdn.jsdelivr.net/npm/katanakit-js/dist/index.js` (needs bundler or import map) |
|
|
31
31
|
|
|
32
|
-
Pin a version in production (e.g. `@
|
|
32
|
+
Pin a version in production (e.g. `@6.0.4/+esm`). There is no IIFE/UMD build.
|
|
33
33
|
|
|
34
34
|
## Quick Start
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
import {
|
|
37
|
+
import { defineApiConfig, useGetApi, useLogger } from "katanakit-js";
|
|
38
38
|
|
|
39
39
|
useLogger("boot");
|
|
40
40
|
|
|
41
|
-
// Register your APIs once
|
|
42
|
-
|
|
41
|
+
// Register your APIs once — returns the config, so you can also
|
|
42
|
+
// `export default defineApiConfig({ … })` from a config file.
|
|
43
|
+
defineApiConfig({
|
|
43
44
|
pokeapi: {
|
|
44
45
|
baseUri: "https://pokeapi.co/api/v2",
|
|
45
46
|
endpoints: { pokemonById: "/pokemon/:id/" },
|
|
@@ -58,6 +59,39 @@ if (result.ok) {
|
|
|
58
59
|
}
|
|
59
60
|
```
|
|
60
61
|
|
|
62
|
+
## Configuration files
|
|
63
|
+
|
|
64
|
+
Every service that takes config exposes a **`define*Config`** entry point. One call
|
|
65
|
+
registers it and hands it back, so a whole file can be just this:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// katanakit.config.ts
|
|
69
|
+
export default defineApiConfig({
|
|
70
|
+
pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { byId: "/pokemon/:id/" } },
|
|
71
|
+
debug: true, // boolean flags stay off the registry, on `config`
|
|
72
|
+
getPokemon: async function () {
|
|
73
|
+
// ^^^^^^^^ `function`, never an arrow
|
|
74
|
+
if (this.config.debug) console.log("fetching…");
|
|
75
|
+
return useFetch("pokeapi", "byId", { params: { id: 25 } });
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import api from "./katanakit.config.js";
|
|
82
|
+
|
|
83
|
+
api.config.pokeapi; // your props and flags
|
|
84
|
+
await api.getPokemon(); // your methods
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Only `{ baseUri, endpoints }` objects reach the API registry. **Declare methods
|
|
88
|
+
with `function`** — arrows have no `this`, so `this.config` inside one is
|
|
89
|
+
`undefined` and TypeScript reports it.
|
|
90
|
+
|
|
91
|
+
The old `useInit*` calls still work; they are deprecated and map one-for-one onto
|
|
92
|
+
`define*Config`. Full table of which services accept methods in
|
|
93
|
+
[Getting Started](https://docs.senseikatana.com/guides/getting-started).
|
|
94
|
+
|
|
61
95
|
## HTTP Client — API Manager
|
|
62
96
|
|
|
63
97
|
The core of KatanaKit is a **typed, registry-based HTTP client**. You register
|
|
@@ -67,9 +101,9 @@ and returns a **Safe Result** (`{ ok, data, error }`) that never throws on HTTP
|
|
|
67
101
|
### 1. Register your APIs
|
|
68
102
|
|
|
69
103
|
```ts
|
|
70
|
-
import {
|
|
104
|
+
import { defineApiConfig } from "katanakit-js";
|
|
71
105
|
|
|
72
|
-
|
|
106
|
+
defineApiConfig({
|
|
73
107
|
// A public REST API
|
|
74
108
|
jsonplaceholder: {
|
|
75
109
|
baseUri: "https://jsonplaceholder.typicode.com",
|
|
@@ -323,11 +357,153 @@ const stop = useKatanaWatch(newProduct, () => checkValidations(), { deep: true }
|
|
|
323
357
|
|
|
324
358
|
## Features
|
|
325
359
|
|
|
326
|
-
- **Safe Results** — HTTP (and other fallible) operations return `{ data, error, ok }` instead of throwing
|
|
360
|
+
- **Safe Results + helpers** — HTTP (and other fallible) operations return `{ data, error, ok }` instead of throwing; `useAttempt()`, `useTryJsonParse()` and `useErrorNormalize()` standardize boundaries and error shapes (see [Error Handling](https://docs.senseikatana.com/guides/errors))
|
|
361
|
+
- **Zod validation everywhere** — `types/` is the single source of truth, inferred from Zod schemas via `z.infer`; `useValidate()` turns any schema into a Safe Result and API adapters validate every response at the boundary
|
|
327
362
|
- **Zero side effects** — importing any module is safe. No `fetch` calls, no `console.log`, no storage writes
|
|
328
363
|
- **Hexagonal architecture** — pure core, infrastructure adapters, framework adapters
|
|
329
364
|
- **Tree-shakeable** — destructured re-exports from Singleton facades
|
|
330
365
|
- **SSR-safe** — all infrastructure adapters guard or fall back gracefully in server environments
|
|
366
|
+
- **Filesystem (Node/Bun)** — `useReadFile`, `useWriteFile`, `useReadJsonFile`, `useReadModuleJson`, `useHashFile` and friends return Safe Results with native errno codes, loaded lazily through dynamic `import()` and guarded by `useIsNode()`
|
|
367
|
+
- **Fake data (optional)** — `useFakeVehicle`, `useFakeEmail`, `useFakeList`, … via an optional, lazy-loaded `@faker-js/faker` peer
|
|
368
|
+
- **Katana UI** — framework-agnostic component foundations (`useButton`, `useInput`, `useCard`, `useBadge`, `useAlert`) live in the private `@katanakit/ui` workspace, styled with `katanakit-css` (see [UI Kit](https://docs.senseikatana.com/ui-kit/))
|
|
369
|
+
|
|
370
|
+
## Filesystem (Node/Bun)
|
|
371
|
+
|
|
372
|
+
Node-only helpers that wrap `node:fs/promises` and `node:path` with the Safe
|
|
373
|
+
Result contract. Built-ins load through dynamic `import()`, so importing them is
|
|
374
|
+
browser-safe; outside Node/Bun every fallible call returns `ERR_FS_UNAVAILABLE`
|
|
375
|
+
instead of throwing.
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
import {
|
|
379
|
+
useEnsureDir,
|
|
380
|
+
useReadDir,
|
|
381
|
+
useReadJsonFile,
|
|
382
|
+
useReadModuleJson,
|
|
383
|
+
useWriteJsonFile,
|
|
384
|
+
} from "katanakit-js";
|
|
385
|
+
import { z } from "zod";
|
|
386
|
+
|
|
387
|
+
const BooksSchema = z.array(z.object({ title: z.string() }));
|
|
388
|
+
|
|
389
|
+
// Read relative to the current module (the __dirname pattern, without __dirname)
|
|
390
|
+
const result = await useReadModuleJson(import.meta.url, "../data/books.json", BooksSchema);
|
|
391
|
+
|
|
392
|
+
if (result.ok) {
|
|
393
|
+
console.log(result.data);
|
|
394
|
+
} else {
|
|
395
|
+
console.error(result.error.code, result.error.message); // ENOENT | ERR_VALIDATION | ...
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Or with an explicit path (relative paths resolve against process.cwd())
|
|
399
|
+
await useEnsureDir("data/cache");
|
|
400
|
+
await useWriteJsonFile("data/cache/books.json", [{ title: "Kata" }]);
|
|
401
|
+
const books = await useReadJsonFile("data/cache/books.json", BooksSchema);
|
|
402
|
+
const files = await useReadDir("data/cache", { recursive: true });
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
| Group | Helpers |
|
|
406
|
+
| ----- | ------- |
|
|
407
|
+
| Read | `useReadFile`, `useReadFileBuffer`, `useReadJsonFile`, `useReadModuleFile`, `useReadModuleJson` |
|
|
408
|
+
| Write | `useWriteFile`, `useAppendFile`, `useWriteJsonFile`, `useEnsureDir` |
|
|
409
|
+
| Inspect | `useFileExists`, `useGetFileStats`, `useReadDir` |
|
|
410
|
+
| Checksums | `useHashFile`, `useVerifyFileHash` — streaming `md5`/`sha1`/`sha256`/`sha512` digests (`sha256` by default) and case-insensitive verification |
|
|
411
|
+
| Move / delete | `useCopyFile`, `useMoveFile`, `useRemoveFile`, `useRemoveDir` |
|
|
412
|
+
| Paths | `useGetDirname`, `useResolvePath`, `useJoinPath`, `useGetRelativePath`, `useGetBasename`, `useGetFileExtension`, `useGetCwd`, `useIsNode` |
|
|
413
|
+
|
|
414
|
+
## Fake data (optional)
|
|
415
|
+
|
|
416
|
+
`@faker-js/faker` is an **optional peer dependency**: these helpers load it
|
|
417
|
+
through dynamic `import()` on first call, so install it only if you use them
|
|
418
|
+
(`bun add @faker-js/faker` / `npm install @faker-js/faker`).
|
|
419
|
+
|
|
420
|
+
| Group | Helpers |
|
|
421
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
422
|
+
| People / internet | `useFakeFullName`, `useFakeFirstName`, `useFakeLastName`, `useFakeEmail`, `useFakePhone`, `useFakeCompanyName`, `useFakeUrl` |
|
|
423
|
+
| Values | `useFakeUuid`, `useFakeText`, `useFakeNumber`, `useFakeBoolean`, `useFakeDate`, `useFakeVehicle` |
|
|
424
|
+
| Collections | `useFakeList(factory, count)` — the factory receives the zero-based index |
|
|
425
|
+
| Reproducibility | `useFakeSeed(seed?)`, `useFakeSetDefaultRefDate(refDate?)` |
|
|
426
|
+
|
|
427
|
+
### Reproducible seeds
|
|
428
|
+
|
|
429
|
+
`useFakeSeed(42)` sets the seed **and returns it**. Call it with no arguments to
|
|
430
|
+
roll a fresh random seed (also returned) — log it in CI and pass it back later
|
|
431
|
+
to replay the exact run. `useFakeSetDefaultRefDate("2026-01-01")` pins the
|
|
432
|
+
reference date used by date helpers. Same seed + same reference date + same
|
|
433
|
+
call order + same faker major = identical output.
|
|
434
|
+
|
|
435
|
+
```ts
|
|
436
|
+
import { useFakeSeed, useFakeSetDefaultRefDate, useFakeUuid } from "katanakit-js";
|
|
437
|
+
|
|
438
|
+
const seed = await useFakeSeed(); // e.g. 1696121567592875 — log it in CI
|
|
439
|
+
await useFakeSetDefaultRefDate("2026-01-01");
|
|
440
|
+
|
|
441
|
+
await useFakeSeed(seed); // replay the exact same sequence
|
|
442
|
+
const id = await useFakeUuid();
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Seed data (users, products, orders)
|
|
446
|
+
|
|
447
|
+
Compose the helpers with `useFakeList` to build realistic fixtures, then write
|
|
448
|
+
them anywhere with the [filesystem helpers](#filesystem-nodebun):
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
import {
|
|
452
|
+
useEnsureDir,
|
|
453
|
+
useFakeDate,
|
|
454
|
+
useFakeEmail,
|
|
455
|
+
useFakeFullName,
|
|
456
|
+
useFakeList,
|
|
457
|
+
useFakeNumber,
|
|
458
|
+
useFakeSeed,
|
|
459
|
+
useFakeSetDefaultRefDate,
|
|
460
|
+
useFakeText,
|
|
461
|
+
useFakeUuid,
|
|
462
|
+
useWriteJsonFile,
|
|
463
|
+
} from "katanakit-js";
|
|
464
|
+
|
|
465
|
+
await useFakeSeed(42);
|
|
466
|
+
await useFakeSetDefaultRefDate("2026-01-01");
|
|
467
|
+
|
|
468
|
+
const users = await useFakeList(
|
|
469
|
+
async () => ({
|
|
470
|
+
id: await useFakeUuid(),
|
|
471
|
+
fullName: await useFakeFullName(),
|
|
472
|
+
email: await useFakeEmail(),
|
|
473
|
+
createdAt: (await useFakeDate("2024-01-01")).toISOString(),
|
|
474
|
+
}),
|
|
475
|
+
5,
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
const products = await useFakeList(
|
|
479
|
+
async () => ({
|
|
480
|
+
id: await useFakeUuid(),
|
|
481
|
+
name: await useFakeText(3),
|
|
482
|
+
price: await useFakeNumber(5, 250),
|
|
483
|
+
stock: await useFakeNumber(0, 120),
|
|
484
|
+
}),
|
|
485
|
+
8,
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
// Relations: the factory receives the index
|
|
489
|
+
const orders = await useFakeList(
|
|
490
|
+
async (index) => ({
|
|
491
|
+
id: await useFakeUuid(),
|
|
492
|
+
userId: users[index % users.length].id,
|
|
493
|
+
productId: products[index % products.length].id,
|
|
494
|
+
quantity: await useFakeNumber(1, 6),
|
|
495
|
+
placedAt: (await useFakeDate("2025-01-01")).toISOString(),
|
|
496
|
+
}),
|
|
497
|
+
12,
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
await useEnsureDir("data/seed");
|
|
501
|
+
await useWriteJsonFile("data/seed/users.json", users);
|
|
502
|
+
// feed the arrays to your seeder: prisma.user.createMany({ data: users }), ...
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
A runnable version (users, products and orders with relations, written as JSON)
|
|
506
|
+
lives in [`examples/seed/`](./examples/seed/README.md).
|
|
331
507
|
|
|
332
508
|
## AI assistant (Kitt)
|
|
333
509
|
|
|
@@ -510,9 +686,9 @@ app.use(
|
|
|
510
686
|
Long polling does not need a public URL. Session ids are `telegram:<chatId>`.
|
|
511
687
|
|
|
512
688
|
```ts
|
|
513
|
-
import {
|
|
689
|
+
import { defineTelegramConfig, useStartTelegramPolling } from "katanakit-js/adapters/telegram";
|
|
514
690
|
|
|
515
|
-
|
|
691
|
+
defineTelegramConfig({ token: process.env.TELEGRAM_BOT_TOKEN });
|
|
516
692
|
await useStartTelegramPolling();
|
|
517
693
|
```
|
|
518
694
|
|
|
@@ -528,9 +704,9 @@ await useStartTelegramPolling();
|
|
|
528
704
|
Webhook: `GET` / `POST` `/whatsapp/webhook`. Session ids are `wa:<phone>`.
|
|
529
705
|
|
|
530
706
|
```ts
|
|
531
|
-
import {
|
|
707
|
+
import { defineWhatsAppConfig, useStartWhatsApp } from "katanakit-js/adapters/whatsapp";
|
|
532
708
|
|
|
533
|
-
|
|
709
|
+
defineWhatsAppConfig({
|
|
534
710
|
token: process.env.WHATSAPP_TOKEN,
|
|
535
711
|
phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID,
|
|
536
712
|
verifyToken: process.env.WHATSAPP_VERIFY_TOKEN,
|
|
@@ -587,15 +763,15 @@ product FAQ, CRM, or ticket system. Keep the `{ name, description, parameters, e
|
|
|
587
763
|
|
|
588
764
|
## Framework usage
|
|
589
765
|
|
|
590
|
-
All common `use*` helpers (`useLogger`, `
|
|
766
|
+
All common `use*` helpers (`useLogger`, `useGetApi`, formatter, dates, utils, theme, …) plus the `define*Config` entry points (`defineApiConfig`, …) are on the **main barrel** `katanakit-js`.
|
|
591
767
|
|
|
592
768
|
### Astro (npm)
|
|
593
769
|
|
|
594
770
|
```astro
|
|
595
771
|
---
|
|
596
772
|
// Frontmatter = server
|
|
597
|
-
import { useLogger, useGetApi,
|
|
598
|
-
|
|
773
|
+
import { useLogger, useGetApi, defineApiConfig } from "katanakit-js";
|
|
774
|
+
defineApiConfig({ /* ... */ });
|
|
599
775
|
const result = await useGetApi("pokeapi", "pokemonById", { params: { id: 25 } });
|
|
600
776
|
---
|
|
601
777
|
<script>
|
|
@@ -617,7 +793,7 @@ const result = await useGetApi("pokeapi", "pokemonById", { params: { id: 25 } })
|
|
|
617
793
|
### Vue / Nuxt / vanilla
|
|
618
794
|
|
|
619
795
|
```ts
|
|
620
|
-
import { useLogger,
|
|
796
|
+
import { useLogger, defineApiConfig, useGetApi } from "katanakit-js";
|
|
621
797
|
import { useRequest } from "katanakit-js/adapters/vue"; // Vue only
|
|
622
798
|
import { useUnwrap } from "katanakit-js/adapters/nuxt"; // Nuxt only
|
|
623
799
|
```
|
|
@@ -629,7 +805,7 @@ import { useUnwrap } from "katanakit-js/adapters/nuxt"; // Nuxt only
|
|
|
629
805
|
</script>
|
|
630
806
|
```
|
|
631
807
|
|
|
632
|
-
See [Getting Started](https://docs.senseikatana.com/
|
|
808
|
+
See [Getting Started](https://docs.senseikatana.com/guides/getting-started) for full recipes.
|
|
633
809
|
|
|
634
810
|
## Framework Adapters
|
|
635
811
|
|
|
@@ -640,8 +816,8 @@ See [Getting Started](https://docs.senseikatana.com/docs/guides/getting-started/
|
|
|
640
816
|
| **Vue** | `katanakit-js/adapters/vue` | `useRequest` composable with reactivity |
|
|
641
817
|
| **Astro** | `katanakit-js` or `katanakit-js/adapters/astro` | `AstroService`, `RssService` |
|
|
642
818
|
| **Assistant** | `katanakit-js/adapters/assistant` | REST digital assistant (`useStartAssistant`) |
|
|
643
|
-
| **Telegram** | `katanakit-js/adapters/telegram` | BotFather bot (`
|
|
644
|
-
| **WhatsApp** | `katanakit-js/adapters/whatsapp` | Meta Cloud API (`
|
|
819
|
+
| **Telegram** | `katanakit-js/adapters/telegram` | BotFather bot (`defineTelegramConfig`, `useStartTelegramPolling`) |
|
|
820
|
+
| **WhatsApp** | `katanakit-js/adapters/whatsapp` | Meta Cloud API (`defineWhatsAppConfig`, `useStartWhatsApp`) |
|
|
645
821
|
|
|
646
822
|
## REST API Adapters
|
|
647
823
|
|
|
@@ -652,6 +828,11 @@ All functions return `FetchResult<T>` — the same Safe Result pattern used by t
|
|
|
652
828
|
| ------------- | --------------------------------- | ----------------------------------------------------------------- |
|
|
653
829
|
| **Notion** | `katanakit-js/adapters/notion` | Pages, databases, blocks, search with cursor pagination |
|
|
654
830
|
| **WordPress** | `katanakit-js/adapters/wordpress` | Posts, pages, media, categories, tags, comments, users, batch ops |
|
|
831
|
+
| **InsForge** | `katanakit-js/adapters/insforge` | Database fallback, storage buckets and edge functions |
|
|
832
|
+
|
|
833
|
+
All REST adapters validate responses with Zod: malformed payloads return a typed `502`
|
|
834
|
+
Safe Result instead of untyped garbage, and invalid inputs are rejected with `400`
|
|
835
|
+
before any network call.
|
|
655
836
|
|
|
656
837
|
### Notion
|
|
657
838
|
|
|
@@ -661,10 +842,10 @@ full TypeScript types, cursor-based auto-pagination, and Safe Results.
|
|
|
661
842
|
#### Setup
|
|
662
843
|
|
|
663
844
|
```ts
|
|
664
|
-
import {
|
|
845
|
+
import { defineNotionConfig } from "katanakit-js/adapters/notion";
|
|
665
846
|
|
|
666
847
|
// Token starts with "ntn_" or "secret_" — get one at https://www.notion.so/my-integrations
|
|
667
|
-
|
|
848
|
+
defineNotionConfig({ token: process.env.NOTION_TOKEN });
|
|
668
849
|
```
|
|
669
850
|
|
|
670
851
|
#### Pages — read, create, update, archive
|
|
@@ -870,22 +1051,22 @@ and batch operations. All functions return `FetchResult<T>`.
|
|
|
870
1051
|
#### Setup
|
|
871
1052
|
|
|
872
1053
|
```ts
|
|
873
|
-
import {
|
|
1054
|
+
import { defineWordPressConfig } from "katanakit-js/adapters/wordpress";
|
|
874
1055
|
|
|
875
1056
|
// Application Passwords (recommended) — WP Admin → Users → Your Profile → Application Passwords
|
|
876
|
-
|
|
1057
|
+
defineWordPressConfig({
|
|
877
1058
|
baseUrl: "https://mysite.com",
|
|
878
1059
|
auth: { type: "application-passwords", username: "admin", password: "xxxx xxxx xxxx" },
|
|
879
1060
|
});
|
|
880
1061
|
|
|
881
1062
|
// JWT tokens
|
|
882
|
-
|
|
1063
|
+
defineWordPressConfig({
|
|
883
1064
|
baseUrl: "https://mysite.com",
|
|
884
1065
|
auth: { type: "jwt", token: "eyJhbGci..." },
|
|
885
1066
|
});
|
|
886
1067
|
|
|
887
1068
|
// Nonce-based (for WP themes)
|
|
888
|
-
|
|
1069
|
+
defineWordPressConfig({
|
|
889
1070
|
baseUrl: "https://mysite.com",
|
|
890
1071
|
auth: { type: "nonce", nonce: "abc123" },
|
|
891
1072
|
});
|
|
@@ -1217,6 +1398,34 @@ const full = await useWpGetPosts({
|
|
|
1217
1398
|
| **Next.js** | [`examples/wordpress/next-[slug].tsx`](https://github.com/senseikatana/katanakit-js/tree/main/examples/wordpress/next-[slug].tsx) | Dynamic `[slug]` page |
|
|
1218
1399
|
| **Node.js** | [`examples/wordpress/demo.ts`](https://github.com/senseikatana/katanakit-js/tree/main/examples/wordpress/demo.ts) | Runnable demo covering all WP operations, `_fields`, `_embed`, ACF |
|
|
1219
1400
|
|
|
1401
|
+
### InsForge (database fallback)
|
|
1402
|
+
|
|
1403
|
+
InsForge is supported as the **database fallback** (the primary data layer is Cloudflare),
|
|
1404
|
+
plus object storage and edge functions. The adapter wraps the official SDK in the same
|
|
1405
|
+
Safe Result contract, validates every input, and refuses mass writes (update/delete
|
|
1406
|
+
require non-empty filters).
|
|
1407
|
+
|
|
1408
|
+
```ts
|
|
1409
|
+
import { defineInsforgeConfig, useIfSelect, useIfInsert } from "katanakit-js/adapters/insforge";
|
|
1410
|
+
|
|
1411
|
+
// Server-only admin client (apiKey), or browser-safe client (anonKey)
|
|
1412
|
+
defineInsforgeConfig({ baseUrl: process.env.INSFORGE_URL!, apiKey: process.env.INSFORGE_API_KEY! });
|
|
1413
|
+
|
|
1414
|
+
const posts = await useIfSelect<{ id: number; title: string }>({
|
|
1415
|
+
table: "posts",
|
|
1416
|
+
filters: { author_id: 7 },
|
|
1417
|
+
order: { column: "created_at", ascending: false },
|
|
1418
|
+
limit: 10,
|
|
1419
|
+
});
|
|
1420
|
+
if (posts.ok) console.log(posts.data);
|
|
1421
|
+
|
|
1422
|
+
const created = await useIfInsert("posts", [{ title: "Hello" }]);
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1425
|
+
Storage (`useIfUpload`, `useIfDownload`, `useIfRemove`, `useIfListObjects`,
|
|
1426
|
+
`useIfGetPublicUrl`) and edge functions (`useIfInvokeFunction`) follow the same pattern.
|
|
1427
|
+
Install the optional peer with `bun add @insforge/sdk`.
|
|
1428
|
+
|
|
1220
1429
|
## Contributing
|
|
1221
1430
|
|
|
1222
1431
|
We welcome contributions from the community! Whether it's fixing a bug, adding
|
|
@@ -1253,14 +1462,15 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full development contract.
|
|
|
1253
1462
|
|
|
1254
1463
|
## Documentation
|
|
1255
1464
|
|
|
1256
|
-
The docs site is deployed with Cloudflare Pages at [docs.senseikatana.com](https://docs.senseikatana.com/).
|
|
1465
|
+
The docs site is built with **VitePress** from [`docs/`](./docs) and deployed with Cloudflare Pages at [docs.senseikatana.com](https://docs.senseikatana.com/). Run it locally with `bun run docs:dev`.
|
|
1257
1466
|
|
|
1258
|
-
- [Getting Started](https://docs.senseikatana.com/
|
|
1259
|
-
- [
|
|
1260
|
-
- [
|
|
1261
|
-
- [
|
|
1262
|
-
- [
|
|
1263
|
-
- [
|
|
1467
|
+
- [Getting Started](https://docs.senseikatana.com/guides/getting-started)
|
|
1468
|
+
- [Error Handling](https://docs.senseikatana.com/guides/errors)
|
|
1469
|
+
- [Architecture](https://docs.senseikatana.com/guides/architecture)
|
|
1470
|
+
- [UI Kit (Katana UI)](https://docs.senseikatana.com/ui-kit/)
|
|
1471
|
+
- [API Reference](https://docs.senseikatana.com/api/)
|
|
1472
|
+
- [Roadmap](https://docs.senseikatana.com/guides/roadmap)
|
|
1473
|
+
- [Changelog](https://docs.senseikatana.com/changelog)
|
|
1264
1474
|
|
|
1265
1475
|
## License
|
|
1266
1476
|
|
|
@@ -43,7 +43,7 @@ export function useRequest(apiName, endpointName, options) {
|
|
|
43
43
|
error.set(null);
|
|
44
44
|
const result = await useFetch(apiName, endpointName, {
|
|
45
45
|
method: "GET",
|
|
46
|
-
|
|
46
|
+
...options,
|
|
47
47
|
signal: next.signal,
|
|
48
48
|
});
|
|
49
49
|
if (disposed || current !== version)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/adapters/angular/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAe,MAAM,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAW/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,UAAU,CACzB,OAAe,EACf,YAAoB,EACpB,OAAoB;IAEpB,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAEtC,MAAM,IAAI,GAAG,MAAM,CAAW,IAAI,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,MAAM,CAAkB,IAAI,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,UAAU,GAA2B,IAAI,CAAC;IAC9C,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,OAAO,GAAG,KAAK,IAAmB,EAAE;QACzC,MAAM,OAAO,GAAG,EAAE,OAAO,CAAC;QAC1B,UAAU,EAAE,KAAK,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;QACnC,UAAU,GAAG,IAAI,CAAC;QAElB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,KAAK,CAAC,GAAG,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H,IAAI,QAAQ,IAAI,OAAO,KAAK,OAAO;YAAE,OAAO;QAE5C,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC,CAAC;IAEF,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE;QACzB,QAAQ,GAAG,IAAI,CAAC;QAChB,UAAU,EAAE,KAAK,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,KAAK,OAAO,EAAE,CAAC;IAEf,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
/** Base URL of the public dummyjson.com REST API. */
|
|
2
2
|
export declare const DUMMYJSON_BASE_URL = "https://dummyjson.com";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The dummyjson.com API definition — plain data, so importing this module runs
|
|
5
|
+
* nothing and hits no network.
|
|
6
|
+
*
|
|
7
|
+
* Register it once with `defineApiConfig` before any {@link useDummyJsonProducts}-style
|
|
8
|
+
* handler; there is no separate init call to remember.
|
|
6
9
|
*
|
|
7
10
|
* @example
|
|
8
11
|
* ```ts
|
|
9
|
-
* import {
|
|
12
|
+
* import { defineApiConfig } from "katanakit-js";
|
|
13
|
+
* import { dummyJsonApiConfig, useDummyJsonProducts } from "katanakit-js/adapters/bun";
|
|
14
|
+
*
|
|
15
|
+
* defineApiConfig(dummyJsonApiConfig);
|
|
10
16
|
*
|
|
11
|
-
*
|
|
17
|
+
* const response = await useDummyJsonProducts();
|
|
12
18
|
* ```
|
|
13
19
|
*/
|
|
14
|
-
export declare
|
|
20
|
+
export declare const dummyJsonApiConfig: {
|
|
21
|
+
dummyjson: {
|
|
22
|
+
baseUri: string;
|
|
23
|
+
endpoints: {
|
|
24
|
+
products: string;
|
|
25
|
+
productById: string;
|
|
26
|
+
productSearch: string;
|
|
27
|
+
productCategories: string;
|
|
28
|
+
productByCategory: string;
|
|
29
|
+
users: string;
|
|
30
|
+
userById: string;
|
|
31
|
+
posts: string;
|
|
32
|
+
postById: string;
|
|
33
|
+
quotes: string;
|
|
34
|
+
quoteRandom: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
15
38
|
/** Serializes `data` into a JSON {@link Response}. */
|
|
16
39
|
export declare function jsonResponse(data: unknown, status?: number): Response;
|
|
17
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dummyjson.service.d.ts","sourceRoot":"","sources":["../../../src/adapters/bun/dummyjson.service.ts"],"names":[],"mappings":"AAGA,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAiB1D
|
|
1
|
+
{"version":3,"file":"dummyjson.service.d.ts","sourceRoot":"","sources":["../../../src/adapters/bun/dummyjson.service.ts"],"names":[],"mappings":"AAGA,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAiB1D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;CAK9B,CAAC;AAkBF,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,SAAM,GAAG,QAAQ,CAKlE;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE9D;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE3E;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEhF;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,QAAQ,CAAC,CAEvE;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAExF;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE3D;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAExE;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE3D;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAExE;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE5D;AAED;;;;GAIG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAEjE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useFetch
|
|
1
|
+
import { useFetch } from "../../core/services/http.service.js";
|
|
2
2
|
/** Base URL of the public dummyjson.com REST API. */
|
|
3
3
|
export const DUMMYJSON_BASE_URL = "https://dummyjson.com";
|
|
4
4
|
/** Endpoints of the dummyjson.com REST API (relative to {@link DUMMYJSON_BASE_URL}). */
|
|
@@ -16,24 +16,28 @@ const DUMMYJSON_ENDPOINTS = {
|
|
|
16
16
|
quoteRandom: "/quotes/random",
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* The dummyjson.com API definition — plain data, so importing this module runs
|
|
20
|
+
* nothing and hits no network.
|
|
21
|
+
*
|
|
22
|
+
* Register it once with `defineApiConfig` before any {@link useDummyJsonProducts}-style
|
|
23
|
+
* handler; there is no separate init call to remember.
|
|
21
24
|
*
|
|
22
25
|
* @example
|
|
23
26
|
* ```ts
|
|
24
|
-
* import {
|
|
27
|
+
* import { defineApiConfig } from "katanakit-js";
|
|
28
|
+
* import { dummyJsonApiConfig, useDummyJsonProducts } from "katanakit-js/adapters/bun";
|
|
29
|
+
*
|
|
30
|
+
* defineApiConfig(dummyJsonApiConfig);
|
|
25
31
|
*
|
|
26
|
-
*
|
|
32
|
+
* const response = await useDummyJsonProducts();
|
|
27
33
|
* ```
|
|
28
34
|
*/
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
}
|
|
35
|
+
export const dummyJsonApiConfig = {
|
|
36
|
+
dummyjson: {
|
|
37
|
+
baseUri: DUMMYJSON_BASE_URL,
|
|
38
|
+
endpoints: DUMMYJSON_ENDPOINTS,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
37
41
|
/**
|
|
38
42
|
* Converts a Safe Result into a JSON {@link Response}.
|
|
39
43
|
*
|
|
@@ -68,7 +72,7 @@ export async function useDummyJsonProducts() {
|
|
|
68
72
|
* @returns A JSON `Response` wrapping the product.
|
|
69
73
|
*/
|
|
70
74
|
export async function useDummyJsonProductById(id) {
|
|
71
|
-
return toResponse(await useFetch("dummyjson", "productById", {
|
|
75
|
+
return toResponse(await useFetch("dummyjson", "productById", { params: { id } }));
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
74
78
|
* Searches products by a free-text query.
|
|
@@ -77,7 +81,7 @@ export async function useDummyJsonProductById(id) {
|
|
|
77
81
|
* @returns A JSON `Response` wrapping the search results.
|
|
78
82
|
*/
|
|
79
83
|
export async function useDummyJsonProductSearch(query) {
|
|
80
|
-
return toResponse(await useFetch("dummyjson", "productSearch", {
|
|
84
|
+
return toResponse(await useFetch("dummyjson", "productSearch", { query: { q: query } }));
|
|
81
85
|
}
|
|
82
86
|
/**
|
|
83
87
|
* Lists all product categories.
|
|
@@ -94,7 +98,7 @@ export async function useDummyJsonProductCategories() {
|
|
|
94
98
|
* @returns A JSON `Response` wrapping the products.
|
|
95
99
|
*/
|
|
96
100
|
export async function useDummyJsonProductsByCategory(category) {
|
|
97
|
-
return toResponse(await useFetch("dummyjson", "productByCategory", {
|
|
101
|
+
return toResponse(await useFetch("dummyjson", "productByCategory", { params: { category } }));
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
100
104
|
* Lists users from dummyjson.com.
|
|
@@ -111,7 +115,7 @@ export async function useDummyJsonUsers() {
|
|
|
111
115
|
* @returns A JSON `Response` wrapping the user.
|
|
112
116
|
*/
|
|
113
117
|
export async function useDummyJsonUserById(id) {
|
|
114
|
-
return toResponse(await useFetch("dummyjson", "userById", {
|
|
118
|
+
return toResponse(await useFetch("dummyjson", "userById", { params: { id } }));
|
|
115
119
|
}
|
|
116
120
|
/**
|
|
117
121
|
* Lists posts from dummyjson.com.
|
|
@@ -128,7 +132,7 @@ export async function useDummyJsonPosts() {
|
|
|
128
132
|
* @returns A JSON `Response` wrapping the post.
|
|
129
133
|
*/
|
|
130
134
|
export async function useDummyJsonPostById(id) {
|
|
131
|
-
return toResponse(await useFetch("dummyjson", "postById", {
|
|
135
|
+
return toResponse(await useFetch("dummyjson", "postById", { params: { id } }));
|
|
132
136
|
}
|
|
133
137
|
/**
|
|
134
138
|
* Lists quotes from dummyjson.com.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dummyjson.service.js","sourceRoot":"","sources":["../../../src/adapters/bun/dummyjson.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"dummyjson.service.js","sourceRoot":"","sources":["../../../src/adapters/bun/dummyjson.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAA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H,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACtC,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EAAU;IACpD,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAChF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACvC,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC5C,OAAO,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineApiConfig } from "../../core/services/http.service.js";
|
|
2
|
+
import { dummyJsonApiConfig } from "./dummyjson.service.js";
|
|
2
3
|
import { useBunStart } from "./server.js";
|
|
3
|
-
|
|
4
|
+
defineApiConfig(dummyJsonApiConfig);
|
|
4
5
|
const server = useBunStart(Number(process.env.PORT ?? 3000), process.env.HOST ?? "localhost");
|
|
5
6
|
console.log(`Server running at ${server.url}`);
|
|
6
7
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/adapters/bun/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/adapters/bun/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAEpC,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC;AAC9F,OAAO,CAAC,GAAG,CAAC,qBAAqB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
|
@@ -21,9 +21,10 @@ export interface BunServerOptions {
|
|
|
21
21
|
*
|
|
22
22
|
* @example
|
|
23
23
|
* ```ts
|
|
24
|
-
* import {
|
|
24
|
+
* import { dummyJsonApiConfig, useBunCreate } from "katanakit-js/adapters/bun";
|
|
25
|
+
* import { defineApiConfig } from "katanakit-js";
|
|
25
26
|
*
|
|
26
|
-
*
|
|
27
|
+
* defineApiConfig(dummyJsonApiConfig);
|
|
27
28
|
* const server = useBunCreate({ port: 3000 });
|
|
28
29
|
* console.log(`Server running at ${server.url}`);
|
|
29
30
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/adapters/bun/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,eAAe,EAA2B,MAAM,aAAa,CAAC;AAK5E,gDAAgD;AAChD,MAAM,WAAW,gBAAgB;IAChC,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,sDAAsD;IACtD,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,QAAQ,GAAG,OAAO,CA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