sim 2.2.9-preview.214.1 → 2.2.9-preview.215.1

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,21 +1,69 @@
1
1
  import type { Command } from 'commander';
2
- import type { V2OperationName } from '../generated/v2-api';
2
+ import type { ResolvedProfile } from '../config/index';
3
+ import { type V2OperationName } from '../generated/v2-api';
4
+ import { type RequestAllPagesOptions, type RequestOptions, type SimClient, type WorkspaceOptions } from '../http/client';
3
5
  /**
4
- * Records the one v2 operation whose request and response a command presents as its
5
- * own: every generated command, and a hand-written one that prints a single call's result.
6
+ * The one operation whose request and response a command presents as its own, as its
7
+ * declaration named it: every generated command, and a hand-written one that prints a
8
+ * single call's result.
6
9
  *
7
- * The command inventory reads it here rather than mapping paths back to operations: a
8
- * derived path can equal another operation's (`undeployWorkflow` derives
9
- * `workflows deploy`), and a reverse lookup by path then describes the wrong one.
10
+ * The inventory reads it here rather than mapping paths back to operations: a derived
11
+ * path can equal another operation's (`undeployWorkflow` derives `workflows deploy`), and
12
+ * a reverse lookup by path then describes the wrong one.
10
13
  */
11
- export declare function runsOperation(command: Command, operation: V2OperationName): Command;
12
14
  export declare function operationOf(command: Command): V2OperationName | undefined;
15
+ /** The v2 operations a command declared it calls; absent when it calls none. */
16
+ export declare function calledOperations(command: Command): readonly V2OperationName[] | undefined;
17
+ /** Options for a call to a named operation; `params` fills its `[param]` path segments. */
18
+ type OperationOptions<Options extends RequestOptions> = Omit<Options, 'method'> & {
19
+ params?: Record<string, string>;
20
+ };
21
+ type ClientCalls = Pick<SimClient, 'request' | 'requestRaw' | 'requireWorkspace'>;
13
22
  /**
14
- * Records the v2 operations a hand-written command calls.
23
+ * How a command reaches the API: each call names its operation, and only the operations
24
+ * the command declared are accepted.
15
25
  *
16
- * A hand-written command is opaque until it says what it calls, and the inventory needs
17
- * that to describe it truthfully, such as whether every call is open to a Mothership
18
- * caller.
26
+ * Route and method come from the operation table, so no call can address an endpoint
27
+ * the declaration leaves out. That keeps the inventory's view of a command, and with it
28
+ * whether Mothership may run it, true without a list anyone has to keep in sync.
19
29
  */
20
- export declare function callsOperations(command: Command, operations: readonly V2OperationName[]): Command;
21
- export declare function calledOperations(command: Command): readonly V2OperationName[] | undefined;
30
+ export declare class OperationClient<Operation extends V2OperationName> {
31
+ private readonly client;
32
+ private readonly operations;
33
+ private readonly caller;
34
+ constructor(client: ClientCalls, operations: ReadonlySet<V2OperationName>, caller: string);
35
+ requireWorkspace(explicit?: string, options?: WorkspaceOptions): string;
36
+ request<T>(operation: Operation, { params, ...options }?: OperationOptions<RequestOptions>): Promise<T>;
37
+ requestRaw(operation: Operation, { params, ...options }?: OperationOptions<RequestOptions>): Promise<Response>;
38
+ requestAllPages<T>(operation: Operation, { params, ...options }: OperationOptions<RequestAllPagesOptions>): Promise<T[]>;
39
+ /**
40
+ * The same declared operations over another client. A request's own signal cannot
41
+ * stand in: the client also honours its profile's signal, which is what a cleanup
42
+ * after cancellation has to escape.
43
+ */
44
+ over(client: ClientCalls): OperationClient<Operation>;
45
+ private route;
46
+ }
47
+ export interface Connection<Operation extends V2OperationName> {
48
+ client: OperationClient<Operation>;
49
+ profile: ResolvedProfile;
50
+ }
51
+ /**
52
+ * Connects a command by its declaration, for code handed the command rather than the
53
+ * declaration: the generated handler, and the protocols layered onto a generated leaf.
54
+ * Naming the operations a caller relies on types the client to them and refuses a
55
+ * declaration that leaves one out.
56
+ */
57
+ export declare function connect<const Operation extends V2OperationName = V2OperationName>(command: Command, expects?: readonly Operation[]): Connection<Operation>;
58
+ interface Declaration<Operation extends V2OperationName> {
59
+ /** The one operation whose result the command prints as its own. */
60
+ runs?: NoInfer<Operation>;
61
+ }
62
+ /**
63
+ * Declares every v2 operation a command can call, and returns how it connects: a client
64
+ * typed to exactly these operations, so a call to any other does not compile.
65
+ */
66
+ export declare function callsOperations<const Operation extends V2OperationName>(command: Command, operations: readonly Operation[], { runs }?: Declaration<Operation>): () => Connection<Operation>;
67
+ /** Adds a subcommand that calls the API, declared before anything else is attached. */
68
+ export declare function apiCommand<const Operation extends V2OperationName>(parent: Command, name: string, operations: readonly Operation[], declaration?: Declaration<Operation>): [Command, () => Connection<Operation>];
69
+ export {};
@@ -1,3 +1,4 @@
1
+ import type { Command } from 'commander';
1
2
  import { type V2OperationName } from '../generated/v2-api';
2
3
  /**
3
4
  * Derives a command path from an operation's route.
@@ -18,3 +19,5 @@ export declare function kebab(value: string): string;
18
19
  * parsed flag has to go through this.
19
20
  */
20
21
  export declare function camel(flag: string): string;
22
+ /** The command's own name and its ancestors', root excluded, in typing order. */
23
+ export declare function commandPath(command: Command): string[];
@@ -103,7 +103,8 @@ export declare function encodeFolderPath(value: string): string;
103
103
  */
104
104
  export declare function coerce(raw: unknown, field: FieldSpec, flag: FlagSpec, flagName: string): Promise<unknown>;
105
105
  export interface BuiltRequest {
106
- path: string;
106
+ /** The values filling the operation's `[param]` path segments, encoded when routed. */
107
+ params: Record<string, string>;
107
108
  query: Record<string, QueryValue>;
108
109
  body: Record<string, unknown> | undefined;
109
110
  /** Contract-declared request headers, absent when the operation declares none. */