@scalar/workspace-store 0.40.2 → 0.40.4
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.
- package/CHANGELOG.md +13 -0
- package/dist/client.d.ts +7 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +820 -681
- package/dist/entities/auth/index.js +96 -101
- package/dist/entities/auth/schema.d.ts +10 -0
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/entities/auth/schema.js +42 -116
- package/dist/entities/history/index.js +80 -60
- package/dist/entities/history/schema.js +94 -88
- package/dist/events/bus.js +146 -93
- package/dist/events/definitions/analytics.js +1 -1
- package/dist/events/definitions/auth.js +1 -1
- package/dist/events/definitions/common.js +1 -1
- package/dist/events/definitions/cookie.js +1 -1
- package/dist/events/definitions/document.js +1 -1
- package/dist/events/definitions/environment.js +1 -1
- package/dist/events/definitions/hooks.js +1 -1
- package/dist/events/definitions/index.js +1 -1
- package/dist/events/definitions/meta.js +1 -1
- package/dist/events/definitions/operation.js +1 -1
- package/dist/events/definitions/server.js +1 -1
- package/dist/events/definitions/tabs.js +1 -1
- package/dist/events/definitions/tag.js +1 -1
- package/dist/events/definitions/ui.js +1 -1
- package/dist/events/definitions/workspace.js +1 -1
- package/dist/events/index.js +3 -9
- package/dist/events/listeners.js +20 -22
- package/dist/events/old-definitions.js +15 -12
- package/dist/helpers/deep-clone.js +33 -17
- package/dist/helpers/detect-changes-proxy.js +95 -57
- package/dist/helpers/general.js +78 -23
- package/dist/helpers/generate-unique-value.js +77 -45
- package/dist/helpers/get-fetch.js +12 -10
- package/dist/helpers/get-resolved-ref.js +11 -10
- package/dist/helpers/is-non-optional-security-requirement.js +3 -6
- package/dist/helpers/merge-object.js +71 -30
- package/dist/helpers/overrides-proxy.js +98 -58
- package/dist/helpers/unpack-proxy.js +60 -58
- package/dist/mutators/auth.js +358 -230
- package/dist/mutators/cookie.js +59 -42
- package/dist/mutators/document.js +104 -66
- package/dist/mutators/environment.js +97 -72
- package/dist/mutators/helpers.js +9 -13
- package/dist/mutators/index.js +62 -49
- package/dist/mutators/operation/body.js +88 -57
- package/dist/mutators/operation/extensions.js +20 -12
- package/dist/mutators/operation/helpers/fetch-request-to-har.js +144 -107
- package/dist/mutators/operation/helpers/fetch-response-to-har.js +143 -95
- package/dist/mutators/operation/helpers/get-parameter-position.js +12 -12
- package/dist/mutators/operation/helpers/har-to-operation.js +169 -132
- package/dist/mutators/operation/helpers/sync-path-parameters.js +109 -60
- package/dist/mutators/operation/history.js +60 -64
- package/dist/mutators/operation/index.js +25 -49
- package/dist/mutators/operation/operation.js +349 -240
- package/dist/mutators/operation/parameters.js +157 -93
- package/dist/mutators/server.js +213 -152
- package/dist/mutators/tabs.js +173 -130
- package/dist/mutators/tag.js +131 -97
- package/dist/mutators/workspace.js +72 -42
- package/dist/navigation/get-navigation-options.js +97 -84
- package/dist/navigation/helpers/get-openapi-object.js +46 -29
- package/dist/navigation/helpers/get-operation-entries.js +72 -32
- package/dist/navigation/helpers/get-parent-entry.js +16 -12
- package/dist/navigation/helpers/get-tag-entries.js +56 -29
- package/dist/navigation/helpers/get-tag.js +22 -23
- package/dist/navigation/helpers/get-x-keys.js +13 -9
- package/dist/navigation/helpers/traverse-description.js +90 -72
- package/dist/navigation/helpers/traverse-document.js +111 -98
- package/dist/navigation/helpers/traverse-examples.js +35 -31
- package/dist/navigation/helpers/traverse-paths.js +118 -106
- package/dist/navigation/helpers/traverse-schemas.js +65 -64
- package/dist/navigation/helpers/traverse-tags.js +158 -129
- package/dist/navigation/helpers/traverse-webhooks.js +96 -90
- package/dist/navigation/helpers/update-order-ids.js +59 -51
- package/dist/navigation/helpers/utils.js +71 -21
- package/dist/navigation/index.js +5 -13
- package/dist/navigation/types.js +1 -1
- package/dist/persistence/index.js +283 -285
- package/dist/persistence/indexdb.js +263 -126
- package/dist/plugins/bundler/helpers.js +21 -12
- package/dist/plugins/bundler/index.d.ts +7 -0
- package/dist/plugins/bundler/index.d.ts.map +1 -1
- package/dist/plugins/bundler/index.js +305 -171
- package/dist/plugins/client/index.js +1 -5
- package/dist/plugins/client/persistence.js +95 -90
- package/dist/resolve.js +18 -25
- package/dist/schemas/compose.js +6 -7
- package/dist/schemas/extensions/document/x-internal.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-environments.js +16 -22
- package/dist/schemas/extensions/document/x-scalar-icon.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-ignore.js +3 -7
- package/dist/schemas/extensions/document/x-scalar-is-dirty.js +21 -8
- package/dist/schemas/extensions/document/x-scalar-original-document-hash.js +17 -8
- package/dist/schemas/extensions/document/x-scalar-registry-meta.js +15 -21
- package/dist/schemas/extensions/document/x-scalar-sdk-installation.js +5 -13
- package/dist/schemas/extensions/document/x-scalar-watch-mode.js +4 -8
- package/dist/schemas/extensions/document/x-tags.js +3 -7
- package/dist/schemas/extensions/example/x-disabled.js +17 -7
- package/dist/schemas/extensions/general/x-scalar-active-environment.js +4 -7
- package/dist/schemas/extensions/general/x-scalar-cookies.js +9 -14
- package/dist/schemas/extensions/general/x-scalar-order.js +8 -7
- package/dist/schemas/extensions/operation/index.js +4 -23
- package/dist/schemas/extensions/operation/x-badge.js +42 -50
- package/dist/schemas/extensions/operation/x-code-samples.js +8 -12
- package/dist/schemas/extensions/operation/x-draft-examples.js +3 -7
- package/dist/schemas/extensions/operation/x-post-response.js +18 -7
- package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js +57 -13
- package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +9 -7
- package/dist/schemas/extensions/operation/x-scalar-stability.js +15 -14
- package/dist/schemas/extensions/parameter/x-global.js +12 -7
- package/dist/schemas/extensions/schema/x-additional-properties-name.js +10 -7
- package/dist/schemas/extensions/schema/x-enum-descriptions.js +17 -12
- package/dist/schemas/extensions/schema/x-enum-varnames.js +21 -8
- package/dist/schemas/extensions/schema/x-examples.js +3 -7
- package/dist/schemas/extensions/schema/x-variable.js +3 -7
- package/dist/schemas/extensions/security/index.js +1 -1
- package/dist/schemas/extensions/security/x-default-scopes.js +16 -7
- package/dist/schemas/extensions/security/x-scalar-credentials-location.js +16 -7
- package/dist/schemas/extensions/security/x-scalar-security-body.js +14 -7
- package/dist/schemas/extensions/security/x-scalar-security-query.js +14 -7
- package/dist/schemas/extensions/security/x-scalar-security-secrets.js +66 -37
- package/dist/schemas/extensions/security/x-tokenName.js +11 -7
- package/dist/schemas/extensions/security/x-use-pkce.js +6 -10
- package/dist/schemas/extensions/server/x-scalar-selected-server.js +3 -7
- package/dist/schemas/extensions/tag/index.js +1 -1
- package/dist/schemas/extensions/tag/x-display-name.js +11 -7
- package/dist/schemas/extensions/tag/x-tag-groups.js +13 -15
- package/dist/schemas/extensions/workspace/index.js +2 -11
- package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js +13 -7
- package/dist/schemas/extensions/workspace/x-scalar-tabs.js +15 -13
- package/dist/schemas/extensions.js +11 -15
- package/dist/schemas/inmemory-workspace.d.ts +6 -0
- package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
- package/dist/schemas/inmemory-workspace.js +13 -21
- package/dist/schemas/navigation.js +48 -85
- package/dist/schemas/reference-config/appearance.js +15 -22
- package/dist/schemas/reference-config/features.js +14 -21
- package/dist/schemas/reference-config/index.d.ts +2 -0
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/index.js +42 -44
- package/dist/schemas/reference-config/meta.js +11 -18
- package/dist/schemas/reference-config/routing.js +7 -14
- package/dist/schemas/reference-config/settings.d.ts +2 -0
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.js +10 -17
- package/dist/schemas/typebox-coerce.js +23 -6
- package/dist/schemas/v3.1/strict/callback.js +6 -12
- package/dist/schemas/v3.1/strict/components.js +26 -48
- package/dist/schemas/v3.1/strict/contact.js +9 -12
- package/dist/schemas/v3.1/strict/discriminator.js +11 -10
- package/dist/schemas/v3.1/strict/encoding.js +15 -12
- package/dist/schemas/v3.1/strict/example.js +11 -13
- package/dist/schemas/v3.1/strict/external-documentation.js +7 -10
- package/dist/schemas/v3.1/strict/header.js +27 -28
- package/dist/schemas/v3.1/strict/info.js +10 -16
- package/dist/schemas/v3.1/strict/license.js +9 -12
- package/dist/schemas/v3.1/strict/link.js +22 -19
- package/dist/schemas/v3.1/strict/media-type.js +17 -16
- package/dist/schemas/v3.1/strict/oauth-flow.js +28 -62
- package/dist/schemas/v3.1/strict/oauthflows.js +14 -20
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +70 -0
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/openapi-document.js +126 -210
- package/dist/schemas/v3.1/strict/operation.js +16 -43
- package/dist/schemas/v3.1/strict/parameter.d.ts +6 -0
- package/dist/schemas/v3.1/strict/parameter.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/parameter.js +29 -35
- package/dist/schemas/v3.1/strict/path-item.js +36 -40
- package/dist/schemas/v3.1/strict/paths.js +8 -11
- package/dist/schemas/v3.1/strict/ref-definitions.js +76 -100
- package/dist/schemas/v3.1/strict/reference.js +18 -21
- package/dist/schemas/v3.1/strict/request-body.js +8 -16
- package/dist/schemas/v3.1/strict/response.js +12 -16
- package/dist/schemas/v3.1/strict/responses.js +13 -11
- package/dist/schemas/v3.1/strict/schema.js +149 -157
- package/dist/schemas/v3.1/strict/security-requirement.js +13 -12
- package/dist/schemas/v3.1/strict/security-scheme.js +29 -41
- package/dist/schemas/v3.1/strict/server-variable.js +9 -12
- package/dist/schemas/v3.1/strict/server.js +10 -13
- package/dist/schemas/v3.1/strict/tag.js +11 -20
- package/dist/schemas/v3.1/strict/type-guards.js +20 -20
- package/dist/schemas/v3.1/strict/xml.js +17 -16
- package/dist/schemas/workspace-specification/index.js +11 -23
- package/dist/schemas/workspace-specification/info.js +4 -8
- package/dist/schemas/workspace.d.ts +6 -0
- package/dist/schemas/workspace.d.ts.map +1 -1
- package/dist/schemas/workspace.js +25 -51
- package/dist/schemas.js +2 -6
- package/dist/server.js +286 -176
- package/dist/workspace-plugin.js +1 -1
- package/package.json +13 -19
- package/dist/client.js.map +0 -7
- package/dist/entities/auth/index.js.map +0 -7
- package/dist/entities/auth/schema.js.map +0 -7
- package/dist/entities/history/index.js.map +0 -7
- package/dist/entities/history/schema.js.map +0 -7
- package/dist/events/bus.js.map +0 -7
- package/dist/events/definitions/analytics.js.map +0 -7
- package/dist/events/definitions/auth.js.map +0 -7
- package/dist/events/definitions/common.js.map +0 -7
- package/dist/events/definitions/cookie.js.map +0 -7
- package/dist/events/definitions/document.js.map +0 -7
- package/dist/events/definitions/environment.js.map +0 -7
- package/dist/events/definitions/hooks.js.map +0 -7
- package/dist/events/definitions/index.js.map +0 -7
- package/dist/events/definitions/meta.js.map +0 -7
- package/dist/events/definitions/operation.js.map +0 -7
- package/dist/events/definitions/server.js.map +0 -7
- package/dist/events/definitions/tabs.js.map +0 -7
- package/dist/events/definitions/tag.js.map +0 -7
- package/dist/events/definitions/ui.js.map +0 -7
- package/dist/events/definitions/workspace.js.map +0 -7
- package/dist/events/index.js.map +0 -7
- package/dist/events/listeners.js.map +0 -7
- package/dist/events/old-definitions.js.map +0 -7
- package/dist/helpers/apply-selective-updates.d.ts +0 -19
- package/dist/helpers/apply-selective-updates.d.ts.map +0 -1
- package/dist/helpers/apply-selective-updates.js +0 -37
- package/dist/helpers/apply-selective-updates.js.map +0 -7
- package/dist/helpers/deep-clone.js.map +0 -7
- package/dist/helpers/detect-changes-proxy.js.map +0 -7
- package/dist/helpers/general.js.map +0 -7
- package/dist/helpers/generate-unique-value.js.map +0 -7
- package/dist/helpers/get-fetch.js.map +0 -7
- package/dist/helpers/get-resolved-ref.js.map +0 -7
- package/dist/helpers/is-non-optional-security-requirement.js.map +0 -7
- package/dist/helpers/merge-object.js.map +0 -7
- package/dist/helpers/overrides-proxy.js.map +0 -7
- package/dist/helpers/unpack-proxy.js.map +0 -7
- package/dist/mutators/auth.js.map +0 -7
- package/dist/mutators/cookie.js.map +0 -7
- package/dist/mutators/document.js.map +0 -7
- package/dist/mutators/environment.js.map +0 -7
- package/dist/mutators/helpers.js.map +0 -7
- package/dist/mutators/index.js.map +0 -7
- package/dist/mutators/operation/body.js.map +0 -7
- package/dist/mutators/operation/extensions.js.map +0 -7
- package/dist/mutators/operation/helpers/fetch-request-to-har.js.map +0 -7
- package/dist/mutators/operation/helpers/fetch-response-to-har.js.map +0 -7
- package/dist/mutators/operation/helpers/get-parameter-position.js.map +0 -7
- package/dist/mutators/operation/helpers/har-to-operation.js.map +0 -7
- package/dist/mutators/operation/helpers/sync-path-parameters.js.map +0 -7
- package/dist/mutators/operation/history.js.map +0 -7
- package/dist/mutators/operation/index.js.map +0 -7
- package/dist/mutators/operation/operation.js.map +0 -7
- package/dist/mutators/operation/parameters.js.map +0 -7
- package/dist/mutators/server.js.map +0 -7
- package/dist/mutators/tabs.js.map +0 -7
- package/dist/mutators/tag.js.map +0 -7
- package/dist/mutators/workspace.js.map +0 -7
- package/dist/navigation/get-navigation-options.js.map +0 -7
- package/dist/navigation/helpers/get-openapi-object.js.map +0 -7
- package/dist/navigation/helpers/get-operation-entries.js.map +0 -7
- package/dist/navigation/helpers/get-parent-entry.js.map +0 -7
- package/dist/navigation/helpers/get-tag-entries.js.map +0 -7
- package/dist/navigation/helpers/get-tag.js.map +0 -7
- package/dist/navigation/helpers/get-x-keys.js.map +0 -7
- package/dist/navigation/helpers/traverse-description.js.map +0 -7
- package/dist/navigation/helpers/traverse-document.js.map +0 -7
- package/dist/navigation/helpers/traverse-examples.js.map +0 -7
- package/dist/navigation/helpers/traverse-paths.js.map +0 -7
- package/dist/navigation/helpers/traverse-schemas.js.map +0 -7
- package/dist/navigation/helpers/traverse-tags.js.map +0 -7
- package/dist/navigation/helpers/traverse-webhooks.js.map +0 -7
- package/dist/navigation/helpers/update-order-ids.js.map +0 -7
- package/dist/navigation/helpers/utils.js.map +0 -7
- package/dist/navigation/index.js.map +0 -7
- package/dist/navigation/types.js.map +0 -7
- package/dist/persistence/index.js.map +0 -7
- package/dist/persistence/indexdb.js.map +0 -7
- package/dist/plugins/bundler/helpers.js.map +0 -7
- package/dist/plugins/bundler/index.js.map +0 -7
- package/dist/plugins/client/index.js.map +0 -7
- package/dist/plugins/client/persistence.js.map +0 -7
- package/dist/resolve.js.map +0 -7
- package/dist/schemas/compose.js.map +0 -7
- package/dist/schemas/extensions/document/x-internal.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-environments.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-icon.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-ignore.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-is-dirty.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-original-document-hash.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-registry-meta.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-sdk-installation.js.map +0 -7
- package/dist/schemas/extensions/document/x-scalar-watch-mode.js.map +0 -7
- package/dist/schemas/extensions/document/x-tags.js.map +0 -7
- package/dist/schemas/extensions/example/x-disabled.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-active-environment.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-cookies.js.map +0 -7
- package/dist/schemas/extensions/general/x-scalar-order.js.map +0 -7
- package/dist/schemas/extensions/operation/index.js.map +0 -7
- package/dist/schemas/extensions/operation/x-badge.js.map +0 -7
- package/dist/schemas/extensions/operation/x-code-samples.js.map +0 -7
- package/dist/schemas/extensions/operation/x-draft-examples.js.map +0 -7
- package/dist/schemas/extensions/operation/x-post-response.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js.map +0 -7
- package/dist/schemas/extensions/operation/x-scalar-stability.js.map +0 -7
- package/dist/schemas/extensions/parameter/x-global.js.map +0 -7
- package/dist/schemas/extensions/schema/x-additional-properties-name.js.map +0 -7
- package/dist/schemas/extensions/schema/x-enum-descriptions.js.map +0 -7
- package/dist/schemas/extensions/schema/x-enum-varnames.js.map +0 -7
- package/dist/schemas/extensions/schema/x-examples.js.map +0 -7
- package/dist/schemas/extensions/schema/x-variable.js.map +0 -7
- package/dist/schemas/extensions/security/index.js.map +0 -7
- package/dist/schemas/extensions/security/x-default-scopes.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-credentials-location.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-body.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-query.js.map +0 -7
- package/dist/schemas/extensions/security/x-scalar-security-secrets.js.map +0 -7
- package/dist/schemas/extensions/security/x-tokenName.js.map +0 -7
- package/dist/schemas/extensions/security/x-use-pkce.js.map +0 -7
- package/dist/schemas/extensions/server/x-scalar-selected-server.js.map +0 -7
- package/dist/schemas/extensions/tag/index.js.map +0 -7
- package/dist/schemas/extensions/tag/x-display-name.js.map +0 -7
- package/dist/schemas/extensions/tag/x-tag-groups.js.map +0 -7
- package/dist/schemas/extensions/workspace/index.js.map +0 -7
- package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js.map +0 -7
- package/dist/schemas/extensions/workspace/x-scalar-tabs.js.map +0 -7
- package/dist/schemas/extensions.js.map +0 -7
- package/dist/schemas/inmemory-workspace.js.map +0 -7
- package/dist/schemas/navigation.js.map +0 -7
- package/dist/schemas/reference-config/appearance.js.map +0 -7
- package/dist/schemas/reference-config/features.js.map +0 -7
- package/dist/schemas/reference-config/index.js.map +0 -7
- package/dist/schemas/reference-config/meta.js.map +0 -7
- package/dist/schemas/reference-config/routing.js.map +0 -7
- package/dist/schemas/reference-config/settings.js.map +0 -7
- package/dist/schemas/typebox-coerce.js.map +0 -7
- package/dist/schemas/v3.1/strict/callback.js.map +0 -7
- package/dist/schemas/v3.1/strict/components.js.map +0 -7
- package/dist/schemas/v3.1/strict/contact.js.map +0 -7
- package/dist/schemas/v3.1/strict/discriminator.js.map +0 -7
- package/dist/schemas/v3.1/strict/encoding.js.map +0 -7
- package/dist/schemas/v3.1/strict/example.js.map +0 -7
- package/dist/schemas/v3.1/strict/external-documentation.js.map +0 -7
- package/dist/schemas/v3.1/strict/header.js.map +0 -7
- package/dist/schemas/v3.1/strict/info.js.map +0 -7
- package/dist/schemas/v3.1/strict/license.js.map +0 -7
- package/dist/schemas/v3.1/strict/link.js.map +0 -7
- package/dist/schemas/v3.1/strict/media-type.js.map +0 -7
- package/dist/schemas/v3.1/strict/oauth-flow.js.map +0 -7
- package/dist/schemas/v3.1/strict/oauthflows.js.map +0 -7
- package/dist/schemas/v3.1/strict/openapi-document.js.map +0 -7
- package/dist/schemas/v3.1/strict/operation.js.map +0 -7
- package/dist/schemas/v3.1/strict/parameter.js.map +0 -7
- package/dist/schemas/v3.1/strict/path-item.js.map +0 -7
- package/dist/schemas/v3.1/strict/paths.js.map +0 -7
- package/dist/schemas/v3.1/strict/ref-definitions.js.map +0 -7
- package/dist/schemas/v3.1/strict/reference.js.map +0 -7
- package/dist/schemas/v3.1/strict/request-body.js.map +0 -7
- package/dist/schemas/v3.1/strict/response.js.map +0 -7
- package/dist/schemas/v3.1/strict/responses.js.map +0 -7
- package/dist/schemas/v3.1/strict/schema.js.map +0 -7
- package/dist/schemas/v3.1/strict/security-requirement.js.map +0 -7
- package/dist/schemas/v3.1/strict/security-scheme.js.map +0 -7
- package/dist/schemas/v3.1/strict/server-variable.js.map +0 -7
- package/dist/schemas/v3.1/strict/server.js.map +0 -7
- package/dist/schemas/v3.1/strict/tag.js.map +0 -7
- package/dist/schemas/v3.1/strict/type-guards.js.map +0 -7
- package/dist/schemas/v3.1/strict/xml.js.map +0 -7
- package/dist/schemas/workspace-specification/index.js.map +0 -7
- package/dist/schemas/workspace-specification/info.js.map +0 -7
- package/dist/schemas/workspace.js.map +0 -7
- package/dist/schemas.js.map +0 -7
- package/dist/server.js.map +0 -7
- package/dist/workspace-plugin.js.map +0 -7
|
@@ -1,100 +1,164 @@
|
|
|
1
|
-
import { getResolvedRef } from
|
|
2
|
-
import { unpackProxyObject } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { getResolvedRef } from '../../helpers/get-resolved-ref.js';
|
|
2
|
+
import { unpackProxyObject } from '../../helpers/unpack-proxy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Updates an existing parameter of a given `type` by its index within that
|
|
5
|
+
* type subset (e.g. the N-th query parameter). Supports updating name, value,
|
|
6
|
+
* and enabled state for the targeted example.
|
|
7
|
+
* Safely no-ops if the document, operation, or parameter does not exist.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
* ```ts
|
|
11
|
+
* updateOperationParameter({
|
|
12
|
+
* document,
|
|
13
|
+
* type: 'query',
|
|
14
|
+
* index: 0,
|
|
15
|
+
* meta: { method: 'get', path: '/search', exampleKey: 'default' },
|
|
16
|
+
* payload: { value: 'alice', isDisabled: false },
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const upsertOperationParameter = (document, { meta, type, payload, originalParameter }) => {
|
|
21
|
+
// We are editing an existing parameter
|
|
22
|
+
if (originalParameter) {
|
|
23
|
+
// To support content-type parameters in the API client, we just assume an
|
|
24
|
+
// examples property can be set.
|
|
25
|
+
const param = originalParameter;
|
|
26
|
+
param.name = payload.name;
|
|
27
|
+
if (!param.examples) {
|
|
28
|
+
param.examples = {};
|
|
29
|
+
}
|
|
30
|
+
// Create the example if it doesn't exist
|
|
31
|
+
if (!param.examples[meta.exampleKey]) {
|
|
32
|
+
param.examples[meta.exampleKey] = {};
|
|
33
|
+
}
|
|
34
|
+
const example = getResolvedRef(param.examples[meta.exampleKey]);
|
|
35
|
+
// Update the example value and disabled state
|
|
36
|
+
example.value = payload.value;
|
|
37
|
+
example['x-disabled'] = payload.isDisabled;
|
|
38
|
+
return;
|
|
9
39
|
}
|
|
10
|
-
|
|
11
|
-
|
|
40
|
+
// We are adding a new parameter
|
|
41
|
+
const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
|
|
42
|
+
if (!operation) {
|
|
43
|
+
console.error('Operation not found', { meta, document });
|
|
44
|
+
return;
|
|
12
45
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
46
|
+
operation.parameters ||= [];
|
|
47
|
+
operation.parameters.push({
|
|
48
|
+
name: payload.name,
|
|
49
|
+
in: type,
|
|
50
|
+
required: type === 'path' ? true : false,
|
|
51
|
+
examples: {
|
|
52
|
+
[meta.exampleKey]: {
|
|
53
|
+
value: payload.value,
|
|
54
|
+
// We always want a new parameter to be enabled by default
|
|
55
|
+
'x-disabled': false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
16
59
|
return;
|
|
17
|
-
}
|
|
18
|
-
const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
|
|
19
|
-
if (!operation) {
|
|
20
|
-
console.error("Operation not found", { meta, document });
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
operation.parameters ||= [];
|
|
24
|
-
operation.parameters.push({
|
|
25
|
-
name: payload.name,
|
|
26
|
-
in: type,
|
|
27
|
-
required: type === "path" ? true : false,
|
|
28
|
-
examples: {
|
|
29
|
-
[meta.exampleKey]: {
|
|
30
|
-
value: payload.value,
|
|
31
|
-
// We always want a new parameter to be enabled by default
|
|
32
|
-
"x-disabled": false
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
60
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Updates the disabled state of a default parameter for an operation.
|
|
63
|
+
* Default parameters are inherited from higher-level configurations (like collection or server defaults)
|
|
64
|
+
* and this allows individual operations to selectively disable them without removing them entirely.
|
|
65
|
+
*
|
|
66
|
+
* The disabled state is stored in the `x-scalar-disable-parameters` extension object, organized by
|
|
67
|
+
* parameter type and example key. Missing objects are initialized automatically.
|
|
68
|
+
*
|
|
69
|
+
* @param document - The current workspace document
|
|
70
|
+
* @param type - The parameter type (e.g., 'header'). Determines the storage key ('default-headers' for headers)
|
|
71
|
+
* @param meta.path - Path of the operation (e.g., '/users')
|
|
72
|
+
* @param meta.method - HTTP method of the operation (e.g., 'get')
|
|
73
|
+
* @param meta.exampleKey - Key identifying the relevant example
|
|
74
|
+
* @param meta.key - The specific parameter key being updated
|
|
75
|
+
* @param payload.isDisabled - Whether the parameter should be disabled
|
|
76
|
+
*/
|
|
77
|
+
export const updateOperationExtraParameters = (document, { type, meta, payload, in: location }) => {
|
|
78
|
+
// Ensure there's a valid document
|
|
79
|
+
if (!document) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Resolve the referenced operation from the document using the path and method
|
|
83
|
+
const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
|
|
84
|
+
if (!operation) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Initialize the 'x-scalar-disable-parameters' object if it doesn't exist
|
|
88
|
+
if (!operation['x-scalar-disable-parameters']) {
|
|
89
|
+
operation['x-scalar-disable-parameters'] = {};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Maps parameter type and location to the corresponding config key.
|
|
93
|
+
* Only valid combinations are defined here.
|
|
94
|
+
*/
|
|
95
|
+
const mapping = {
|
|
96
|
+
global: { cookie: 'global-cookies' },
|
|
97
|
+
default: { header: 'default-headers' },
|
|
98
|
+
};
|
|
99
|
+
const key = mapping[type]?.[location];
|
|
100
|
+
if (!key) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Initialize the 'default-headers' object within 'x-scalar-disable-parameters' if it doesn't exist
|
|
104
|
+
if (!operation['x-scalar-disable-parameters'][key]) {
|
|
105
|
+
operation['x-scalar-disable-parameters'][key] = {};
|
|
106
|
+
}
|
|
107
|
+
// Update (or create) the entry for the specific example and key, preserving any existing settings
|
|
108
|
+
operation['x-scalar-disable-parameters'][key][meta.exampleKey] = {
|
|
109
|
+
...(operation['x-scalar-disable-parameters'][key][meta.exampleKey] ?? {}),
|
|
110
|
+
[meta.name]: payload.isDisabled ?? false,
|
|
111
|
+
};
|
|
83
112
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Removes a parameter from the operation OR path
|
|
115
|
+
*
|
|
116
|
+
* Example:
|
|
117
|
+
* ```ts
|
|
118
|
+
* deleteOperationParameter({
|
|
119
|
+
* document,
|
|
120
|
+
* originalParameter,
|
|
121
|
+
* meta: { method: 'get', path: '/users', exampleKey: 'default' },
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export const deleteOperationParameter = (document, { meta, originalParameter }) => {
|
|
126
|
+
const operation = getResolvedRef(document?.paths?.[meta.path]?.[meta.method]);
|
|
127
|
+
// Lets check if its on the operation first as its more likely
|
|
128
|
+
const operationIndex = operation?.parameters?.findIndex((it) => getResolvedRef(it) === originalParameter) ?? -1;
|
|
129
|
+
// We cannot call splice on a proxy object, so we unwrap the array and filter it
|
|
130
|
+
if (operation && operationIndex >= 0) {
|
|
131
|
+
operation.parameters = unpackProxyObject(operation.parameters?.filter((_, i) => i !== operationIndex), { depth: 1 });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// If it wasn't on the operation it might be on the path
|
|
135
|
+
const path = getResolvedRef(document?.paths?.[meta.path]);
|
|
136
|
+
const pathIndex = path?.parameters?.findIndex((it) => getResolvedRef(it) === originalParameter) ?? -1;
|
|
137
|
+
if (path && pathIndex >= 0) {
|
|
138
|
+
path.parameters = unpackProxyObject(path.parameters?.filter((_, i) => i !== pathIndex), { depth: 1 });
|
|
139
|
+
}
|
|
93
140
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Deletes all parameters of a given `type` from the operation.
|
|
143
|
+
* Safely no-ops if the document or operation does not exist.
|
|
144
|
+
*
|
|
145
|
+
* Example:
|
|
146
|
+
* ```ts
|
|
147
|
+
* deleteAllOperationParameters({
|
|
148
|
+
* document,
|
|
149
|
+
* type: 'cookie',
|
|
150
|
+
* meta: { method: 'get', path: '/users' },
|
|
151
|
+
* })
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export const deleteAllOperationParameters = (document, { meta, type }) => {
|
|
155
|
+
if (!document) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method]);
|
|
159
|
+
if (!operation) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// Filter out parameters of the specified type
|
|
163
|
+
operation.parameters = operation.parameters?.filter((it) => getResolvedRef(it).in !== type) ?? [];
|
|
99
164
|
};
|
|
100
|
-
//# sourceMappingURL=parameters.js.map
|
package/dist/mutators/server.js
CHANGED
|
@@ -1,166 +1,227 @@
|
|
|
1
|
-
import { findVariables } from
|
|
2
|
-
import { getResolvedRef } from
|
|
3
|
-
import { unpackProxyObject } from
|
|
4
|
-
import { coerceValue } from
|
|
5
|
-
import { ServerObjectSchema } from
|
|
1
|
+
import { findVariables } from '@scalar/helpers/regex/find-variables';
|
|
2
|
+
import { getResolvedRef } from '../helpers/get-resolved-ref.js';
|
|
3
|
+
import { unpackProxyObject } from '../helpers/unpack-proxy.js';
|
|
4
|
+
import { coerceValue } from '../schemas/typebox-coerce.js';
|
|
5
|
+
import { ServerObjectSchema } from '../schemas/v3.1/strict/openapi-document.js';
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the server target (document or operation) from meta.
|
|
8
|
+
* Document-level servers live on the document; operation-level servers on the operation object.
|
|
9
|
+
*/
|
|
6
10
|
const getServerTarget = (document, meta) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
const initializeServers = (document, { meta }) => {
|
|
16
|
-
const target = getServerTarget(document, meta);
|
|
17
|
-
if (!target) {
|
|
18
|
-
console.error("Target not found", meta);
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
target.servers = [];
|
|
22
|
-
return target.servers;
|
|
11
|
+
if (!document) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
if (meta.type === 'document') {
|
|
15
|
+
return document;
|
|
16
|
+
}
|
|
17
|
+
return getResolvedRef(document.paths?.[meta.path]?.[meta.method]) ?? null;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Initializes the servers for the document or operation based on meta.
|
|
21
|
+
*
|
|
22
|
+
* @param document - The document to initialize the servers for
|
|
23
|
+
* @param meta - Target context (document or operation)
|
|
24
|
+
*/
|
|
25
|
+
export const initializeServers = (document, { meta }) => {
|
|
26
|
+
const target = getServerTarget(document, meta);
|
|
27
|
+
if (!target) {
|
|
28
|
+
console.error('Target not found', meta);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
32
31
|
target.servers = [];
|
|
33
|
-
|
|
34
|
-
target.servers.push(parsed);
|
|
35
|
-
return parsed;
|
|
32
|
+
return target.servers;
|
|
36
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Adds a new ServerObject to the document or operation based on meta.
|
|
36
|
+
*
|
|
37
|
+
* @param document - The document to add the server to
|
|
38
|
+
* @returns the new server object or undefined if the target is not found
|
|
39
|
+
*/
|
|
40
|
+
export const addServer = (document, { meta }) => {
|
|
41
|
+
const target = getServerTarget(document, meta);
|
|
42
|
+
if (!target) {
|
|
43
|
+
console.error('Target not found', meta);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const parsed = coerceValue(ServerObjectSchema, {});
|
|
47
|
+
if (!target.servers) {
|
|
48
|
+
target.servers = [];
|
|
49
|
+
}
|
|
50
|
+
target.servers.push(parsed);
|
|
51
|
+
return parsed;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Creates a map of variable names to their character positions in a URL.
|
|
55
|
+
* Used to detect renamed variables by position matching.
|
|
56
|
+
*/
|
|
37
57
|
const getVariablePositions = (url, variables) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
const positions = {};
|
|
59
|
+
for (const varName of variables) {
|
|
60
|
+
const position = url.indexOf(`{${varName}}`);
|
|
61
|
+
if (position !== -1) {
|
|
62
|
+
positions[varName] = position;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return positions;
|
|
46
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Syncs server variables when the URL changes.
|
|
69
|
+
*
|
|
70
|
+
* Preserves variable configurations by:
|
|
71
|
+
* 1. Keeping variables with matching names
|
|
72
|
+
* 2. Renaming variables at the same position
|
|
73
|
+
* 3. Creating new variables with empty defaults
|
|
74
|
+
*/
|
|
47
75
|
const syncVariablesForUrlChange = (newUrl, oldUrl, existingVariables) => {
|
|
48
|
-
|
|
49
|
-
(v) => v !==
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return syncedVariables;
|
|
76
|
-
};
|
|
77
|
-
const updateServer = (document, { index, server, meta }) => {
|
|
78
|
-
const target = getServerTarget(document, meta);
|
|
79
|
-
if (!target) {
|
|
80
|
-
return void 0;
|
|
81
|
-
}
|
|
82
|
-
const oldServer = unpackProxyObject(target.servers?.[index], { depth: 1 });
|
|
83
|
-
if (!oldServer) {
|
|
84
|
-
console.error("Server not found at index:", index);
|
|
85
|
-
return void 0;
|
|
86
|
-
}
|
|
87
|
-
const oldUrl = oldServer.url;
|
|
88
|
-
const updatedServer = coerceValue(ServerObjectSchema, { ...oldServer, ...server });
|
|
89
|
-
const hasUrlChanged = oldUrl && oldUrl !== updatedServer.url;
|
|
90
|
-
if (hasUrlChanged) {
|
|
91
|
-
const existingVariables = updatedServer.variables ?? {};
|
|
92
|
-
updatedServer.variables = syncVariablesForUrlChange(updatedServer.url, oldUrl, existingVariables);
|
|
93
|
-
if (target["x-scalar-selected-server"] === oldUrl) {
|
|
94
|
-
target["x-scalar-selected-server"] = updatedServer.url;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (!target.servers) {
|
|
98
|
-
target.servers = [updatedServer];
|
|
99
|
-
} else {
|
|
100
|
-
target.servers[index] = updatedServer;
|
|
101
|
-
}
|
|
102
|
-
return updatedServer;
|
|
76
|
+
// Filter out undefined values from findVariables results
|
|
77
|
+
const oldVariables = findVariables(oldUrl, { includePath: true, includeEnv: false }).filter((v) => v !== undefined);
|
|
78
|
+
const newVariables = findVariables(newUrl, { includePath: true, includeEnv: false }).filter((v) => v !== undefined);
|
|
79
|
+
const oldPositions = getVariablePositions(oldUrl, oldVariables);
|
|
80
|
+
const newPositions = getVariablePositions(newUrl, newVariables);
|
|
81
|
+
const usedOldVariables = new Set();
|
|
82
|
+
const syncedVariables = {};
|
|
83
|
+
for (const newVar of newVariables) {
|
|
84
|
+
// Case 1: Variable with same name exists - preserve its config
|
|
85
|
+
if (existingVariables[newVar]) {
|
|
86
|
+
syncedVariables[newVar] = existingVariables[newVar];
|
|
87
|
+
usedOldVariables.add(newVar);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// Case 2: Check for variable at same position (likely a rename)
|
|
91
|
+
const newVarPosition = newPositions[newVar];
|
|
92
|
+
const oldVarAtPosition = oldVariables.find((oldVar) => oldPositions[oldVar] === newVarPosition && !usedOldVariables.has(oldVar));
|
|
93
|
+
if (oldVarAtPosition && existingVariables[oldVarAtPosition]) {
|
|
94
|
+
// Rename: transfer the old variable's config to the new name
|
|
95
|
+
syncedVariables[newVar] = existingVariables[oldVarAtPosition];
|
|
96
|
+
usedOldVariables.add(oldVarAtPosition);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
// Case 3: New variable - create with empty default
|
|
100
|
+
syncedVariables[newVar] = { default: '' };
|
|
101
|
+
}
|
|
102
|
+
return syncedVariables;
|
|
103
103
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Updates a ServerObject in the document or operation based on meta.
|
|
106
|
+
* When the URL changes, intelligently syncs variables by preserving configurations
|
|
107
|
+
* for renamed variables (detected by position) and existing variables.
|
|
108
|
+
*
|
|
109
|
+
* @param document - The document containing the server to update
|
|
110
|
+
* @param index - The index of the server to update
|
|
111
|
+
* @param server - The partial server object with fields to update
|
|
112
|
+
* @param meta - Target context (document or operation)
|
|
113
|
+
* @returns the updated server object or undefined if the server is not found
|
|
114
|
+
*/
|
|
115
|
+
export const updateServer = (document, { index, server, meta }) => {
|
|
116
|
+
const target = getServerTarget(document, meta);
|
|
117
|
+
if (!target) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const oldServer = unpackProxyObject(target.servers?.[index], { depth: 1 });
|
|
121
|
+
if (!oldServer) {
|
|
122
|
+
console.error('Server not found at index:', index);
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
const oldUrl = oldServer.url;
|
|
126
|
+
const updatedServer = coerceValue(ServerObjectSchema, { ...oldServer, ...server });
|
|
127
|
+
const hasUrlChanged = oldUrl && oldUrl !== updatedServer.url;
|
|
128
|
+
if (hasUrlChanged) {
|
|
129
|
+
const existingVariables = updatedServer.variables ?? {};
|
|
130
|
+
updatedServer.variables = syncVariablesForUrlChange(updatedServer.url, oldUrl, existingVariables);
|
|
131
|
+
if (target['x-scalar-selected-server'] === oldUrl) {
|
|
132
|
+
target['x-scalar-selected-server'] = updatedServer.url;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!target.servers) {
|
|
136
|
+
target.servers = [updatedServer];
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
target.servers[index] = updatedServer;
|
|
140
|
+
}
|
|
141
|
+
return updatedServer;
|
|
114
142
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Deletes a ServerObject at the specified index from the document or operation based on meta.
|
|
145
|
+
*
|
|
146
|
+
* @param document - The document to delete the server from
|
|
147
|
+
* @param index - The index of the server to delete
|
|
148
|
+
* @param meta - Target context (document or operation)
|
|
149
|
+
*/
|
|
150
|
+
export const deleteServer = (document, { index, meta }) => {
|
|
151
|
+
const target = getServerTarget(document, meta);
|
|
152
|
+
if (!target?.servers) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const url = target.servers[index]?.url;
|
|
156
|
+
target.servers.splice(index, 1);
|
|
157
|
+
if (target['x-scalar-selected-server'] === url) {
|
|
158
|
+
target['x-scalar-selected-server'] = target.servers[0]?.url ?? undefined;
|
|
159
|
+
}
|
|
122
160
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Clears all servers from the document or operation based on meta.
|
|
163
|
+
*
|
|
164
|
+
* @param document - The document to clear the servers from
|
|
165
|
+
* @param meta - Target context (document or operation)
|
|
166
|
+
*/
|
|
167
|
+
export const clearServers = (document, { meta }) => {
|
|
168
|
+
const target = getServerTarget(document, meta);
|
|
169
|
+
if (!target) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
// Remove the servers array
|
|
173
|
+
target.servers = undefined;
|
|
174
|
+
// Clear the selected server
|
|
175
|
+
target['x-scalar-selected-server'] = undefined;
|
|
132
176
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Updates a server variable for the document or operation based on meta.
|
|
179
|
+
*
|
|
180
|
+
* @param document - The document to update the server variables in
|
|
181
|
+
* @param index - The index of the server to update
|
|
182
|
+
* @param key - The key of the variable to update
|
|
183
|
+
* @param value - The new value of the variable
|
|
184
|
+
* @param meta - Target context (document or operation)
|
|
185
|
+
* @returns the updated variable or undefined if the variable is not found
|
|
186
|
+
*/
|
|
187
|
+
export const updateServerVariables = (document, { index, key, value, meta }) => {
|
|
188
|
+
const target = getServerTarget(document, meta);
|
|
189
|
+
const variable = target?.servers?.[index]?.variables?.[key];
|
|
190
|
+
if (!variable) {
|
|
191
|
+
console.error('Variable not found', key, index);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
variable.default = value;
|
|
195
|
+
return variable;
|
|
144
196
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Updates the selected server for the document or operation based on meta.
|
|
199
|
+
*
|
|
200
|
+
* @param document - The document to update the selected server in
|
|
201
|
+
* @param url - The URL of the server to select (or '' to clear)
|
|
202
|
+
* @param meta - Target context (document or operation)
|
|
203
|
+
* @returns the url of the selected server or undefined if the target is not found
|
|
204
|
+
*/
|
|
205
|
+
export const updateSelectedServer = (document, { url, meta }) => {
|
|
206
|
+
const target = getServerTarget(document, meta);
|
|
207
|
+
if (!target) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (url === '') {
|
|
211
|
+
target['x-scalar-selected-server'] = '';
|
|
212
|
+
return '';
|
|
213
|
+
}
|
|
214
|
+
target['x-scalar-selected-server'] = target['x-scalar-selected-server'] === url ? '' : url;
|
|
215
|
+
return target['x-scalar-selected-server'];
|
|
155
216
|
};
|
|
156
|
-
export {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
217
|
+
export const serverMutatorsFactory = ({ document }) => {
|
|
218
|
+
return {
|
|
219
|
+
initializeServers: (payload) => initializeServers(document, payload),
|
|
220
|
+
addServer: (payload) => addServer(document, payload),
|
|
221
|
+
updateServer: (payload) => updateServer(document, payload),
|
|
222
|
+
deleteServer: (payload) => deleteServer(document, payload),
|
|
223
|
+
clearServers: (payload) => clearServers(document, payload),
|
|
224
|
+
updateServerVariables: (payload) => updateServerVariables(document, payload),
|
|
225
|
+
updateSelectedServer: (payload) => updateSelectedServer(document, payload),
|
|
226
|
+
};
|
|
165
227
|
};
|
|
166
|
-
//# sourceMappingURL=server.js.map
|