create-nwire 0.8.0 → 0.8.17
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/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/L1/README.md +4 -4
- package/templates/L1/package.json +2 -2
- package/templates/L2/README.md +6 -6
- package/templates/L2/package.json +5 -5
- package/templates/L4/README.md +13 -7
- package/templates/L4/modules/posts/actions/submit-post.ts +5 -0
- package/templates/L4/modules/posts/posts.module.ts +2 -1
- package/templates/L4/modules/posts/queries/posts-by-author.ts +53 -0
- package/templates/L4/package.json +6 -6
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,MAAM,EACN,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAI1D,MAAM,SAAS,GAA4D;IACzE,EAAE,EAAE;QACF,KAAK,EAAE,cAAc;QACrB,KAAK,EAAE,oEAAoE;KAC5E;IACD,EAAE,EAAE;QACF,KAAK,EAAE,cAAc;QACrB,KAAK,EAAE,oEAAoE;KAC5E;IACD,EAAE,EAAE;QACF,KAAK,EAAE,iBAAiB;QACxB,KAAK,EAAE,+EAA+E;KACvF;CACF,CAAC;AAQF;;;;GAIG;AACH,SAAS,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AS,CAAC,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;YAChE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;YAC7D,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACzD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,OAAQ,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
package/templates/L1/README.md
CHANGED
|
@@ -42,11 +42,11 @@ pnpm test
|
|
|
42
42
|
|
|
43
43
|
## Where to add a …
|
|
44
44
|
|
|
45
|
-
| You want to add … | Where it goes
|
|
46
|
-
| ----------------- |
|
|
45
|
+
| You want to add … | Where it goes |
|
|
46
|
+
| ----------------- | ------------------------------------------------------------------------------------------------- |
|
|
47
47
|
| A new route | `app/routes/<verb-noun>.ts` exports `{name}Route + {name}Handler`; `.wire()` it from `app/api.ts` |
|
|
48
|
-
| Middleware | Inline in `app/api.ts` via `.use(middlewareFn)`
|
|
49
|
-
| Container deps | Graduate to L2 — `app/store/` + `.provide(container)` in api.ts
|
|
48
|
+
| Middleware | Inline in `app/api.ts` via `.use(middlewareFn)` |
|
|
49
|
+
| Container deps | Graduate to L2 — `app/store/` + `.provide(container)` in api.ts |
|
|
50
50
|
|
|
51
51
|
## What you get free
|
|
52
52
|
|
package/templates/L2/README.md
CHANGED
|
@@ -56,13 +56,13 @@ curl -X POST http://localhost:3000/api/todos/<id>/complete \
|
|
|
56
56
|
|
|
57
57
|
## Where to add a …
|
|
58
58
|
|
|
59
|
-
| You want to add … | Where it goes
|
|
60
|
-
| ----------------- |
|
|
59
|
+
| You want to add … | Where it goes |
|
|
60
|
+
| ----------------- | --------------------------------------------------------------------------------------------- |
|
|
61
61
|
| A new route | `app/routes/<verb-noun>.ts` exports `{name}Route + {name}Handler`; `.wire()` it from `api.ts` |
|
|
62
|
-
| A new error type | `app/errors/<resource>-errors.ts` — `defineError({ code, status, summary })`
|
|
63
|
-
| A new middleware | `app/middleware/<name>.ts` exports `HttpMiddleware`; `.use()` it from `api.ts
|
|
64
|
-
| A new resource | `app/resources/<name>.ts` — `defineResource` schema + `public` field list
|
|
65
|
-
| Real persistence | Swap `app/store/todo-store.ts` for `@nwire/data-drizzle` or `@nwire/store-mongo`
|
|
62
|
+
| A new error type | `app/errors/<resource>-errors.ts` — `defineError({ code, status, summary })` |
|
|
63
|
+
| A new middleware | `app/middleware/<name>.ts` exports `HttpMiddleware`; `.use()` it from `api.ts` |
|
|
64
|
+
| A new resource | `app/resources/<name>.ts` — `defineResource` schema + `public` field list |
|
|
65
|
+
| Real persistence | Swap `app/store/todo-store.ts` for `@nwire/data-drizzle` or `@nwire/store-mongo` |
|
|
66
66
|
|
|
67
67
|
## Grow up
|
|
68
68
|
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"test": "vitest run"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nwire/app": "^0.
|
|
12
|
-
"@nwire/container": "^0.
|
|
13
|
-
"@nwire/endpoint": "^0.
|
|
14
|
-
"@nwire/forge": "^0.
|
|
15
|
-
"@nwire/http": "^0.
|
|
11
|
+
"@nwire/app": "^0.8.17",
|
|
12
|
+
"@nwire/container": "^0.8.17",
|
|
13
|
+
"@nwire/endpoint": "^0.8.17",
|
|
14
|
+
"@nwire/forge": "^0.8.17",
|
|
15
|
+
"@nwire/http": "^0.8.17",
|
|
16
16
|
"zod": "^4.0.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
package/templates/L4/README.md
CHANGED
|
@@ -60,6 +60,8 @@ pnpm test
|
|
|
60
60
|
│ │ └── auto-moderate.ts ← defineWorkflow — saga shape
|
|
61
61
|
│ ├── projections/
|
|
62
62
|
│ │ └── queue-dashboard.ts ← defineProjection + queries
|
|
63
|
+
│ ├── queries/
|
|
64
|
+
│ │ └── posts-by-author.ts ← defineQuery handler form (no projection)
|
|
63
65
|
│ └── routes/
|
|
64
66
|
│ ├── submit-post.ts ← POST /api/posts
|
|
65
67
|
│ ├── approve-post.ts ← POST /api/posts/:postId/approve
|
|
@@ -73,14 +75,18 @@ pnpm test
|
|
|
73
75
|
|
|
74
76
|
## Where to add a …
|
|
75
77
|
|
|
76
|
-
| You want to add … | Where it goes
|
|
77
|
-
| ----------------- |
|
|
78
|
-
| A new event | `modules/<bc>/events/<noun-was-verbed>.ts` — `defineEvent`; register in module
|
|
79
|
-
| A new action | `modules/<bc>/actions/<verb-noun>.ts` — `defineAction({ emits, handler })`
|
|
80
|
-
| A new workflow | `modules/<bc>/workflows/<name>.ts` — `defineWorkflow(({ on, send }) => ...)`
|
|
81
|
-
| A new projection | `modules/<bc>/projections/<name>.ts` — `defineProjection` + co-located `defineQuery
|
|
78
|
+
| You want to add … | Where it goes |
|
|
79
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------- |
|
|
80
|
+
| A new event | `modules/<bc>/events/<noun-was-verbed>.ts` — `defineEvent`; register in module |
|
|
81
|
+
| A new action | `modules/<bc>/actions/<verb-noun>.ts` — `defineAction({ emits, handler })` |
|
|
82
|
+
| A new workflow | `modules/<bc>/workflows/<name>.ts` — `defineWorkflow(({ on, send }) => ...)` |
|
|
83
|
+
| A new projection | `modules/<bc>/projections/<name>.ts` — `defineProjection` + co-located `defineQuery` |
|
|
84
|
+
| A query off a DB | `modules/<bc>/queries/<name>.ts` — `defineQuery({ name, schema, handler })`; `ctx.resolve("db")` |
|
|
82
85
|
| A new route | `modules/<bc>/routes/<verb-noun>.ts` exports `{name}Route + {name}Handler`; `.wire()` from `app/api.ts` |
|
|
83
|
-
| A new bounded ctx | `modules/<new-bc>/` mirroring `posts/`; add to `createApp({ modules: [...] })` in `app/app.ts`
|
|
86
|
+
| A new bounded ctx | `modules/<new-bc>/` mirroring `posts/`; add to `createApp({ modules: [...] })` in `app/app.ts` |
|
|
87
|
+
|
|
88
|
+
See also: [Concepts → Write paths](https://nwire.dev/docs/concepts/write-paths) — when to use an
|
|
89
|
+
actor (`defineActor`) versus a direct DB write inside a handler.
|
|
84
90
|
|
|
85
91
|
## Studio
|
|
86
92
|
|
|
@@ -18,6 +18,11 @@ import { z } from "zod";
|
|
|
18
18
|
import { defineAction } from "@nwire/forge";
|
|
19
19
|
import { PostWasSubmitted } from "../events/post-was-submitted";
|
|
20
20
|
|
|
21
|
+
// dispatch via: execute(submitPost({ authorId, body }))
|
|
22
|
+
// — same shape as defineEvent: the action is callable, mints a typed
|
|
23
|
+
// CommandMessage with validated input, then `execute` routes it.
|
|
24
|
+
// `runtime.dispatch(submitPost, input)` still works too.
|
|
25
|
+
|
|
21
26
|
export const submitPost = defineAction({
|
|
22
27
|
name: "posts.submit-post",
|
|
23
28
|
description: "Author submits a draft to the moderation queue.",
|
|
@@ -24,6 +24,7 @@ import { rejectPost } from "./actions/reject-post";
|
|
|
24
24
|
import { autoModerate } from "./workflows/auto-moderate";
|
|
25
25
|
|
|
26
26
|
import { queueDashboard, listPending, queueTotals, getPost } from "./projections/queue-dashboard";
|
|
27
|
+
import { postsByAuthor } from "./queries/posts-by-author";
|
|
27
28
|
|
|
28
29
|
export const postsModule = defineModule("posts", {
|
|
29
30
|
description: "Post moderation queue — submit, auto-check, decide, dashboard.",
|
|
@@ -31,5 +32,5 @@ export const postsModule = defineModule("posts", {
|
|
|
31
32
|
actions: [submitPost.public(), approvePost.public(), rejectPost.public()],
|
|
32
33
|
workflows: [autoModerate],
|
|
33
34
|
projections: [queueDashboard],
|
|
34
|
-
queries: [listPending.public(), queueTotals.public(), getPost.public()],
|
|
35
|
+
queries: [listPending.public(), queueTotals.public(), getPost.public(), postsByAuthor.public()],
|
|
35
36
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postsByAuthor — handler-form query (no projection).
|
|
3
|
+
*
|
|
4
|
+
* Most queries in this template are projection-driven — `defineQuery` is
|
|
5
|
+
* handed a projection and reads from its folded state. That's the right
|
|
6
|
+
* default when the read can be eventually-consistent over events you
|
|
7
|
+
* publish in-process.
|
|
8
|
+
*
|
|
9
|
+
* Sometimes the read lives somewhere else entirely: a Postgres table the
|
|
10
|
+
* domain doesn't own, a search index, a cache. For those, defineQuery
|
|
11
|
+
* accepts a flat handler form — no projection, no state. The handler
|
|
12
|
+
* receives validated input plus a `QueryContext` that can resolve DI
|
|
13
|
+
* bindings (a `db` connection, an http client, anything the runtime
|
|
14
|
+
* registered).
|
|
15
|
+
*
|
|
16
|
+
* defineQuery({ name, schema, handler })
|
|
17
|
+
*
|
|
18
|
+
* The handler below returns a small mock list so the template boots
|
|
19
|
+
* out of the box. The shape of a real implementation is in the comment
|
|
20
|
+
* inside `handler` — swap the mock for a `ctx.resolve<DrizzleDb>("db")`
|
|
21
|
+
* call (or whatever your store binding is named) and you're done.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
import { defineQuery } from "@nwire/forge";
|
|
26
|
+
|
|
27
|
+
interface AuthorPost {
|
|
28
|
+
postId: string;
|
|
29
|
+
authorId: string;
|
|
30
|
+
status: "pending" | "approved" | "rejected";
|
|
31
|
+
submittedAt: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const postsByAuthor = defineQuery({
|
|
35
|
+
name: "posts.by-author",
|
|
36
|
+
description: "All posts an author has submitted, across statuses.",
|
|
37
|
+
schema: z.object({
|
|
38
|
+
authorId: z.string(),
|
|
39
|
+
limit: z.coerce.number().int().min(1).max(100).default(20),
|
|
40
|
+
}),
|
|
41
|
+
handler: async ({ authorId, limit }, _ctx): Promise<AuthorPost[]> => {
|
|
42
|
+
// Production form:
|
|
43
|
+
// const db = _ctx.resolve<DrizzleDb>("db");
|
|
44
|
+
// return db.select().from(posts).where(eq(posts.authorId, authorId)).limit(limit);
|
|
45
|
+
//
|
|
46
|
+
// Template form — small in-memory mock so this boots without a DB:
|
|
47
|
+
const all: AuthorPost[] = [
|
|
48
|
+
{ postId: "p-1", authorId, status: "approved", submittedAt: "2026-01-01T00:00:00Z" },
|
|
49
|
+
{ postId: "p-2", authorId, status: "pending", submittedAt: "2026-01-02T00:00:00Z" },
|
|
50
|
+
];
|
|
51
|
+
return all.slice(0, limit);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"test": "vitest run"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nwire/app": "^0.
|
|
12
|
-
"@nwire/endpoint": "^0.
|
|
13
|
-
"@nwire/forge": "^0.
|
|
14
|
-
"@nwire/http": "^0.
|
|
15
|
-
"@nwire/messages": "^0.
|
|
11
|
+
"@nwire/app": "^0.8.17",
|
|
12
|
+
"@nwire/endpoint": "^0.8.17",
|
|
13
|
+
"@nwire/forge": "^0.8.17",
|
|
14
|
+
"@nwire/http": "^0.8.17",
|
|
15
|
+
"@nwire/messages": "^0.8.17",
|
|
16
16
|
"zod": "^4.0.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@nwire/test-kit": "^0.
|
|
19
|
+
"@nwire/test-kit": "^0.8.17",
|
|
20
20
|
"@types/node": "^22.19.9",
|
|
21
21
|
"typescript": "^5.9.0",
|
|
22
22
|
"vite-node": "^3.2.4",
|