@weave-kit/client 0.1.0 → 0.1.1
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 +95 -64
- package/dist/scripts.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,64 +1,95 @@
|
|
|
1
|
-
# @weave-kit/client
|
|
2
|
-
|
|
3
|
-
Framework-agnostic TypeScript SDK for the WeaveKit engine.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
`
|
|
43
|
-
|
|
44
|
-
- `
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
# @weave-kit/client
|
|
2
|
+
|
|
3
|
+
> Framework-agnostic TypeScript SDK for the WeaveKit engine.
|
|
4
|
+
|
|
5
|
+
No DOM or UI-framework dependencies — usable in browsers, Node.js, or anywhere a `fetch`
|
|
6
|
+
implementation exists.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @weave-kit/client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Node.js 24 LTS (for a Node runtime) or any modern browser.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { createClient } from '@weave-kit/client';
|
|
20
|
+
import type { Lead } from './generated/types';
|
|
21
|
+
|
|
22
|
+
const client = createClient({ baseUrl: 'http://localhost:3000', apiKey: 'sk-admin' });
|
|
23
|
+
const leads = client.objects<Lead>('lead');
|
|
24
|
+
|
|
25
|
+
const result = await leads.find({
|
|
26
|
+
filter: { status: 'open' },
|
|
27
|
+
sort: [{ field: 'created_at', direction: 'desc' }],
|
|
28
|
+
limit: 20,
|
|
29
|
+
});
|
|
30
|
+
const one = await leads.findOne('L1'); // null on 404 (does not leak existence)
|
|
31
|
+
const created = await leads.create({ title: 'New lead' });
|
|
32
|
+
const updated = await leads.update('L1', { title: 'Renamed' });
|
|
33
|
+
await leads.delete('L1');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Methods
|
|
37
|
+
|
|
38
|
+
`objects<T>(name)` returns:
|
|
39
|
+
|
|
40
|
+
- `find(params?)` — `Promise<RestResult<T>>` (`{ rows, total, limit, offset }`)
|
|
41
|
+
- `findOne(id, params?)` — `Promise<T | null>` (404 → null)
|
|
42
|
+
- `create(data: Partial<T>)` — `Promise<T>`
|
|
43
|
+
- `update(id, changes: Partial<T>)` — `Promise<T>`
|
|
44
|
+
- `delete(id)` — `Promise<void>`
|
|
45
|
+
|
|
46
|
+
The client also exposes `metadata`, `permissions`, `audit`, `approvals`, `guardrails`, `identities`,
|
|
47
|
+
`layouts`, `schema`, `scripts`, and an SSE `subscribe` for live events.
|
|
48
|
+
|
|
49
|
+
## Object-level types
|
|
50
|
+
|
|
51
|
+
`weave types` in your engine project compiles `schema.json` into `generated/types.ts`:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
weave types # → generated/types.ts
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import type { Lead } from './generated/types';
|
|
59
|
+
const leads = createClient({ baseUrl, apiKey }).objects<Lead>('lead');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Every field type, enum union, and relation's primary-key type is derived from the schema.
|
|
63
|
+
`objects<T>` defaults to `Record<string, unknown>` when you omit the type.
|
|
64
|
+
|
|
65
|
+
## Errors
|
|
66
|
+
|
|
67
|
+
Non-2xx responses throw `ClientError`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { ClientError } from '@weave-kit/client';
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
await leads.find();
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof ClientError) {
|
|
76
|
+
error.status; // 401/403/404/400/500
|
|
77
|
+
error.code; // e.g. 'rbac.denied.read', 'auth.missingKey'
|
|
78
|
+
error.message;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
npm install
|
|
87
|
+
npm run build # tsc → dist
|
|
88
|
+
npm test
|
|
89
|
+
npm run typecheck
|
|
90
|
+
npm run lint
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
[MIT](LICENSE)
|
package/dist/scripts.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ScriptSaveResult {
|
|
|
17
17
|
version: string;
|
|
18
18
|
warnings?: string[];
|
|
19
19
|
}
|
|
20
|
-
/** Page-scoped client script accessor (
|
|
20
|
+
/** Page-scoped client script accessor (per-page customization): `show.client`/`list.client`.
|
|
21
21
|
* Page-level (`/pages/<path>/scripts/<kind>`) overrides the object script for
|
|
22
22
|
* that page; block-level (`/pages/<path>/blocks/<ui_id>/scripts/<kind>`) scopes
|
|
23
23
|
* a script to one `list` block instance. */
|