@nilejs/cli 1.0.2 → 1.0.3

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
@@ -72,12 +72,12 @@ const getUserSchema = z.object({
72
72
 
73
73
  type GetUserInput = z.infer<typeof getUserSchema>;
74
74
 
75
- const getUserHandler = async (input: GetUserInput) => {
75
+ const getUserHandler = async (data: GetUserInput) => {
76
76
  // Implement users.get-user here
77
- return Ok({ result: input });
77
+ return Ok({ result: data });
78
78
  };
79
79
 
80
- export const getUserAction = createAction<GetUserInput>({
80
+ export const getUserAction = createAction({
81
81
  name: "get-user",
82
82
  description: "GetUser action for users",
83
83
  validation: getUserSchema,
@@ -107,7 +107,7 @@ Every registered action is included in `ServicePayloads`. Actions without a vali
107
107
 
108
108
  ## Current starter
109
109
 
110
- CLI 1.0.2 targets Nile `^1.0.4`, Zod 4, TypeScript 7 and the Drizzle model helpers. The generated layout passes Nile’s strict boot checks. Database setup returns a Result and prevents startup on failure; shutdown drains Nile’s work before closing PGlite. Helpers are available as `utils.createModel`, and Result helpers come from `@nilejs/nile/fp`.
110
+ The starter uses Nile `^1.0.5`, Zod 4, TypeScript 7 and the Drizzle model helpers. The generated layout passes Nile’s strict boot checks. Database setup returns a Result and prevents startup on failure; shutdown drains Nile’s work before closing PGlite. Helpers are available as `utils.createModel`, and Result helpers come from `@nilejs/nile/fp`.
111
111
 
112
112
  Existing apps are not rewritten when the CLI updates. For an older starter, add a service entry point at `src/services/<domain>/index.ts`, register its actions there, and import that service from `services.config.ts`. [Nile’s migration notes](https://github.com/nile-js/nile/blob/main/packages/nile/docs/release-migration.md) describe the current error and startup behavior.
113
113
 
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import { resolve as resolve6 } from "node:path";
5
5
  import { Command } from "commander";
6
6
  // package.json
7
- var version = "1.0.2";
7
+ var version = "1.0.3";
8
8
 
9
9
  // src/commands/generate-action.ts
10
10
  import { resolve } from "node:path";
@@ -99,12 +99,12 @@ const ${camel}Schema = z.object({
99
99
 
100
100
  type ${pascal}Input = z.infer<typeof ${camel}Schema>;
101
101
 
102
- const ${camel}Handler = async (input: ${pascal}Input) => {
102
+ const ${camel}Handler = async (data: ${pascal}Input) => {
103
103
  // Implement ${serviceName}.${actionName} here
104
- return Ok({ result: input });
104
+ return Ok({ result: data });
105
105
  };
106
106
 
107
- export const ${camel}Action = createAction<${pascal}Input>({
107
+ export const ${camel}Action = createAction({
108
108
  name: "${actionName}",
109
109
  description: "${pascal} action for ${serviceName}",
110
110
  validation: ${camel}Schema,
@@ -459,11 +459,11 @@ const sample${pascal}Schema = z.object({
459
459
 
460
460
  type Sample${pascal}Input = z.infer<typeof sample${pascal}Schema>;
461
461
 
462
- const sample${pascal}Handler = async (input: Sample${pascal}Input) => {
463
- return Ok({ ${camel}: { name: input.name } });
462
+ const sample${pascal}Handler = async (data: Sample${pascal}Input) => {
463
+ return Ok({ ${camel}: { name: data.name } });
464
464
  };
465
465
 
466
- export const sample${pascal}Action = createAction<Sample${pascal}Input>({
466
+ export const sample${pascal}Action = createAction({
467
467
  name: "sample",
468
468
  description: "Sample ${serviceName} action",
469
469
  validation: sample${pascal}Schema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nilejs/cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "CLI for scaffolding and generating Nile backend projects",
5
5
  "type": "module",
6
6
  "bin": {
package/template/SKILL.md CHANGED
@@ -49,7 +49,7 @@ Structure violations fail startup by default. An application needs `src/index.ts
49
49
 
50
50
  ## The action pattern
51
51
 
52
- Every action uses a named schema, an inferred input type, a separately written named handler and `createAction<T>`:
52
+ Define a named schema, derive the handler’s data type and pass the named handler to `createAction`. The action type and handler return type are inferred. Use `data` and `context` for the parameters you need; omit unused parameters:
53
53
 
54
54
  ```ts
55
55
  import { createAction } from "@nilejs/nile";
@@ -62,15 +62,15 @@ const createProjectSchema = z.object({
62
62
 
63
63
  type CreateProjectInput = z.infer<typeof createProjectSchema>;
64
64
 
65
- const createProjectHandler = (input: CreateProjectInput) => {
66
- if (input.name === "system") {
65
+ const createProjectHandler = (data: CreateProjectInput) => {
66
+ if (data.name === "system") {
67
67
  return Err("Choose a different project name");
68
68
  }
69
69
 
70
- return Ok({ project: { name: input.name } });
70
+ return Ok({ project: { name: data.name } });
71
71
  };
72
72
 
73
- export const createProjectAction = createAction<CreateProjectInput>({
73
+ export const createProjectAction = createAction({
74
74
  name: "create",
75
75
  description: "Create a project",
76
76
  validation: createProjectSchema,
@@ -104,7 +104,7 @@ Action names are unique within a service. Folder names do not create routes; onl
104
104
 
105
105
  ## Handlers take (data, context)
106
106
 
107
- Nile Js calls every handler with two arguments: the validated input and the execution's `NileContext`. The type marks the context optional. Use `createAction<Input>` for the schema’s parsed output type, and import `NileContext` when annotating a named handler’s second argument. Read an optional context with `?.` or explicitly reject its absence before using it.
107
+ Nile Js calls every handler with two arguments: the validated input and the execution's `NileContext`. For a named handler, annotate `data` with the schema’s parsed output type and use `context` for its second parameter. Import `NileContext` when you need to annotate it. `createAction` infers its type from the handler; leave off the repeated generic argument and inferred return annotation. Read an optional context with `?.` or explicitly reject its absence before using it.
108
108
 
109
109
  - `context.getSession("rest")` returns the verified JWT identity (`userId`, `organizationId` and other claims) for a protected action.
110
110
  - `context.resources` holds what `createNileServer` received (`logger`, `database`).
@@ -324,7 +324,7 @@ Advanced pages cover handler context, composed hooks, execution options and test
324
324
  1. Read `services.config.ts`, the target service’s `index.ts` and its actions before you change anything.
325
325
  2. Follow the existing pattern in that service. Do not add a second architecture.
326
326
  3. Never invent an API. Check the guide, the installed `@nilejs/nile` types in `node_modules`, or the existing code. If it is not there, say so.
327
- 4. Use named schemas, inferred input types, named handlers, `createAction<T>` and braces on every `if`.
327
+ 4. Use named schemas and handlers. Name action parameters `data` and `context`, and hook parameters `hookContext`. Annotate a named handler’s data from the schema; let `createAction` and return types infer the rest. Use braces on every `if`.
328
328
  5. Start with business rules in the action’s named handler. Move reusable rules or transaction coordination into ordinary domain functions when that makes them easier to share or test. Keep persistence in models or repositories; keep transaction boundaries explicit.
329
329
  6. Typecheck and run the relevant tests after a coherent change. Exercise the registered action through `server.invoke` or a transport when registration, policy or validation changes.
330
330
  7. Do not commit, publish or change secrets, `.env` values or deployment settings unless the user asks.
@@ -12,7 +12,7 @@
12
12
  "typecheck": "tsc --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@nilejs/nile": "^1.0.4",
15
+ "@nilejs/nile": "^1.0.5",
16
16
  "@electric-sql/pglite": "^0.2.5",
17
17
  "drizzle-orm": "^0.45.4",
18
18
  "pino": "^10.4.0",
@@ -54,12 +54,12 @@ const server = await createNileServer({
54
54
  onBoot: {
55
55
  // The first PGlite start on a slow machine can take longer than the 10 second default.
56
56
  maxWaitTime: 30_000,
57
- fn: async (ctx) => {
57
+ fn: async (context) => {
58
58
  const prepared = await pushSchema();
59
59
  if (prepared.isErr) {
60
60
  return prepared;
61
61
  }
62
- ctx.resources?.logger?.info({
62
+ context.resources?.logger?.info({
63
63
  atFunction: "onBoot",
64
64
  message: "{{projectName}} booted - PGLite schema ready",
65
65
  });
@@ -1,5 +1,5 @@
1
1
  import { createAction } from "@nilejs/nile";
2
- import { Err, Ok } from "@nilejs/nile/fp";
2
+ import { Ok } from "@nilejs/nile/fp";
3
3
  import z from "zod";
4
4
  import { taskModel } from "@/db/models";
5
5
 
@@ -14,23 +14,23 @@ const createTaskSchema = z.object({
14
14
 
15
15
  type CreateTaskInput = z.infer<typeof createTaskSchema>;
16
16
 
17
- const createTaskHandler = async (input: CreateTaskInput) => {
17
+ const createTaskHandler = async (data: CreateTaskInput) => {
18
18
  const result = await taskModel.create({
19
19
  data: {
20
- title: input.title,
21
- description: input.description,
22
- status: input.status,
20
+ title: data.title,
21
+ description: data.description,
22
+ status: data.status,
23
23
  },
24
24
  });
25
25
 
26
26
  if (result.isErr) {
27
- return Err(result.error);
27
+ return result;
28
28
  }
29
29
 
30
30
  return Ok({ task: result.value });
31
31
  };
32
32
 
33
- export const createTaskAction = createAction<CreateTaskInput>({
33
+ export const createTaskAction = createAction({
34
34
  name: "create",
35
35
  description: "Create a new task",
36
36
  validation: createTaskSchema,
@@ -1,5 +1,5 @@
1
1
  import { createAction } from "@nilejs/nile";
2
- import { Err, Ok } from "@nilejs/nile/fp";
2
+ import { Ok } from "@nilejs/nile/fp";
3
3
  import z from "zod";
4
4
  import { taskModel } from "@/db/models";
5
5
 
@@ -9,17 +9,17 @@ const deleteTaskSchema = z.object({
9
9
 
10
10
  type DeleteTaskInput = z.infer<typeof deleteTaskSchema>;
11
11
 
12
- const deleteTaskHandler = async (input: DeleteTaskInput) => {
13
- const result = await taskModel.delete(input.id);
12
+ const deleteTaskHandler = async (data: DeleteTaskInput) => {
13
+ const result = await taskModel.delete(data.id);
14
14
 
15
15
  if (result.isErr) {
16
- return Err(result.error);
16
+ return result;
17
17
  }
18
18
 
19
- return Ok({ deleted: true, id: input.id });
19
+ return Ok({ deleted: true, id: data.id });
20
20
  };
21
21
 
22
- export const deleteTaskAction = createAction<DeleteTaskInput>({
22
+ export const deleteTaskAction = createAction({
23
23
  name: "delete",
24
24
  description: "Delete a task by ID",
25
25
  validation: deleteTaskSchema,
@@ -1,5 +1,5 @@
1
1
  import { createAction } from "@nilejs/nile";
2
- import { Err, Ok } from "@nilejs/nile/fp";
2
+ import { Ok } from "@nilejs/nile/fp";
3
3
  import z from "zod";
4
4
  import { taskModel } from "@/db/models";
5
5
 
@@ -9,17 +9,17 @@ const getTaskSchema = z.object({
9
9
 
10
10
  type GetTaskInput = z.infer<typeof getTaskSchema>;
11
11
 
12
- const getTaskHandler = async (input: GetTaskInput) => {
13
- const result = await taskModel.findById(input.id);
12
+ const getTaskHandler = async (data: GetTaskInput) => {
13
+ const result = await taskModel.findById(data.id);
14
14
 
15
15
  if (result.isErr) {
16
- return Err(result.error);
16
+ return result;
17
17
  }
18
18
 
19
19
  return Ok({ task: result.value });
20
20
  };
21
21
 
22
- export const getTaskAction = createAction<GetTaskInput>({
22
+ export const getTaskAction = createAction({
23
23
  name: "get",
24
24
  description: "Get a task by ID",
25
25
  validation: getTaskSchema,
@@ -1,12 +1,12 @@
1
1
  import { createAction } from "@nilejs/nile";
2
- import { Err, Ok } from "@nilejs/nile/fp";
2
+ import { Ok } from "@nilejs/nile/fp";
3
3
  import { taskModel } from "@/db/models";
4
4
 
5
5
  const listTasksHandler = async () => {
6
6
  const result = await taskModel.findAll();
7
7
 
8
8
  if (result.isErr) {
9
- return Err(result.error);
9
+ return result;
10
10
  }
11
11
 
12
12
  return Ok({ tasks: result.value });
@@ -1,5 +1,5 @@
1
1
  import { createAction } from "@nilejs/nile";
2
- import { Err, Ok } from "@nilejs/nile/fp";
2
+ import { Ok } from "@nilejs/nile/fp";
3
3
  import z from "zod";
4
4
  import { taskModel } from "@/db/models";
5
5
 
@@ -12,25 +12,25 @@ const updateTaskSchema = z.object({
12
12
 
13
13
  type UpdateTaskInput = z.infer<typeof updateTaskSchema>;
14
14
 
15
- const updateTaskHandler = async (input: UpdateTaskInput) => {
15
+ const updateTaskHandler = async (data: UpdateTaskInput) => {
16
16
  // Fields left out of the request stay undefined and are not changed.
17
17
  const result = await taskModel.update({
18
- id: input.id,
18
+ id: data.id,
19
19
  data: {
20
- title: input.title,
21
- description: input.description,
22
- status: input.status,
20
+ title: data.title,
21
+ description: data.description,
22
+ status: data.status,
23
23
  },
24
24
  });
25
25
 
26
26
  if (result.isErr) {
27
- return Err(result.error);
27
+ return result;
28
28
  }
29
29
 
30
30
  return Ok({ task: result.value });
31
31
  };
32
32
 
33
- export const updateTaskAction = createAction<UpdateTaskInput>({
33
+ export const updateTaskAction = createAction({
34
34
  name: "update",
35
35
  description: "Update an existing task",
36
36
  validation: updateTaskSchema,