@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,48 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Updates the active proxy for the given workspace.
|
|
3
|
+
*
|
|
4
|
+
* @param workspace - The workspace to update
|
|
5
|
+
* @param payload - The new active proxy value
|
|
6
|
+
*/
|
|
7
|
+
export const updateActiveProxy = (workspace, payload) => {
|
|
8
|
+
// If workspace is null, exit early
|
|
9
|
+
if (!workspace) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// Set or clear the active proxy in the workspace object
|
|
13
|
+
workspace['x-scalar-active-proxy'] = payload;
|
|
6
14
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Updates the color mode for the given workspace.
|
|
17
|
+
*
|
|
18
|
+
* @param workspace - The workspace to update
|
|
19
|
+
* @param payload - The new color mode value
|
|
20
|
+
*/
|
|
21
|
+
export const updateColorMode = (workspace, payload) => {
|
|
22
|
+
// If workspace is null, do nothing
|
|
23
|
+
if (!workspace) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Set the color mode in the workspace object
|
|
27
|
+
workspace['x-scalar-color-mode'] = payload;
|
|
12
28
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Updates the theme for the given workspace.
|
|
31
|
+
*
|
|
32
|
+
* @param workspace - The workspace to update
|
|
33
|
+
* @param payload - The new theme value
|
|
34
|
+
*/
|
|
35
|
+
export const updateTheme = (workspace, payload) => {
|
|
36
|
+
// If workspace is null, exit early
|
|
37
|
+
if (!workspace) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Set the theme in the workspace object
|
|
41
|
+
workspace['x-scalar-theme'] = payload;
|
|
18
42
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Updates the active environment for the given workspace.
|
|
45
|
+
*
|
|
46
|
+
* @param workspace - The workspace to update
|
|
47
|
+
* @param payload - The new active environment value
|
|
48
|
+
*/
|
|
49
|
+
export const updateActiveEnvironment = (workspace, payload) => {
|
|
50
|
+
// If workspace is null, exit early
|
|
51
|
+
if (!workspace) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Set the active environment in the workspace object
|
|
55
|
+
workspace['x-scalar-active-environment'] = payload ?? undefined;
|
|
24
56
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Updates the selected http client on the workspace
|
|
59
|
+
*
|
|
60
|
+
* @param workspace - The workspace to update the selected http client in
|
|
61
|
+
* @param payload - The payload to update the selected client with
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
export const updateSelectedClient = (workspace, payload) => {
|
|
65
|
+
if (!workspace) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
workspace['x-scalar-default-client'] = payload;
|
|
30
69
|
};
|
|
31
|
-
const workspaceMutatorsFactory = ({ workspace }) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
70
|
+
export const workspaceMutatorsFactory = ({ workspace }) => {
|
|
71
|
+
return {
|
|
72
|
+
updateActiveProxy: (payload) => updateActiveProxy(workspace, payload),
|
|
73
|
+
updateColorMode: (payload) => updateColorMode(workspace, payload),
|
|
74
|
+
updateTheme: (payload) => updateTheme(workspace, payload),
|
|
75
|
+
updateSelectedClient: (payload) => updateSelectedClient(workspace, payload),
|
|
76
|
+
updateActiveEnvironment: (payload) => updateActiveEnvironment(workspace, payload),
|
|
77
|
+
};
|
|
39
78
|
};
|
|
40
|
-
export {
|
|
41
|
-
updateActiveEnvironment,
|
|
42
|
-
updateActiveProxy,
|
|
43
|
-
updateColorMode,
|
|
44
|
-
updateSelectedClient,
|
|
45
|
-
updateTheme,
|
|
46
|
-
workspaceMutatorsFactory
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=workspace.js.map
|
|
@@ -1,85 +1,98 @@
|
|
|
1
|
-
import { slug } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
1
|
+
import { slug } from 'github-slugger';
|
|
2
|
+
/**
|
|
3
|
+
* Returns options for traversing an OpenAPI document, allowing customization of
|
|
4
|
+
* how IDs and slugs are generated for tags, headings, models, operations, and webhooks.
|
|
5
|
+
* The returned options can be influenced by the provided DocumentConfiguration
|
|
6
|
+
*/
|
|
7
|
+
export const getNavigationOptions = (documentName, options) => {
|
|
8
|
+
const generateId = (props) => {
|
|
9
|
+
const documentId = `${slug(documentName)}`;
|
|
10
|
+
// -------- Default text id generation logic --------
|
|
11
|
+
if (props.type === 'text') {
|
|
12
|
+
if (options?.generateHeadingSlug) {
|
|
13
|
+
return options?.generateHeadingSlug({ slug: props.slug });
|
|
14
|
+
}
|
|
15
|
+
if (props.slug) {
|
|
16
|
+
return `${documentId}/description/${props.slug}`;
|
|
17
|
+
}
|
|
18
|
+
return `${documentId}/`;
|
|
19
|
+
}
|
|
20
|
+
// -------- Default tag id generation logic --------
|
|
21
|
+
if (props.type === 'tag') {
|
|
22
|
+
if (options?.generateTagSlug) {
|
|
23
|
+
return `${documentId}/tag/${options.generateTagSlug(props.tag)}`;
|
|
24
|
+
}
|
|
25
|
+
return `${documentId}/tag/${slug(props.tag.name ?? '')}`;
|
|
26
|
+
}
|
|
27
|
+
// -------- Default operation id generation logic --------
|
|
28
|
+
if (props.type === 'operation') {
|
|
29
|
+
const prefixTag = props.parentTag
|
|
30
|
+
? `${generateId({
|
|
31
|
+
type: 'tag',
|
|
32
|
+
tag: props.parentTag.tag,
|
|
33
|
+
parentId: props.parentTag.id,
|
|
34
|
+
})}/`
|
|
35
|
+
: `${documentId}/`;
|
|
36
|
+
if (options?.generateOperationSlug) {
|
|
37
|
+
return `${prefixTag}${options.generateOperationSlug({
|
|
38
|
+
path: props.path,
|
|
39
|
+
operationId: props.operation.operationId,
|
|
40
|
+
method: props.method.toUpperCase(),
|
|
41
|
+
summary: props.operation.summary,
|
|
42
|
+
})}`;
|
|
43
|
+
}
|
|
44
|
+
return `${prefixTag}${props.method.toUpperCase()}${props.path}`;
|
|
45
|
+
}
|
|
46
|
+
// -------- Default webhook id generation logic --------
|
|
47
|
+
if (props.type === 'webhook') {
|
|
48
|
+
const prefixTag = props.parentTag
|
|
49
|
+
? `${generateId({
|
|
50
|
+
type: 'tag',
|
|
51
|
+
parentId: props.parentTag.id,
|
|
52
|
+
tag: props.parentTag.tag,
|
|
53
|
+
})}/`
|
|
54
|
+
: `${documentId}/`;
|
|
55
|
+
if (options?.generateWebhookSlug) {
|
|
56
|
+
return `${prefixTag}webhook/${options.generateWebhookSlug({
|
|
57
|
+
name: props.name,
|
|
58
|
+
method: props.method?.toUpperCase(),
|
|
59
|
+
})}`;
|
|
60
|
+
}
|
|
61
|
+
return `${prefixTag}webhook/${props.method?.toUpperCase()}/${slug(props.name)}`;
|
|
62
|
+
}
|
|
63
|
+
// -------- Default model id generation logic --------
|
|
64
|
+
if (props.type === 'model') {
|
|
65
|
+
if (!props.name) {
|
|
66
|
+
return `${documentId}/models`;
|
|
67
|
+
}
|
|
68
|
+
const prefixTag = props.parentTag
|
|
69
|
+
? `${generateId({
|
|
70
|
+
type: 'tag',
|
|
71
|
+
parentId: props.parentTag.id,
|
|
72
|
+
tag: props.parentTag.tag,
|
|
73
|
+
})}/`
|
|
74
|
+
: `${documentId}/`;
|
|
75
|
+
if (options?.generateModelSlug) {
|
|
76
|
+
return `${prefixTag}model/${options.generateModelSlug({
|
|
77
|
+
name: props.name,
|
|
78
|
+
})}`;
|
|
79
|
+
}
|
|
80
|
+
return `${prefixTag}model/${slug(props.name, true)}`;
|
|
81
|
+
}
|
|
82
|
+
if (props.type === 'example') {
|
|
83
|
+
return `${props.parentId}/example/${slug(props.name)}`;
|
|
84
|
+
}
|
|
85
|
+
if (props.type === 'document') {
|
|
86
|
+
// -------- Default document id generation logic --------
|
|
87
|
+
return documentId;
|
|
88
|
+
}
|
|
89
|
+
console.warn('[WARNING]: unhandled id generation for navigation item:', props);
|
|
90
|
+
return 'unknown-id';
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
hideModels: options?.hideModels ?? false,
|
|
94
|
+
operationsSorter: options?.operationsSorter,
|
|
95
|
+
tagsSorter: options?.tagsSorter,
|
|
96
|
+
generateId,
|
|
97
|
+
};
|
|
81
98
|
};
|
|
82
|
-
export {
|
|
83
|
-
getNavigationOptions
|
|
84
|
-
};
|
|
85
|
-
//# sourceMappingURL=get-navigation-options.js.map
|
|
@@ -1,31 +1,48 @@
|
|
|
1
|
-
import { getResolvedRef } from
|
|
2
|
-
import { getParentEntry } from
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { getResolvedRef } from '../../helpers/get-resolved-ref.js';
|
|
2
|
+
import { getParentEntry } from './get-parent-entry.js';
|
|
3
|
+
/** Type guard which checks if the entry has an x-scalar-order property */
|
|
4
|
+
export const canHaveOrder = (entry) => entry.type === 'document' || entry.type === 'tag' || entry.type === 'operation';
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the corresponding OpenAPI object (document, tag, or operation) from the workspace store based on the provided entry.
|
|
7
|
+
*
|
|
8
|
+
* This helper abstracts the common lookup logic for working with sidebar/drag-and-drop entries and their associated OpenAPI objects.
|
|
9
|
+
* Returns `null` when the lookup cannot be completed (e.g., document/tag/operation not found).
|
|
10
|
+
*
|
|
11
|
+
* @template Entry Either TraversedDocument, TraversedTag, or TraversedOperation.
|
|
12
|
+
* @param store - The workspace store containing loaded documents.
|
|
13
|
+
* @param entry - The sidebar entry (document, tag, or operation).
|
|
14
|
+
* @returns The corresponding OpenAPI object (WorkspaceDocument, TagObject, or OperationObject) or `null` if not found.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // For a Document entry:
|
|
18
|
+
* const document = getOpenapiObject({ store, entry: documentEntry })
|
|
19
|
+
*
|
|
20
|
+
* // For a Tag entry:
|
|
21
|
+
* const tag = getOpenapiObject({ store, entry: tagEntry })
|
|
22
|
+
*
|
|
23
|
+
* // For an Operation entry:
|
|
24
|
+
* const operation = getOpenapiObject({ store, entry: operationEntry })
|
|
25
|
+
*/
|
|
26
|
+
export const getOpenapiObject = ({ store, entry, }) => {
|
|
27
|
+
const documentEntry = getParentEntry('document', entry);
|
|
28
|
+
if (!documentEntry) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const document = store.workspace.documents[documentEntry.name];
|
|
32
|
+
if (!document) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (entry.type === 'document') {
|
|
36
|
+
return document;
|
|
37
|
+
}
|
|
38
|
+
if (entry.type === 'tag') {
|
|
39
|
+
// Find the tag by name in the document's tags array
|
|
40
|
+
return document.tags?.find((tag) => tag.name === entry.name) ?? null;
|
|
41
|
+
}
|
|
42
|
+
if (entry.type === 'operation') {
|
|
43
|
+
// Fetch and resolve the referenced operation object at the given path/method
|
|
44
|
+
return getResolvedRef(document.paths?.[entry.path]?.[entry.method]) ?? null;
|
|
45
|
+
}
|
|
46
|
+
// If entry type is unknown, return null
|
|
10
47
|
return null;
|
|
11
|
-
}
|
|
12
|
-
const document = store.workspace.documents[documentEntry.name];
|
|
13
|
-
if (!document) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
if (entry.type === "document") {
|
|
17
|
-
return document;
|
|
18
|
-
}
|
|
19
|
-
if (entry.type === "tag") {
|
|
20
|
-
return document.tags?.find((tag) => tag.name === entry.name) ?? null;
|
|
21
|
-
}
|
|
22
|
-
if (entry.type === "operation") {
|
|
23
|
-
return getResolvedRef(document.paths?.[entry.path]?.[entry.method]) ?? null;
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
export {
|
|
28
|
-
canHaveOrder,
|
|
29
|
-
getOpenapiObject
|
|
30
48
|
};
|
|
31
|
-
//# sourceMappingURL=get-openapi-object.js.map
|
|
@@ -1,33 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Builds a map of all operations and webhooks in a document, indexed by path/name and method.
|
|
3
|
+
*
|
|
4
|
+
* This function recursively traverses the document structure and collects all operation and webhook
|
|
5
|
+
* entries. Multiple entries can share the same path|method key (for example, when operations are
|
|
6
|
+
* duplicated across different tags or groups).
|
|
7
|
+
*
|
|
8
|
+
* ~Performance note: If this function is called frequently, consider generating this map once when
|
|
9
|
+
* creating the sidebar state rather than recalculating it in mutators.~
|
|
10
|
+
* Update: we are now generating it features/operation and its drilled down from there
|
|
11
|
+
*
|
|
12
|
+
* @param document - The traversed OpenAPI document to extract operations from
|
|
13
|
+
* @returns A map where keys are `path|method` (for operations) or `name|method` (for webhooks),
|
|
14
|
+
* and values are arrays of matching entries. The pipe separator is used to create a
|
|
15
|
+
* unique composite key from the two parts.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const entries = getOperationEntries(document)
|
|
19
|
+
* const getUsers = entries.get('/users|get') // Array of all GET /users operations
|
|
20
|
+
*/
|
|
21
|
+
export const getOperationEntries = (document) => {
|
|
22
|
+
const map = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* Helper function to add an entry to the map under the specified key.
|
|
25
|
+
* If the key already exists, appends to the array; otherwise creates a new array.
|
|
26
|
+
*
|
|
27
|
+
* @param key - The composite key (path|method or name|method)
|
|
28
|
+
* @param entry - The operation or webhook entry to add (with parent information)
|
|
29
|
+
*/
|
|
30
|
+
const addToMap = (key, entry) => {
|
|
31
|
+
const existing = map.get(key);
|
|
32
|
+
if (existing) {
|
|
33
|
+
existing.push(entry);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
map.set(key, [entry]);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Recursively traverses the document tree to find all operations and webhooks.
|
|
41
|
+
* Handles three entry types:
|
|
42
|
+
* - operations: collected into the map using path|method as key
|
|
43
|
+
* - webhooks: collected into the map using name|method as key
|
|
44
|
+
* - containers (tags, groups): recursively traversed for their children
|
|
45
|
+
*
|
|
46
|
+
* @param entries - Array of entries to traverse (may be undefined for empty sections)
|
|
47
|
+
* @param parent - The parent entry of the current entries (if any)
|
|
48
|
+
*/
|
|
49
|
+
const traverse = (entries, parent) => {
|
|
50
|
+
if (!entries) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
// Handle operations - use path and method to create unique key
|
|
55
|
+
if (entry.type === 'operation') {
|
|
56
|
+
const key = `${entry.path}|${entry.method}`;
|
|
57
|
+
addToMap(key, { ...entry, parent });
|
|
58
|
+
}
|
|
59
|
+
// Handle webhooks - use name and method to create unique key
|
|
60
|
+
else if (entry.type === 'webhook') {
|
|
61
|
+
const key = `${entry.name}|${entry.method}`;
|
|
62
|
+
addToMap(key, { ...entry, parent });
|
|
63
|
+
}
|
|
64
|
+
// Handle containers - recursively traverse children, passing current entry as parent
|
|
65
|
+
else if ('children' in entry && entry.children) {
|
|
66
|
+
traverse(entry.children, { ...entry, parent });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// Start traversal from document root
|
|
71
|
+
traverse(document.children, document);
|
|
72
|
+
return map;
|
|
29
73
|
};
|
|
30
|
-
export {
|
|
31
|
-
getOperationEntries
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=get-operation-entries.js.map
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Traverses up the tree to find and return the closest parent node (including self) of a specified type.
|
|
3
|
+
*
|
|
4
|
+
* @template Type - The type of node to look for.
|
|
5
|
+
* @param type - The type to match in the parent chain.
|
|
6
|
+
* @param node - The node from which traversal begins.
|
|
7
|
+
* @returns The closest parent node of the specified type, or undefined if not found.
|
|
8
|
+
*/
|
|
9
|
+
export const getParentEntry = (type, node) => {
|
|
10
|
+
if (!node) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
if (node.type === type) {
|
|
14
|
+
return node;
|
|
15
|
+
}
|
|
16
|
+
return getParentEntry(type, node.parent);
|
|
9
17
|
};
|
|
10
|
-
export {
|
|
11
|
-
getParentEntry
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=get-parent-entry.js.map
|
|
@@ -1,30 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Builds a map of all tag entries in a document, indexed by tag name.
|
|
3
|
+
*
|
|
4
|
+
* Tags with the same name can appear more than once (for example, when the same tag
|
|
5
|
+
* is referenced in multiple x-tagGroups), so each key maps to an array of matches.
|
|
6
|
+
*
|
|
7
|
+
* This is the tag-side counterpart to `getOperationEntries`. Keep them separate so
|
|
8
|
+
* callers only pay for the traversal they actually need.
|
|
9
|
+
*
|
|
10
|
+
* @param document - The traversed OpenAPI document to extract tags from
|
|
11
|
+
* @returns A map where keys are tag names and values are arrays of matching tag entries,
|
|
12
|
+
* each decorated with a `parent` reference for walking up the tree.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const tags = getTagEntries(document)
|
|
16
|
+
* const userTagEntries = tags.get('Users') // All tag entries named "Users"
|
|
17
|
+
*/
|
|
18
|
+
export const getTagEntries = (document) => {
|
|
19
|
+
const map = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Appends an entry to the array stored at `key`, creating the array if needed.
|
|
22
|
+
*/
|
|
23
|
+
const addToMap = (key, entry) => {
|
|
24
|
+
const existing = map.get(key);
|
|
25
|
+
if (existing) {
|
|
26
|
+
existing.push(entry);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
map.set(key, [entry]);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Recursively walks the document tree collecting tag entries.
|
|
34
|
+
* Tags can be nested (e.g. inside x-tagGroups), so we recurse into their children too.
|
|
35
|
+
*
|
|
36
|
+
* @param entries - The current level of entries to walk (may be undefined)
|
|
37
|
+
* @param parent - The parent entry or document at this level
|
|
38
|
+
*/
|
|
39
|
+
const traverse = (entries, parent) => {
|
|
40
|
+
if (!entries) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.type === 'tag') {
|
|
45
|
+
// Record this tag entry, then keep walking its children — tags can be nested
|
|
46
|
+
addToMap(entry.name, { ...entry, parent });
|
|
47
|
+
traverse(entry.children, { ...entry, parent });
|
|
48
|
+
}
|
|
49
|
+
else if ('children' in entry && entry.children) {
|
|
50
|
+
// Non-tag containers (models, documents) may still hold tags inside them
|
|
51
|
+
traverse(entry.children, { ...entry, parent });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
traverse(document.children, document);
|
|
56
|
+
return map;
|
|
26
57
|
};
|
|
27
|
-
export {
|
|
28
|
-
getTagEntries
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=get-tag-entries.js.map
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Gets or creates a tag in the tags dictionary.
|
|
3
|
+
* If the tag doesn't exist, it creates a new tag object with the given name.
|
|
4
|
+
*
|
|
5
|
+
* @param tagsDict - Map of tag names to tag objects
|
|
6
|
+
* @param name - Name of the tag to get or create
|
|
7
|
+
* @returns The tag object for the given name
|
|
8
|
+
*/
|
|
9
|
+
export const getTag = ({ tagsMap, name, documentId, generateId, }) => {
|
|
10
|
+
if (!tagsMap.get(name)) {
|
|
11
|
+
tagsMap.set(name, {
|
|
12
|
+
id: generateId({
|
|
13
|
+
type: 'tag',
|
|
14
|
+
tag: { name },
|
|
15
|
+
parentId: documentId,
|
|
16
|
+
}),
|
|
17
|
+
parentId: documentId,
|
|
18
|
+
entries: [],
|
|
19
|
+
tag: { name },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return tagsMap.get(name); // We can safely assert non-null since we just set the value if it didn't exist
|
|
20
23
|
};
|
|
21
|
-
export {
|
|
22
|
-
getTag
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=get-tag.js.map
|