@kubb/studio 5.13.0 → 5.14.0

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,70 +1,22 @@
1
1
  import { ExtensionKind, ExtensionManifest } from "@kubb/core";
2
2
  import { InputNode } from "@kubb/ast";
3
- //#region src/protocol.d.ts
4
- /**
5
- * JSON-serializable Kubb config exchanged over RPC. A live `kubb/kit` config holds
6
- * functions and class instances that cannot survive JSON, so both sides pass this flattened shape
7
- * and rebuild the real config from it.
8
- */
9
- type JSONKubbConfig = {
10
- /**
11
- * Plugins with their serialized options. `name` is the package name (e.g. `@kubb/plugin-ts`)
12
- * and `options` is an opaque blob the agent forwards unchanged to the plugin factory. An entry
13
- * with `disabled: true` is dropped even when the disk config's `plugins` array still lists it.
14
- */
15
- plugins?: Array<{
16
- name: string;
17
- options?: object;
18
- disabled?: boolean;
19
- }>;
20
- /**
21
- * Raw OpenAPI / Swagger spec content (YAML or JSON string), never a file path.
22
- * Required by a 'sandbox' agent, which has no disk config of its own and refuses anything else.
23
- * A 'managed' agent also takes a URL or a `git+<repo>#<ref>:<path>` input, and falls back to its disk config without one.
24
- * Any other agent always reads its spec from disk, so this is ignored with a `kubb:warn`.
25
- */
26
- input?: string;
27
- /**
28
- * Adapter option overrides sent from Studio UI. Merged into the disk config's adapter options
29
- * and re-applied through the same adapter factory, since an adapter instance's functions
30
- * (`parse`, `getImports`, ...) can't survive JSON serialization over the WebSocket.
31
- */
32
- adapter?: object;
33
- /**
34
- * Parser option overrides from Studio, matched to the disk config's parsers by `name` and
35
- * re-applied through each parser's factory, the same way `adapter` is.
36
- */
37
- parsers?: Array<{
38
- name: string;
39
- options?: object;
40
- }>;
41
- /** Root `output` overrides for `barrel`, `format`, `lint`, `clean`, and `defaultBanner`. Other members are ignored. */
42
- output?: object;
43
- /**
44
- * Which `defineConfig(...)` entry to generate from. Omitted runs the first one.
45
- */
46
- config?: ConfigRef;
47
- };
48
- /**
49
- * Which `defineConfig(...)` entry an edit targets, for a config file that exports an array.
50
- *
51
- * A number selects by position, a string matches the entry's `name`. Omitted targets the only
52
- * entry, or the first one when the file exports an array.
53
- */
3
+ //#region ../../internals/shared/src/configFile/types.d.ts
4
+ /** Which `defineConfig(...)` entry an edit targets: its index or `name`, the first entry when omitted. */
54
5
  type ConfigRef = string | number;
55
- /**
56
- * A value the agent can read out of a plugin option in `kubb.config.ts` and round-trip through JSON.
57
- */
6
+ /** A literal option value that survives a JSON round trip. */
58
7
  type OptionValue = string | number | boolean | null | Array<OptionValue> | {
59
8
  [key: string]: OptionValue;
60
9
  };
61
- /**
62
- * The kinds of {@link ConfigEdit}, one per `operation`.
63
- */
10
+ declare const extensionKinds: {
11
+ readonly plugin: 'plugin';
12
+ readonly adapter: 'adapter';
13
+ readonly parser: 'parser';
14
+ };
64
15
  declare const ConfigEditOperation: {
65
- readonly SET: 'set';
66
- readonly REMOVE: 'remove';
16
+ readonly SET_OPTION: 'set-option';
17
+ readonly REMOVE_OPTION: 'remove-option';
67
18
  readonly ADD_PLUGIN: 'add-plugin';
19
+ readonly REMOVE_EXTENSION: 'remove-extension';
68
20
  readonly DISABLE_PLUGIN: 'disable-plugin';
69
21
  readonly ENABLE_PLUGIN: 'enable-plugin';
70
22
  readonly SET_INPUT: 'set-input';
@@ -73,177 +25,170 @@ declare const ConfigEditOperation: {
73
25
  };
74
26
  type ConfigEditOperation = (typeof ConfigEditOperation)[keyof typeof ConfigEditOperation];
75
27
  /**
76
- * One change to a plugin's options in the user's `kubb.config.ts`.
77
- *
78
- * `plugin` is the package name (`@kubb/plugin-ts`), the same identity used in {@link JSONKubbConfig}.
79
- * The agent applies these to the file with an AST patch, so only the targeted values are rewritten.
80
- *
81
- * Declared here rather than in `configFile.ts` because this is the wire contract, and the patcher
82
- * imports it from here. Type-only, so nothing pulls `magicast` into this entry point.
28
+ * One change to `kubb.config.ts`. `plugin` is the package name, and `kind` picks the `plugins` entry
29
+ * (default), the `adapter`, or a `parsers` entry. `path` walks nested option objects.
83
30
  */
84
- type ConfigEdit =
85
- /**
86
- * Write a literal option value. `path` walks nested objects, so `['enum', 'type']` targets
87
- * `pluginTs({ enum: { type } })`. `kind` names which factory call `plugin` is: one in `plugins`
88
- * when left out, the config's `adapter`, or one in `parsers`.
89
- */
90
- {
91
- operation: typeof ConfigEditOperation.SET;
31
+ type ConfigEdit = {
32
+ operation: typeof ConfigEditOperation.SET_OPTION;
92
33
  config?: ConfigRef;
93
34
  kind?: ExtensionKind;
94
35
  plugin: string;
95
36
  path: Array<string>;
96
37
  value: unknown;
97
- } |
98
- /**
99
- * Drop an option so the extension falls back to its default. `kind` as for `set`.
100
- */
101
- {
102
- operation: typeof ConfigEditOperation.REMOVE;
38
+ } | {
39
+ operation: typeof ConfigEditOperation.REMOVE_OPTION;
103
40
  config?: ConfigRef;
104
41
  kind?: ExtensionKind;
105
42
  plugin: string;
106
43
  path: Array<string>;
107
44
  } |
108
- /**
109
- * Add a plugin factory call and its import to the `plugins` array.
110
- */
45
+ /** With `kind: 'parser'`, adds to `parsers`. A config without `parsers` gets the defaults written next to it, so they keep running. */
111
46
  {
112
47
  operation: typeof ConfigEditOperation.ADD_PLUGIN;
113
48
  config?: ConfigRef;
49
+ kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser;
114
50
  plugin: string;
115
51
  options?: Record<string, unknown>;
116
52
  } |
117
- /**
118
- * Comment the plugin call out, keeping its options in the file so enabling it again restores them.
119
- */
53
+ /** Deletes every call of a plugin, or a parser with `kind: 'parser'`, a disabled block included, and the imports nothing else uses. */
120
54
  {
55
+ operation: typeof ConfigEditOperation.REMOVE_EXTENSION;
56
+ config?: ConfigRef;
57
+ kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser;
58
+ plugin: string;
59
+ } | {
121
60
  operation: typeof ConfigEditOperation.DISABLE_PLUGIN;
122
61
  config?: ConfigRef;
123
62
  plugin: string;
124
- } |
125
- /**
126
- * Uncomment a plugin call a previous `disable-plugin` commented out.
127
- */
128
- {
63
+ } | {
129
64
  operation: typeof ConfigEditOperation.ENABLE_PLUGIN;
130
65
  config?: ConfigRef;
131
66
  plugin: string;
132
- } |
133
- /**
134
- * Point the config's `input` at a spec. The agent writes a document to `openapi.yaml` (or
135
- * `openapi.json`, and `openapi-<entry>` for a later entry) in its project and points `input` there.
136
- * Refused without `allowSaveInput`, and a managed agent takes only a document, a URL, or a `git+` file.
137
- */
138
- {
67
+ } | {
139
68
  operation: typeof ConfigEditOperation.SET_INPUT;
140
69
  config?: ConfigRef;
141
70
  input: string;
142
- } |
143
- /** Write a literal inside the root `output` object, for the members `JSONKubbConfig.output` takes. */
144
- {
71
+ } | {
145
72
  operation: typeof ConfigEditOperation.SET_OUTPUT;
146
73
  config?: ConfigRef;
147
74
  path: Array<string>;
148
75
  value: unknown;
149
- } |
150
- /** Drop a member of the root `output` object that `set-output` may write. */
151
- {
76
+ } | {
152
77
  operation: typeof ConfigEditOperation.REMOVE_OUTPUT;
153
78
  config?: ConfigRef;
154
79
  path: Array<string>;
155
80
  };
156
- /** The top-level keys of an object in the config file, as {@link PluginView.options} describes. */
81
+ /** Option keys, each with whether Studio may write it. `locked` lists the code paths inside a partly literal object. */
157
82
  type OptionsView = Record<string, {
158
83
  literal: boolean;
159
84
  value?: OptionValue;
160
85
  locked?: Array<Array<string>>;
161
86
  }>;
162
- /**
163
- * A factory call the agent found in a `defineConfig(...)`: a plugin in `plugins`, the `adapter`, or
164
- * a parser in `parsers`.
165
- */
87
+ /** A factory call in `plugins`, `adapter`, or `parsers`. `importName` is the local name, alias included. */
166
88
  type PluginView = {
167
- /**
168
- * Local identifier of the factory in the file, e.g. `pluginTs`. This is the alias when the plugin
169
- * was imported under one.
170
- */
171
89
  importName: string;
172
- /**
173
- * Module the factory is imported from, e.g. `@kubb/plugin-ts`.
174
- */
175
90
  packageName: string;
176
- /**
177
- * Top-level option keys, each flagged with whether the agent may write it and, when it can, the
178
- * value found in the file. An option marked `literal: false` holds a function or a reference the
179
- * agent will not overwrite, so Studio shows the control disabled rather than hiding it, and
180
- * `value` is absent since there is nothing safe to display as the current value.
181
- *
182
- * An object option that holds code in only some members, such as
183
- * `output: { path: './gen', banner: () => '' }`, also carries `value` with its literal members
184
- * and `locked` with the paths of the members that are code, relative to the option
185
- * (`[['banner']]`). A `set` at any deeper path outside `locked` succeeds, so Studio can edit
186
- * `output.path` there.
187
- */
188
91
  options: OptionsView;
189
- /**
190
- * Set when the plugin call is commented out in the file. Its options stay on disk but are not
191
- * readable, so `options` is empty until it is enabled again.
192
- */
92
+ /** The call is commented out by `disable-plugin`. */
193
93
  disabled?: true;
194
94
  };
195
- /**
196
- * One `defineConfig(...)` entry. A config file that exports a single object has exactly one.
197
- */
198
95
  type ConfigView = {
199
- /**
200
- * The entry's `name`, when it sets one. Studio labels the config picker with it.
201
- */
202
96
  name?: string;
203
- /**
204
- * Each plugin call in the entry, with its top-level option keys.
205
- */
206
97
  plugins: Array<PluginView>;
207
- /**
208
- * The `adapter` call, when the entry sets one through an imported factory.
209
- */
210
98
  adapter?: PluginView;
211
- /**
212
- * The parser calls in `parsers`, when the entry lists any through imported factories.
213
- */
214
99
  parsers?: Array<PluginView>;
215
- /** The root `output` members Studio may set. Absent when `output` is not an object literal. */
100
+ /** The root `output` members Studio may set, absent when `output` is not an object literal. */
216
101
  output?: OptionsView;
217
102
  };
218
- /**
219
- * What the agent found in the user's config file, so Studio knows which controls it may offer.
220
- * Absent when the agent could not read the file at all.
221
- */
103
+ /** The config file as Studio may edit it, or why it cannot. */
222
104
  type ConfigFileView = {
223
105
  managed: true;
224
- /**
225
- * One entry per config the file exports, in source order. Every {@link ConfigEdit} names
226
- * which of these it targets through its `config` field.
227
- */
228
106
  configs: Array<ConfigView>;
229
107
  } | {
230
108
  managed: false;
231
- /**
232
- * Why the file is outside what the agent edits, for example a default export that is not a
233
- * `defineConfig(...)` call. Studio shows this and offers no property-level controls.
234
- */
235
109
  reason: string;
236
110
  };
237
- /**
238
- * Outcome of a single {@link ConfigEdit}, returned in a {@link SaveResult}.
239
- */
240
111
  type ConfigEditOutcome = {
241
112
  edit: ConfigEdit;
242
113
  applied: boolean;
114
+ reason?: string;
115
+ };
116
+ type ExtensionEntry = {
117
+ package: string;
118
+ version: string;
119
+ manifest: ExtensionManifest;
120
+ /** Ships with `kubb` at its version, so updating `kubb` updates it and `kubb update` cannot. */
121
+ bundled?: true;
122
+ };
123
+ /** Installed extensions by package name, the only ones Studio may import besides `@kubb/plugin-*`. */
124
+ type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>;
125
+ //#endregion
126
+ //#region ../../internals/shared/src/configFile/configFile.d.ts
127
+ /** Applies edits in place, touching only the text each targets. A refused edit is reported and the rest still run. */
128
+ declare function editConfig({ source, edits, extensions }: {
129
+ source: string;
130
+ edits: Array<ConfigEdit>;
131
+ extensions?: InstalledExtensions;
132
+ }): {
133
+ source: string;
134
+ outcomes: Array<ConfigEditOutcome>;
135
+ changed: boolean;
136
+ };
137
+ /** Applies `edits` to `filePath`, writing only when something changed. */
138
+ declare function editConfigFile({ filePath, edits, extensions }: {
139
+ filePath: string;
140
+ edits: Array<ConfigEdit>;
141
+ extensions?: InstalledExtensions;
142
+ }): Promise<{
143
+ source: string;
144
+ outcomes: Array<ConfigEditOutcome>;
145
+ changed: boolean;
146
+ }>;
147
+ //#endregion
148
+ //#region src/protocol.d.ts
149
+ /**
150
+ * JSON-serializable Kubb config exchanged over RPC. A live `kubb/kit` config holds
151
+ * functions and class instances that cannot survive JSON, so both sides pass this flattened shape
152
+ * and rebuild the real config from it.
153
+ */
154
+ type JSONKubbConfig = {
243
155
  /**
244
- * Why the edit was refused, absent when it was applied.
156
+ * Plugins with their serialized options. `name` is the package name (e.g. `@kubb/plugin-ts`)
157
+ * and `options` is an opaque blob the agent forwards unchanged to the plugin factory. An entry
158
+ * with `disabled: true` is dropped even when the disk config's `plugins` array still lists it.
245
159
  */
246
- reason?: string;
160
+ plugins?: Array<{
161
+ name: string;
162
+ options?: object;
163
+ disabled?: boolean;
164
+ }>;
165
+ /**
166
+ * Raw OpenAPI / Swagger spec content (YAML or JSON string), never a file path.
167
+ * Required by a 'sandbox' agent, which has no disk config of its own and refuses anything else.
168
+ * A 'managed' agent also takes a URL or a `git+<repo>#<ref>:<path>` input, and falls back to its disk config without one.
169
+ * Any other agent always reads its spec from disk, so this is ignored with a `kubb:warn`.
170
+ */
171
+ input?: string;
172
+ /**
173
+ * Adapter option overrides sent from Studio UI. Merged into the disk config's adapter options
174
+ * and re-applied through the same adapter factory, since an adapter instance's functions
175
+ * (`parse`, `getImports`, ...) can't survive JSON serialization over the WebSocket.
176
+ */
177
+ adapter?: object;
178
+ /**
179
+ * Parser option overrides from Studio, matched to the disk config's parsers by `name` and
180
+ * re-applied through each parser's factory, the same way `adapter` is.
181
+ */
182
+ parsers?: Array<{
183
+ name: string;
184
+ options?: object;
185
+ }>;
186
+ /** Root `output` overrides for `barrel`, `format`, `lint`, `clean`, and `defaultBanner`. Other members are ignored. */
187
+ output?: object;
188
+ /**
189
+ * Which `defineConfig(...)` entry to generate from. Omitted runs the first one.
190
+ */
191
+ config?: ConfigRef;
247
192
  };
248
193
  /**
249
194
  * The public, JSON-safe subset of Kubb lifecycle hooks. The core registry remains extensible;
@@ -455,6 +400,16 @@ type UpdateExtensionsResult = {
455
400
  updated: boolean;
456
401
  reason?: string;
457
402
  };
403
+ /** Asks the agent to run `kubb remove <id> --yes`. `requestedBy` as for {@link GenerateInput}. */
404
+ type RemoveExtensionInput = {
405
+ id: string;
406
+ requestedBy?: string;
407
+ };
408
+ /** `removed` is false when the agent refused or `kubb remove` failed, with `reason` saying why. */
409
+ type RemoveExtensionResult = {
410
+ removed: boolean;
411
+ reason?: string;
412
+ };
458
413
  /**
459
414
  * Reads an immutable output set kept on disk, from a generation or the initial connection.
460
415
  */
@@ -613,6 +568,8 @@ type AgentApi = {
613
568
  installExtension: (input: InstallExtensionInput) => Promise<InstallExtensionResult>;
614
569
  /** Refused without `allowUpdate`. Installs packages only, so `kubb.config.ts` stays as it is. */
615
570
  updateExtensions: (input: UpdateExtensionsInput) => Promise<UpdateExtensionsResult>;
571
+ /** Refused without `allowRemove` and `allowConfigEdit`. An agent from before `removeExtension` rejects the call. */
572
+ removeExtension: (input: RemoveExtensionInput) => Promise<RemoveExtensionResult>;
616
573
  readFiles: (input: ReadFilesInput) => Promise<ReadFilesResult>;
617
574
  /**
618
575
  * Refused unless the agent was granted `allowRead`, like {@link AgentApi.readFiles}.
@@ -733,14 +690,6 @@ type ConfigEntryView = {
733
690
  options?: object;
734
691
  }>;
735
692
  };
736
- /** An installed extension package and the manifest it ships. */
737
- type ExtensionEntry = {
738
- package: string;
739
- version: string;
740
- manifest: ExtensionManifest;
741
- };
742
- /** Installed extension packages by package name, the only ones Studio may import besides `@kubb/plugin-*`. */
743
- type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>;
744
693
  /**
745
694
  * What an agent may do in the project it serves. Every one is off unless the host granted it, and
746
695
  * a sandbox narrows them further.
@@ -764,6 +713,8 @@ type AgentPermissions = {
764
713
  allowInstall: boolean;
765
714
  /** Whether the agent may run `kubb update` in the project, which installs newer extension versions and leaves `kubb.config.ts` alone. */
766
715
  allowUpdate: boolean;
716
+ /** Whether the agent may run `kubb remove` in the project, which edits `kubb.config.ts` and uninstalls packages. Needs `allowConfigEdit` as well. */
717
+ allowRemove: boolean;
767
718
  /** Whether the agent may keep the spec Studio sends: a document in `openapi.yaml` and `input` in `kubb.config.ts`. Needs `allowConfigEdit` as well. */
768
719
  allowSaveInput: boolean;
769
720
  /**
@@ -787,6 +738,7 @@ declare const AgentPermission: {
787
738
  readonly CONFIG_EDIT: 'allowConfigEdit';
788
739
  readonly INSTALL: 'allowInstall';
789
740
  readonly UPDATE: 'allowUpdate';
741
+ readonly REMOVE: 'allowRemove';
790
742
  readonly SAVE_INPUT: 'allowSaveInput';
791
743
  readonly EXEC: 'allowExec';
792
744
  };
@@ -879,5 +831,5 @@ type PublishedSnapshot = {
879
831
  branchChanges?: BranchSnapshotChanges;
880
832
  };
881
833
  //#endregion
882
- export { generationEventTypes as $, InstallExtensionResult as A, ReadDiffInput as B, GenerateInput as C, GenerationEventType as D, GenerationEventPayloads as E, MAX_SNAPSHOT_BYTES as F, ReadInputResult as G, ReadFilesInput as H, OptionValue as I, SnapshotChanges as J, SaveConfigInput as K, OptionsView as L, JSONKubbConfig as M, MAX_FILES_PER_REQUEST as N, GenerationRun as O, MAX_PAGE_LINES as P, UpdateExtensionsResult as Q, PluginView as R, FilePage as S, GenerationEvent as T, ReadFilesResult as U, ReadDiffResult as V, ReadInputInput as W, StudioApi as X, SnapshotUploadMetadata as Y, UpdateExtensionsInput as Z, ConnectMessagePayload as _, AgentConnectInfo as a, DiskOutput as b, AgentPermissions as c, ConfigEditOperation as d, ConfigEditOutcome as f, ConfigView as g, ConfigRef as h, AgentCloseCode as i, InstalledExtensions as j, InstallExtensionInput as k, BranchSnapshotChanges as l, ConfigFileView as m, AGENT_SOCKET_PATH as n, AgentMessage as o, ConfigEntryView as p, SaveResult as q, AgentApi as r, AgentPermission as s, AGENT_INSTANCE_HEADER as t, ConfigEdit as u, DiffHunk as v, GenerateResult as w, ExtensionEntry as x, DiffStats as y, PublishedSnapshot as z };
883
- //# sourceMappingURL=protocol-C4loKcxw.d.ts.map
834
+ export { ExtensionEntry as $, ReadDiffResult as A, SnapshotUploadMetadata as B, InstallExtensionResult as C, MAX_SNAPSHOT_BYTES as D, MAX_PAGE_LINES as E, RemoveExtensionInput as F, editConfig as G, UpdateExtensionsInput as H, RemoveExtensionResult as I, ConfigEditOperation as J, editConfigFile as K, SaveConfigInput as L, ReadFilesResult as M, ReadInputInput as N, PublishedSnapshot as O, ReadInputResult as P, ConfigView as Q, SaveResult as R, InstallExtensionInput as S, MAX_FILES_PER_REQUEST as T, UpdateExtensionsResult as U, StudioApi as V, generationEventTypes as W, ConfigFileView as X, ConfigEditOutcome as Y, ConfigRef as Z, GenerateResult as _, AgentConnectInfo as a, GenerationEventType as b, AgentPermissions as c, ConnectMessagePayload as d, InstalledExtensions as et, DiffHunk as f, GenerateInput as g, FilePage as h, AgentCloseCode as i, ReadFilesInput as j, ReadDiffInput as k, BranchSnapshotChanges as l, DiskOutput as m, AGENT_SOCKET_PATH as n, OptionsView as nt, AgentMessage as o, DiffStats as p, ConfigEdit as q, AgentApi as r, PluginView as rt, AgentPermission as s, AGENT_INSTANCE_HEADER as t, OptionValue as tt, ConfigEntryView as u, GenerationEvent as v, JSONKubbConfig as w, GenerationRun as x, GenerationEventPayloads as y, SnapshotChanges as z };
835
+ //# sourceMappingURL=protocol-DQTwqmNO.d.cts.map