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
package/README.md
CHANGED
|
@@ -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",
|
|
@@ -329,8 +363,9 @@ const stop = useKatanaWatch(newProduct, () => checkValidations(), { deep: true }
|
|
|
329
363
|
- **Hexagonal architecture** — pure core, infrastructure adapters, framework adapters
|
|
330
364
|
- **Tree-shakeable** — destructured re-exports from Singleton facades
|
|
331
365
|
- **SSR-safe** — all infrastructure adapters guard or fall back gracefully in server environments
|
|
332
|
-
- **Filesystem (Node/Bun)** — `useReadFile`, `useWriteFile`, `useReadJsonFile`, `useReadModuleJson` and friends return Safe Results with native errno codes, loaded lazily through dynamic `import()` and guarded by `useIsNode()`
|
|
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()`
|
|
333
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/))
|
|
334
369
|
|
|
335
370
|
## Filesystem (Node/Bun)
|
|
336
371
|
|
|
@@ -372,6 +407,7 @@ const files = await useReadDir("data/cache", { recursive: true });
|
|
|
372
407
|
| Read | `useReadFile`, `useReadFileBuffer`, `useReadJsonFile`, `useReadModuleFile`, `useReadModuleJson` |
|
|
373
408
|
| Write | `useWriteFile`, `useAppendFile`, `useWriteJsonFile`, `useEnsureDir` |
|
|
374
409
|
| Inspect | `useFileExists`, `useGetFileStats`, `useReadDir` |
|
|
410
|
+
| Checksums | `useHashFile`, `useVerifyFileHash` — streaming `md5`/`sha1`/`sha256`/`sha512` digests (`sha256` by default) and case-insensitive verification |
|
|
375
411
|
| Move / delete | `useCopyFile`, `useMoveFile`, `useRemoveFile`, `useRemoveDir` |
|
|
376
412
|
| Paths | `useGetDirname`, `useResolvePath`, `useJoinPath`, `useGetRelativePath`, `useGetBasename`, `useGetFileExtension`, `useGetCwd`, `useIsNode` |
|
|
377
413
|
|
|
@@ -650,9 +686,9 @@ app.use(
|
|
|
650
686
|
Long polling does not need a public URL. Session ids are `telegram:<chatId>`.
|
|
651
687
|
|
|
652
688
|
```ts
|
|
653
|
-
import {
|
|
689
|
+
import { defineTelegramConfig, useStartTelegramPolling } from "katanakit-js/adapters/telegram";
|
|
654
690
|
|
|
655
|
-
|
|
691
|
+
defineTelegramConfig({ token: process.env.TELEGRAM_BOT_TOKEN });
|
|
656
692
|
await useStartTelegramPolling();
|
|
657
693
|
```
|
|
658
694
|
|
|
@@ -668,9 +704,9 @@ await useStartTelegramPolling();
|
|
|
668
704
|
Webhook: `GET` / `POST` `/whatsapp/webhook`. Session ids are `wa:<phone>`.
|
|
669
705
|
|
|
670
706
|
```ts
|
|
671
|
-
import {
|
|
707
|
+
import { defineWhatsAppConfig, useStartWhatsApp } from "katanakit-js/adapters/whatsapp";
|
|
672
708
|
|
|
673
|
-
|
|
709
|
+
defineWhatsAppConfig({
|
|
674
710
|
token: process.env.WHATSAPP_TOKEN,
|
|
675
711
|
phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID,
|
|
676
712
|
verifyToken: process.env.WHATSAPP_VERIFY_TOKEN,
|
|
@@ -727,15 +763,15 @@ product FAQ, CRM, or ticket system. Keep the `{ name, description, parameters, e
|
|
|
727
763
|
|
|
728
764
|
## Framework usage
|
|
729
765
|
|
|
730
|
-
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`.
|
|
731
767
|
|
|
732
768
|
### Astro (npm)
|
|
733
769
|
|
|
734
770
|
```astro
|
|
735
771
|
---
|
|
736
772
|
// Frontmatter = server
|
|
737
|
-
import { useLogger, useGetApi,
|
|
738
|
-
|
|
773
|
+
import { useLogger, useGetApi, defineApiConfig } from "katanakit-js";
|
|
774
|
+
defineApiConfig({ /* ... */ });
|
|
739
775
|
const result = await useGetApi("pokeapi", "pokemonById", { params: { id: 25 } });
|
|
740
776
|
---
|
|
741
777
|
<script>
|
|
@@ -757,7 +793,7 @@ const result = await useGetApi("pokeapi", "pokemonById", { params: { id: 25 } })
|
|
|
757
793
|
### Vue / Nuxt / vanilla
|
|
758
794
|
|
|
759
795
|
```ts
|
|
760
|
-
import { useLogger,
|
|
796
|
+
import { useLogger, defineApiConfig, useGetApi } from "katanakit-js";
|
|
761
797
|
import { useRequest } from "katanakit-js/adapters/vue"; // Vue only
|
|
762
798
|
import { useUnwrap } from "katanakit-js/adapters/nuxt"; // Nuxt only
|
|
763
799
|
```
|
|
@@ -780,8 +816,8 @@ See [Getting Started](https://docs.senseikatana.com/guides/getting-started) for
|
|
|
780
816
|
| **Vue** | `katanakit-js/adapters/vue` | `useRequest` composable with reactivity |
|
|
781
817
|
| **Astro** | `katanakit-js` or `katanakit-js/adapters/astro` | `AstroService`, `RssService` |
|
|
782
818
|
| **Assistant** | `katanakit-js/adapters/assistant` | REST digital assistant (`useStartAssistant`) |
|
|
783
|
-
| **Telegram** | `katanakit-js/adapters/telegram` | BotFather bot (`
|
|
784
|
-
| **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`) |
|
|
785
821
|
|
|
786
822
|
## REST API Adapters
|
|
787
823
|
|
|
@@ -806,10 +842,10 @@ full TypeScript types, cursor-based auto-pagination, and Safe Results.
|
|
|
806
842
|
#### Setup
|
|
807
843
|
|
|
808
844
|
```ts
|
|
809
|
-
import {
|
|
845
|
+
import { defineNotionConfig } from "katanakit-js/adapters/notion";
|
|
810
846
|
|
|
811
847
|
// Token starts with "ntn_" or "secret_" — get one at https://www.notion.so/my-integrations
|
|
812
|
-
|
|
848
|
+
defineNotionConfig({ token: process.env.NOTION_TOKEN });
|
|
813
849
|
```
|
|
814
850
|
|
|
815
851
|
#### Pages — read, create, update, archive
|
|
@@ -1015,22 +1051,22 @@ and batch operations. All functions return `FetchResult<T>`.
|
|
|
1015
1051
|
#### Setup
|
|
1016
1052
|
|
|
1017
1053
|
```ts
|
|
1018
|
-
import {
|
|
1054
|
+
import { defineWordPressConfig } from "katanakit-js/adapters/wordpress";
|
|
1019
1055
|
|
|
1020
1056
|
// Application Passwords (recommended) — WP Admin → Users → Your Profile → Application Passwords
|
|
1021
|
-
|
|
1057
|
+
defineWordPressConfig({
|
|
1022
1058
|
baseUrl: "https://mysite.com",
|
|
1023
1059
|
auth: { type: "application-passwords", username: "admin", password: "xxxx xxxx xxxx" },
|
|
1024
1060
|
});
|
|
1025
1061
|
|
|
1026
1062
|
// JWT tokens
|
|
1027
|
-
|
|
1063
|
+
defineWordPressConfig({
|
|
1028
1064
|
baseUrl: "https://mysite.com",
|
|
1029
1065
|
auth: { type: "jwt", token: "eyJhbGci..." },
|
|
1030
1066
|
});
|
|
1031
1067
|
|
|
1032
1068
|
// Nonce-based (for WP themes)
|
|
1033
|
-
|
|
1069
|
+
defineWordPressConfig({
|
|
1034
1070
|
baseUrl: "https://mysite.com",
|
|
1035
1071
|
auth: { type: "nonce", nonce: "abc123" },
|
|
1036
1072
|
});
|
|
@@ -1370,10 +1406,10 @@ Safe Result contract, validates every input, and refuses mass writes (update/del
|
|
|
1370
1406
|
require non-empty filters).
|
|
1371
1407
|
|
|
1372
1408
|
```ts
|
|
1373
|
-
import {
|
|
1409
|
+
import { defineInsforgeConfig, useIfSelect, useIfInsert } from "katanakit-js/adapters/insforge";
|
|
1374
1410
|
|
|
1375
1411
|
// Server-only admin client (apiKey), or browser-safe client (anonKey)
|
|
1376
|
-
|
|
1412
|
+
defineInsforgeConfig({ baseUrl: process.env.INSFORGE_URL!, apiKey: process.env.INSFORGE_API_KEY! });
|
|
1377
1413
|
|
|
1378
1414
|
const posts = await useIfSelect<{ id: number; title: string }>({
|
|
1379
1415
|
table: "posts",
|
|
@@ -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,CAAC,IAAI,CAAC,CAAC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AAO,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,MAAM,qCAAqC,CAAC;AAG/D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AU,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,CAAC,QAAQ,CAAC,CAAC;CACtF;AAED
|
|
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,CAAC,QAAQ,CAAC,CAAC;CACtF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,gBAAqB,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAWlF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAE5F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAE9D;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,sBAAsB,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9E"}
|
|
@@ -13,9 +13,10 @@ let server = null;
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* import {
|
|
16
|
+
* import { dummyJsonApiConfig, useBunCreate } from "katanakit-js/adapters/bun";
|
|
17
|
+
* import { defineApiConfig } from "katanakit-js";
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
+
* defineApiConfig(dummyJsonApiConfig);
|
|
19
20
|
* const server = useBunCreate({ port: 3000 });
|
|
20
21
|
* console.log(`Server running at ${server.url}`);
|
|
21
22
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/adapters/bun/server.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,OAAO,EAAwB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE5E,yCAAyC;AACzC,IAAI,MAAM,GAAiC,IAAI,CAAC;AAchD
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/adapters/bun/server.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,OAAO,EAAwB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE5E,yCAAyC;AACzC,IAAI,MAAM,GAAiC,IAAI,CAAC;AAchD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,UAA4B,EAAE;IAC1D,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,GAAG,GAAG,CAAC,KAAK,CAAY;QAC7B,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;QAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,WAAW;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,uBAAuB,EAAE;QACnD,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClD,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAsB,EAAE,QAAiB;IACpE,OAAO,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,sBAAsB,GAAG,KAAK;IAC9D,IAAI,MAAM,EAAE,CAAC;QACZ,MAAM,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC1C,MAAM,GAAG,IAAI,CAAC;IACf,CAAC;AACF,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export type { IfConfig, IfInsertRows, IfInvokeOptions, IfListOptions, IfOrder, IfRpcCall, IfStorageRef, IfTableQuery, IfUpdatePatch, IfWriteQuery, } from "../../types/index.js";
|
|
2
|
-
export { useGetInsforgeClient, useIfDelete, useIfDownload, useIfGetPublicUrl, useIfInsert, useIfInvokeFunction, useIfListObjects, useIfRemove, useIfRpc, useIfSelect, useIfUpdate, useIfUpload, useInitInsforge, } from "./insforge.service.js";
|
|
2
|
+
export { defineInsforgeConfig, useGetInsforgeClient, useIfDelete, useIfDownload, useIfGetPublicUrl, useIfInsert, useIfInvokeFunction, useIfListObjects, useIfRemove, useIfRpc, useIfSelect, useIfUpdate, useIfUpload, useInitInsforge, } from "./insforge.service.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/insforge/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,aAAa,EACb,OAAO,EACP,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,GACf,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/insforge/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,aAAa,EACb,OAAO,EACP,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,GACf,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useGetInsforgeClient, useIfDelete, useIfDownload, useIfGetPublicUrl, useIfInsert, useIfInvokeFunction, useIfListObjects, useIfRemove, useIfRpc, useIfSelect, useIfUpdate, useIfUpload, useInitInsforge, } from "./insforge.service.js";
|
|
1
|
+
export { defineInsforgeConfig, useGetInsforgeClient, useIfDelete, useIfDownload, useIfGetPublicUrl, useIfInsert, useIfInvokeFunction, useIfListObjects, useIfRemove, useIfRpc, useIfSelect, useIfUpdate, useIfUpload, useInitInsforge, } from "./insforge.service.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/insforge/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACN,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,GACf,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/insforge/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,GACf,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
import { type InsForgeClient } from "@insforge/sdk";
|
|
2
|
-
import type { FetchResult, IfConfig, IfInsertRows, IfInvokeOptions, IfListOptions, IfRpcCall, IfStorageRef, IfTableQuery, IfUpdatePatch, IfWriteQuery } from "../../types/index.js";
|
|
2
|
+
import type { ConfigFacade, FetchResult, IfConfig, IfInsertRows, IfInvokeOptions, IfListOptions, IfRpcCall, IfStorageRef, IfTableQuery, IfUpdatePatch, IfWriteQuery } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Registers the InsForge client and returns your methods alongside it — the
|
|
5
|
+
* config-file entry point. One call is the whole setup: no separate
|
|
6
|
+
* `useInitInsforge(...)` step.
|
|
7
|
+
*
|
|
8
|
+
* Prefer `apiKey` (server-only, admin) or `anonKey` (browser-safe) depending
|
|
9
|
+
* on the runtime. Declare methods with `function` (never arrows) so
|
|
10
|
+
* `this.config` resolves to the config you declared.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam T - The literal passed in: InsForge config plus any methods.
|
|
13
|
+
* @param input - Backend URL + credentials + optional schema, plus your methods.
|
|
14
|
+
* @returns The declared config plus your methods (see {@link ConfigFacade}).
|
|
15
|
+
* @throws {Error} If the config fails validation.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { defineInsforgeConfig } from "katanakit-js/adapters/insforge";
|
|
20
|
+
*
|
|
21
|
+
* export default defineInsforgeConfig({
|
|
22
|
+
* baseUrl: "https://app.insforge.app",
|
|
23
|
+
* anonKey: "…",
|
|
24
|
+
* listUsers: async function () {
|
|
25
|
+
* return useIfSelect("users");
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function defineInsforgeConfig<T extends IfConfig>(input: T & ThisType<ConfigFacade<T>>): ConfigFacade<T>;
|
|
3
31
|
/**
|
|
4
32
|
* Registers the InsForge client. Call once per app. Prefer `apiKey`
|
|
5
33
|
* (server-only, admin) or `anonKey` (browser-safe) depending on the runtime.
|
|
6
34
|
*
|
|
35
|
+
* @deprecated Use {@link defineInsforgeConfig}, which registers the config and
|
|
36
|
+
* returns it with any methods declared on the same literal.
|
|
37
|
+
*
|
|
7
38
|
* @param config - Backend URL + credentials + optional schema.
|
|
8
39
|
* @throws {Error} If the config fails validation.
|
|
9
40
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insforge.service.d.ts","sourceRoot":"","sources":["../../../src/adapters/insforge/insforge.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"insforge.service.d.ts","sourceRoot":"","sources":["../../../src/adapters/insforge/insforge.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAiBrF,OAAO,KAAK,EAEX,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,MAAM,sBAAsB,CAAC;AAkJ9B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,QAAQ,EACtD,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAClC,YAAY,CAAC,CAAC,CAAC,CAKjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,GAAG,IA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AAG,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAsBjF;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAChC,GAAG,EAAE,YAAY,GACf,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAW/C;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa,GACrB,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAa/C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG,WAAW,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAiBvF;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EACpD,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAazB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAdminClient, createClient } from "@insforge/sdk";
|
|
2
|
+
import { useSplitConfig } from "../../core/services/utils.service.js";
|
|
2
3
|
import { useValidate } from "../../core/services/validation.service.js";
|
|
3
4
|
import { IfBucketSchema, IfConfigSchema, IfInsertRowsSchema, IfInvokeOptionsSchema, IfListOptionsSchema, IfRpcCallSchema, IfStorageRefSchema, IfTableNameSchema, IfTableQuerySchema, IfUpdatePatchSchema, IfWriteQuerySchema, } from "../../schemas/insforge.schema.js";
|
|
4
5
|
/** Module-level client. InsForge is the database fallback, not the default. */
|
|
@@ -70,7 +71,7 @@ function invalidInput(parsed) {
|
|
|
70
71
|
function notConfigured() {
|
|
71
72
|
return {
|
|
72
73
|
data: null,
|
|
73
|
-
error: { message: "[InsForge] Not configured. Call
|
|
74
|
+
error: { message: "[InsForge] Not configured. Call defineInsforgeConfig() first.", status: 0 },
|
|
74
75
|
url: "",
|
|
75
76
|
status: 0,
|
|
76
77
|
ok: false,
|
|
@@ -103,10 +104,46 @@ function scopedDatabase(database, schema) {
|
|
|
103
104
|
}
|
|
104
105
|
return database;
|
|
105
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Registers the InsForge client and returns your methods alongside it — the
|
|
109
|
+
* config-file entry point. One call is the whole setup: no separate
|
|
110
|
+
* `useInitInsforge(...)` step.
|
|
111
|
+
*
|
|
112
|
+
* Prefer `apiKey` (server-only, admin) or `anonKey` (browser-safe) depending
|
|
113
|
+
* on the runtime. Declare methods with `function` (never arrows) so
|
|
114
|
+
* `this.config` resolves to the config you declared.
|
|
115
|
+
*
|
|
116
|
+
* @typeParam T - The literal passed in: InsForge config plus any methods.
|
|
117
|
+
* @param input - Backend URL + credentials + optional schema, plus your methods.
|
|
118
|
+
* @returns The declared config plus your methods (see {@link ConfigFacade}).
|
|
119
|
+
* @throws {Error} If the config fails validation.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { defineInsforgeConfig } from "katanakit-js/adapters/insforge";
|
|
124
|
+
*
|
|
125
|
+
* export default defineInsforgeConfig({
|
|
126
|
+
* baseUrl: "https://app.insforge.app",
|
|
127
|
+
* anonKey: "…",
|
|
128
|
+
* listUsers: async function () {
|
|
129
|
+
* return useIfSelect("users");
|
|
130
|
+
* },
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export function defineInsforgeConfig(input) {
|
|
135
|
+
const { config, methods } = useSplitConfig(input);
|
|
136
|
+
// Zod strips the method entries, so the whole literal is safe to validate.
|
|
137
|
+
useInitInsforge(input);
|
|
138
|
+
return { config, ...methods };
|
|
139
|
+
}
|
|
106
140
|
/**
|
|
107
141
|
* Registers the InsForge client. Call once per app. Prefer `apiKey`
|
|
108
142
|
* (server-only, admin) or `anonKey` (browser-safe) depending on the runtime.
|
|
109
143
|
*
|
|
144
|
+
* @deprecated Use {@link defineInsforgeConfig}, which registers the config and
|
|
145
|
+
* returns it with any methods declared on the same literal.
|
|
146
|
+
*
|
|
110
147
|
* @param config - Backend URL + credentials + optional schema.
|
|
111
148
|
* @throws {Error} If the config fails validation.
|
|
112
149
|
*
|