@cosmicdrift/kumiko-framework 0.19.0 → 0.19.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
|
@@ -7,7 +7,7 @@ Framework core for Kumiko — engine, pipeline, API, DB, event-store, and
|
|
|
7
7
|
every other bit that makes Kumiko go.
|
|
8
8
|
|
|
9
9
|
> Multi-tenant, command-based, event-sourced app framework for Bun + Hono +
|
|
10
|
-
>
|
|
10
|
+
> Postgres. Define features, register entities, write commands — the framework
|
|
11
11
|
> wires dispatch, persistence, projections, async subscribers, and realtime
|
|
12
12
|
> delivery.
|
|
13
13
|
|
|
@@ -18,12 +18,12 @@ for runnable examples of every feature.
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
|
|
21
|
+
bun add @cosmicdrift/kumiko-framework
|
|
22
22
|
# peers you probably already have:
|
|
23
|
-
|
|
23
|
+
bun add hono ioredis zod
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Bun is the intended runtime
|
|
26
|
+
Bun is the intended runtime and test runner.
|
|
27
27
|
|
|
28
28
|
## At-a-glance
|
|
29
29
|
|
|
@@ -108,7 +108,7 @@ export const taskFeature = defineFeature("tasks", (r) => {
|
|
|
108
108
|
| Entry | What's in it |
|
|
109
109
|
|---|---|
|
|
110
110
|
| `@cosmicdrift/kumiko-framework/engine` | `defineFeature`, `createEntity`, field helpers, access rules, registry |
|
|
111
|
-
| `@cosmicdrift/kumiko-framework/db` |
|
|
111
|
+
| `@cosmicdrift/kumiko-framework/db` | `buildEntityTableMeta`, `createEventStoreExecutor`, migrations, tenant-db |
|
|
112
112
|
| `@cosmicdrift/kumiko-framework/event-store` | `events` table, `append`, `loadAggregate`, `loadAggregateAsOf` |
|
|
113
113
|
| `@cosmicdrift/kumiko-framework/pipeline` | Dispatcher, event-dispatcher (AsyncDaemon), projection-rebuild, SSE + search consumers |
|
|
114
114
|
| `@cosmicdrift/kumiko-framework/api` | `buildServer`, auth middleware, SSE route, error contract |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-framework",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -123,6 +123,10 @@
|
|
|
123
123
|
"types": "./src/search/meilisearch-adapter.ts",
|
|
124
124
|
"default": "./src/search/meilisearch-adapter.ts"
|
|
125
125
|
},
|
|
126
|
+
"./seeding": {
|
|
127
|
+
"types": "./src/seeding/index.ts",
|
|
128
|
+
"default": "./src/seeding/index.ts"
|
|
129
|
+
},
|
|
126
130
|
"./secrets": {
|
|
127
131
|
"types": "./src/secrets/index.ts",
|
|
128
132
|
"default": "./src/secrets/index.ts"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runEventStoreSeed } from "../entity-seed";
|
|
3
|
+
|
|
4
|
+
describe("runEventStoreSeed", () => {
|
|
5
|
+
test('default ifExists="skip" returns existing id without update', async () => {
|
|
6
|
+
let updateCalls = 0;
|
|
7
|
+
let createCalls = 0;
|
|
8
|
+
|
|
9
|
+
const result = await runEventStoreSeed({
|
|
10
|
+
existing: { id: "agg-1", version: 3 },
|
|
11
|
+
create: async () => {
|
|
12
|
+
createCalls++;
|
|
13
|
+
return { id: "new" };
|
|
14
|
+
},
|
|
15
|
+
update: async () => {
|
|
16
|
+
updateCalls++;
|
|
17
|
+
return { id: "agg-1" };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result.id).toBe("agg-1");
|
|
22
|
+
expect(updateCalls).toBe(0);
|
|
23
|
+
expect(createCalls).toBe(0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('ifExists="update" calls update when row exists', async () => {
|
|
27
|
+
let updateCalls = 0;
|
|
28
|
+
|
|
29
|
+
const result = await runEventStoreSeed({
|
|
30
|
+
existing: { id: "agg-2", version: 1 },
|
|
31
|
+
ifExists: "update",
|
|
32
|
+
create: async () => ({ id: "new" }),
|
|
33
|
+
update: async (existing) => {
|
|
34
|
+
updateCalls++;
|
|
35
|
+
expect(existing.version).toBe(1);
|
|
36
|
+
return { id: existing.id };
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(result.id).toBe("agg-2");
|
|
41
|
+
expect(updateCalls).toBe(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("missing row calls create", async () => {
|
|
45
|
+
let createCalls = 0;
|
|
46
|
+
|
|
47
|
+
const result = await runEventStoreSeed({
|
|
48
|
+
existing: null,
|
|
49
|
+
create: async () => {
|
|
50
|
+
createCalls++;
|
|
51
|
+
return { id: "created" };
|
|
52
|
+
},
|
|
53
|
+
update: async () => ({ id: "never" }),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(result.id).toBe("created");
|
|
57
|
+
expect(createCalls).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DEFAULT_SEED_IF_EXISTS, type SeedIfExists } from "./types";
|
|
2
|
+
|
|
3
|
+
export type EventStoreSeedExisting = {
|
|
4
|
+
readonly id: string | number;
|
|
5
|
+
readonly version: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type RunEventStoreSeedOptions<TExisting extends EventStoreSeedExisting> = {
|
|
9
|
+
readonly existing: TExisting | null | undefined;
|
|
10
|
+
readonly ifExists?: SeedIfExists;
|
|
11
|
+
readonly create: () => Promise<{ id: string | number }>;
|
|
12
|
+
readonly update: (existing: TExisting) => Promise<{ id: string | number }>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Shared create-or-skip/update path for event-store boot-seed helpers. */
|
|
16
|
+
export async function runEventStoreSeed<TExisting extends EventStoreSeedExisting>(
|
|
17
|
+
opts: RunEventStoreSeedOptions<TExisting>,
|
|
18
|
+
): Promise<{ id: string | number }> {
|
|
19
|
+
const ifExists = opts.ifExists ?? DEFAULT_SEED_IF_EXISTS;
|
|
20
|
+
if (opts.existing != null) {
|
|
21
|
+
if (ifExists === "skip") {
|
|
22
|
+
return { id: opts.existing.id };
|
|
23
|
+
}
|
|
24
|
+
return opts.update(opts.existing);
|
|
25
|
+
}
|
|
26
|
+
return opts.create();
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Boot-seed semantics for event-sourced entity helpers.
|
|
2
|
+
*
|
|
3
|
+
* - `skip` (default): row exists → return without write (no event).
|
|
4
|
+
* - `update`: row exists → overwrite via executor.update (opt-in, e.g.
|
|
5
|
+
* demo-fixtures where code is source-of-truth). */
|
|
6
|
+
export type SeedIfExists = "skip" | "update";
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_SEED_IF_EXISTS: SeedIfExists = "skip";
|