katanakit-js 6.7.2 → 6.7.3
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 +88 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ 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. `@6.7.
|
|
32
|
+
Pin a version in production (e.g. `@6.7.3/+esm`). There is no IIFE/UMD build.
|
|
33
33
|
|
|
34
34
|
## Quick Start
|
|
35
35
|
|
|
@@ -355,10 +355,66 @@ const stop = useKatanaWatch(newProduct, () => checkValidations(), { deep: true }
|
|
|
355
355
|
- **Direct cache updates** — `setQueryData` for optimistic updates.
|
|
356
356
|
- **Prefetch** — `prefetchQuery` anticipates user actions.
|
|
357
357
|
|
|
358
|
+
## Design patterns
|
|
359
|
+
|
|
360
|
+
Services are **Singleton facades** with stable `use*` wrappers, and the classic
|
|
361
|
+
patterns stay swappable without leaving the functional API.
|
|
362
|
+
|
|
363
|
+
### Singleton + `use*` wrappers
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
import { LoggerService, useLogger } from "katanakit-js";
|
|
367
|
+
|
|
368
|
+
LoggerService.getInstance().useLog("Application started");
|
|
369
|
+
useLogger("Cache miss", undefined, "warn"); // thin wrapper over the singleton
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Strategy — access control and AI providers
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
import {
|
|
376
|
+
AccessService,
|
|
377
|
+
AgentService,
|
|
378
|
+
FlatAccessStrategy,
|
|
379
|
+
OpenAiCompatibleStrategy,
|
|
380
|
+
} from "katanakit-js";
|
|
381
|
+
|
|
382
|
+
// Swap the behavior of the shared singleton…
|
|
383
|
+
AccessService.getInstance().useSetStrategy(new FlatAccessStrategy());
|
|
384
|
+
|
|
385
|
+
// …or create an isolated instance (handy in tests).
|
|
386
|
+
const access = AccessService.create(new FlatAccessStrategy());
|
|
387
|
+
const agent = AgentService.create(new OpenAiCompatibleStrategy());
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Factory — one `QueryClient` per request (SSR)
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
import { QueryClientFactory } from "katanakit-js";
|
|
394
|
+
|
|
395
|
+
const client = QueryClientFactory.create(); // fresh cache per request
|
|
396
|
+
// QueryClientFactory.createShared() reuses the browser singleton
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Decorators — retry, TTL cache and timing traces
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
import { CacheDecorator, LoggerDecorator, RetryDecorator } from "katanakit-js";
|
|
403
|
+
|
|
404
|
+
const loadUser = RetryDecorator(LoggerDecorator(fetchUser, "user"), 2, 200);
|
|
405
|
+
const cached = CacheDecorator(loadUser, { ttlMs: 60_000 });
|
|
406
|
+
|
|
407
|
+
cached.useClearCache();
|
|
408
|
+
cached.useCacheSize();
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
`RetryDecorator` only retries **thrown** errors: Safe Result helpers never throw,
|
|
412
|
+
so unwrap them (e.g. with `useSafeQueryFn`) before composing.
|
|
413
|
+
|
|
358
414
|
## Features
|
|
359
415
|
|
|
360
416
|
- **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
|
|
417
|
+
- **Zod validation everywhere** — `types/` is the single source of truth, inferred from Zod schemas via `z.infer`; every runtime schema is public under `katanakit-js/schemas`, `useValidate(schema, data)` turns any schema into a Safe Result, and API adapters validate every response at the boundary
|
|
362
418
|
- **Zero side effects** — importing any module is safe. No `fetch` calls, no `console.log`, no storage writes
|
|
363
419
|
- **Hexagonal architecture** — pure core, infrastructure adapters, framework adapters
|
|
364
420
|
- **Design patterns** — services are Singleton classes (`getInstance()`) with swappable Strategy implementations (`AccessService`, `AgentService`), a `QueryClientFactory` for per-request SSR clients, and composable Decorators exported from the main barrel: `RetryDecorator`, `CacheDecorator` (TTL memoization) and `LoggerDecorator` (timing traces)
|
|
@@ -810,15 +866,36 @@ See [Getting Started](https://docs.senseikatana.com/guides/getting-started) for
|
|
|
810
866
|
|
|
811
867
|
## Framework Adapters
|
|
812
868
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
|
816
|
-
|
|
|
817
|
-
| **
|
|
818
|
-
| **
|
|
819
|
-
| **
|
|
820
|
-
| **
|
|
821
|
-
|
|
869
|
+
### Server & meta-framework
|
|
870
|
+
|
|
871
|
+
| Adapter | Import | Description |
|
|
872
|
+
| ----------- | ----------------------------------------------- | ------------------------------------------------------- |
|
|
873
|
+
| **Express** | `katanakit-js/adapters/express` | Reference server with CORS and hardened headers |
|
|
874
|
+
| **Bun** | `katanakit-js/adapters/bun` | `Bun.serve` route table + dummyjson.com demo |
|
|
875
|
+
| **Nuxt** | `katanakit-js/adapters/nuxt` | `useUnwrap`, `useSafeResponse`, `useEventResponse` |
|
|
876
|
+
| **Astro** | `katanakit-js` or `katanakit-js/adapters/astro` | `AstroService`, `RssService` |
|
|
877
|
+
|
|
878
|
+
### UI frameworks
|
|
879
|
+
|
|
880
|
+
Each subpath is a complete entry point: it re-exports the query client helpers
|
|
881
|
+
and adds the framework's native reactivity over TanStack Query Core.
|
|
882
|
+
|
|
883
|
+
| Adapter | Import | Bindings |
|
|
884
|
+
| ----------- | ------------------------------ | --------------------------------------------------- |
|
|
885
|
+
| **React** | `katanakit-js/adapters/react` | `useQuery`, `useMutation`, `useRequest`, `useWatch` |
|
|
886
|
+
| **Vue** | `katanakit-js/adapters/vue` | `useQuery`, `useMutation`, `useRequest`, `useWatch` |
|
|
887
|
+
| **Solid** | `katanakit-js/adapters/solid` | `useQuery`, `useMutation`, `useRequest`, `useWatch` |
|
|
888
|
+
| **Svelte** | `katanakit-js/adapters/svelte` | `useQuery`, `useMutation`, `useRequest`, `useWatch` |
|
|
889
|
+
| **Angular** | `katanakit-js/adapters/angular` | `useQuery`, `useMutation`, `useRequest`, `useWatch` |
|
|
890
|
+
| **Vanilla** | `katanakit-js/adapters/vanilla` | Raw `QueryObserver` / `MutationObserver`, no framework |
|
|
891
|
+
|
|
892
|
+
### Assistant & messaging
|
|
893
|
+
|
|
894
|
+
| Adapter | Import | Description |
|
|
895
|
+
| ------------- | --------------------------------- | ------------------------------------------------------------------ |
|
|
896
|
+
| **Assistant** | `katanakit-js/adapters/assistant` | REST digital assistant (`useStartAssistant`) |
|
|
897
|
+
| **Telegram** | `katanakit-js/adapters/telegram` | BotFather bot (`defineTelegramConfig`, `useStartTelegramPolling`) |
|
|
898
|
+
| **WhatsApp** | `katanakit-js/adapters/whatsapp` | Meta Cloud API (`defineWhatsAppConfig`, `useStartWhatsApp`) |
|
|
822
899
|
|
|
823
900
|
## UI and Auth Adapters
|
|
824
901
|
|
package/package.json
CHANGED