@scalar/workspace-store 0.19.0 → 0.21.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.
Files changed (188) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +2 -2
  3. package/dist/client.d.ts +40 -4
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +58 -23
  6. package/dist/client.js.map +2 -2
  7. package/dist/events/bus.d.ts +13 -1
  8. package/dist/events/bus.d.ts.map +1 -1
  9. package/dist/events/bus.js +46 -10
  10. package/dist/events/bus.js.map +3 -3
  11. package/dist/events/definitions/auth.d.ts +20 -2
  12. package/dist/events/definitions/auth.d.ts.map +1 -1
  13. package/dist/events/definitions/cookie.d.ts +20 -0
  14. package/dist/events/definitions/cookie.d.ts.map +1 -0
  15. package/dist/events/definitions/cookie.js +1 -0
  16. package/dist/events/definitions/cookie.js.map +7 -0
  17. package/dist/events/definitions/document.d.ts +11 -1
  18. package/dist/events/definitions/document.d.ts.map +1 -1
  19. package/dist/events/definitions/index.d.ts +4 -2
  20. package/dist/events/definitions/index.d.ts.map +1 -1
  21. package/dist/events/definitions/operation.d.ts +0 -13
  22. package/dist/events/definitions/operation.d.ts.map +1 -1
  23. package/dist/events/definitions/server.d.ts +20 -28
  24. package/dist/events/definitions/server.d.ts.map +1 -1
  25. package/dist/events/definitions/tabs.d.ts +40 -0
  26. package/dist/events/definitions/tabs.d.ts.map +1 -0
  27. package/dist/events/definitions/tabs.js +1 -0
  28. package/dist/events/definitions/tabs.js.map +7 -0
  29. package/dist/events/definitions/ui.d.ts +39 -4
  30. package/dist/events/definitions/ui.d.ts.map +1 -1
  31. package/dist/events/definitions/workspace.d.ts +18 -0
  32. package/dist/events/definitions/workspace.d.ts.map +1 -0
  33. package/dist/events/definitions/workspace.js +1 -0
  34. package/dist/events/definitions/workspace.js.map +7 -0
  35. package/dist/events/index.d.ts +2 -2
  36. package/dist/events/index.d.ts.map +1 -1
  37. package/dist/events/index.js.map +2 -2
  38. package/dist/helpers/generate-unique-value.d.ts +19 -6
  39. package/dist/helpers/generate-unique-value.d.ts.map +1 -1
  40. package/dist/helpers/generate-unique-value.js +12 -7
  41. package/dist/helpers/generate-unique-value.js.map +2 -2
  42. package/dist/helpers/unpack-proxy.d.ts +14 -1
  43. package/dist/helpers/unpack-proxy.d.ts.map +1 -1
  44. package/dist/helpers/unpack-proxy.js +51 -1
  45. package/dist/helpers/unpack-proxy.js.map +3 -3
  46. package/dist/mutators/auth.d.ts +10 -73
  47. package/dist/mutators/auth.d.ts.map +1 -1
  48. package/dist/mutators/auth.js +47 -111
  49. package/dist/mutators/auth.js.map +2 -2
  50. package/dist/mutators/cookie.d.ts +21 -13
  51. package/dist/mutators/cookie.d.ts.map +1 -1
  52. package/dist/mutators/cookie.js +34 -26
  53. package/dist/mutators/cookie.js.map +3 -3
  54. package/dist/mutators/document.d.ts +13 -0
  55. package/dist/mutators/document.d.ts.map +1 -0
  56. package/dist/mutators/document.js +25 -0
  57. package/dist/mutators/document.js.map +7 -0
  58. package/dist/mutators/index.d.ts +13 -20
  59. package/dist/mutators/index.d.ts.map +1 -1
  60. package/dist/mutators/index.js +49 -8
  61. package/dist/mutators/index.js.map +3 -3
  62. package/dist/mutators/operation.d.ts +23 -101
  63. package/dist/mutators/operation.d.ts.map +1 -1
  64. package/dist/mutators/operation.js +132 -96
  65. package/dist/mutators/operation.js.map +2 -2
  66. package/dist/mutators/server.d.ts +43 -8
  67. package/dist/mutators/server.d.ts.map +1 -1
  68. package/dist/mutators/server.js +113 -20
  69. package/dist/mutators/server.js.map +2 -2
  70. package/dist/mutators/workspace.d.ts +6 -0
  71. package/dist/mutators/workspace.d.ts.map +1 -0
  72. package/dist/mutators/workspace.js +24 -0
  73. package/dist/mutators/workspace.js.map +7 -0
  74. package/dist/navigation/get-navigation-options.d.ts.map +1 -1
  75. package/dist/navigation/get-navigation-options.js +4 -4
  76. package/dist/navigation/get-navigation-options.js.map +2 -2
  77. package/dist/navigation/helpers/traverse-document.d.ts +2 -0
  78. package/dist/navigation/helpers/traverse-document.d.ts.map +1 -1
  79. package/dist/navigation/helpers/traverse-document.js +18 -3
  80. package/dist/navigation/helpers/traverse-document.js.map +2 -2
  81. package/dist/navigation/helpers/traverse-examples.js +2 -2
  82. package/dist/navigation/helpers/traverse-examples.js.map +2 -2
  83. package/dist/navigation/helpers/traverse-paths.d.ts +6 -3
  84. package/dist/navigation/helpers/traverse-paths.d.ts.map +1 -1
  85. package/dist/navigation/helpers/traverse-paths.js +4 -9
  86. package/dist/navigation/helpers/traverse-paths.js.map +2 -2
  87. package/dist/navigation/helpers/traverse-tags.d.ts +0 -1
  88. package/dist/navigation/helpers/traverse-tags.d.ts.map +1 -1
  89. package/dist/navigation/helpers/traverse-tags.js +57 -49
  90. package/dist/navigation/helpers/traverse-tags.js.map +3 -3
  91. package/dist/persistence/index.d.ts +6 -0
  92. package/dist/persistence/index.d.ts.map +1 -1
  93. package/dist/persistence/index.js +18 -0
  94. package/dist/persistence/index.js.map +2 -2
  95. package/dist/persistence/indexdb.d.ts +1 -0
  96. package/dist/persistence/indexdb.d.ts.map +1 -1
  97. package/dist/persistence/indexdb.js +6 -1
  98. package/dist/persistence/indexdb.js.map +2 -2
  99. package/dist/plugins/client/persistence.d.ts +2 -1
  100. package/dist/plugins/client/persistence.d.ts.map +1 -1
  101. package/dist/plugins/client/persistence.js +17 -9
  102. package/dist/plugins/client/persistence.js.map +2 -2
  103. package/dist/schemas/extensions/document/x-scalar-environments.d.ts +1 -0
  104. package/dist/schemas/extensions/document/x-scalar-environments.d.ts.map +1 -1
  105. package/dist/schemas/extensions/document/x-scalar-environments.js.map +2 -2
  106. package/dist/schemas/extensions/document/x-scalar-set-operation-security.d.ts +13 -0
  107. package/dist/schemas/extensions/document/x-scalar-set-operation-security.d.ts.map +1 -0
  108. package/dist/schemas/extensions/document/x-scalar-set-operation-security.js +8 -0
  109. package/dist/schemas/extensions/document/x-scalar-set-operation-security.js.map +7 -0
  110. package/dist/schemas/extensions/general/x-scalar-cookies.d.ts +36 -0
  111. package/dist/schemas/extensions/general/x-scalar-cookies.d.ts.map +1 -0
  112. package/dist/schemas/extensions/general/x-scalar-cookies.js +15 -0
  113. package/dist/schemas/extensions/general/x-scalar-cookies.js.map +7 -0
  114. package/dist/schemas/extensions/general/x-scalar-order.d.ts +12 -0
  115. package/dist/schemas/extensions/general/x-scalar-order.d.ts.map +1 -0
  116. package/dist/schemas/extensions/general/x-scalar-order.js +8 -0
  117. package/dist/schemas/extensions/general/x-scalar-order.js.map +7 -0
  118. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts +7 -7
  119. package/dist/schemas/extensions/security/x-scalar-selected-security.d.ts.map +1 -1
  120. package/dist/schemas/extensions/security/x-scalar-selected-security.js +2 -2
  121. package/dist/schemas/extensions/security/x-scalar-selected-security.js.map +2 -2
  122. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts +8 -0
  123. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts.map +1 -0
  124. package/dist/schemas/extensions/server/x-scalar-selected-server.js +8 -0
  125. package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +7 -0
  126. package/dist/schemas/extensions/tag/x-tag-groups.d.ts +10 -5
  127. package/dist/schemas/extensions/tag/x-tag-groups.d.ts.map +1 -1
  128. package/dist/schemas/extensions/tag/x-tag-groups.js +15 -10
  129. package/dist/schemas/extensions/tag/x-tag-groups.js.map +2 -2
  130. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.d.ts +18 -0
  131. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.d.ts.map +1 -0
  132. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js +8 -0
  133. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js.map +7 -0
  134. package/dist/schemas/extensions.d.ts +1 -1
  135. package/dist/schemas/extensions.js +1 -1
  136. package/dist/schemas/extensions.js.map +2 -2
  137. package/dist/schemas/inmemory-workspace.d.ts +59 -33
  138. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  139. package/dist/schemas/navigation.d.ts +9 -1
  140. package/dist/schemas/navigation.d.ts.map +1 -1
  141. package/dist/schemas/navigation.js +3 -1
  142. package/dist/schemas/navigation.js.map +2 -2
  143. package/dist/schemas/reference-config/index.d.ts +29 -16
  144. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  145. package/dist/schemas/reference-config/settings.d.ts +29 -16
  146. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  147. package/dist/schemas/reference-config/settings.js +2 -0
  148. package/dist/schemas/reference-config/settings.js.map +2 -2
  149. package/dist/schemas/v3.1/strict/openapi-document.d.ts +992 -549
  150. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  151. package/dist/schemas/v3.1/strict/openapi-document.js +14 -6
  152. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  153. package/dist/schemas/v3.1/strict/operation.d.ts +3 -7
  154. package/dist/schemas/v3.1/strict/operation.d.ts.map +1 -1
  155. package/dist/schemas/v3.1/strict/operation.js +1 -5
  156. package/dist/schemas/v3.1/strict/operation.js.map +2 -2
  157. package/dist/schemas/v3.1/strict/tag.d.ts +4 -1
  158. package/dist/schemas/v3.1/strict/tag.d.ts.map +1 -1
  159. package/dist/schemas/v3.1/strict/tag.js +3 -1
  160. package/dist/schemas/v3.1/strict/tag.js.map +2 -2
  161. package/dist/schemas/v3.1/strict/type-guards.d.ts +6 -0
  162. package/dist/schemas/v3.1/strict/type-guards.d.ts.map +1 -1
  163. package/dist/schemas/v3.1/strict/type-guards.js +4 -0
  164. package/dist/schemas/v3.1/strict/type-guards.js.map +2 -2
  165. package/dist/schemas/workspace-specification/config.d.ts +29 -16
  166. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  167. package/dist/schemas/workspace-specification/index.d.ts +30 -17
  168. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  169. package/dist/schemas/workspace.d.ts +233 -130
  170. package/dist/schemas/workspace.d.ts.map +1 -1
  171. package/dist/schemas/workspace.js +8 -6
  172. package/dist/schemas/workspace.js.map +2 -2
  173. package/dist/server.d.ts +1 -1
  174. package/dist/workspace-plugin.d.ts +3 -0
  175. package/dist/workspace-plugin.d.ts.map +1 -1
  176. package/package.json +8 -7
  177. package/dist/helpers/debounce.d.ts +0 -28
  178. package/dist/helpers/debounce.d.ts.map +0 -1
  179. package/dist/helpers/debounce.js +0 -31
  180. package/dist/helpers/debounce.js.map +0 -7
  181. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts +0 -13
  182. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.d.ts.map +0 -1
  183. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js +0 -9
  184. package/dist/schemas/extensions/operation/x-scalar-operation-identifiers.js.map +0 -7
  185. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-cookies.d.ts +0 -32
  186. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-cookies.d.ts.map +0 -1
  187. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-cookies.js +0 -13
  188. package/dist/schemas/v3.1/strict/client-config-extensions/x-scalar-client-config-cookies.js.map +0 -7
@@ -1,9 +1,73 @@
1
+ import { findVariables } from "@scalar/helpers/regex/find-variables";
1
2
  import { getResolvedRef } from "../helpers/get-resolved-ref.js";
2
- const updateOperationSummary = ({
3
- document,
4
- meta,
5
- payload: { summary }
6
- }) => {
3
+ import { unpackProxyObject } from "../helpers/unpack-proxy.js";
4
+ import { isContentTypeParameterObject } from "../schemas/v3.1/strict/type-guards.js";
5
+ const getParameterPositions = (path, parameters) => {
6
+ const positions = {};
7
+ for (const paramName of parameters) {
8
+ const position = path.indexOf(`{${paramName}}`);
9
+ if (position !== -1) {
10
+ positions[paramName] = position;
11
+ }
12
+ }
13
+ return positions;
14
+ };
15
+ const syncParametersForPathChange = (newPath, oldPath, existingParameters) => {
16
+ const oldPathParams = findVariables(oldPath, { includePath: true, includeEnv: false }).filter(
17
+ (v) => v !== void 0
18
+ );
19
+ const newPathParams = findVariables(newPath, { includePath: true, includeEnv: false }).filter(
20
+ (v) => v !== void 0
21
+ );
22
+ const oldPositions = getParameterPositions(oldPath, oldPathParams);
23
+ const newPositions = getParameterPositions(newPath, newPathParams);
24
+ const pathParameters = [];
25
+ const nonPathParameters = [];
26
+ for (const param of existingParameters) {
27
+ const resolved = getResolvedRef(param);
28
+ if (resolved?.in === "path") {
29
+ pathParameters.push(param);
30
+ } else {
31
+ nonPathParameters.push(param);
32
+ }
33
+ }
34
+ const existingPathParamsByName = /* @__PURE__ */ new Map();
35
+ for (const param of pathParameters) {
36
+ const resolved = getResolvedRef(param);
37
+ if (resolved?.name) {
38
+ existingPathParamsByName.set(resolved.name, param);
39
+ }
40
+ }
41
+ const usedOldParams = /* @__PURE__ */ new Set();
42
+ const syncedPathParameters = [];
43
+ for (const newParamName of newPathParams) {
44
+ if (existingPathParamsByName.has(newParamName)) {
45
+ syncedPathParameters.push(existingPathParamsByName.get(newParamName));
46
+ usedOldParams.add(newParamName);
47
+ continue;
48
+ }
49
+ const newParamPosition = newPositions[newParamName];
50
+ const oldParamAtPosition = oldPathParams.find(
51
+ (oldParam) => oldPositions[oldParam] === newParamPosition && !usedOldParams.has(oldParam)
52
+ );
53
+ if (oldParamAtPosition && existingPathParamsByName.has(oldParamAtPosition)) {
54
+ const oldParam = existingPathParamsByName.get(oldParamAtPosition);
55
+ const resolved = getResolvedRef(oldParam);
56
+ if (resolved) {
57
+ resolved.name = newParamName;
58
+ syncedPathParameters.push(oldParam);
59
+ usedOldParams.add(oldParamAtPosition);
60
+ continue;
61
+ }
62
+ }
63
+ syncedPathParameters.push({
64
+ name: newParamName,
65
+ in: "path"
66
+ });
67
+ }
68
+ return [...syncedPathParameters, ...nonPathParameters];
69
+ };
70
+ const updateOperationSummary = (document, { meta, payload: { summary } }) => {
7
71
  if (!document) {
8
72
  return;
9
73
  }
@@ -13,25 +77,21 @@ const updateOperationSummary = ({
13
77
  }
14
78
  operation.summary = summary;
15
79
  };
16
- const updateOperationMethodDraft = ({
17
- document,
18
- meta,
19
- payload: { method }
20
- }) => {
21
- if (!document) {
80
+ const updateOperationMethod = (document, { meta, payload: { method } }) => {
81
+ const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
82
+ if (!operation) {
83
+ console.error("Operation not found", { meta, document });
22
84
  return;
23
85
  }
24
- const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
25
- if (!operation) {
86
+ const path = document?.paths?.[meta.path];
87
+ if (!path) {
88
+ console.error("Path not found", { meta, document });
26
89
  return;
27
90
  }
28
- operation["x-scalar-method"] = method;
91
+ path[method] = unpackProxyObject(operation);
92
+ delete path[meta.method];
29
93
  };
30
- const updateOperationPathDraft = ({
31
- document,
32
- meta,
33
- payload: { path }
34
- }) => {
94
+ const updateOperationPath = (document, { meta, payload: { path } }) => {
35
95
  if (!document) {
36
96
  return;
37
97
  }
@@ -39,24 +99,35 @@ const updateOperationPathDraft = ({
39
99
  if (!operation) {
40
100
  return;
41
101
  }
42
- operation["x-scalar-path"] = path;
43
- const pathVariables = Array.from(path.matchAll(/{([^\/}]+)}/g), (m) => m[1]);
44
- const pathVariablesWithoutPathParameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== "path");
45
- operation.parameters = [
46
- ...pathVariablesWithoutPathParameters ?? [],
47
- ...pathVariables.map((it) => ({
48
- name: it ?? "",
49
- in: "path",
50
- required: true
51
- }))
52
- ];
102
+ if (meta.path === path) {
103
+ return;
104
+ }
105
+ const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter(
106
+ (v) => v !== void 0
107
+ );
108
+ const newPathParams = findVariables(path, { includePath: true, includeEnv: false }).filter(
109
+ (v) => v !== void 0
110
+ );
111
+ if (oldPathParams.length > 0 || newPathParams.length > 0) {
112
+ const existingParameters = operation.parameters ?? [];
113
+ operation.parameters = syncParametersForPathChange(path, meta.path, existingParameters);
114
+ }
115
+ if (!document.paths) {
116
+ document.paths = {};
117
+ }
118
+ if (!document.paths[path]) {
119
+ document.paths[path] = {};
120
+ }
121
+ document.paths[path][meta.method] = unpackProxyObject(operation);
122
+ const oldPath = document.paths[meta.path];
123
+ if (oldPath) {
124
+ delete oldPath[meta.method];
125
+ if (Object.keys(oldPath).length === 0) {
126
+ delete document.paths[meta.path];
127
+ }
128
+ }
53
129
  };
54
- const addOperationParameter = ({
55
- document,
56
- meta,
57
- payload,
58
- type
59
- }) => {
130
+ const addOperationParameter = (document, { meta, payload, type }) => {
60
131
  if (!document) {
61
132
  return;
62
133
  }
@@ -79,13 +150,7 @@ const addOperationParameter = ({
79
150
  }
80
151
  });
81
152
  };
82
- const updateOperationParameter = ({
83
- document,
84
- meta,
85
- type,
86
- payload,
87
- index
88
- }) => {
153
+ const updateOperationParameter = (document, { meta, type, payload, index }) => {
89
154
  if (!document) {
90
155
  return;
91
156
  }
@@ -99,24 +164,24 @@ const updateOperationParameter = ({
99
164
  return;
100
165
  }
101
166
  parameter.name = payload.key ?? parameter.name ?? "";
102
- if ("examples" in parameter) {
103
- if (!parameter.examples) {
104
- parameter.examples = {};
105
- }
106
- const example = getResolvedRef(parameter.examples[meta.exampleKey]);
107
- if (!example) {
108
- return;
109
- }
110
- example.value = payload.value ?? example?.value ?? "";
111
- example["x-disabled"] = payload.isEnabled === void 0 ? example["x-disabled"] : !payload.isEnabled;
167
+ if (isContentTypeParameterObject(parameter)) {
168
+ return;
169
+ }
170
+ if (!parameter.examples) {
171
+ parameter.examples = {};
172
+ }
173
+ const example = getResolvedRef(parameter.examples[meta.exampleKey]);
174
+ if (!example) {
175
+ parameter.examples[meta.exampleKey] = {
176
+ value: payload.value ?? "",
177
+ "x-disabled": payload.isEnabled === void 0 ? false : !payload.isEnabled
178
+ };
179
+ return;
112
180
  }
181
+ example.value = payload.value ?? example?.value ?? "";
182
+ example["x-disabled"] = payload.isEnabled === void 0 ? example["x-disabled"] : !payload.isEnabled;
113
183
  };
114
- const deleteOperationParameter = ({
115
- document,
116
- meta,
117
- index,
118
- type
119
- }) => {
184
+ const deleteOperationParameter = (document, { meta, index, type }) => {
120
185
  if (!document) {
121
186
  return;
122
187
  }
@@ -132,11 +197,7 @@ const deleteOperationParameter = ({
132
197
  const actualIndex = operation.parameters?.findIndex((it) => getResolvedRef(it) === parameter);
133
198
  operation.parameters?.splice(actualIndex, 1);
134
199
  };
135
- const deleteAllOperationParameters = ({
136
- document,
137
- meta,
138
- type
139
- }) => {
200
+ const deleteAllOperationParameters = (document, { meta, type }) => {
140
201
  if (!document) {
141
202
  return;
142
203
  }
@@ -146,11 +207,7 @@ const deleteAllOperationParameters = ({
146
207
  }
147
208
  operation.parameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== type) ?? [];
148
209
  };
149
- const updateOperationRequestBodyContentType = ({
150
- document,
151
- meta,
152
- payload
153
- }) => {
210
+ const updateOperationRequestBodyContentType = (document, { meta, payload }) => {
154
211
  if (!document) {
155
212
  return;
156
213
  }
@@ -170,12 +227,7 @@ const updateOperationRequestBodyContentType = ({
170
227
  }
171
228
  requestBody["x-scalar-selected-content-type"][meta.exampleKey] = payload.contentType;
172
229
  };
173
- const updateOperationRequestBodyExample = ({
174
- document,
175
- meta,
176
- payload,
177
- contentType
178
- }) => {
230
+ const updateOperationRequestBodyExample = (document, { meta, payload, contentType }) => {
179
231
  if (!document) {
180
232
  return;
181
233
  }
@@ -207,12 +259,7 @@ const updateOperationRequestBodyExample = ({
207
259
  }
208
260
  example.value = payload.value;
209
261
  };
210
- const addOperationRequestBodyFormRow = ({
211
- document,
212
- meta,
213
- payload,
214
- contentType
215
- }) => {
262
+ const addOperationRequestBodyFormRow = (document, { meta, payload, contentType }) => {
216
263
  if (!document) {
217
264
  return;
218
265
  }
@@ -253,13 +300,7 @@ const addOperationRequestBodyFormRow = ({
253
300
  value: payload.value ?? ""
254
301
  });
255
302
  };
256
- const updateOperationRequestBodyFormRow = ({
257
- document,
258
- meta,
259
- index,
260
- payload,
261
- contentType
262
- }) => {
303
+ const updateOperationRequestBodyFormRow = (document, { meta, index, payload, contentType }) => {
263
304
  if (!document) {
264
305
  return;
265
306
  }
@@ -290,12 +331,7 @@ const updateOperationRequestBodyFormRow = ({
290
331
  value: payload.value === null ? void 0 : payload.value ?? example.value[index]?.value ?? ""
291
332
  };
292
333
  };
293
- const deleteOperationRequestBodyFormRow = ({
294
- document,
295
- meta,
296
- index,
297
- contentType
298
- }) => {
334
+ const deleteOperationRequestBodyFormRow = (document, { meta, index, contentType }) => {
299
335
  if (!document) {
300
336
  return;
301
337
  }
@@ -329,9 +365,9 @@ export {
329
365
  deleteAllOperationParameters,
330
366
  deleteOperationParameter,
331
367
  deleteOperationRequestBodyFormRow,
332
- updateOperationMethodDraft,
368
+ updateOperationMethod,
333
369
  updateOperationParameter,
334
- updateOperationPathDraft,
370
+ updateOperationPath,
335
371
  updateOperationRequestBodyContentType,
336
372
  updateOperationRequestBodyExample,
337
373
  updateOperationRequestBodyFormRow,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/operation.ts"],
4
- "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Describes the minimal identity for an operation in the workspace document.\n * It is used by mutators to find the target operation under `paths`.\n *\n * Example:\n * ```ts\n * const meta: OperationMeta = { method: 'get', path: '/users/{id}' }\n * ```\n */\nexport type OperationMeta = {\n method: HttpMethod\n path: string\n}\n\n/**\n * Extends {@link OperationMeta} with an `exampleKey` to address a specific\n * example variant (e.g. per environment or scenario) for request/parameters.\n *\n * Example:\n * ```ts\n * const meta: OperationExampleMeta = {\n * method: 'post',\n * path: '/upload',\n * exampleKey: 'default',\n * }\n * ```\n */\nexport type OperationExampleMeta = OperationMeta & {\n exampleKey: string\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Operation Draft Mutators\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Updates the `summary` of an operation.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationSummary({\n * document,\n * meta: { method: 'get', path: '/users/{id}' },\n * payload: { summary: 'Get a single user' },\n * })\n * ```\n */\nexport const updateOperationSummary = ({\n document,\n meta,\n payload: { summary },\n}: {\n document: WorkspaceDocument | null\n payload: { summary: string }\n meta: OperationMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method as HttpMethod])\n\n if (!operation) {\n return\n }\n\n operation.summary = summary\n}\n\n/**\n * Stores the chosen HTTP method under `x-scalar-method` on the operation.\n * This does not move the operation to a different method slot under `paths`;\n * it records the desired method as an extension for downstream consumers.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationMethodDraft({\n * document,\n * meta: { method: 'get', path: '/users' },\n * payload: { method: 'post' },\n * })\n * ```\n */\nexport const updateOperationMethodDraft = ({\n document,\n meta,\n payload: { method },\n}: {\n document: WorkspaceDocument | null\n payload: { method: HttpMethod }\n meta: OperationMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n if (!operation) {\n return\n }\n\n operation['x-scalar-method'] = method\n}\n\n/**\n * Records a normalized path for the operation under `x-scalar-path`, and\n * synchronizes path parameters in `operation.parameters` with the placeholders\n * present in the provided `path` (e.g. `/users/{id}`). Existing non-path\n * parameters are preserved.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationPathDraft({\n * document,\n * meta: { method: 'get', path: '/users/{id}' },\n * payload: { path: '/users/{id}' },\n * })\n * ```\n */\nexport const updateOperationPathDraft = ({\n document,\n meta,\n payload: { path },\n}: {\n document: WorkspaceDocument | null\n payload: { path: string }\n meta: OperationMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n if (!operation) {\n return\n }\n\n operation['x-scalar-path'] = path\n\n // Extract the path variables from the path\n const pathVariables = Array.from(path.matchAll(/{([^\\/}]+)}/g), (m) => m[1])\n\n // now we need to update the operation path variables\n const pathVariablesWithoutPathParameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== 'path')\n\n operation.parameters = [\n ...(pathVariablesWithoutPathParameters ?? []),\n ...pathVariables.map((it) => ({\n name: it ?? '',\n in: 'path' as const,\n required: true,\n })),\n ]\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Operation Parameters Mutators\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Adds a parameter to the operation with an example value tracked by `exampleKey`.\n * For `path` parameters `required` is set to true automatically.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * addOperationParameter({\n * document,\n * type: 'query',\n * meta: { method: 'get', path: '/search', exampleKey: 'default' },\n * payload: { key: 'q', value: 'john', isEnabled: true },\n * })\n * ```\n */\nexport const addOperationParameter = ({\n document,\n meta,\n payload,\n type,\n}: {\n document: WorkspaceDocument | null\n type: 'header' | 'path' | 'query' | 'cookie'\n payload: {\n key: string\n value: string\n isEnabled: boolean\n }\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Initialize parameters array if it doesn't exist\n if (!operation.parameters) {\n operation.parameters = []\n }\n\n // Add the new parameter\n operation.parameters.push({\n name: payload.key,\n in: type,\n required: type === 'path' ? true : false,\n examples: {\n [meta.exampleKey]: {\n value: payload.value,\n 'x-disabled': !payload.isEnabled,\n },\n },\n })\n}\n\n/**\n * Updates an existing parameter of a given `type` by its index within that\n * type subset (e.g. the N-th query parameter). Supports updating name, value,\n * and enabled state for the targeted example.\n * Safely no-ops if the document, operation, or parameter does not exist.\n *\n * Example:\n * ```ts\n * updateOperationParameter({\n * document,\n * type: 'query',\n * index: 0,\n * meta: { method: 'get', path: '/search', exampleKey: 'default' },\n * payload: { value: 'alice', isEnabled: true },\n * })\n * ```\n */\nexport const updateOperationParameter = ({\n document,\n meta,\n type,\n payload,\n index,\n}: {\n document: WorkspaceDocument | null\n type: 'header' | 'path' | 'query' | 'cookie'\n index: number\n payload: Partial<{\n key: string\n value: string\n isEnabled: boolean\n }>\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Get all resolved parameters of the specified type\n // The passed index corresponds to this filtered list\n const resolvedParameters = operation.parameters?.map((it) => getResolvedRef(it)).filter((it) => it.in === type) ?? []\n const parameter = resolvedParameters[index]\n\n // Don't proceed if parameter doesn't exist\n if (!parameter) {\n return\n }\n\n parameter.name = payload.key ?? parameter.name ?? ''\n\n // TODO: handle content-type parameters\n if ('examples' in parameter) {\n if (!parameter.examples) {\n parameter.examples = {}\n }\n\n const example = getResolvedRef(parameter.examples[meta.exampleKey])\n\n if (!example) {\n return\n }\n\n example.value = payload.value ?? example?.value ?? ''\n example['x-disabled'] = payload.isEnabled === undefined ? example['x-disabled'] : !payload.isEnabled\n }\n}\n\n/**\n * Removes a parameter from the operation by resolving its position within\n * the filtered list of parameters of the specified `type`.\n * Safely no-ops if the document, operation, or parameter does not exist.\n *\n * Example:\n * ```ts\n * deleteOperationParameter({\n * document,\n * type: 'header',\n * index: 1,\n * meta: { method: 'get', path: '/users', exampleKey: 'default' },\n * })\n * ```\n */\nexport const deleteOperationParameter = ({\n document,\n meta,\n index,\n type,\n}: {\n document: WorkspaceDocument | null\n type: 'header' | 'path' | 'query' | 'cookie'\n index: number\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Translate the index from the filtered list to the actual parameters array\n const resolvedParameters = operation.parameters?.map((it) => getResolvedRef(it)).filter((it) => it.in === type) ?? []\n const parameter = resolvedParameters[index]\n\n // Don't proceed if parameter doesn't exist\n if (!parameter) {\n return\n }\n\n const actualIndex = operation.parameters?.findIndex((it) => getResolvedRef(it) === parameter) as number\n\n // Remove the parameter from the operation\n operation.parameters?.splice(actualIndex, 1)\n}\n\n/**\n * Deletes all parameters of a given `type` from the operation.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * deleteAllOperationParameters({\n * document,\n * type: 'cookie',\n * meta: { method: 'get', path: '/users' },\n * })\n * ```\n */\nexport const deleteAllOperationParameters = ({\n document,\n meta,\n type,\n}: {\n document: WorkspaceDocument | null\n type: 'header' | 'path' | 'query' | 'cookie'\n meta: OperationMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Filter out parameters of the specified type\n operation.parameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== type) ?? []\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Operation Request Body Mutators\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Sets the selected request-body content type for the current `exampleKey`.\n * This stores the selection under `x-scalar-selected-content-type` on the\n * resolved requestBody. Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationRequestBodyContentType({\n * document,\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * payload: { contentType: 'multipart/form-data' },\n * })\n * ```\n */\nexport const updateOperationRequestBodyContentType = ({\n document,\n meta,\n payload,\n}: {\n document: WorkspaceDocument | null\n payload: {\n contentType: string\n }\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!['x-scalar-selected-content-type']) {\n requestBody!['x-scalar-selected-content-type'] = {}\n }\n\n requestBody!['x-scalar-selected-content-type'][meta.exampleKey] = payload.contentType\n}\n\n/**\n * Creates or updates a concrete example value for a specific request-body\n * `contentType` and `exampleKey`. Safely no-ops if the document or operation\n * does not exist.\n *\n * Example:\n * ```ts\n * updateOperationRequestBodyExample({\n * document,\n * contentType: 'application/json',\n * meta: { method: 'post', path: '/users', exampleKey: 'default' },\n * payload: { value: JSON.stringify({ name: 'Ada' }) },\n * })\n * ```\n */\nexport const updateOperationRequestBodyExample = ({\n document,\n meta,\n payload,\n contentType,\n}: {\n document: WorkspaceDocument | null\n contentType: string\n payload: {\n value: string | File | undefined\n }\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!.content[contentType]) {\n requestBody!.content[contentType] = {\n examples: {},\n }\n }\n\n // Ensure examples object exists and get a resolved reference\n const mediaType = requestBody!.content[contentType]!\n mediaType.examples ??= {}\n const examples = getResolvedRef(mediaType.examples)!\n\n const example = getResolvedRef(examples[meta.exampleKey])\n\n if (!example) {\n examples[meta.exampleKey] = {\n value: payload.value,\n }\n return\n }\n\n example.value = payload.value\n}\n\n/**\n * Appends a form-data row to the request-body example identified by\n * `contentType` and `exampleKey`. Initializes the example as an array when\n * needed. Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * addOperationRequestBodyFormRow({\n * document,\n * contentType: 'multipart/form-data',\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * payload: { key: 'file', value: new File(['x'], 'a.txt') },\n * })\n * ```\n */\nexport const addOperationRequestBodyFormRow = ({\n document,\n meta,\n payload,\n contentType,\n}: {\n document: WorkspaceDocument | null\n payload: Partial<{ key: string; value?: string | File }>\n contentType: string\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!.content[contentType]) {\n requestBody!.content[contentType] = {\n examples: {},\n }\n }\n\n if (!requestBody!.content[contentType]!.examples) {\n requestBody!.content[contentType]!.examples = {}\n }\n\n const examples = getResolvedRef(requestBody!.content[contentType]!.examples)\n\n const example = getResolvedRef(examples[meta.exampleKey])\n\n if (!example || !Array.isArray(example.value)) {\n examples[meta.exampleKey] = {\n value: [\n {\n name: payload.key,\n value: payload.value,\n },\n ],\n }\n return\n }\n\n // Add the new row to the example\n example.value.push({\n name: payload.key ?? '',\n value: payload.value ?? '',\n })\n}\n\n/**\n * Updates a form-data row at a given `index` for the specified example and\n * `contentType`. Setting `payload.value` to `null` clears the value (sets to\n * `undefined`). Safely no-ops if the document, operation, or example does not exist.\n *\n * Example:\n * ```ts\n * updateOperationRequestBodyFormRow({\n * document,\n * index: 0,\n * contentType: 'multipart/form-data',\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * payload: { key: 'description', value: 'Profile picture' },\n * })\n * ```\n */\nexport const updateOperationRequestBodyFormRow = ({\n document,\n meta,\n index,\n payload,\n contentType,\n}: {\n document: WorkspaceDocument | null\n index: number\n payload: Partial<{ key: string; value: string | File | null }>\n contentType: string\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!.content[contentType]) {\n return\n }\n\n const examples = getResolvedRef(requestBody!.content[contentType]!.examples)\n\n if (!examples) {\n return\n }\n\n const example = getResolvedRef(examples[meta.exampleKey])\n\n if (!example || !Array.isArray(example.value)) {\n return\n }\n\n example.value[index] = {\n name: payload.key ?? example.value[index]?.name ?? '',\n value: payload.value === null ? undefined : (payload.value ?? example.value[index]?.value ?? ''),\n }\n}\n\n/**\n * Deletes a form-data row at a given `index` from the example for the given\n * `contentType`. If the example becomes empty, the example entry is removed.\n * Safely no-ops if the document, operation, example, or row does not exist.\n *\n * Example:\n * ```ts\n * deleteOperationRequestBodyFormRow({\n * document,\n * index: 0,\n * contentType: 'multipart/form-data',\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * })\n * ```\n */\nexport const deleteOperationRequestBodyFormRow = ({\n document,\n meta,\n index,\n contentType,\n}: {\n document: WorkspaceDocument | null\n index: number\n contentType: string\n meta: OperationExampleMeta\n}) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n const requestBody = getResolvedRef(operation.requestBody)\n\n if (!requestBody) {\n return\n }\n\n if (!requestBody.content[contentType]) {\n return\n }\n\n const examples = getResolvedRef(requestBody.content[contentType]!.examples)\n\n if (!examples) {\n return\n }\n\n const example = getResolvedRef(examples[meta.exampleKey])\n\n if (!example || !Array.isArray(example.value)) {\n return\n }\n\n example.value.splice(index, 1)\n\n if (example.value.length === 0) {\n delete requestBody.content[contentType]!.examples![meta.exampleKey]\n }\n}\n"],
5
- "mappings": "AAEA,SAAS,sBAAsB;AAmDxB,MAAM,yBAAyB,CAAC;AAAA,EACrC;AAAA,EACA;AAAA,EACA,SAAS,EAAE,QAAQ;AACrB,MAIM;AACJ,MAAI,CAAC,UAAU;AACb;AAAA,E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\nimport { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { OperationEvents } from '@/events/definitions/operation'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport type { WorkspaceDocument } from '@/schemas'\nimport type { ParameterObject } from '@/schemas/v3.1/strict/openapi-document'\nimport type { ReferenceType } from '@/schemas/v3.1/strict/reference'\nimport { isContentTypeParameterObject } from '@/schemas/v3.1/strict/type-guards'\n\n/**\n * Describes the minimal identity for an operation in the workspace document.\n * It is used by mutators to find the target operation under `paths`.\n *\n * Example:\n * ```ts\n * const meta: OperationMeta = { method: 'get', path: '/users/{id}' }\n * ```\n */\nexport type OperationMeta = {\n method: HttpMethod\n path: string\n}\n\n/**\n * Extends {@link OperationMeta} with an `exampleKey` to address a specific\n * example variant (e.g. per environment or scenario) for request/parameters.\n *\n * Example:\n * ```ts\n * const meta: OperationExampleMeta = {\n * method: 'post',\n * path: '/upload',\n * exampleKey: 'default',\n * }\n * ```\n */\nexport type OperationExampleMeta = OperationMeta & {\n exampleKey: string\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Helper Functions for Path Parameter Synchronization\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Creates a map of parameter names to their character positions in a path.\n * Used to detect renamed path parameters by position matching.\n */\nconst getParameterPositions = (path: string, parameters: readonly string[]): Record<string, number> => {\n const positions: Record<string, number> = {}\n\n for (const paramName of parameters) {\n const position = path.indexOf(`{${paramName}}`)\n if (position !== -1) {\n positions[paramName] = position\n }\n }\n\n return positions\n}\n\n/**\n * Syncs path parameters when the path changes.\n *\n * Preserves parameter configurations by:\n * 1. Keeping parameters with matching names\n * 2. Renaming parameters at the same position\n * 3. Creating new parameters with empty examples\n * 4. Removing parameters that no longer exist in the new path\n */\nconst syncParametersForPathChange = (\n newPath: string,\n oldPath: string,\n existingParameters: ReferenceType<ParameterObject>[],\n): ReferenceType<ParameterObject>[] => {\n // Extract path parameter names from both paths\n const oldPathParams = findVariables(oldPath, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newPathParams = findVariables(newPath, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n const oldPositions = getParameterPositions(oldPath, oldPathParams)\n const newPositions = getParameterPositions(newPath, newPathParams)\n\n // Separate path and non-path parameters, keeping original references\n const pathParameters: ReferenceType<ParameterObject>[] = []\n const nonPathParameters: ReferenceType<ParameterObject>[] = []\n\n for (const param of existingParameters) {\n const resolved = getResolvedRef(param)\n if (resolved?.in === 'path') {\n pathParameters.push(param)\n } else {\n nonPathParameters.push(param)\n }\n }\n\n // Create a map of existing path parameters by name for quick lookup\n const existingPathParamsByName = new Map<string, ReferenceType<ParameterObject>>()\n for (const param of pathParameters) {\n const resolved = getResolvedRef(param)\n if (resolved?.name) {\n existingPathParamsByName.set(resolved.name, param)\n }\n }\n\n const usedOldParams = new Set<string>()\n const syncedPathParameters: ReferenceType<ParameterObject>[] = []\n\n for (const newParamName of newPathParams) {\n // Case 1: Parameter with same name exists - preserve its config\n if (existingPathParamsByName.has(newParamName)) {\n syncedPathParameters.push(existingPathParamsByName.get(newParamName)!)\n usedOldParams.add(newParamName)\n continue\n }\n\n // Case 2: Check for parameter at same position (likely a rename)\n const newParamPosition = newPositions[newParamName]\n const oldParamAtPosition = oldPathParams.find(\n (oldParam) => oldPositions[oldParam] === newParamPosition && !usedOldParams.has(oldParam),\n )\n\n if (oldParamAtPosition && existingPathParamsByName.has(oldParamAtPosition)) {\n // Rename: transfer the old parameter's config to the new name\n const oldParam = existingPathParamsByName.get(oldParamAtPosition)!\n const resolved = getResolvedRef(oldParam)\n if (resolved) {\n resolved.name = newParamName\n syncedPathParameters.push(oldParam)\n usedOldParams.add(oldParamAtPosition)\n continue\n }\n }\n\n // Case 3: New parameter - create with empty examples\n syncedPathParameters.push({\n name: newParamName,\n in: 'path',\n })\n }\n\n // Return all parameters: synced path parameters + preserved non-path parameters\n return [...syncedPathParameters, ...nonPathParameters]\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Operation Draft Mutators\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Updates the `summary` of an operation.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationSummary(\n * document,\n * {\n * meta: { method: 'get', path: '/users/{id}' },\n * payload: { summary: 'Get a single user' },\n * })\n * ```\n */\nexport const updateOperationSummary = (\n document: WorkspaceDocument | null,\n { meta, payload: { summary } }: OperationEvents['operation:update:summary'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method as HttpMethod])\n if (!operation) {\n return\n }\n\n operation.summary = summary\n}\n\n/**\n * Stores the chosen HTTP method under `x-scalar-method` on the operation.\n * This does not move the operation to a different method slot under `paths`;\n * it records the desired method as an extension for downstream consumers.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationMethodDraft({\n * document,\n * meta: { method: 'get', path: '/users' },\n * payload: { method: 'post' },\n * })\n * ```\n */\nexport const updateOperationMethod = (\n document: WorkspaceDocument | null,\n { meta, payload: { method } }: OperationEvents['operation:update:method'],\n) => {\n const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n console.error('Operation not found', { meta, document })\n return\n }\n\n /** Ensure the path exists */\n const path = document?.paths?.[meta.path]\n if (!path) {\n console.error('Path not found', { meta, document })\n return\n }\n\n path[method] = unpackProxyObject(operation)\n delete path[meta.method]\n}\n\n/**\n * Moves the operation to a new path in the document and synchronizes path\n * parameters in `operation.parameters` with the placeholders present in the\n * provided `path` (e.g. `/users/{id}`). When path parameters change,\n * intelligently syncs them by preserving configurations for renamed parameters\n * (detected by position) and existing parameters. Existing non-path parameters\n * are preserved. The operation is removed from the old path location.\n *\n * Example:\n * ```ts\n * updateOperationPath({\n * document,\n * meta: { method: 'get', path: '/users/{id}' },\n * payload: { path: '/users/{userId}' },\n * })\n * ```\n */\nexport const updateOperationPath = (\n document: WorkspaceDocument | null,\n { meta, payload: { path } }: OperationEvents['operation:update:path'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n return\n }\n\n // If the path has not changed, no need to move the operation\n if (meta.path === path) {\n return\n }\n\n // Sync path parameters if either the old or new path has path parameters\n const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newPathParams = findVariables(path, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n if (oldPathParams.length > 0 || newPathParams.length > 0) {\n const existingParameters = operation.parameters ?? []\n operation.parameters = syncParametersForPathChange(path, meta.path, existingParameters)\n }\n\n // Initialize the paths object if it does not exist\n if (!document.paths) {\n document.paths = {}\n }\n\n // Initialize the new path if it does not exist\n if (!document.paths[path]) {\n document.paths[path] = {}\n }\n\n // Move the operation to the new path\n document.paths[path][meta.method] = unpackProxyObject(operation)\n\n // Remove the operation from the old path\n const oldPath = document.paths[meta.path]\n if (oldPath) {\n delete oldPath[meta.method]\n\n // If the old path has no more operations, remove the path entry\n if (Object.keys(oldPath).length === 0) {\n delete document.paths[meta.path]\n }\n }\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Operation Parameters Mutators\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Adds a parameter to the operation with an example value tracked by `exampleKey`.\n * For `path` parameters `required` is set to true automatically.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * addOperationParameter({\n * document,\n * type: 'query',\n * meta: { method: 'get', path: '/search', exampleKey: 'default' },\n * payload: { key: 'q', value: 'john', isEnabled: true },\n * })\n * ```\n */\nexport const addOperationParameter = (\n document: WorkspaceDocument | null,\n { meta, payload, type }: OperationEvents['operation:add:parameter'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Initialize parameters array if it doesn't exist\n if (!operation.parameters) {\n operation.parameters = []\n }\n\n // Add the new parameter\n operation.parameters.push({\n name: payload.key,\n in: type,\n required: type === 'path' ? true : false,\n examples: {\n [meta.exampleKey]: {\n value: payload.value,\n 'x-disabled': !payload.isEnabled,\n },\n },\n })\n}\n\n/**\n * Updates an existing parameter of a given `type` by its index within that\n * type subset (e.g. the N-th query parameter). Supports updating name, value,\n * and enabled state for the targeted example.\n * Safely no-ops if the document, operation, or parameter does not exist.\n *\n * Example:\n * ```ts\n * updateOperationParameter({\n * document,\n * type: 'query',\n * index: 0,\n * meta: { method: 'get', path: '/search', exampleKey: 'default' },\n * payload: { value: 'alice', isEnabled: true },\n * })\n * ```\n */\nexport const updateOperationParameter = (\n document: WorkspaceDocument | null,\n { meta, type, payload, index }: OperationEvents['operation:update:parameter'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Get all resolved parameters of the specified type\n // The passed index corresponds to this filtered list\n const resolvedParameters = operation.parameters?.map((it) => getResolvedRef(it)).filter((it) => it.in === type) ?? []\n const parameter = resolvedParameters[index]\n if (!parameter) {\n return\n }\n\n parameter.name = payload.key ?? parameter.name ?? ''\n\n if (isContentTypeParameterObject(parameter)) {\n // TODO: handle content-type parameters\n return\n }\n\n if (!parameter.examples) {\n parameter.examples = {}\n }\n\n const example = getResolvedRef(parameter.examples[meta.exampleKey])\n\n // Create the example if it doesn't exist\n if (!example) {\n parameter.examples[meta.exampleKey] = {\n value: payload.value ?? '',\n 'x-disabled': payload.isEnabled === undefined ? false : !payload.isEnabled,\n }\n return\n }\n\n // Update existing example value\n example.value = payload.value ?? example?.value ?? ''\n example['x-disabled'] = payload.isEnabled === undefined ? example['x-disabled'] : !payload.isEnabled\n}\n\n/**\n * Removes a parameter from the operation by resolving its position within\n * the filtered list of parameters of the specified `type`.\n * Safely no-ops if the document, operation, or parameter does not exist.\n *\n * Example:\n * ```ts\n * deleteOperationParameter({\n * document,\n * type: 'header',\n * index: 1,\n * meta: { method: 'get', path: '/users', exampleKey: 'default' },\n * })\n * ```\n */\nexport const deleteOperationParameter = (\n document: WorkspaceDocument | null,\n { meta, index, type }: OperationEvents['operation:delete:parameter'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n // Translate the index from the filtered list to the actual parameters array\n const resolvedParameters = operation.parameters?.map((it) => getResolvedRef(it)).filter((it) => it.in === type) ?? []\n const parameter = resolvedParameters[index]\n if (!parameter) {\n return\n }\n\n const actualIndex = operation.parameters?.findIndex((it) => getResolvedRef(it) === parameter) as number\n\n // Remove the parameter from the operation\n operation.parameters?.splice(actualIndex, 1)\n}\n\n/**\n * Deletes all parameters of a given `type` from the operation.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * deleteAllOperationParameters({\n * document,\n * type: 'cookie',\n * meta: { method: 'get', path: '/users' },\n * })\n * ```\n */\nexport const deleteAllOperationParameters = (\n document: WorkspaceDocument | null,\n { meta, type }: OperationEvents['operation:delete-all:parameters'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n return\n }\n\n // Filter out parameters of the specified type\n operation.parameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== type) ?? []\n}\n\n/** ------------------------------------------------------------------------------------------------\n * Operation Request Body Mutators\n * ------------------------------------------------------------------------------------------------ */\n\n/**\n * Sets the selected request-body content type for the current `exampleKey`.\n * This stores the selection under `x-scalar-selected-content-type` on the\n * resolved requestBody. Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationRequestBodyContentType({\n * document,\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * payload: { contentType: 'multipart/form-data' },\n * })\n * ```\n */\nexport const updateOperationRequestBodyContentType = (\n document: WorkspaceDocument | null,\n { meta, payload }: OperationEvents['operation:update:requestBody:contentType'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!['x-scalar-selected-content-type']) {\n requestBody!['x-scalar-selected-content-type'] = {}\n }\n\n requestBody!['x-scalar-selected-content-type'][meta.exampleKey] = payload.contentType\n}\n\n/**\n * Creates or updates a concrete example value for a specific request-body\n * `contentType` and `exampleKey`. Safely no-ops if the document or operation\n * does not exist.\n *\n * Example:\n * ```ts\n * updateOperationRequestBodyExample({\n * document,\n * contentType: 'application/json',\n * meta: { method: 'post', path: '/users', exampleKey: 'default' },\n * payload: { value: JSON.stringify({ name: 'Ada' }) },\n * })\n * ```\n */\nexport const updateOperationRequestBodyExample = (\n document: WorkspaceDocument | null,\n { meta, payload, contentType }: OperationEvents['operation:update:requestBody:value'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!.content[contentType]) {\n requestBody!.content[contentType] = {\n examples: {},\n }\n }\n\n // Ensure examples object exists and get a resolved reference\n const mediaType = requestBody!.content[contentType]!\n mediaType.examples ??= {}\n const examples = getResolvedRef(mediaType.examples)!\n\n const example = getResolvedRef(examples[meta.exampleKey])\n if (!example) {\n examples[meta.exampleKey] = {\n value: payload.value,\n }\n return\n }\n\n example.value = payload.value\n}\n\n/**\n * Appends a form-data row to the request-body example identified by\n * `contentType` and `exampleKey`. Initializes the example as an array when\n * needed. Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * addOperationRequestBodyFormRow({\n * document,\n * contentType: 'multipart/form-data',\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * payload: { key: 'file', value: new File(['x'], 'a.txt') },\n * })\n * ```\n */\nexport const addOperationRequestBodyFormRow = (\n document: WorkspaceDocument | null,\n { meta, payload, contentType }: OperationEvents['operation:add:requestBody:formRow'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n\n // Don't proceed if operation doesn't exist\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!.content[contentType]) {\n requestBody!.content[contentType] = {\n examples: {},\n }\n }\n\n if (!requestBody!.content[contentType]!.examples) {\n requestBody!.content[contentType]!.examples = {}\n }\n\n const examples = getResolvedRef(requestBody!.content[contentType]!.examples)\n\n const example = getResolvedRef(examples[meta.exampleKey])\n\n if (!example || !Array.isArray(example.value)) {\n examples[meta.exampleKey] = {\n value: [\n {\n name: payload.key,\n value: payload.value,\n },\n ],\n }\n return\n }\n\n // Add the new row to the example\n example.value.push({\n name: payload.key ?? '',\n value: payload.value ?? '',\n })\n}\n\n/**\n * Updates a form-data row at a given `index` for the specified example and\n * `contentType`. Setting `payload.value` to `null` clears the value (sets to\n * `undefined`). Safely no-ops if the document, operation, or example does not exist.\n *\n * Example:\n * ```ts\n * updateOperationRequestBodyFormRow({\n * document,\n * index: 0,\n * contentType: 'multipart/form-data',\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * payload: { key: 'description', value: 'Profile picture' },\n * })\n * ```\n */\nexport const updateOperationRequestBodyFormRow = (\n document: WorkspaceDocument | null,\n { meta, index, payload, contentType }: OperationEvents['operation:update:requestBody:formRow'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n return\n }\n\n let requestBody = getResolvedRef(operation.requestBody)\n if (!requestBody) {\n operation.requestBody = {\n content: {},\n }\n requestBody = getResolvedRef(operation.requestBody)\n }\n\n if (!requestBody!.content[contentType]) {\n return\n }\n\n const examples = getResolvedRef(requestBody!.content[contentType]!.examples)\n if (!examples) {\n return\n }\n\n const example = getResolvedRef(examples[meta.exampleKey])\n if (!example || !Array.isArray(example.value)) {\n return\n }\n\n example.value[index] = {\n name: payload.key ?? example.value[index]?.name ?? '',\n value: payload.value === null ? undefined : (payload.value ?? example.value[index]?.value ?? ''),\n }\n}\n\n/**\n * Deletes a form-data row at a given `index` from the example for the given\n * `contentType`. If the example becomes empty, the example entry is removed.\n * Safely no-ops if the document, operation, example, or row does not exist.\n *\n * Example:\n * ```ts\n * deleteOperationRequestBodyFormRow({\n * document,\n * index: 0,\n * contentType: 'multipart/form-data',\n * meta: { method: 'post', path: '/upload', exampleKey: 'default' },\n * })\n * ```\n */\nexport const deleteOperationRequestBodyFormRow = (\n document: WorkspaceDocument | null,\n { meta, index, contentType }: OperationEvents['operation:delete:requestBody:formRow'],\n) => {\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method])\n if (!operation) {\n return\n }\n\n const requestBody = getResolvedRef(operation.requestBody)\n if (!requestBody) {\n return\n }\n\n if (!requestBody.content[contentType]) {\n return\n }\n\n const examples = getResolvedRef(requestBody.content[contentType]!.examples)\n if (!examples) {\n return\n }\n\n const example = getResolvedRef(examples[meta.exampleKey])\n if (!example || !Array.isArray(example.value)) {\n return\n }\n\n example.value.splice(index, 1)\n\n if (example.value.length === 0) {\n delete requestBody.content[contentType]!.examples![meta.exampleKey]\n }\n}\n"],
5
+ "mappings": "AACA,SAAS,qBAAqB;AAG9B,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAIlC,SAAS,oCAAoC;AAyC7C,MAAM,wBAAwB,CAAC,MAAc,eAA0D;AACrG,QAAM,YAAoC,CAAC;AAE3C,aA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,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAEA,QAAM,UAAU,eAAe,SAAS,KAAK,UAAU,CAAC;AACxD,MAAI,CAAC,WAAW,CAAC,MAAM,QAAQ,QAAQ,KAAK,GAAG;AAC7C;AAAA,EACF;AAEA,UAAQ,MAAM,KAAK,IAAI;AAAA,IACrB,MAAM,QAAQ,OAAO,QAAQ,MAAM,KAAK,GAAG,QAAQ;AAAA,IACnD,OAAO,QAAQ,UAAU,OAAO,SAAa,QAAQ,SAAS,QAAQ,MAAM,KAAK,GAAG,SAAS;AAAA,EAC/F;AACF;AAiBO,MAAM,oCAAoC,CAC/C,UACA,EAAE,MAAM,OAAO,YAAY,MACxB;AACH,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAEA,QAAM,YAAY,eAAe,SAAS,QAAQ,KAAK,IAAI,IAAI,KAAK,MAAM,CAAC;AAC3E,MAAI,CAAC,WAAW;AACd;AAAA,EACF;AAEA,QAAM,cAAc,eAAe,UAAU,WAAW;AACxD,MAAI,CAAC,aAAa;AAChB;AAAA,EACF;AAEA,MAAI,CAAC,YAAY,QAAQ,WAAW,GAAG;AACrC;AAAA,EACF;AAEA,QAAM,WAAW,eAAe,YAAY,QAAQ,WAAW,EAAG,QAAQ;AAC1E,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAEA,QAAM,UAAU,eAAe,SAAS,KAAK,UAAU,CAAC;AACxD,MAAI,CAAC,WAAW,CAAC,MAAM,QAAQ,QAAQ,KAAK,GAAG;AAC7C;AAAA,EACF;AAEA,UAAQ,MAAM,OAAO,OAAO,CAAC;AAE7B,MAAI,QAAQ,MAAM,WAAW,GAAG;AAC9B,WAAO,YAAY,QAAQ,WAAW,EAAG,SAAU,KAAK,UAAU;AAAA,EACpE;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,47 @@
1
- import type { ServerObject } from '../schemas/v3.1/strict/openapi-document.js';
1
+ import type { ServerEvents } from '../events/definitions/server.js';
2
+ import { type ServerObject } from '../schemas/v3.1/strict/openapi-document.js';
3
+ import type { WorkspaceDocument } from '../schemas/workspace.js';
2
4
  /**
3
- * Provides mutator functions for managing an array of OpenAPI ServerObject entries.
5
+ * Adds a new ServerObject to the document.
4
6
  *
5
- * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.
6
- * @returns An object with addServer and deleteServer methods.
7
+ * @param document - The document to add the server to
8
+ * @returns the new server object or undefined if the document is not found
7
9
  */
8
- export declare const serverMutators: (target?: ServerObject[]) => {
9
- addServer: (server: ServerObject) => boolean;
10
- deleteServer: (url: string) => boolean;
11
- };
10
+ export declare const addServer: (document: WorkspaceDocument | null) => ServerObject | undefined;
11
+ /**
12
+ * Updates a ServerObject in the document.
13
+ * When the URL changes, intelligently syncs variables by preserving configurations
14
+ * for renamed variables (detected by position) and existing variables.
15
+ *
16
+ * @param document - The document containing the server to update
17
+ * @param index - The index of the server to update
18
+ * @param server - The partial server object with fields to update
19
+ * @returns the updated server object or undefined if the server is not found
20
+ */
21
+ export declare const updateServer: (document: WorkspaceDocument | null, { index, server }: ServerEvents["server:update:server"]) => ServerObject | undefined;
22
+ /**
23
+ * Deletes a ServerObject at the specified index from the target array.
24
+ *
25
+ * @param document - The document to delete the server from
26
+ * @param index - The index of the server to delete.
27
+ */
28
+ export declare const deleteServer: (document: WorkspaceDocument | null, { index }: ServerEvents["server:delete:server"]) => void;
29
+ /**
30
+ * Updates a server variable for the selected server
31
+ *
32
+ * @param document - The document to update the server variables in
33
+ * @param index - The index of the server to update
34
+ * @param key - The key of the variable to update
35
+ * @param value - The new value of the variable
36
+ * @returns the updated variable or undefined if the variable is not found
37
+ */
38
+ export declare const updateServerVariables: (document: WorkspaceDocument | null, { index, key, value }: ServerEvents["server:update:variables"]) => import("../schemas/v3.1/strict/openapi-document.js").ServerVariableObject | undefined;
39
+ /**
40
+ * Updates the selected server for the document
41
+ *
42
+ * @param document - The document to update the selected server in
43
+ * @param index - The index of the server to update
44
+ * @returns the url of the selected server or undefined if the server is not found
45
+ */
46
+ export declare const updateSelectedServer: (document: WorkspaceDocument | null, { url }: ServerEvents["server:update:selected"]) => string | undefined;
12
47
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mutators/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,YAAY,EAAE;wBAMzB,YAAY,KAAG,OAAO;wBAatB,MAAM,KAAG,OAAO;CAc5C,CAAA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mutators/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE/D,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,wCAAwC,CAAA;AAC9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,GAAG,IAAI,KAAG,YAAY,GAAG,SAc7E,CAAA;AAgFD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,YAAY,CAAC,sBAAsB,CAAC,KACtD,YAAY,GAAG,SA+BjB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,iBAAiB,GAAG,IAAI,EAAE,WAAW,YAAY,CAAC,sBAAsB,CAAC,SAY/G,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,iBAAiB,GAAG,IAAI,EAClC,uBAAuB,YAAY,CAAC,yBAAyB,CAAC,sFAkB/D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,iBAAiB,GAAG,IAAI,EAClC,SAAS,YAAY,CAAC,wBAAwB,CAAC,KAC9C,MAAM,GAAG,SAaX,CAAA"}