@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,63 +1,101 @@
|
|
|
1
|
-
import { isObject } from
|
|
2
|
-
const isDetectChangesProxy = Symbol(
|
|
3
|
-
const detectChangesProxyTarget = Symbol(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { isObject } from '@scalar/helpers/object/is-object';
|
|
2
|
+
const isDetectChangesProxy = Symbol('isDetectChangesProxy');
|
|
3
|
+
const detectChangesProxyTarget = Symbol('detectChangesProxyTarget');
|
|
4
|
+
/**
|
|
5
|
+
* createDetectChangesProxy - Creates a proxy for an object or array that detects and triggers hooks on changes.
|
|
6
|
+
*
|
|
7
|
+
* This proxy enables detection of set operations, triggering optional hooks (onBeforeChange, onAfterChange) with the path and value changed.
|
|
8
|
+
* The proxy can be applied recursively to all nested objects/arrays, and caches proxies to prevent creating multiple proxies for the same object.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* const obj = { foo: 1, bar: { baz: 2 } };
|
|
13
|
+
* const proxy = createDetectChangesProxy(obj, {
|
|
14
|
+
* hooks: {
|
|
15
|
+
* onBeforeChange: (path, value) => console.log('Before', path, value),
|
|
16
|
+
* onAfterChange: (path, value) => console.log('After', path, value),
|
|
17
|
+
* }
|
|
18
|
+
* });
|
|
19
|
+
* proxy.foo = 42; // Console: Before ['foo'] '42', After ['foo'] '42'
|
|
20
|
+
* proxy.bar.baz = 99; // Console: Before ['bar', 'baz'] '99', After ['bar', 'baz'] '99'
|
|
21
|
+
*
|
|
22
|
+
* @param target The target object or array to wrap in a proxy
|
|
23
|
+
* @param options Optional: hooks for change detection
|
|
24
|
+
* @param args Internal: proxy cache and current property path (used for recursion)
|
|
25
|
+
* @returns The proxied object/array with change detection capabilities
|
|
26
|
+
*/
|
|
27
|
+
export const createDetectChangesProxy = (target, options, args = {
|
|
28
|
+
proxyCache: new WeakMap(),
|
|
29
|
+
path: [],
|
|
7
30
|
}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (args.proxyCache.has(target)) {
|
|
12
|
-
return args.proxyCache.get(target);
|
|
13
|
-
}
|
|
14
|
-
const proxy = new Proxy(target, {
|
|
15
|
-
get(target2, prop, receiver) {
|
|
16
|
-
if (prop === isDetectChangesProxy) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
if (prop === detectChangesProxyTarget) {
|
|
20
|
-
return target2;
|
|
21
|
-
}
|
|
22
|
-
const value = Reflect.get(target2, prop, receiver);
|
|
23
|
-
if (isDetectChangesProxyObject(value)) {
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
return createDetectChangesProxy(value, options, { ...args, path: [...args.path, String(prop)] });
|
|
27
|
-
},
|
|
28
|
-
set(target2, prop, value, receiver) {
|
|
29
|
-
const path = [...args.path, String(prop)];
|
|
30
|
-
options?.hooks?.onBeforeChange?.(path, value);
|
|
31
|
-
const result = Reflect.set(target2, prop, value, receiver);
|
|
32
|
-
options?.hooks?.onAfterChange?.(path, value);
|
|
33
|
-
return result;
|
|
34
|
-
},
|
|
35
|
-
deleteProperty(target2, prop) {
|
|
36
|
-
const path = [...args.path, String(prop)];
|
|
37
|
-
options?.hooks?.onBeforeChange?.(path);
|
|
38
|
-
const result = Reflect.deleteProperty(target2, prop);
|
|
39
|
-
options?.hooks?.onAfterChange?.(path);
|
|
40
|
-
return result;
|
|
31
|
+
// Only wrap objects or arrays
|
|
32
|
+
if (!isObject(target) && !Array.isArray(target)) {
|
|
33
|
+
return target;
|
|
41
34
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
// Return cached proxy if already created for this target
|
|
36
|
+
if (args.proxyCache.has(target)) {
|
|
37
|
+
return args.proxyCache.get(target);
|
|
38
|
+
}
|
|
39
|
+
const proxy = new Proxy(target, {
|
|
40
|
+
get(target, prop, receiver) {
|
|
41
|
+
// Allow identifying if an object is a detect changes proxy
|
|
42
|
+
if (prop === isDetectChangesProxy) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
// Allow access to the original target
|
|
46
|
+
if (prop === detectChangesProxyTarget) {
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
// Recursively wrap property values in the detect changes proxy
|
|
50
|
+
const value = Reflect.get(target, prop, receiver);
|
|
51
|
+
if (isDetectChangesProxyObject(value)) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
return createDetectChangesProxy(value, options, { ...args, path: [...args.path, String(prop)] });
|
|
55
|
+
},
|
|
56
|
+
set(target, prop, value, receiver) {
|
|
57
|
+
const path = [...args.path, String(prop)];
|
|
58
|
+
// Call before-change hook if provided
|
|
59
|
+
options?.hooks?.onBeforeChange?.(path, value);
|
|
60
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
61
|
+
// Call after-change hook if provided
|
|
62
|
+
options?.hooks?.onAfterChange?.(path, value);
|
|
63
|
+
return result;
|
|
64
|
+
},
|
|
65
|
+
deleteProperty(target, prop) {
|
|
66
|
+
const path = [...args.path, String(prop)];
|
|
67
|
+
options?.hooks?.onBeforeChange?.(path);
|
|
68
|
+
const result = Reflect.deleteProperty(target, prop);
|
|
69
|
+
options?.hooks?.onAfterChange?.(path);
|
|
70
|
+
return result;
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
// Cache the proxy for this target
|
|
74
|
+
args.proxyCache.set(target, proxy);
|
|
75
|
+
return proxy;
|
|
45
76
|
};
|
|
46
|
-
const isDetectChangesProxyObject = (obj) => {
|
|
47
|
-
|
|
77
|
+
export const isDetectChangesProxyObject = (obj) => {
|
|
78
|
+
return (typeof obj === 'object' &&
|
|
79
|
+
obj !== null &&
|
|
80
|
+
obj[isDetectChangesProxy] === true);
|
|
48
81
|
};
|
|
49
|
-
|
|
50
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Returns the raw/original (non-proxy) object if the passed object is a detect-changes proxy.
|
|
84
|
+
* If the object is not a proxy, it returns the same object.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const proxy = createDetectChangesProxy({ a: 1 });
|
|
88
|
+
* const raw = unpackDetectChangesProxy(proxy); // Gets the original object { a: 1 }
|
|
89
|
+
* const notProxy = { b: 2 };
|
|
90
|
+
* const stillRaw = unpackDetectChangesProxy(notProxy); // Returns { b: 2 }, unchanged
|
|
91
|
+
*/
|
|
92
|
+
export const unpackDetectChangesProxy = (obj) => {
|
|
93
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
// If object is a detect-changes proxy, return its underlying target
|
|
97
|
+
if (obj[isDetectChangesProxy]) {
|
|
98
|
+
return obj[detectChangesProxyTarget];
|
|
99
|
+
}
|
|
51
100
|
return obj;
|
|
52
|
-
}
|
|
53
|
-
if (obj[isDetectChangesProxy]) {
|
|
54
|
-
return obj[detectChangesProxyTarget];
|
|
55
|
-
}
|
|
56
|
-
return obj;
|
|
57
|
-
};
|
|
58
|
-
export {
|
|
59
|
-
createDetectChangesProxy,
|
|
60
|
-
isDetectChangesProxyObject,
|
|
61
|
-
unpackDetectChangesProxy
|
|
62
101
|
};
|
|
63
|
-
//# sourceMappingURL=detect-changes-proxy.js.map
|
package/dist/helpers/general.js
CHANGED
|
@@ -1,28 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a string is a local reference (starts with #)
|
|
3
|
+
* @param value - The reference string to check
|
|
4
|
+
* @returns true if the string is a local reference, false otherwise
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* isLocalRef('#/components/schemas/User') // true
|
|
8
|
+
* isLocalRef('https://example.com/schema.json') // false
|
|
9
|
+
* isLocalRef('./local-schema.json') // false
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function isLocalRef(value) {
|
|
13
|
+
return value.startsWith('#');
|
|
3
14
|
}
|
|
4
|
-
function keyOf(value) {
|
|
5
|
-
|
|
15
|
+
export function keyOf(value) {
|
|
16
|
+
return Object.keys(value);
|
|
6
17
|
}
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Deep clones a value using JSON serialization.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to deep clone
|
|
22
|
+
* @template T - The type of the value
|
|
23
|
+
* @returns A deep clone of the value
|
|
24
|
+
*/
|
|
25
|
+
export const deepClone = (value) => {
|
|
26
|
+
return JSON.parse(JSON.stringify(value));
|
|
9
27
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Splits an array into two arrays based on a condition.
|
|
30
|
+
*
|
|
31
|
+
* This function takes an array and a predicate function, then returns a tuple containing
|
|
32
|
+
* two arrays: the first contains elements that pass the condition, and the second contains
|
|
33
|
+
* elements that fail the condition.
|
|
34
|
+
*
|
|
35
|
+
* @param array - The array to split
|
|
36
|
+
* @param condition - A predicate function that determines which array each element belongs to
|
|
37
|
+
* @returns A tuple of two arrays: [passingElements, failingElements]
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const numbers = [1, 2, 3, 4, 5, 6]
|
|
42
|
+
* const [evens, odds] = split(numbers, (n) => n % 2 === 0)
|
|
43
|
+
* // evens: [2, 4, 6]
|
|
44
|
+
* // odds: [1, 3, 5]
|
|
45
|
+
*
|
|
46
|
+
* const words = ['apple', 'banana', 'cherry', 'date']
|
|
47
|
+
* const [longWords, shortWords] = split(words, (word) => word.length > 5)
|
|
48
|
+
* // longWords: ['banana', 'cherry']
|
|
49
|
+
* // shortWords: ['apple', 'date']
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const split = (array, condition) => {
|
|
53
|
+
return array.reduce(([pass, fail], item) => {
|
|
54
|
+
return condition(item) ? [[...pass, item], fail] : [pass, [...fail, item]];
|
|
55
|
+
}, [[], []]);
|
|
17
56
|
};
|
|
18
|
-
|
|
19
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Safely assigns properties from a source object to a target object.
|
|
59
|
+
*
|
|
60
|
+
* This function uses Object.assign to copy enumerable properties from the source object
|
|
61
|
+
* to the target object. It's a type-safe wrapper around Object.assign that ensures
|
|
62
|
+
* the source object is compatible with the target object's type.
|
|
63
|
+
*
|
|
64
|
+
* @param target - The target object to assign properties to
|
|
65
|
+
* @param source - The source object containing properties to assign
|
|
66
|
+
* @template T - The type of the target object
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const target = { name: 'John', age: 30 }
|
|
71
|
+
* const source = { age: 31, city: 'New York' }
|
|
72
|
+
* safeAssign(target, source)
|
|
73
|
+
* // target is now: { name: 'John', age: 31, city: 'New York' }
|
|
74
|
+
*
|
|
75
|
+
* const config = { theme: 'dark', language: 'en' }
|
|
76
|
+
* const updates = { theme: 'light' }
|
|
77
|
+
* safeAssign(config, updates)
|
|
78
|
+
* // config is now: { theme: 'light', language: 'en' }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export const safeAssign = (target, source) => {
|
|
82
|
+
Object.assign(target, source);
|
|
20
83
|
};
|
|
21
|
-
export {
|
|
22
|
-
deepClone,
|
|
23
|
-
isLocalRef,
|
|
24
|
-
keyOf,
|
|
25
|
-
safeAssign,
|
|
26
|
-
split
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=general.js.map
|
|
@@ -1,47 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique value based on a given default value and a validation function.
|
|
3
|
+
*
|
|
4
|
+
* The process works as follows:
|
|
5
|
+
* 1. Optionally transform (e.g., slugify) the default value using a transformation function.
|
|
6
|
+
* 2. Check if this value is unique by executing the provided validation function.
|
|
7
|
+
* 3. If not unique, repeatedly append an incrementing integer (e.g., "my-name 1", "my-name 2", ...) and re-check uniqueness,
|
|
8
|
+
* up to a maximum number of attempts (maxRetries).
|
|
9
|
+
* 4. Returns the first unique value found or undefined if a unique value cannot be generated within the maximum retries.
|
|
10
|
+
*
|
|
11
|
+
* Example:
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Existing names in use
|
|
14
|
+
* const existing = new Set(['foo', 'foo 1', 'foo 2']);
|
|
15
|
+
* const uniqueName = generateUniqueValue({
|
|
16
|
+
* defaultValue: 'foo',
|
|
17
|
+
* validation: (value) => !existing.has(value),
|
|
18
|
+
* // transformation is optional, e.g. (val) => val.toLowerCase().replace(/[^\w]+/g, '-'),
|
|
19
|
+
* maxRetries: 10,
|
|
20
|
+
* });
|
|
21
|
+
* // uniqueName === 'foo 3'
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export async function generateUniqueValue({ defaultValue,
|
|
25
|
+
/** Check function to verify the uniqueness of the value */
|
|
26
|
+
validation,
|
|
27
|
+
/** Transformation function to transform the default value (such as into a slug) */
|
|
28
|
+
transformation,
|
|
29
|
+
/** The maximum number of attempts to create a unique value by incrementing. */
|
|
30
|
+
maxRetries = 5, }) {
|
|
31
|
+
const transformed = transformation?.(defaultValue) ?? defaultValue;
|
|
32
|
+
if (await validation(transformed)) {
|
|
33
|
+
return transformed;
|
|
34
|
+
}
|
|
35
|
+
return incrementValue({
|
|
36
|
+
value: [transformed, 1],
|
|
37
|
+
validation,
|
|
38
|
+
maxRetries,
|
|
39
|
+
transformation,
|
|
40
|
+
});
|
|
20
41
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Attempts to generate a unique value by appending and incrementing a counter to a base string.
|
|
44
|
+
*
|
|
45
|
+
* On each attempt, appends the next incrementing integer (e.g. "foo 1", "foo 2", etc.) to the original value,
|
|
46
|
+
* and checks with the validation function whether the candidate value is unique.
|
|
47
|
+
*
|
|
48
|
+
* Continues until a unique value is found, or the maximum number of attempts is reached.
|
|
49
|
+
*
|
|
50
|
+
* Returns the first unique value found, or undefined if a unique value cannot be generated within maxRetries.
|
|
51
|
+
*
|
|
52
|
+
* Example:
|
|
53
|
+
* ```ts
|
|
54
|
+
* const existing = new Set(['bar', 'bar 1']);
|
|
55
|
+
* const result = incrementValue({
|
|
56
|
+
* value: ['bar', 1],
|
|
57
|
+
* validation: (val) => !existing.has(val),
|
|
58
|
+
* maxRetries: 5,
|
|
59
|
+
* });
|
|
60
|
+
* // result === "bar 2"
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
async function incrementValue({ value, validation, maxRetries, attempts = 0, transformation, }) {
|
|
64
|
+
if (attempts >= maxRetries) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const incremented = value.join(' ');
|
|
68
|
+
const transformed = transformation?.(incremented) ?? incremented;
|
|
69
|
+
if (await validation(transformed)) {
|
|
70
|
+
return transformed;
|
|
71
|
+
}
|
|
72
|
+
return incrementValue({
|
|
73
|
+
value: [value[0], value[1] + 1],
|
|
74
|
+
validation,
|
|
75
|
+
maxRetries,
|
|
76
|
+
transformation,
|
|
77
|
+
attempts: attempts + 1,
|
|
78
|
+
});
|
|
43
79
|
}
|
|
44
|
-
export {
|
|
45
|
-
generateUniqueValue
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=generate-unique-value.js.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { redirectToProxy } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { redirectToProxy } from '@scalar/helpers/url/redirect-to-proxy';
|
|
2
|
+
/**
|
|
3
|
+
* Get the fetch function from the configuration
|
|
4
|
+
*
|
|
5
|
+
* @param config - The API reference configuration.
|
|
6
|
+
* @returns The fetch function.
|
|
7
|
+
*/
|
|
8
|
+
export const getFetch = (config) => {
|
|
9
|
+
if (config.fetch) {
|
|
10
|
+
return config.fetch;
|
|
11
|
+
}
|
|
12
|
+
return ((input, init) => fetch(redirectToProxy(config.proxyUrl, input.toString()), init));
|
|
7
13
|
};
|
|
8
|
-
export {
|
|
9
|
-
getFetch
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=get-fetch.js.map
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
const defaultTransform = (node) => {
|
|
2
|
-
|
|
2
|
+
return node['$ref-value'];
|
|
3
3
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a node that may be a $ref object to its actual value.
|
|
6
|
+
* If the node contains a $ref, applies the provided transform (default: returns '$ref-value').
|
|
7
|
+
* Otherwise, returns the node as-is.
|
|
8
|
+
*/
|
|
9
|
+
export const getResolvedRef = (node, transform = defaultTransform) => {
|
|
10
|
+
if (typeof node === 'object' && node !== null && '$ref' in node) {
|
|
11
|
+
return transform(node);
|
|
12
|
+
}
|
|
13
|
+
return node;
|
|
9
14
|
};
|
|
10
|
-
export {
|
|
11
|
-
getResolvedRef
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=get-resolved-ref.js.map
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** Type guard to determine if a security requirement is non-optional */
|
|
2
|
+
export const isNonOptionalSecurityRequirement = (securityRequirement) => {
|
|
3
|
+
return securityRequirement !== undefined && Object.keys(securityRequirement).length > 0;
|
|
3
4
|
};
|
|
4
|
-
export {
|
|
5
|
-
isNonOptionalSecurityRequirement
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=is-non-optional-security-requirement.js.map
|
|
@@ -1,34 +1,75 @@
|
|
|
1
|
-
import { getRaw } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { getRaw } from '@scalar/json-magic/magic-proxy';
|
|
2
|
+
/**
|
|
3
|
+
* Deep merges two objects, combining their properties recursively.
|
|
4
|
+
* Handles circular references by tracking visited objects to prevent infinite recursion.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ Note: This operation assumes there are no key collisions between the objects.
|
|
7
|
+
* Use isKeyCollisions() to check for collisions before merging.
|
|
8
|
+
*
|
|
9
|
+
* @param a - Target object to merge into
|
|
10
|
+
* @param b - Source object to merge from
|
|
11
|
+
* @param cache - Set of visited objects to prevent circular reference issues
|
|
12
|
+
* @returns The merged object (mutates and returns a)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Simple merge
|
|
16
|
+
* const a = { name: 'John' }
|
|
17
|
+
* const b = { age: 30 }
|
|
18
|
+
* mergeObjects(a, b) // { name: 'John', age: 30 }
|
|
19
|
+
*
|
|
20
|
+
* // Nested merge
|
|
21
|
+
* const a = { user: { name: 'John' } }
|
|
22
|
+
* const b = { user: { age: 30 } }
|
|
23
|
+
* mergeObjects(a, b) // { user: { name: 'John', age: 30 } }
|
|
24
|
+
*
|
|
25
|
+
* // Circular reference safe
|
|
26
|
+
* const obj = { name: 'John' }
|
|
27
|
+
* obj.self = obj
|
|
28
|
+
* const target = { age: 30 }
|
|
29
|
+
* mergeObjects(target, obj) // Safely merges without infinite recursion
|
|
30
|
+
*/
|
|
31
|
+
export const mergeObjects = (a, b,
|
|
32
|
+
/**
|
|
33
|
+
* By default we overwrite array indexes, our store is built on this assumption when coercing the document
|
|
34
|
+
* Alternatively we may want to prevent this behaviour when merging with defaults and replace the whole array instead
|
|
35
|
+
*/
|
|
36
|
+
replaceArrays = false, cache = new Set()) => {
|
|
37
|
+
for (const key in b) {
|
|
38
|
+
if (!(key in a)) {
|
|
39
|
+
a[key] = b[key];
|
|
15
40
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
else {
|
|
42
|
+
const aValue = a[key];
|
|
43
|
+
const bValue = b[key];
|
|
44
|
+
/** Replace whole array instead of replacing each index */
|
|
45
|
+
const shouldReplaceArrays = replaceArrays && (Array.isArray(aValue) || Array.isArray(bValue));
|
|
46
|
+
if (typeof aValue === 'object' &&
|
|
47
|
+
aValue !== null &&
|
|
48
|
+
typeof bValue === 'object' &&
|
|
49
|
+
bValue !== null &&
|
|
50
|
+
!shouldReplaceArrays) {
|
|
51
|
+
const rawA = getRaw(aValue);
|
|
52
|
+
const rawB = getRaw(bValue);
|
|
53
|
+
// Check for circular references before recursive merge
|
|
54
|
+
if (cache.has(rawA) || cache.has(rawB)) {
|
|
55
|
+
// Skip merging this branch to prevent infinite recursion
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// Add objects to cache before recursive call
|
|
59
|
+
cache.add(rawA);
|
|
60
|
+
cache.add(rawB);
|
|
61
|
+
mergeObjects(aValue, bValue, replaceArrays, cache);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
try {
|
|
65
|
+
a[key] = bValue; // Overwrite with b's value if not an object
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.warn(`Issue setting ${key} on object`);
|
|
69
|
+
console.warn(error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
25
72
|
}
|
|
26
|
-
}
|
|
27
73
|
}
|
|
28
|
-
|
|
29
|
-
return a;
|
|
74
|
+
return a;
|
|
30
75
|
};
|
|
31
|
-
export {
|
|
32
|
-
mergeObjects
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=merge-object.js.map
|