@nilejs/cli 1.0.1 → 1.0.2
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 +2 -2
- package/dist/index.js +8 -15
- package/package.json +5 -3
- package/template/README.md +1 -1
package/README.md
CHANGED
|
@@ -103,11 +103,11 @@ Reads every action's validation schema from `src/services/services.config.ts` an
|
|
|
103
103
|
| `-e, --entry <path>` | Path to the services config (detected by default) |
|
|
104
104
|
| `-o, --output <path>` | Output directory (default: `src/generated`) |
|
|
105
105
|
|
|
106
|
-
Actions without a validation schema
|
|
106
|
+
Every registered action is included in `ServicePayloads`. Actions without a validation schema accept an object payload (`Record<string, unknown>`), so actions such as `tasks.list` can be called with `{}`. This fallback does not add server-side validation. Schemas that cannot be converted are reported separately. Share the generated files with a frontend to validate forms with the same rules as the server.
|
|
107
107
|
|
|
108
108
|
## Current starter
|
|
109
109
|
|
|
110
|
-
CLI 1.0.
|
|
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`.
|
|
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.
|
|
7
|
+
var version = "1.0.2";
|
|
8
8
|
|
|
9
9
|
// src/commands/generate-action.ts
|
|
10
10
|
import { resolve } from "node:path";
|
|
@@ -210,7 +210,7 @@ var buildSchemaEntries = (extraction) => {
|
|
|
210
210
|
const entries = [];
|
|
211
211
|
for (const [serviceName, actions] of Object.entries(extraction.schemas)) {
|
|
212
212
|
for (const [actionName, jsonSchema] of Object.entries(actions)) {
|
|
213
|
-
const zodCode = jsonSchemaToZod(jsonSchema, {
|
|
213
|
+
const zodCode = jsonSchema === null ? "z.record(z.string(), z.unknown())" : jsonSchemaToZod(jsonSchema, {
|
|
214
214
|
noImport: true
|
|
215
215
|
});
|
|
216
216
|
entries.push({
|
|
@@ -237,7 +237,7 @@ var generateSchemasFile = (extraction) => {
|
|
|
237
237
|
lines.push("");
|
|
238
238
|
}
|
|
239
239
|
if (extraction.skipped.length > 0) {
|
|
240
|
-
lines.push(`// Skipped (
|
|
240
|
+
lines.push(`// Skipped (schema conversion failed): ${extraction.skipped.join(", ")}`);
|
|
241
241
|
lines.push("");
|
|
242
242
|
}
|
|
243
243
|
return lines.join(`
|
|
@@ -247,7 +247,7 @@ var generateTypesFile = (extraction) => {
|
|
|
247
247
|
const entries = buildSchemaEntries(extraction);
|
|
248
248
|
if (entries.length === 0) {
|
|
249
249
|
return `${generateHeader()}
|
|
250
|
-
|
|
250
|
+
export type ServicePayloads = Record<never, never>;
|
|
251
251
|
`;
|
|
252
252
|
}
|
|
253
253
|
const schemaImports = entries.map((e) => e.exportName);
|
|
@@ -302,7 +302,7 @@ for (const service of services) {
|
|
|
302
302
|
|
|
303
303
|
for (const action of service.actions) {
|
|
304
304
|
if (!action.validation) {
|
|
305
|
-
|
|
305
|
+
serviceSchemas[action.name] = null;
|
|
306
306
|
continue;
|
|
307
307
|
}
|
|
308
308
|
|
|
@@ -419,15 +419,8 @@ var generateSchemaCommand = async (options) => {
|
|
|
419
419
|
error(err instanceof Error ? err.message : String(err));
|
|
420
420
|
process.exit(1);
|
|
421
421
|
}
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
spinner.stop("No action schemas found");
|
|
425
|
-
warn("None of the actions have validation schemas defined.");
|
|
426
|
-
hint("Add a Zod validation schema to your actions to generate types.");
|
|
427
|
-
outro();
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
spinner.stop(`Extracted ${schemaCount} action schema${schemaCount > 1 ? "s" : ""}`);
|
|
422
|
+
const actionCount = Object.values(extraction.schemas).reduce((sum, actions) => sum + Object.keys(actions).length, 0);
|
|
423
|
+
spinner.stop(`Read ${actionCount} action contract${actionCount === 1 ? "" : "s"}`);
|
|
431
424
|
const outputDir = resolve3(projectRoot, options.output ?? DEFAULT_OUTPUT_DIR);
|
|
432
425
|
await ensureDir(outputDir);
|
|
433
426
|
const schemasContent = generateSchemasFile(extraction);
|
|
@@ -440,7 +433,7 @@ var generateSchemaCommand = async (options) => {
|
|
|
440
433
|
success(`Generated ${typesPath.replace(projectRoot, "").replace(LEADING_SLASH2, "")}`);
|
|
441
434
|
if (extraction.skipped.length > 0) {
|
|
442
435
|
console.log("");
|
|
443
|
-
|
|
436
|
+
warn(`Could not convert validation schemas for ${extraction.skipped.length} action(s):`);
|
|
444
437
|
hint(extraction.skipped.join(", "));
|
|
445
438
|
}
|
|
446
439
|
outro();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nilejs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CLI for scaffolding and generating Nile backend projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^22.8.1",
|
|
20
|
-
"typescript": "^5"
|
|
20
|
+
"typescript": "^5",
|
|
21
|
+
"zod": "4.6.7"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
24
|
"build": "bun run scripts/build.ts",
|
|
24
25
|
"dev": "bun run src/index.ts",
|
|
25
26
|
"typecheck": "tsc --noEmit",
|
|
26
|
-
"export": "bun run typecheck && bun run build && node dist/index.js --version"
|
|
27
|
+
"export": "bun run typecheck && bun run build && node dist/index.js --version",
|
|
28
|
+
"test": "bun test scripts/schema-contracts.spec.ts"
|
|
27
29
|
}
|
|
28
30
|
}
|
package/template/README.md
CHANGED
|
@@ -127,7 +127,7 @@ Options:
|
|
|
127
127
|
| `-e, --entry <path>` | Path to services config (auto-detected by default) |
|
|
128
128
|
| `-o, --output <path>` | Output directory (default: `src/generated`) |
|
|
129
129
|
|
|
130
|
-
Actions without
|
|
130
|
+
Every registered action is included in `ServicePayloads`. Actions without validation accept an object payload (`Record<string, unknown>`); call `tasks.list` with `{}`. This fallback does not add server-side validation. Schemas that cannot be converted are reported separately.
|
|
131
131
|
|
|
132
132
|
## Database
|
|
133
133
|
|