@rhythmjs/cli 0.0.2 → 0.0.4

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.
@@ -1,5 +1,5 @@
1
1
  import { t as RhythmPrompt } from "../prompt-DXqXd-xC.js";
2
- import { t as RhythmCliContext } from "../context-SCtZ6pOg.js";
2
+ import { t as RhythmCliContext } from "../context-DyXPT9sP.js";
3
3
  import { Rhythm } from "@rhythmjs/rhythm";
4
4
  //#region src/adapters/bun.d.ts
5
5
  export declare function toCliHandler<TContext extends RhythmCliContext, TProviders extends object = {}>(app: Rhythm<RhythmCliContext, TContext, TProviders>): (argv: string[]) => Promise<number>;
@@ -1,2 +1,2 @@
1
- import { n as RhythmCliResponse, t as RhythmCliContext } from "../context-SCtZ6pOg.js";
1
+ import { n as RhythmCliResponse, t as RhythmCliContext } from "../context-DyXPT9sP.js";
2
2
  export { RhythmCliContext, RhythmCliResponse };
@@ -1,7 +1,5 @@
1
- import { RhythmMutable } from "@rhythmjs/rhythm";
2
1
  //#region src/adapters/context.ts
3
2
  var RhythmCliResponse = class {
4
- [RhythmMutable] = true;
5
3
  exitCode = 0;
6
4
  stdout = [];
7
5
  stderr = [];
@@ -1,5 +1,5 @@
1
1
  import { t as RhythmPrompt } from "../prompt-DXqXd-xC.js";
2
- import { t as RhythmCliContext } from "../context-SCtZ6pOg.js";
2
+ import { t as RhythmCliContext } from "../context-DyXPT9sP.js";
3
3
  import { Rhythm } from "@rhythmjs/rhythm";
4
4
  //#region src/adapters/node.d.ts
5
5
  export declare function toCliHandler<TContext extends RhythmCliContext, TProviders extends object = {}>(app: Rhythm<RhythmCliContext, TContext, TProviders>): (argv: string[]) => Promise<number>;
@@ -0,0 +1,17 @@
1
+ //#region src/adapters/context.d.ts
2
+ declare class RhythmCliResponse {
3
+ exitCode: number;
4
+ stdout: string[];
5
+ stderr: string[];
6
+ print(line: string): this;
7
+ printError(line: string): this;
8
+ exit(code: number): this;
9
+ }
10
+ interface RhythmCliContext {
11
+ readonly argv: readonly string[];
12
+ readonly flags: Readonly<Record<string, string | boolean>>;
13
+ readonly stdin: ReadableStream<Uint8Array> | null;
14
+ readonly response: RhythmCliResponse;
15
+ }
16
+ //#endregion
17
+ export { RhythmCliResponse as n, RhythmCliContext as t };
@@ -1,8 +1,8 @@
1
- import { t as RhythmCliContext } from "./context-SCtZ6pOg.js";
2
- import { Middleware } from "@rhythmjs/rhythm";
1
+ import { t as RhythmCliContext } from "./context-DyXPT9sP.js";
2
+ import { DeriveMiddleware, Middleware } from "@rhythmjs/rhythm/types";
3
3
  //#region src/rhythm-cli.d.ts
4
4
  export interface RhythmCliCommandContext {
5
- args: Record<string, string>;
5
+ readonly args: Readonly<Record<string, string>>;
6
6
  }
7
7
  export interface RhythmCliOptions {
8
8
  prefix?: string;
@@ -10,9 +10,10 @@ export interface RhythmCliOptions {
10
10
  export declare class RhythmCli<TContext extends RhythmCliContext = RhythmCliContext> {
11
11
  #private;
12
12
  constructor(options?: RhythmCliOptions);
13
- use(child: RhythmCli<any>): this;
14
- use<TExtra extends object = {}>(fn: Middleware<TContext>): RhythmCli<TContext & TExtra>;
13
+ use<TExtra extends object>(fn: DeriveMiddleware<TContext, TExtra>): RhythmCli<TContext & TExtra>;
14
+ use(fn: Middleware<TContext>): this;
15
+ command<TExtra extends object>(path: string, middleware: DeriveMiddleware<TContext & RhythmCliCommandContext, TExtra>, ...handlers: Middleware<TContext & RhythmCliCommandContext & TExtra>[]): this;
15
16
  command(path: string, ...handlers: Middleware<TContext & RhythmCliCommandContext>[]): this;
16
- commands(): Middleware<TContext>;
17
+ middleware(): Middleware<TContext>;
17
18
  }
18
19
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { parseArgv } from "./argv.js";
2
- import { compose } from "@rhythmjs/rhythm";
2
+ import { compose } from "@rhythmjs/rhythm/compose";
3
3
  //#region src/rhythm-cli.ts
4
4
  function toSegments(command) {
5
5
  return command.trim().split(/\s+/).filter(Boolean);
@@ -15,29 +15,21 @@ function matchCommand(pattern, positionals) {
15
15
  }
16
16
  return params;
17
17
  }
18
- var RhythmCli = class RhythmCli {
18
+ var RhythmCli = class {
19
19
  #options;
20
20
  #entries = [];
21
- #composed = null;
22
21
  constructor(options = {}) {
23
22
  this.#options = options;
24
23
  }
25
24
  get #prefixSegments() {
26
25
  return this.#options.prefix ? toSegments(this.#options.prefix) : [];
27
26
  }
28
- use(arg) {
29
- if (arg instanceof RhythmCli) for (const entry of arg.#entries) this.#entries.push(entry.kind === "command" ? {
30
- ...entry,
31
- segments: [...this.#prefixSegments, ...entry.segments]
32
- } : entry);
33
- else {
34
- if (typeof arg !== "function") throw new TypeError("middleware must be a function!");
35
- this.#entries.push({
36
- kind: "middleware",
37
- fn: arg
38
- });
39
- }
40
- this.#composed = null;
27
+ use(fn) {
28
+ if (typeof fn !== "function") throw new TypeError("middleware must be a function!");
29
+ this.#entries.push({
30
+ kind: "middleware",
31
+ fn
32
+ });
41
33
  return this;
42
34
  }
43
35
  command(path, ...handlers) {
@@ -46,11 +38,9 @@ var RhythmCli = class RhythmCli {
46
38
  segments: [...this.#prefixSegments, ...toSegments(path)],
47
39
  handlers
48
40
  });
49
- this.#composed = null;
50
41
  return this;
51
42
  }
52
43
  #compile() {
53
- if (this.#composed) return this.#composed;
54
44
  const dispatchFor = (compiled) => {
55
45
  return async (ctx, next) => {
56
46
  const { positionals } = parseArgv(ctx.argv);
@@ -87,12 +77,12 @@ var RhythmCli = class RhythmCli {
87
77
  }
88
78
  stack.push(dispatchFor(compiled));
89
79
  }
90
- this.#composed = compose(stack);
91
- return this.#composed;
80
+ return compose(stack);
92
81
  }
93
- commands() {
82
+ middleware() {
83
+ const fn = this.#compile();
94
84
  return async (ctx, next) => {
95
- await this.#compile()(ctx, next);
85
+ await fn(ctx, next);
96
86
  };
97
87
  }
98
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhythmjs/cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Command-line argument parsing, prompts, and command routing for the Rhythm middleware kernel.",
5
5
  "homepage": "https://rhythm.js.org/cli",
6
6
  "license": "ISC",
@@ -49,7 +49,7 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@rhythmjs/rhythm": "0.0.2"
52
+ "@rhythmjs/rhythm": "0.0.4"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/bun": "^1.4.2",
@@ -1,19 +0,0 @@
1
- import { RhythmMutable } from "@rhythmjs/rhythm";
2
- //#region src/adapters/context.d.ts
3
- declare class RhythmCliResponse {
4
- readonly [RhythmMutable] = true;
5
- exitCode: number;
6
- stdout: string[];
7
- stderr: string[];
8
- print(line: string): this;
9
- printError(line: string): this;
10
- exit(code: number): this;
11
- }
12
- interface RhythmCliContext {
13
- argv: string[];
14
- flags: Record<string, string | boolean>;
15
- stdin: ReadableStream<Uint8Array> | null;
16
- response: RhythmCliResponse;
17
- }
18
- //#endregion
19
- export { RhythmCliResponse as n, RhythmCliContext as t };