@sanity/cli 8.27.0 → 8.28.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.
Files changed (138) hide show
  1. package/README.md +1515 -408
  2. package/dist/actions/context/commandTable.js +215 -0
  3. package/dist/actions/context/commandTable.js.map +1 -0
  4. package/dist/actions/context/contextCommand.js +246 -0
  5. package/dist/actions/context/contextCommand.js.map +1 -0
  6. package/dist/actions/context/contextSpec.js +18 -0
  7. package/dist/actions/context/contextSpec.js.map +1 -0
  8. package/dist/actions/context/distillContextOperations.js +335 -0
  9. package/dist/actions/context/distillContextOperations.js.map +1 -0
  10. package/dist/actions/context/mcpEndpoint.js.map +1 -1
  11. package/dist/actions/context/operationInput.js +226 -0
  12. package/dist/actions/context/operationInput.js.map +1 -0
  13. package/dist/actions/context/operationTypes.js +3 -0
  14. package/dist/actions/context/operationTypes.js.map +1 -0
  15. package/dist/actions/context/removedCommands.js +26 -0
  16. package/dist/actions/context/removedCommands.js.map +1 -0
  17. package/dist/actions/context/renderOperationResult.js +72 -0
  18. package/dist/actions/context/renderOperationResult.js.map +1 -0
  19. package/dist/actions/context/sourceFile.js +31 -0
  20. package/dist/actions/context/sourceFile.js.map +1 -0
  21. package/dist/actions/context/syncOutput.js +17 -0
  22. package/dist/actions/context/syncOutput.js.map +1 -0
  23. package/dist/actions/context/table.js +13 -0
  24. package/dist/actions/context/table.js.map +1 -0
  25. package/dist/actions/context/waitForJob.js.map +1 -1
  26. package/dist/actions/context/waitForSourceSync.js +48 -0
  27. package/dist/actions/context/waitForSourceSync.js.map +1 -0
  28. package/dist/actions/context/watchJob.js.map +1 -1
  29. package/dist/actions/context/watchSourceSync.js +40 -0
  30. package/dist/actions/context/watchSourceSync.js.map +1 -0
  31. package/dist/actions/dev/servers/startStudioDevServer.js +4 -1
  32. package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -1
  33. package/dist/commands/context/build.js +19 -81
  34. package/dist/commands/context/build.js.map +1 -1
  35. package/dist/commands/context/create.js +3 -90
  36. package/dist/commands/context/create.js.map +1 -1
  37. package/dist/commands/context/delete.js +3 -73
  38. package/dist/commands/context/delete.js.map +1 -1
  39. package/dist/commands/context/documents/content.js +117 -0
  40. package/dist/commands/context/documents/content.js.map +1 -0
  41. package/dist/commands/context/documents/delete.js +5 -0
  42. package/dist/commands/context/documents/delete.js.map +1 -0
  43. package/dist/commands/context/documents/edit.js +5 -0
  44. package/dist/commands/context/documents/edit.js.map +1 -0
  45. package/dist/commands/context/documents/get.js +5 -0
  46. package/dist/commands/context/documents/get.js.map +1 -0
  47. package/dist/commands/context/documents/list.js +5 -0
  48. package/dist/commands/context/documents/list.js.map +1 -0
  49. package/dist/commands/context/entries/list.js +2 -2
  50. package/dist/commands/context/entries/list.js.map +1 -1
  51. package/dist/commands/context/entries/rebuild.js +3 -93
  52. package/dist/commands/context/entries/rebuild.js.map +1 -1
  53. package/dist/commands/context/get.js +3 -88
  54. package/dist/commands/context/get.js.map +1 -1
  55. package/dist/commands/context/instructions/create.js +5 -0
  56. package/dist/commands/context/instructions/create.js.map +1 -0
  57. package/dist/commands/context/instructions/delete.js +5 -0
  58. package/dist/commands/context/instructions/delete.js.map +1 -0
  59. package/dist/commands/context/instructions/edit.js +5 -0
  60. package/dist/commands/context/instructions/edit.js.map +1 -0
  61. package/dist/commands/context/issues/apply.js +3 -84
  62. package/dist/commands/context/issues/apply.js.map +1 -1
  63. package/dist/commands/context/issues/dismiss.js +3 -50
  64. package/dist/commands/context/issues/dismiss.js.map +1 -1
  65. package/dist/commands/context/issues/reopen.js +3 -51
  66. package/dist/commands/context/issues/reopen.js.map +1 -1
  67. package/dist/commands/context/issues/resolve.js +23 -92
  68. package/dist/commands/context/issues/resolve.js.map +1 -1
  69. package/dist/commands/context/jobs/get.js +3 -88
  70. package/dist/commands/context/jobs/get.js.map +1 -1
  71. package/dist/commands/context/list.js +3 -95
  72. package/dist/commands/context/list.js.map +1 -1
  73. package/dist/commands/context/mcp/initial-context.js +5 -0
  74. package/dist/commands/context/mcp/initial-context.js.map +1 -0
  75. package/dist/commands/context/mcp/list.js +2 -2
  76. package/dist/commands/context/mcp/list.js.map +1 -1
  77. package/dist/commands/context/mcp/status.js.map +1 -1
  78. package/dist/commands/context/mcp/update.js.map +1 -1
  79. package/dist/commands/context/sources/create.js +175 -0
  80. package/dist/commands/context/sources/create.js.map +1 -0
  81. package/dist/commands/context/sources/delete.js +5 -0
  82. package/dist/commands/context/sources/delete.js.map +1 -0
  83. package/dist/commands/context/sources/edit.js +29 -0
  84. package/dist/commands/context/sources/edit.js.map +1 -0
  85. package/dist/commands/context/sources/get.js +5 -0
  86. package/dist/commands/context/sources/get.js.map +1 -0
  87. package/dist/commands/context/sources/list.js +5 -0
  88. package/dist/commands/context/sources/list.js.map +1 -0
  89. package/dist/commands/context/sources/sync.js +5 -0
  90. package/dist/commands/context/sources/sync.js.map +1 -0
  91. package/dist/commands/context/sources/syncs/confirm.js +5 -0
  92. package/dist/commands/context/sources/syncs/confirm.js.map +1 -0
  93. package/dist/commands/context/sources/syncs/discard.js +5 -0
  94. package/dist/commands/context/sources/syncs/discard.js.map +1 -0
  95. package/dist/commands/context/sources/syncs/get.js +5 -0
  96. package/dist/commands/context/sources/syncs/get.js.map +1 -0
  97. package/dist/commands/context/sources/syncs/list.js +5 -0
  98. package/dist/commands/context/sources/syncs/list.js.map +1 -0
  99. package/dist/commands/context/sources/upload.js +63 -0
  100. package/dist/commands/context/sources/upload.js.map +1 -0
  101. package/dist/commands/context/sync.js +5 -0
  102. package/dist/commands/context/sync.js.map +1 -0
  103. package/dist/commands/context/update.js +3 -136
  104. package/dist/commands/context/update.js.map +1 -1
  105. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +41 -26
  106. package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
  107. package/dist/generated/apiRoutes.js +28 -0
  108. package/dist/generated/apiRoutes.js.map +1 -1
  109. package/dist/generated/contextOperations.js +1116 -0
  110. package/dist/generated/contextOperations.js.map +1 -0
  111. package/dist/hooks/commandNotFound/topicAliases.js +8 -2
  112. package/dist/hooks/commandNotFound/topicAliases.js.map +1 -1
  113. package/dist/services/context.js +241 -268
  114. package/dist/services/context.js.map +1 -1
  115. package/dist/util/telemetry/cliCommandIdentity.js +10 -18
  116. package/dist/util/telemetry/cliCommandIdentity.js.map +1 -1
  117. package/oclif.manifest.json +3380 -1910
  118. package/package.json +24 -23
  119. package/templates/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  120. package/templates/app-quickstart/AGENTS.md +49 -0
  121. package/templates/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  122. package/templates/app-sanity-ui/AGENTS.md +49 -0
  123. package/templates/shared/dashboard/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  124. package/templates/shared/dashboard/app-quickstart/AGENTS.md +49 -0
  125. package/templates/shared/dashboard/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
  126. package/templates/shared/dashboard/app-sanity-ui/AGENTS.md +49 -0
  127. package/dist/commands/context/imports/create.js +0 -270
  128. package/dist/commands/context/imports/create.js.map +0 -1
  129. package/dist/commands/context/imports/delete.js +0 -73
  130. package/dist/commands/context/imports/delete.js.map +0 -1
  131. package/dist/commands/context/imports/download.js +0 -60
  132. package/dist/commands/context/imports/download.js.map +0 -1
  133. package/dist/commands/context/imports/get.js +0 -88
  134. package/dist/commands/context/imports/get.js.map +0 -1
  135. package/dist/commands/context/imports/list.js +0 -100
  136. package/dist/commands/context/imports/list.js.map +0 -1
  137. package/dist/commands/context/refresh.js +0 -46
  138. package/dist/commands/context/refresh.js.map +0 -1
@@ -0,0 +1,215 @@
1
+ /**
2
+ * The Context commands generated from the Context API's OpenAPI spec: one
3
+ * command per operation. `pnpm generate:context-commands` reads this table and
4
+ * the spec `@sanity/client` vendors, and writes the operation metadata
5
+ * (`src/generated/contextOperations.ts`) and one command file per entry.
6
+ *
7
+ * Path parameters become arguments; query and body fields become flags, with
8
+ * their types, enums and descriptions from the spec. The fields below cover
9
+ * only what the spec can't say.
10
+ */ export const contextCommandTable = [
11
+ {
12
+ columns: [
13
+ 'publicId',
14
+ 'title',
15
+ 'state',
16
+ 'openIssueCount',
17
+ 'updatedAt'
18
+ ],
19
+ id: 'context list',
20
+ operationId: 'listKnowledgeBases'
21
+ },
22
+ {
23
+ id: 'context create',
24
+ operationId: 'createKnowledgeBase',
25
+ prompt: [
26
+ 'title',
27
+ 'description'
28
+ ],
29
+ promptUnless: 'draft'
30
+ },
31
+ {
32
+ id: 'context get',
33
+ operationId: 'getKnowledgeBase'
34
+ },
35
+ {
36
+ guard: 'knowledgeBaseBlueprint',
37
+ guardFields: [
38
+ 'title',
39
+ 'description'
40
+ ],
41
+ id: 'context update',
42
+ operationId: 'updateKnowledgeBase'
43
+ },
44
+ {
45
+ guard: 'knowledgeBaseBlueprint',
46
+ id: 'context delete',
47
+ operationId: 'deleteKnowledgeBase'
48
+ },
49
+ {
50
+ id: 'context sync',
51
+ operationId: 'syncAllSources'
52
+ },
53
+ {
54
+ handWritten: true,
55
+ id: 'context build',
56
+ operationId: 'buildKnowledgeBase',
57
+ watch: 'job'
58
+ },
59
+ {
60
+ columns: [
61
+ 'id',
62
+ 'type',
63
+ 'title',
64
+ 'documentCount',
65
+ 'syncFrequency',
66
+ 'updatedAt'
67
+ ],
68
+ id: 'context sources list',
69
+ operationId: 'listSources'
70
+ },
71
+ {
72
+ handWritten: true,
73
+ id: 'context sources create',
74
+ omit: [
75
+ 'content'
76
+ ],
77
+ operationId: 'createSource',
78
+ watch: 'sync'
79
+ },
80
+ {
81
+ id: 'context sources get',
82
+ operationId: 'getSource'
83
+ },
84
+ {
85
+ handWritten: true,
86
+ id: 'context sources edit',
87
+ operationId: 'updateSource'
88
+ },
89
+ {
90
+ id: 'context sources delete',
91
+ operationId: 'deleteSource'
92
+ },
93
+ {
94
+ id: 'context sources sync',
95
+ omit: [
96
+ 'uploadId'
97
+ ],
98
+ operationId: 'startSync',
99
+ watch: 'sync'
100
+ },
101
+ {
102
+ handWritten: true,
103
+ id: 'context sources upload',
104
+ omit: [
105
+ 'filename',
106
+ 'contentType'
107
+ ],
108
+ operationId: 'startSourceUpload',
109
+ watch: 'sync'
110
+ },
111
+ {
112
+ columns: [
113
+ 'id',
114
+ 'status',
115
+ 'trigger',
116
+ 'documentsSeen',
117
+ 'documentsUpserted',
118
+ 'createdAt'
119
+ ],
120
+ id: 'context sources syncs list',
121
+ operationId: 'listSyncs'
122
+ },
123
+ {
124
+ id: 'context sources syncs get',
125
+ operationId: 'getSync'
126
+ },
127
+ {
128
+ id: 'context sources syncs confirm',
129
+ operationId: 'confirmSync'
130
+ },
131
+ {
132
+ id: 'context sources syncs discard',
133
+ operationId: 'discardSync'
134
+ },
135
+ {
136
+ columns: [
137
+ 'id',
138
+ 'title',
139
+ 'state',
140
+ 'conversion',
141
+ 'url',
142
+ 'updatedAt'
143
+ ],
144
+ id: 'context documents list',
145
+ operationId: 'listDocuments'
146
+ },
147
+ {
148
+ id: 'context documents get',
149
+ operationId: 'getDocument'
150
+ },
151
+ {
152
+ handWritten: true,
153
+ id: 'context documents content',
154
+ operationId: 'getDocumentContent'
155
+ },
156
+ {
157
+ id: 'context documents edit',
158
+ operationId: 'updateDocument'
159
+ },
160
+ {
161
+ id: 'context documents delete',
162
+ operationId: 'deleteDocument'
163
+ },
164
+ {
165
+ id: 'context entries rebuild',
166
+ operationId: 'rebuildEntry',
167
+ watch: 'job'
168
+ },
169
+ {
170
+ id: 'context jobs get',
171
+ operationId: 'getJob',
172
+ watch: 'job'
173
+ },
174
+ {
175
+ id: 'context issues apply',
176
+ operationId: 'applyIssues',
177
+ variadicArg: 'issueIds',
178
+ watch: 'job'
179
+ },
180
+ {
181
+ id: 'context issues dismiss',
182
+ operationId: 'dismissIssue'
183
+ },
184
+ {
185
+ id: 'context issues reopen',
186
+ operationId: 'reopenIssue'
187
+ },
188
+ {
189
+ handWritten: true,
190
+ id: 'context issues resolve',
191
+ omit: [
192
+ 'resolution'
193
+ ],
194
+ operationId: 'resolveIssue',
195
+ watch: 'job'
196
+ },
197
+ {
198
+ id: 'context instructions create',
199
+ operationId: 'createInstruction'
200
+ },
201
+ {
202
+ id: 'context instructions edit',
203
+ operationId: 'updateInstruction'
204
+ },
205
+ {
206
+ id: 'context instructions delete',
207
+ operationId: 'deleteInstruction'
208
+ },
209
+ {
210
+ id: 'context mcp initial-context',
211
+ operationId: 'getMcpEndpointInitialContext'
212
+ }
213
+ ];
214
+
215
+ //# sourceMappingURL=commandTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/context/commandTable.ts"],"sourcesContent":["/**\n * The Context commands generated from the Context API's OpenAPI spec: one\n * command per operation. `pnpm generate:context-commands` reads this table and\n * the spec `@sanity/client` vendors, and writes the operation metadata\n * (`src/generated/contextOperations.ts`) and one command file per entry.\n *\n * Path parameters become arguments; query and body fields become flags, with\n * their types, enums and descriptions from the spec. The fields below cover\n * only what the spec can't say.\n */\nexport interface ContextCommandEntry {\n /** The command id, after `sanity` */\n readonly id: string\n /** The Context API operation the command calls */\n readonly operationId: string\n\n /** Columns of the table a list renders, in order; the item's scalar fields when left out */\n readonly columns?: readonly string[]\n /** A check that runs before the request, such as refusing a resource a blueprint manages */\n readonly guard?: 'knowledgeBaseBlueprint'\n /** The body fields the guard protects; it guards every request when left out */\n readonly guardFields?: readonly string[]\n /**\n * The command file is hand-written: a class extending `contextCommand(id)`\n * that adds what the spec can't describe, such as reading a local file\n */\n readonly handWritten?: true\n /** Body fields left out of the flags */\n readonly omit?: readonly string[]\n /** Body fields to prompt for when interactive and not passed as flags */\n readonly prompt?: readonly string[]\n /** A boolean body field that, when true, makes the prompted fields optional and skips their prompts */\n readonly promptUnless?: string\n /** A string array body field taken from the remaining arguments instead of a flag */\n readonly variadicArg?: string\n /** What `--watch` waits for: the job the response starts, or the sync of the source */\n readonly watch?: 'job' | 'sync'\n}\n\nexport const contextCommandTable = [\n {\n columns: ['publicId', 'title', 'state', 'openIssueCount', 'updatedAt'],\n id: 'context list',\n operationId: 'listKnowledgeBases',\n },\n {\n id: 'context create',\n operationId: 'createKnowledgeBase',\n prompt: ['title', 'description'],\n promptUnless: 'draft',\n },\n {id: 'context get', operationId: 'getKnowledgeBase'},\n {\n guard: 'knowledgeBaseBlueprint',\n guardFields: ['title', 'description'],\n id: 'context update',\n operationId: 'updateKnowledgeBase',\n },\n {guard: 'knowledgeBaseBlueprint', id: 'context delete', operationId: 'deleteKnowledgeBase'},\n {id: 'context sync', operationId: 'syncAllSources'},\n {handWritten: true, id: 'context build', operationId: 'buildKnowledgeBase', watch: 'job'},\n\n {\n columns: ['id', 'type', 'title', 'documentCount', 'syncFrequency', 'updatedAt'],\n id: 'context sources list',\n operationId: 'listSources',\n },\n {\n handWritten: true,\n id: 'context sources create',\n omit: ['content'],\n operationId: 'createSource',\n watch: 'sync',\n },\n {id: 'context sources get', operationId: 'getSource'},\n {handWritten: true, id: 'context sources edit', operationId: 'updateSource'},\n {id: 'context sources delete', operationId: 'deleteSource'},\n {id: 'context sources sync', omit: ['uploadId'], operationId: 'startSync', watch: 'sync'},\n {\n handWritten: true,\n id: 'context sources upload',\n omit: ['filename', 'contentType'],\n operationId: 'startSourceUpload',\n watch: 'sync',\n },\n {\n columns: ['id', 'status', 'trigger', 'documentsSeen', 'documentsUpserted', 'createdAt'],\n id: 'context sources syncs list',\n operationId: 'listSyncs',\n },\n {id: 'context sources syncs get', operationId: 'getSync'},\n {id: 'context sources syncs confirm', operationId: 'confirmSync'},\n {id: 'context sources syncs discard', operationId: 'discardSync'},\n\n {\n columns: ['id', 'title', 'state', 'conversion', 'url', 'updatedAt'],\n id: 'context documents list',\n operationId: 'listDocuments',\n },\n {id: 'context documents get', operationId: 'getDocument'},\n {handWritten: true, id: 'context documents content', operationId: 'getDocumentContent'},\n {id: 'context documents edit', operationId: 'updateDocument'},\n {id: 'context documents delete', operationId: 'deleteDocument'},\n\n {id: 'context entries rebuild', operationId: 'rebuildEntry', watch: 'job'},\n {id: 'context jobs get', operationId: 'getJob', watch: 'job'},\n\n {id: 'context issues apply', operationId: 'applyIssues', variadicArg: 'issueIds', watch: 'job'},\n {id: 'context issues dismiss', operationId: 'dismissIssue'},\n {id: 'context issues reopen', operationId: 'reopenIssue'},\n {\n handWritten: true,\n id: 'context issues resolve',\n omit: ['resolution'],\n operationId: 'resolveIssue',\n watch: 'job',\n },\n\n {id: 'context instructions create', operationId: 'createInstruction'},\n {id: 'context instructions edit', operationId: 'updateInstruction'},\n {id: 'context instructions delete', operationId: 'deleteInstruction'},\n\n {id: 'context mcp initial-context', operationId: 'getMcpEndpointInitialContext'},\n] as const satisfies readonly ContextCommandEntry[]\n\nexport type ContextCommandId = (typeof contextCommandTable)[number]['id']\n"],"names":["contextCommandTable","columns","id","operationId","prompt","promptUnless","guard","guardFields","handWritten","watch","omit","variadicArg"],"mappings":"AAAA;;;;;;;;;CASC,GA8BD,OAAO,MAAMA,sBAAsB;IACjC;QACEC,SAAS;YAAC;YAAY;YAAS;YAAS;YAAkB;SAAY;QACtEC,IAAI;QACJC,aAAa;IACf;IACA;QACED,IAAI;QACJC,aAAa;QACbC,QAAQ;YAAC;YAAS;SAAc;QAChCC,cAAc;IAChB;IACA;QAACH,IAAI;QAAeC,aAAa;IAAkB;IACnD;QACEG,OAAO;QACPC,aAAa;YAAC;YAAS;SAAc;QACrCL,IAAI;QACJC,aAAa;IACf;IACA;QAACG,OAAO;QAA0BJ,IAAI;QAAkBC,aAAa;IAAqB;IAC1F;QAACD,IAAI;QAAgBC,aAAa;IAAgB;IAClD;QAACK,aAAa;QAAMN,IAAI;QAAiBC,aAAa;QAAsBM,OAAO;IAAK;IAExF;QACER,SAAS;YAAC;YAAM;YAAQ;YAAS;YAAiB;YAAiB;SAAY;QAC/EC,IAAI;QACJC,aAAa;IACf;IACA;QACEK,aAAa;QACbN,IAAI;QACJQ,MAAM;YAAC;SAAU;QAC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+BC,aAAa;IAAmB;IAEpE;QAACD,IAAI;QAA+BC,aAAa;IAA8B;CAChF,CAAkD"}
@@ -0,0 +1,246 @@
1
+ import { CLIError } from '@oclif/core/errors';
2
+ import { exitCodes, SanityCommand, subdebug } from '@sanity/cli-core';
3
+ import { getErrorMessage, JsonOutputError } from '@sanity/cli-core/errors';
4
+ import { confirm } from '@sanity/cli-core/ux';
5
+ import { isHttpError } from '@sanity/client';
6
+ import { contextOperations } from '../../generated/contextOperations.js';
7
+ import { promptForText } from '../../prompts/promptForText.js';
8
+ import { describeBlueprintManager, getKnowledgeBaseBlueprintOwnership, getSource, requestAllPages, requestContext } from '../../services/context.js';
9
+ import { contextCommandTable } from './commandTable.js';
10
+ import { buildOperationRequest, flagName, humanize, needsOrganization, operationArgs, operationFlags, redactedFlags } from './operationInput.js';
11
+ import { renderOperationResult } from './renderOperationResult.js';
12
+ import { resolveOrganizationId } from './resolveOrganizationId.js';
13
+ import { heldSyncHint } from './syncOutput.js';
14
+ import { formatJobFailure, watchJob } from './watchJob.js';
15
+ import { formatSyncFailure, watchSourceSync } from './watchSourceSync.js';
16
+ function stringValue(values, name) {
17
+ const value = values[name];
18
+ return typeof value === 'string' ? value : undefined;
19
+ }
20
+ function record(value, name) {
21
+ if (typeof value !== 'object' || value === null || !(name in value)) return undefined;
22
+ return Object.entries(value).find(([key])=>key === name)?.[1];
23
+ }
24
+ function field(value, name) {
25
+ if (typeof value !== 'object' || value === null || !(name in value)) return undefined;
26
+ const found = Object.entries(value).find(([key])=>key === name)?.[1];
27
+ return typeof found === 'string' ? found : undefined;
28
+ }
29
+ function examples(operation) {
30
+ const args = operation.pathParams.filter((param)=>param.name !== 'organizationId').map((param)=>`<${param.name}>`).join(' ');
31
+ const invocation = `<%= config.bin %> <%= command.id %>${args ? ` ${args}` : ''}`;
32
+ return [
33
+ {
34
+ command: invocation,
35
+ description: operation.summary
36
+ },
37
+ {
38
+ command: `${invocation} --json`,
39
+ description: `${operation.summary}, as JSON`
40
+ }
41
+ ];
42
+ }
43
+ function getEntry(id) {
44
+ const entry = contextCommandTable.find((candidate)=>candidate.id === id);
45
+ if (!entry) throw new Error(`No context command "${id}" in the command table`);
46
+ return entry;
47
+ }
48
+ /**
49
+ * The command class for an entry of the command table, built from the
50
+ * operation the spec describes: its arguments and flags, the request, and
51
+ * output as JSON with `--json` or as a table or key-value lines otherwise.
52
+ * Hand-written commands extend it and override `send` or `render`.
53
+ */ export function contextCommand(id) {
54
+ const entry = getEntry(id);
55
+ const operations = contextOperations;
56
+ const operation = operations[entry.operationId];
57
+ if (!operation) throw new Error(`No operation "${entry.operationId}" in the generated operations`);
58
+ const debug = subdebug(id.replaceAll(' ', ':'));
59
+ const flags = operationFlags(operation, entry);
60
+ return class ContextOperationCommand extends SanityCommand {
61
+ static args = operationArgs(operation, entry);
62
+ static description = operation.description || operation.summary;
63
+ static enableJsonFlag = true;
64
+ static examples = examples(operation);
65
+ static flags = flags;
66
+ static summary = operation.summary;
67
+ static telemetry = {
68
+ // Generated flags have no aliases or chars, so each is redacted under its name alone
69
+ redactedFlags: redactedFlags(operation, entry).map((name)=>({
70
+ canonical: `--${name}`,
71
+ flags: [
72
+ `--${name}`
73
+ ]
74
+ }))
75
+ };
76
+ entry = entry;
77
+ operation = operation;
78
+ async confirmDeletion(args, values) {
79
+ if (values.yes) return;
80
+ if (this.isUnattended()) {
81
+ this.error('Deletion requires confirmation. Pass `--yes` to delete.', {
82
+ exit: exitCodes.USAGE_ERROR
83
+ });
84
+ }
85
+ const target = operation.pathParams.map((param)=>args[param.name]).findLast(Boolean);
86
+ const confirmed = await confirm({
87
+ default: false,
88
+ message: `${operation.summary}${typeof target === 'string' ? ` "${target}"` : ''}?`
89
+ });
90
+ if (!confirmed) {
91
+ this.log('Nothing deleted');
92
+ this.exit(exitCodes.USER_ABORT);
93
+ }
94
+ }
95
+ /** Fail the command with the API's error message */ fail(error) {
96
+ // A usage error or a cancelled prompt is not a failed request
97
+ if (error instanceof CLIError || error instanceof Error && error.name === 'ExitPromptError') {
98
+ throw error;
99
+ }
100
+ debug('Request failed', error);
101
+ const notFound = isHttpError(error) && error.statusCode === 404;
102
+ this.error(`${notFound ? 'Not found' : `${operation.summary} failed`}: ${getErrorMessage(error)}`, {
103
+ exit: exitCodes.RUNTIME_ERROR
104
+ });
105
+ }
106
+ async guard(args, body) {
107
+ const knowledgeBaseId = stringValue(args, 'knowledgeBaseId');
108
+ if (entry.guard !== 'knowledgeBaseBlueprint' || !knowledgeBaseId) return;
109
+ // A blueprint reconciles only some fields; changing the others is fine
110
+ const guarded = entry.guardFields;
111
+ if (guarded && !guarded.some((name)=>body?.[name] !== undefined)) return;
112
+ const ownership = await getKnowledgeBaseBlueprintOwnership(knowledgeBaseId);
113
+ if (!ownership.managed) return;
114
+ const manager = describeBlueprintManager(ownership.stackName);
115
+ this.error(operation.route.startsWith('DELETE ') ? `${manager} manages knowledge base "${knowledgeBaseId}". To delete it, deploy it with \`lifecycle: {deletionPolicy: 'allow'}\` in the blueprint, then remove it from the blueprint and deploy again.` : `${manager} manages the ${(guarded ?? []).join(' and ')} of knowledge base "${knowledgeBaseId}", so the next deploy would undo this change. Change them in the blueprint and run \`sanity blueprints deploy\` instead.`, {
116
+ exit: exitCodes.USAGE_ERROR
117
+ });
118
+ }
119
+ /** Print the result: JSON with `--json`, otherwise a table or key-value lines */ render(result) {
120
+ if (this.flags.json) {
121
+ this.logJson(result ?? {});
122
+ return;
123
+ }
124
+ this.log(renderOperationResult(result, {
125
+ columns: entry.columns,
126
+ summary: operation.summary
127
+ }));
128
+ }
129
+ async run() {
130
+ const values = {
131
+ ...this.flags
132
+ };
133
+ const args = {
134
+ ...this.args
135
+ };
136
+ const organizationId = needsOrganization(operation) ? await resolveOrganizationId({
137
+ configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,
138
+ flagOrganizationId: stringValue(values, 'organization'),
139
+ unattended: this.isUnattended()
140
+ }) : undefined;
141
+ const promptsSkipped = entry.promptUnless !== undefined && values[flagName({
142
+ name: entry.promptUnless
143
+ })] === true;
144
+ for (const name of promptsSkipped ? [] : entry.prompt ?? []){
145
+ const flag = flagName({
146
+ name
147
+ });
148
+ if (values[flag] === undefined && !this.isUnattended()) {
149
+ values[flag] = await promptForText(`${humanize(name)}:`);
150
+ }
151
+ }
152
+ let request;
153
+ try {
154
+ request = buildOperationRequest(operation, entry, {
155
+ args,
156
+ flags: values,
157
+ organizationId
158
+ });
159
+ } catch (error) {
160
+ this.error(getErrorMessage(error), {
161
+ exit: exitCodes.USAGE_ERROR
162
+ });
163
+ }
164
+ await this.guard(args, request.body);
165
+ if (operation.route.startsWith('DELETE ')) await this.confirmDeletion(args, values);
166
+ const knowledgeBaseId = stringValue(args, 'knowledgeBaseId');
167
+ const watchedSource = stringValue(args, 'sourceId');
168
+ const previousSyncId = entry.watch === 'sync' && values.watch && knowledgeBaseId && watchedSource ? await getSource(knowledgeBaseId, watchedSource).then((source)=>source.latestSync?.id ?? null, (error)=>this.fail(error)) : null;
169
+ let result;
170
+ try {
171
+ result = await this.send(request, values);
172
+ } catch (error) {
173
+ this.fail(error);
174
+ }
175
+ if (!values.watch || !knowledgeBaseId) {
176
+ this.render(result);
177
+ return;
178
+ }
179
+ if (entry.watch === 'sync') {
180
+ const sourceId = watchedSource ?? field(result, 'id');
181
+ const syncId = field(record(result, 'latestSync'), 'id');
182
+ const jobId = field(result, 'jobId');
183
+ if (!sourceId) {
184
+ this.render(result);
185
+ return;
186
+ }
187
+ if (!this.flags.json) this.render(result);
188
+ await this.watchSync(knowledgeBaseId, sourceId, syncId ? {
189
+ syncId
190
+ } : jobId ? {
191
+ jobId
192
+ } : {
193
+ previousSyncId
194
+ });
195
+ return;
196
+ }
197
+ const jobId = field(result, 'jobId') ?? stringValue(args, 'jobId');
198
+ if (!jobId) {
199
+ this.render(result);
200
+ return;
201
+ }
202
+ if (!this.flags.json) this.render(result);
203
+ await this.watchJob(knowledgeBaseId, jobId);
204
+ }
205
+ /** Send the request; hand-written commands override this to upload a file or download bytes */ async send(request, _flags) {
206
+ return operation.paginated ? requestAllPages(operation.route, request, operation.pageSize) : requestContext(operation.route, request);
207
+ }
208
+ async watchJob(knowledgeBaseId, jobId) {
209
+ let job;
210
+ try {
211
+ job = await watchJob(knowledgeBaseId, jobId, {
212
+ label: `Waiting for job ${jobId}`
213
+ });
214
+ } catch (error) {
215
+ this.fail(error);
216
+ }
217
+ if (job.status !== 'succeeded') {
218
+ if (this.flags.json) throw new JsonOutputError(formatJobFailure('Job', job), job, exitCodes.RUNTIME_ERROR);
219
+ this.error(formatJobFailure('Job', job), {
220
+ exit: exitCodes.RUNTIME_ERROR
221
+ });
222
+ }
223
+ if (this.flags.json) this.logJson(job);
224
+ }
225
+ async watchSync(knowledgeBaseId, sourceId, target) {
226
+ let sync;
227
+ try {
228
+ sync = await watchSourceSync(knowledgeBaseId, sourceId, target);
229
+ } catch (error) {
230
+ this.fail(error);
231
+ }
232
+ if (sync.status === 'completed') {
233
+ if (this.flags.json) this.logJson(sync);
234
+ return;
235
+ }
236
+ // A held sync waits on a decision, so a script must not read it as done
237
+ const message = sync.status === 'held' ? heldSyncHint(knowledgeBaseId, sync) ?? 'Sync held for confirmation' : formatSyncFailure(sync);
238
+ if (this.flags.json) throw new JsonOutputError(message, sync, exitCodes.RUNTIME_ERROR);
239
+ this.error(message, {
240
+ exit: exitCodes.RUNTIME_ERROR
241
+ });
242
+ }
243
+ };
244
+ }
245
+
246
+ //# sourceMappingURL=contextCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/context/contextCommand.ts"],"sourcesContent":["import {type Command} from '@oclif/core'\nimport {CLIError} from '@oclif/core/errors'\nimport {exitCodes, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {getErrorMessage, JsonOutputError} from '@sanity/cli-core/errors'\nimport {confirm} from '@sanity/cli-core/ux'\nimport {isHttpError} from '@sanity/client'\n\nimport {contextOperations} from '../../generated/contextOperations.js'\nimport {promptForText} from '../../prompts/promptForText.js'\nimport {\n describeBlueprintManager,\n getKnowledgeBaseBlueprintOwnership,\n getSource,\n requestAllPages,\n requestContext,\n} from '../../services/context.js'\nimport {type CommandTelemetry} from '../../util/telemetry/commandTelemetry.js'\nimport {\n type ContextCommandEntry,\n type ContextCommandId,\n contextCommandTable,\n} from './commandTable.js'\nimport {\n buildOperationRequest,\n flagName,\n humanize,\n needsOrganization,\n operationArgs,\n operationFlags,\n type OperationRequest,\n redactedFlags,\n} from './operationInput.js'\nimport {type ContextOperation} from './operationTypes.js'\nimport {renderOperationResult} from './renderOperationResult.js'\nimport {resolveOrganizationId} from './resolveOrganizationId.js'\nimport {heldSyncHint} from './syncOutput.js'\nimport {type SyncTarget} from './waitForSourceSync.js'\nimport {formatJobFailure, watchJob} from './watchJob.js'\nimport {formatSyncFailure, watchSourceSync} from './watchSourceSync.js'\n\ntype Values = Record<string, unknown>\n\nfunction stringValue(values: Values, name: string): string | undefined {\n const value = values[name]\n return typeof value === 'string' ? value : undefined\n}\n\nfunction record(value: unknown, name: string): unknown {\n if (typeof value !== 'object' || value === null || !(name in value)) return undefined\n return Object.entries(value).find(([key]) => key === name)?.[1]\n}\n\nfunction field(value: unknown, name: string): string | undefined {\n if (typeof value !== 'object' || value === null || !(name in value)) return undefined\n const found: unknown = Object.entries(value).find(([key]) => key === name)?.[1]\n return typeof found === 'string' ? found : undefined\n}\n\nfunction examples(operation: ContextOperation): Command.Example[] {\n const args = operation.pathParams\n .filter((param) => param.name !== 'organizationId')\n .map((param) => `<${param.name}>`)\n .join(' ')\n const invocation = `<%= config.bin %> <%= command.id %>${args ? ` ${args}` : ''}`\n return [\n {command: invocation, description: operation.summary},\n {command: `${invocation} --json`, description: `${operation.summary}, as JSON`},\n ]\n}\n\nfunction getEntry(id: ContextCommandId): ContextCommandEntry {\n const entry = contextCommandTable.find((candidate) => candidate.id === id)\n if (!entry) throw new Error(`No context command \"${id}\" in the command table`)\n return entry\n}\n\n/**\n * The command class for an entry of the command table, built from the\n * operation the spec describes: its arguments and flags, the request, and\n * output as JSON with `--json` or as a table or key-value lines otherwise.\n * Hand-written commands extend it and override `send` or `render`.\n */\nexport function contextCommand(id: ContextCommandId) {\n const entry = getEntry(id)\n const operations: Readonly<Record<string, ContextOperation>> = contextOperations\n const operation = operations[entry.operationId]\n if (!operation) throw new Error(`No operation \"${entry.operationId}\" in the generated operations`)\n const debug = subdebug(id.replaceAll(' ', ':'))\n const flags = operationFlags(operation, entry)\n\n return class ContextOperationCommand extends SanityCommand<typeof ContextOperationCommand> {\n static override args = operationArgs(operation, entry)\n static override description = operation.description || operation.summary\n static override enableJsonFlag = true\n static override examples = examples(operation)\n static override flags = flags\n static override summary = operation.summary\n static telemetry: CommandTelemetry = {\n // Generated flags have no aliases or chars, so each is redacted under its name alone\n redactedFlags: redactedFlags(operation, entry).map((name) => ({\n canonical: `--${name}`,\n flags: [`--${name}`],\n })),\n }\n\n readonly entry = entry\n readonly operation = operation\n\n public async confirmDeletion(args: Values, values: Values): Promise<void> {\n if (values.yes) return\n if (this.isUnattended()) {\n this.error('Deletion requires confirmation. Pass `--yes` to delete.', {\n exit: exitCodes.USAGE_ERROR,\n })\n }\n const target = operation.pathParams.map((param) => args[param.name]).findLast(Boolean)\n const confirmed = await confirm({\n default: false,\n message: `${operation.summary}${typeof target === 'string' ? ` \"${target}\"` : ''}?`,\n })\n if (!confirmed) {\n this.log('Nothing deleted')\n this.exit(exitCodes.USER_ABORT)\n }\n }\n\n /** Fail the command with the API's error message */\n public fail(error: unknown): never {\n // A usage error or a cancelled prompt is not a failed request\n if (\n error instanceof CLIError ||\n (error instanceof Error && error.name === 'ExitPromptError')\n ) {\n throw error\n }\n debug('Request failed', error)\n const notFound = isHttpError(error) && error.statusCode === 404\n this.error(\n `${notFound ? 'Not found' : `${operation.summary} failed`}: ${getErrorMessage(error)}`,\n {\n exit: exitCodes.RUNTIME_ERROR,\n },\n )\n }\n\n public async guard(args: Values, body: Values | undefined): Promise<void> {\n const knowledgeBaseId = stringValue(args, 'knowledgeBaseId')\n if (entry.guard !== 'knowledgeBaseBlueprint' || !knowledgeBaseId) return\n // A blueprint reconciles only some fields; changing the others is fine\n const guarded = entry.guardFields\n if (guarded && !guarded.some((name) => body?.[name] !== undefined)) return\n const ownership = await getKnowledgeBaseBlueprintOwnership(knowledgeBaseId)\n if (!ownership.managed) return\n const manager = describeBlueprintManager(ownership.stackName)\n this.error(\n operation.route.startsWith('DELETE ')\n ? `${manager} manages knowledge base \"${knowledgeBaseId}\". To delete it, deploy it with \\`lifecycle: {deletionPolicy: 'allow'}\\` in the blueprint, then remove it from the blueprint and deploy again.`\n : `${manager} manages the ${(guarded ?? []).join(' and ')} of knowledge base \"${knowledgeBaseId}\", so the next deploy would undo this change. Change them in the blueprint and run \\`sanity blueprints deploy\\` instead.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n }\n\n /** Print the result: JSON with `--json`, otherwise a table or key-value lines */\n public render(result: unknown): void {\n if (this.flags.json) {\n this.logJson(result ?? {})\n return\n }\n this.log(renderOperationResult(result, {columns: entry.columns, summary: operation.summary}))\n }\n\n public async run(): Promise<void> {\n const values: Values = {...this.flags}\n const args: Values = {...this.args}\n const organizationId = needsOrganization(operation)\n ? await resolveOrganizationId({\n configuredOrganizationId: (await this.tryGetCliConfig()).app?.organizationId,\n flagOrganizationId: stringValue(values, 'organization'),\n unattended: this.isUnattended(),\n })\n : undefined\n\n const promptsSkipped =\n entry.promptUnless !== undefined && values[flagName({name: entry.promptUnless})] === true\n for (const name of promptsSkipped ? [] : (entry.prompt ?? [])) {\n const flag = flagName({name})\n if (values[flag] === undefined && !this.isUnattended()) {\n values[flag] = await promptForText(`${humanize(name)}:`)\n }\n }\n\n let request: OperationRequest\n try {\n request = buildOperationRequest(operation, entry, {args, flags: values, organizationId})\n } catch (error) {\n this.error(getErrorMessage(error), {exit: exitCodes.USAGE_ERROR})\n }\n await this.guard(args, request.body)\n if (operation.route.startsWith('DELETE ')) await this.confirmDeletion(args, values)\n\n const knowledgeBaseId = stringValue(args, 'knowledgeBaseId')\n const watchedSource = stringValue(args, 'sourceId')\n const previousSyncId =\n entry.watch === 'sync' && values.watch && knowledgeBaseId && watchedSource\n ? await getSource(knowledgeBaseId, watchedSource).then(\n (source) => source.latestSync?.id ?? null,\n (error: unknown) => this.fail(error),\n )\n : null\n\n let result: unknown\n try {\n result = await this.send(request, values)\n } catch (error) {\n this.fail(error)\n }\n\n if (!values.watch || !knowledgeBaseId) {\n this.render(result)\n return\n }\n if (entry.watch === 'sync') {\n const sourceId = watchedSource ?? field(result, 'id')\n const syncId = field(record(result, 'latestSync'), 'id')\n const jobId = field(result, 'jobId')\n if (!sourceId) {\n this.render(result)\n return\n }\n if (!this.flags.json) this.render(result)\n await this.watchSync(\n knowledgeBaseId,\n sourceId,\n syncId ? {syncId} : jobId ? {jobId} : {previousSyncId},\n )\n return\n }\n const jobId = field(result, 'jobId') ?? stringValue(args, 'jobId')\n if (!jobId) {\n this.render(result)\n return\n }\n if (!this.flags.json) this.render(result)\n await this.watchJob(knowledgeBaseId, jobId)\n }\n\n /** Send the request; hand-written commands override this to upload a file or download bytes */\n public async send(request: OperationRequest, _flags: Values): Promise<unknown> {\n return operation.paginated\n ? requestAllPages(operation.route, request, operation.pageSize)\n : requestContext(operation.route, request)\n }\n\n public async watchJob(knowledgeBaseId: string, jobId: string): Promise<void> {\n let job\n try {\n job = await watchJob(knowledgeBaseId, jobId, {label: `Waiting for job ${jobId}`})\n } catch (error) {\n this.fail(error)\n }\n if (job.status !== 'succeeded') {\n if (this.flags.json)\n throw new JsonOutputError(formatJobFailure('Job', job), job, exitCodes.RUNTIME_ERROR)\n this.error(formatJobFailure('Job', job), {exit: exitCodes.RUNTIME_ERROR})\n }\n if (this.flags.json) this.logJson(job)\n }\n\n public async watchSync(\n knowledgeBaseId: string,\n sourceId: string,\n target: SyncTarget,\n ): Promise<void> {\n let sync\n try {\n sync = await watchSourceSync(knowledgeBaseId, sourceId, target)\n } catch (error) {\n this.fail(error)\n }\n if (sync.status === 'completed') {\n if (this.flags.json) this.logJson(sync)\n return\n }\n // A held sync waits on a decision, so a script must not read it as done\n const message =\n sync.status === 'held'\n ? (heldSyncHint(knowledgeBaseId, sync) ?? 'Sync held for confirmation')\n : formatSyncFailure(sync)\n if (this.flags.json) throw new JsonOutputError(message, sync, exitCodes.RUNTIME_ERROR)\n this.error(message, {exit: exitCodes.RUNTIME_ERROR})\n }\n }\n}\n"],"names":["CLIError","exitCodes","SanityCommand","subdebug","getErrorMessage","JsonOutputError","confirm","isHttpError","contextOperations","promptForText","describeBlueprintManager","getKnowledgeBaseBlueprintOwnership","getSource","requestAllPages","requestContext","contextCommandTable","buildOperationRequest","flagName","humanize","needsOrganization","operationArgs","operationFlags","redactedFlags","renderOperationResult","resolveOrganizationId","heldSyncHint","formatJobFailure","watchJob","formatSyncFailure","watchSourceSync","stringValue","values","name","value","undefined","record","Object","entries","find","key","field","found","examples","operation","args","pathParams","filter","param","map","join","invocation","command","description","summary","getEntry","id","entry","candidate","Error","contextCommand","operations","operationId","debug","replaceAll","flags","ContextOperationCommand","enableJsonFlag","telemetry","canonical","confirmDeletion","yes","isUnattended","error","exit","USAGE_ERROR","target","findLast","Boolean","confirmed","default","message","log","USER_ABORT","fail","notFound","statusCode","RUNTIME_ERROR","guard","body","knowledgeBaseId","guarded","guardFields","some","ownership","managed","manager","stackName","route","startsWith","render","result","json","logJson","columns","run","organizationId","configuredOrganizationId","tryGetCliConfig","app","flagOrganizationId","unattended","promptsSkipped","promptUnless","prompt","flag","request","watchedSource","previousSyncId","watch","then","source","latestSync","send","sourceId","syncId","jobId","watchSync","_flags","paginated","pageSize","job","label","status","sync"],"mappings":"AACA,SAAQA,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,SAAS,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACnE,SAAQC,eAAe,EAAEC,eAAe,QAAO,0BAAyB;AACxE,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QA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MxE,UAAUqF,aAAa;YAAA;QACpD;IACF;AACF"}
@@ -0,0 +1,18 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname, join } from 'node:path';
4
+ /**
5
+ * The Context API's OpenAPI spec as vendored by the installed `@sanity/client`,
6
+ * the same spec its `client.context.request` types come from
7
+ */ export function readContextSpec() {
8
+ const clientRoot = dirname(createRequire(import.meta.url).resolve('@sanity/client/package.json'));
9
+ return JSON.parse(readFileSync(join(clientRoot, 'src/context/openapi.json'), 'utf8'));
10
+ }
11
+ /** Where a command's file lives, relative to the package root: `context sources list` → `src/commands/context/sources/list.ts` */ export function commandFilePath(commandId) {
12
+ return `src/commands/${commandId.split(' ').join('/')}.ts`;
13
+ }
14
+ /** The exported class name of an operation's command: `listSources` → `ListSourcesCommand` */ export function commandClassName(operationId) {
15
+ return `${operationId[0].toUpperCase()}${operationId.slice(1)}Command`;
16
+ }
17
+
18
+ //# sourceMappingURL=contextSpec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/context/contextSpec.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport {createRequire} from 'node:module'\nimport {dirname, join} from 'node:path'\n\nimport {type ContextOpenApiDocument} from './distillContextOperations.js'\n\n/**\n * The Context API's OpenAPI spec as vendored by the installed `@sanity/client`,\n * the same spec its `client.context.request` types come from\n */\nexport function readContextSpec(): ContextOpenApiDocument {\n const clientRoot = dirname(createRequire(import.meta.url).resolve('@sanity/client/package.json'))\n return JSON.parse(readFileSync(join(clientRoot, 'src/context/openapi.json'), 'utf8'))\n}\n\n/** Where a command's file lives, relative to the package root: `context sources list` → `src/commands/context/sources/list.ts` */\nexport function commandFilePath(commandId: string): string {\n return `src/commands/${commandId.split(' ').join('/')}.ts`\n}\n\n/** The exported class name of an operation's command: `listSources` → `ListSourcesCommand` */\nexport function commandClassName(operationId: string): string {\n return `${operationId[0].toUpperCase()}${operationId.slice(1)}Command`\n}\n"],"names":["readFileSync","createRequire","dirname","join","readContextSpec","clientRoot","url","resolve","JSON","parse","commandFilePath","commandId","split","commandClassName","operationId","toUpperCase","slice"],"mappings":"AAAA,SAAQA,YAAY,QAAO,UAAS;AACpC,SAAQC,aAAa,QAAO,cAAa;AACzC,SAAQC,OAAO,EAAEC,IAAI,QAAO,YAAW;AAIvC;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,aAAaH,QAAQD,cAAc,YAAYK,GAAG,EAAEC,OAAO,CAAC;IAClE,OAAOC,KAAKC,KAAK,CAACT,aAAaG,KAAKE,YAAY,6BAA6B;AAC/E;AAEA,gIAAgI,GAChI,OAAO,SAASK,gBAAgBC,SAAiB;IAC/C,OAAO,CAAC,aAAa,EAAEA,UAAUC,KAAK,CAAC,KAAKT,IAAI,CAAC,KAAK,GAAG,CAAC;AAC5D;AAEA,4FAA4F,GAC5F,OAAO,SAASU,iBAAiBC,WAAmB;IAClD,OAAO,GAAGA,WAAW,CAAC,EAAE,CAACC,WAAW,KAAKD,YAAYE,KAAK,CAAC,GAAG,OAAO,CAAC;AACxE"}