@granular-software/sdk 0.4.6 → 0.4.8
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 +18 -12
- package/dist/cli/index.js +1279 -380
- package/dist/index.d.mts +37 -11
- package/dist/index.d.ts +37 -11
- package/dist/index.js +115 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,16 +55,16 @@ import { Granular, type ManifestContent } from '@granular-software/sdk';
|
|
|
55
55
|
|
|
56
56
|
const granular = new Granular({ apiKey: process.env.GRANULAR_API_KEY });
|
|
57
57
|
|
|
58
|
-
// 1.
|
|
59
|
-
const
|
|
58
|
+
// 1. Connect to sandbox for one of your app users
|
|
59
|
+
const env = await granular.connect({
|
|
60
|
+
sandbox: 'my-sandbox',
|
|
60
61
|
userId: 'user_123',
|
|
61
62
|
permissions: ['agent'],
|
|
63
|
+
name: 'Jane Doe', // optional
|
|
64
|
+
email: 'jane@example.com', // optional
|
|
62
65
|
});
|
|
63
66
|
|
|
64
|
-
// 2.
|
|
65
|
-
const env = await granular.connect({ sandbox: 'my-sandbox', user });
|
|
66
|
-
|
|
67
|
-
// 3. Define your domain ontology
|
|
67
|
+
// 2. Define your domain ontology
|
|
68
68
|
const manifest: ManifestContent = {
|
|
69
69
|
schemaVersion: 2,
|
|
70
70
|
name: 'my-app',
|
|
@@ -105,7 +105,7 @@ const manifest: ManifestContent = {
|
|
|
105
105
|
|
|
106
106
|
await env.applyManifest(manifest);
|
|
107
107
|
|
|
108
|
-
//
|
|
108
|
+
// 3. Record object instances
|
|
109
109
|
await env.recordObject({
|
|
110
110
|
className: 'customer',
|
|
111
111
|
id: 'cust_42',
|
|
@@ -113,7 +113,7 @@ await env.recordObject({
|
|
|
113
113
|
fields: { name: 'Acme Corp', email: 'billing@acme.com', tier: 'enterprise' },
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
//
|
|
116
|
+
// 4. Register live effect handlers for effects already declared in the build manifest
|
|
117
117
|
await granular.registerEffects(env.sandboxId, [
|
|
118
118
|
{
|
|
119
119
|
name: 'get_billing_summary',
|
|
@@ -172,11 +172,11 @@ Effects must be declared ahead of time in the sandbox build manifest with `withE
|
|
|
172
172
|
## Core Flow
|
|
173
173
|
|
|
174
174
|
```
|
|
175
|
-
declare effects in build manifest → connect() → recordObject() → registerEffects() → submitJob()
|
|
175
|
+
declare effects in build manifest → connect({ userId }) → recordObject() → registerEffects() → submitJob()
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
1. **`
|
|
179
|
-
2. **`
|
|
178
|
+
1. **`connect()`** — Connect to a sandbox for a given `userId`, returning an `Environment`
|
|
179
|
+
2. **`recordUser()`** — Optional explicit user upsert when you want the returned `granularId`
|
|
180
180
|
3. **`applyManifest()`** — Define your domain ontology (classes, properties, relationships)
|
|
181
181
|
4. **`recordObject()`** — Create/update instances of your classes with fields and relationships
|
|
182
182
|
5. **`granular.registerEffects()`** — Register sandbox-scoped live handlers for effects declared in the build manifest
|
|
@@ -232,9 +232,15 @@ await env.applyManifest(manifest);
|
|
|
232
232
|
|
|
233
233
|
## Recording Object Instances
|
|
234
234
|
|
|
235
|
-
After defining the ontology, populate it with data:
|
|
235
|
+
After defining the ontology, connect as a user and populate it with data:
|
|
236
236
|
|
|
237
237
|
```typescript
|
|
238
|
+
const env = await granular.connect({
|
|
239
|
+
sandbox: 'library-app',
|
|
240
|
+
userId: 'user_123',
|
|
241
|
+
permissions: ['agent'],
|
|
242
|
+
});
|
|
243
|
+
|
|
238
244
|
const tolkien = await env.recordObject({
|
|
239
245
|
className: 'author',
|
|
240
246
|
id: 'tolkien', // Real-world ID (unique per class)
|