@camunda8/cli 2.6.1 → 2.7.0-alpha.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.
Files changed (135) hide show
  1. package/dist/command-dispatch.d.ts +16 -0
  2. package/dist/command-dispatch.d.ts.map +1 -0
  3. package/dist/command-dispatch.js +129 -0
  4. package/dist/command-dispatch.js.map +1 -0
  5. package/dist/command-framework.d.ts +248 -0
  6. package/dist/command-framework.d.ts.map +1 -0
  7. package/dist/command-framework.js +229 -0
  8. package/dist/command-framework.js.map +1 -0
  9. package/dist/command-registry.d.ts +2081 -0
  10. package/dist/command-registry.d.ts.map +1 -0
  11. package/dist/command-registry.js +1460 -0
  12. package/dist/command-registry.js.map +1 -0
  13. package/dist/command-validation.d.ts +30 -4
  14. package/dist/command-validation.d.ts.map +1 -1
  15. package/dist/command-validation.js +90 -4
  16. package/dist/command-validation.js.map +1 -1
  17. package/dist/commands/completion.d.ts +1 -1
  18. package/dist/commands/completion.d.ts.map +1 -1
  19. package/dist/commands/completion.js +331 -1221
  20. package/dist/commands/completion.js.map +1 -1
  21. package/dist/commands/deployments.d.ts +2 -0
  22. package/dist/commands/deployments.d.ts.map +1 -1
  23. package/dist/commands/deployments.js +13 -2
  24. package/dist/commands/deployments.js.map +1 -1
  25. package/dist/commands/forms.d.ts +2 -20
  26. package/dist/commands/forms.d.ts.map +1 -1
  27. package/dist/commands/forms.js +76 -79
  28. package/dist/commands/forms.js.map +1 -1
  29. package/dist/commands/help.d.ts +3 -87
  30. package/dist/commands/help.d.ts.map +1 -1
  31. package/dist/commands/help.js +565 -1939
  32. package/dist/commands/help.js.map +1 -1
  33. package/dist/commands/identity-authorizations.d.ts +5 -24
  34. package/dist/commands/identity-authorizations.d.ts.map +1 -1
  35. package/dist/commands/identity-authorizations.js +113 -137
  36. package/dist/commands/identity-authorizations.js.map +1 -1
  37. package/dist/commands/identity-groups.d.ts +5 -26
  38. package/dist/commands/identity-groups.d.ts.map +1 -1
  39. package/dist/commands/identity-groups.js +91 -124
  40. package/dist/commands/identity-groups.js.map +1 -1
  41. package/dist/commands/identity-mapping-rules.d.ts +5 -30
  42. package/dist/commands/identity-mapping-rules.d.ts.map +1 -1
  43. package/dist/commands/identity-mapping-rules.js +106 -136
  44. package/dist/commands/identity-mapping-rules.js.map +1 -1
  45. package/dist/commands/identity-roles.d.ts +5 -26
  46. package/dist/commands/identity-roles.d.ts.map +1 -1
  47. package/dist/commands/identity-roles.js +91 -124
  48. package/dist/commands/identity-roles.js.map +1 -1
  49. package/dist/commands/identity-tenants.d.ts +5 -26
  50. package/dist/commands/identity-tenants.d.ts.map +1 -1
  51. package/dist/commands/identity-tenants.js +92 -126
  52. package/dist/commands/identity-tenants.js.map +1 -1
  53. package/dist/commands/identity-users.d.ts +5 -29
  54. package/dist/commands/identity-users.d.ts.map +1 -1
  55. package/dist/commands/identity-users.js +95 -129
  56. package/dist/commands/identity-users.js.map +1 -1
  57. package/dist/commands/identity.d.ts +6 -6
  58. package/dist/commands/identity.d.ts.map +1 -1
  59. package/dist/commands/identity.js +6 -7
  60. package/dist/commands/identity.js.map +1 -1
  61. package/dist/commands/incidents.d.ts +3 -16
  62. package/dist/commands/incidents.d.ts.map +1 -1
  63. package/dist/commands/incidents.js +71 -98
  64. package/dist/commands/incidents.js.map +1 -1
  65. package/dist/commands/jobs.d.ts +4 -26
  66. package/dist/commands/jobs.d.ts.map +1 -1
  67. package/dist/commands/jobs.js +143 -159
  68. package/dist/commands/jobs.js.map +1 -1
  69. package/dist/commands/mcp-proxy.d.ts +1 -0
  70. package/dist/commands/mcp-proxy.d.ts.map +1 -1
  71. package/dist/commands/mcp-proxy.js +10 -2
  72. package/dist/commands/mcp-proxy.js.map +1 -1
  73. package/dist/commands/messages.d.ts +2 -12
  74. package/dist/commands/messages.d.ts.map +1 -1
  75. package/dist/commands/messages.js +87 -81
  76. package/dist/commands/messages.js.map +1 -1
  77. package/dist/commands/open.d.ts +4 -0
  78. package/dist/commands/open.d.ts.map +1 -1
  79. package/dist/commands/open.js +18 -0
  80. package/dist/commands/open.js.map +1 -1
  81. package/dist/commands/plugins.d.ts +7 -9
  82. package/dist/commands/plugins.d.ts.map +1 -1
  83. package/dist/commands/plugins.js +32 -25
  84. package/dist/commands/plugins.js.map +1 -1
  85. package/dist/commands/process-definitions.d.ts +2 -14
  86. package/dist/commands/process-definitions.d.ts.map +1 -1
  87. package/dist/commands/process-definitions.js +57 -80
  88. package/dist/commands/process-definitions.js.map +1 -1
  89. package/dist/commands/process-instances.d.ts +8 -37
  90. package/dist/commands/process-instances.d.ts.map +1 -1
  91. package/dist/commands/process-instances.js +242 -193
  92. package/dist/commands/process-instances.js.map +1 -1
  93. package/dist/commands/profiles.d.ts +4 -0
  94. package/dist/commands/profiles.d.ts.map +1 -1
  95. package/dist/commands/profiles.js +29 -0
  96. package/dist/commands/profiles.js.map +1 -1
  97. package/dist/commands/run.d.ts +2 -0
  98. package/dist/commands/run.d.ts.map +1 -1
  99. package/dist/commands/run.js +10 -0
  100. package/dist/commands/run.js.map +1 -1
  101. package/dist/commands/search.d.ts +7 -100
  102. package/dist/commands/search.d.ts.map +1 -1
  103. package/dist/commands/search.js +530 -694
  104. package/dist/commands/search.js.map +1 -1
  105. package/dist/commands/session.d.ts +3 -0
  106. package/dist/commands/session.d.ts.map +1 -1
  107. package/dist/commands/session.js +30 -0
  108. package/dist/commands/session.js.map +1 -1
  109. package/dist/commands/topology.d.ts +1 -3
  110. package/dist/commands/topology.d.ts.map +1 -1
  111. package/dist/commands/topology.js +11 -18
  112. package/dist/commands/topology.js.map +1 -1
  113. package/dist/commands/user-tasks.d.ts +2 -16
  114. package/dist/commands/user-tasks.d.ts.map +1 -1
  115. package/dist/commands/user-tasks.js +73 -101
  116. package/dist/commands/user-tasks.js.map +1 -1
  117. package/dist/commands/watch.d.ts +1 -0
  118. package/dist/commands/watch.d.ts.map +1 -1
  119. package/dist/commands/watch.js +15 -0
  120. package/dist/commands/watch.js.map +1 -1
  121. package/dist/default-plugins/cluster/c8ctl-plugin.js +11 -0
  122. package/dist/index.d.ts +0 -4
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +77 -1020
  125. package/dist/index.js.map +1 -1
  126. package/dist/logger.d.ts +5 -0
  127. package/dist/logger.d.ts.map +1 -1
  128. package/dist/logger.js +7 -1
  129. package/dist/logger.js.map +1 -1
  130. package/dist/plugin-loader.d.ts +5 -0
  131. package/dist/plugin-loader.d.ts.map +1 -1
  132. package/dist/plugin-loader.js +1 -0
  133. package/dist/plugin-loader.js.map +1 -1
  134. package/package.json +1 -1
  135. /package/dist/templates/{tsconfig.json → tsconfig.json.template} +0 -0
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Registry-driven command dispatch map.
3
+ *
4
+ * Maps "verb:resource" keys to command handlers. For resourceless verbs
5
+ * (deploy, run, watch, etc.), the key is "verb:".
6
+ *
7
+ * This replaces the ~1800-line if/else dispatch chain that previously
8
+ * lived in index.ts.
9
+ */
10
+ import type { AnyCommandHandler } from "./command-framework.ts";
11
+ /**
12
+ * Dispatch map keyed by "verb:resource".
13
+ * For resourceless verbs the key is "verb:" (empty resource).
14
+ */
15
+ export declare const COMMAND_DISPATCH: ReadonlyMap<string, AnyCommandHandler>;
16
+ //# sourceMappingURL=command-dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-dispatch.d.ts","sourceRoot":"","sources":["../src/command-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAmGhE;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAiHlE,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Registry-driven command dispatch map.
3
+ *
4
+ * Maps "verb:resource" keys to command handlers. For resourceless verbs
5
+ * (deploy, run, watch, etc.), the key is "verb:".
6
+ *
7
+ * This replaces the ~1800-line if/else dispatch chain that previously
8
+ * lived in index.ts.
9
+ */
10
+ import { deployCommand } from "./commands/deployments.js";
11
+ import { getFormCommand } from "./commands/forms.js";
12
+ import { createIdentityAuthorizationCommand, createIdentityGroupCommand, createIdentityMappingRuleCommand, createIdentityRoleCommand, createIdentityTenantCommand, createIdentityUserCommand, deleteIdentityAuthorizationCommand, deleteIdentityGroupCommand, deleteIdentityMappingRuleCommand, deleteIdentityRoleCommand, deleteIdentityTenantCommand, deleteIdentityUserCommand, getIdentityAuthorizationCommand, getIdentityGroupCommand, getIdentityMappingRuleCommand, getIdentityRoleCommand, getIdentityTenantCommand, getIdentityUserCommand, listAuthorizationsCommand, listGroupsCommand, listMappingRulesCommand, listRolesCommand, listTenantsCommand, listUsersCommand, searchIdentityAuthorizationsCommand, searchIdentityGroupsCommand, searchIdentityMappingRulesCommand, searchIdentityRolesCommand, searchIdentityTenantsCommand, searchIdentityUsersCommand, } from "./commands/identity.js";
13
+ import { getIncidentCommand, listIncidentsCommand, resolveIncidentCommand, } from "./commands/incidents.js";
14
+ import { activateJobsCommand, completeJobCommand, failJobCommand, listJobsCommand, } from "./commands/jobs.js";
15
+ import { mcpProxyCommand } from "./commands/mcp-proxy.js";
16
+ import { correlateMessageCommand, publishMessageCommand, } from "./commands/messages.js";
17
+ import { feedbackCommand, openAppCommand } from "./commands/open.js";
18
+ import { downgradePluginCommand, initPluginCommand, listPluginsCommand, loadPluginCommand, syncPluginsCommand, unloadPluginCommand, upgradePluginCommand, } from "./commands/plugins.js";
19
+ import { getProcessDefinitionCommand, listProcessDefinitionsCommand, } from "./commands/process-definitions.js";
20
+ import { awaitProcessInstanceCommand, cancelProcessInstanceCommand, createProcessInstanceCommand, getProcessInstanceCommand, listProcessInstancesCommand, } from "./commands/process-instances.js";
21
+ import { addProfileCommand, listProfileCommand, removeProfileCommand, whichProfileCommand, } from "./commands/profiles.js";
22
+ import { runCommand } from "./commands/run.js";
23
+ import { searchIncidentsCommand, searchJobsCommand, searchProcessDefinitionsCommand, searchProcessInstancesCommand, searchUserTasksCommand, searchVariablesCommand, } from "./commands/search.js";
24
+ import { outputCommand, useProfileCommand, useTenantCommand, } from "./commands/session.js";
25
+ import { getTopologyCommand } from "./commands/topology.js";
26
+ import { completeUserTaskCommand, listUserTasksCommand, } from "./commands/user-tasks.js";
27
+ import { watchCommand } from "./commands/watch.js";
28
+ /**
29
+ * Dispatch map keyed by "verb:resource".
30
+ * For resourceless verbs the key is "verb:" (empty resource).
31
+ */
32
+ export const COMMAND_DISPATCH = new Map([
33
+ // ── Session / profile ──────────────────────────────────────────────
34
+ ["use:profile", useProfileCommand],
35
+ ["use:tenant", useTenantCommand],
36
+ ["output:", outputCommand],
37
+ ["list:profile", listProfileCommand],
38
+ ["add:profile", addProfileCommand],
39
+ ["remove:profile", removeProfileCommand],
40
+ ["which:profile", whichProfileCommand],
41
+ // ── Plugins ────────────────────────────────────────────────────────
42
+ ["list:plugin", listPluginsCommand],
43
+ ["load:plugin", loadPluginCommand],
44
+ ["unload:plugin", unloadPluginCommand],
45
+ ["sync:plugin", syncPluginsCommand],
46
+ ["upgrade:plugin", upgradePluginCommand],
47
+ ["downgrade:plugin", downgradePluginCommand],
48
+ ["init:plugin", initPluginCommand],
49
+ // ── Process instances ──────────────────────────────────────────────
50
+ ["list:process-instance", listProcessInstancesCommand],
51
+ ["get:process-instance", getProcessInstanceCommand],
52
+ ["create:process-instance", createProcessInstanceCommand],
53
+ ["cancel:process-instance", cancelProcessInstanceCommand],
54
+ ["await:process-instance", awaitProcessInstanceCommand],
55
+ // ── Process definitions ────────────────────────────────────────────
56
+ ["list:process-definition", listProcessDefinitionsCommand],
57
+ ["get:process-definition", getProcessDefinitionCommand],
58
+ // ── User tasks ─────────────────────────────────────────────────────
59
+ ["list:user-task", listUserTasksCommand],
60
+ ["complete:user-task", completeUserTaskCommand],
61
+ // ── Incidents ──────────────────────────────────────────────────────
62
+ ["list:incident", listIncidentsCommand],
63
+ ["get:incident", getIncidentCommand],
64
+ ["resolve:incident", resolveIncidentCommand],
65
+ // ── Jobs ────────────────────────────────────────────────────────────
66
+ ["list:jobs", listJobsCommand],
67
+ ["activate:jobs", activateJobsCommand],
68
+ ["complete:job", completeJobCommand],
69
+ ["fail:job", failJobCommand],
70
+ // ── Messages ───────────────────────────────────────────────────────
71
+ ["publish:message", publishMessageCommand],
72
+ ["correlate:message", correlateMessageCommand],
73
+ // ── Topology / forms ───────────────────────────────────────────────
74
+ ["get:topology", getTopologyCommand],
75
+ ["get:form", getFormCommand],
76
+ // ── Search ─────────────────────────────────────────────────────────
77
+ ["search:process-definition", searchProcessDefinitionsCommand],
78
+ ["search:process-instance", searchProcessInstancesCommand],
79
+ ["search:user-task", searchUserTasksCommand],
80
+ ["search:incident", searchIncidentsCommand],
81
+ ["search:jobs", searchJobsCommand],
82
+ ["search:variable", searchVariablesCommand],
83
+ ["search:user", searchIdentityUsersCommand],
84
+ ["search:role", searchIdentityRolesCommand],
85
+ ["search:group", searchIdentityGroupsCommand],
86
+ ["search:tenant", searchIdentityTenantsCommand],
87
+ ["search:authorization", searchIdentityAuthorizationsCommand],
88
+ ["search:mapping-rule", searchIdentityMappingRulesCommand],
89
+ // ── Identity: list ─────────────────────────────────────────────────
90
+ ["list:user", listUsersCommand],
91
+ ["list:role", listRolesCommand],
92
+ ["list:group", listGroupsCommand],
93
+ ["list:tenant", listTenantsCommand],
94
+ ["list:authorization", listAuthorizationsCommand],
95
+ ["list:mapping-rule", listMappingRulesCommand],
96
+ // ── Identity: get ──────────────────────────────────────────────────
97
+ ["get:user", getIdentityUserCommand],
98
+ ["get:role", getIdentityRoleCommand],
99
+ ["get:group", getIdentityGroupCommand],
100
+ ["get:tenant", getIdentityTenantCommand],
101
+ ["get:authorization", getIdentityAuthorizationCommand],
102
+ ["get:mapping-rule", getIdentityMappingRuleCommand],
103
+ // ── Identity: create ───────────────────────────────────────────────
104
+ ["create:user", createIdentityUserCommand],
105
+ ["create:role", createIdentityRoleCommand],
106
+ ["create:group", createIdentityGroupCommand],
107
+ ["create:tenant", createIdentityTenantCommand],
108
+ ["create:authorization", createIdentityAuthorizationCommand],
109
+ ["create:mapping-rule", createIdentityMappingRuleCommand],
110
+ // ── Identity: delete ───────────────────────────────────────────────
111
+ ["delete:user", deleteIdentityUserCommand],
112
+ ["delete:role", deleteIdentityRoleCommand],
113
+ ["delete:group", deleteIdentityGroupCommand],
114
+ ["delete:tenant", deleteIdentityTenantCommand],
115
+ ["delete:authorization", deleteIdentityAuthorizationCommand],
116
+ ["delete:mapping-rule", deleteIdentityMappingRuleCommand],
117
+ // ── Resourceless verbs ─────────────────────────────────────────────
118
+ ["deploy:", deployCommand],
119
+ ["run:", runCommand],
120
+ ["watch:", watchCommand],
121
+ ["open:", openAppCommand],
122
+ ["open:operate", openAppCommand],
123
+ ["open:tasklist", openAppCommand],
124
+ ["open:modeler", openAppCommand],
125
+ ["open:optimize", openAppCommand],
126
+ ["feedback:", feedbackCommand],
127
+ ["mcp-proxy:", mcpProxyCommand],
128
+ ]);
129
+ //# sourceMappingURL=command-dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-dispatch.js","sourceRoot":"","sources":["../src/command-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACN,kCAAkC,EAClC,0BAA0B,EAC1B,gCAAgC,EAChC,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,kCAAkC,EAClC,0BAA0B,EAC1B,gCAAgC,EAChC,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,+BAA+B,EAC/B,uBAAuB,EACvB,6BAA6B,EAC7B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EACl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C,CAAC,UAAU,EAAE,sBAAsB,CAAC;IACpC,CAAC,WAAW,EAAE,uBAAuB,CAAC;IACtC,CAAC,YAAY,EAAE,wBAAwB,CAAC;IACxC,CAAC,mBAAmB,EAAE,+BAA+B,CAAC;IACtD,CAAC,kBAAkB,EAAE,6BAA6B,CAAC;IAEnD,sEAAsE;IACtE,CAAC,aAAa,EAAE,yBAAyB,CAAC;IAC1C,CAAC,aAAa,EAAE,yBAAyB,CAAC;IAC1C,CAAC,cAAc,EAAE,0BAA0B,CAAC;IAC5C,CAAC,eAAe,EAAE,2BAA2B,CAAC;IAC9C,CAAC,sBAAsB,EAAE,kCAAkC,CAAC;IAC5D,CAAC,qBAAqB,EAAE,gCAAgC,CAAC;IAEzD,sEAAsE;IACtE,CAAC,aAAa,EAAE,yBAAyB,CAAC;IAC1C,CAAC,aAAa,EAAE,yBAAyB,CAAC;IAC1C,CAAC,cAAc,EAAE,0BAA0B,CAAC;IAC5C,CAAC,eAAe,EAAE,2BAA2B,CAAC;IAC9C,CAAC,sBAAsB,EAAE,kCAAkC,CAAC;IAC5D,CAAC,qBAAqB,EAAE,gCAAgC,CAAC;IAEzD,sEAAsE;IACtE,CAAC,SAAS,EAAE,aAAa,CAAC;IAC1B,CAAC,MAAM,EAAE,UAAU,CAAC;IACpB,CAAC,QAAQ,EAAE,YAAY,CAAC;IACxB,CAAC,OAAO,EAAE,cAAc,CAAC;IACzB,CAAC,cAAc,EAAE,cAAc,CAAC;IAChC,CAAC,eAAe,EAAE,cAAc,CAAC;IACjC,CAAC,cAAc,EAAE,cAAc,CAAC;IAChC,CAAC,eAAe,EAAE,cAAc,CAAC;IACjC,CAAC,WAAW,EAAE,eAAe,CAAC;IAC9B,CAAC,YAAY,EAAE,eAAe,CAAC;CAC/B,CAAC,CAAC"}
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Type-safe command definition framework.
3
+ *
4
+ * Provides `defineCommand(verb, resource, handler)` — flags and positionals
5
+ * are derived from the command registry, so handlers receive branded SDK types
6
+ * without any ceremony or `as` casts.
7
+ *
8
+ * Handlers return a `CommandResult` discriminated union. The framework renders
9
+ * results and catches errors in a single place, eliminating per-handler
10
+ * boilerplate for table/json output, empty-list messages, dry-run emission,
11
+ * sorting, and error handling.
12
+ *
13
+ * Phase 2 of #230.
14
+ */
15
+ import type { CamundaClient } from "@camunda8/orchestration-cluster-api";
16
+ import { COMMAND_REGISTRY, type FlagDef, type PositionalDef } from "./command-registry.ts";
17
+ import { type Logger, type SortOrder } from "./logger.ts";
18
+ export type { PositionalDef };
19
+ /** Narrow type of the registry — preserves literal keys and `as const` values. */
20
+ type Registry = typeof COMMAND_REGISTRY;
21
+ /**
22
+ * Resolve the flag schema for a verb×resource pair.
23
+ *
24
+ * If the verb has `resourceFlags[R]`, use it. Otherwise fall back to
25
+ * the verb-level `flags` superset.
26
+ */
27
+ export type ResolvedFlags<V extends keyof Registry, R extends string> = Registry[V] extends {
28
+ resourceFlags: Record<string, Record<string, FlagDef>>;
29
+ } ? R extends keyof Registry[V]["resourceFlags"] ? Registry[V]["resourceFlags"][R] : Registry[V]["flags"] : Registry[V]["flags"];
30
+ /**
31
+ * Resolve the positional schema for a verb×resource pair.
32
+ *
33
+ * If the verb has `resourcePositionals[R]`, use it. Otherwise the
34
+ * command has no positional arguments.
35
+ */
36
+ export type ResolvedPositionals<V extends keyof Registry, R extends string> = Registry[V] extends {
37
+ resourcePositionals: Record<string, readonly PositionalDef[]>;
38
+ } ? R extends keyof Registry[V]["resourcePositionals"] ? Registry[V]["resourcePositionals"][R] : readonly [] : readonly [];
39
+ /**
40
+ * Map a flag schema to typed handler parameters.
41
+ *
42
+ * - Flags with `validate` → the validator's return type (branded) | undefined
43
+ * - Boolean flags → boolean | undefined
44
+ * - Everything else → string | undefined
45
+ *
46
+ * All flags are optional because CLI users may omit any flag.
47
+ *
48
+ * The type parameter is unconstrained so conditional types like
49
+ * `ResolvedFlags<V, R>` can be passed through without constraint errors.
50
+ */
51
+ export type InferFlags<F extends Record<string, any>> = {
52
+ [K in keyof F]: F[K] extends {
53
+ validate: (v: string) => infer R;
54
+ } ? R | undefined : F[K] extends {
55
+ type: "boolean";
56
+ } ? boolean | undefined : string | undefined;
57
+ };
58
+ /**
59
+ * Map a readonly positional schema tuple to a named record of typed values.
60
+ *
61
+ * - Positionals with `validate` → the validator's return type
62
+ * - Positionals without `validate` → string
63
+ * - Required positionals → non-optional
64
+ * - Optional positionals → `| undefined`
65
+ *
66
+ * Accepts any type and uses a conditional guard so deferred types
67
+ * like `ResolvedPositionals<V, R>` pass through cleanly.
68
+ */
69
+ export type InferPositionals<P> = P extends readonly PositionalDef[] ? {
70
+ [K in P[number] as K["name"]]: K extends {
71
+ validate: (v: string) => infer R;
72
+ } ? K extends {
73
+ required: true;
74
+ } ? R : R | undefined : K extends {
75
+ required: true;
76
+ } ? string : string | undefined;
77
+ } : Record<string, never>;
78
+ /**
79
+ * Discriminated union returned by command handlers.
80
+ *
81
+ * The framework's `execute` method renders these centrally — handlers
82
+ * never call `logger.table()` or `logger.json()` directly.
83
+ */
84
+ /** List/search command: render as table or JSON array. */
85
+ export interface ListResult {
86
+ readonly kind: "list";
87
+ /** Already-mapped display rows (e.g. { Key, "Process ID", State }). */
88
+ readonly items: Record<string, unknown>[];
89
+ /** Message when items is empty (e.g. "No process instances found"). */
90
+ readonly emptyMessage: string;
91
+ }
92
+ /** Get command: render a single object as JSON. */
93
+ export interface GetResult {
94
+ readonly kind: "get";
95
+ /** The raw API response object. */
96
+ readonly data: unknown;
97
+ /** Optional info message logged before the JSON data (e.g. source hint). */
98
+ readonly message?: string;
99
+ }
100
+ /** Raw output: emit a string verbatim (e.g. BPMN XML). */
101
+ export interface RawResult {
102
+ readonly kind: "raw";
103
+ /** String content to output verbatim. */
104
+ readonly content: string;
105
+ }
106
+ /** Dry-run: handler determined a dry-run was emitted and wants to stop. */
107
+ export interface DryRunResult {
108
+ readonly kind: "dryRun";
109
+ /** Dry-run info object (passed to logger.json). */
110
+ readonly info: Record<string, unknown>;
111
+ }
112
+ /** Info message: no data to display, just a message (e.g. "User task has no form"). */
113
+ export interface InfoResult {
114
+ readonly kind: "info";
115
+ /** Message to display. */
116
+ readonly message: string;
117
+ }
118
+ /** Success message: a mutating operation succeeded (e.g. "Incident 77777 resolved"). */
119
+ export interface SuccessResult {
120
+ readonly kind: "success";
121
+ /** Human-readable success message. */
122
+ readonly message: string;
123
+ /** Optional resource key to display alongside the message. */
124
+ readonly key?: string | number;
125
+ }
126
+ /** No result: side-effectful command that handles its own output (e.g. deploy, run, open). */
127
+ export interface NoResult {
128
+ readonly kind: "none";
129
+ }
130
+ /** Never-returning command: runs indefinitely or takes over the process (e.g. watch, mcp-proxy). */
131
+ export interface NeverResult {
132
+ readonly kind: "never";
133
+ }
134
+ export type CommandResult = ListResult | GetResult | RawResult | DryRunResult | InfoResult | SuccessResult | NoResult | NeverResult;
135
+ /**
136
+ * Shared dependencies injected into every command handler.
137
+ *
138
+ * Replaces the current pattern where each handler independently calls
139
+ * createClient(), resolveTenantId(), getLogger().
140
+ */
141
+ export interface CommandContext {
142
+ /** Authenticated SDK client for the active profile. */
143
+ client: CamundaClient;
144
+ /** Logger configured for the current output mode. */
145
+ logger: Logger;
146
+ /** Tenant ID from the active profile (undefined if not multi-tenant). */
147
+ tenantId: string | undefined;
148
+ /** Normalised resource name (e.g. "process-instance"). */
149
+ resource: string;
150
+ /** Positional arguments after verb and resource (e.g. the key in `get pi <key>`). */
151
+ positionals: string[];
152
+ /** Sort direction from --asc / --desc flags. */
153
+ sortOrder: SortOrder;
154
+ /** Sort field from --sortBy flag. */
155
+ sortBy: string | undefined;
156
+ /** Pagination limit from --limit flag (parsed to number). */
157
+ limit: number | undefined;
158
+ /** Whether --all was set (e.g. list all, disable default state filter). */
159
+ all: boolean | undefined;
160
+ /** Date range from --between flag (e.g. "7d", "2024-01-01..2024-12-31"). */
161
+ between: string | undefined;
162
+ /** Date field for --between filter. */
163
+ dateField: string | undefined;
164
+ /** Version filter (parsed from --version flag). */
165
+ version?: number | undefined;
166
+ /** Whether --dry-run was set. */
167
+ dryRun: boolean | undefined;
168
+ /** Active profile name (for client/tenant resolution). */
169
+ profile: string | undefined;
170
+ }
171
+ /**
172
+ * Return type of `defineCommand`. Stores the verb, resource, and an
173
+ * `execute` method that deserializes raw CLI input and calls the handler
174
+ * with fully typed flags and positionals.
175
+ */
176
+ export interface CommandHandler<V extends keyof Registry, R extends string> {
177
+ verb: V;
178
+ resource: R;
179
+ execute: (ctx: CommandContext, rawValues: Record<string, unknown>, rawArgs: string[]) => Promise<void>;
180
+ }
181
+ /**
182
+ * Type-erased command handler for use in dispatch maps.
183
+ * Preserves the `execute` signature without carrying generic type params.
184
+ */
185
+ export type AnyCommandHandler = CommandHandler<keyof Registry, string>;
186
+ /**
187
+ * Define a command handler for a verb×resource pair.
188
+ *
189
+ * Flags and positionals are derived from the command registry —
190
+ * no ceremony, no duplication. The handler receives fully typed
191
+ * parameters.
192
+ *
193
+ * ```ts
194
+ * export const getProcessDefinition = defineCommand(
195
+ * "get",
196
+ * "process-definition",
197
+ * async (ctx, flags, args) => {
198
+ * // ctx.client is CamundaClient
199
+ * // flags.xml is boolean | undefined
200
+ * // args.key is ProcessDefinitionKey
201
+ * },
202
+ * );
203
+ * ```
204
+ */
205
+ export declare function defineCommand<V extends keyof Registry, R extends string>(verb: V, resource: R, handler: (ctx: CommandContext, flags: InferFlags<ResolvedFlags<V, R>>, args: InferPositionals<ResolvedPositionals<V, R>>) => Promise<CommandResult | undefined>): CommandHandler<V, R>;
206
+ /**
207
+ * Deserialize raw parseArgs values into typed flags.
208
+ *
209
+ * For each flag in the schema:
210
+ * - If the flag has a `validate` function and the raw value is a non-empty
211
+ * string, call the validator (which returns a branded type).
212
+ * - If the flag is boolean, extract the boolean value.
213
+ * - Otherwise, extract the string value.
214
+ *
215
+ * Validators that throw are intentionally NOT caught here — validation
216
+ * errors should propagate to the top-level error handler.
217
+ */
218
+ export declare function deserializeFlags<F extends Record<string, FlagDef>>(values: Record<string, unknown>, flagDefs: F): InferFlags<F>;
219
+ /**
220
+ * Deserialize raw positional strings into a typed named record.
221
+ *
222
+ * For each positional in the schema (in order):
223
+ * - If required and missing, exits with an error message.
224
+ * - If a `validate` function is present, calls it to produce a branded type.
225
+ * - Otherwise, passes the raw string through.
226
+ *
227
+ * Returns a named record keyed by each positional's `name`.
228
+ */
229
+ export declare function deserializePositionals<P extends readonly PositionalDef[]>(raw: string[], positionalDefs: P, verb: string, resource: string): InferPositionals<P>;
230
+ /**
231
+ * Check if dry-run mode is active and return a `DryRunResult` if so.
232
+ *
233
+ * Usage in handlers:
234
+ * ```ts
235
+ * const dr = dryRun({ command: "list pi", method: "POST", endpoint: "/process-instances/search", profile, body: filter });
236
+ * if (dr) return dr;
237
+ * ```
238
+ *
239
+ * Replaces the old `emitDryRun()` side-effecting pattern.
240
+ */
241
+ export declare function dryRun(opts: {
242
+ command: string;
243
+ method: string;
244
+ endpoint: string;
245
+ profile?: string;
246
+ body?: unknown;
247
+ }): DryRunResult | null;
248
+ //# sourceMappingURL=command-framework.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-framework.d.ts","sourceRoot":"","sources":["../src/command-framework.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EACN,gBAAgB,EAEhB,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAEN,KAAK,MAAM,EACX,KAAK,SAAS,EAEd,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,aAAa,EAAE,CAAC;AAI9B,kFAAkF;AAClF,KAAK,QAAQ,GAAG,OAAO,gBAAgB,CAAC;AAIxC;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CACxB,CAAC,SAAS,MAAM,QAAQ,EACxB,CAAC,SAAS,MAAM,IACb,QAAQ,CAAC,CAAC,CAAC,S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AQ,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC,CAsBf;AAID;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,SAAS,aAAa,EAAE,EACxE,GAAG,EAAE,MAAM,EAAE,EACb,cAAc,EAAE,CAAC,EACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACd,gBAAgB,CAAC,CAAC,CAAC,CAoDrB;AAkDD;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,GAAG,YAAY,GAAG,IAAI,CAatB"}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Type-safe command definition framework.
3
+ *
4
+ * Provides `defineCommand(verb, resource, handler)` — flags and positionals
5
+ * are derived from the command registry, so handlers receive branded SDK types
6
+ * without any ceremony or `as` casts.
7
+ *
8
+ * Handlers return a `CommandResult` discriminated union. The framework renders
9
+ * results and catches errors in a single place, eliminating per-handler
10
+ * boilerplate for table/json output, empty-list messages, dry-run emission,
11
+ * sorting, and error handling.
12
+ *
13
+ * Phase 2 of #230.
14
+ */
15
+ import { COMMAND_REGISTRY, } from "./command-registry.js";
16
+ import { resolveClusterConfig } from "./config.js";
17
+ import { handleCommandError } from "./errors.js";
18
+ import { getLogger, sortTableData, } from "./logger.js";
19
+ import { c8ctl } from "./runtime.js";
20
+ // ─── defineCommand ───────────────────────────────────────────────────────────
21
+ /**
22
+ * Define a command handler for a verb×resource pair.
23
+ *
24
+ * Flags and positionals are derived from the command registry —
25
+ * no ceremony, no duplication. The handler receives fully typed
26
+ * parameters.
27
+ *
28
+ * ```ts
29
+ * export const getProcessDefinition = defineCommand(
30
+ * "get",
31
+ * "process-definition",
32
+ * async (ctx, flags, args) => {
33
+ * // ctx.client is CamundaClient
34
+ * // flags.xml is boolean | undefined
35
+ * // args.key is ProcessDefinitionKey
36
+ * },
37
+ * );
38
+ * ```
39
+ */
40
+ export function defineCommand(verb, resource, handler) {
41
+ // Widen to CommandDef so optional properties are accessible regardless of which verb V is
42
+ const entry = COMMAND_REGISTRY[verb];
43
+ const flagDefs = entry.resourceFlags?.[resource] ?? entry.flags;
44
+ const positionalDefs = entry.resourcePositionals?.[resource] ?? [];
45
+ return {
46
+ verb,
47
+ resource,
48
+ execute: async (ctx, rawValues, rawArgs) => {
49
+ const flags = deserializeFlags(rawValues, flagDefs);
50
+ const args = deserializePositionals(rawArgs, positionalDefs, verb, resource);
51
+ try {
52
+ const result = await handler(ctx,
53
+ // biome-ignore lint/plugin: framework-internal assertion — flagDefs resolved from COMMAND_REGISTRY[V][R]
54
+ flags,
55
+ // biome-ignore lint/plugin: framework-internal assertion — positionalDefs resolved from COMMAND_REGISTRY[V][R]
56
+ args);
57
+ if (result)
58
+ renderResult(result, ctx);
59
+ }
60
+ catch (error) {
61
+ handleCommandError(ctx.logger, `Failed to ${verb} ${resource.replace(/-/g, " ")}`, error);
62
+ }
63
+ },
64
+ };
65
+ }
66
+ // ─── deserializeFlags ────────────────────────────────────────────────────────
67
+ /**
68
+ * Deserialize raw parseArgs values into typed flags.
69
+ *
70
+ * For each flag in the schema:
71
+ * - If the flag has a `validate` function and the raw value is a non-empty
72
+ * string, call the validator (which returns a branded type).
73
+ * - If the flag is boolean, extract the boolean value.
74
+ * - Otherwise, extract the string value.
75
+ *
76
+ * Validators that throw are intentionally NOT caught here — validation
77
+ * errors should propagate to the top-level error handler.
78
+ */
79
+ export function deserializeFlags(values, flagDefs) {
80
+ const result = {};
81
+ for (const [key, def] of Object.entries(flagDefs)) {
82
+ const raw = values[key];
83
+ if (raw === undefined || raw === false) {
84
+ result[key] = undefined;
85
+ continue;
86
+ }
87
+ if (def.type === "boolean") {
88
+ result[key] = typeof raw === "boolean" ? raw : undefined;
89
+ }
90
+ else if (typeof raw === "string" && raw !== "") {
91
+ result[key] = def.validate ? def.validate(raw) : raw;
92
+ }
93
+ else {
94
+ result[key] = undefined;
95
+ }
96
+ }
97
+ // biome-ignore lint/plugin: internal assertion — result is built key-by-key from flagDefs, matching InferFlags<F> structurally
98
+ return result;
99
+ }
100
+ // ─── deserializePositionals ──────────────────────────────────────────────────
101
+ /**
102
+ * Deserialize raw positional strings into a typed named record.
103
+ *
104
+ * For each positional in the schema (in order):
105
+ * - If required and missing, exits with an error message.
106
+ * - If a `validate` function is present, calls it to produce a branded type.
107
+ * - Otherwise, passes the raw string through.
108
+ *
109
+ * Returns a named record keyed by each positional's `name`.
110
+ */
111
+ export function deserializePositionals(raw, positionalDefs, verb, resource) {
112
+ const result = {};
113
+ for (let i = 0; i < positionalDefs.length; i++) {
114
+ const def = positionalDefs[i];
115
+ const value = raw[i];
116
+ if (!value) {
117
+ if (def.required) {
118
+ // Build a human-readable label from the positional name:
119
+ // "roleId" → "role ID", "mappingRuleId" → "mapping rule ID", "key" → "key"
120
+ const expandedName = def.name
121
+ .replace(/([a-z])([A-Z])/g, "$1 $2")
122
+ .toLowerCase()
123
+ .replace(/\bid\b/gi, "ID");
124
+ // If the expanded name already starts with the resource name,
125
+ // use it directly (e.g. "username" for resource "user" → "Username required").
126
+ // Otherwise, prepend the resource as context (e.g. "key" for "user-task" → "User task key required").
127
+ const resourceNorm = resource.replace(/-/g, " ");
128
+ const alreadyDescriptive = expandedName
129
+ .toLowerCase()
130
+ .startsWith(resourceNorm.toLowerCase());
131
+ let displayLabel;
132
+ if (alreadyDescriptive) {
133
+ displayLabel =
134
+ expandedName.charAt(0).toUpperCase() + expandedName.slice(1);
135
+ }
136
+ else {
137
+ // Singularize trailing "s" for the prefix (e.g. "jobs" → "Job")
138
+ const prefix = resourceNorm.replace(/s$/, "");
139
+ displayLabel =
140
+ prefix.charAt(0).toUpperCase() +
141
+ prefix.slice(1) +
142
+ " " +
143
+ expandedName;
144
+ }
145
+ getLogger().error(`${displayLabel} required. Usage: c8 ${verb} ${resource} <${def.name}>`);
146
+ process.exit(1);
147
+ }
148
+ result[def.name] = undefined;
149
+ continue;
150
+ }
151
+ result[def.name] = def.validate ? def.validate(value) : value;
152
+ }
153
+ // biome-ignore lint/plugin: internal assertion — result is built key-by-key from positionalDefs, matching InferPositionals<P> structurally
154
+ return result;
155
+ }
156
+ // ─── renderResult ────────────────────────────────────────────────────────────
157
+ /**
158
+ * Render a `CommandResult` to the user via the logger.
159
+ *
160
+ * This is the single rendering point for all command output —
161
+ * handlers never call logger.table/json/output/info directly.
162
+ *
163
+ * During migration, handlers that still do their own I/O return
164
+ * `undefined` (implicit void) — renderResult is a no-op in that case.
165
+ */
166
+ function renderResult(result, ctx) {
167
+ if (!result)
168
+ return;
169
+ const { logger, sortBy, sortOrder } = ctx;
170
+ switch (result.kind) {
171
+ case "list":
172
+ if (result.items.length > 0) {
173
+ const sorted = sortTableData(result.items, sortBy, logger, sortOrder);
174
+ logger.table(sorted);
175
+ }
176
+ else {
177
+ logger.info(result.emptyMessage);
178
+ }
179
+ break;
180
+ case "get":
181
+ if (result.message)
182
+ logger.info(result.message);
183
+ logger.json(result.data);
184
+ break;
185
+ case "raw":
186
+ logger.output(result.content);
187
+ break;
188
+ case "dryRun":
189
+ logger.json(result.info);
190
+ break;
191
+ case "info":
192
+ logger.info(result.message);
193
+ break;
194
+ case "success":
195
+ logger.success(result.message, result.key);
196
+ break;
197
+ case "none":
198
+ case "never":
199
+ break;
200
+ }
201
+ }
202
+ // ─── dryRun ──────────────────────────────────────────────────────────────────
203
+ /**
204
+ * Check if dry-run mode is active and return a `DryRunResult` if so.
205
+ *
206
+ * Usage in handlers:
207
+ * ```ts
208
+ * const dr = dryRun({ command: "list pi", method: "POST", endpoint: "/process-instances/search", profile, body: filter });
209
+ * if (dr) return dr;
210
+ * ```
211
+ *
212
+ * Replaces the old `emitDryRun()` side-effecting pattern.
213
+ */
214
+ export function dryRun(opts) {
215
+ if (!c8ctl.dryRun)
216
+ return null;
217
+ const config = resolveClusterConfig(opts.profile);
218
+ return {
219
+ kind: "dryRun",
220
+ info: {
221
+ dryRun: true,
222
+ command: opts.command,
223
+ method: opts.method,
224
+ url: `${config.baseUrl}${opts.endpoint}`,
225
+ ...(opts.body !== undefined && { body: opts.body }),
226
+ },
227
+ };
228
+ }
229
+ //# sourceMappingURL=command-framework.js.map