@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,99 +1,105 @@
|
|
|
1
|
-
import { Type } from
|
|
1
|
+
import { Type } from '@scalar/typebox';
|
|
2
2
|
const HeaderSchema = Type.Object({
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
name: Type.String(),
|
|
4
|
+
value: Type.String(),
|
|
5
5
|
});
|
|
6
|
+
/**
|
|
7
|
+
* This object contains detailed info about performed request.
|
|
8
|
+
*/
|
|
6
9
|
const RequestSchema = Type.Object({
|
|
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
|
-
)
|
|
10
|
+
/** Absolute URL of the request (fragments are not included). */
|
|
11
|
+
url: Type.String(),
|
|
12
|
+
/** Request method (`GET`, `POST`, ...). */
|
|
13
|
+
method: Type.String(),
|
|
14
|
+
/** Request HTTP Version. */
|
|
15
|
+
httpVersion: Type.String(),
|
|
16
|
+
/** List of header objects. */
|
|
17
|
+
headers: Type.Array(HeaderSchema),
|
|
18
|
+
/** List of cookie objects. */
|
|
19
|
+
cookies: Type.Array(HeaderSchema),
|
|
20
|
+
/**
|
|
21
|
+
* Total number of bytes from the start of the HTTP request message until
|
|
22
|
+
* (and including) the double CRLF before the body.
|
|
23
|
+
*
|
|
24
|
+
* Set to `-1` if the info is not available.
|
|
25
|
+
*/
|
|
26
|
+
headersSize: Type.Number(),
|
|
27
|
+
/** List of query string objects. */
|
|
28
|
+
queryString: Type.Array(HeaderSchema),
|
|
29
|
+
/**
|
|
30
|
+
* Size of the request body (POST data payload) in bytes.
|
|
31
|
+
*
|
|
32
|
+
* Set to `-1` if the info is not available.
|
|
33
|
+
*/
|
|
34
|
+
bodySize: Type.Number(),
|
|
35
|
+
/** Posted data info. */
|
|
36
|
+
postData: Type.Optional(Type.Union([
|
|
37
|
+
Type.Object({
|
|
38
|
+
/** Mime type of posted data. */
|
|
39
|
+
mimeType: Type.String(),
|
|
40
|
+
text: Type.String(),
|
|
41
|
+
}),
|
|
42
|
+
Type.Object({
|
|
43
|
+
/** Mime type of posted data. */
|
|
44
|
+
mimeType: Type.String(),
|
|
45
|
+
params: Type.Array(Type.Object({ name: Type.String(), value: Type.Optional(Type.String()) })),
|
|
46
|
+
}),
|
|
47
|
+
])),
|
|
47
48
|
});
|
|
48
49
|
const ResponseSchema = Type.Object({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
status: Type.Number(),
|
|
51
|
+
statusText: Type.String(),
|
|
52
|
+
headers: Type.Array(HeaderSchema),
|
|
53
|
+
cookies: Type.Array(HeaderSchema),
|
|
54
|
+
httpVersion: Type.String(),
|
|
55
|
+
redirectURL: Type.String(),
|
|
56
|
+
headersSize: Type.Number(),
|
|
57
|
+
bodySize: Type.Number(),
|
|
58
|
+
content: Type.Object({
|
|
59
|
+
size: Type.Number(),
|
|
60
|
+
mimeType: Type.String(),
|
|
61
|
+
encoding: Type.Optional(Type.String()),
|
|
62
|
+
text: Type.Optional(Type.String()),
|
|
63
|
+
}),
|
|
63
64
|
});
|
|
64
65
|
const HistoryEntrySchema = Type.Object({
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
* This is the sum of all timings available in the timings object
|
|
69
|
-
* (i.e. not including `-1` values).
|
|
70
|
-
*/
|
|
71
|
-
time: Type.Number(),
|
|
72
|
-
/** Timestamp of the request. */
|
|
73
|
-
timestamp: Type.Number(),
|
|
74
|
-
/** Detailed info about the request. */
|
|
75
|
-
request: RequestSchema,
|
|
76
|
-
/** Detailed info about the response. */
|
|
77
|
-
response: ResponseSchema,
|
|
78
|
-
/** Meta data about the request. */
|
|
79
|
-
meta: Type.Object({
|
|
80
|
-
/** The example key for the request. */
|
|
81
|
-
example: Type.String()
|
|
82
|
-
}),
|
|
83
|
-
requestMetadata: Type.Object({
|
|
84
|
-
/** Variables used in the request.
|
|
66
|
+
/**
|
|
67
|
+
* Total elapsed time of the request in milliseconds.
|
|
85
68
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* We don't need to do any server + variables matching and replacement.
|
|
69
|
+
* This is the sum of all timings available in the timings object
|
|
70
|
+
* (i.e. not including `-1` values).
|
|
89
71
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
time: Type.Number(),
|
|
73
|
+
/** Timestamp of the request. */
|
|
74
|
+
timestamp: Type.Number(),
|
|
75
|
+
/** Detailed info about the request. */
|
|
76
|
+
request: RequestSchema,
|
|
77
|
+
/** Detailed info about the response. */
|
|
78
|
+
response: ResponseSchema,
|
|
79
|
+
/** Meta data about the request. */
|
|
80
|
+
meta: Type.Object({
|
|
81
|
+
/** The example key for the request. */
|
|
82
|
+
example: Type.String(),
|
|
83
|
+
}),
|
|
84
|
+
requestMetadata: Type.Object({
|
|
85
|
+
/** Variables used in the request.
|
|
86
|
+
*
|
|
87
|
+
* Since HAR format does not support variables, we need to store them here.
|
|
88
|
+
* This way we can easily re-use the request with the same variables.
|
|
89
|
+
* We don't need to do any server + variables matching and replacement.
|
|
90
|
+
*/
|
|
91
|
+
variables: Type.Record(Type.String(), Type.String()),
|
|
92
|
+
// Other meta fields (e.g., server) can be added here in the future.
|
|
93
|
+
}),
|
|
93
94
|
});
|
|
95
|
+
/**
|
|
96
|
+
* Schema for the path method history.
|
|
97
|
+
*
|
|
98
|
+
* {
|
|
99
|
+
* "path": {
|
|
100
|
+
* "method": [Entry]
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
103
|
+
*/
|
|
94
104
|
const PathMethodHistorySchema = Type.Record(Type.String(), Type.Record(Type.String(), Type.Array(HistoryEntrySchema)));
|
|
95
|
-
const DocumentHistorySchema = Type.Record(Type.String(), PathMethodHistorySchema);
|
|
96
|
-
export {
|
|
97
|
-
DocumentHistorySchema
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=schema.js.map
|
|
105
|
+
export const DocumentHistorySchema = Type.Record(Type.String(), PathMethodHistorySchema);
|
package/dist/events/bus.js
CHANGED
|
@@ -1,96 +1,149 @@
|
|
|
1
|
-
import { debounce } from
|
|
2
|
-
import { unpackProxyObject } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { debounce } from '@scalar/helpers/general/debounce';
|
|
2
|
+
import { unpackProxyObject } from '../helpers/unpack-proxy.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a type-safe event bus for workspace events
|
|
5
|
+
*
|
|
6
|
+
* This implementation uses a Map for O(1) lookups and maintains
|
|
7
|
+
* a separate Set for each event type to efficiently manage listeners.
|
|
8
|
+
*
|
|
9
|
+
* Create this once per application instance.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration options
|
|
12
|
+
* @returns A fully type-safe event bus instance
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const bus = createWorkspaceEventBus()
|
|
16
|
+
*
|
|
17
|
+
* // Subscribe to events
|
|
18
|
+
* const unsubscribe = bus.on('scalar-update-sidebar', (detail) => {
|
|
19
|
+
* console.log('Sidebar:', detail.value)
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // Emit events
|
|
23
|
+
* bus.emit('scalar-update-sidebar', { value: true })
|
|
24
|
+
*
|
|
25
|
+
* // Clean up
|
|
26
|
+
* unsubscribe()
|
|
27
|
+
*/
|
|
28
|
+
export const createWorkspaceEventBus = (options = {}) => {
|
|
29
|
+
const { debug = false } = options;
|
|
30
|
+
const events = new Map();
|
|
31
|
+
const pendingLogs = [];
|
|
32
|
+
let logTimeout = null;
|
|
33
|
+
/**
|
|
34
|
+
* Single debounce instance for all debounced emits
|
|
35
|
+
* Uses keys to separate different event + debounceKey combinations
|
|
36
|
+
*/
|
|
37
|
+
const { execute: debouncedEmitter } = debounce({ delay: 328 });
|
|
38
|
+
/**
|
|
39
|
+
* Get or create a listener set for an event
|
|
40
|
+
*/
|
|
41
|
+
const getListeners = (event) => {
|
|
42
|
+
const listeners = events.get(event) ?? new Set();
|
|
43
|
+
events.set(event, listeners);
|
|
44
|
+
return listeners;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Flush batched logs using console.groupCollapsed
|
|
48
|
+
*/
|
|
49
|
+
const flushLogs = () => {
|
|
50
|
+
if (pendingLogs.length === 0) {
|
|
51
|
+
return;
|
|
23
52
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
if (debug) {
|
|
54
|
+
if (pendingLogs.length === 1) {
|
|
55
|
+
// Only one log, output it normally without grouping
|
|
56
|
+
const firstLog = pendingLogs[0];
|
|
57
|
+
if (firstLog) {
|
|
58
|
+
console.log(`[EventBus] ${firstLog.message}`, ...firstLog.args);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Multiple logs, use a collapsed group
|
|
63
|
+
console.groupCollapsed(`[EventBus] ${pendingLogs.length} operations`);
|
|
64
|
+
for (const { message, args } of pendingLogs) {
|
|
65
|
+
console.log(message, ...args);
|
|
66
|
+
}
|
|
67
|
+
console.groupEnd();
|
|
68
|
+
}
|
|
28
69
|
}
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
70
|
+
pendingLogs.length = 0;
|
|
71
|
+
logTimeout = null;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Log debug information if debug mode is enabled
|
|
75
|
+
* Batches multiple logs together using console.groupCollapsed
|
|
76
|
+
*/
|
|
77
|
+
const log = (message, ...args) => {
|
|
78
|
+
if (debug) {
|
|
79
|
+
pendingLogs.push({ message, args });
|
|
80
|
+
// Clear existing timeout and set a new one to batch logs
|
|
81
|
+
if (logTimeout) {
|
|
82
|
+
clearTimeout(logTimeout);
|
|
83
|
+
}
|
|
84
|
+
logTimeout = setTimeout(flushLogs, 500);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const on = (event, listener) => {
|
|
88
|
+
const listeners = getListeners(event);
|
|
89
|
+
listeners.add(listener);
|
|
90
|
+
log(`Added listener for "${String(event)}" (${listeners.size} total)`);
|
|
91
|
+
return () => off(event, listener);
|
|
92
|
+
};
|
|
93
|
+
const off = (event, listener) => {
|
|
94
|
+
const listeners = events.get(event);
|
|
95
|
+
if (!listeners) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
listeners.delete(listener);
|
|
99
|
+
log(`Removed listener for "${String(event)}" (${listeners.size} remaining)`);
|
|
100
|
+
// Clean up empty listener sets to avoid memory leaks
|
|
101
|
+
if (listeners.size === 0) {
|
|
102
|
+
events.delete(event);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Internal function that performs the actual emission logic
|
|
107
|
+
* This is extracted so it can be wrapped with debouncing
|
|
108
|
+
*/
|
|
109
|
+
const performEmit = (event, payload, options) => {
|
|
110
|
+
// We unpack the payload here to ensure that, within mutators, we are not assigning proxies directly,
|
|
111
|
+
// but are always assigning plain objects 5 level depth.
|
|
112
|
+
const unpackedPayload = options?.skipUnpackProxy ? payload : unpackProxyObject(payload, { depth: 5 });
|
|
113
|
+
const listeners = events.get(event);
|
|
114
|
+
if (!listeners || listeners.size === 0) {
|
|
115
|
+
log(`🛑 No listeners for "${String(event)}"`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
log(`Emitting "${String(event)}" to ${listeners.size} listener(s)`, payload);
|
|
119
|
+
// Convert to array to avoid issues if listeners modify the set during iteration
|
|
120
|
+
const listenersArray = Array.from(listeners);
|
|
121
|
+
// Execute all listeners
|
|
122
|
+
for (const listener of listenersArray) {
|
|
123
|
+
try {
|
|
124
|
+
listener(unpackedPayload);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
// Do not let one listener error break other listeners
|
|
128
|
+
console.error(`[EventBus] Error in listener for "${String(event)}":`, error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const emit = (...args) => {
|
|
133
|
+
const [event, payload, options] = args;
|
|
134
|
+
// If no debounce key is provided, emit immediately
|
|
135
|
+
if (!options?.debounceKey) {
|
|
136
|
+
performEmit(event, payload, options);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Create a unique key for this event + debounce key combination
|
|
140
|
+
const debounceMapKey = `${event}-${options.debounceKey}`;
|
|
141
|
+
// Pass the closure directly - debounce will store the latest version
|
|
142
|
+
debouncedEmitter(debounceMapKey, () => performEmit(event, payload, options));
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
on,
|
|
146
|
+
off,
|
|
147
|
+
emit,
|
|
148
|
+
};
|
|
95
149
|
};
|
|
96
|
-
//# sourceMappingURL=bus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/dist/events/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
createWorkspaceEventBus,
|
|
6
|
-
emitCustomEvent,
|
|
7
|
-
onCustomEvent
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { createWorkspaceEventBus } from './bus.js';
|
|
2
|
+
export { onCustomEvent } from './listeners.js';
|
|
3
|
+
export { emitCustomEvent } from './old-definitions.js';
|
package/dist/events/listeners.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import { onBeforeUnmount, watch } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { onBeforeUnmount, watch } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Vue wrapper for attaching and removing event listeners
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Use the the event bus instead
|
|
6
|
+
*/
|
|
7
|
+
export function onCustomEvent(el, event, handler) {
|
|
8
|
+
// Any time the element reference changes, we need to add the event listener
|
|
9
|
+
watch(() => el.value, (element) => {
|
|
10
|
+
if (!element) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
element.addEventListener(event, handler);
|
|
14
|
+
}, { immediate: true });
|
|
15
|
+
onBeforeUnmount(() => {
|
|
16
|
+
if (!el.value) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
el.value.removeEventListener(event, handler);
|
|
20
|
+
});
|
|
19
21
|
}
|
|
20
|
-
export {
|
|
21
|
-
onCustomEvent
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=listeners.js.map
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Scalar blocks will use vanilla events to allow more flexibility in integrations
|
|
3
|
+
*
|
|
4
|
+
* Event can include typed payloads using the `data` property. A target for the dispatch must be provided.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Use the the event bus instead
|
|
7
|
+
*/
|
|
8
|
+
export function emitCustomEvent(target, event, detail) {
|
|
9
|
+
const instance = new CustomEvent(event, {
|
|
10
|
+
detail: detail,
|
|
11
|
+
bubbles: true,
|
|
12
|
+
composed: true,
|
|
13
|
+
cancelable: true,
|
|
14
|
+
});
|
|
15
|
+
target?.dispatchEvent(instance);
|
|
9
16
|
}
|
|
10
|
-
export {
|
|
11
|
-
emitCustomEvent
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=old-definitions.js.map
|
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Deeply clones an object or array, handling circular references.
|
|
3
|
+
*
|
|
4
|
+
* This function recursively copies all properties of the input value,
|
|
5
|
+
* creating a new object or array. If the input contains circular references,
|
|
6
|
+
* they are preserved in the clone using a WeakMap to track already-cloned objects.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to deep clone (object, array, or primitive)
|
|
9
|
+
* @param hash - (internal) WeakMap for tracking circular references
|
|
10
|
+
* @returns A deep clone of the input value
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const obj: any = { a: 1 }
|
|
14
|
+
* obj.self = obj
|
|
15
|
+
* const clone = deepClone(obj)
|
|
16
|
+
* console.log(clone) // { a: 1, self: [Circular] }
|
|
17
|
+
* console.log(clone !== obj) // true
|
|
18
|
+
* console.log(clone.self === clone) // true
|
|
19
|
+
*/
|
|
20
|
+
export const deepClone = (value, hash = new WeakMap()) => {
|
|
21
|
+
if (typeof value !== 'object' || value === null) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (hash.has(value)) {
|
|
25
|
+
return hash.get(value);
|
|
26
|
+
}
|
|
27
|
+
const result = Array.isArray(value) ? [] : {};
|
|
28
|
+
hash.set(value, result);
|
|
29
|
+
Object.keys(value).forEach((key) => {
|
|
30
|
+
// @ts-expect-error: Index signature for generic object
|
|
31
|
+
result[key] = deepClone(value[key], hash);
|
|
32
|
+
});
|
|
33
|
+
return result;
|
|
14
34
|
};
|
|
15
|
-
export {
|
|
16
|
-
deepClone
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=deep-clone.js.map
|