@ekairos/domain 1.22.14-beta.feature-core-thread-registry-sync.0 → 1.22.15-beta.development.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 +123 -128
- package/dist/cli/bin.d.ts +9 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +488 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/client-runtime.d.ts +25 -0
- package/dist/cli/client-runtime.d.ts.map +1 -0
- package/dist/cli/client-runtime.js +60 -0
- package/dist/cli/client-runtime.js.map +1 -0
- package/dist/cli/config.d.ts +5 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +44 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/create-app.d.ts +33 -0
- package/dist/cli/create-app.d.ts.map +1 -0
- package/dist/cli/create-app.js +1317 -0
- package/dist/cli/create-app.js.map +1 -0
- package/dist/cli/http.d.ts +28 -0
- package/dist/cli/http.d.ts.map +1 -0
- package/dist/cli/http.js +117 -0
- package/dist/cli/http.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +7 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/server.d.ts +3 -0
- package/dist/cli/server.d.ts.map +1 -0
- package/dist/cli/server.js +437 -0
- package/dist/cli/server.js.map +1 -0
- package/dist/cli/types.d.ts +60 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/ui.d.ts +3 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +136 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/index.d.ts +72 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -19
- package/dist/index.js.map +1 -1
- package/dist/next.d.ts +21 -21
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +212 -345
- package/dist/next.js.map +1 -1
- package/dist/polyfills/dom-events.d.ts +2 -0
- package/dist/polyfills/dom-events.d.ts.map +1 -0
- package/dist/polyfills/dom-events.js +92 -0
- package/dist/polyfills/dom-events.js.map +1 -0
- package/dist/runtime-handle.d.ts +34 -0
- package/dist/runtime-handle.d.ts.map +1 -0
- package/dist/runtime-handle.js +82 -0
- package/dist/runtime-handle.js.map +1 -0
- package/dist/runtime-step.d.ts +52 -0
- package/dist/runtime-step.d.ts.map +1 -0
- package/dist/runtime-step.js +116 -0
- package/dist/runtime-step.js.map +1 -0
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +72 -19
- package/dist/runtime.js.map +1 -1
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -1,173 +1,168 @@
|
|
|
1
1
|
# @ekairos/domain
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Build one app graph from many bounded contexts.
|
|
4
|
+
Read it through InstantDB.
|
|
5
|
+
Write through step-safe domain actions.
|
|
6
|
+
Operate it through a CLI.
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
## What you get
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
- Composed domain graphs with `domain(...).schema(...)`
|
|
11
|
+
- Explicit runtimes with `EkairosRuntime`
|
|
12
|
+
- Step-safe write boundaries with `defineDomainAction(...)`
|
|
13
|
+
- Workflow-ready action execution with `executeRuntimeAction(...)`
|
|
14
|
+
- A built-in CLI for `create-app`, `inspect`, `action`, and `query`
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
- Runtime resolution.
|
|
12
|
-
- Typed domain actions.
|
|
13
|
-
- AI-ready domain context.
|
|
16
|
+
## Start Fast
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Install
|
|
18
|
+
Scaffold a Next app that already exposes the Ekairos domain endpoint:
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
|
-
|
|
21
|
-
pnpm add -D @instantdb/admin
|
|
21
|
+
npx @ekairos/domain create-app my-app --next
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- `@ekairos/domain`
|
|
27
|
-
- `@ekairos/domain/runtime`
|
|
28
|
-
- `@ekairos/domain/next`
|
|
29
|
-
|
|
30
|
-
## Quick start
|
|
31
|
-
|
|
32
|
-
### 1. Define a domain schema
|
|
33
|
-
|
|
34
|
-
```ts
|
|
35
|
-
import { domain } from "@ekairos/domain";
|
|
36
|
-
import { i } from "@instantdb/core";
|
|
24
|
+
If you already have an Instant platform token, provision the app and write `.env.local` in one pass:
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
management_tasks: i.entity({
|
|
41
|
-
title: i.string(),
|
|
42
|
-
status: i.string().indexed(),
|
|
43
|
-
createdAt: i.date().indexed(),
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
links: {},
|
|
47
|
-
rooms: {},
|
|
48
|
-
});
|
|
26
|
+
```bash
|
|
27
|
+
npx @ekairos/domain create-app my-app --next --instantToken=$INSTANT_PERSONAL_ACCESS_TOKEN
|
|
49
28
|
```
|
|
50
29
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
import { defineDomainAction } from "@ekairos/domain";
|
|
55
|
-
|
|
56
|
-
const createTask = defineDomainAction<
|
|
57
|
-
{ orgId: string; actorId: string },
|
|
58
|
-
{ title: string },
|
|
59
|
-
{ ok: true; taskId: string },
|
|
60
|
-
{ db: any }
|
|
61
|
-
>({
|
|
62
|
-
name: "management.task.create",
|
|
63
|
-
description: "Create a management task",
|
|
64
|
-
async execute({ env, input, runtime }) {
|
|
65
|
-
const title = String(input.title ?? "").trim();
|
|
66
|
-
if (!title) throw new Error("title_required");
|
|
67
|
-
|
|
68
|
-
// use runtime.db here
|
|
69
|
-
return { ok: true, taskId: `task_${env.orgId}` };
|
|
70
|
-
},
|
|
71
|
-
});
|
|
30
|
+
Then run it and inspect it:
|
|
72
31
|
|
|
73
|
-
|
|
32
|
+
```bash
|
|
33
|
+
npx @ekairos/domain inspect --baseUrl=http://localhost:3000 --admin --pretty
|
|
34
|
+
npx @ekairos/domain seedDemo --baseUrl=http://localhost:3000 --admin --pretty
|
|
35
|
+
npx @ekairos/domain query "{ app_tasks: { comments: {} } }" --baseUrl=http://localhost:3000 --admin --pretty
|
|
74
36
|
```
|
|
75
37
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import { configureRuntime } from "@ekairos/domain/runtime";
|
|
80
|
-
import { appDomain } from "./domain";
|
|
81
|
-
|
|
82
|
-
configureRuntime({
|
|
83
|
-
domain: { domain: appDomain },
|
|
84
|
-
runtime: async (env) => {
|
|
85
|
-
// Resolve DB by env (org, actor, tenant, etc.)
|
|
86
|
-
return { db: { orgId: env.orgId } };
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
```
|
|
38
|
+
## Next.js Route
|
|
90
39
|
|
|
91
|
-
|
|
40
|
+
New Next.js apps expose the domain adapter explicitly:
|
|
92
41
|
|
|
93
42
|
```ts
|
|
94
|
-
|
|
43
|
+
// src/app/api/ekairos/domain/route.ts
|
|
44
|
+
import { createRuntimeRouteHandler } from "@ekairos/domain/next";
|
|
45
|
+
import { createRuntime } from "@/runtime";
|
|
95
46
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
env: { orgId: "org_123", actorId: "user_1" },
|
|
99
|
-
input: { title: "Ship domain action runtime" },
|
|
47
|
+
export const { GET, POST } = createRuntimeRouteHandler({
|
|
48
|
+
createRuntime,
|
|
100
49
|
});
|
|
101
50
|
```
|
|
102
51
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Actions are explicit and portable:
|
|
106
|
-
|
|
107
|
-
- Domain package owns contracts.
|
|
108
|
-
- Adapters own environment (`env`).
|
|
109
|
-
- Runtime is resolved per action domain.
|
|
110
|
-
- Nested action calls are supported with cycle protection.
|
|
52
|
+
This replaces the old `withRuntime(...)` pattern.
|
|
53
|
+
There is no Next config patching and no generated `.well-known` domain route in new apps.
|
|
111
54
|
|
|
112
|
-
|
|
55
|
+
Your `next.config.ts` should stay focused on Workflow:
|
|
113
56
|
|
|
114
|
-
|
|
57
|
+
```ts
|
|
58
|
+
import type { NextConfig } from "next";
|
|
59
|
+
import { withWorkflow } from "workflow/next";
|
|
115
60
|
|
|
116
|
-
|
|
61
|
+
const nextConfig: NextConfig = {
|
|
62
|
+
transpilePackages: ["@ekairos/domain"],
|
|
63
|
+
};
|
|
117
64
|
|
|
118
|
-
|
|
119
|
-
|
|
65
|
+
export default withWorkflow(nextConfig) as NextConfig;
|
|
66
|
+
```
|
|
120
67
|
|
|
121
|
-
|
|
68
|
+
The CLI uses `/api/ekairos/domain` by default and falls back to the legacy
|
|
69
|
+
`/.well-known/ekairos/v1/domain` endpoint for older apps.
|
|
122
70
|
|
|
123
|
-
##
|
|
71
|
+
## Core Pattern
|
|
124
72
|
|
|
125
|
-
|
|
73
|
+
```ts
|
|
74
|
+
import { defineDomainAction, domain } from "@ekairos/domain";
|
|
75
|
+
import { EkairosRuntime } from "@ekairos/domain/runtime-handle";
|
|
76
|
+
import { executeRuntimeAction } from "@ekairos/domain/runtime";
|
|
77
|
+
import { init } from "@instantdb/admin";
|
|
78
|
+
import { i } from "@instantdb/core";
|
|
126
79
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
80
|
+
const baseDomain = domain("tasks").schema({
|
|
81
|
+
entities: {
|
|
82
|
+
tasks: i.entity({
|
|
83
|
+
title: i.string().indexed(),
|
|
84
|
+
status: i.string().indexed(),
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
links: {},
|
|
88
|
+
rooms: {},
|
|
89
|
+
});
|
|
130
90
|
|
|
131
|
-
|
|
91
|
+
export const createTaskAction = defineDomainAction({
|
|
92
|
+
name: "tasks.create",
|
|
93
|
+
async execute({ runtime, input }) {
|
|
94
|
+
"use step";
|
|
95
|
+
const scoped = await runtime.use(appDomain);
|
|
96
|
+
// transact...
|
|
97
|
+
return { ok: true };
|
|
98
|
+
},
|
|
99
|
+
});
|
|
132
100
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
101
|
+
export const appDomain = baseDomain.actions({
|
|
102
|
+
createTask: createTaskAction,
|
|
103
|
+
});
|
|
136
104
|
|
|
137
|
-
|
|
105
|
+
export class AppRuntime extends EkairosRuntime<{
|
|
106
|
+
appId?: string;
|
|
107
|
+
adminToken?: string;
|
|
108
|
+
}, typeof appDomain, any> {
|
|
109
|
+
protected getDomain() {
|
|
110
|
+
return appDomain;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
protected async resolveDb(env: { appId?: string; adminToken?: string }) {
|
|
114
|
+
return init({
|
|
115
|
+
appId: env.appId!,
|
|
116
|
+
adminToken: env.adminToken!,
|
|
117
|
+
schema: appDomain.toInstantSchema(),
|
|
118
|
+
useDateObjects: true,
|
|
119
|
+
} as any);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function createRuntime(env = {}) {
|
|
124
|
+
return new AppRuntime(env);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function runWorkflow() {
|
|
128
|
+
"use workflow";
|
|
129
|
+
const runtime = createRuntime({
|
|
130
|
+
appId: process.env.NEXT_PUBLIC_INSTANT_APP_ID,
|
|
131
|
+
adminToken: process.env.INSTANT_ADMIN_TOKEN,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return await executeRuntimeAction({
|
|
135
|
+
runtime,
|
|
136
|
+
action: createTaskAction,
|
|
137
|
+
input: { title: "Ship it" },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
```
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
- Runtime is explicit.
|
|
141
|
-
- Actions are explicit.
|
|
142
|
-
- `env` is adapter-defined and opaque to the package.
|
|
143
|
-
- Included subdomains do not auto-export actions.
|
|
142
|
+
## Rules Of Thumb
|
|
144
143
|
|
|
145
|
-
|
|
144
|
+
- Read directly from the composed schema when no invariant is involved.
|
|
145
|
+
- Put every meaningful write behind an action.
|
|
146
|
+
- Keep action bodies `"use step"`.
|
|
147
|
+
- Keep workflow orchestration above actions.
|
|
148
|
+
- Use `DOMAIN.md` plus `domain.contextString()` when an AI agent needs the model explained.
|
|
146
149
|
|
|
147
|
-
|
|
148
|
-
- Domain schema results are immutable at runtime.
|
|
149
|
-
- `.actions(...)` is persistent: it returns a new domain result and never mutates the original one.
|
|
150
|
-
- Duplicate link attributes (`entity->label`) are rejected before schema materialization.
|
|
150
|
+
## CLI Input Quality Of Life
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
The CLI accepts JSON5, `@file`, and stdin:
|
|
153
153
|
|
|
154
154
|
```bash
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
npx @ekairos/domain query "{ tasks: { $: { limit: 5 } } }" --admin
|
|
156
|
+
npx @ekairos/domain query @query.json5 --admin
|
|
157
|
+
cat query.json5 | npx @ekairos/domain query - --admin
|
|
157
158
|
```
|
|
158
159
|
|
|
159
|
-
|
|
160
|
+
Add `--meta` when you need to know whether a query used the local client runtime path or the server route.
|
|
161
|
+
|
|
162
|
+
## Tests
|
|
160
163
|
|
|
161
164
|
```bash
|
|
162
|
-
pnpm
|
|
165
|
+
pnpm --filter @ekairos/domain test
|
|
166
|
+
pnpm --filter @ekairos/domain test:cli
|
|
167
|
+
pnpm --filter @ekairos/domain test:workflow
|
|
163
168
|
```
|
|
164
|
-
|
|
165
|
-
## Links
|
|
166
|
-
|
|
167
|
-
- npm: https://www.npmjs.com/package/@ekairos/domain
|
|
168
|
-
- source: https://github.com/e-kairos/ekairos/tree/main/packages/domain
|
|
169
|
-
- issues: https://github.com/e-kairos/ekairos/issues
|
|
170
|
-
|
|
171
|
-
## License
|
|
172
|
-
|
|
173
|
-
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { stdout as output } from "node:process";
|
|
3
|
+
type CliContext = {
|
|
4
|
+
stdout: Pick<typeof output, "write">;
|
|
5
|
+
stderr: Pick<typeof output, "write">;
|
|
6
|
+
};
|
|
7
|
+
export declare function runCli(argv: string[], ctx?: CliContext): Promise<1 | 0>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAkB,MAAM,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AAgB/D,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,IAAI,CAAC,OAAO,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,MAAM,EAAE,IAAI,CAAC,OAAO,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC,CAAA;AAkiBD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,GAAE,UAA+C,kBAkDrD"}
|