@zero-server/cli 0.9.7 → 0.9.9
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/lib/cli.js +26 -26
- package/package.json +5 -4
- package/types/body.d.ts +82 -14
- package/types/cli.d.ts +40 -2
- package/types/index.d.ts +3 -2
- package/types/middleware.d.ts +17 -71
- package/types/orm.d.ts +1 -10
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @zero-server/cli
|
|
2
2
|
|
|
3
|
-
> Programmatic access to the `
|
|
3
|
+
> Programmatic access to the `zs` CLI.
|
|
4
4
|
|
|
5
|
-
Programmatic entry points for the bundled CLI (`
|
|
5
|
+
Programmatic entry points for the bundled CLI (`zs`): scaffolding, migrations, seeding, rollback, status. Useful when embedding the CLI inside your own tooling.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
package/lib/cli.js
CHANGED
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
* };
|
|
19
19
|
*
|
|
20
20
|
* // Run via npx (no global install needed):
|
|
21
|
-
* // npx
|
|
22
|
-
* // npx
|
|
23
|
-
* // npx
|
|
24
|
-
* // npx
|
|
25
|
-
* // npx
|
|
26
|
-
* // npx
|
|
27
|
-
* // npx
|
|
21
|
+
* // npx zs migrate
|
|
22
|
+
* // npx zs migrate:rollback
|
|
23
|
+
* // npx zs migrate:status
|
|
24
|
+
* // npx zs seed
|
|
25
|
+
* // npx zs make:model User
|
|
26
|
+
* // npx zs make:migration create_posts
|
|
27
|
+
* // npx zs make:seeder Users
|
|
28
28
|
*
|
|
29
29
|
* // Or programmatically:
|
|
30
30
|
* const { runCLI } = require('@zero-server/sdk');
|
|
@@ -154,7 +154,7 @@ class CLI
|
|
|
154
154
|
// webrtc CLI module so the top-level dispatcher stays small.
|
|
155
155
|
if (typeof this.command === 'string' && this.command.startsWith('webrtc:'))
|
|
156
156
|
{
|
|
157
|
-
const { runWebRTCCommand } = require('
|
|
157
|
+
const { runWebRTCCommand } = require('@zero-server/webrtc');
|
|
158
158
|
await runWebRTCCommand(this.command.slice('webrtc:'.length), this.flags);
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
@@ -215,7 +215,7 @@ class CLI
|
|
|
215
215
|
throw new Error(
|
|
216
216
|
'No configuration file found.\n' +
|
|
217
217
|
'Create a zero.config.js with database and migration settings.\n' +
|
|
218
|
-
'See "
|
|
218
|
+
'See "zs help" for examples.'
|
|
219
219
|
);
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -431,7 +431,7 @@ class CLI
|
|
|
431
431
|
if (status.executed.includes(lastMigration.name))
|
|
432
432
|
{
|
|
433
433
|
console.error(red(`Cannot remove "${lastMigration.name}" - it has already been applied.`));
|
|
434
|
-
console.error(dim('Run "
|
|
434
|
+
console.error(dim('Run "zs migrate:rollback" first, then try again.'));
|
|
435
435
|
process.exitCode = 1;
|
|
436
436
|
await db.close();
|
|
437
437
|
return;
|
|
@@ -519,7 +519,7 @@ class CLI
|
|
|
519
519
|
const name = this.args.find(a => !a.startsWith('-'));
|
|
520
520
|
if (!name)
|
|
521
521
|
{
|
|
522
|
-
console.error(red('Usage:
|
|
522
|
+
console.error(red('Usage: zs make:model <Name>'));
|
|
523
523
|
process.exitCode = 1;
|
|
524
524
|
return;
|
|
525
525
|
}
|
|
@@ -575,7 +575,7 @@ module.exports = ${className};
|
|
|
575
575
|
const name = this.args.find(a => !a.startsWith('-'));
|
|
576
576
|
if (!name)
|
|
577
577
|
{
|
|
578
|
-
console.error(red('Usage:
|
|
578
|
+
console.error(red('Usage: zs make:migration <name>'));
|
|
579
579
|
process.exitCode = 1;
|
|
580
580
|
return;
|
|
581
581
|
}
|
|
@@ -701,7 +701,7 @@ module.exports = {
|
|
|
701
701
|
const name = this.args.find(a => !a.startsWith('-'));
|
|
702
702
|
if (!name)
|
|
703
703
|
{
|
|
704
|
-
console.error(red('Usage:
|
|
704
|
+
console.error(red('Usage: zs make:seeder <name>'));
|
|
705
705
|
process.exitCode = 1;
|
|
706
706
|
return;
|
|
707
707
|
}
|
|
@@ -751,9 +751,9 @@ module.exports = ${className};
|
|
|
751
751
|
_help()
|
|
752
752
|
{
|
|
753
753
|
console.log(`
|
|
754
|
-
${bold('
|
|
754
|
+
${bold('zs CLI')} - zero-server ORM tooling
|
|
755
755
|
|
|
756
|
-
${bold('Usage:')} npx
|
|
756
|
+
${bold('Usage:')} npx zs <command> [options]
|
|
757
757
|
|
|
758
758
|
${bold('Commands:')}
|
|
759
759
|
|
|
@@ -803,19 +803,19 @@ ${bold('Config file:')} ${dim('zero.config.js (or .zero-server.js / legacy .zero
|
|
|
803
803
|
|
|
804
804
|
${bold('Auto-generated migrations:')}
|
|
805
805
|
|
|
806
|
-
${dim('$')} npx
|
|
807
|
-
${dim('$')} npx
|
|
808
|
-
${dim('$')} npx
|
|
809
|
-
${dim('$')} npx
|
|
810
|
-
${dim('$')} npx
|
|
806
|
+
${dim('$')} npx zs make:migration create_users ${dim('# detects new User model → generates CREATE TABLE')}
|
|
807
|
+
${dim('$')} npx zs make:migration add_email ${dim('# detects new email column → generates ADD COLUMN')}
|
|
808
|
+
${dim('$')} npx zs make:migration --empty init ${dim('# blank migration (manual mode)')}
|
|
809
|
+
${dim('$')} npx zs migrate ${dim('# apply pending migrations')}
|
|
810
|
+
${dim('$')} npx zs migrate:remove ${dim('# undo last make:migration')}
|
|
811
811
|
|
|
812
812
|
${bold('Examples:')}
|
|
813
813
|
|
|
814
|
-
${dim('$')} npx
|
|
815
|
-
${dim('$')} npx
|
|
816
|
-
${dim('$')} npx
|
|
817
|
-
${dim('$')} npx
|
|
818
|
-
${dim('$')} npx
|
|
814
|
+
${dim('$')} npx zs make:model User ${dim('# creates models/User.js')}
|
|
815
|
+
${dim('$')} npx zs make:migration create_users ${dim('# auto-generates from models')}
|
|
816
|
+
${dim('$')} npx zs migrate ${dim('# runs all pending migrations')}
|
|
817
|
+
${dim('$')} npx zs migrate --config=db.config.js
|
|
818
|
+
${dim('$')} npx zs seed ${dim('# runs all seeders')}
|
|
819
819
|
`);
|
|
820
820
|
}
|
|
821
821
|
|
|
@@ -825,7 +825,7 @@ ${bold('Examples:')}
|
|
|
825
825
|
_version()
|
|
826
826
|
{
|
|
827
827
|
const pkg = require('../package.json');
|
|
828
|
-
console.log(`
|
|
828
|
+
console.log(`zs v${pkg.version} (zero-server)`);
|
|
829
829
|
}
|
|
830
830
|
}
|
|
831
831
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zero-server/cli",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "Programmatic access to the `
|
|
3
|
+
"version": "0.9.9",
|
|
4
|
+
"description": "Programmatic access to the `zs` CLI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zero-server",
|
|
7
7
|
"zero-server",
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
},
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@zero-server/orm": "0.9.
|
|
48
|
+
"@zero-server/orm": "0.9.9",
|
|
49
|
+
"@zero-server/webrtc": "0.9.9"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
51
|
-
"@zero-server/sdk": ">=0.9.
|
|
52
|
+
"@zero-server/sdk": ">=0.9.9"
|
|
52
53
|
},
|
|
53
54
|
"peerDependenciesMeta": {
|
|
54
55
|
"@zero-server/sdk": {
|
package/types/body.d.ts
CHANGED
|
@@ -1,14 +1,82 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
// TypeScript declarations for the bundled body parsers
|
|
2
|
+
// (`json`, `urlencoded`, `text`, `raw`, `multipart`).
|
|
3
|
+
//
|
|
4
|
+
// These live in `lib/body/*` at runtime and are surfaced both via the
|
|
5
|
+
// top-level SDK and the standalone `@zero-server/body` scope. They are
|
|
6
|
+
// declared here (not in `./middleware`) so the body-parser package has
|
|
7
|
+
// a self-contained declaration file.
|
|
8
|
+
|
|
9
|
+
import { MiddlewareFunction } from './middleware';
|
|
10
|
+
import { Request } from './request';
|
|
11
|
+
import { Response } from './response';
|
|
12
|
+
|
|
13
|
+
export interface BodyParserOptions {
|
|
14
|
+
/** Max body size (e.g. '10kb', '1mb'). Default: '1mb'. */
|
|
15
|
+
limit?: string | number;
|
|
16
|
+
/** Content-Type(s) to match. Accepts a string, an array of strings, or a predicate function. */
|
|
17
|
+
type?: string | string[] | ((ct: string) => boolean);
|
|
18
|
+
/** Reject non-HTTPS requests with 403. */
|
|
19
|
+
requireSecure?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Verification callback invoked with the raw buffer before parsing.
|
|
22
|
+
* Throw an error to reject the request with 403.
|
|
23
|
+
* Useful for webhook signature verification (e.g. Stripe, GitHub).
|
|
24
|
+
*/
|
|
25
|
+
verify?: (req: Request, res: Response, buf: Buffer, encoding: string) => void;
|
|
26
|
+
/** Decompress gzip/deflate/br request bodies. Default: true. When false, compressed bodies return 415. */
|
|
27
|
+
inflate?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface JsonParserOptions extends BodyParserOptions {
|
|
31
|
+
/** JSON.parse reviver function. */
|
|
32
|
+
reviver?: (key: string, value: any) => any;
|
|
33
|
+
/** Reject non-object/array roots. Default: true. */
|
|
34
|
+
strict?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface UrlencodedParserOptions extends BodyParserOptions {
|
|
38
|
+
/** Enable nested bracket parsing. Default: false. */
|
|
39
|
+
extended?: boolean;
|
|
40
|
+
/** Max number of parameters. Default: 1000. Prevents parameter flooding DoS. */
|
|
41
|
+
parameterLimit?: number;
|
|
42
|
+
/** Max nesting depth for bracket syntax. Default: 32. Prevents deep-nesting DoS. */
|
|
43
|
+
depth?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TextParserOptions extends BodyParserOptions {
|
|
47
|
+
/** Fallback character encoding when Content-Type has no charset. Default: 'utf8'. */
|
|
48
|
+
encoding?: BufferEncoding;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MultipartOptions {
|
|
52
|
+
/** Upload directory (default: OS temp). */
|
|
53
|
+
dir?: string;
|
|
54
|
+
/** Maximum size per file in bytes. */
|
|
55
|
+
maxFileSize?: number;
|
|
56
|
+
/** Reject non-HTTPS requests with 403. */
|
|
57
|
+
requireSecure?: boolean;
|
|
58
|
+
/** Maximum number of non-file fields. Default: 1000. */
|
|
59
|
+
maxFields?: number;
|
|
60
|
+
/** Maximum number of uploaded files. Default: 10. */
|
|
61
|
+
maxFiles?: number;
|
|
62
|
+
/** Maximum size of a single field value in bytes. Default: 1 MB. */
|
|
63
|
+
maxFieldSize?: number;
|
|
64
|
+
/** Whitelist of allowed MIME types for uploaded files (e.g. ['image/png', 'image/jpeg']). */
|
|
65
|
+
allowedMimeTypes?: string[];
|
|
66
|
+
/** Maximum combined size of all uploaded files in bytes. */
|
|
67
|
+
maxTotalSize?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface MultipartFile {
|
|
71
|
+
originalFilename: string;
|
|
72
|
+
storedName: string;
|
|
73
|
+
path: string;
|
|
74
|
+
contentType: string;
|
|
75
|
+
size: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function json(options?: JsonParserOptions): MiddlewareFunction;
|
|
79
|
+
export function urlencoded(options?: UrlencodedParserOptions): MiddlewareFunction;
|
|
80
|
+
export function text(options?: TextParserOptions): MiddlewareFunction;
|
|
81
|
+
export function raw(options?: BodyParserOptions): MiddlewareFunction;
|
|
82
|
+
export function multipart(options?: MultipartOptions): MiddlewareFunction;
|
package/types/cli.d.ts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
1
|
+
// TypeScript declarations for the bundled CLI runner (`zs` / `zh`).
|
|
2
|
+
//
|
|
3
|
+
// The CLI lives in `lib/cli.js` and is published both as the `zs` /
|
|
4
|
+
// `zh` bin scripts and as a programmatic API on the SDK. It dispatches
|
|
5
|
+
// ORM subcommands (`migrate`, `seed`, `make:*`) to `@zero-server/orm`
|
|
6
|
+
// and `webrtc:*` subcommands to `@zero-server/webrtc`, but the runner
|
|
7
|
+
// itself is scope-neutral - hence its own declaration file.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CLI runner for the bundled `zs` command.
|
|
11
|
+
*
|
|
12
|
+
* Parses `process.argv`-style input, resolves a config file
|
|
13
|
+
* (`zero.config.js` / `.zero-server.js` / `.zero-http.js`), and
|
|
14
|
+
* dispatches to the matching subcommand handler.
|
|
15
|
+
*/
|
|
16
|
+
export class CLI {
|
|
17
|
+
constructor(argv?: string[]);
|
|
18
|
+
|
|
19
|
+
/** The first positional argument (subcommand name). Defaults to `"help"`. */
|
|
20
|
+
readonly command: string;
|
|
21
|
+
|
|
22
|
+
/** Remaining positional arguments after the subcommand. */
|
|
23
|
+
readonly args: string[];
|
|
24
|
+
|
|
25
|
+
/** Parsed `--flag=value` and `-f value` pairs. */
|
|
26
|
+
readonly flags: Map<string, string>;
|
|
27
|
+
|
|
28
|
+
/** Execute the parsed command. Sets `process.exitCode` on failure. */
|
|
29
|
+
run(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One-shot helper: `new CLI(argv).run()`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const { runCLI } = require('@zero-server/sdk');
|
|
37
|
+
* await runCLI(['migrate']);
|
|
38
|
+
* await runCLI(['make:model', 'User', '--dir=src/models']);
|
|
39
|
+
*/
|
|
40
|
+
export function runCLI(argv?: string[]): Promise<void>;
|
package/types/index.d.ts
CHANGED
|
@@ -97,8 +97,8 @@ export {
|
|
|
97
97
|
StoredProcedure, StoredProcedureOptions, ProcedureParam,
|
|
98
98
|
StoredFunction, StoredFunctionOptions,
|
|
99
99
|
TriggerManager, TriggerDefinition,
|
|
100
|
-
CLI, runCLI,
|
|
101
100
|
} from './orm';
|
|
101
|
+
export { CLI, runCLI } from './cli';
|
|
102
102
|
// Re-export validate from orm as schemaValidate to avoid collision with middleware validate
|
|
103
103
|
export { validate as schemaValidate } from './orm';
|
|
104
104
|
export {
|
|
@@ -161,7 +161,8 @@ import { Database, Model, Query } from './orm';
|
|
|
161
161
|
import { TYPES, validateFKAction, validateCheck } from './orm';
|
|
162
162
|
import { Migrator, QueryCache, Seeder, SeederRunner, Factory, Fake, defineMigration } from './orm';
|
|
163
163
|
import { QueryProfiler, ReplicaManager } from './orm';
|
|
164
|
-
import { TenantManager, AuditLog, PluginManager, StoredProcedure, StoredFunction, TriggerManager
|
|
164
|
+
import { TenantManager, AuditLog, PluginManager, StoredProcedure, StoredFunction, TriggerManager } from './orm';
|
|
165
|
+
import { CLI, runCLI } from './cli';
|
|
165
166
|
import { LifecycleManager, LIFECYCLE_STATE } from './lifecycle';
|
|
166
167
|
import { ClusterManager, cluster as clusterize } from './cluster';
|
|
167
168
|
import {
|
package/types/middleware.d.ts
CHANGED
|
@@ -21,77 +21,23 @@ export interface CorsOptions {
|
|
|
21
21
|
export function cors(options?: CorsOptions): MiddlewareFunction;
|
|
22
22
|
|
|
23
23
|
// --- Body Parsers ------------------------------------------------
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface JsonParserOptions extends BodyParserOptions {
|
|
43
|
-
/** JSON.parse reviver function. */
|
|
44
|
-
reviver?: (key: string, value: any) => any;
|
|
45
|
-
/** Reject non-object/array roots. Default: true. */
|
|
46
|
-
strict?: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface UrlencodedParserOptions extends BodyParserOptions {
|
|
50
|
-
/** Enable nested bracket parsing. Default: false. */
|
|
51
|
-
extended?: boolean;
|
|
52
|
-
/** Max number of parameters. Default: 1000. Prevents parameter flooding DoS. */
|
|
53
|
-
parameterLimit?: number;
|
|
54
|
-
/** Max nesting depth for bracket syntax. Default: 32. Prevents deep-nesting DoS. */
|
|
55
|
-
depth?: number;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface TextParserOptions extends BodyParserOptions {
|
|
59
|
-
/** Fallback character encoding when Content-Type has no charset. Default: 'utf8'. */
|
|
60
|
-
encoding?: BufferEncoding;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface MultipartOptions {
|
|
64
|
-
/** Upload directory (default: OS temp). */
|
|
65
|
-
dir?: string;
|
|
66
|
-
/** Maximum size per file in bytes. */
|
|
67
|
-
maxFileSize?: number;
|
|
68
|
-
/** Reject non-HTTPS requests with 403. */
|
|
69
|
-
requireSecure?: boolean;
|
|
70
|
-
/** Maximum number of non-file fields. Default: 1000. */
|
|
71
|
-
maxFields?: number;
|
|
72
|
-
/** Maximum number of uploaded files. Default: 10. */
|
|
73
|
-
maxFiles?: number;
|
|
74
|
-
/** Maximum size of a single field value in bytes. Default: 1 MB. */
|
|
75
|
-
maxFieldSize?: number;
|
|
76
|
-
/** Whitelist of allowed MIME types for uploaded files (e.g. ['image/png', 'image/jpeg']). */
|
|
77
|
-
allowedMimeTypes?: string[];
|
|
78
|
-
/** Maximum combined size of all uploaded files in bytes. */
|
|
79
|
-
maxTotalSize?: number;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface MultipartFile {
|
|
83
|
-
originalFilename: string;
|
|
84
|
-
storedName: string;
|
|
85
|
-
path: string;
|
|
86
|
-
contentType: string;
|
|
87
|
-
size: number;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function json(options?: JsonParserOptions): MiddlewareFunction;
|
|
91
|
-
export function urlencoded(options?: UrlencodedParserOptions): MiddlewareFunction;
|
|
92
|
-
export function text(options?: TextParserOptions): MiddlewareFunction;
|
|
93
|
-
export function raw(options?: BodyParserOptions): MiddlewareFunction;
|
|
94
|
-
export function multipart(options?: MultipartOptions): MiddlewareFunction;
|
|
24
|
+
// Declarations live in `./body` so the standalone `@zero-server/body`
|
|
25
|
+
// package has its own self-contained type file. Re-exported here so
|
|
26
|
+
// callers using the aggregate middleware surface continue to work.
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
BodyParserOptions,
|
|
30
|
+
JsonParserOptions,
|
|
31
|
+
UrlencodedParserOptions,
|
|
32
|
+
TextParserOptions,
|
|
33
|
+
MultipartOptions,
|
|
34
|
+
MultipartFile,
|
|
35
|
+
json,
|
|
36
|
+
urlencoded,
|
|
37
|
+
text,
|
|
38
|
+
raw,
|
|
39
|
+
multipart,
|
|
40
|
+
} from './body';
|
|
95
41
|
|
|
96
42
|
// --- Rate Limiting -----------------------------------------------
|
|
97
43
|
|
package/types/orm.d.ts
CHANGED
|
@@ -1875,13 +1875,4 @@ export class TriggerManager {
|
|
|
1875
1875
|
get(name: string): TriggerDefinition | undefined;
|
|
1876
1876
|
}
|
|
1877
1877
|
|
|
1878
|
-
//
|
|
1879
|
-
|
|
1880
|
-
export class CLI {
|
|
1881
|
-
constructor(argv?: string[]);
|
|
1882
|
-
/** Run the CLI command. */
|
|
1883
|
-
run(): Promise<void>;
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
/** Create and run the CLI. */
|
|
1887
|
-
export function runCLI(argv?: string[]): Promise<void>;
|
|
1878
|
+
// CLI declarations live in `./cli` (re-exported from `./index`).
|