@granular-software/sdk 0.4.12 → 0.4.14
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 +14 -12
- package/dist/cli/index.js +486 -75
- package/dist/index.d.mts +215 -12
- package/dist/index.d.ts +215 -12
- package/dist/index.js +375 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +374 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -54,8 +54,8 @@ When the resolved API URL points at `localhost` or `127.0.0.1`, the SDK and CLI
|
|
|
54
54
|
|
|
55
55
|
Projects created with `granular init` can include Markdown for coding agents (optional `AGENTS.md` plus generated guides):
|
|
56
56
|
|
|
57
|
-
- **`docs/granular-manifest.md`** — **What Granular is**, glossary, manifest → build → connect → jobs, **`granular.json`** syntax (**fields**, **relationships**, **effects**), **`@granular-software/sdk`** map, CLI. Self-contained for agents new to the product. Added when you opt in at init (`--agent-docs` / `--no-agent-docs`, or the prompt).
|
|
58
|
-
- **`GRANULAR_SANDBOX.md`** — **This sandbox’s ontology** snapshot: ids, exact names/keys, effect schemas, snippets. Updated after each successful **`granular build`**, **`granular deploy`**, and **`granular dev`** rebuild, and on **`granular document`** (run `build` to record
|
|
57
|
+
- **`docs/granular-manifest.md`** — **What Granular is**, glossary, manifest → version → build run → connect → jobs, **`granular.json`** syntax (**fields**, **relationships**, **effects**), **`@granular-software/sdk`** map, CLI. Self-contained for agents new to the product. Added when you opt in at init (`--agent-docs` / `--no-agent-docs`, or the prompt).
|
|
58
|
+
- **`GRANULAR_SANDBOX.md`** — **This sandbox’s ontology** snapshot: ids, exact names/keys, effect schemas, snippets. Updated after each successful **`granular build`**, **`granular deploy`**, and **`granular dev`** rebuild, and on **`granular document`** (run `build` to record version/build metadata).
|
|
59
59
|
- **`AGENTS.md`** — Two-step index: manifest guide first, then sandbox doc (merged idempotently with `<!-- granular-sdk:begin -->`).
|
|
60
60
|
|
|
61
61
|
## Quick Start
|
|
@@ -65,9 +65,10 @@ import { Granular, type ManifestContent } from '@granular-software/sdk';
|
|
|
65
65
|
|
|
66
66
|
const granular = new Granular({ apiKey: process.env.GRANULAR_API_KEY });
|
|
67
67
|
|
|
68
|
-
// 1. Connect to
|
|
68
|
+
// 1. Connect to the default dev environment for one of your app users
|
|
69
69
|
const env = await granular.connect({
|
|
70
|
-
|
|
70
|
+
ontology: 'my-ontology',
|
|
71
|
+
environment: 'dev',
|
|
71
72
|
userId: 'user_123',
|
|
72
73
|
permissions: ['agent'],
|
|
73
74
|
name: 'Jane Doe', // optional
|
|
@@ -123,7 +124,7 @@ await env.recordObject({
|
|
|
123
124
|
fields: { name: 'Acme Corp', email: 'billing@acme.com', tier: 'enterprise' },
|
|
124
125
|
});
|
|
125
126
|
|
|
126
|
-
// 4. Register live effect handlers for effects already declared in the
|
|
127
|
+
// 4. Register live effect handlers for effects already declared in the ontology manifest
|
|
127
128
|
await granular.registerEffects(env.sandboxId, [
|
|
128
129
|
{
|
|
129
130
|
name: 'get_billing_summary',
|
|
@@ -177,19 +178,19 @@ const job = await env.submitJob(`
|
|
|
177
178
|
const result = await job.result;
|
|
178
179
|
```
|
|
179
180
|
|
|
180
|
-
Effects must be declared ahead of time in the
|
|
181
|
+
Effects must be declared ahead of time in the ontology version manifest with `withEffect`. Live registration only makes already-declared effects available at runtime.
|
|
181
182
|
|
|
182
183
|
## Core Flow
|
|
183
184
|
|
|
184
185
|
```
|
|
185
|
-
declare effects in
|
|
186
|
+
declare effects in the manifest → `granular build` creates or reuses a version → `connect({ ontology, environment, userId })` opens a named environment → `recordObject()` → `registerEffects()` → `submitJob()`
|
|
186
187
|
```
|
|
187
188
|
|
|
188
|
-
1. **`connect()`** — Connect to
|
|
189
|
+
1. **`connect()`** — Connect to an ontology environment for a given `userId`, returning an `Environment`
|
|
189
190
|
2. **`recordUser()`** — Optional explicit user upsert when you want the returned `granularId`
|
|
190
191
|
3. **`applyManifest()`** — Define your domain ontology (classes, properties, relationships)
|
|
191
192
|
4. **`recordObject()`** — Create/update instances of your classes with fields and relationships
|
|
192
|
-
5. **`granular.registerEffects()`** — Register sandbox-scoped live handlers for effects declared in the
|
|
193
|
+
5. **`granular.registerEffects()`** — Register sandbox-scoped live handlers for effects declared in the ontology manifest
|
|
193
194
|
6. **`submitJob()`** — Execute code in the sandbox that uses the auto-generated typed classes
|
|
194
195
|
|
|
195
196
|
## Defining the Domain Ontology
|
|
@@ -246,7 +247,8 @@ After defining the ontology, connect as a user and populate it with data:
|
|
|
246
247
|
|
|
247
248
|
```typescript
|
|
248
249
|
const env = await granular.connect({
|
|
249
|
-
|
|
250
|
+
ontology: 'library-app',
|
|
251
|
+
environment: 'dev',
|
|
250
252
|
userId: 'user_123',
|
|
251
253
|
permissions: ['agent'],
|
|
252
254
|
});
|
|
@@ -446,7 +448,7 @@ See [examples/](./examples/) for runnable code:
|
|
|
446
448
|
Registers a user identity and their assigned permission profiles.
|
|
447
449
|
|
|
448
450
|
### `granular.connect(options)`
|
|
449
|
-
Connects to
|
|
451
|
+
Connects to an environment session for the specified user. Pass `ontology` and `environment` explicitly, for example `environment: 'dev'` or `environment: 'prod'`. Only pass `tagName` for advanced overrides.
|
|
450
452
|
|
|
451
453
|
### `environment.applyManifest(manifest)`
|
|
452
454
|
Defines domain ontology: classes (with typed properties), and relationships (with cardinality).
|
|
@@ -461,7 +463,7 @@ Returns relationship definitions for a given class.
|
|
|
461
463
|
Lists related instances through a relationship.
|
|
462
464
|
|
|
463
465
|
### `granular.registerEffects(sandboxId, effects)`
|
|
464
|
-
Registers sandbox-scoped live handlers for effects declared in the
|
|
466
|
+
Registers sandbox-scoped live handlers for effects declared in the ontology manifest. Effects can be instance methods (`className` set, `static` omitted), static methods (`static: true`), or global functions (no `className`).
|
|
465
467
|
|
|
466
468
|
### `environment.submitJob(code)`
|
|
467
469
|
Submits code to be executed in the sandbox. The code imports typed classes from `./sandbox-tools`.
|