katanakit-js 4.0.4 → 5.2.0
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 +184 -10
- 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 +116 -0
- package/dist/adapters/insforge/insforge.service.d.ts.map +1 -0
- package/dist/adapters/insforge/insforge.service.js +437 -0
- package/dist/adapters/insforge/insforge.service.js.map +1 -0
- package/dist/adapters/notion/notion.service.d.ts.map +1 -1
- package/dist/adapters/notion/notion.service.js +72 -54
- package/dist/adapters/notion/notion.service.js.map +1 -1
- package/dist/adapters/wordpress/wordpress.service.d.ts.map +1 -1
- package/dist/adapters/wordpress/wordpress.service.js +163 -85
- 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.map +1 -1
- package/dist/core/services/http.service.js +10 -16
- 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/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/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 +191 -800
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +40 -15
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
|
```
|
|
@@ -323,11 +323,151 @@ const stop = useKatanaWatch(newProduct, () => checkValidations(), { deep: true }
|
|
|
323
323
|
|
|
324
324
|
## Features
|
|
325
325
|
|
|
326
|
-
- **Safe Results** — HTTP (and other fallible) operations return `{ data, error, ok }` instead of throwing
|
|
326
|
+
- **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))
|
|
327
|
+
- **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
328
|
- **Zero side effects** — importing any module is safe. No `fetch` calls, no `console.log`, no storage writes
|
|
328
329
|
- **Hexagonal architecture** — pure core, infrastructure adapters, framework adapters
|
|
329
330
|
- **Tree-shakeable** — destructured re-exports from Singleton facades
|
|
330
331
|
- **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()`
|
|
333
|
+
- **Fake data (optional)** — `useFakeVehicle`, `useFakeEmail`, `useFakeList`, … via an optional, lazy-loaded `@faker-js/faker` peer
|
|
334
|
+
|
|
335
|
+
## Filesystem (Node/Bun)
|
|
336
|
+
|
|
337
|
+
Node-only helpers that wrap `node:fs/promises` and `node:path` with the Safe
|
|
338
|
+
Result contract. Built-ins load through dynamic `import()`, so importing them is
|
|
339
|
+
browser-safe; outside Node/Bun every fallible call returns `ERR_FS_UNAVAILABLE`
|
|
340
|
+
instead of throwing.
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
import {
|
|
344
|
+
useEnsureDir,
|
|
345
|
+
useReadDir,
|
|
346
|
+
useReadJsonFile,
|
|
347
|
+
useReadModuleJson,
|
|
348
|
+
useWriteJsonFile,
|
|
349
|
+
} from "katanakit-js";
|
|
350
|
+
import { z } from "zod";
|
|
351
|
+
|
|
352
|
+
const BooksSchema = z.array(z.object({ title: z.string() }));
|
|
353
|
+
|
|
354
|
+
// Read relative to the current module (the __dirname pattern, without __dirname)
|
|
355
|
+
const result = await useReadModuleJson(import.meta.url, "../data/books.json", BooksSchema);
|
|
356
|
+
|
|
357
|
+
if (result.ok) {
|
|
358
|
+
console.log(result.data);
|
|
359
|
+
} else {
|
|
360
|
+
console.error(result.error.code, result.error.message); // ENOENT | ERR_VALIDATION | ...
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Or with an explicit path (relative paths resolve against process.cwd())
|
|
364
|
+
await useEnsureDir("data/cache");
|
|
365
|
+
await useWriteJsonFile("data/cache/books.json", [{ title: "Kata" }]);
|
|
366
|
+
const books = await useReadJsonFile("data/cache/books.json", BooksSchema);
|
|
367
|
+
const files = await useReadDir("data/cache", { recursive: true });
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
| Group | Helpers |
|
|
371
|
+
| ----- | ------- |
|
|
372
|
+
| Read | `useReadFile`, `useReadFileBuffer`, `useReadJsonFile`, `useReadModuleFile`, `useReadModuleJson` |
|
|
373
|
+
| Write | `useWriteFile`, `useAppendFile`, `useWriteJsonFile`, `useEnsureDir` |
|
|
374
|
+
| Inspect | `useFileExists`, `useGetFileStats`, `useReadDir` |
|
|
375
|
+
| Move / delete | `useCopyFile`, `useMoveFile`, `useRemoveFile`, `useRemoveDir` |
|
|
376
|
+
| Paths | `useGetDirname`, `useResolvePath`, `useJoinPath`, `useGetRelativePath`, `useGetBasename`, `useGetFileExtension`, `useGetCwd`, `useIsNode` |
|
|
377
|
+
|
|
378
|
+
## Fake data (optional)
|
|
379
|
+
|
|
380
|
+
`@faker-js/faker` is an **optional peer dependency**: these helpers load it
|
|
381
|
+
through dynamic `import()` on first call, so install it only if you use them
|
|
382
|
+
(`bun add @faker-js/faker` / `npm install @faker-js/faker`).
|
|
383
|
+
|
|
384
|
+
| Group | Helpers |
|
|
385
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
386
|
+
| People / internet | `useFakeFullName`, `useFakeFirstName`, `useFakeLastName`, `useFakeEmail`, `useFakePhone`, `useFakeCompanyName`, `useFakeUrl` |
|
|
387
|
+
| Values | `useFakeUuid`, `useFakeText`, `useFakeNumber`, `useFakeBoolean`, `useFakeDate`, `useFakeVehicle` |
|
|
388
|
+
| Collections | `useFakeList(factory, count)` — the factory receives the zero-based index |
|
|
389
|
+
| Reproducibility | `useFakeSeed(seed?)`, `useFakeSetDefaultRefDate(refDate?)` |
|
|
390
|
+
|
|
391
|
+
### Reproducible seeds
|
|
392
|
+
|
|
393
|
+
`useFakeSeed(42)` sets the seed **and returns it**. Call it with no arguments to
|
|
394
|
+
roll a fresh random seed (also returned) — log it in CI and pass it back later
|
|
395
|
+
to replay the exact run. `useFakeSetDefaultRefDate("2026-01-01")` pins the
|
|
396
|
+
reference date used by date helpers. Same seed + same reference date + same
|
|
397
|
+
call order + same faker major = identical output.
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
import { useFakeSeed, useFakeSetDefaultRefDate, useFakeUuid } from "katanakit-js";
|
|
401
|
+
|
|
402
|
+
const seed = await useFakeSeed(); // e.g. 1696121567592875 — log it in CI
|
|
403
|
+
await useFakeSetDefaultRefDate("2026-01-01");
|
|
404
|
+
|
|
405
|
+
await useFakeSeed(seed); // replay the exact same sequence
|
|
406
|
+
const id = await useFakeUuid();
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Seed data (users, products, orders)
|
|
410
|
+
|
|
411
|
+
Compose the helpers with `useFakeList` to build realistic fixtures, then write
|
|
412
|
+
them anywhere with the [filesystem helpers](#filesystem-nodebun):
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
import {
|
|
416
|
+
useEnsureDir,
|
|
417
|
+
useFakeDate,
|
|
418
|
+
useFakeEmail,
|
|
419
|
+
useFakeFullName,
|
|
420
|
+
useFakeList,
|
|
421
|
+
useFakeNumber,
|
|
422
|
+
useFakeSeed,
|
|
423
|
+
useFakeSetDefaultRefDate,
|
|
424
|
+
useFakeText,
|
|
425
|
+
useFakeUuid,
|
|
426
|
+
useWriteJsonFile,
|
|
427
|
+
} from "katanakit-js";
|
|
428
|
+
|
|
429
|
+
await useFakeSeed(42);
|
|
430
|
+
await useFakeSetDefaultRefDate("2026-01-01");
|
|
431
|
+
|
|
432
|
+
const users = await useFakeList(
|
|
433
|
+
async () => ({
|
|
434
|
+
id: await useFakeUuid(),
|
|
435
|
+
fullName: await useFakeFullName(),
|
|
436
|
+
email: await useFakeEmail(),
|
|
437
|
+
createdAt: (await useFakeDate("2024-01-01")).toISOString(),
|
|
438
|
+
}),
|
|
439
|
+
5,
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
const products = await useFakeList(
|
|
443
|
+
async () => ({
|
|
444
|
+
id: await useFakeUuid(),
|
|
445
|
+
name: await useFakeText(3),
|
|
446
|
+
price: await useFakeNumber(5, 250),
|
|
447
|
+
stock: await useFakeNumber(0, 120),
|
|
448
|
+
}),
|
|
449
|
+
8,
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
// Relations: the factory receives the index
|
|
453
|
+
const orders = await useFakeList(
|
|
454
|
+
async (index) => ({
|
|
455
|
+
id: await useFakeUuid(),
|
|
456
|
+
userId: users[index % users.length].id,
|
|
457
|
+
productId: products[index % products.length].id,
|
|
458
|
+
quantity: await useFakeNumber(1, 6),
|
|
459
|
+
placedAt: (await useFakeDate("2025-01-01")).toISOString(),
|
|
460
|
+
}),
|
|
461
|
+
12,
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
await useEnsureDir("data/seed");
|
|
465
|
+
await useWriteJsonFile("data/seed/users.json", users);
|
|
466
|
+
// feed the arrays to your seeder: prisma.user.createMany({ data: users }), ...
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
A runnable version (users, products and orders with relations, written as JSON)
|
|
470
|
+
lives in [`examples/seed/`](./examples/seed/README.md).
|
|
331
471
|
|
|
332
472
|
## AI assistant (Kitt)
|
|
333
473
|
|
|
@@ -629,7 +769,7 @@ import { useUnwrap } from "katanakit-js/adapters/nuxt"; // Nuxt only
|
|
|
629
769
|
</script>
|
|
630
770
|
```
|
|
631
771
|
|
|
632
|
-
See [Getting Started](https://docs.senseikatana.com/
|
|
772
|
+
See [Getting Started](https://docs.senseikatana.com/guides/getting-started) for full recipes.
|
|
633
773
|
|
|
634
774
|
## Framework Adapters
|
|
635
775
|
|
|
@@ -652,6 +792,11 @@ All functions return `FetchResult<T>` — the same Safe Result pattern used by t
|
|
|
652
792
|
| ------------- | --------------------------------- | ----------------------------------------------------------------- |
|
|
653
793
|
| **Notion** | `katanakit-js/adapters/notion` | Pages, databases, blocks, search with cursor pagination |
|
|
654
794
|
| **WordPress** | `katanakit-js/adapters/wordpress` | Posts, pages, media, categories, tags, comments, users, batch ops |
|
|
795
|
+
| **InsForge** | `katanakit-js/adapters/insforge` | Database fallback, storage buckets and edge functions |
|
|
796
|
+
|
|
797
|
+
All REST adapters validate responses with Zod: malformed payloads return a typed `502`
|
|
798
|
+
Safe Result instead of untyped garbage, and invalid inputs are rejected with `400`
|
|
799
|
+
before any network call.
|
|
655
800
|
|
|
656
801
|
### Notion
|
|
657
802
|
|
|
@@ -1217,6 +1362,34 @@ const full = await useWpGetPosts({
|
|
|
1217
1362
|
| **Next.js** | [`examples/wordpress/next-[slug].tsx`](https://github.com/senseikatana/katanakit-js/tree/main/examples/wordpress/next-[slug].tsx) | Dynamic `[slug]` page |
|
|
1218
1363
|
| **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
1364
|
|
|
1365
|
+
### InsForge (database fallback)
|
|
1366
|
+
|
|
1367
|
+
InsForge is supported as the **database fallback** (the primary data layer is Cloudflare),
|
|
1368
|
+
plus object storage and edge functions. The adapter wraps the official SDK in the same
|
|
1369
|
+
Safe Result contract, validates every input, and refuses mass writes (update/delete
|
|
1370
|
+
require non-empty filters).
|
|
1371
|
+
|
|
1372
|
+
```ts
|
|
1373
|
+
import { useInitInsforge, useIfSelect, useIfInsert } from "katanakit-js/adapters/insforge";
|
|
1374
|
+
|
|
1375
|
+
// Server-only admin client (apiKey), or browser-safe client (anonKey)
|
|
1376
|
+
useInitInsforge({ baseUrl: process.env.INSFORGE_URL!, apiKey: process.env.INSFORGE_API_KEY! });
|
|
1377
|
+
|
|
1378
|
+
const posts = await useIfSelect<{ id: number; title: string }>({
|
|
1379
|
+
table: "posts",
|
|
1380
|
+
filters: { author_id: 7 },
|
|
1381
|
+
order: { column: "created_at", ascending: false },
|
|
1382
|
+
limit: 10,
|
|
1383
|
+
});
|
|
1384
|
+
if (posts.ok) console.log(posts.data);
|
|
1385
|
+
|
|
1386
|
+
const created = await useIfInsert("posts", [{ title: "Hello" }]);
|
|
1387
|
+
```
|
|
1388
|
+
|
|
1389
|
+
Storage (`useIfUpload`, `useIfDownload`, `useIfRemove`, `useIfListObjects`,
|
|
1390
|
+
`useIfGetPublicUrl`) and edge functions (`useIfInvokeFunction`) follow the same pattern.
|
|
1391
|
+
Install the optional peer with `bun add @insforge/sdk`.
|
|
1392
|
+
|
|
1220
1393
|
## Contributing
|
|
1221
1394
|
|
|
1222
1395
|
We welcome contributions from the community! Whether it's fixing a bug, adding
|
|
@@ -1253,14 +1426,15 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full development contract.
|
|
|
1253
1426
|
|
|
1254
1427
|
## Documentation
|
|
1255
1428
|
|
|
1256
|
-
The docs site is deployed with Cloudflare Pages at [docs.senseikatana.com](https://docs.senseikatana.com/).
|
|
1429
|
+
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
1430
|
|
|
1258
|
-
- [Getting Started](https://docs.senseikatana.com/
|
|
1259
|
-
- [
|
|
1260
|
-
- [
|
|
1261
|
-
- [
|
|
1262
|
-
- [
|
|
1263
|
-
- [
|
|
1431
|
+
- [Getting Started](https://docs.senseikatana.com/guides/getting-started)
|
|
1432
|
+
- [Error Handling](https://docs.senseikatana.com/guides/errors)
|
|
1433
|
+
- [Architecture](https://docs.senseikatana.com/guides/architecture)
|
|
1434
|
+
- [UI Kit (Katana UI)](https://docs.senseikatana.com/ui-kit/)
|
|
1435
|
+
- [API Reference](https://docs.senseikatana.com/api/)
|
|
1436
|
+
- [Roadmap](https://docs.senseikatana.com/guides/roadmap)
|
|
1437
|
+
- [Changelog](https://docs.senseikatana.com/changelog)
|
|
1264
1438
|
|
|
1265
1439
|
## License
|
|
1266
1440
|
|
|
@@ -0,0 +1,3 @@
|
|
|
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";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type InsForgeClient } from "@insforge/sdk";
|
|
2
|
+
import type { FetchResult, IfConfig, IfInsertRows, IfInvokeOptions, IfListOptions, IfRpcCall, IfStorageRef, IfTableQuery, IfUpdatePatch, IfWriteQuery } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Registers the InsForge client. Call once per app. Prefer `apiKey`
|
|
5
|
+
* (server-only, admin) or `anonKey` (browser-safe) depending on the runtime.
|
|
6
|
+
*
|
|
7
|
+
* @param config - Backend URL + credentials + optional schema.
|
|
8
|
+
* @throws {Error} If the config fails validation.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { useInitInsforge } from "katanakit-js/adapters/insforge";
|
|
13
|
+
*
|
|
14
|
+
* useInitInsforge({ baseUrl: "https://app.insforge.app", anonKey: "…" });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useInitInsforge(config: IfConfig): void;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the initialized client (or `null` before `useInitInsforge`).
|
|
20
|
+
* Exposed for advanced use — the wrappers cover the supported surface.
|
|
21
|
+
*
|
|
22
|
+
* @returns The InsForge client or `null`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useGetInsforgeClient(): InsForgeClient | null;
|
|
25
|
+
/**
|
|
26
|
+
* Reads rows from a table with equality filters, ordering and pagination.
|
|
27
|
+
*
|
|
28
|
+
* @param query - Table, columns, filters, order, limit and offset.
|
|
29
|
+
* @returns Safe Result with the rows.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const result = await useIfSelect<Post>({ table: "posts", filters: { author_id: 7 } });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function useIfSelect<T = Record<string, unknown>>(query: IfTableQuery): Promise<FetchResult<T[]>>;
|
|
37
|
+
/**
|
|
38
|
+
* Inserts one or more rows and returns the created rows.
|
|
39
|
+
*
|
|
40
|
+
* @param table - Table name.
|
|
41
|
+
* @param rows - Rows to insert (at least one).
|
|
42
|
+
* @param schema - Optional schema override.
|
|
43
|
+
* @returns Safe Result with the inserted rows.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useIfInsert<T = Record<string, unknown>>(table: string, rows: IfInsertRows, schema?: string): Promise<FetchResult<T[]>>;
|
|
46
|
+
/**
|
|
47
|
+
* Updates rows matching the filters and returns the updated rows.
|
|
48
|
+
* Filters are REQUIRED — mass updates are refused at validation time.
|
|
49
|
+
*
|
|
50
|
+
* @param query - Table + mandatory filters (+ optional schema).
|
|
51
|
+
* @param patch - Column patch (must not be empty).
|
|
52
|
+
* @returns Safe Result with the updated rows.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useIfUpdate<T = Record<string, unknown>>(query: IfWriteQuery, patch: IfUpdatePatch): Promise<FetchResult<T[]>>;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes rows matching the filters and returns the deleted rows.
|
|
57
|
+
* Filters are REQUIRED — mass deletes are refused at validation time.
|
|
58
|
+
*
|
|
59
|
+
* @param query - Table + mandatory filters (+ optional schema).
|
|
60
|
+
* @returns Safe Result with the deleted rows.
|
|
61
|
+
*/
|
|
62
|
+
export declare function useIfDelete<T = Record<string, unknown>>(query: IfWriteQuery): Promise<FetchResult<T[]>>;
|
|
63
|
+
/**
|
|
64
|
+
* Calls a Postgres function (RPC).
|
|
65
|
+
*
|
|
66
|
+
* @param call - Function name, params and optional schema.
|
|
67
|
+
* @returns Safe Result with the function output.
|
|
68
|
+
*/
|
|
69
|
+
export declare function useIfRpc<T = unknown>(call: IfRpcCall): Promise<FetchResult<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* Uploads a file to a bucket (standard PUT semantics: same key replaces).
|
|
72
|
+
*
|
|
73
|
+
* @param ref - Bucket + object key.
|
|
74
|
+
* @param file - File or Blob to upload.
|
|
75
|
+
* @returns Safe Result with the stored file metadata.
|
|
76
|
+
*/
|
|
77
|
+
export declare function useIfUpload(ref: IfStorageRef, file: File | Blob): Promise<FetchResult<Record<string, unknown>>>;
|
|
78
|
+
/**
|
|
79
|
+
* Downloads a file from a bucket.
|
|
80
|
+
*
|
|
81
|
+
* @param ref - Bucket + object key.
|
|
82
|
+
* @returns Safe Result with the file as a Blob.
|
|
83
|
+
*/
|
|
84
|
+
export declare function useIfDownload(ref: IfStorageRef): Promise<FetchResult<Blob>>;
|
|
85
|
+
/**
|
|
86
|
+
* Removes a file from a bucket.
|
|
87
|
+
*
|
|
88
|
+
* @param ref - Bucket + object key.
|
|
89
|
+
* @returns Safe Result with the deletion response.
|
|
90
|
+
*/
|
|
91
|
+
export declare function useIfRemove(ref: IfStorageRef): Promise<FetchResult<Record<string, unknown>>>;
|
|
92
|
+
/**
|
|
93
|
+
* Lists objects in a bucket.
|
|
94
|
+
*
|
|
95
|
+
* @param bucket - Bucket name.
|
|
96
|
+
* @param options - Prefix, search, limit and offset.
|
|
97
|
+
* @returns Safe Result with the listing.
|
|
98
|
+
*/
|
|
99
|
+
export declare function useIfListObjects(bucket: string, options?: IfListOptions): Promise<FetchResult<Record<string, unknown>>>;
|
|
100
|
+
/**
|
|
101
|
+
* Builds the public URL for an object in a public bucket (no network call).
|
|
102
|
+
*
|
|
103
|
+
* @param ref - Bucket + object key.
|
|
104
|
+
* @returns Safe Result with `{ publicUrl }`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function useIfGetPublicUrl(ref: IfStorageRef): FetchResult<{
|
|
107
|
+
publicUrl: string;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Invokes an edge function.
|
|
111
|
+
*
|
|
112
|
+
* @param options - Function slug + optional JSON body.
|
|
113
|
+
* @returns Safe Result with the function response.
|
|
114
|
+
*/
|
|
115
|
+
export declare function useIfInvokeFunction<T = unknown>(options: IfInvokeOptions): Promise<FetchResult<T>>;
|
|
116
|
+
//# sourceMappingURL=insforge.service.d.ts.map
|
|
@@ -0,0 +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;AAgBrF,OAAO,KAAK,EAEX,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAA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