@scalar/workspace-store 0.22.2 → 0.24.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 (91) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +3 -2
  4. package/dist/client.js.map +2 -2
  5. package/dist/events/definitions/document.d.ts +7 -0
  6. package/dist/events/definitions/document.d.ts.map +1 -1
  7. package/dist/events/definitions/hooks.d.ts +25 -0
  8. package/dist/events/definitions/hooks.d.ts.map +1 -0
  9. package/dist/events/definitions/hooks.js +1 -0
  10. package/dist/events/definitions/hooks.js.map +7 -0
  11. package/dist/events/definitions/index.d.ts +2 -1
  12. package/dist/events/definitions/index.d.ts.map +1 -1
  13. package/dist/events/definitions/operation.d.ts +34 -24
  14. package/dist/events/definitions/operation.d.ts.map +1 -1
  15. package/dist/events/definitions/tag.d.ts +9 -2
  16. package/dist/events/definitions/tag.d.ts.map +1 -1
  17. package/dist/events/definitions/ui.d.ts +20 -10
  18. package/dist/events/definitions/ui.d.ts.map +1 -1
  19. package/dist/events/definitions/workspace.d.ts +5 -0
  20. package/dist/events/definitions/workspace.d.ts.map +1 -1
  21. package/dist/helpers/is-non-optional-security-requirement.d.ts +4 -0
  22. package/dist/helpers/is-non-optional-security-requirement.d.ts.map +1 -0
  23. package/dist/helpers/is-non-optional-security-requirement.js +7 -0
  24. package/dist/helpers/is-non-optional-security-requirement.js.map +7 -0
  25. package/dist/helpers/merge-object.d.ts +6 -1
  26. package/dist/helpers/merge-object.d.ts.map +1 -1
  27. package/dist/helpers/merge-object.js +4 -3
  28. package/dist/helpers/merge-object.js.map +2 -2
  29. package/dist/mutators/auth.d.ts.map +1 -1
  30. package/dist/mutators/auth.js +2 -1
  31. package/dist/mutators/auth.js.map +2 -2
  32. package/dist/mutators/document.d.ts +6 -0
  33. package/dist/mutators/document.d.ts.map +1 -1
  34. package/dist/mutators/document.js +7 -0
  35. package/dist/mutators/document.js.map +2 -2
  36. package/dist/mutators/index.d.ts +4 -5
  37. package/dist/mutators/index.d.ts.map +1 -1
  38. package/dist/mutators/index.js +12 -7
  39. package/dist/mutators/index.js.map +2 -2
  40. package/dist/mutators/operation.d.ts +36 -19
  41. package/dist/mutators/operation.d.ts.map +1 -1
  42. package/dist/mutators/operation.js +181 -65
  43. package/dist/mutators/operation.js.map +2 -2
  44. package/dist/mutators/tabs.js +5 -5
  45. package/dist/mutators/tabs.js.map +2 -2
  46. package/dist/mutators/tag.d.ts +12 -0
  47. package/dist/mutators/tag.d.ts.map +1 -1
  48. package/dist/mutators/tag.js +40 -3
  49. package/dist/mutators/tag.js.map +2 -2
  50. package/dist/mutators/workspace.d.ts +8 -0
  51. package/dist/mutators/workspace.d.ts.map +1 -1
  52. package/dist/mutators/workspace.js +7 -0
  53. package/dist/mutators/workspace.js.map +2 -2
  54. package/dist/navigation/helpers/get-operation-entries.d.ts +5 -5
  55. package/dist/navigation/helpers/get-operation-entries.d.ts.map +1 -1
  56. package/dist/navigation/helpers/get-operation-entries.js.map +2 -2
  57. package/dist/navigation/index.d.ts +1 -0
  58. package/dist/navigation/index.d.ts.map +1 -1
  59. package/dist/navigation/index.js +2 -0
  60. package/dist/navigation/index.js.map +2 -2
  61. package/dist/plugins/client/index.d.ts +0 -1
  62. package/dist/plugins/client/index.d.ts.map +1 -1
  63. package/dist/plugins/client/index.js.map +2 -2
  64. package/dist/schemas/extensions/schema/x-examples.d.ts +10 -0
  65. package/dist/schemas/extensions/schema/x-examples.d.ts.map +1 -0
  66. package/dist/schemas/extensions/schema/x-examples.js +8 -0
  67. package/dist/schemas/extensions/schema/x-examples.js.map +7 -0
  68. package/dist/schemas/inmemory-workspace.d.ts +28 -4
  69. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  70. package/dist/schemas/reference-config/index.d.ts +16 -4
  71. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  72. package/dist/schemas/reference-config/index.js.map +2 -2
  73. package/dist/schemas/reference-config/settings.d.ts +13 -1
  74. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  75. package/dist/schemas/v3.1/strict/openapi-document.d.ts +442 -34
  76. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  77. package/dist/schemas/v3.1/strict/schema.d.ts +16 -1
  78. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  79. package/dist/schemas/v3.1/strict/schema.js +2 -0
  80. package/dist/schemas/v3.1/strict/schema.js.map +2 -2
  81. package/dist/schemas/v3.1/strict/security-requirement.d.ts +4 -4
  82. package/dist/schemas/v3.1/strict/security-requirement.d.ts.map +1 -1
  83. package/dist/schemas/v3.1/strict/security-requirement.js +6 -4
  84. package/dist/schemas/v3.1/strict/security-requirement.js.map +2 -2
  85. package/dist/schemas/workspace-specification/config.d.ts +14 -2
  86. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  87. package/dist/schemas/workspace-specification/index.d.ts +15 -3
  88. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  89. package/dist/schemas/workspace.d.ts +93 -9
  90. package/dist/schemas/workspace.d.ts.map +1 -1
  91. package/package.json +9 -9
@@ -82,7 +82,7 @@ import {
82
82
  updateSelectedSecuritySchemes
83
83
  } from "./auth.js";
84
84
  import { deleteCookie, upsertCookie } from "./cookie.js";
85
- import { createEmptyDocument, toggleSecurity, updateDocumentIcon, updateWatchMode } from "./document.js";
85
+ import { createEmptyDocument, deleteDocument, toggleSecurity, updateDocumentIcon, updateWatchMode } from "./document.js";
86
86
  import {
87
87
  upsertEnvironment,
88
88
  upsertEnvironmentVariable
@@ -92,11 +92,12 @@ import {
92
92
  addOperationRequestBodyFormRow,
93
93
  createOperation,
94
94
  deleteAllOperationParameters,
95
+ deleteOperation,
96
+ deleteOperationExample,
95
97
  deleteOperationParameter,
96
98
  deleteOperationRequestBodyFormRow,
97
- updateOperationMethod,
98
99
  updateOperationParameter,
99
- updateOperationPath,
100
+ updateOperationPathMethod,
100
101
  updateOperationRequestBodyContentType,
101
102
  updateOperationRequestBodyExample,
102
103
  updateOperationRequestBodyFormRow,
@@ -119,8 +120,8 @@ import {
119
120
  navigatePreviousTab,
120
121
  updateTabs
121
122
  } from "./tabs.js";
122
- import { createTag } from "./tag.js";
123
- import { updateActiveProxy, updateColorMode, updateTheme } from "./workspace.js";
123
+ import { createTag, deleteTag } from "./tag.js";
124
+ import { updateActiveProxy, updateColorMode, updateSelectedClient, updateTheme } from "./workspace.js";
124
125
  export {
125
126
  addOperationParameter,
126
127
  addOperationRequestBodyFormRow,
@@ -133,10 +134,14 @@ export {
133
134
  createTag,
134
135
  deleteAllOperationParameters,
135
136
  deleteCookie,
137
+ deleteDocument,
138
+ deleteOperation,
139
+ deleteOperationExample,
136
140
  deleteOperationParameter,
137
141
  deleteOperationRequestBodyFormRow,
138
142
  deleteSecurityScheme,
139
143
  deleteServer,
144
+ deleteTag,
140
145
  focusLastTab,
141
146
  focusTab,
142
147
  generateClientMutators,
@@ -146,15 +151,15 @@ export {
146
151
  updateActiveProxy,
147
152
  updateColorMode,
148
153
  updateDocumentIcon,
149
- updateOperationMethod,
150
154
  updateOperationParameter,
151
- updateOperationPath,
155
+ updateOperationPathMethod,
152
156
  updateOperationRequestBodyContentType,
153
157
  updateOperationRequestBodyExample,
154
158
  updateOperationRequestBodyFormRow,
155
159
  updateOperationSummary,
156
160
  updateSecurityScheme,
157
161
  updateSelectedAuthTab,
162
+ updateSelectedClient,
158
163
  updateSelectedScopes,
159
164
  updateSelectedSecuritySchemes,
160
165
  updateSelectedServer,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/index.ts"],
4
- "sourcesContent": ["/** biome-ignore-all lint/performance/noBarrelFile: Mutators entry point */\nimport type { WorkspaceStore } from '@/client'\nimport { getDocument } from '@/mutators/helpers'\nimport { requestMutators } from '@/mutators/request'\nimport { securitySchemeMutators } from '@/mutators/security-schemes'\nimport type { ServerObject } from '@/schemas/v3.1/strict/openapi-document'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\n *\n * @deprecated use the individual mutators instead, this will be removed after we move fully to the new store\n *\n * @param store - The workspace store containing all documents and workspace-level data\n * @returns An object with mutators for the workspace, the active document, and any named document\n */\nexport function generateClientMutators(store: WorkspaceStore) {\n /**\n * Provides mutator functions for managing an array of OpenAPI ServerObject entries.\n *\n * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.\n * @returns An object with addServer and deleteServer methods.\n */\n const serverMutators = (target?: ServerObject[]) => {\n /**\n * Adds a new ServerObject to the target array.\n * @param server - The ServerObject to add.\n * @returns true if the server was added, false if target is undefined.\n */\n const addServer = (server: ServerObject): boolean => {\n if (!target) {\n return false\n }\n target.push(server)\n return true\n }\n\n /**\n * Deletes a ServerObject at the specified index from the target array.\n * @param index - The index of the server to delete.\n * @returns true if the server was deleted, false if target is undefined.\n */\n const deleteServer = (url: string): boolean => {\n if (!target) {\n return false\n }\n const newTarget = [...target.filter((it) => it.url !== url)]\n target.splice(0, target.length)\n target.push(...newTarget)\n return true\n }\n\n return {\n addServer,\n deleteServer,\n }\n }\n\n /**\n * Returns mutators for a specific document by name.\n *\n * @param documentName - The name of the document to get mutators for\n * @returns An object containing mutators for requests, request examples, security schemes, environments, and cookies\n */\n const documentMutators = (documentName: string) => {\n const document = getDocument(store, documentName)\n\n if (document) {\n // Make sure the document has a servers array\n if (!document.servers) {\n document.servers = []\n }\n\n // Make sure the document has the securitySchema object\n if (!document.components) {\n document.components = {}\n }\n\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n }\n\n return {\n requestMutators: requestMutators(document),\n securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes),\n serverMutators: serverMutators(document?.servers),\n }\n }\n\n /**\n * Returns mutators for the workspace-level configuration.\n *\n * @returns An object containing mutators for environments and cookies at the workspace level\n */\n const workspaceMutators = () => {\n const workspace = store.workspace\n\n // Make sure the workspace has a servers array\n if (!workspace['x-scalar-client-config-servers']) {\n workspace['x-scalar-client-config-servers'] = []\n }\n\n // Make sure the workspace has the securitySchema object\n if (!store.workspace['x-scalar-client-config-security-schemes']) {\n store.workspace['x-scalar-client-config-security-schemes'] = {}\n }\n\n return {\n serverMutators: serverMutators(store.workspace['x-scalar-client-config-servers']),\n securitySchemeMutators: securitySchemeMutators(store.workspace['x-scalar-client-config-security-schemes']),\n }\n }\n\n return {\n /**\n * Returns mutators for the workspace-level configuration.\n */\n workspace: () => workspaceMutators(),\n /**\n * Returns mutators for the currently active document.\n * Falls back to the first document if no active document is set.\n */\n active: () =>\n documentMutators(store.workspace['x-scalar-active-document'] ?? Object.keys(store.workspace.documents)[0] ?? ''),\n /**\n * Returns mutators for a specific document by name.\n *\n * @param name - The name of the document\n */\n doc: (name: string) => documentMutators(name),\n }\n}\n\nexport {\n type AuthMeta,\n deleteSecurityScheme,\n updateSecurityScheme,\n updateSelectedAuthTab,\n updateSelectedScopes,\n updateSelectedSecuritySchemes,\n} from './auth'\nexport { deleteCookie, upsertCookie } from './cookie'\nexport { createEmptyDocument, toggleSecurity, updateDocumentIcon, updateWatchMode } from './document'\nexport {\n upsertEnvironment,\n upsertEnvironmentVariable,\n} from './environment'\nexport {\n type OperationExampleMeta,\n type OperationMeta,\n addOperationParameter,\n addOperationRequestBodyFormRow,\n createOperation,\n deleteAllOperationParameters,\n deleteOperationParameter,\n deleteOperationRequestBodyFormRow,\n updateOperationMethod,\n updateOperationParameter,\n updateOperationPath,\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormRow,\n updateOperationSummary,\n} from './operation'\nexport {\n addServer,\n deleteServer,\n updateSelectedServer,\n updateServer,\n updateServerVariables,\n} from './server'\nexport {\n addTab,\n closeOtherTabs,\n closeTab,\n focusLastTab,\n focusTab,\n navigateNextTab,\n navigatePreviousTab,\n updateTabs,\n} from './tabs'\nexport { createTag } from './tag'\nexport { updateActiveProxy, updateColorMode, updateTheme } from './workspace'\n"],
5
- "mappings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G;AAC/D,YAAM,UAAU,yCAAyC,IAAI,CAAC;AAAA,IAChE;AAEA,WAAO;AAAA,MACL,gBAAgB,eAAe,MAAM,UAAU,gCAAgC,CAAC;AAAA,MAChF,wBAAwB,uBAAuB,MAAM,UAAU,yCAAyC,CAAC;AAAA,IAC3G;AAAA,EACF;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,WAAW,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnC,QAAQ,MACN,iBAAiB,MAAM,UAAU,0BAA0B,KAAK,OAAO,KAAK,MAAM,UAAU,SAAS,EAAE,CAAC,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMjH,KAAK,CAAC,SAAiB,iBAAiB,IAAI;AAAA,EAC9C;AACF;AAEA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,oBAAoB;AAC3C,SAAS,qBAAqB,gBAAgB,oBAAoB,uBAAuB;AACzF;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB,iBAAiB,mBAAmB;",
4
+ "sourcesContent": ["import type { WorkspaceStore } from '@/client'\nimport { getDocument } from '@/mutators/helpers'\nimport { requestMutators } from '@/mutators/request'\nimport { securitySchemeMutators } from '@/mutators/security-schemes'\nimport type { ServerObject } from '@/schemas/v3.1/strict/openapi-document'\n\n/**\n * Generates a set of mutators for managing OpenAPI document and workspace state.\n *\n * @deprecated use the individual mutators instead, this will be removed after we move fully to the new store\n *\n * @param store - The workspace store containing all documents and workspace-level data\n * @returns An object with mutators for the workspace, the active document, and any named document\n */\nexport function generateClientMutators(store: WorkspaceStore) {\n /**\n * Provides mutator functions for managing an array of OpenAPI ServerObject entries.\n *\n * @param target - The array of ServerObject to mutate. If not provided, mutators will be no-ops.\n * @returns An object with addServer and deleteServer methods.\n */\n const serverMutators = (target?: ServerObject[]) => {\n /**\n * Adds a new ServerObject to the target array.\n * @param server - The ServerObject to add.\n * @returns true if the server was added, false if target is undefined.\n */\n const addServer = (server: ServerObject): boolean => {\n if (!target) {\n return false\n }\n target.push(server)\n return true\n }\n\n /**\n * Deletes a ServerObject at the specified index from the target array.\n * @param index - The index of the server to delete.\n * @returns true if the server was deleted, false if target is undefined.\n */\n const deleteServer = (url: string): boolean => {\n if (!target) {\n return false\n }\n const newTarget = [...target.filter((it) => it.url !== url)]\n target.splice(0, target.length)\n target.push(...newTarget)\n return true\n }\n\n return {\n addServer,\n deleteServer,\n }\n }\n\n /**\n * Returns mutators for a specific document by name.\n *\n * @param documentName - The name of the document to get mutators for\n * @returns An object containing mutators for requests, request examples, security schemes, environments, and cookies\n */\n const documentMutators = (documentName: string) => {\n const document = getDocument(store, documentName)\n\n if (document) {\n // Make sure the document has a servers array\n if (!document.servers) {\n document.servers = []\n }\n\n // Make sure the document has the securitySchema object\n if (!document.components) {\n document.components = {}\n }\n\n if (!document.components.securitySchemes) {\n document.components.securitySchemes = {}\n }\n }\n\n return {\n requestMutators: requestMutators(document),\n securitySchemeMutators: securitySchemeMutators(document?.components?.securitySchemes),\n serverMutators: serverMutators(document?.servers),\n }\n }\n\n /**\n * Returns mutators for the workspace-level configuration.\n *\n * @returns An object containing mutators for environments and cookies at the workspace level\n */\n const workspaceMutators = () => {\n const workspace = store.workspace\n\n // Make sure the workspace has a servers array\n if (!workspace['x-scalar-client-config-servers']) {\n workspace['x-scalar-client-config-servers'] = []\n }\n\n // Make sure the workspace has the securitySchema object\n if (!store.workspace['x-scalar-client-config-security-schemes']) {\n store.workspace['x-scalar-client-config-security-schemes'] = {}\n }\n\n return {\n serverMutators: serverMutators(store.workspace['x-scalar-client-config-servers']),\n securitySchemeMutators: securitySchemeMutators(store.workspace['x-scalar-client-config-security-schemes']),\n }\n }\n\n return {\n /**\n * Returns mutators for the workspace-level configuration.\n */\n workspace: () => workspaceMutators(),\n /**\n * Returns mutators for the currently active document.\n * Falls back to the first document if no active document is set.\n */\n active: () =>\n documentMutators(store.workspace['x-scalar-active-document'] ?? Object.keys(store.workspace.documents)[0] ?? ''),\n /**\n * Returns mutators for a specific document by name.\n *\n * @param name - The name of the document\n */\n doc: (name: string) => documentMutators(name),\n }\n}\n\nexport {\n type AuthMeta,\n deleteSecurityScheme,\n updateSecurityScheme,\n updateSelectedAuthTab,\n updateSelectedScopes,\n updateSelectedSecuritySchemes,\n} from './auth'\nexport { deleteCookie, upsertCookie } from './cookie'\nexport { createEmptyDocument, deleteDocument, toggleSecurity, updateDocumentIcon, updateWatchMode } from './document'\nexport {\n upsertEnvironment,\n upsertEnvironmentVariable,\n} from './environment'\nexport {\n type OperationExampleMeta,\n type OperationMeta,\n addOperationParameter,\n addOperationRequestBodyFormRow,\n createOperation,\n deleteAllOperationParameters,\n deleteOperation,\n deleteOperationExample,\n deleteOperationParameter,\n deleteOperationRequestBodyFormRow,\n updateOperationParameter,\n updateOperationPathMethod,\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormRow,\n updateOperationSummary,\n} from './operation'\nexport {\n addServer,\n deleteServer,\n updateSelectedServer,\n updateServer,\n updateServerVariables,\n} from './server'\nexport {\n addTab,\n closeOtherTabs,\n closeTab,\n focusLastTab,\n focusTab,\n navigateNextTab,\n navigatePreviousTab,\n updateTabs,\n} from './tabs'\nexport { createTag, deleteTag } from './tag'\nexport { updateActiveProxy, updateColorMode, updateSelectedCl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,CAAC,MAAM,UAAU,yCAAyC,GAAG;AAC/D,YAAM,UAAU,yCAAyC,IAAI,CAAC;AAAA,IAChE;AAEA,WAAO;AAAA,MACL,gBAAgB,eAAe,MAAM,UAAU,gCAAgC,CAAC;AAAA,MAChF,wBAAwB,uBAAuB,MAAM,UAAU,yCAAyC,CAAC;AAAA,IAC3G;AAAA,EACF;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA,IAIL,WAAW,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA,IAKnC,QAAQ,MACN,iBAAiB,MAAM,UAAU,0BAA0B,KAAK,OAAO,KAAK,MAAM,UAAU,SAAS,EAAE,CAAC,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMjH,KAAK,CAAC,SAAiB,iBAAiB,IAAI;AAAA,EAC9C;AACF;AAEA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,oBAAoB;AAC3C,SAAS,qBAAqB,gBAAgB,gBAAgB,oBAAoB,uBAAuB;AACzG;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,iBAAiB;AACrC,SAAS,mBAAmB,iBAAiB,sBAAsB,mBAAmB;",
6
6
  "names": ["addServer", "deleteServer"]
7
7
  }
@@ -2,6 +2,7 @@ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
2
  import type { WorkspaceStore } from '../client.js';
3
3
  import type { OperationEvents } from '../events/definitions/operation.js';
4
4
  import type { WorkspaceDocument } from '../schemas.js';
5
+ import type { OperationObject, ParameterObject } from '../schemas/v3.1/strict/openapi-document.js';
5
6
  /**
6
7
  * Describes the minimal identity for an operation in the workspace document.
7
8
  * It is used by mutators to find the target operation under `paths`.
@@ -64,43 +65,45 @@ export declare const createOperation: (workspaceStore: WorkspaceStore | null, pa
64
65
  */
65
66
  export declare const updateOperationSummary: (document: WorkspaceDocument | null, { meta, payload: { summary } }: OperationEvents["operation:update:summary"]) => void;
66
67
  /**
67
- * Updates the HTTP method of an operation and moves it to the new method slot.
68
+ * Updates the HTTP method and/or path of an operation and moves it to the new location.
68
69
  * This function:
69
- * 1. Moves the operation from the old method to the new method under paths
70
+ * 1. Moves the operation from the old method/path to the new method/path under paths
70
71
  * 2. Updates x-scalar-order to maintain the operation's position in the sidebar
71
- * 3. Rebuilds the sidebar to reflect the changes
72
+ * 3. Syncs path parameters when the path changes
72
73
  *
73
- * Safely no-ops if the document or operation does not exist.
74
+ * Safely no-ops if nothing has changed, or if the document or operation does not exist.
74
75
  *
75
76
  * Example:
76
77
  * ```ts
77
- * updateOperationMethod({
78
+ * updateOperationPathMethod({
78
79
  * document,
79
80
  * store,
80
81
  * meta: { method: 'get', path: '/users' },
81
- * payload: { method: 'post' },
82
+ * payload: { method: 'post', path: '/api/users' },
82
83
  * })
83
84
  * ```
84
85
  */
85
- export declare const updateOperationMethod: (document: WorkspaceDocument | null, store: WorkspaceStore | null, { meta, payload: { method } }: OperationEvents["operation:update:method"], callback?: (success: boolean) => void) => void;
86
+ export declare const updateOperationPathMethod: (document: WorkspaceDocument | null, store: WorkspaceStore | null, { meta, payload: { method, path } }: OperationEvents["operation:update:pathMethod"], callback: OperationEvents["operation:update:pathMethod"]["callback"]) => void;
86
87
  /**
87
- * Moves the operation to a new path in the document and synchronizes path
88
- * parameters in `operation.parameters` with the placeholders present in the
89
- * provided `path` (e.g. `/users/{id}`). When path parameters change,
90
- * intelligently syncs them by preserving configurations for renamed parameters
91
- * (detected by position) and existing parameters. Existing non-path parameters
92
- * are preserved. The operation is removed from the old path location.
88
+ * Deletes an operation from the workspace
93
89
  *
94
90
  * Example:
95
91
  * ```ts
96
- * updateOperationPath({
92
+ * deleteOperation({
97
93
  * document,
98
- * meta: { method: 'get', path: '/users/{id}' },
99
- * payload: { path: '/users/{userId}' },
94
+ * meta: { method: 'get', path: '/users' },
100
95
  * })
101
96
  * ```
102
97
  */
103
- export declare const updateOperationPath: (document: WorkspaceDocument | null, { meta, payload: { path } }: OperationEvents["operation:update:path"]) => void;
98
+ export declare const deleteOperation: (workspace: WorkspaceStore | null, { meta, documentName }: OperationEvents["operation:delete:operation"]) => void;
99
+ /**
100
+ * Deletes an example with the given exampleKey from operation parameters and request body.
101
+ *
102
+ * - Finds the target operation within the specified document and path/method.
103
+ * - Removes example values matching exampleKey from both parameter-level and content-level examples.
104
+ * - Safely no-ops if the document, operation, or request body does not exist.
105
+ */
106
+ export declare const deleteOperationExample: (workspace: WorkspaceStore | null, { meta: { path, method, exampleKey }, documentName }: OperationEvents["operation:delete:example"]) => void;
104
107
  /** ------------------------------------------------------------------------------------------------
105
108
  * Operation Parameters Mutators
106
109
  * ------------------------------------------------------------------------------------------------ */
@@ -115,7 +118,7 @@ export declare const updateOperationPath: (document: WorkspaceDocument | null, {
115
118
  * document,
116
119
  * type: 'query',
117
120
  * meta: { method: 'get', path: '/search', exampleKey: 'default' },
118
- * payload: { key: 'q', value: 'john', isEnabled: true },
121
+ * payload: { key: 'q', value: 'john', isDisabled: false },
119
122
  * })
120
123
  * ```
121
124
  */
@@ -133,7 +136,7 @@ export declare const addOperationParameter: (document: WorkspaceDocument | null,
133
136
  * type: 'query',
134
137
  * index: 0,
135
138
  * meta: { method: 'get', path: '/search', exampleKey: 'default' },
136
- * payload: { value: 'alice', isEnabled: true },
139
+ * payload: { value: 'alice', isDisabled: false },
137
140
  * })
138
141
  * ```
139
142
  */
@@ -171,6 +174,20 @@ export declare const deleteAllOperationParameters: (document: WorkspaceDocument
171
174
  /** ------------------------------------------------------------------------------------------------
172
175
  * Operation Request Body Mutators
173
176
  * ------------------------------------------------------------------------------------------------ */
177
+ /**
178
+ * Sets a header parameter value for a specific example key.
179
+ * Creates the header parameter if it does not exist, otherwise updates the existing one.
180
+ *
181
+ * Note: This function does not handle parameters with content (ParameterWithContentObject).
182
+ * Those cases are currently unsupported and will no-op.
183
+ */
184
+ export declare const setHeader: ({ operation, type, name, value, exampleKey, }: {
185
+ operation: OperationObject;
186
+ type: ParameterObject["in"];
187
+ name: string;
188
+ value: string;
189
+ exampleKey: string;
190
+ }) => void;
174
191
  /**
175
192
  * Sets the selected request-body content type for the current `exampleKey`.
176
193
  * This stores the selection under `x-scalar-selected-content-type` on the
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/mutators/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAKnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAOrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAKlD;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IACjD,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AA8GD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,cAAc,GAAG,IAAI,EACrC,SAAS,eAAe,CAAC,4BAA4B,CAAC,KACrD,MAAM,GAAG,SA8BX,CAAA;AAED;;;;;;;;;;;;;GAaG;A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BAAgB,eAAe,CAAC,iCAAiC,CAAC,SAanE,CAAA;AAED;;sGAEsG;AAEtG;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,+CAMvB;IACD,SAAS,EAAE,eAAe,CAAA;IAC1B,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;CACnB,SA8CA,CAAA;AAID;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qCAAqC,GAChD,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,eAAe,CAAC,0CAA0C,CAAC,SAmC/E,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,GAC5C,UAAU,iBAAiB,GAAG,IAAI,EAClC,gCAAgC,eAAe,CAAC,oCAAoC,CAAC,SAuCtF,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,8BAA8B,GACzC,UAAU,iBAAiB,GAAG,IAAI,EAClC,gCAAgC,eAAe,CAAC,mCAAmC,CAAC,SAmDrF,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iCAAiC,GAC5C,UAAU,iBAAiB,GAAG,IAAI,EAClC,uCAAuC,eAAe,CAAC,sCAAsC,CAAC,SAwC/F,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,GAC5C,UAAU,iBAAiB,GAAG,IAAI,EAClC,8BAA8B,eAAe,CAAC,sCAAsC,CAAC,SAuCtF,CAAA"}
@@ -1,12 +1,12 @@
1
1
  import { isHttpMethod } from "@scalar/helpers/http/is-http-method";
2
+ import { objectKeys } from "@scalar/helpers/object/object-keys";
2
3
  import { preventPollution } from "@scalar/helpers/object/prevent-pollution";
3
4
  import { findVariables } from "@scalar/helpers/regex/find-variables";
4
5
  import { getResolvedRef } from "../helpers/get-resolved-ref.js";
5
6
  import { unpackProxyObject } from "../helpers/unpack-proxy.js";
6
- import { getOpenapiObject } from "../navigation/index.js";
7
+ import { getOpenapiObject, getOperationEntries } from "../navigation/index.js";
7
8
  import { getNavigationOptions } from "../navigation/get-navigation-options.js";
8
9
  import { canHaveOrder } from "../navigation/helpers/get-openapi-object.js";
9
- import { getOperationEntries } from "../navigation/helpers/get-operation-entries.js";
10
10
  import { isContentTypeParameterObject } from "../schemas/v3.1/strict/type-guards.js";
11
11
  const getParameterPositions = (path, parameters) => {
12
12
  const positions = {};
@@ -90,6 +90,19 @@ const createOperation = (workspaceStore, payload) => {
90
90
  preventPollution(normalizedPath);
91
91
  preventPollution(method);
92
92
  document.paths[normalizedPath][method] = operation;
93
+ const { servers } = operation;
94
+ const firstServer = unpackProxyObject(servers?.[0]);
95
+ for (const server of servers ?? []) {
96
+ if (!document.servers?.some((s) => s.url === server.url)) {
97
+ if (!document.servers) {
98
+ document.servers = [];
99
+ }
100
+ document.servers.push(unpackProxyObject(server));
101
+ }
102
+ }
103
+ if (firstServer) {
104
+ document["x-scalar-selected-server"] = firstServer.url;
105
+ }
93
106
  payload.callback?.(true);
94
107
  return normalizedPath;
95
108
  };
@@ -103,24 +116,14 @@ const updateOperationSummary = (document, { meta, payload: { summary } }) => {
103
116
  }
104
117
  operation.summary = summary;
105
118
  };
106
- const updateOperationMethod = (document, store, { meta, payload: { method } }, callback) => {
107
- if (meta.method === method || !isHttpMethod(method)) {
108
- return;
109
- }
110
- const documentName = document?.["x-scalar-navigation"]?.name;
111
- if (!document?.["x-scalar-navigation"] || !documentName || !store) {
112
- console.error("Document or workspace not found", { document });
113
- return;
114
- }
115
- const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
116
- if (!operation) {
117
- console.error("Operation not found", { meta, document });
118
- return;
119
- }
120
- const documentConfig = store?.getDocumentConfiguration(documentName);
121
- const { generateId } = getNavigationOptions(documentName, documentConfig);
122
- const operationsMap = getOperationEntries(document["x-scalar-navigation"]);
123
- const entries = operationsMap.get(`${meta.path}|${meta.method}`);
119
+ const updateOperationOrderId = ({
120
+ store,
121
+ operation,
122
+ generateId,
123
+ method,
124
+ path,
125
+ entries
126
+ }) => {
124
127
  entries?.forEach((entry) => {
125
128
  if (!canHaveOrder(entry.parent)) {
126
129
  return;
@@ -137,62 +140,114 @@ const updateOperationMethod = (document, store, { meta, payload: { method } }, c
137
140
  const parentTag = entry.parent.type === "tag" && "name" in parentOpenAPIObject ? { tag: parentOpenAPIObject, id: entry.parent.id } : void 0;
138
141
  order[index] = generateId({
139
142
  type: "operation",
140
- path: meta.path,
143
+ path,
141
144
  method,
142
145
  operation,
143
146
  parentId: entry.parent.id,
144
147
  parentTag
145
148
  });
146
149
  });
147
- preventPollution(meta.path);
148
- const pathItems = document.paths?.[meta.path];
149
- if (!pathItems) {
150
+ };
151
+ const updateOperationPathMethod = (document, store, { meta, payload: { method, path } }, callback) => {
152
+ const methodChanged = meta.method !== method;
153
+ const pathChanged = meta.path !== path;
154
+ if (!methodChanged && !pathChanged) {
155
+ callback("no-change");
150
156
  return;
151
157
  }
152
- pathItems[method] = unpackProxyObject(operation);
153
- delete pathItems[meta.method];
154
- if (store) {
155
- const success = store.buildSidebar(documentName);
156
- callback?.(success);
157
- } else {
158
- callback?.(true);
158
+ const finalMethod = methodChanged ? method : meta.method;
159
+ const finalPath = pathChanged ? path : meta.path;
160
+ if (document?.paths?.[finalPath]?.[finalMethod]) {
161
+ callback("conflict");
162
+ return;
159
163
  }
160
- };
161
- const updateOperationPath = (document, { meta, payload: { path } }) => {
162
- if (!document) {
164
+ const documentNavigation = document?.["x-scalar-navigation"];
165
+ if (!documentNavigation || !store) {
166
+ console.error("Document or workspace not found", { document });
163
167
  return;
164
168
  }
165
169
  const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
166
170
  if (!operation) {
171
+ console.error("Operation not found", { meta, document });
167
172
  return;
168
173
  }
169
- if (meta.path === path) {
170
- return;
174
+ if (pathChanged) {
175
+ const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter(
176
+ (v) => v !== void 0
177
+ );
178
+ const newPathParams = findVariables(finalPath, { includePath: true, includeEnv: false }).filter(
179
+ (v) => v !== void 0
180
+ );
181
+ if (oldPathParams.length > 0 || newPathParams.length > 0) {
182
+ const existingParameters = operation.parameters ?? [];
183
+ operation.parameters = syncParametersForPathChange(finalPath, meta.path, existingParameters);
184
+ }
171
185
  }
172
- const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter(
173
- (v) => v !== void 0
174
- );
175
- const newPathParams = findVariables(path, { includePath: true, includeEnv: false }).filter(
176
- (v) => v !== void 0
177
- );
178
- if (oldPathParams.length > 0 || newPathParams.length > 0) {
179
- const existingParameters = operation.parameters ?? [];
180
- operation.parameters = syncParametersForPathChange(path, meta.path, existingParameters);
186
+ const documentConfig = store.getDocumentConfiguration(documentNavigation.name);
187
+ const { generateId } = getNavigationOptions(documentNavigation.name, documentConfig);
188
+ const operationEntriesMap = getOperationEntries(documentNavigation);
189
+ const entries = operationEntriesMap.get(`${meta.path}|${meta.method}`);
190
+ if (entries) {
191
+ updateOperationOrderId({ store, operation, generateId, method: finalMethod, path: finalPath, entries });
181
192
  }
182
193
  if (!document.paths) {
183
194
  document.paths = {};
184
195
  }
185
- if (!document.paths[path]) {
186
- document.paths[path] = {};
196
+ if (!document.paths[finalPath]) {
197
+ document.paths[finalPath] = {};
187
198
  }
188
- document.paths[path][meta.method] = unpackProxyObject(operation);
189
- const oldPath = document.paths[meta.path];
190
- if (oldPath) {
191
- delete oldPath[meta.method];
192
- if (Object.keys(oldPath).length === 0) {
199
+ preventPollution(finalPath);
200
+ preventPollution(meta.path);
201
+ preventPollution(finalMethod);
202
+ document.paths[finalPath][finalMethod] = unpackProxyObject(operation);
203
+ const oldPathItems = document.paths[meta.path];
204
+ if (oldPathItems && isHttpMethod(meta.method)) {
205
+ delete oldPathItems[meta.method];
206
+ if (Object.keys(oldPathItems).length === 0) {
193
207
  delete document.paths[meta.path];
194
208
  }
195
209
  }
210
+ callback("success");
211
+ };
212
+ const deleteOperation = (workspace, { meta, documentName }) => {
213
+ const document = workspace?.workspace.documents[documentName];
214
+ if (!document) {
215
+ return;
216
+ }
217
+ preventPollution(meta.path);
218
+ preventPollution(meta.method);
219
+ delete document.paths?.[meta.path]?.[meta.method];
220
+ if (Object.keys(document.paths?.[meta.path] ?? {}).length === 0) {
221
+ delete document.paths?.[meta.path];
222
+ }
223
+ };
224
+ const deleteOperationExample = (workspace, { meta: { path, method, exampleKey }, documentName }) => {
225
+ const document = workspace?.workspace.documents[documentName];
226
+ if (!document) {
227
+ return;
228
+ }
229
+ const operation = getResolvedRef(document.paths?.[path]?.[method]);
230
+ if (!operation) {
231
+ return;
232
+ }
233
+ operation.parameters?.forEach((parameter) => {
234
+ const resolvedParameter = getResolvedRef(parameter);
235
+ if ("content" in resolvedParameter && resolvedParameter.content) {
236
+ Object.values(resolvedParameter.content).forEach((mediaType) => {
237
+ delete mediaType.examples?.[exampleKey];
238
+ });
239
+ }
240
+ if ("examples" in resolvedParameter && resolvedParameter.examples) {
241
+ delete resolvedParameter.examples?.[exampleKey];
242
+ }
243
+ });
244
+ const requestBody = getResolvedRef(operation.requestBody);
245
+ if (!requestBody) {
246
+ return;
247
+ }
248
+ Object.values(requestBody.content ?? {}).forEach((mediaType) => {
249
+ delete mediaType.examples?.[exampleKey];
250
+ });
196
251
  };
197
252
  const addOperationParameter = (document, { meta, payload, type }) => {
198
253
  if (!document) {
@@ -212,7 +267,7 @@ const addOperationParameter = (document, { meta, payload, type }) => {
212
267
  examples: {
213
268
  [meta.exampleKey]: {
214
269
  value: payload.value,
215
- "x-disabled": !payload.isEnabled
270
+ "x-disabled": Boolean(payload.isDisabled)
216
271
  }
217
272
  }
218
273
  });
@@ -241,12 +296,12 @@ const updateOperationParameter = (document, { meta, type, payload, index }) => {
241
296
  if (!example) {
242
297
  parameter.examples[meta.exampleKey] = {
243
298
  value: payload.value ?? "",
244
- "x-disabled": payload.isEnabled === void 0 ? false : !payload.isEnabled
299
+ "x-disabled": Boolean(payload.isDisabled)
245
300
  };
246
301
  return;
247
302
  }
248
303
  example.value = payload.value ?? example?.value ?? "";
249
- example["x-disabled"] = payload.isEnabled === void 0 ? example["x-disabled"] : !payload.isEnabled;
304
+ example["x-disabled"] = Boolean(payload.isDisabled ?? example["x-disabled"]);
250
305
  };
251
306
  const deleteOperationParameter = (document, { meta, index, type }) => {
252
307
  if (!document) {
@@ -262,7 +317,10 @@ const deleteOperationParameter = (document, { meta, index, type }) => {
262
317
  return;
263
318
  }
264
319
  const actualIndex = operation.parameters?.findIndex((it) => getResolvedRef(it) === parameter);
265
- operation.parameters?.splice(actualIndex, 1);
320
+ operation.parameters = unpackProxyObject(
321
+ operation.parameters?.filter((_, i) => i !== actualIndex),
322
+ { depth: 1 }
323
+ );
266
324
  };
267
325
  const deleteAllOperationParameters = (document, { meta, type }) => {
268
326
  if (!document) {
@@ -274,6 +332,46 @@ const deleteAllOperationParameters = (document, { meta, type }) => {
274
332
  }
275
333
  operation.parameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== type) ?? [];
276
334
  };
335
+ const setHeader = ({
336
+ operation,
337
+ type,
338
+ name,
339
+ value,
340
+ exampleKey
341
+ }) => {
342
+ if (!operation.parameters) {
343
+ operation.parameters = [];
344
+ }
345
+ const existingParameter = operation.parameters.find((param) => {
346
+ const resolvedParam = getResolvedRef(param);
347
+ return resolvedParam.name.toLowerCase() === name.toLowerCase() && resolvedParam.in === type;
348
+ });
349
+ if (!existingParameter) {
350
+ operation.parameters.push({
351
+ in: type,
352
+ name,
353
+ examples: {
354
+ [exampleKey]: {
355
+ value
356
+ }
357
+ }
358
+ });
359
+ return;
360
+ }
361
+ const resolvedParameter = getResolvedRef(existingParameter);
362
+ if (isContentTypeParameterObject(resolvedParameter)) {
363
+ return;
364
+ }
365
+ if (!resolvedParameter.examples) {
366
+ resolvedParameter.examples = {};
367
+ }
368
+ if (!resolvedParameter.examples[exampleKey]) {
369
+ resolvedParameter.examples[exampleKey] = {};
370
+ }
371
+ getResolvedRef(resolvedParameter.examples[exampleKey]).value = value;
372
+ return;
373
+ };
374
+ const SKIP_CONTENT_TYPE_HEADERS = ["other", "none"];
277
375
  const updateOperationRequestBodyContentType = (document, { meta, payload }) => {
278
376
  if (!document) {
279
377
  return;
@@ -293,6 +391,15 @@ const updateOperationRequestBodyContentType = (document, { meta, payload }) => {
293
391
  requestBody["x-scalar-selected-content-type"] = {};
294
392
  }
295
393
  requestBody["x-scalar-selected-content-type"][meta.exampleKey] = payload.contentType;
394
+ if (!SKIP_CONTENT_TYPE_HEADERS.includes(payload.contentType)) {
395
+ setHeader({
396
+ operation,
397
+ name: "Content-Type",
398
+ type: "header",
399
+ exampleKey: meta.exampleKey,
400
+ value: payload.contentType
401
+ });
402
+ }
296
403
  };
297
404
  const updateOperationRequestBodyExample = (document, { meta, payload, contentType }) => {
298
405
  if (!document) {
@@ -356,7 +463,8 @@ const addOperationRequestBodyFormRow = (document, { meta, payload, contentType }
356
463
  value: [
357
464
  {
358
465
  name: payload.key,
359
- value: payload.value
466
+ value: payload.value,
467
+ isDisabled: false
360
468
  }
361
469
  ]
362
470
  };
@@ -364,7 +472,8 @@ const addOperationRequestBodyFormRow = (document, { meta, payload, contentType }
364
472
  }
365
473
  example.value.push({
366
474
  name: payload.key ?? "",
367
- value: payload.value ?? ""
475
+ value: payload.value ?? "",
476
+ isDisabled: false
368
477
  });
369
478
  };
370
479
  const updateOperationRequestBodyFormRow = (document, { meta, index, payload, contentType }) => {
@@ -393,10 +502,12 @@ const updateOperationRequestBodyFormRow = (document, { meta, index, payload, con
393
502
  if (!example || !Array.isArray(example.value)) {
394
503
  return;
395
504
  }
396
- example.value[index] = {
397
- name: payload.key ?? example.value[index]?.name ?? "",
398
- value: payload.value === null ? void 0 : payload.value ?? example.value[index]?.value ?? ""
399
- };
505
+ for (const key of objectKeys(payload)) {
506
+ if (example.value[index]) {
507
+ preventPollution(key, "updateOperationRequestBodyFormRow");
508
+ example.value[index][key === "key" ? "name" : key] = payload[key];
509
+ }
510
+ }
400
511
  };
401
512
  const deleteOperationRequestBodyFormRow = (document, { meta, index, contentType }) => {
402
513
  if (!document) {
@@ -421,7 +532,10 @@ const deleteOperationRequestBodyFormRow = (document, { meta, index, contentType
421
532
  if (!example || !Array.isArray(example.value)) {
422
533
  return;
423
534
  }
424
- example.value.splice(index, 1);
535
+ example.value = unpackProxyObject(
536
+ example.value.filter((_, i) => i !== index),
537
+ { depth: 1 }
538
+ );
425
539
  if (example.value.length === 0) {
426
540
  delete requestBody.content[contentType].examples[meta.exampleKey];
427
541
  }
@@ -431,11 +545,13 @@ export {
431
545
  addOperationRequestBodyFormRow,
432
546
  createOperation,
433
547
  deleteAllOperationParameters,
548
+ deleteOperation,
549
+ deleteOperationExample,
434
550
  deleteOperationParameter,
435
551
  deleteOperationRequestBodyFormRow,
436
- updateOperationMethod,
552
+ setHeader,
437
553
  updateOperationParameter,
438
- updateOperationPath,
554
+ updateOperationPathMethod,
439
555
  updateOperationRequestBodyContentType,
440
556
  updateOperationRequestBodyExample,
441
557
  updateOperationRequestBodyFormRow,