@scalar/workspace-store 0.40.2 → 0.40.3

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 (354) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/client.d.ts +7 -2
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +820 -681
  5. package/dist/entities/auth/index.js +96 -101
  6. package/dist/entities/auth/schema.js +42 -116
  7. package/dist/entities/history/index.js +80 -60
  8. package/dist/entities/history/schema.js +94 -88
  9. package/dist/events/bus.js +146 -93
  10. package/dist/events/definitions/analytics.js +1 -1
  11. package/dist/events/definitions/auth.js +1 -1
  12. package/dist/events/definitions/common.js +1 -1
  13. package/dist/events/definitions/cookie.js +1 -1
  14. package/dist/events/definitions/document.js +1 -1
  15. package/dist/events/definitions/environment.js +1 -1
  16. package/dist/events/definitions/hooks.js +1 -1
  17. package/dist/events/definitions/index.js +1 -1
  18. package/dist/events/definitions/meta.js +1 -1
  19. package/dist/events/definitions/operation.js +1 -1
  20. package/dist/events/definitions/server.js +1 -1
  21. package/dist/events/definitions/tabs.js +1 -1
  22. package/dist/events/definitions/tag.js +1 -1
  23. package/dist/events/definitions/ui.js +1 -1
  24. package/dist/events/definitions/workspace.js +1 -1
  25. package/dist/events/index.js +3 -9
  26. package/dist/events/listeners.js +20 -22
  27. package/dist/events/old-definitions.js +15 -12
  28. package/dist/helpers/deep-clone.js +33 -17
  29. package/dist/helpers/detect-changes-proxy.js +95 -57
  30. package/dist/helpers/general.js +78 -23
  31. package/dist/helpers/generate-unique-value.js +77 -45
  32. package/dist/helpers/get-fetch.js +12 -10
  33. package/dist/helpers/get-resolved-ref.js +11 -10
  34. package/dist/helpers/is-non-optional-security-requirement.js +3 -6
  35. package/dist/helpers/merge-object.js +71 -30
  36. package/dist/helpers/overrides-proxy.js +98 -58
  37. package/dist/helpers/unpack-proxy.js +60 -58
  38. package/dist/mutators/auth.js +358 -230
  39. package/dist/mutators/cookie.js +59 -42
  40. package/dist/mutators/document.js +104 -66
  41. package/dist/mutators/environment.js +97 -72
  42. package/dist/mutators/helpers.js +9 -13
  43. package/dist/mutators/index.js +62 -49
  44. package/dist/mutators/operation/body.js +88 -57
  45. package/dist/mutators/operation/extensions.js +20 -12
  46. package/dist/mutators/operation/helpers/fetch-request-to-har.js +144 -107
  47. package/dist/mutators/operation/helpers/fetch-response-to-har.js +143 -95
  48. package/dist/mutators/operation/helpers/get-parameter-position.js +12 -12
  49. package/dist/mutators/operation/helpers/har-to-operation.js +169 -132
  50. package/dist/mutators/operation/helpers/sync-path-parameters.js +109 -60
  51. package/dist/mutators/operation/history.js +60 -64
  52. package/dist/mutators/operation/index.js +25 -49
  53. package/dist/mutators/operation/operation.js +349 -240
  54. package/dist/mutators/operation/parameters.js +157 -93
  55. package/dist/mutators/server.js +213 -152
  56. package/dist/mutators/tabs.js +173 -130
  57. package/dist/mutators/tag.js +131 -97
  58. package/dist/mutators/workspace.js +72 -42
  59. package/dist/navigation/get-navigation-options.js +97 -84
  60. package/dist/navigation/helpers/get-openapi-object.js +46 -29
  61. package/dist/navigation/helpers/get-operation-entries.js +72 -32
  62. package/dist/navigation/helpers/get-parent-entry.js +16 -12
  63. package/dist/navigation/helpers/get-tag-entries.js +56 -29
  64. package/dist/navigation/helpers/get-tag.js +22 -23
  65. package/dist/navigation/helpers/get-x-keys.js +13 -9
  66. package/dist/navigation/helpers/traverse-description.js +90 -72
  67. package/dist/navigation/helpers/traverse-document.js +111 -98
  68. package/dist/navigation/helpers/traverse-examples.js +35 -31
  69. package/dist/navigation/helpers/traverse-paths.js +118 -106
  70. package/dist/navigation/helpers/traverse-schemas.js +65 -64
  71. package/dist/navigation/helpers/traverse-tags.js +158 -129
  72. package/dist/navigation/helpers/traverse-webhooks.js +96 -90
  73. package/dist/navigation/helpers/update-order-ids.js +59 -51
  74. package/dist/navigation/helpers/utils.js +71 -21
  75. package/dist/navigation/index.js +5 -13
  76. package/dist/navigation/types.js +1 -1
  77. package/dist/persistence/index.js +283 -285
  78. package/dist/persistence/indexdb.js +263 -126
  79. package/dist/plugins/bundler/helpers.js +21 -12
  80. package/dist/plugins/bundler/index.d.ts +7 -0
  81. package/dist/plugins/bundler/index.d.ts.map +1 -1
  82. package/dist/plugins/bundler/index.js +305 -171
  83. package/dist/plugins/client/index.js +1 -5
  84. package/dist/plugins/client/persistence.js +95 -90
  85. package/dist/resolve.js +18 -25
  86. package/dist/schemas/compose.js +6 -7
  87. package/dist/schemas/extensions/document/x-internal.js +3 -7
  88. package/dist/schemas/extensions/document/x-scalar-environments.js +16 -22
  89. package/dist/schemas/extensions/document/x-scalar-icon.js +3 -7
  90. package/dist/schemas/extensions/document/x-scalar-ignore.js +3 -7
  91. package/dist/schemas/extensions/document/x-scalar-is-dirty.js +21 -8
  92. package/dist/schemas/extensions/document/x-scalar-original-document-hash.js +17 -8
  93. package/dist/schemas/extensions/document/x-scalar-registry-meta.js +15 -21
  94. package/dist/schemas/extensions/document/x-scalar-sdk-installation.js +5 -13
  95. package/dist/schemas/extensions/document/x-scalar-watch-mode.js +4 -8
  96. package/dist/schemas/extensions/document/x-tags.js +3 -7
  97. package/dist/schemas/extensions/example/x-disabled.js +17 -7
  98. package/dist/schemas/extensions/general/x-scalar-active-environment.js +4 -7
  99. package/dist/schemas/extensions/general/x-scalar-cookies.js +9 -14
  100. package/dist/schemas/extensions/general/x-scalar-order.js +8 -7
  101. package/dist/schemas/extensions/operation/index.js +4 -23
  102. package/dist/schemas/extensions/operation/x-badge.js +42 -50
  103. package/dist/schemas/extensions/operation/x-code-samples.js +8 -12
  104. package/dist/schemas/extensions/operation/x-draft-examples.js +3 -7
  105. package/dist/schemas/extensions/operation/x-post-response.js +18 -7
  106. package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js +57 -13
  107. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +9 -7
  108. package/dist/schemas/extensions/operation/x-scalar-stability.js +15 -14
  109. package/dist/schemas/extensions/parameter/x-global.js +12 -7
  110. package/dist/schemas/extensions/schema/x-additional-properties-name.js +10 -7
  111. package/dist/schemas/extensions/schema/x-enum-descriptions.js +17 -12
  112. package/dist/schemas/extensions/schema/x-enum-varnames.js +21 -8
  113. package/dist/schemas/extensions/schema/x-examples.js +3 -7
  114. package/dist/schemas/extensions/schema/x-variable.js +3 -7
  115. package/dist/schemas/extensions/security/index.js +1 -1
  116. package/dist/schemas/extensions/security/x-default-scopes.js +16 -7
  117. package/dist/schemas/extensions/security/x-scalar-credentials-location.js +16 -7
  118. package/dist/schemas/extensions/security/x-scalar-security-body.js +14 -7
  119. package/dist/schemas/extensions/security/x-scalar-security-query.js +14 -7
  120. package/dist/schemas/extensions/security/x-scalar-security-secrets.js +66 -37
  121. package/dist/schemas/extensions/security/x-tokenName.js +11 -7
  122. package/dist/schemas/extensions/security/x-use-pkce.js +6 -10
  123. package/dist/schemas/extensions/server/x-scalar-selected-server.js +3 -7
  124. package/dist/schemas/extensions/tag/index.js +1 -1
  125. package/dist/schemas/extensions/tag/x-display-name.js +11 -7
  126. package/dist/schemas/extensions/tag/x-tag-groups.js +13 -15
  127. package/dist/schemas/extensions/workspace/index.js +2 -11
  128. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js +13 -7
  129. package/dist/schemas/extensions/workspace/x-scalar-tabs.js +15 -13
  130. package/dist/schemas/extensions.js +11 -15
  131. package/dist/schemas/inmemory-workspace.js +13 -21
  132. package/dist/schemas/navigation.js +48 -85
  133. package/dist/schemas/reference-config/appearance.js +15 -22
  134. package/dist/schemas/reference-config/features.js +14 -21
  135. package/dist/schemas/reference-config/index.js +42 -44
  136. package/dist/schemas/reference-config/meta.js +11 -18
  137. package/dist/schemas/reference-config/routing.js +7 -14
  138. package/dist/schemas/reference-config/settings.js +10 -17
  139. package/dist/schemas/typebox-coerce.js +23 -6
  140. package/dist/schemas/v3.1/strict/callback.js +6 -12
  141. package/dist/schemas/v3.1/strict/components.js +26 -48
  142. package/dist/schemas/v3.1/strict/contact.js +9 -12
  143. package/dist/schemas/v3.1/strict/discriminator.js +11 -10
  144. package/dist/schemas/v3.1/strict/encoding.js +15 -12
  145. package/dist/schemas/v3.1/strict/example.js +11 -13
  146. package/dist/schemas/v3.1/strict/external-documentation.js +7 -10
  147. package/dist/schemas/v3.1/strict/header.js +27 -28
  148. package/dist/schemas/v3.1/strict/info.js +10 -16
  149. package/dist/schemas/v3.1/strict/license.js +9 -12
  150. package/dist/schemas/v3.1/strict/link.js +22 -19
  151. package/dist/schemas/v3.1/strict/media-type.js +17 -16
  152. package/dist/schemas/v3.1/strict/oauth-flow.js +28 -62
  153. package/dist/schemas/v3.1/strict/oauthflows.js +14 -20
  154. package/dist/schemas/v3.1/strict/openapi-document.js +126 -210
  155. package/dist/schemas/v3.1/strict/operation.js +16 -43
  156. package/dist/schemas/v3.1/strict/parameter.js +27 -35
  157. package/dist/schemas/v3.1/strict/path-item.js +36 -40
  158. package/dist/schemas/v3.1/strict/paths.js +8 -11
  159. package/dist/schemas/v3.1/strict/ref-definitions.js +76 -100
  160. package/dist/schemas/v3.1/strict/reference.js +18 -21
  161. package/dist/schemas/v3.1/strict/request-body.js +8 -16
  162. package/dist/schemas/v3.1/strict/response.js +12 -16
  163. package/dist/schemas/v3.1/strict/responses.js +13 -11
  164. package/dist/schemas/v3.1/strict/schema.js +149 -157
  165. package/dist/schemas/v3.1/strict/security-requirement.js +13 -12
  166. package/dist/schemas/v3.1/strict/security-scheme.js +29 -41
  167. package/dist/schemas/v3.1/strict/server-variable.js +9 -12
  168. package/dist/schemas/v3.1/strict/server.js +10 -13
  169. package/dist/schemas/v3.1/strict/tag.js +11 -20
  170. package/dist/schemas/v3.1/strict/type-guards.js +20 -20
  171. package/dist/schemas/v3.1/strict/xml.js +17 -16
  172. package/dist/schemas/workspace-specification/index.js +11 -23
  173. package/dist/schemas/workspace-specification/info.js +4 -8
  174. package/dist/schemas/workspace.js +25 -51
  175. package/dist/schemas.js +2 -6
  176. package/dist/server.js +286 -176
  177. package/dist/workspace-plugin.js +1 -1
  178. package/package.json +13 -19
  179. package/dist/client.js.map +0 -7
  180. package/dist/entities/auth/index.js.map +0 -7
  181. package/dist/entities/auth/schema.js.map +0 -7
  182. package/dist/entities/history/index.js.map +0 -7
  183. package/dist/entities/history/schema.js.map +0 -7
  184. package/dist/events/bus.js.map +0 -7
  185. package/dist/events/definitions/analytics.js.map +0 -7
  186. package/dist/events/definitions/auth.js.map +0 -7
  187. package/dist/events/definitions/common.js.map +0 -7
  188. package/dist/events/definitions/cookie.js.map +0 -7
  189. package/dist/events/definitions/document.js.map +0 -7
  190. package/dist/events/definitions/environment.js.map +0 -7
  191. package/dist/events/definitions/hooks.js.map +0 -7
  192. package/dist/events/definitions/index.js.map +0 -7
  193. package/dist/events/definitions/meta.js.map +0 -7
  194. package/dist/events/definitions/operation.js.map +0 -7
  195. package/dist/events/definitions/server.js.map +0 -7
  196. package/dist/events/definitions/tabs.js.map +0 -7
  197. package/dist/events/definitions/tag.js.map +0 -7
  198. package/dist/events/definitions/ui.js.map +0 -7
  199. package/dist/events/definitions/workspace.js.map +0 -7
  200. package/dist/events/index.js.map +0 -7
  201. package/dist/events/listeners.js.map +0 -7
  202. package/dist/events/old-definitions.js.map +0 -7
  203. package/dist/helpers/apply-selective-updates.d.ts +0 -19
  204. package/dist/helpers/apply-selective-updates.d.ts.map +0 -1
  205. package/dist/helpers/apply-selective-updates.js +0 -37
  206. package/dist/helpers/apply-selective-updates.js.map +0 -7
  207. package/dist/helpers/deep-clone.js.map +0 -7
  208. package/dist/helpers/detect-changes-proxy.js.map +0 -7
  209. package/dist/helpers/general.js.map +0 -7
  210. package/dist/helpers/generate-unique-value.js.map +0 -7
  211. package/dist/helpers/get-fetch.js.map +0 -7
  212. package/dist/helpers/get-resolved-ref.js.map +0 -7
  213. package/dist/helpers/is-non-optional-security-requirement.js.map +0 -7
  214. package/dist/helpers/merge-object.js.map +0 -7
  215. package/dist/helpers/overrides-proxy.js.map +0 -7
  216. package/dist/helpers/unpack-proxy.js.map +0 -7
  217. package/dist/mutators/auth.js.map +0 -7
  218. package/dist/mutators/cookie.js.map +0 -7
  219. package/dist/mutators/document.js.map +0 -7
  220. package/dist/mutators/environment.js.map +0 -7
  221. package/dist/mutators/helpers.js.map +0 -7
  222. package/dist/mutators/index.js.map +0 -7
  223. package/dist/mutators/operation/body.js.map +0 -7
  224. package/dist/mutators/operation/extensions.js.map +0 -7
  225. package/dist/mutators/operation/helpers/fetch-request-to-har.js.map +0 -7
  226. package/dist/mutators/operation/helpers/fetch-response-to-har.js.map +0 -7
  227. package/dist/mutators/operation/helpers/get-parameter-position.js.map +0 -7
  228. package/dist/mutators/operation/helpers/har-to-operation.js.map +0 -7
  229. package/dist/mutators/operation/helpers/sync-path-parameters.js.map +0 -7
  230. package/dist/mutators/operation/history.js.map +0 -7
  231. package/dist/mutators/operation/index.js.map +0 -7
  232. package/dist/mutators/operation/operation.js.map +0 -7
  233. package/dist/mutators/operation/parameters.js.map +0 -7
  234. package/dist/mutators/server.js.map +0 -7
  235. package/dist/mutators/tabs.js.map +0 -7
  236. package/dist/mutators/tag.js.map +0 -7
  237. package/dist/mutators/workspace.js.map +0 -7
  238. package/dist/navigation/get-navigation-options.js.map +0 -7
  239. package/dist/navigation/helpers/get-openapi-object.js.map +0 -7
  240. package/dist/navigation/helpers/get-operation-entries.js.map +0 -7
  241. package/dist/navigation/helpers/get-parent-entry.js.map +0 -7
  242. package/dist/navigation/helpers/get-tag-entries.js.map +0 -7
  243. package/dist/navigation/helpers/get-tag.js.map +0 -7
  244. package/dist/navigation/helpers/get-x-keys.js.map +0 -7
  245. package/dist/navigation/helpers/traverse-description.js.map +0 -7
  246. package/dist/navigation/helpers/traverse-document.js.map +0 -7
  247. package/dist/navigation/helpers/traverse-examples.js.map +0 -7
  248. package/dist/navigation/helpers/traverse-paths.js.map +0 -7
  249. package/dist/navigation/helpers/traverse-schemas.js.map +0 -7
  250. package/dist/navigation/helpers/traverse-tags.js.map +0 -7
  251. package/dist/navigation/helpers/traverse-webhooks.js.map +0 -7
  252. package/dist/navigation/helpers/update-order-ids.js.map +0 -7
  253. package/dist/navigation/helpers/utils.js.map +0 -7
  254. package/dist/navigation/index.js.map +0 -7
  255. package/dist/navigation/types.js.map +0 -7
  256. package/dist/persistence/index.js.map +0 -7
  257. package/dist/persistence/indexdb.js.map +0 -7
  258. package/dist/plugins/bundler/helpers.js.map +0 -7
  259. package/dist/plugins/bundler/index.js.map +0 -7
  260. package/dist/plugins/client/index.js.map +0 -7
  261. package/dist/plugins/client/persistence.js.map +0 -7
  262. package/dist/resolve.js.map +0 -7
  263. package/dist/schemas/compose.js.map +0 -7
  264. package/dist/schemas/extensions/document/x-internal.js.map +0 -7
  265. package/dist/schemas/extensions/document/x-scalar-environments.js.map +0 -7
  266. package/dist/schemas/extensions/document/x-scalar-icon.js.map +0 -7
  267. package/dist/schemas/extensions/document/x-scalar-ignore.js.map +0 -7
  268. package/dist/schemas/extensions/document/x-scalar-is-dirty.js.map +0 -7
  269. package/dist/schemas/extensions/document/x-scalar-original-document-hash.js.map +0 -7
  270. package/dist/schemas/extensions/document/x-scalar-registry-meta.js.map +0 -7
  271. package/dist/schemas/extensions/document/x-scalar-sdk-installation.js.map +0 -7
  272. package/dist/schemas/extensions/document/x-scalar-watch-mode.js.map +0 -7
  273. package/dist/schemas/extensions/document/x-tags.js.map +0 -7
  274. package/dist/schemas/extensions/example/x-disabled.js.map +0 -7
  275. package/dist/schemas/extensions/general/x-scalar-active-environment.js.map +0 -7
  276. package/dist/schemas/extensions/general/x-scalar-cookies.js.map +0 -7
  277. package/dist/schemas/extensions/general/x-scalar-order.js.map +0 -7
  278. package/dist/schemas/extensions/operation/index.js.map +0 -7
  279. package/dist/schemas/extensions/operation/x-badge.js.map +0 -7
  280. package/dist/schemas/extensions/operation/x-code-samples.js.map +0 -7
  281. package/dist/schemas/extensions/operation/x-draft-examples.js.map +0 -7
  282. package/dist/schemas/extensions/operation/x-post-response.js.map +0 -7
  283. package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js.map +0 -7
  284. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +0 -7
  285. package/dist/schemas/extensions/operation/x-scalar-stability.js.map +0 -7
  286. package/dist/schemas/extensions/parameter/x-global.js.map +0 -7
  287. package/dist/schemas/extensions/schema/x-additional-properties-name.js.map +0 -7
  288. package/dist/schemas/extensions/schema/x-enum-descriptions.js.map +0 -7
  289. package/dist/schemas/extensions/schema/x-enum-varnames.js.map +0 -7
  290. package/dist/schemas/extensions/schema/x-examples.js.map +0 -7
  291. package/dist/schemas/extensions/schema/x-variable.js.map +0 -7
  292. package/dist/schemas/extensions/security/index.js.map +0 -7
  293. package/dist/schemas/extensions/security/x-default-scopes.js.map +0 -7
  294. package/dist/schemas/extensions/security/x-scalar-credentials-location.js.map +0 -7
  295. package/dist/schemas/extensions/security/x-scalar-security-body.js.map +0 -7
  296. package/dist/schemas/extensions/security/x-scalar-security-query.js.map +0 -7
  297. package/dist/schemas/extensions/security/x-scalar-security-secrets.js.map +0 -7
  298. package/dist/schemas/extensions/security/x-tokenName.js.map +0 -7
  299. package/dist/schemas/extensions/security/x-use-pkce.js.map +0 -7
  300. package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +0 -7
  301. package/dist/schemas/extensions/tag/index.js.map +0 -7
  302. package/dist/schemas/extensions/tag/x-display-name.js.map +0 -7
  303. package/dist/schemas/extensions/tag/x-tag-groups.js.map +0 -7
  304. package/dist/schemas/extensions/workspace/index.js.map +0 -7
  305. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js.map +0 -7
  306. package/dist/schemas/extensions/workspace/x-scalar-tabs.js.map +0 -7
  307. package/dist/schemas/extensions.js.map +0 -7
  308. package/dist/schemas/inmemory-workspace.js.map +0 -7
  309. package/dist/schemas/navigation.js.map +0 -7
  310. package/dist/schemas/reference-config/appearance.js.map +0 -7
  311. package/dist/schemas/reference-config/features.js.map +0 -7
  312. package/dist/schemas/reference-config/index.js.map +0 -7
  313. package/dist/schemas/reference-config/meta.js.map +0 -7
  314. package/dist/schemas/reference-config/routing.js.map +0 -7
  315. package/dist/schemas/reference-config/settings.js.map +0 -7
  316. package/dist/schemas/typebox-coerce.js.map +0 -7
  317. package/dist/schemas/v3.1/strict/callback.js.map +0 -7
  318. package/dist/schemas/v3.1/strict/components.js.map +0 -7
  319. package/dist/schemas/v3.1/strict/contact.js.map +0 -7
  320. package/dist/schemas/v3.1/strict/discriminator.js.map +0 -7
  321. package/dist/schemas/v3.1/strict/encoding.js.map +0 -7
  322. package/dist/schemas/v3.1/strict/example.js.map +0 -7
  323. package/dist/schemas/v3.1/strict/external-documentation.js.map +0 -7
  324. package/dist/schemas/v3.1/strict/header.js.map +0 -7
  325. package/dist/schemas/v3.1/strict/info.js.map +0 -7
  326. package/dist/schemas/v3.1/strict/license.js.map +0 -7
  327. package/dist/schemas/v3.1/strict/link.js.map +0 -7
  328. package/dist/schemas/v3.1/strict/media-type.js.map +0 -7
  329. package/dist/schemas/v3.1/strict/oauth-flow.js.map +0 -7
  330. package/dist/schemas/v3.1/strict/oauthflows.js.map +0 -7
  331. package/dist/schemas/v3.1/strict/openapi-document.js.map +0 -7
  332. package/dist/schemas/v3.1/strict/operation.js.map +0 -7
  333. package/dist/schemas/v3.1/strict/parameter.js.map +0 -7
  334. package/dist/schemas/v3.1/strict/path-item.js.map +0 -7
  335. package/dist/schemas/v3.1/strict/paths.js.map +0 -7
  336. package/dist/schemas/v3.1/strict/ref-definitions.js.map +0 -7
  337. package/dist/schemas/v3.1/strict/reference.js.map +0 -7
  338. package/dist/schemas/v3.1/strict/request-body.js.map +0 -7
  339. package/dist/schemas/v3.1/strict/response.js.map +0 -7
  340. package/dist/schemas/v3.1/strict/responses.js.map +0 -7
  341. package/dist/schemas/v3.1/strict/schema.js.map +0 -7
  342. package/dist/schemas/v3.1/strict/security-requirement.js.map +0 -7
  343. package/dist/schemas/v3.1/strict/security-scheme.js.map +0 -7
  344. package/dist/schemas/v3.1/strict/server-variable.js.map +0 -7
  345. package/dist/schemas/v3.1/strict/server.js.map +0 -7
  346. package/dist/schemas/v3.1/strict/tag.js.map +0 -7
  347. package/dist/schemas/v3.1/strict/type-guards.js.map +0 -7
  348. package/dist/schemas/v3.1/strict/xml.js.map +0 -7
  349. package/dist/schemas/workspace-specification/index.js.map +0 -7
  350. package/dist/schemas/workspace-specification/info.js.map +0 -7
  351. package/dist/schemas/workspace.js.map +0 -7
  352. package/dist/schemas.js.map +0 -7
  353. package/dist/server.js.map +0 -7
  354. package/dist/workspace-plugin.js.map +0 -7
@@ -1,24 +1,12 @@
1
- import { Type } from "@scalar/typebox";
2
- import { compose } from "../../schemas/compose.js";
3
- import { WorkspaceMetaSchema } from "../../schemas/workspace.js";
4
- import { InfoSchema } from "../../schemas/workspace-specification/info.js";
5
- const WorkspaceSpecificationSchema = compose(
6
- Type.Object({
7
- workspace: Type.Union([Type.Literal("draft")]),
1
+ import { Type } from '@scalar/typebox';
2
+ import { compose } from '../../schemas/compose.js';
3
+ import { WorkspaceMetaSchema } from '../../schemas/workspace.js';
4
+ import { InfoSchema } from '../../schemas/workspace-specification/info.js';
5
+ export const WorkspaceSpecificationSchema = compose(Type.Object({
6
+ workspace: Type.Union([Type.Literal('draft')]),
8
7
  info: InfoSchema,
9
- documents: Type.Optional(
10
- Type.Record(
11
- Type.String(),
12
- Type.Object({
13
- $ref: Type.String()
14
- })
15
- )
16
- ),
17
- overrides: Type.Optional(Type.Record(Type.String(), Type.Any()))
18
- }),
19
- WorkspaceMetaSchema
20
- );
21
- export {
22
- WorkspaceSpecificationSchema
23
- };
24
- //# sourceMappingURL=index.js.map
8
+ documents: Type.Optional(Type.Record(Type.String(), Type.Object({
9
+ $ref: Type.String(),
10
+ }))),
11
+ overrides: Type.Optional(Type.Record(Type.String(), Type.Any())),
12
+ }), WorkspaceMetaSchema);
@@ -1,9 +1,5 @@
1
- import { Type } from "@scalar/typebox";
2
- const InfoSchema = Type.Object({
3
- title: Type.String(),
4
- description: Type.Optional(Type.String())
1
+ import { Type } from '@scalar/typebox';
2
+ export const InfoSchema = Type.Object({
3
+ title: Type.String(),
4
+ description: Type.Optional(Type.String()),
5
5
  });
6
- export {
7
- InfoSchema
8
- };
9
- //# sourceMappingURL=info.js.map
@@ -1,53 +1,27 @@
1
- import { Type } from "@scalar/typebox";
2
- import { AVAILABLE_CLIENTS } from "@scalar/types/snippetz";
3
- import { compose } from "../schemas/compose.js";
4
- import { extensions } from "../schemas/extensions.js";
5
- import {
6
- xScalarEnvironmentsSchema
7
- } from "../schemas/extensions/document/x-scalar-environments.js";
8
- import {
9
- XScalarActiveEnvironmentSchema
10
- } from "../schemas/extensions/general/x-scalar-active-environment.js";
11
- import { xScalarCookiesSchema } from "../schemas/extensions/general/x-scalar-cookies.js";
12
- import { XScalarOrderSchema } from "../schemas/extensions/general/x-scalar-order.js";
13
- import { XScalarActiveProxySchema } from "../schemas/extensions/workspace/x-scalar-active-proxy.js";
14
- import { XScalarTabsSchema } from "../schemas/extensions/workspace/x-scalar-tabs.js";
15
- import { OpenAPIDocumentSchema } from "./v3.1/strict/openapi-document.js";
16
- const WorkspaceDocumentSchema = OpenAPIDocumentSchema;
17
- const ColorModeSchema = Type.Union([Type.Literal("system"), Type.Literal("light"), Type.Literal("dark")]);
18
- const WorkspaceMetaSchema = Type.Partial(
19
- compose(
20
- Type.Object({
21
- [extensions.workspace.colorMode]: ColorModeSchema,
22
- [extensions.workspace.defaultClient]: Type.Union(AVAILABLE_CLIENTS.map((client) => Type.Literal(client))),
23
- [extensions.workspace.activeDocument]: Type.String(),
24
- [extensions.workspace.theme]: Type.String(),
25
- [extensions.workspace.sidebarWidth]: Type.Number({ default: 288 })
26
- }),
27
- XScalarActiveProxySchema
28
- )
29
- );
30
- const WorkspaceExtensionsSchema = compose(
31
- xScalarEnvironmentsSchema,
32
- XScalarActiveEnvironmentSchema,
33
- XScalarOrderSchema,
34
- xScalarCookiesSchema,
35
- XScalarTabsSchema
36
- );
37
- const WorkspaceSchema = compose(
38
- WorkspaceMetaSchema,
39
- Type.Object({
1
+ import { Type } from '@scalar/typebox';
2
+ import { AVAILABLE_CLIENTS } from '@scalar/types/snippetz';
3
+ import { compose } from '../schemas/compose.js';
4
+ import { extensions } from '../schemas/extensions.js';
5
+ import { xScalarEnvironmentsSchema, } from '../schemas/extensions/document/x-scalar-environments.js';
6
+ import { XScalarActiveEnvironmentSchema, } from '../schemas/extensions/general/x-scalar-active-environment.js';
7
+ import { xScalarCookiesSchema } from '../schemas/extensions/general/x-scalar-cookies.js';
8
+ import { XScalarOrderSchema } from '../schemas/extensions/general/x-scalar-order.js';
9
+ import { XScalarActiveProxySchema } from '../schemas/extensions/workspace/x-scalar-active-proxy.js';
10
+ import { XScalarTabsSchema } from '../schemas/extensions/workspace/x-scalar-tabs.js';
11
+ import { OpenAPIDocumentSchema } from './v3.1/strict/openapi-document.js';
12
+ // Note: use Type.Intersect to combine schemas here because Type.Compose does not work as expected with Modules
13
+ export const WorkspaceDocumentSchema = OpenAPIDocumentSchema;
14
+ export const ColorModeSchema = Type.Union([Type.Literal('system'), Type.Literal('light'), Type.Literal('dark')]);
15
+ export const WorkspaceMetaSchema = Type.Partial(compose(Type.Object({
16
+ [extensions.workspace.colorMode]: ColorModeSchema,
17
+ [extensions.workspace.defaultClient]: Type.Union(AVAILABLE_CLIENTS.map((client) => Type.Literal(client))),
18
+ [extensions.workspace.activeDocument]: Type.String(),
19
+ [extensions.workspace.theme]: Type.String(),
20
+ [extensions.workspace.sidebarWidth]: Type.Number({ default: 288 }),
21
+ }), XScalarActiveProxySchema));
22
+ export const WorkspaceExtensionsSchema = compose(xScalarEnvironmentsSchema, XScalarActiveEnvironmentSchema, XScalarOrderSchema, xScalarCookiesSchema, XScalarTabsSchema);
23
+ export const WorkspaceSchema = compose(WorkspaceMetaSchema, Type.Object({
40
24
  documents: Type.Record(Type.String(), WorkspaceDocumentSchema),
41
25
  /** Active document is possibly undefined if we attempt to lookup with an invalid key */
42
- activeDocument: Type.Union([Type.Undefined(), WorkspaceDocumentSchema])
43
- }),
44
- WorkspaceExtensionsSchema
45
- );
46
- export {
47
- ColorModeSchema,
48
- WorkspaceDocumentSchema,
49
- WorkspaceExtensionsSchema,
50
- WorkspaceMetaSchema,
51
- WorkspaceSchema
52
- };
53
- //# sourceMappingURL=workspace.js.map
26
+ activeDocument: Type.Union([Type.Undefined(), WorkspaceDocumentSchema]),
27
+ }), WorkspaceExtensionsSchema);
package/dist/schemas.js CHANGED
@@ -1,6 +1,2 @@
1
- import { WorkspaceDocumentSchema, WorkspaceSchema } from "./schemas/workspace.js";
2
- export {
3
- WorkspaceDocumentSchema,
4
- WorkspaceSchema
5
- };
6
- //# sourceMappingURL=schemas.js.map
1
+ // biome-ignore lint/performance/noBarrelFile: This is a barrel file that re-exports workspace schemas
2
+ export { WorkspaceDocumentSchema, WorkspaceSchema } from './schemas/workspace.js';
package/dist/server.js CHANGED
@@ -1,192 +1,302 @@
1
- import fs from "node:fs/promises";
2
- import { cwd } from "node:process";
3
- import { parseJsonPointerSegments } from "@scalar/helpers/json/parse-json-pointer-segments";
4
- import { getValueAtPath } from "@scalar/helpers/object/get-value-at-path";
5
- import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
6
- import { escapeJsonPointer } from "@scalar/json-magic/helpers/escape-json-pointer";
7
- import { upgrade } from "@scalar/openapi-upgrader";
8
- import { keyOf } from "./helpers/general.js";
9
- import { createNavigation } from "./navigation/index.js";
10
- import { extensions } from "./schemas/extensions.js";
11
- import { coerceValue } from "./schemas/typebox-coerce.js";
12
- import {
13
- OpenAPIDocumentSchema
14
- } from "./schemas/v3.1/strict/openapi-document.js";
15
- const DEFAULT_ASSETS_FOLDER = "assets";
16
- const WORKSPACE_FILE_NAME = "scalar-workspace.json";
17
- const httpMethods = /* @__PURE__ */ new Set(["get", "put", "post", "delete", "options", "head", "patch", "trace"]);
18
- function filterHttpMethodsOnly(paths) {
19
- const result = {};
20
- for (const [path, methods] of Object.entries(paths)) {
21
- if (!methods) {
22
- continue;
23
- }
24
- const filteredMethods = {};
25
- for (const [method, operation] of Object.entries(methods)) {
26
- if (httpMethods.has(method.toLowerCase())) {
27
- filteredMethods[method] = operation;
28
- }
29
- }
30
- if (Object.keys(filteredMethods).length > 0) {
31
- result[path] = filteredMethods;
32
- }
33
- }
34
- return result;
35
- }
36
- function escapePaths(paths) {
37
- const result = {};
38
- Object.keys(paths).forEach((path) => {
39
- if (paths[path]) {
40
- result[escapeJsonPointer(path)] = paths[path];
1
+ import fs from 'node:fs/promises';
2
+ import { cwd } from 'node:process';
3
+ import { parseJsonPointerSegments } from '@scalar/helpers/json/parse-json-pointer-segments';
4
+ import { getValueAtPath } from '@scalar/helpers/object/get-value-at-path';
5
+ import { fetchUrls, readFiles } from '@scalar/json-magic/bundle/plugins/node';
6
+ import { escapeJsonPointer } from '@scalar/json-magic/helpers/escape-json-pointer';
7
+ import { upgrade } from '@scalar/openapi-upgrader';
8
+ import { keyOf } from './helpers/general.js';
9
+ import { createNavigation } from './navigation/index.js';
10
+ import { extensions } from './schemas/extensions.js';
11
+ import { coerceValue } from './schemas/typebox-coerce.js';
12
+ import { OpenAPIDocumentSchema, } from './schemas/v3.1/strict/openapi-document.js';
13
+ const DEFAULT_ASSETS_FOLDER = 'assets';
14
+ export const WORKSPACE_FILE_NAME = 'scalar-workspace.json';
15
+ const httpMethods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
16
+ /**
17
+ * Filters an OpenAPI PathsObject to only include standard HTTP methods.
18
+ * Removes any vendor extensions or other non-HTTP properties.
19
+ *
20
+ * @param paths - The OpenAPI PathsObject to filter
21
+ * @returns A new PathsObject containing only standard HTTP methods
22
+ *
23
+ * @example
24
+ * Input: {
25
+ * "/users": {
26
+ * "get": {...},
27
+ * "x-custom": {...},
28
+ * "post": {...}
29
+ * }
30
+ * }
31
+ * Output: {
32
+ * "/users": {
33
+ * "get": {...},
34
+ * "post": {...}
35
+ * }
36
+ * }
37
+ */
38
+ export function filterHttpMethodsOnly(paths) {
39
+ const result = {};
40
+ // Todo: skip extension properties
41
+ for (const [path, methods] of Object.entries(paths)) {
42
+ if (!methods) {
43
+ continue;
44
+ }
45
+ const filteredMethods = {};
46
+ for (const [method, operation] of Object.entries(methods)) {
47
+ if (httpMethods.has(method.toLowerCase())) {
48
+ filteredMethods[method] = operation;
49
+ }
50
+ }
51
+ if (Object.keys(filteredMethods).length > 0) {
52
+ result[path] = filteredMethods;
53
+ }
41
54
  }
42
- });
43
- return result;
55
+ return result;
44
56
  }
45
- function externalizeComponentReferences(document, meta) {
46
- const result = {};
47
- if (!document.components) {
57
+ /**
58
+ * Escapes path keys in an OpenAPI PathsObject to be JSON Pointer compatible.
59
+ * This is necessary because OpenAPI paths can contain characters that need to be escaped
60
+ * when used as JSON Pointer references (like '/' and '~').
61
+ *
62
+ * @example
63
+ * Input: { "/users/{id}": { ... } }
64
+ * Output: { "/users~1{id}": { ... } }
65
+ */
66
+ export function escapePaths(paths) {
67
+ const result = {};
68
+ Object.keys(paths).forEach((path) => {
69
+ if (paths[path]) {
70
+ result[escapeJsonPointer(path)] = paths[path];
71
+ }
72
+ });
48
73
  return result;
49
- }
50
- Object.entries(document.components).forEach(([type, component]) => {
51
- if (!component || typeof component !== "object") {
52
- return;
74
+ }
75
+ /**
76
+ * Externalizes components by turning them into refs.
77
+ */
78
+ export function externalizeComponentReferences(document, meta) {
79
+ const result = {};
80
+ if (!document.components) {
81
+ return result;
53
82
  }
54
- result[type] = {};
55
- Object.keys(component).forEach((name) => {
56
- const ref = meta.mode === "ssr" ? `${meta.baseUrl}/${meta.name}/components/${type}/${name}#` : `./chunks/${meta.name}/components/${type}/${name}.json#`;
57
- result[type][name] = { "$ref": ref, $global: true };
83
+ Object.entries(document.components).forEach(([type, component]) => {
84
+ if (!component || typeof component !== 'object') {
85
+ return;
86
+ }
87
+ result[type] = {};
88
+ Object.keys(component).forEach((name) => {
89
+ const ref = meta.mode === 'ssr'
90
+ ? `${meta.baseUrl}/${meta.name}/components/${type}/${name}#`
91
+ : `./chunks/${meta.name}/components/${type}/${name}.json#`;
92
+ result[type][name] = { '$ref': ref, $global: true };
93
+ });
58
94
  });
59
- });
60
- return result;
61
- }
62
- function externalizePathReferences(document, meta) {
63
- const result = {};
64
- if (!document.paths) {
65
95
  return result;
66
- }
67
- Object.entries(document.paths).forEach(([path, pathItem]) => {
68
- if (!pathItem || typeof pathItem !== "object") {
69
- return;
96
+ }
97
+ /**
98
+ * Externalizes paths operations by turning them into refs.
99
+ */
100
+ export function externalizePathReferences(document, meta) {
101
+ const result = {};
102
+ if (!document.paths) {
103
+ return result;
70
104
  }
71
- const pathItemRecord = pathItem;
72
- result[path] = {};
73
- const escapedPath = escapeJsonPointer(path);
74
- keyOf(pathItemRecord).forEach((type) => {
75
- if (httpMethods.has(type)) {
76
- const ref = meta.mode === "ssr" ? `${meta.baseUrl}/${meta.name}/operations/${escapedPath}/${type}#` : `./chunks/${meta.name}/operations/${escapedPath}/${type}.json#`;
77
- result[path][type] = { "$ref": ref, $global: true };
78
- } else {
79
- result[path][type] = pathItemRecord[type];
80
- }
105
+ Object.entries(document.paths).forEach(([path, pathItem]) => {
106
+ if (!pathItem || typeof pathItem !== 'object') {
107
+ return;
108
+ }
109
+ const pathItemRecord = pathItem;
110
+ result[path] = {};
111
+ const escapedPath = escapeJsonPointer(path);
112
+ keyOf(pathItemRecord).forEach((type) => {
113
+ if (httpMethods.has(type)) {
114
+ const ref = meta.mode === 'ssr'
115
+ ? `${meta.baseUrl}/${meta.name}/operations/${escapedPath}/${type}#`
116
+ : `./chunks/${meta.name}/operations/${escapedPath}/${type}.json#`;
117
+ result[path][type] = { '$ref': ref, $global: true };
118
+ }
119
+ else {
120
+ result[path][type] = pathItemRecord[type];
121
+ }
122
+ });
81
123
  });
82
- });
83
- return result;
124
+ return result;
84
125
  }
126
+ /**
127
+ * Resolves a workspace document from various input sources (URL, local file, or direct document object).
128
+ *
129
+ * @param workspaceDocument - The document input to resolve, which can be:
130
+ * - A URL to fetch the document from
131
+ * - A local file path to read the document from
132
+ * - A direct document object
133
+ * @returns A promise that resolves to an object containing:
134
+ * - ok: boolean indicating if the resolution was successful
135
+ * - data: The resolved document data
136
+ *
137
+ * @example
138
+ * // Resolve from URL
139
+ * const urlDoc = await loadDocument({ name: 'api', url: 'https://api.example.com/openapi.json' })
140
+ *
141
+ * // Resolve direct document
142
+ * const directDoc = await loadDocument({
143
+ * name: 'inline',
144
+ * document: { openapi: '3.0.0', paths: {} }
145
+ * })
146
+ */
85
147
  function loadDocument(workspaceDocument) {
86
- if ("url" in workspaceDocument) {
87
- return fetchUrls().exec(workspaceDocument.url);
88
- }
89
- if ("path" in workspaceDocument) {
90
- return readFiles().exec(workspaceDocument.path);
91
- }
92
- return Promise.resolve({
93
- ok: true,
94
- data: workspaceDocument.document,
95
- raw: JSON.stringify(workspaceDocument.document)
96
- });
148
+ if ('url' in workspaceDocument) {
149
+ return fetchUrls().exec(workspaceDocument.url);
150
+ }
151
+ if ('path' in workspaceDocument) {
152
+ return readFiles().exec(workspaceDocument.path);
153
+ }
154
+ return Promise.resolve({
155
+ ok: true,
156
+ data: workspaceDocument.document,
157
+ raw: JSON.stringify(workspaceDocument.document),
158
+ });
97
159
  }
98
- async function createServerWorkspaceStore(workspaceProps) {
99
- const workspace = {
100
- ...workspaceProps.meta,
101
- documents: {}
102
- };
103
- const assets = {};
104
- const addDocumentSync = (document, meta, navigationOptions) => {
105
- const { name, ...documentMeta } = meta;
106
- const documentV3 = coerceValue(OpenAPIDocumentSchema, upgrade(document, "3.1"));
107
- assets[meta.name] = {
108
- components: documentV3.components,
109
- operations: documentV3.paths && escapePaths(filterHttpMethodsOnly(documentV3.paths))
160
+ /**
161
+ * Create server state workspace store
162
+ */
163
+ export async function createServerWorkspaceStore(workspaceProps) {
164
+ /**
165
+ * Base workspace document containing essential metadata and document references.
166
+ *
167
+ * This workspace document provides the minimal information needed for initial rendering.
168
+ * All components and path operations are replaced with references to enable lazy loading.
169
+ *
170
+ * In SSR mode, references point to API endpoints.
171
+ * In static mode, references point to filesystem chunks.
172
+ */
173
+ const workspace = {
174
+ ...workspaceProps.meta,
175
+ documents: {},
110
176
  };
111
- const options = workspaceProps.mode === "ssr" ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl } : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER };
112
- const components = externalizeComponentReferences(documentV3, options);
113
- const paths = externalizePathReferences(documentV3, options);
114
- const navigation = createNavigation(name, documentV3, navigationOptions ?? workspaceProps.navigationOptions);
115
- workspace.documents[meta.name] = {
116
- ...documentMeta,
117
- ...documentV3,
118
- components,
119
- paths,
120
- [extensions.document.navigation]: navigation
177
+ /**
178
+ * A map of document chunks that can be loaded asynchronously by the client.
179
+ * Each document is split into components and operations to enable lazy loading.
180
+ * The keys are document names and values contain the components and operations
181
+ * for that document.
182
+ */
183
+ const assets = {};
184
+ /**
185
+ * Adds a new document to the workspace.
186
+ *
187
+ * This function processes an OpenAPI document by:
188
+ * 1. Converting it to OpenAPI 3.1 format if needed
189
+ * 2. Separating it into reusable components and path operations
190
+ * 3. Externalizing references based on the workspace mode (SSR or static)
191
+ * 4. Adding the processed document to the workspace with its metadata
192
+ *
193
+ * The resulting document contains minimal information with externalized references
194
+ * that will be resolved on-demand through the workspace's get() method.
195
+ *
196
+ * @param document - The OpenAPI document to process and add
197
+ * @param meta - Document metadata containing the required name and optional settings
198
+ */
199
+ const addDocumentSync = (document, meta, navigationOptions) => {
200
+ const { name, ...documentMeta } = meta;
201
+ const documentV3 = coerceValue(OpenAPIDocumentSchema, upgrade(document, '3.1'));
202
+ // add the assets
203
+ assets[meta.name] = {
204
+ components: documentV3.components,
205
+ operations: documentV3.paths && escapePaths(filterHttpMethodsOnly(documentV3.paths)),
206
+ };
207
+ const options = workspaceProps.mode === 'ssr'
208
+ ? { mode: workspaceProps.mode, name, baseUrl: workspaceProps.baseUrl }
209
+ : { mode: workspaceProps.mode, name, directory: workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER };
210
+ const components = externalizeComponentReferences(documentV3, options);
211
+ const paths = externalizePathReferences(documentV3, options);
212
+ // Build the sidebar entries
213
+ const navigation = createNavigation(name, documentV3, navigationOptions ?? workspaceProps.navigationOptions);
214
+ // The document is now a minimal version with externalized references to components and operations.
215
+ // These references will be resolved asynchronously when needed through the workspace's get() method.
216
+ workspace.documents[meta.name] = {
217
+ ...documentMeta,
218
+ ...documentV3,
219
+ components,
220
+ paths,
221
+ [extensions.document.navigation]: navigation,
222
+ };
121
223
  };
122
- };
123
- const addDocument = async (input, navigationOptions) => {
124
- const document = await loadDocument(input);
125
- if (!document.ok) {
126
- console.warn(`Failed to load document "${input.name}`);
127
- return;
128
- }
129
- addDocumentSync(document.data, { name: input.name, ...input.meta }, navigationOptions);
130
- };
131
- await Promise.all(workspaceProps.documents.map((document) => addDocument(document)));
132
- return {
133
- generateWorkspaceChunks: async () => {
134
- if (workspaceProps.mode !== "static") {
135
- throw "Mode has to be set to `static` to generate filesystem workspace chunks";
136
- }
137
- const basePath = `${cwd()}/${workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER}`;
138
- await fs.mkdir(basePath, { recursive: true });
139
- await fs.writeFile(`${basePath}/${WORKSPACE_FILE_NAME}`, JSON.stringify(workspace));
140
- for (const [name, { components, operations }] of Object.entries(assets)) {
141
- if (components) {
142
- for (const [type, component] of Object.entries(components)) {
143
- const componentPath = `${basePath}/chunks/${name}/components/${type}`;
144
- await fs.mkdir(componentPath, { recursive: true });
145
- for (const [key, value] of Object.entries(component)) {
146
- await fs.writeFile(`${componentPath}/${key}.json`, JSON.stringify(value));
147
- }
148
- }
224
+ /**
225
+ * Adds a new document to the workspace asynchronously.
226
+ *
227
+ * This function:
228
+ * 1. Loads the document using the provided input
229
+ * 2. Checks if the document loaded successfully
230
+ * 3. If successful, adds the document to the workspace using addDocumentSync
231
+ *
232
+ * @param input - The document input containing the document source and metadata
233
+ */
234
+ const addDocument = async (input, navigationOptions) => {
235
+ const document = await loadDocument(input);
236
+ if (!document.ok) {
237
+ console.warn(`Failed to load document "${input.name}`);
238
+ return;
149
239
  }
150
- if (operations) {
151
- for (const [path, methods] of Object.entries(operations)) {
152
- const operationPath = `${basePath}/chunks/${name}/operations/${path}`;
153
- await fs.mkdir(operationPath, { recursive: true });
154
- for (const [method, operation] of Object.entries(methods)) {
155
- await fs.writeFile(`${operationPath}/${method}.json`, JSON.stringify(operation));
240
+ addDocumentSync(document.data, { name: input.name, ...input.meta }, navigationOptions);
241
+ };
242
+ // Load and process all initial documents in parallel
243
+ await Promise.all(workspaceProps.documents.map((document) => addDocument(document)));
244
+ return {
245
+ generateWorkspaceChunks: async () => {
246
+ if (workspaceProps.mode !== 'static') {
247
+ throw 'Mode has to be set to `static` to generate filesystem workspace chunks';
156
248
  }
157
- }
158
- }
159
- }
160
- },
161
- getWorkspace: () => {
162
- return workspace;
163
- },
164
- get: (pointer) => {
165
- const pointerPath = (() => {
166
- if (pointer.startsWith("#")) {
167
- return pointer.slice(1);
168
- }
169
- if (pointer.startsWith("/")) {
170
- return pointer;
171
- }
172
- try {
173
- return new URL(pointer).pathname;
174
- } catch {
175
- return pointer;
176
- }
177
- })();
178
- const path = parseJsonPointerSegments(pointerPath).map(escapeJsonPointer);
179
- return getValueAtPath(assets, path);
180
- },
181
- addDocument
182
- };
249
+ // Write the workspace document
250
+ const basePath = `${cwd()}/${workspaceProps.directory ?? DEFAULT_ASSETS_FOLDER}`;
251
+ await fs.mkdir(basePath, { recursive: true });
252
+ // Write the workspace contents on the file system
253
+ await fs.writeFile(`${basePath}/${WORKSPACE_FILE_NAME}`, JSON.stringify(workspace));
254
+ // Write the chunks
255
+ for (const [name, { components, operations }] of Object.entries(assets)) {
256
+ // Write the components chunks
257
+ if (components) {
258
+ for (const [type, component] of Object.entries(components)) {
259
+ const componentPath = `${basePath}/chunks/${name}/components/${type}`;
260
+ await fs.mkdir(componentPath, { recursive: true });
261
+ for (const [key, value] of Object.entries(component)) {
262
+ await fs.writeFile(`${componentPath}/${key}.json`, JSON.stringify(value));
263
+ }
264
+ }
265
+ }
266
+ // Write the operations chunks
267
+ if (operations) {
268
+ for (const [path, methods] of Object.entries(operations)) {
269
+ const operationPath = `${basePath}/chunks/${name}/operations/${path}`;
270
+ await fs.mkdir(operationPath, { recursive: true });
271
+ for (const [method, operation] of Object.entries(methods)) {
272
+ await fs.writeFile(`${operationPath}/${method}.json`, JSON.stringify(operation));
273
+ }
274
+ }
275
+ }
276
+ }
277
+ },
278
+ getWorkspace: () => {
279
+ return workspace;
280
+ },
281
+ get: (pointer) => {
282
+ const pointerPath = (() => {
283
+ if (pointer.startsWith('#')) {
284
+ return pointer.slice(1);
285
+ }
286
+ if (pointer.startsWith('/')) {
287
+ return pointer;
288
+ }
289
+ try {
290
+ return new URL(pointer).pathname;
291
+ }
292
+ catch {
293
+ return pointer;
294
+ }
295
+ })();
296
+ // Keep the path segments escaped cuz we store them on the filesystem as escaped sequences
297
+ const path = parseJsonPointerSegments(pointerPath).map(escapeJsonPointer);
298
+ return getValueAtPath(assets, path);
299
+ },
300
+ addDocument,
301
+ };
183
302
  }
184
- export {
185
- WORKSPACE_FILE_NAME,
186
- createServerWorkspaceStore,
187
- escapePaths,
188
- externalizeComponentReferences,
189
- externalizePathReferences,
190
- filterHttpMethodsOnly
191
- };
192
- //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- //# sourceMappingURL=workspace-plugin.js.map
1
+ export {};