@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 CHANGED
@@ -1,64 +1,95 @@
1
- # @weave-kit/client
2
-
3
- Framework-agnostic TypeScript SDK for the WeaveKit engine. No DOM or UI-framework dependencies — usable in browsers, Node, or anywhere a `fetch` implementation exists.
4
-
5
- ## Usage
6
-
7
- ```ts
8
- import { createClient } from '@weave-kit/client';
9
- import type { Lead } from './generated/types';
10
-
11
- const client = createClient({ baseUrl: 'http://localhost:3000', apiKey: 'sk-admin' });
12
- const leads = client.objects<Lead>('lead');
13
-
14
- const result = await leads.find({
15
- filter: { status: 'open' },
16
- sort: [{ field: 'created_at', direction: 'desc' }],
17
- limit: 20,
18
- });
19
- const one = await leads.findOne('L1'); // null on 404 (does not leak existence)
20
- const created = await leads.create({ title: 'New lead' });
21
- const updated = await leads.update('L1', { title: 'Renamed' });
22
- await leads.delete('L1');
23
- ```
24
-
25
- ## Object-level types
26
-
27
- `weave types` in your project compiles `schema.json` into `generated/types.ts`:
28
-
29
- ```sh
30
- weave types # generated/types.ts
31
- ```
32
-
33
- ```ts
34
- import type { Lead } from './generated/types';
35
- const leads = createClient({ baseUrl, apiKey }).objects<Lead>('lead');
36
- ```
37
-
38
- Every field type, enum union, and relation's primary-key type is derived from the schema. `objects<T>` defaults to `Record<string, unknown>` when you omit the type.
39
-
40
- ## Methods
41
-
42
- `objects<T>(name)` returns:
43
-
44
- - `find(params?)` — `Promise<RestResult<T>>` (`{ rows, total, limit, offset }`)
45
- - `findOne(id, params?)` — `Promise<T | null>` (404 → null)
46
- - `create(data: Partial<T>)` `Promise<T>`
47
- - `update(id, changes: Partial<T>)` `Promise<T>`
48
- - `delete(id)` — `Promise<void>`
49
-
50
- ## Errors
51
-
52
- Non-2xx responses throw `ClientError`:
53
-
54
- ```ts
55
- try {
56
- await leads.find();
57
- } catch (error) {
58
- if (error instanceof ClientError) {
59
- error.status; // 401/403/404/400/500
60
- error.code; // e.g. 'rbac.denied.read', 'auth.missingKey'
61
- error.message;
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 (千页千面): `show.client`/`list.client`.
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. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weave-kit/client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "WeaveKit client — framework-agnostic TypeScript SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",