create-nwire 0.7.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/bin.mjs +3 -0
  4. package/dist/__tests__/scaffold.test.d.ts +9 -0
  5. package/dist/__tests__/scaffold.test.d.ts.map +1 -0
  6. package/dist/__tests__/scaffold.test.js +83 -0
  7. package/dist/__tests__/scaffold.test.js.map +1 -0
  8. package/dist/index.d.ts +30 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +168 -0
  11. package/dist/index.js.map +1 -0
  12. package/package.json +38 -0
  13. package/templates/L1/README.md +34 -0
  14. package/templates/L1/_gitignore +5 -0
  15. package/templates/L1/app/api.ts +18 -0
  16. package/templates/L1/app/main.ts +17 -0
  17. package/templates/L1/package.json +21 -0
  18. package/templates/L1/tsconfig.json +15 -0
  19. package/templates/L2/README.md +50 -0
  20. package/templates/L2/_gitignore +5 -0
  21. package/templates/L2/app/api.ts +125 -0
  22. package/templates/L2/app/errors.ts +48 -0
  23. package/templates/L2/app/main.ts +35 -0
  24. package/templates/L2/app/middleware.ts +32 -0
  25. package/templates/L2/app/model.ts +60 -0
  26. package/templates/L2/app/store.ts +122 -0
  27. package/templates/L2/package.json +24 -0
  28. package/templates/L2/tsconfig.json +15 -0
  29. package/templates/L4/README.md +52 -0
  30. package/templates/L4/_gitignore +5 -0
  31. package/templates/L4/app/actions.ts +81 -0
  32. package/templates/L4/app/api.ts +118 -0
  33. package/templates/L4/app/app.ts +28 -0
  34. package/templates/L4/app/auto-moderate.workflow.ts +78 -0
  35. package/templates/L4/app/events.ts +53 -0
  36. package/templates/L4/app/main.ts +39 -0
  37. package/templates/L4/app/moderation.module.ts +28 -0
  38. package/templates/L4/app/queue.projection.ts +162 -0
  39. package/templates/L4/package.json +25 -0
  40. package/templates/L4/tsconfig.json +15 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Gefter / 200apps Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # create-nwire
2
+
3
+ Scaffold a new Nwire project.
4
+
5
+ ```bash
6
+ # pnpm
7
+ pnpm create nwire my-app --template L2
8
+
9
+ # npm
10
+ npm create nwire my-app -- --template L2
11
+
12
+ # yarn
13
+ yarn create nwire my-app --template L2
14
+ ```
15
+
16
+ ## Templates
17
+
18
+ | Level | Shape | What you get |
19
+ | ----- | -------------- | -------------------------------------------------------------------------------------------------------- |
20
+ | `L1` | **Minimal** | One POST route. `httpInterface` + `endpoint`. No app, no DI. ~30 LOC. |
21
+ | `L2` | **Service** | Todo CRUD. Container, plugin lifecycle, structured errors, middleware, in-memory store. |
22
+ | `L4` | **Enterprise** | Moderation queue. `createApp`, modules, actors, events, stateful workflow (saga), projection, resolvers. |
23
+
24
+ Pick the smallest level that fits — graduating up is just re-scaffolding
25
+ into a new folder and porting your code one file at a time.
26
+
27
+ ## What ships with every level
28
+
29
+ - **Zod-validated** route handlers, automatic OpenAPI at `/openapi.json`
30
+ - **Graceful shutdown** via `@nwire/endpoint` (SIGTERM drain + lightship probes)
31
+ - **K8s probes** on port 9000 (`/readyz`, `/healthz`)
32
+ - **TypeScript strict** + Bundler module resolution for fast dev loops
33
+
34
+ ## After scaffold
35
+
36
+ ```bash
37
+ cd my-app
38
+ pnpm install
39
+ pnpm dev
40
+ ```
41
+
42
+ Then point `nwire studio` at the running app to get live traces +
43
+ manual dispatch.
44
+
45
+ ## Flags
46
+
47
+ | Flag | Effect |
48
+ | ------------ | ------------------------------------------------ |
49
+ | `--template` | `L1` \| `L2` \| `L4` (defaults to `L2`) |
50
+ | `--name` | Override project name (defaults to dir basename) |
package/bin.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from "./dist/index.js";
3
+ await runCli();
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Scaffold tests — verify each template materializes a coherent project
3
+ * directory with the project name substituted and the canonical files
4
+ * present. Does NOT install or boot the project (npm I in CI burns minutes
5
+ * and adds nothing — the templates themselves are exercised by the
6
+ * end-to-end examples that share their source).
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=scaffold.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaffold.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/scaffold.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Scaffold tests — verify each template materializes a coherent project
3
+ * directory with the project name substituted and the canonical files
4
+ * present. Does NOT install or boot the project (npm I in CI burns minutes
5
+ * and adds nothing — the templates themselves are exercised by the
6
+ * end-to-end examples that share their source).
7
+ */
8
+ import { mkdtempSync, readFileSync, existsSync, rmSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { describe, it, expect, beforeEach, afterEach } from "vitest";
12
+ import { scaffold } from "../index.js";
13
+ describe("create-nwire scaffold", () => {
14
+ let target;
15
+ beforeEach(() => {
16
+ target = mkdtempSync(join(tmpdir(), "create-nwire-test-"));
17
+ rmSync(target, { recursive: true, force: true });
18
+ });
19
+ afterEach(() => {
20
+ if (existsSync(target))
21
+ rmSync(target, { recursive: true, force: true });
22
+ });
23
+ it("L1 — writes minimal http+endpoint shape with project name swapped", () => {
24
+ const { written } = scaffold({ target, template: "L1", name: "alpha" });
25
+ expect(written.length).toBeGreaterThan(0);
26
+ const pkg = JSON.parse(readFileSync(join(target, "package.json"), "utf8"));
27
+ expect(pkg.name).toBe("alpha");
28
+ expect(pkg.dependencies["@nwire/endpoint"]).toBeDefined();
29
+ expect(pkg.dependencies["@nwire/http"]).toBeDefined();
30
+ expect(existsSync(join(target, "src/main.ts"))).toBe(true);
31
+ expect(existsSync(join(target, "src/api.ts"))).toBe(true);
32
+ expect(existsSync(join(target, "tsconfig.json"))).toBe(true);
33
+ expect(existsSync(join(target, ".gitignore"))).toBe(true);
34
+ expect(readFileSync(join(target, "src/main.ts"), "utf8")).toContain('"alpha"');
35
+ });
36
+ it("L2 — writes the full service shape (model + errors + middleware + store)", () => {
37
+ const { written } = scaffold({ target, template: "L2", name: "beta-svc" });
38
+ expect(written.length).toBeGreaterThan(0);
39
+ const pkg = JSON.parse(readFileSync(join(target, "package.json"), "utf8"));
40
+ expect(pkg.name).toBe("beta-svc");
41
+ expect(pkg.dependencies["@nwire/forge"]).toBeDefined();
42
+ for (const f of ["main.ts", "api.ts", "model.ts", "errors.ts", "middleware.ts", "store.ts"]) {
43
+ expect(existsSync(join(target, "src", f))).toBe(true);
44
+ }
45
+ });
46
+ it("L4 — writes the enterprise shape (modules + workflow + projection)", () => {
47
+ const { written } = scaffold({ target, template: "L4", name: "gamma-app" });
48
+ expect(written.length).toBeGreaterThan(0);
49
+ const pkg = JSON.parse(readFileSync(join(target, "package.json"), "utf8"));
50
+ expect(pkg.name).toBe("gamma-app");
51
+ expect(pkg.dependencies["@nwire/app"]).toBeDefined();
52
+ expect(pkg.dependencies["@nwire/forge"]).toBeDefined();
53
+ for (const f of [
54
+ "main.ts",
55
+ "app.ts",
56
+ "api.ts",
57
+ "events.ts",
58
+ "actions.ts",
59
+ "moderation.module.ts",
60
+ "auto-moderate.workflow.ts",
61
+ "queue.projection.ts",
62
+ ]) {
63
+ expect(existsSync(join(target, "src", f))).toBe(true);
64
+ }
65
+ });
66
+ it("refuses to scaffold into a non-empty target", () => {
67
+ const { written } = scaffold({ target, template: "L1", name: "first" });
68
+ expect(written.length).toBeGreaterThan(0);
69
+ expect(() => scaffold({ target, template: "L1", name: "second" })).toThrowError(/not empty/);
70
+ });
71
+ it("derives project name from target dir basename when --name omitted", () => {
72
+ const t = join(tmpdir(), "create-nwire-derived-" + Date.now());
73
+ try {
74
+ scaffold({ target: t, template: "L1" });
75
+ const pkg = JSON.parse(readFileSync(join(t, "package.json"), "utf8"));
76
+ expect(pkg.name).toMatch(/^create-nwire-derived-/);
77
+ }
78
+ finally {
79
+ rmSync(t, { recursive: true, force: true });
80
+ }
81
+ });
82
+ });
83
+ //# sourceMappingURL=scaffold.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaffold.test.js","sourceRoot":"","sources":["../../src/__tests__/scaffold.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,QAAQ,CAAC,uBAAuB,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,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAC/F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QAC3E,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,uBAAuB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC;YACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACxC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACtE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;QACrD,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * create-nwire — scaffold a new Nwire project from one of three templates.
3
+ *
4
+ * L1 → smallest possible (httpInterface + endpoint only, no domain)
5
+ * L2 → in-memory app with one bounded context + middleware + structured errors
6
+ * L4 → full enterprise shape (modules + actors + workflows + projections + resolvers)
7
+ *
8
+ * Usage:
9
+ * pnpm create nwire <target-dir> [--template L1|L2|L4] [--no-install]
10
+ *
11
+ * The CLI is deliberately tiny — no interactive wizard, no plugin registry,
12
+ * no template fetching from GitHub. Picking a level is the only decision;
13
+ * everything else is whatever the user does once their starter is live.
14
+ */
15
+ export type TemplateLevel = "L1" | "L2" | "L4";
16
+ interface ScaffoldOptions {
17
+ target: string;
18
+ template: TemplateLevel;
19
+ name?: string;
20
+ }
21
+ /**
22
+ * Copy the template tree into target, swapping `{{PROJECT_NAME}}` in
23
+ * package.json and README.md so the scaffolded project reads coherent.
24
+ */
25
+ export declare function scaffold(opts: ScaffoldOptions): {
26
+ written: string[];
27
+ };
28
+ export declare function runCli(): Promise<void>;
29
+ export {};
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAiB/C,UAAU,eAAe;IACvB,MAAM,EAAI,MAAM,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,CAAC,EAAK,MAAM,CAAC;CAClB;AAeD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAiBrE;AAqGD,wBAAsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAE5C"}
package/dist/index.js ADDED
@@ -0,0 +1,168 @@
1
+ /**
2
+ * create-nwire — scaffold a new Nwire project from one of three templates.
3
+ *
4
+ * L1 → smallest possible (httpInterface + endpoint only, no domain)
5
+ * L2 → in-memory app with one bounded context + middleware + structured errors
6
+ * L4 → full enterprise shape (modules + actors + workflows + projections + resolvers)
7
+ *
8
+ * Usage:
9
+ * pnpm create nwire <target-dir> [--template L1|L2|L4] [--no-install]
10
+ *
11
+ * The CLI is deliberately tiny — no interactive wizard, no plugin registry,
12
+ * no template fetching from GitHub. Picking a level is the only decision;
13
+ * everything else is whatever the user does once their starter is live.
14
+ */
15
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
16
+ import { dirname, join, resolve } from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+ import { defineCommand, runMain } from "citty";
19
+ import pc from "picocolors";
20
+ const __dirname = dirname(fileURLToPath(import.meta.url));
21
+ const TEMPLATES = {
22
+ L1: {
23
+ title: "Minimal (L1)",
24
+ blurb: "httpInterface + endpoint only. ~30 LOC. No app, no DI, no domain.",
25
+ },
26
+ L2: {
27
+ title: "Service (L2)",
28
+ blurb: "Standalone http app with structured errors, middleware, in-memory store.",
29
+ },
30
+ L4: {
31
+ title: "Enterprise (L4)",
32
+ blurb: "Modules, actors, workflows, projections, resolvers — full forge shape.",
33
+ },
34
+ };
35
+ /**
36
+ * Locate the templates/ folder. In dev it's a sibling of dist/; in a
37
+ * published package it's a sibling of the bin entry. Resolve relative to
38
+ * this module file so both shapes work.
39
+ */
40
+ function templatesRoot() {
41
+ // dist/index.js → ../templates ; src/index.ts (dev) → ../templates
42
+ const candidate = resolve(__dirname, "..", "templates");
43
+ if (existsSync(candidate))
44
+ return candidate;
45
+ // Fallback: src layout — go up one more
46
+ return resolve(__dirname, "..", "..", "templates");
47
+ }
48
+ /**
49
+ * Copy the template tree into target, swapping `{{PROJECT_NAME}}` in
50
+ * package.json and README.md so the scaffolded project reads coherent.
51
+ */
52
+ export function scaffold(opts) {
53
+ const src = join(templatesRoot(), opts.template);
54
+ if (!existsSync(src)) {
55
+ throw new Error(`Template "${opts.template}" not found at ${src}`);
56
+ }
57
+ if (existsSync(opts.target) && readdirSync(opts.target).length > 0) {
58
+ throw new Error(`Target directory "${opts.target}" exists and is not empty.`);
59
+ }
60
+ mkdirSync(opts.target, { recursive: true });
61
+ const written = [];
62
+ copyTree(src, opts.target, written);
63
+ const projectName = opts.name ?? basename(opts.target);
64
+ applyVariables(opts.target, { PROJECT_NAME: projectName });
65
+ return { written };
66
+ }
67
+ function copyTree(src, dest, log) {
68
+ for (const entry of readdirSync(src)) {
69
+ const s = join(src, entry);
70
+ // npm strips dotfiles from published tarballs, so templates ship them
71
+ // as `_gitignore` / `_npmrc`; rename back on copy. Same trick that
72
+ // create-vite uses.
73
+ const renamed = entry.startsWith("_") ? "." + entry.slice(1) : entry;
74
+ const d = join(dest, renamed);
75
+ if (statSync(s).isDirectory()) {
76
+ mkdirSync(d, { recursive: true });
77
+ copyTree(s, d, log);
78
+ }
79
+ else {
80
+ cpSync(s, d);
81
+ log.push(d);
82
+ }
83
+ }
84
+ }
85
+ function applyVariables(root, vars) {
86
+ // Walk dest tree; for *.json, *.md, *.ts, *.mjs apply token substitution.
87
+ for (const entry of readdirSync(root)) {
88
+ const p = join(root, entry);
89
+ const st = statSync(p);
90
+ if (st.isDirectory()) {
91
+ applyVariables(p, vars);
92
+ continue;
93
+ }
94
+ if (!/\.(json|md|ts|mjs|js|cjs|yaml|yml)$/.test(entry))
95
+ continue;
96
+ const text = readFileSync(p, "utf8");
97
+ let out = text;
98
+ for (const [k, v] of Object.entries(vars)) {
99
+ out = out.split(`{{${k}}}`).join(v);
100
+ }
101
+ if (out !== text)
102
+ writeFileSync(p, out);
103
+ }
104
+ }
105
+ function basename(p) {
106
+ const parts = p.split(/[\\/]/).filter(Boolean);
107
+ return parts[parts.length - 1] ?? "nwire-app";
108
+ }
109
+ const main = defineCommand({
110
+ meta: {
111
+ name: "create-nwire",
112
+ description: "Scaffold a new Nwire project.",
113
+ },
114
+ args: {
115
+ target: {
116
+ type: "positional",
117
+ description: "Target directory (will be created if missing).",
118
+ required: false,
119
+ },
120
+ template: {
121
+ type: "string",
122
+ description: "Template level: L1 | L2 | L4",
123
+ default: "L2",
124
+ },
125
+ name: {
126
+ type: "string",
127
+ description: "Project name (defaults to target dir basename).",
128
+ },
129
+ },
130
+ async run(ctx) {
131
+ const targetArg = ctx.args.target;
132
+ if (!targetArg) {
133
+ console.error(pc.red("missing target directory."));
134
+ console.error(` ${pc.dim("e.g.")} ${pc.cyan("pnpm create nwire my-app --template L2")}`);
135
+ console.error("");
136
+ console.error("templates:");
137
+ for (const [k, v] of Object.entries(TEMPLATES)) {
138
+ console.error(` ${pc.yellow(k)} ${pc.bold(v.title)} ${pc.dim("— " + v.blurb)}`);
139
+ }
140
+ process.exit(1);
141
+ }
142
+ const tplRaw = String(ctx.args.template).toUpperCase();
143
+ if (tplRaw !== "L1" && tplRaw !== "L2" && tplRaw !== "L4") {
144
+ console.error(pc.red(`unknown template "${ctx.args.template}". Use L1, L2, or L4.`));
145
+ process.exit(1);
146
+ }
147
+ const template = tplRaw;
148
+ const target = resolve(process.cwd(), targetArg);
149
+ console.log(pc.cyan(`\n scaffolding ${pc.bold(template)} into ${pc.bold(target)}`));
150
+ try {
151
+ const { written } = scaffold({ target, template, name: ctx.args.name });
152
+ console.log(pc.green(` ✓ wrote ${written.length} files\n`));
153
+ console.log(` next:`);
154
+ console.log(` ${pc.dim("$")} ${pc.cyan(`cd ${targetArg}`)}`);
155
+ console.log(` ${pc.dim("$")} ${pc.cyan("pnpm install")}`);
156
+ console.log(` ${pc.dim("$")} ${pc.cyan("pnpm dev")}`);
157
+ console.log("");
158
+ }
159
+ catch (err) {
160
+ console.error(pc.red(` ✗ ${err.message}`));
161
+ process.exit(1);
162
+ }
163
+ },
164
+ });
165
+ export async function runCli() {
166
+ await runMain(main);
167
+ }
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5G,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,E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AO,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 ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "create-nwire",
3
+ "version": "0.7.0",
4
+ "description": "Scaffolder for new Nwire projects. Run `pnpm create nwire <name>` or `npm create nwire <name>` to bootstrap.",
5
+ "keywords": [
6
+ "nwire",
7
+ "scaffolder",
8
+ "starter",
9
+ "template"
10
+ ],
11
+ "bin": {
12
+ "create-nwire": "./bin.mjs"
13
+ },
14
+ "files": [
15
+ "bin.mjs",
16
+ "dist",
17
+ "templates",
18
+ "README.md"
19
+ ],
20
+ "type": "module",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "citty": "^0.1.6",
26
+ "picocolors": "^1.1.1"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^22.19.9",
30
+ "typescript": "^5.9.0",
31
+ "vitest": "^4.0.18"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc && node ../../scripts/fix-dist-extensions.mjs dist",
35
+ "typecheck": "tsc --noEmit",
36
+ "test": "vitest run"
37
+ }
38
+ }
@@ -0,0 +1,34 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ The smallest possible Nwire shape — one POST route, one inline handler,
4
+ no app, no DI, no domain primitives.
5
+
6
+ ## Run
7
+
8
+ ```bash
9
+ pnpm install
10
+ pnpm dev
11
+ ```
12
+
13
+ ## Try
14
+
15
+ ```bash
16
+ curl -X POST http://localhost:3000/hello \
17
+ -H "content-type: application/json" \
18
+ -d '{"name":"Alice"}'
19
+ ```
20
+
21
+ ## What you get free
22
+
23
+ | Feature | Comes from |
24
+ | -------------------------------------- | ----------------- |
25
+ | Zod request validation | `@nwire/http` |
26
+ | OpenAPI schema (visit `/openapi.json`) | `@nwire/http` |
27
+ | Graceful SIGTERM drain | `@nwire/endpoint` |
28
+ | K8s probes on port 9400 | `@nwire/endpoint` |
29
+
30
+ ## Grow up
31
+
32
+ When you outgrow inline handlers (multiple routes, persistence, events)
33
+ re-scaffold with `pnpm create nwire <name> --template L2` for the
34
+ service shape or `--template L4` for the full enterprise shape.
@@ -0,0 +1,5 @@
1
+ node_modules/
2
+ dist/
3
+ .nwire/
4
+ *.log
5
+ .DS_Store
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Single route — Zod-validated body, typed handler return.
3
+ *
4
+ * This is the smallest possible Nwire shape. Once you outgrow inline
5
+ * handlers (multiple bounded contexts, persistence, events) graduate
6
+ * to the L2 or L4 templates.
7
+ */
8
+
9
+ import { httpInterface, post } from "@nwire/http";
10
+ import { z } from "zod";
11
+
12
+ export const api = httpInterface().wire(
13
+ post("/hello", { body: z.object({ name: z.string().min(1) }) }),
14
+ async ({ input }) => {
15
+ const { name } = input as { name: string };
16
+ return { message: `Hello, ${name}!` };
17
+ },
18
+ );
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Entry — boots the http interface inside an endpoint.
3
+ *
4
+ * Run: pnpm dev
5
+ * Try: curl -X POST http://localhost:3000/hello \
6
+ * -H "content-type: application/json" \
7
+ * -d '{"name":"Alice"}'
8
+ *
9
+ * Probes (K8s readiness/liveness):
10
+ * curl http://localhost:9400/ready
11
+ * curl http://localhost:9400/live
12
+ */
13
+
14
+ import { endpoint } from "@nwire/endpoint";
15
+ import { api } from "./api";
16
+
17
+ await endpoint("{{PROJECT_NAME}}", { port: 3000 }).serve(api).run();
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite-node app/main.ts",
8
+ "test": "vitest run"
9
+ },
10
+ "dependencies": {
11
+ "@nwire/endpoint": "^0.7.0",
12
+ "@nwire/http": "^0.7.0",
13
+ "zod": "^4.0.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^22.19.9",
17
+ "typescript": "^5.9.0",
18
+ "vite-node": "^3.2.4",
19
+ "vitest": "^4.0.18"
20
+ }
21
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2022"],
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "noEmit": true,
12
+ "types": ["node", "vite/client"]
13
+ },
14
+ "include": ["app/**/*"]
15
+ }
@@ -0,0 +1,50 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ A Level 2 Nwire service — todo CRUD with structured errors, middleware
4
+ chain, public-shape projection, and an in-memory store wired via a
5
+ container binding.
6
+
7
+ No actors, no events, no workflows yet — see Level 4 for those.
8
+
9
+ ## Run
10
+
11
+ ```bash
12
+ pnpm install
13
+ pnpm dev
14
+ ```
15
+
16
+ ## Try
17
+
18
+ ```bash
19
+ # create a todo
20
+ curl -X POST http://localhost:3000/api/todos \
21
+ -H "content-type: application/json" \
22
+ -H "x-user-id: alice" \
23
+ -d '{"text":"buy milk"}'
24
+
25
+ # list this user's todos
26
+ curl -H "x-user-id: alice" http://localhost:3000/api/todos
27
+
28
+ # complete one
29
+ curl -X POST http://localhost:3000/api/todos/<id>/complete \
30
+ -H "x-user-id: alice"
31
+ ```
32
+
33
+ ## Source map
34
+
35
+ | File | What it does |
36
+ | --------------- | ----------------------------------------------------------- |
37
+ | `main.ts` | Boots `endpoint().serve(api).run()` |
38
+ | `api.ts` | The 4 routes + inline handlers |
39
+ | `model.ts` | `defineResource("Todo", ...)` — public field list |
40
+ | `errors.ts` | `defineError(...)` — `TodoNotFound`, `TodoAlreadyCompleted` |
41
+ | `middleware.ts` | `requireUser` — checks `x-user-id` header |
42
+ | `store.ts` | In-memory `TodoStore` + plugin shape |
43
+
44
+ Swap `store.ts` for `@nwire/data-drizzle` (Postgres) or
45
+ `@nwire/store-mongo` once you need durability.
46
+
47
+ ## Grow up
48
+
49
+ When you need bounded contexts, actors, events, workflows, projections,
50
+ re-scaffold with `pnpm create nwire <name> --template L4`.
@@ -0,0 +1,5 @@
1
+ node_modules/
2
+ dist/
3
+ .nwire/
4
+ *.log
5
+ .DS_Store