@forinda/kickjs-cli 3.1.2 → 3.2.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/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs-cli v3.1.2
2
+ * @forinda/kickjs-cli v3.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -711,6 +711,8 @@ Copy \`.env.example\` to \`.env\` and configure:
711
711
  function generateClaude(name, template, pm) {
712
712
  return `# CLAUDE.md — ${name} Development Guide
713
713
 
714
+ > **Read \`AGENTS.md\` first.** It is the canonical, multi-agent reference for this project (Claude, Copilot, Codex, Gemini, etc.). This file contains the same project context distilled for Claude, plus Claude-specific notes. When the two disagree on anything substantive, treat \`AGENTS.md\` as authoritative and flag the discrepancy.
715
+
714
716
  ## Project Overview
715
717
 
716
718
  This is a **${{
@@ -802,9 +804,12 @@ export class UserService {
802
804
 
803
805
  ### Modules
804
806
 
805
- Modules implement \`AppModule\` and wire controllers via \`buildRoutes()\`:
807
+ Modules implement \`AppModule\` and wire controllers via \`buildRoutes()\`.
808
+
809
+ > **Naming matters.** Module files **must** be named \`<name>.module.ts\` and live under \`src/modules/\`. The Vite plugin auto-discovers files matching \`*.module.[tj]sx?\` for HMR — a misnamed file (e.g., \`projects.ts\`) won't trigger a graceful module rebuild on save and will require a full server restart. The CLI generator (\`kick g module <name>\`) follows this convention automatically.
806
810
 
807
811
  \`\`\`ts
812
+ // src/modules/users/users.module.ts (named <feature>.module.ts)
808
813
  import { type AppModule, type ModuleRoutes, buildRoutes } from '@forinda/kickjs'
809
814
  import { UserController } from './user.controller'
810
815
 
@@ -855,6 +860,8 @@ ctx.notFound() // 404 Not Found
855
860
  ctx.badRequest(msg) // 400 Bad Request
856
861
  \`\`\`
857
862
 
863
+ > **Context decorators** — when a middleware's only job is to populate \`ctx.set/get\` for the handler to read, prefer \`defineContextDecorator()\` over \`@Middleware()\`. Typed via \`ContextMeta\`, supports \`dependsOn\` ordering, validates the pipeline at boot. Full pattern reference in \`AGENTS.md\` and at <https://forinda.github.io/kick-js/guide/context-decorators>.
864
+
858
865
  ## CLI Generators
859
866
 
860
867
  Generate code with the \`kick\` CLI:
@@ -1118,6 +1125,8 @@ ${template === "graphql" ? "| GraphQL resolvers | `src/resolvers/` |\n" : ""}| E
1118
1125
 
1119
1126
  ### Module Pattern (${template.toUpperCase()})
1120
1127
 
1128
+ > **Vite HMR auto-discovery contract:** module files **must** be named \`<name>.module.ts\` (or \`.tsx\`/\`.js\`/\`.jsx\`) and live under \`src/modules/\`. The Vite plugin scans for \`*.module.[tj]sx?\` to drive graceful HMR rebuilds; renaming a file to \`projects.ts\` (no \`.module\`) silently breaks HMR — saves trigger a full restart instead of a swap. The CLI generator (\`kick g module <name>\`) follows the convention; manual files must too.
1129
+
1121
1130
  Each module in \`src/modules/<name>/\` typically contains:
1122
1131
 
1123
1132
  ${template === "ddd" ? `\`\`\`
@@ -1401,6 +1410,27 @@ These work anywhere — scripts, plain files, outside \`@Service\`/\`@Controller
1401
1410
  | \`@Inject('token')\` | Token-based injection |
1402
1411
  | \`@Value('VAR')\` | Inject env variable |
1403
1412
 
1413
+ ### Context Decorators
1414
+
1415
+ Typed, ordered way to populate \`ctx.set/get\` keys before the handler runs.
1416
+ Use this **instead of \`@Middleware()\`** when the middleware's only output
1417
+ is a value other code reads off \`ctx\`.
1418
+
1419
+ | Concept | Where it lives |
1420
+ |---------|----------------|
1421
+ | \`defineContextDecorator({ key, deps, dependsOn, optional, onError, resolve })\` | \`@forinda/kickjs\` |
1422
+ | Method/class decorator | \`@LoadX\` on a controller method/class |
1423
+ | Module hook | \`AppModule.contributors?(): ContributorRegistration[]\` |
1424
+ | Adapter hook | \`AppAdapter.contributors?(): ContributorRegistration[]\` |
1425
+ | Global registration | \`bootstrap({ contributors: [LoadX.registration] })\` |
1426
+ | Type augmentation | \`declare module '@forinda/kickjs' { interface ContextMeta { ... } }\` |
1427
+
1428
+ Precedence high → low: **method > class > module > adapter > global**.
1429
+ Cycles and missing \`dependsOn\` keys throw at \`app.setup()\` (boot fails
1430
+ fast). The \`onError\` hook is async-permitted.
1431
+
1432
+ Full guide: <https://forinda.github.io/kick-js/guide/context-decorators>.
1433
+
1404
1434
  ${template === "graphql" ? `### GraphQL
1405
1435
  | Decorator | Purpose |
1406
1436
  |-----------|---------|
@@ -1423,9 +1453,11 @@ ${template === "graphql" ? `### GraphQL
1423
1453
  2. **DI not working** — Ensure \`reflect-metadata\` is imported in \`src/index.ts\`
1424
1454
  3. **Tests failing randomly** — Missing \`Container.reset()\` in \`beforeEach\`
1425
1455
  4. **Routes not found** — Check controller path and module registration
1426
- 5. **HMR not working** — Verify \`vite.config.ts\` has \`hmr: true\`
1456
+ 5. **HMR not working** — Two checks: (a) \`vite.config.ts\` has \`hmr: true\`; (b) module file is named \`<name>.module.ts\` (or \`.tsx\`/\`.js\`/\`.jsx\`) and lives under \`src/modules/\`. The Vite plugin auto-discovers \`*.module.[tj]sx?\` for graceful HMR — a misnamed module file (e.g., \`projects.ts\`) silently degrades to a full restart on every save.
1427
1457
  6. **Decorators not working** — Check \`tsconfig.json\` has \`experimentalDecorators: true\`
1428
1458
  7. **\`config.get('YOUR_KEY')\` returns \`undefined\`** — \`src/index.ts\` is missing \`import './config'\`. That side-effect import registers the env schema with kickjs (\`loadEnv(envSchema)\` runs at module load). Without it, \`ConfigService\` falls back to the base schema (\`PORT\`/\`NODE_ENV\`/\`LOG_LEVEL\` only) and every user-defined key reads as \`undefined\`. \`@Value()\` may *appear* to work because of a raw \`process.env\` fallback, but Zod coercion and schema defaults are silently skipped — investigate \`src/index.ts\` and \`src/config/index.ts\` first.
1459
+ 8. **Used \`@Middleware()\` to compute a value for \`ctx\`** — prefer \`defineContextDecorator()\` (see Context Decorators above). It's typed via \`ContextMeta\`, supports \`dependsOn\` for ordering, and validates the pipeline at boot. \`@Middleware()\` is for response short-circuiting, stream mutation, and pre-route-matching work.
1460
+ 9. **Context contributor's \`dependsOn\` key not produced anywhere** — boot throws \`MissingContributorError\` naming the dependent and the route. Either remove the dep or register a contributor that produces the key (at any precedence level: method/class/module/adapter/global).
1429
1461
 
1430
1462
  ## CLI Commands Reference
1431
1463
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @forinda/kickjs-cli v3.1.2
2
+ * @forinda/kickjs-cli v3.2.0
3
3
  *
4
4
  * Copyright (c) Felix Orinda
5
5
  *
@@ -2980,6 +2980,8 @@ Copy \`.env.example\` to \`.env\` and configure:
2980
2980
  function generateClaude(name, template, pm) {
2981
2981
  return `# CLAUDE.md — ${name} Development Guide
2982
2982
 
2983
+ > **Read \`AGENTS.md\` first.** It is the canonical, multi-agent reference for this project (Claude, Copilot, Codex, Gemini, etc.). This file contains the same project context distilled for Claude, plus Claude-specific notes. When the two disagree on anything substantive, treat \`AGENTS.md\` as authoritative and flag the discrepancy.
2984
+
2983
2985
  ## Project Overview
2984
2986
 
2985
2987
  This is a **${{
@@ -3071,9 +3073,12 @@ export class UserService {
3071
3073
 
3072
3074
  ### Modules
3073
3075
 
3074
- Modules implement \`AppModule\` and wire controllers via \`buildRoutes()\`:
3076
+ Modules implement \`AppModule\` and wire controllers via \`buildRoutes()\`.
3077
+
3078
+ > **Naming matters.** Module files **must** be named \`<name>.module.ts\` and live under \`src/modules/\`. The Vite plugin auto-discovers files matching \`*.module.[tj]sx?\` for HMR — a misnamed file (e.g., \`projects.ts\`) won't trigger a graceful module rebuild on save and will require a full server restart. The CLI generator (\`kick g module <name>\`) follows this convention automatically.
3075
3079
 
3076
3080
  \`\`\`ts
3081
+ // src/modules/users/users.module.ts (named <feature>.module.ts)
3077
3082
  import { type AppModule, type ModuleRoutes, buildRoutes } from '@forinda/kickjs'
3078
3083
  import { UserController } from './user.controller'
3079
3084
 
@@ -3124,6 +3129,8 @@ ctx.notFound() // 404 Not Found
3124
3129
  ctx.badRequest(msg) // 400 Bad Request
3125
3130
  \`\`\`
3126
3131
 
3132
+ > **Context decorators** — when a middleware's only job is to populate \`ctx.set/get\` for the handler to read, prefer \`defineContextDecorator()\` over \`@Middleware()\`. Typed via \`ContextMeta\`, supports \`dependsOn\` ordering, validates the pipeline at boot. Full pattern reference in \`AGENTS.md\` and at <https://forinda.github.io/kick-js/guide/context-decorators>.
3133
+
3127
3134
  ## CLI Generators
3128
3135
 
3129
3136
  Generate code with the \`kick\` CLI:
@@ -3387,6 +3394,8 @@ ${template === "graphql" ? "| GraphQL resolvers | `src/resolvers/` |\n" : ""}| E
3387
3394
 
3388
3395
  ### Module Pattern (${template.toUpperCase()})
3389
3396
 
3397
+ > **Vite HMR auto-discovery contract:** module files **must** be named \`<name>.module.ts\` (or \`.tsx\`/\`.js\`/\`.jsx\`) and live under \`src/modules/\`. The Vite plugin scans for \`*.module.[tj]sx?\` to drive graceful HMR rebuilds; renaming a file to \`projects.ts\` (no \`.module\`) silently breaks HMR — saves trigger a full restart instead of a swap. The CLI generator (\`kick g module <name>\`) follows the convention; manual files must too.
3398
+
3390
3399
  Each module in \`src/modules/<name>/\` typically contains:
3391
3400
 
3392
3401
  ${template === "ddd" ? `\`\`\`
@@ -3670,6 +3679,27 @@ These work anywhere — scripts, plain files, outside \`@Service\`/\`@Controller
3670
3679
  | \`@Inject('token')\` | Token-based injection |
3671
3680
  | \`@Value('VAR')\` | Inject env variable |
3672
3681
 
3682
+ ### Context Decorators
3683
+
3684
+ Typed, ordered way to populate \`ctx.set/get\` keys before the handler runs.
3685
+ Use this **instead of \`@Middleware()\`** when the middleware's only output
3686
+ is a value other code reads off \`ctx\`.
3687
+
3688
+ | Concept | Where it lives |
3689
+ |---------|----------------|
3690
+ | \`defineContextDecorator({ key, deps, dependsOn, optional, onError, resolve })\` | \`@forinda/kickjs\` |
3691
+ | Method/class decorator | \`@LoadX\` on a controller method/class |
3692
+ | Module hook | \`AppModule.contributors?(): ContributorRegistration[]\` |
3693
+ | Adapter hook | \`AppAdapter.contributors?(): ContributorRegistration[]\` |
3694
+ | Global registration | \`bootstrap({ contributors: [LoadX.registration] })\` |
3695
+ | Type augmentation | \`declare module '@forinda/kickjs' { interface ContextMeta { ... } }\` |
3696
+
3697
+ Precedence high → low: **method > class > module > adapter > global**.
3698
+ Cycles and missing \`dependsOn\` keys throw at \`app.setup()\` (boot fails
3699
+ fast). The \`onError\` hook is async-permitted.
3700
+
3701
+ Full guide: <https://forinda.github.io/kick-js/guide/context-decorators>.
3702
+
3673
3703
  ${template === "graphql" ? `### GraphQL
3674
3704
  | Decorator | Purpose |
3675
3705
  |-----------|---------|
@@ -3692,9 +3722,11 @@ ${template === "graphql" ? `### GraphQL
3692
3722
  2. **DI not working** — Ensure \`reflect-metadata\` is imported in \`src/index.ts\`
3693
3723
  3. **Tests failing randomly** — Missing \`Container.reset()\` in \`beforeEach\`
3694
3724
  4. **Routes not found** — Check controller path and module registration
3695
- 5. **HMR not working** — Verify \`vite.config.ts\` has \`hmr: true\`
3725
+ 5. **HMR not working** — Two checks: (a) \`vite.config.ts\` has \`hmr: true\`; (b) module file is named \`<name>.module.ts\` (or \`.tsx\`/\`.js\`/\`.jsx\`) and lives under \`src/modules/\`. The Vite plugin auto-discovers \`*.module.[tj]sx?\` for graceful HMR — a misnamed module file (e.g., \`projects.ts\`) silently degrades to a full restart on every save.
3696
3726
  6. **Decorators not working** — Check \`tsconfig.json\` has \`experimentalDecorators: true\`
3697
3727
  7. **\`config.get('YOUR_KEY')\` returns \`undefined\`** — \`src/index.ts\` is missing \`import './config'\`. That side-effect import registers the env schema with kickjs (\`loadEnv(envSchema)\` runs at module load). Without it, \`ConfigService\` falls back to the base schema (\`PORT\`/\`NODE_ENV\`/\`LOG_LEVEL\` only) and every user-defined key reads as \`undefined\`. \`@Value()\` may *appear* to work because of a raw \`process.env\` fallback, but Zod coercion and schema defaults are silently skipped — investigate \`src/index.ts\` and \`src/config/index.ts\` first.
3728
+ 8. **Used \`@Middleware()\` to compute a value for \`ctx\`** — prefer \`defineContextDecorator()\` (see Context Decorators above). It's typed via \`ContextMeta\`, supports \`dependsOn\` for ordering, and validates the pipeline at boot. \`@Middleware()\` is for response short-circuiting, stream mutation, and pre-route-matching work.
3729
+ 9. **Context contributor's \`dependsOn\` key not produced anywhere** — boot throws \`MissingContributorError\` naming the dependent and the route. Either remove the dep or register a contributor that produces the key (at any precedence level: method/class/module/adapter/global).
3698
3730
 
3699
3731
  ## CLI Commands Reference
3700
3732
 
@@ -3772,7 +3804,7 @@ async function initProject(options) {
3772
3804
  }
3773
3805
  }
3774
3806
  try {
3775
- const { runTypegen } = await import("./typegen-D-the-Kw.mjs");
3807
+ const { runTypegen } = await import("./typegen-C30frihW.mjs");
3776
3808
  await runTypegen({
3777
3809
  cwd: dir,
3778
3810
  allowDuplicates: true,