@scalar/workspace-store 0.21.0 → 0.22.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 (156) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/client.d.ts +14 -2
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +8 -6
  5. package/dist/client.js.map +2 -2
  6. package/dist/events/bus.d.ts +1 -1
  7. package/dist/events/bus.d.ts.map +1 -1
  8. package/dist/events/bus.js.map +1 -1
  9. package/dist/events/definitions/auth.d.ts +2 -1
  10. package/dist/events/definitions/auth.d.ts.map +1 -1
  11. package/dist/events/definitions/document.d.ts +11 -0
  12. package/dist/events/definitions/document.d.ts.map +1 -1
  13. package/dist/events/definitions/index.d.ts +3 -1
  14. package/dist/events/definitions/index.d.ts.map +1 -1
  15. package/dist/events/definitions/operation.d.ts +20 -1
  16. package/dist/events/definitions/operation.d.ts.map +1 -1
  17. package/dist/events/definitions/tabs.d.ts +16 -1
  18. package/dist/events/definitions/tabs.d.ts.map +1 -1
  19. package/dist/events/definitions/tag.d.ts +15 -0
  20. package/dist/events/definitions/tag.d.ts.map +1 -0
  21. package/dist/events/definitions/tag.js +1 -0
  22. package/dist/events/definitions/tag.js.map +7 -0
  23. package/dist/events/definitions/ui.d.ts +118 -61
  24. package/dist/events/definitions/ui.d.ts.map +1 -1
  25. package/dist/events/index.d.ts +1 -1
  26. package/dist/events/index.d.ts.map +1 -1
  27. package/dist/events/index.js.map +2 -2
  28. package/dist/mutators/auth.d.ts +6 -1
  29. package/dist/mutators/auth.d.ts.map +1 -1
  30. package/dist/mutators/document.d.ts +3 -0
  31. package/dist/mutators/document.d.ts.map +1 -1
  32. package/dist/mutators/document.js +24 -0
  33. package/dist/mutators/document.js.map +2 -2
  34. package/dist/mutators/index.d.ts +28 -8
  35. package/dist/mutators/index.d.ts.map +1 -1
  36. package/dist/mutators/index.js +24 -1
  37. package/dist/mutators/index.js.map +2 -2
  38. package/dist/mutators/operation.d.ts +27 -8
  39. package/dist/mutators/operation.d.ts.map +1 -1
  40. package/dist/mutators/operation.js +75 -7
  41. package/dist/mutators/operation.js.map +2 -2
  42. package/dist/mutators/request.d.ts +2 -1
  43. package/dist/mutators/request.d.ts.map +1 -1
  44. package/dist/mutators/request.js.map +1 -1
  45. package/dist/mutators/server.d.ts.map +1 -1
  46. package/dist/mutators/server.js +1 -1
  47. package/dist/mutators/server.js.map +2 -2
  48. package/dist/mutators/tabs.d.ts +44 -0
  49. package/dist/mutators/tabs.d.ts.map +1 -0
  50. package/dist/mutators/tabs.js +133 -0
  51. package/dist/mutators/tabs.js.map +7 -0
  52. package/dist/mutators/tag.d.ts +12 -0
  53. package/dist/mutators/tag.d.ts.map +1 -0
  54. package/dist/mutators/tag.js +19 -0
  55. package/dist/mutators/tag.js.map +7 -0
  56. package/dist/navigation/get-navigation-options.js +4 -4
  57. package/dist/navigation/get-navigation-options.js.map +2 -2
  58. package/dist/navigation/helpers/get-openapi-object.d.ts +35 -0
  59. package/dist/navigation/helpers/get-openapi-object.d.ts.map +1 -0
  60. package/dist/navigation/helpers/get-openapi-object.js +31 -0
  61. package/dist/navigation/helpers/get-openapi-object.js.map +7 -0
  62. package/dist/navigation/helpers/get-operation-entries.d.ts +24 -0
  63. package/dist/navigation/helpers/get-operation-entries.d.ts.map +1 -0
  64. package/dist/navigation/helpers/get-operation-entries.js +33 -0
  65. package/dist/navigation/helpers/get-operation-entries.js.map +7 -0
  66. package/dist/navigation/helpers/get-parent-entry.d.ts +15 -0
  67. package/dist/navigation/helpers/get-parent-entry.d.ts.map +1 -0
  68. package/dist/navigation/helpers/get-parent-entry.js +13 -0
  69. package/dist/navigation/helpers/get-parent-entry.js.map +7 -0
  70. package/dist/navigation/helpers/traverse-description.d.ts +0 -1
  71. package/dist/navigation/helpers/traverse-description.d.ts.map +1 -1
  72. package/dist/navigation/helpers/traverse-description.js +0 -1
  73. package/dist/navigation/helpers/traverse-description.js.map +2 -2
  74. package/dist/navigation/helpers/traverse-document.js +1 -1
  75. package/dist/navigation/helpers/traverse-document.js.map +2 -2
  76. package/dist/navigation/helpers/traverse-paths.js +1 -1
  77. package/dist/navigation/helpers/traverse-paths.js.map +1 -1
  78. package/dist/navigation/helpers/traverse-tags.d.ts.map +1 -1
  79. package/dist/navigation/helpers/traverse-tags.js +2 -2
  80. package/dist/navigation/helpers/traverse-tags.js.map +2 -2
  81. package/dist/navigation/helpers/utils.d.ts +2 -1
  82. package/dist/navigation/helpers/utils.d.ts.map +1 -1
  83. package/dist/navigation/helpers/utils.js.map +1 -1
  84. package/dist/navigation/index.d.ts +2 -1
  85. package/dist/navigation/index.d.ts.map +1 -1
  86. package/dist/navigation/index.js +5 -3
  87. package/dist/navigation/index.js.map +2 -2
  88. package/dist/schemas/extensions/operation/index.d.ts +4 -1
  89. package/dist/schemas/extensions/operation/index.d.ts.map +1 -1
  90. package/dist/schemas/extensions/operation/index.js +22 -0
  91. package/dist/schemas/extensions/operation/index.js.map +3 -3
  92. package/dist/schemas/extensions/operation/x-code-samples.d.ts +0 -5
  93. package/dist/schemas/extensions/operation/x-code-samples.d.ts.map +1 -1
  94. package/dist/schemas/extensions/operation/x-code-samples.js +0 -1
  95. package/dist/schemas/extensions/operation/x-code-samples.js.map +2 -2
  96. package/dist/schemas/extensions/operation/x-post-response.d.ts +0 -18
  97. package/dist/schemas/extensions/operation/x-post-response.d.ts.map +1 -1
  98. package/dist/schemas/extensions/operation/x-post-response.js.map +1 -1
  99. package/dist/schemas/extensions/tag/x-tag-groups.d.ts +2 -13
  100. package/dist/schemas/extensions/tag/x-tag-groups.d.ts.map +1 -1
  101. package/dist/schemas/extensions/tag/x-tag-groups.js +0 -1
  102. package/dist/schemas/extensions/tag/x-tag-groups.js.map +2 -2
  103. package/dist/schemas/extensions/workspace/index.d.ts +4 -0
  104. package/dist/schemas/extensions/workspace/index.d.ts.map +1 -0
  105. package/dist/schemas/extensions/workspace/index.js +15 -0
  106. package/dist/schemas/extensions/workspace/index.js.map +7 -0
  107. package/dist/schemas/extensions/workspace/x-scalar-tabs.d.ts +36 -0
  108. package/dist/schemas/extensions/workspace/x-scalar-tabs.d.ts.map +1 -0
  109. package/dist/schemas/extensions/workspace/x-scalar-tabs.js +16 -0
  110. package/dist/schemas/extensions/workspace/x-scalar-tabs.js.map +7 -0
  111. package/dist/schemas/inmemory-workspace.d.ts +5 -6
  112. package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
  113. package/dist/schemas/navigation.d.ts +8 -0
  114. package/dist/schemas/navigation.d.ts.map +1 -1
  115. package/dist/schemas/navigation.js.map +1 -1
  116. package/dist/schemas/reference-config/index.d.ts +2 -3
  117. package/dist/schemas/reference-config/index.d.ts.map +1 -1
  118. package/dist/schemas/reference-config/settings.d.ts +2 -3
  119. package/dist/schemas/reference-config/settings.d.ts.map +1 -1
  120. package/dist/schemas/v3.1/strict/header.d.ts +0 -45
  121. package/dist/schemas/v3.1/strict/header.d.ts.map +1 -1
  122. package/dist/schemas/v3.1/strict/header.js +1 -3
  123. package/dist/schemas/v3.1/strict/header.js.map +2 -2
  124. package/dist/schemas/v3.1/strict/oauth-flow.d.ts +0 -99
  125. package/dist/schemas/v3.1/strict/oauth-flow.d.ts.map +1 -1
  126. package/dist/schemas/v3.1/strict/oauth-flow.js +0 -7
  127. package/dist/schemas/v3.1/strict/oauth-flow.js.map +2 -2
  128. package/dist/schemas/v3.1/strict/openapi-document.d.ts +71 -104
  129. package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
  130. package/dist/schemas/v3.1/strict/openapi-document.js +0 -1
  131. package/dist/schemas/v3.1/strict/openapi-document.js.map +2 -2
  132. package/dist/schemas/v3.1/strict/parameter.d.ts +1 -101
  133. package/dist/schemas/v3.1/strict/parameter.d.ts.map +1 -1
  134. package/dist/schemas/v3.1/strict/parameter.js +1 -4
  135. package/dist/schemas/v3.1/strict/parameter.js.map +2 -2
  136. package/dist/schemas/v3.1/strict/ref-definitions.d.ts +0 -1
  137. package/dist/schemas/v3.1/strict/ref-definitions.d.ts.map +1 -1
  138. package/dist/schemas/v3.1/strict/ref-definitions.js +0 -2
  139. package/dist/schemas/v3.1/strict/ref-definitions.js.map +2 -2
  140. package/dist/schemas/v3.1/strict/schema.d.ts +28 -11
  141. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  142. package/dist/schemas/v3.1/strict/schema.js +2 -2
  143. package/dist/schemas/v3.1/strict/schema.js.map +2 -2
  144. package/dist/schemas/v3.1/strict/security-scheme.d.ts +1 -54
  145. package/dist/schemas/v3.1/strict/security-scheme.d.ts.map +1 -1
  146. package/dist/schemas/v3.1/strict/security-scheme.js +0 -5
  147. package/dist/schemas/v3.1/strict/security-scheme.js.map +2 -2
  148. package/dist/schemas/workspace-specification/config.d.ts +2 -3
  149. package/dist/schemas/workspace-specification/config.d.ts.map +1 -1
  150. package/dist/schemas/workspace-specification/index.d.ts +2 -3
  151. package/dist/schemas/workspace-specification/index.d.ts.map +1 -1
  152. package/dist/schemas/workspace.d.ts +35 -22
  153. package/dist/schemas/workspace.d.ts.map +1 -1
  154. package/dist/schemas/workspace.js +11 -6
  155. package/dist/schemas/workspace.js.map +2 -2
  156. package/package.json +50 -36
@@ -82,7 +82,7 @@ import {
82
82
  updateSelectedSecuritySchemes
83
83
  } from "./auth.js";
84
84
  import { deleteCookie, upsertCookie } from "./cookie.js";
85
- import { toggleSecurity, updateDocumentIcon, updateWatchMode } from "./document.js";
85
+ import { createEmptyDocument, toggleSecurity, updateDocumentIcon, updateWatchMode } from "./document.js";
86
86
  import {
87
87
  upsertEnvironment,
88
88
  upsertEnvironmentVariable
@@ -90,6 +90,7 @@ import {
90
90
  import {
91
91
  addOperationParameter,
92
92
  addOperationRequestBodyFormRow,
93
+ createOperation,
93
94
  deleteAllOperationParameters,
94
95
  deleteOperationParameter,
95
96
  deleteOperationRequestBodyFormRow,
@@ -108,18 +109,39 @@ import {
108
109
  updateServer,
109
110
  updateServerVariables
110
111
  } from "./server.js";
112
+ import {
113
+ addTab,
114
+ closeOtherTabs,
115
+ closeTab,
116
+ focusLastTab,
117
+ focusTab,
118
+ navigateNextTab,
119
+ navigatePreviousTab,
120
+ updateTabs
121
+ } from "./tabs.js";
122
+ import { createTag } from "./tag.js";
111
123
  import { updateActiveProxy, updateColorMode, updateTheme } from "./workspace.js";
112
124
  export {
113
125
  addOperationParameter,
114
126
  addOperationRequestBodyFormRow,
115
127
  addServer,
128
+ addTab,
129
+ closeOtherTabs,
130
+ closeTab,
131
+ createEmptyDocument,
132
+ createOperation,
133
+ createTag,
116
134
  deleteAllOperationParameters,
117
135
  deleteCookie,
118
136
  deleteOperationParameter,
119
137
  deleteOperationRequestBodyFormRow,
120
138
  deleteSecurityScheme,
121
139
  deleteServer,
140
+ focusLastTab,
141
+ focusTab,
122
142
  generateClientMutators,
143
+ navigateNextTab,
144
+ navigatePreviousTab,
123
145
  toggleSecurity,
124
146
  updateActiveProxy,
125
147
  updateColorMode,
@@ -138,6 +160,7 @@ export {
138
160
  updateSelectedServer,
139
161
  updateServer,
140
162
  updateServerVariables,
163
+ updateTabs,
141
164
  updateTheme,
142
165
  updateWatchMode,
143
166
  upsertCookie,
@@ -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 { 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 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 { updateActiveProxy, updateColorMode, updateTheme } from './workspace'\n"],
5
- "mappings": "AAEA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AAWhC,SAAS,uBAAuB,OAAuB;AAO5D,QAAM,iBAAiB,CAAC,WAA4B;AAMlD,UAAMA,aAAY,CAAC,WAAkC;AACnD,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,MACT;AACA,aAAO,KAAK,MAAM;AAClB,aAAO;AAAA,IACT;AAOA,UAAMC,gBAAe,CAAC,QAAyB;AAC7C,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,MACT;AACA,YAAM,YAAY,CAAC,GAAG,OA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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,gBAAgB,oBAAoB,uBAAuB;AACpE;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,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB,iBAAiB,mBAAmB;",
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": "AAEA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AAWhC,SAAS,uBAAuB,OAAuB;AAO5D,QAAM,iBAAiB,CAAC,WAA4B;AAMlD,UAAMA,aAAY,CAAC,WAAkC;AACnD,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,MACT;AACA,aAAO,KAAK,MAAM;AAClB,aAAO;AAAA,IACT;AAOA,UAAMC,gBAAe,CAAC,QAAyB;AAC7C,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,MACT;AACA,YAAM,YAAY,CAAC,GAAG,OAAO,OAAO,CAAC,OAAO,GAAG,QAAQ,GAAG,CAAC;AAC3D,aAAO,OAAO,GAAG,OAAO,MAAM;AAC9B,aAAO,KAAK,GAAG,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AA,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;",
6
6
  "names": ["addServer", "deleteServer"]
7
7
  }
@@ -1,4 +1,5 @@
1
1
  import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
+ import type { WorkspaceStore } from '../client.js';
2
3
  import type { OperationEvents } from '../events/definitions/operation.js';
3
4
  import type { WorkspaceDocument } from '../schemas.js';
4
5
  /**
@@ -30,9 +31,23 @@ export type OperationMeta = {
30
31
  export type OperationExampleMeta = OperationMeta & {
31
32
  exampleKey: string;
32
33
  };
33
- /** ------------------------------------------------------------------------------------------------
34
- * Operation Draft Mutators
35
- * ------------------------------------------------------------------------------------------------ */
34
+ /**
35
+ * Creates a new operation at a specific path and method in the document.
36
+ * Automatically normalizes the path to ensure it starts with a slash.
37
+ *
38
+ * Returns the normalized path if successful, undefined otherwise.
39
+ *
40
+ * Example:
41
+ * ```ts
42
+ * createOperation(
43
+ * document,
44
+ * 'users',
45
+ * 'get',
46
+ * { tags: ['Users'] },
47
+ * )
48
+ * ```
49
+ */
50
+ export declare const createOperation: (workspaceStore: WorkspaceStore | null, payload: OperationEvents["operation:create:operation"]) => string | undefined;
36
51
  /**
37
52
  * Updates the `summary` of an operation.
38
53
  * Safely no-ops if the document or operation does not exist.
@@ -49,21 +64,25 @@ export type OperationExampleMeta = OperationMeta & {
49
64
  */
50
65
  export declare const updateOperationSummary: (document: WorkspaceDocument | null, { meta, payload: { summary } }: OperationEvents["operation:update:summary"]) => void;
51
66
  /**
52
- * Stores the chosen HTTP method under `x-scalar-method` on the operation.
53
- * This does not move the operation to a different method slot under `paths`;
54
- * it records the desired method as an extension for downstream consumers.
67
+ * Updates the HTTP method of an operation and moves it to the new method slot.
68
+ * This function:
69
+ * 1. Moves the operation from the old method to the new method under paths
70
+ * 2. Updates x-scalar-order to maintain the operation's position in the sidebar
71
+ * 3. Rebuilds the sidebar to reflect the changes
72
+ *
55
73
  * Safely no-ops if the document or operation does not exist.
56
74
  *
57
75
  * Example:
58
76
  * ```ts
59
- * updateOperationMethodDraft({
77
+ * updateOperationMethod({
60
78
  * document,
79
+ * store,
61
80
  * meta: { method: 'get', path: '/users' },
62
81
  * payload: { method: 'post' },
63
82
  * })
64
83
  * ```
65
84
  */
66
- export declare const updateOperationMethod: (document: WorkspaceDocument | null, { meta, payload: { method } }: OperationEvents["operation:update:method"]) => void;
85
+ export declare const updateOperationMethod: (document: WorkspaceDocument | null, store: WorkspaceStore | null, { meta, payload: { method } }: OperationEvents["operation:update:method"], callback?: (success: boolean) => void) => void;
67
86
  /**
68
87
  * Moves the operation to a new path in the document and synchronizes path
69
88
  * parameters in `operation.parameters` with the placeholders present in 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;AAGnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAGrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAKlD;;;;;;;;GAQG;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,CAAC,SAanE,CAAA;AAED;;sGAEsG;AAEtG;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qCAAqC,GAChD,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,eAAe,CAAC,0CAA0C,CAAC,SAwB/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,SAqDrF,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iCAAiC,GAC5C,UAAU,iBAAiB,GAAG,IAAI,EAClC,uCAAuC,eAAe,CAAC,sCAAsC,CAAC,SAqC/F,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,GAC5C,UAAU,iBAAiB,GAAG,IAAI,EAClC,8BAA8B,eAAe,CAAC,sCAAsC,CAAC,SAmCtF,CAAA"}
@@ -1,6 +1,12 @@
1
+ import { isHttpMethod } from "@scalar/helpers/http/is-http-method";
2
+ import { preventPollution } from "@scalar/helpers/object/prevent-pollution";
1
3
  import { findVariables } from "@scalar/helpers/regex/find-variables";
2
4
  import { getResolvedRef } from "../helpers/get-resolved-ref.js";
3
5
  import { unpackProxyObject } from "../helpers/unpack-proxy.js";
6
+ import { getOpenapiObject } from "../navigation/index.js";
7
+ import { getNavigationOptions } from "../navigation/get-navigation-options.js";
8
+ import { canHaveOrder } from "../navigation/helpers/get-openapi-object.js";
9
+ import { getOperationEntries } from "../navigation/helpers/get-operation-entries.js";
4
10
  import { isContentTypeParameterObject } from "../schemas/v3.1/strict/type-guards.js";
5
11
  const getParameterPositions = (path, parameters) => {
6
12
  const positions = {};
@@ -67,6 +73,26 @@ const syncParametersForPathChange = (newPath, oldPath, existingParameters) => {
67
73
  }
68
74
  return [...syncedPathParameters, ...nonPathParameters];
69
75
  };
76
+ const createOperation = (workspaceStore, payload) => {
77
+ const document = workspaceStore?.workspace.documents[payload.documentName];
78
+ if (!document) {
79
+ payload.callback?.(false);
80
+ return void 0;
81
+ }
82
+ const { path, method, operation } = payload;
83
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
84
+ if (!document.paths) {
85
+ document.paths = {};
86
+ }
87
+ if (!document.paths[normalizedPath]) {
88
+ document.paths[normalizedPath] = {};
89
+ }
90
+ preventPollution(normalizedPath);
91
+ preventPollution(method);
92
+ document.paths[normalizedPath][method] = operation;
93
+ payload.callback?.(true);
94
+ return normalizedPath;
95
+ };
70
96
  const updateOperationSummary = (document, { meta, payload: { summary } }) => {
71
97
  if (!document) {
72
98
  return;
@@ -77,19 +103,60 @@ const updateOperationSummary = (document, { meta, payload: { summary } }) => {
77
103
  }
78
104
  operation.summary = summary;
79
105
  };
80
- const updateOperationMethod = (document, { meta, payload: { method } }) => {
81
- const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
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]);
82
116
  if (!operation) {
83
117
  console.error("Operation not found", { meta, document });
84
118
  return;
85
119
  }
86
- const path = document?.paths?.[meta.path];
87
- if (!path) {
88
- console.error("Path not found", { meta, document });
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}`);
124
+ entries?.forEach((entry) => {
125
+ if (!canHaveOrder(entry.parent)) {
126
+ return;
127
+ }
128
+ const parentOpenAPIObject = getOpenapiObject({ store, entry: entry.parent });
129
+ if (!parentOpenAPIObject || !("x-scalar-order" in parentOpenAPIObject)) {
130
+ return;
131
+ }
132
+ const order = parentOpenAPIObject["x-scalar-order"];
133
+ const index = order?.indexOf(entry.id);
134
+ if (!Array.isArray(order) || typeof index !== "number" || index < 0) {
135
+ return;
136
+ }
137
+ const parentTag = entry.parent.type === "tag" && "name" in parentOpenAPIObject ? { tag: parentOpenAPIObject, id: entry.parent.id } : void 0;
138
+ order[index] = generateId({
139
+ type: "operation",
140
+ path: meta.path,
141
+ method,
142
+ operation,
143
+ parentId: entry.parent.id,
144
+ parentTag
145
+ });
146
+ });
147
+ preventPollution(meta.path);
148
+ const pathItems = document.paths?.[meta.path];
149
+ if (!pathItems) {
89
150
  return;
90
151
  }
91
- path[method] = unpackProxyObject(operation);
92
- delete path[meta.method];
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);
159
+ }
93
160
  };
94
161
  const updateOperationPath = (document, { meta, payload: { path } }) => {
95
162
  if (!document) {
@@ -362,6 +429,7 @@ const deleteOperationRequestBodyFormRow = (document, { meta, index, contentType
362
429
  export {
363
430
  addOperationParameter,
364
431
  addOperationRequestBodyFormRow,
432
+ createOperation,
365
433
  deleteAllOperationParameters,
366
434
  deleteOperationParameter,
367
435
  deleteOperationRequestBodyFormRow,
@@ -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'\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,aAAW,aAAa,YAAY;AAClC,UAAM,WAAW,KAAK,QAAQ,IAAI,SAAS,GAAG;AAC9C,QAAI,aAAa,IAAI;AACnB,gBAAU,SAAS,IAAI;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AM,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;",
4
+ "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport { isHttpMethod } from '@scalar/helpers/http/is-http-method'\nimport { preventPollution } from '@scalar/helpers/object/prevent-pollution'\nimport { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { WorkspaceStore } from '@/client'\nimport type { OperationEvents } from '@/events/definitions/operation'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport { getOpenapiObject } from '@/navigation'\nimport { getNavigationOptions } from '@/navigation/get-navigation-options'\nimport { canHaveOrder } from '@/navigation/helpers/get-openapi-object'\nimport { getOperationEntries } from '@/navigation/helpers/get-operation-entries'\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 * Creates a new operation at a specific path and method in the document.\n * Automatically normalizes the path to ensure it starts with a slash.\n *\n * Returns the normalized path if successful, undefined otherwise.\n *\n * Example:\n * ```ts\n * createOperation(\n * document,\n * 'users',\n * 'get',\n * { tags: ['Users'] },\n * )\n * ```\n */\nexport const createOperation = (\n workspaceStore: WorkspaceStore | null,\n payload: OperationEvents['operation:create:operation'],\n): string | undefined => {\n const document = workspaceStore?.workspace.documents[payload.documentName]\n if (!document) {\n payload.callback?.(false)\n return undefined\n }\n\n const { path, method, operation } = payload\n\n /** Ensure the path starts with a slash */\n const normalizedPath = path.startsWith('/') ? path : `/${path}`\n\n /** Create the operation in the document */\n if (!document.paths) {\n document.paths = {}\n }\n\n if (!document.paths[normalizedPath]) {\n document.paths[normalizedPath] = {}\n }\n\n /** Prevent pollution of the path and method */\n preventPollution(normalizedPath)\n preventPollution(method)\n\n /** Create the operation in the document */\n document.paths[normalizedPath][method] = operation\n\n payload.callback?.(true)\n return normalizedPath\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 * Updates the HTTP method of an operation and moves it to the new method slot.\n * This function:\n * 1. Moves the operation from the old method to the new method under paths\n * 2. Updates x-scalar-order to maintain the operation's position in the sidebar\n * 3. Rebuilds the sidebar to reflect the changes\n *\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationMethod({\n * document,\n * store,\n * meta: { method: 'get', path: '/users' },\n * payload: { method: 'post' },\n * })\n * ```\n */\nexport const updateOperationMethod = (\n document: WorkspaceDocument | null,\n store: WorkspaceStore | null,\n { meta, payload: { method } }: OperationEvents['operation:update:method'],\n callback?: (success: boolean) => void,\n) => {\n // If the method has not changed, no need to do anything\n if (meta.method === method || !isHttpMethod(method)) {\n return\n }\n\n const documentName = document?.['x-scalar-navigation']?.name\n if (!document?.['x-scalar-navigation'] || !documentName || !store) {\n console.error('Document or workspace not found', { document })\n return\n }\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 // Get the document configuration to generate IDs consistently\n // If no store is provided (e.g., in tests), use default configuration\n const documentConfig = store?.getDocumentConfiguration(documentName)\n const { generateId } = getNavigationOptions(documentName, documentConfig)\n\n /** Generate an operations map of the document */\n const operationsMap = getOperationEntries(document['x-scalar-navigation'])\n\n /** Grabs all of the current operation entries for the given path and method */\n const entries = operationsMap.get(`${meta.path}|${meta.method}`)\n\n // Loop over the entries and replace the ID in the x-scalar-order with the new ID\n entries?.forEach((entry) => {\n if (!canHaveOrder(entry.parent)) {\n return\n }\n\n // Ensure we have an x-scalar-order property\n const parentOpenAPIObject = getOpenapiObject({ store, entry: entry.parent })\n if (!parentOpenAPIObject || !('x-scalar-order' in parentOpenAPIObject)) {\n return\n }\n\n const order = parentOpenAPIObject['x-scalar-order']\n const index = order?.indexOf(entry.id)\n if (!Array.isArray(order) || typeof index !== 'number' || index < 0) {\n return\n }\n\n const parentTag =\n entry.parent.type === 'tag' && 'name' in parentOpenAPIObject\n ? { tag: parentOpenAPIObject, id: entry.parent.id }\n : undefined\n\n // Generate the new ID based on whether this is an operation or webhook\n order[index] = generateId({\n type: 'operation',\n path: meta.path,\n method: method,\n operation: operation,\n parentId: entry.parent.id,\n parentTag,\n })\n })\n\n // Prevent assigning dangerous keys to the path items object\n preventPollution(meta.path)\n\n // Now ensure we replace the actual operation in the document\n const pathItems = document.paths?.[meta.path]\n if (!pathItems) {\n return\n }\n\n pathItems[method] = unpackProxyObject(operation)\n delete pathItems[meta.method]\n\n // Rebuild the sidebar with the updated order (if store is available)\n if (store) {\n const success = store.buildSidebar(documentName)\n callback?.(success)\n } else {\n callback?.(true)\n }\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,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAI9B,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAIpC,SAAS,oCAAoC;AAyC7C,MAAM,wBAAwB,CAAC,MAAc,eAA0D;AACrG,QAAM,YAAoC,CAAC;AAE3C,aAAW,aAAa,YAAY;AAClC,UAAM,WAAW,KAAK,QAAQ,IAAI,SAAS,GAAG;AAC9C,QAAI,aAAa,IAAI;AACnB,gBAAU,SAAS,IAAI;AAAA,IACzB;AAAA,EACF;AAEA,SAAO;AACT;AAWA,MAAM,8BAA8B,CAClC,SACA,SACA,uBACqC;AAErC,QAAM,gBAAgB,cAAc,SAAS,EAAE,aAAa,MAAM,YAAY,MAAM,CAAC,EAAE;AAAA,IACrF,CAAC,MAAmB,MAAM;AAAA,EAC5B;AACA,QAAM,gBAAgB,cAAc,SAAS,EAAE,aAAa,MAAM,YAAY,MAAM,CAAC,EAAE;AAAA,IACrF,CAAC,MAAmB,MAAM;AAAA,EAC5B;AAEA,QAAM,eAAe,sBAAsB,SAAS,aAAa;AACjE,QAAM,eAAe,sBAAsB,SAAS,aAAa;AAGjE,QAAM,iBAAmD,CAAC;AAC1D,QAAM,oBAAsD,CAAC;AAE7D,aAAW,SAAS,oBAAoB;AACtC,UAAM,WAAW,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AAe,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,6 +1,6 @@
1
1
  import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
2
  import type { OpenApiDocument } from '../schemas/v3.1/strict/openapi-document.js';
3
- export type OperationIdentifier = {
3
+ type OperationIdentifier = {
4
4
  path: string;
5
5
  method: Exclude<HttpMethod, 'head' | 'options'>;
6
6
  };
@@ -19,4 +19,5 @@ export declare const requestMutators: (document?: OpenApiDocument) => {
19
19
  }) => boolean;
20
20
  deleteRequest: ({ path, method }: OperationIdentifier) => boolean;
21
21
  };
22
+ export {};
22
23
  //# sourceMappingURL=request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/mutators/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAE7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;CAChD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,eAAe;4CAoBrD;QACD,MAAM,EAAE,mBAAmB,CAAA;QAC3B,WAAW,EAAE,mBAAmB,CAAA;KACjC;sCAqDwC,mBAAmB;CA0B7D,CAAA"}
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/mutators/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAE7E,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;CAChD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,eAAe;4CAoBrD;QACD,MAAM,EAAE,mBAAmB,CAAA;QAC3B,WAAW,EAAE,mBAAmB,CAAA;KACjC;sCAqDwC,mBAAmB;CA0B7D,CAAA"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/request.ts"],
4
- "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport type { OpenApiDocument } from '@/schemas/v3.1/strict/openapi-document'\n\nexport type OperationIdentifier = {\n path: string\n method: Exclude<HttpMethod, 'head' | 'options'>\n}\n\n/**\n * Provides mutator functions for managing OpenAPI operations (requests) within a workspace store.\n * This module contains utilities for moving and deleting API operations while maintaining\n * document integrity and preventing conflicts.\n *\n * @param document - The OpenAPI document to operate on\n * @returns Object containing mutator functions for request operations\n */\nexport const requestMutators = (document?: OpenApiDocument) => {\n /**\n * Moves an operation from one path/method to another within the OpenAPI document.\n * This function handles the relocation of API operations while preserving their configuration\n * and preventing accidental overwrites of existing operations.\n *\n * @param source - The current location of the operation to move\n * @param destination - The target location for the operation (path and/or method)\n * @returns true if the operation was successfully moved, false otherwise\n *\n * @example\n * // Move an operation to a completely new path and method\n * moveOperation({\n * source: { path: '/old-endpoint', method: 'get' },\n * destination: { path: '/new-endpoint', method: 'post' }\n * })\n */\n const moveOperation = ({\n source,\n destination,\n }: {\n source: OperationIdentifier\n destination: OperationIdentifier\n }) => {\n if (!document || !document.paths) {\n return false\n }\n\n const pathObject = document.paths[source.path]\n\n if (!pathObject) {\n return false\n }\n\n const operation = pathObject[source.method]\n\n if (!operation) {\n return false\n }\n\n const newPath = destination.path || source.path\n const newMethod = destination.method || source.method\n\n if (document.paths[newPath]?.[newMethod]) {\n // If the new path and method already exist, we should not overwrite it.\n console.warn(`Request already exists at ${newPath} with method ${newMethod}.`)\n return false\n }\n\n // delete the request from the old location\n delete pathObject[source.method]\n\n if (!document.paths[newPath]) {\n // If the new path does not exist, create it\n document.paths[newPath] = {}\n }\n\n document.paths[newPath][newMethod] = operation\n return true\n }\n\n /**\n * Deletes an operation from the OpenAPI document at the specified path and method.\n *\n * @param path - The path of the operation to delete\n * @param method - The HTTP method of the operation to delete\n * @returns void - Returns early if document, path, or operation doesn't exist\n *\n * @example\n * // Delete a GET operation from /users endpoint\n * deleteRequest({ path: '/users', method: 'get' })\n *\n * @example\n * // Delete a POST operation from /auth/login endpoint\n * deleteRequest({ path: '/auth/login', method: 'post' })\n */\n const deleteRequest = ({ path, method }: OperationIdentifier) => {\n if (!document) {\n return false\n }\n\n const pathObject = document?.paths?.[path]\n\n if (!pathObject) {\n return false\n }\n\n const operation = pathObject[method]\n\n if (!operation) {\n return false\n }\n\n // Delete the request by slug\n delete pathObject[method]\n return true\n }\n\n return {\n moveRequest: moveOperation,\n deleteRequest,\n }\n}\n"],
4
+ "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\n\nimport type { OpenApiDocument } from '@/schemas/v3.1/strict/openapi-document'\n\ntype OperationIdentifier = {\n path: string\n method: Exclude<HttpMethod, 'head' | 'options'>\n}\n\n/**\n * Provides mutator functions for managing OpenAPI operations (requests) within a workspace store.\n * This module contains utilities for moving and deleting API operations while maintaining\n * document integrity and preventing conflicts.\n *\n * @param document - The OpenAPI document to operate on\n * @returns Object containing mutator functions for request operations\n */\nexport const requestMutators = (document?: OpenApiDocument) => {\n /**\n * Moves an operation from one path/method to another within the OpenAPI document.\n * This function handles the relocation of API operations while preserving their configuration\n * and preventing accidental overwrites of existing operations.\n *\n * @param source - The current location of the operation to move\n * @param destination - The target location for the operation (path and/or method)\n * @returns true if the operation was successfully moved, false otherwise\n *\n * @example\n * // Move an operation to a completely new path and method\n * moveOperation({\n * source: { path: '/old-endpoint', method: 'get' },\n * destination: { path: '/new-endpoint', method: 'post' }\n * })\n */\n const moveOperation = ({\n source,\n destination,\n }: {\n source: OperationIdentifier\n destination: OperationIdentifier\n }) => {\n if (!document || !document.paths) {\n return false\n }\n\n const pathObject = document.paths[source.path]\n\n if (!pathObject) {\n return false\n }\n\n const operation = pathObject[source.method]\n\n if (!operation) {\n return false\n }\n\n const newPath = destination.path || source.path\n const newMethod = destination.method || source.method\n\n if (document.paths[newPath]?.[newMethod]) {\n // If the new path and method already exist, we should not overwrite it.\n console.warn(`Request already exists at ${newPath} with method ${newMethod}.`)\n return false\n }\n\n // delete the request from the old location\n delete pathObject[source.method]\n\n if (!document.paths[newPath]) {\n // If the new path does not exist, create it\n document.paths[newPath] = {}\n }\n\n document.paths[newPath][newMethod] = operation\n return true\n }\n\n /**\n * Deletes an operation from the OpenAPI document at the specified path and method.\n *\n * @param path - The path of the operation to delete\n * @param method - The HTTP method of the operation to delete\n * @returns void - Returns early if document, path, or operation doesn't exist\n *\n * @example\n * // Delete a GET operation from /users endpoint\n * deleteRequest({ path: '/users', method: 'get' })\n *\n * @example\n * // Delete a POST operation from /auth/login endpoint\n * deleteRequest({ path: '/auth/login', method: 'post' })\n */\n const deleteRequest = ({ path, method }: OperationIdentifier) => {\n if (!document) {\n return false\n }\n\n const pathObject = document?.paths?.[path]\n\n if (!pathObject) {\n return false\n }\n\n const operation = pathObject[method]\n\n if (!operation) {\n return false\n }\n\n // Delete the request by slug\n delete pathObject[method]\n return true\n }\n\n return {\n moveRequest: moveOperation,\n deleteRequest,\n }\n}\n"],
5
5
  "mappings": "AAiBO,MAAM,kBAAkB,CAAC,aAA+B;AAiB7D,QAAM,gBAAgB,CAAC;AAAA,IACrB;AAAA,IACA;AAAA,EACF,MAGM;AACJ,QAAI,CAAC,YAAY,CAAC,SAAS,OAAO;AAChC,aAAO;AAAA,IACT;AAEA,UAAM,aAAa,SAAS,MAAM,OAAO,IAAI;AAE7C,QAAI,CAAC,YAAY;AACf,aAAO;AAAA,IACT;AAEA,UAAM,YAAY,WAAW,OAAO,MAAM;AAE1C,QAAI,CAAC,WAAW;AACd,aAAO;AAAA,IACT;AAEA,UAAM,UAAU,YAAY,QAAQ,OAAO;AAC3C,UAAM,YAAY,YAAY,UAAU,OAAO;AAE/C,QAAI,SAAS,MAAM,OAAO,IAAI,SAAS,GAAG;AAExC,cAAQ,KAAK,6BAA6B,OAAO,gBAAgB,SAAS,GAAG;AAC7E,aAAO;AAAA,IACT;AAGA,WA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O,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"}
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,SAgBX,CAAA"}
@@ -106,7 +106,7 @@ const updateSelectedServer = (document, { url }) => {
106
106
  if (!document.servers?.some((server) => server.url === url)) {
107
107
  return;
108
108
  }
109
- document["x-scalar-selected-server"] = document["x-scalar-selected-server"] === url ? void 0 : url;
109
+ document["x-scalar-selected-server"] = document["x-scalar-selected-server"] === url ? "" : url;
110
110
  return document["x-scalar-selected-server"];
111
111
  };
112
112
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/mutators/server.ts"],
4
- "sourcesContent": ["import { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { ServerEvents } from '@/events/definitions/server'\nimport { coerceValue } from '@/schemas/typebox-coerce'\nimport { type ServerObject, ServerObjectSchema } from '@/schemas/v3.1/strict/openapi-document'\nimport type { WorkspaceDocument } from '@/schemas/workspace'\n\n/**\n * Adds a new ServerObject to the document.\n *\n * @param document - The document to add the server to\n * @returns the new server object or undefined if the document is not found\n */\nexport const addServer = (document: WorkspaceDocument | null): ServerObject | undefined => {\n if (!document) {\n return undefined\n }\n\n const parsed = coerceValue(ServerObjectSchema, {})\n\n // Initialize the servers array if it doesn't exist\n if (!document.servers) {\n document.servers = []\n }\n\n document.servers.push(parsed)\n return parsed\n}\n\n/**\n * Creates a map of variable names to their character positions in a URL.\n * Used to detect renamed variables by position matching.\n */\nconst getVariablePositions = (url: string, variables: readonly string[]): Record<string, number> => {\n const positions: Record<string, number> = {}\n\n for (const varName of variables) {\n const position = url.indexOf(`{${varName}}`)\n if (position !== -1) {\n positions[varName] = position\n }\n }\n\n return positions\n}\n\ntype VariableConfig = {\n description?: string\n default?: string\n enum?: string[]\n}\n\n/**\n * Syncs server variables when the URL changes.\n *\n * Preserves variable configurations by:\n * 1. Keeping variables with matching names\n * 2. Renaming variables at the same position\n * 3. Creating new variables with empty defaults\n */\nconst syncVariablesForUrlChange = (\n newUrl: string,\n oldUrl: string,\n existingVariables: Record<string, VariableConfig>,\n): Record<string, VariableConfig> => {\n // Filter out undefined values from findVariables results\n const oldVariables = findVariables(oldUrl, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newVariables = findVariables(newUrl, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n const oldPositions = getVariablePositions(oldUrl, oldVariables)\n const newPositions = getVariablePositions(newUrl, newVariables)\n\n const usedOldVariables = new Set<string>()\n const syncedVariables: Record<string, VariableConfig> = {}\n\n for (const newVar of newVariables) {\n // Case 1: Variable with same name exists - preserve its config\n if (existingVariables[newVar]) {\n syncedVariables[newVar] = existingVariables[newVar]\n usedOldVariables.add(newVar)\n continue\n }\n\n // Case 2: Check for variable at same position (likely a rename)\n const newVarPosition = newPositions[newVar]\n const oldVarAtPosition = oldVariables.find(\n (oldVar) => oldPositions[oldVar] === newVarPosition && !usedOldVariables.has(oldVar),\n )\n\n if (oldVarAtPosition && existingVariables[oldVarAtPosition]) {\n // Rename: transfer the old variable's config to the new name\n syncedVariables[newVar] = existingVariables[oldVarAtPosition]\n usedOldVariables.add(oldVarAtPosition)\n continue\n }\n\n // Case 3: New variable - create with empty default\n syncedVariables[newVar] = { default: '' }\n }\n\n return syncedVariables\n}\n\n/**\n * Updates a ServerObject in the document.\n * When the URL changes, intelligently syncs variables by preserving configurations\n * for renamed variables (detected by position) and existing variables.\n *\n * @param document - The document containing the server to update\n * @param index - The index of the server to update\n * @param server - The partial server object with fields to update\n * @returns the updated server object or undefined if the server is not found\n */\nexport const updateServer = (\n document: WorkspaceDocument | null,\n { index, server }: ServerEvents['server:update:server'],\n): ServerObject | undefined => {\n const oldServer = document?.servers?.[index]\n\n if (!oldServer) {\n console.error('Server not found at index:', index)\n return undefined\n }\n\n const oldUrl = oldServer.url\n const updatedServer = coerceValue(ServerObjectSchema, { ...oldServer, ...server })\n\n // Sync variables if the URL changed\n const hasUrlChanged = oldUrl && oldUrl !== updatedServer.url\n if (hasUrlChanged) {\n const existingVariables = updatedServer.variables ?? {}\n updatedServer.variables = syncVariablesForUrlChange(updatedServer.url, oldUrl, existingVariables)\n\n // If the selected server is the one being updated, set the selected server to the new server\n if (document['x-scalar-selected-server'] === oldUrl) {\n document['x-scalar-selected-server'] = updatedServer.url\n }\n }\n\n // Ensure servers array exists and update the server at the specified index\n if (!document.servers) {\n document.servers = [updatedServer]\n } else {\n document.servers[index] = updatedServer\n }\n\n return updatedServer\n}\n\n/**\n * Deletes a ServerObject at the specified index from the target array.\n *\n * @param document - The document to delete the server from\n * @param index - The index of the server to delete.\n */\nexport const deleteServer = (document: WorkspaceDocument | null, { index }: ServerEvents['server:delete:server']) => {\n if (!document?.servers) {\n return\n }\n\n const url = document.servers[index]?.url\n document.servers.splice(index, 1)\n\n // If the selected server is the one being deleted, set the selected server to the first one after removal\n if (document['x-scalar-selected-server'] === url) {\n document['x-scalar-selected-server'] = document.servers[0]?.url ?? undefined\n }\n}\n\n/**\n * Updates a server variable for the selected server\n *\n * @param document - The document to update the server variables in\n * @param index - The index of the server to update\n * @param key - The key of the variable to update\n * @param value - The new value of the variable\n * @returns the updated variable or undefined if the variable is not found\n */\nexport const updateServerVariables = (\n document: WorkspaceDocument | null,\n { index, key, value }: ServerEvents['server:update:variables'],\n) => {\n const variable = document?.servers?.[index]?.variables?.[key]\n if (!variable) {\n console.error('Variable not found', key, index)\n return\n }\n\n variable.default = value\n\n // Now we need to make the url reflect the new variable value\n const url = document?.servers?.[index]?.url\n if (!url) {\n console.error('URL not found', index)\n return\n }\n\n return variable\n}\n\n/**\n * Updates the selected server for the document\n *\n * @param document - The document to update the selected server in\n * @param index - The index of the server to update\n * @returns the url of the selected server or undefined if the server is not found\n */\nexport const updateSelectedServer = (\n document: WorkspaceDocument | null,\n { url }: ServerEvents['server:update:selected'],\n): string | undefined => {\n if (!document) {\n return\n }\n\n // If no servers match then return undefined\n if (!document.servers?.some((server) => server.url === url)) {\n return\n }\n\n // [un]set it and return the url\n document['x-scalar-selected-server'] = document['x-scalar-selected-server'] === url ? undefined : url\n return document['x-scalar-selected-server']\n}\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,mBAAmB;AAC5B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Y,GAAG;AAC5D,MAAI,CAAC,UAAU;AACb,YAAQ,MAAM,sBAAsB,KAAK,KAAK;AAC9C;AAAA,EACF;AAEA,WAAS,UAAU;AAGnB,QAAM,MAAM,UAAU,UAAU,KAAK,GAAG;AACxC,MAAI,CAAC,KAAK;AACR,YAAQ,MAAM,iBAAiB,KAAK;AACpC;AAAA,EACF;AAEA,SAAO;AACT;AASO,MAAM,uBAAuB,CAClC,UACA,EAAE,IAAI,MACiB;AACvB,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AAGA,MAAI,CAAC,SAAS,SAAS,KAAK,CAAC,WAAW,OAAO,QAAQ,GAAG,GAAG;AAC3D;AAAA,EACF;AAGA,WAAS,0BAA0B,IAAI,SAAS,0BAA0B,MAAM,MAAM,SAAY;AAClG,SAAO,SAAS,0BAA0B;AAC5C;",
4
+ "sourcesContent": ["import { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { ServerEvents } from '@/events/definitions/server'\nimport { coerceValue } from '@/schemas/typebox-coerce'\nimport { type ServerObject, ServerObjectSchema } from '@/schemas/v3.1/strict/openapi-document'\nimport type { WorkspaceDocument } from '@/schemas/workspace'\n\n/**\n * Adds a new ServerObject to the document.\n *\n * @param document - The document to add the server to\n * @returns the new server object or undefined if the document is not found\n */\nexport const addServer = (document: WorkspaceDocument | null): ServerObject | undefined => {\n if (!document) {\n return undefined\n }\n\n const parsed = coerceValue(ServerObjectSchema, {})\n\n // Initialize the servers array if it doesn't exist\n if (!document.servers) {\n document.servers = []\n }\n\n document.servers.push(parsed)\n return parsed\n}\n\n/**\n * Creates a map of variable names to their character positions in a URL.\n * Used to detect renamed variables by position matching.\n */\nconst getVariablePositions = (url: string, variables: readonly string[]): Record<string, number> => {\n const positions: Record<string, number> = {}\n\n for (const varName of variables) {\n const position = url.indexOf(`{${varName}}`)\n if (position !== -1) {\n positions[varName] = position\n }\n }\n\n return positions\n}\n\ntype VariableConfig = {\n description?: string\n default?: string\n enum?: string[]\n}\n\n/**\n * Syncs server variables when the URL changes.\n *\n * Preserves variable configurations by:\n * 1. Keeping variables with matching names\n * 2. Renaming variables at the same position\n * 3. Creating new variables with empty defaults\n */\nconst syncVariablesForUrlChange = (\n newUrl: string,\n oldUrl: string,\n existingVariables: Record<string, VariableConfig>,\n): Record<string, VariableConfig> => {\n // Filter out undefined values from findVariables results\n const oldVariables = findVariables(oldUrl, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newVariables = findVariables(newUrl, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n const oldPositions = getVariablePositions(oldUrl, oldVariables)\n const newPositions = getVariablePositions(newUrl, newVariables)\n\n const usedOldVariables = new Set<string>()\n const syncedVariables: Record<string, VariableConfig> = {}\n\n for (const newVar of newVariables) {\n // Case 1: Variable with same name exists - preserve its config\n if (existingVariables[newVar]) {\n syncedVariables[newVar] = existingVariables[newVar]\n usedOldVariables.add(newVar)\n continue\n }\n\n // Case 2: Check for variable at same position (likely a rename)\n const newVarPosition = newPositions[newVar]\n const oldVarAtPosition = oldVariables.find(\n (oldVar) => oldPositions[oldVar] === newVarPosition && !usedOldVariables.has(oldVar),\n )\n\n if (oldVarAtPosition && existingVariables[oldVarAtPosition]) {\n // Rename: transfer the old variable's config to the new name\n syncedVariables[newVar] = existingVariables[oldVarAtPosition]\n usedOldVariables.add(oldVarAtPosition)\n continue\n }\n\n // Case 3: New variable - create with empty default\n syncedVariables[newVar] = { default: '' }\n }\n\n return syncedVariables\n}\n\n/**\n * Updates a ServerObject in the document.\n * When the URL changes, intelligently syncs variables by preserving configurations\n * for renamed variables (detected by position) and existing variables.\n *\n * @param document - The document containing the server to update\n * @param index - The index of the server to update\n * @param server - The partial server object with fields to update\n * @returns the updated server object or undefined if the server is not found\n */\nexport const updateServer = (\n document: WorkspaceDocument | null,\n { index, server }: ServerEvents['server:update:server'],\n): ServerObject | undefined => {\n const oldServer = document?.servers?.[index]\n\n if (!oldServer) {\n console.error('Server not found at index:', index)\n return undefined\n }\n\n const oldUrl = oldServer.url\n const updatedServer = coerceValue(ServerObjectSchema, { ...oldServer, ...server })\n\n // Sync variables if the URL changed\n const hasUrlChanged = oldUrl && oldUrl !== updatedServer.url\n if (hasUrlChanged) {\n const existingVariables = updatedServer.variables ?? {}\n updatedServer.variables = syncVariablesForUrlChange(updatedServer.url, oldUrl, existingVariables)\n\n // If the selected server is the one being updated, set the selected server to the new server\n if (document['x-scalar-selected-server'] === oldUrl) {\n document['x-scalar-selected-server'] = updatedServer.url\n }\n }\n\n // Ensure servers array exists and update the server at the specified index\n if (!document.servers) {\n document.servers = [updatedServer]\n } else {\n document.servers[index] = updatedServer\n }\n\n return updatedServer\n}\n\n/**\n * Deletes a ServerObject at the specified index from the target array.\n *\n * @param document - The document to delete the server from\n * @param index - The index of the server to delete.\n */\nexport const deleteServer = (document: WorkspaceDocument | null, { index }: ServerEvents['server:delete:server']) => {\n if (!document?.servers) {\n return\n }\n\n const url = document.servers[index]?.url\n document.servers.splice(index, 1)\n\n // If the selected server is the one being deleted, set the selected server to the first one after removal\n if (document['x-scalar-selected-server'] === url) {\n document['x-scalar-selected-server'] = document.servers[0]?.url ?? undefined\n }\n}\n\n/**\n * Updates a server variable for the selected server\n *\n * @param document - The document to update the server variables in\n * @param index - The index of the server to update\n * @param key - The key of the variable to update\n * @param value - The new value of the variable\n * @returns the updated variable or undefined if the variable is not found\n */\nexport const updateServerVariables = (\n document: WorkspaceDocument | null,\n { index, key, value }: ServerEvents['server:update:variables'],\n) => {\n const variable = document?.servers?.[index]?.variables?.[key]\n if (!variable) {\n console.error('Variable not found', key, index)\n return\n }\n\n variable.default = value\n\n // Now we need to make the url reflect the new variable value\n const url = document?.servers?.[index]?.url\n if (!url) {\n console.error('URL not found', index)\n return\n }\n\n return variable\n}\n\n/**\n * Updates the selected server for the document\n *\n * @param document - The document to update the selected server in\n * @param index - The index of the server to update\n * @returns the url of the selected server or undefined if the server is not found\n */\nexport const updateSelectedServer = (\n document: WorkspaceDocument | null,\n { url }: ServerEvents['server:update:selected'],\n): string | undefined => {\n if (!document) {\n return\n }\n\n // If no servers match then return undefined\n if (!document.servers?.some((server) => server.url === url)) {\n return\n }\n\n /**\n * [un]set it and return the url,\n * we specifically use en empty string to indicate that the user has unset the selected server\n */\n document['x-scalar-selected-server'] = document['x-scalar-selected-server'] === url ? '' : url\n return document['x-scalar-selected-server']\n}\n"],
5
+ "mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,mBAAmB;AAC5B,SAA4B,0BAA0B;AAS/C,MAAM,YAAY,CAAC,aAAiE;AACzF,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,YAAY,oBAAoB,CAAC,CAAC;AAGjD,MAAI,CAAC,SAAS,SAAS;AACrB,aAAS,UAAU,CAAC;AAAA,EACtB;AAEA,WAAS,QAAQ,KAAK,MAAM;AAC5B,SAAO;AACT;AAMA,MAAM,uBAAuB,CAAC,KAAa,cAAyD;AAClG,QAAM,YAAoC,CAAC;AAE3C,aAAW,WAAW,WAAW;AAC/B,UAAM,WAAW,IAAI,QAAQ,IAAI,OAAO,GAAG;AAC3C,QAAI,aAAa,IAAI;AACnB,gBAAU,OAAO,IAAI;AAAA,IACvB;AAAA,EACF;AAEA,SAAO;AACT;AAgBA,MAAM,4BAA4B,CAChC,QACA,QACA,sBACmC;AAEnC,QAAM,eAAe,cAAc,QAAQ,EAAE,aAAa,MAAM,YAAY,MAAM,CAAC,EAAE;AAAA,IACnF,CAAC,MAAmB,MAAM;AAAA,EAC5B;AACA,QAAM,eAAe,cAAc,QAAQ,EAAE,aAAa,MAAM,YAAY,MAAM,CAAC,EAAE;AAAA,IACnF,CAAC,MAAmB,MAAM;AAAA,EAC5B;AAEA,QAAM,eAAe,qBAAqB,QAAQ,YAAY;AAC9D,QAAM,eAAe,qBAAqB,QAAQ,YAAY;AAE9D,QAAM,mBAAmB,oBAAI,IAAY;AACzC,QAAM,kBAAkD,CAAC;AAEzD,aA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