@snap/camera-kit 0.7.0
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/LICENSE.md +6247 -0
- package/README.md +166 -0
- package/docs/html/.nojekyll +1 -0
- package/docs/html/assets/highlight.css +106 -0
- package/docs/html/assets/main.js +54 -0
- package/docs/html/assets/search.js +1 -0
- package/docs/html/assets/style.css +1225 -0
- package/docs/html/assets/widgets.png +0 -0
- package/docs/html/assets/widgets@2x.png +0 -0
- package/docs/html/classes/CameraKit.html +121 -0
- package/docs/html/classes/CameraKitSession.html +347 -0
- package/docs/html/classes/CameraKitSource.html +152 -0
- package/docs/html/classes/LensPerformanceMeasurement.html +115 -0
- package/docs/html/classes/LensPerformanceMetrics.html +76 -0
- package/docs/html/classes/LensRepository.html +171 -0
- package/docs/html/classes/LensSources.html +82 -0
- package/docs/html/classes/Transform2D.html +99 -0
- package/docs/html/classes/TypedCustomEvent.html +109 -0
- package/docs/html/classes/TypedEventTarget.html +146 -0
- package/docs/html/functions/Injectable.html +193 -0
- package/docs/html/functions/bootstrapCameraKit.html +158 -0
- package/docs/html/functions/createExtension.html +127 -0
- package/docs/html/functions/createImageSource.html +123 -0
- package/docs/html/functions/createMediaStreamSource.html +123 -0
- package/docs/html/functions/createUserMediaSource.html +127 -0
- package/docs/html/functions/createVideoSource.html +124 -0
- package/docs/html/functions/estimateLensPerformance.html +116 -0
- package/docs/html/functions/getRequiredBootstrapURLs.html +124 -0
- package/docs/html/functions/lensSourcesFactory.html +116 -0
- package/docs/html/functions/uriHandlersFactory.html +118 -0
- package/docs/html/index.html +208 -0
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +132 -0
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +121 -0
- package/docs/html/interfaces/ComputedFrameMetrics.html +70 -0
- package/docs/html/interfaces/CreateSessionOptions.html +77 -0
- package/docs/html/interfaces/EstimatedLensPerformance.html +78 -0
- package/docs/html/interfaces/Lens.html +115 -0
- package/docs/html/interfaces/LensSource.html +113 -0
- package/docs/html/interfaces/MediaStreamSourceOptions.html +65 -0
- package/docs/html/interfaces/UriCancelRequest.html +65 -0
- package/docs/html/interfaces/UriHandler.html +128 -0
- package/docs/html/interfaces/UriRequest.html +80 -0
- package/docs/html/interfaces/UriResponse.html +80 -0
- package/docs/html/interfaces/VideoSourceOptions.html +60 -0
- package/docs/html/modules.html +198 -0
- package/docs/html/types/AssetLoader.html +126 -0
- package/docs/html/types/AssetTiming.html +116 -0
- package/docs/html/types/BenchmarkError.html +107 -0
- package/docs/html/types/BootstrapError.html +110 -0
- package/docs/html/types/CacheKeyNotFoundError.html +107 -0
- package/docs/html/types/CameraKitDeviceInfo.html +114 -0
- package/docs/html/types/CameraKitSessionEventListener.html +109 -0
- package/docs/html/types/CameraKitSessionEvents.html +118 -0
- package/docs/html/types/CameraKitSourceError.html +107 -0
- package/docs/html/types/CameraKitSourceInfo.html +107 -0
- package/docs/html/types/CameraKitSourceOptions.html +113 -0
- package/docs/html/types/ConfigurationError.html +109 -0
- package/docs/html/types/Keyboard.html +196 -0
- package/docs/html/types/KeyboardEvents.html +109 -0
- package/docs/html/types/LegalError.html +107 -0
- package/docs/html/types/LensAssetError.html +109 -0
- package/docs/html/types/LensContentValidationError.html +107 -0
- package/docs/html/types/LensError.html +107 -0
- package/docs/html/types/LensExecutionError.html +114 -0
- package/docs/html/types/LensImagePickerError.html +110 -0
- package/docs/html/types/LensLaunchParams.html +109 -0
- package/docs/html/types/LensMetricsEvents.html +110 -0
- package/docs/html/types/LensPerformanceCluster.html +107 -0
- package/docs/html/types/LensView.html +119 -0
- package/docs/html/types/LensWait.html +111 -0
- package/docs/html/types/PersistentStoreError.html +109 -0
- package/docs/html/types/PlatformNotSupportedError.html +110 -0
- package/docs/html/types/PublicContainer.html +110 -0
- package/docs/html/types/RenderTarget.html +111 -0
- package/docs/html/types/Uri.html +107 -0
- package/docs/html/types/UriHandlers.html +109 -0
- package/docs/html/types/WebGLError.html +107 -0
- package/docs/html/variables/extensionRequestContext.html +109 -0
- package/docs/md/.nojekyll +1 -0
- package/docs/md/README.md +168 -0
- package/docs/md/classes/CameraKit.md +94 -0
- package/docs/md/classes/CameraKitSession.md +359 -0
- package/docs/md/classes/CameraKitSource.md +110 -0
- package/docs/md/classes/LensPerformanceMeasurement.md +77 -0
- package/docs/md/classes/LensPerformanceMetrics.md +37 -0
- package/docs/md/classes/LensRepository.md +145 -0
- package/docs/md/classes/LensSources.md +29 -0
- package/docs/md/classes/Transform2D.md +55 -0
- package/docs/md/classes/TypedCustomEvent.md +65 -0
- package/docs/md/classes/TypedEventTarget.md +103 -0
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +106 -0
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +55 -0
- package/docs/md/interfaces/ComputedFrameMetrics.md +29 -0
- package/docs/md/interfaces/CreateSessionOptions.md +35 -0
- package/docs/md/interfaces/EstimatedLensPerformance.md +38 -0
- package/docs/md/interfaces/Lens.md +84 -0
- package/docs/md/interfaces/LensSource.md +68 -0
- package/docs/md/interfaces/MediaStreamSourceOptions.md +22 -0
- package/docs/md/interfaces/UriCancelRequest.md +22 -0
- package/docs/md/interfaces/UriHandler.md +63 -0
- package/docs/md/interfaces/UriRequest.md +43 -0
- package/docs/md/interfaces/UriResponse.md +43 -0
- package/docs/md/interfaces/VideoSourceOptions.md +15 -0
- package/docs/md/modules.md +827 -0
- package/lib/CameraKit.d.ts +170 -0
- package/lib/CameraKit.js +145 -0
- package/lib/CameraKit.js.map +1 -0
- package/lib/__tests__/data.d.ts +9 -0
- package/lib/__tests__/data.js +50 -0
- package/lib/__tests__/data.js.map +1 -0
- package/lib/__tests__/deferred.d.ts +16 -0
- package/lib/__tests__/deferred.js +29 -0
- package/lib/__tests__/deferred.js.map +1 -0
- package/lib/__tests__/jest.matchers.d.ts +17 -0
- package/lib/__tests__/jest.matchers.js +67 -0
- package/lib/__tests__/jest.matchers.js.map +1 -0
- package/lib/assertPlatformSupported.d.ts +4 -0
- package/lib/assertPlatformSupported.js +10 -0
- package/lib/assertPlatformSupported.js.map +1 -0
- package/lib/benchmark/benchmarkGflops.d.ts +16 -0
- package/lib/benchmark/benchmarkGflops.js +129 -0
- package/lib/benchmark/benchmarkGflops.js.map +1 -0
- package/lib/benchmark/estimateLensPerformanceCluster.d.ts +33 -0
- package/lib/benchmark/estimateLensPerformanceCluster.js +48 -0
- package/lib/benchmark/estimateLensPerformanceCluster.js.map +1 -0
- package/lib/benchmark/webglUtils.d.ts +7 -0
- package/lib/benchmark/webglUtils.js +87 -0
- package/lib/benchmark/webglUtils.js.map +1 -0
- package/lib/bootstrapCameraKit.d.ts +96 -0
- package/lib/bootstrapCameraKit.js +204 -0
- package/lib/bootstrapCameraKit.js.map +1 -0
- package/lib/common/__mocks__/loadScript.d.ts +1 -0
- package/lib/common/__mocks__/loadScript.js +10 -0
- package/lib/common/__mocks__/loadScript.js.map +1 -0
- package/lib/common/assertions.d.ts +27 -0
- package/lib/common/assertions.js +39 -0
- package/lib/common/assertions.js.map +1 -0
- package/lib/common/cameraKitUserAgent.d.ts +34 -0
- package/lib/common/cameraKitUserAgent.js +216 -0
- package/lib/common/cameraKitUserAgent.js.map +1 -0
- package/lib/common/copyDefinedProperties.d.ts +13 -0
- package/lib/common/copyDefinedProperties.js +16 -0
- package/lib/common/copyDefinedProperties.js.map +1 -0
- package/lib/common/entries.d.ts +3 -0
- package/lib/common/entries.js +3 -0
- package/lib/common/entries.js.map +1 -0
- package/lib/common/errorHelpers.d.ts +10 -0
- package/lib/common/errorHelpers.js +24 -0
- package/lib/common/errorHelpers.js.map +1 -0
- package/lib/common/getFilename.d.ts +1 -0
- package/lib/common/getFilename.js +4 -0
- package/lib/common/getFilename.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +3 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/loadScript.d.ts +1 -0
- package/lib/common/loadScript.js +11 -0
- package/lib/common/loadScript.js.map +1 -0
- package/lib/common/locale.d.ts +2 -0
- package/lib/common/locale.js +11 -0
- package/lib/common/locale.js.map +1 -0
- package/lib/common/localization.d.ts +43 -0
- package/lib/common/localization.js +43 -0
- package/lib/common/localization.js.map +1 -0
- package/lib/common/memoize.d.ts +8 -0
- package/lib/common/memoize.js +15 -0
- package/lib/common/memoize.js.map +1 -0
- package/lib/common/pageVisibility.d.ts +20 -0
- package/lib/common/pageVisibility.js +62 -0
- package/lib/common/pageVisibility.js.map +1 -0
- package/lib/common/time.d.ts +1 -0
- package/lib/common/time.js +2 -0
- package/lib/common/time.js.map +1 -0
- package/lib/common/typeguards.d.ts +53 -0
- package/lib/common/typeguards.js +92 -0
- package/lib/common/typeguards.js.map +1 -0
- package/lib/common/types.d.ts +10 -0
- package/lib/common/types.js +2 -0
- package/lib/common/types.js.map +1 -0
- package/lib/common/validate.d.ts +14 -0
- package/lib/common/validate.js +104 -0
- package/lib/common/validate.js.map +1 -0
- package/lib/configuration.d.ts +92 -0
- package/lib/configuration.js +36 -0
- package/lib/configuration.js.map +1 -0
- package/lib/configurationOverrides.d.ts +12 -0
- package/lib/configurationOverrides.js +41 -0
- package/lib/configurationOverrides.js.map +1 -0
- package/lib/dependency-injection/Container.d.ts +177 -0
- package/lib/dependency-injection/Container.js +160 -0
- package/lib/dependency-injection/Container.js.map +1 -0
- package/lib/dependency-injection/Injectable.d.ts +39 -0
- package/lib/dependency-injection/Injectable.js +18 -0
- package/lib/dependency-injection/Injectable.js.map +1 -0
- package/lib/dependency-injection/PartialContainer.d.ts +81 -0
- package/lib/dependency-injection/PartialContainer.js +85 -0
- package/lib/dependency-injection/PartialContainer.js.map +1 -0
- package/lib/dependency-injection/RootServices.d.ts +62 -0
- package/lib/dependency-injection/RootServices.js +2 -0
- package/lib/dependency-injection/RootServices.js.map +1 -0
- package/lib/dependency-injection/types.d.ts +56 -0
- package/lib/dependency-injection/types.js +2 -0
- package/lib/dependency-injection/types.js.map +1 -0
- package/lib/environment.json +1 -0
- package/lib/events/TypedCustomEvent.d.ts +10 -0
- package/lib/events/TypedCustomEvent.js +11 -0
- package/lib/events/TypedCustomEvent.js.map +1 -0
- package/lib/events/TypedEventTarget.d.ts +25 -0
- package/lib/events/TypedEventTarget.js +57 -0
- package/lib/events/TypedEventTarget.js.map +1 -0
- package/lib/events/scan.d.ts +15 -0
- package/lib/events/scan.js +46 -0
- package/lib/events/scan.js.map +1 -0
- package/lib/extensions/LensSources.d.ts +58 -0
- package/lib/extensions/LensSources.js +50 -0
- package/lib/extensions/LensSources.js.map +1 -0
- package/lib/extensions/UriHandlers.d.ts +54 -0
- package/lib/extensions/UriHandlers.js +93 -0
- package/lib/extensions/UriHandlers.js.map +1 -0
- package/lib/extensions/extensionRequestContext.d.ts +4 -0
- package/lib/extensions/extensionRequestContext.js +14 -0
- package/lib/extensions/extensionRequestContext.js.map +1 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +5603 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js +522 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +98 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +260 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +543 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +429 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +100 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +164 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +395 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +644 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +185 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +172 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +86 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +234 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +854 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +629 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +86 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +185 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +95 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +104 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +10212 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +1300 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +401 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +525 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +1287 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +135 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4208 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +1053 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +102 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +165 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +8 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +17 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -0
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +75 -0
- package/lib/generated-proto/pb_schema/common/ruid.js +96 -0
- package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -0
- package/lib/generated-proto/pb_schema/common/value.d.ts +131 -0
- package/lib/generated-proto/pb_schema/common/value.js +204 -0
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.d.ts +1 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.js +9 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/api/http.d.ts +3636 -0
- package/lib/generated-proto/pb_schema/google/api/http.js +271 -0
- package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +139 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.js +94 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +50968 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +2962 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +98 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +82 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +173 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +332 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +42 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.js +52 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +32 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.js +50 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +29 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.js +43 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +365 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js +216 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/lures.d.ts +113 -0
- package/lib/generated-proto/pb_schema/lenses/lures.js +64 -0
- package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +29 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js +43 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +921 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.js +954 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +247 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.js +362 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -0
- package/lib/handlers/HandlerChainBuilder.d.ts +95 -0
- package/lib/handlers/HandlerChainBuilder.js +187 -0
- package/lib/handlers/HandlerChainBuilder.js.map +1 -0
- package/lib/handlers/arrayBufferParsingHandler.d.ts +10 -0
- package/lib/handlers/arrayBufferParsingHandler.js +18 -0
- package/lib/handlers/arrayBufferParsingHandler.js.map +1 -0
- package/lib/handlers/batchingHandler.d.ts +25 -0
- package/lib/handlers/batchingHandler.js +79 -0
- package/lib/handlers/batchingHandler.js.map +1 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +12 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +19 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -0
- package/lib/handlers/debugHandler.d.ts +8 -0
- package/lib/handlers/debugHandler.js +27 -0
- package/lib/handlers/debugHandler.js.map +1 -0
- package/lib/handlers/defaultFetchHandler.d.ts +15 -0
- package/lib/handlers/defaultFetchHandler.js +29 -0
- package/lib/handlers/defaultFetchHandler.js.map +1 -0
- package/lib/handlers/headersModifyingFetchHandler.d.ts +8 -0
- package/lib/handlers/headersModifyingFetchHandler.js +13 -0
- package/lib/handlers/headersModifyingFetchHandler.js.map +1 -0
- package/lib/handlers/index.d.ts +2 -0
- package/lib/handlers/index.js +3 -0
- package/lib/handlers/index.js.map +1 -0
- package/lib/handlers/mappingHandler.d.ts +15 -0
- package/lib/handlers/mappingHandler.js +65 -0
- package/lib/handlers/mappingHandler.js.map +1 -0
- package/lib/handlers/noCorsRetryingFetchHandler.d.ts +48 -0
- package/lib/handlers/noCorsRetryingFetchHandler.js +94 -0
- package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -0
- package/lib/handlers/persistingHandler.d.ts +14 -0
- package/lib/handlers/persistingHandler.js +71 -0
- package/lib/handlers/persistingHandler.js.map +1 -0
- package/lib/handlers/rateLimitingHandler.d.ts +20 -0
- package/lib/handlers/rateLimitingHandler.js +43 -0
- package/lib/handlers/rateLimitingHandler.js.map +1 -0
- package/lib/handlers/requestStateEmittingHandler.d.ts +29 -0
- package/lib/handlers/requestStateEmittingHandler.js +43 -0
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -0
- package/lib/handlers/responseCachingHandler.d.ts +27 -0
- package/lib/handlers/responseCachingHandler.js +94 -0
- package/lib/handlers/responseCachingHandler.js.map +1 -0
- package/lib/handlers/retryingHandler.d.ts +37 -0
- package/lib/handlers/retryingHandler.js +73 -0
- package/lib/handlers/retryingHandler.js.map +1 -0
- package/lib/handlers/timeoutHandler.d.ts +18 -0
- package/lib/handlers/timeoutHandler.js +30 -0
- package/lib/handlers/timeoutHandler.js.map +1 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.js +32 -0
- package/lib/index.js.map +1 -0
- package/lib/legal/legalPrompt.d.ts +17 -0
- package/lib/legal/legalPrompt.js +144 -0
- package/lib/legal/legalPrompt.js.map +1 -0
- package/lib/legal/legalState.d.ts +50 -0
- package/lib/legal/legalState.js +149 -0
- package/lib/legal/legalState.js.map +1 -0
- package/lib/lens/Lens.d.ts +71 -0
- package/lib/lens/Lens.js +63 -0
- package/lib/lens/Lens.js.map +1 -0
- package/lib/lens/LensLaunchParams.d.ts +19 -0
- package/lib/lens/LensLaunchParams.js +38 -0
- package/lib/lens/LensLaunchParams.js.map +1 -0
- package/lib/lens/LensPersistenceStore.d.ts +7 -0
- package/lib/lens/LensPersistenceStore.js +20 -0
- package/lib/lens/LensPersistenceStore.js.map +1 -0
- package/lib/lens/LensRepository.d.ts +134 -0
- package/lib/lens/LensRepository.js +239 -0
- package/lib/lens/LensRepository.js.map +1 -0
- package/lib/lens/assets/LensAssetRepository.d.ts +66 -0
- package/lib/lens/assets/LensAssetRepository.js +179 -0
- package/lib/lens/assets/LensAssetRepository.js.map +1 -0
- package/lib/lens/assets/LensAssetsProvider.d.ts +21 -0
- package/lib/lens/assets/LensAssetsProvider.js +41 -0
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -0
- package/lib/lens/assets/deviceDependentAssetLoader.d.ts +11 -0
- package/lib/lens/assets/deviceDependentAssetLoader.js +58 -0
- package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +10 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +26 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -0
- package/lib/lens/assets/staticAssetLoader.d.ts +10 -0
- package/lib/lens/assets/staticAssetLoader.js +24 -0
- package/lib/lens/assets/staticAssetLoader.js.map +1 -0
- package/lib/lens/index.d.ts +7 -0
- package/lib/lens/index.js +7 -0
- package/lib/lens/index.js.map +1 -0
- package/lib/lens/lensEnvelopeUtil.d.ts +5 -0
- package/lib/lens/lensEnvelopeUtil.js +19 -0
- package/lib/lens/lensEnvelopeUtil.js.map +1 -0
- package/lib/lens/lensHttpUtil.d.ts +4 -0
- package/lib/lens/lensHttpUtil.js +30 -0
- package/lib/lens/lensHttpUtil.js.map +1 -0
- package/lib/lens-client-interface/exif.d.ts +20 -0
- package/lib/lens-client-interface/exif.js +61 -0
- package/lib/lens-client-interface/exif.js.map +1 -0
- package/lib/lens-client-interface/imagePicker.d.ts +7 -0
- package/lib/lens-client-interface/imagePicker.js +128 -0
- package/lib/lens-client-interface/imagePicker.js.map +1 -0
- package/lib/lens-client-interface/lensClientInterface.d.ts +13 -0
- package/lib/lens-client-interface/lensClientInterface.js +30 -0
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -0
- package/lib/lens-core-module/generated-types.d.ts +426 -0
- package/lib/lens-core-module/generated-types.js +2 -0
- package/lib/lens-core-module/generated-types.js.map +1 -0
- package/lib/lens-core-module/index.d.ts +2 -0
- package/lib/lens-core-module/index.js +3 -0
- package/lib/lens-core-module/index.js.map +1 -0
- package/lib/lens-core-module/loader/index.d.ts +1 -0
- package/lib/lens-core-module/loader/index.js +2 -0
- package/lib/lens-core-module/loader/index.js.map +1 -0
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +30 -0
- package/lib/lens-core-module/loader/lensCoreFactory.js +121 -0
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -0
- package/lib/lensCoreWasmVersions.json +5 -0
- package/lib/logger/errorLoggingDecorator.d.ts +9 -0
- package/lib/logger/errorLoggingDecorator.js +32 -0
- package/lib/logger/errorLoggingDecorator.js.map +1 -0
- package/lib/logger/logEntries.d.ts +15 -0
- package/lib/logger/logEntries.js +14 -0
- package/lib/logger/logEntries.js.map +1 -0
- package/lib/logger/logger.d.ts +35 -0
- package/lib/logger/logger.js +48 -0
- package/lib/logger/logger.js.map +1 -0
- package/lib/logger/registerLogEntriesSubscriber.d.ts +14 -0
- package/lib/logger/registerLogEntriesSubscriber.js +23 -0
- package/lib/logger/registerLogEntriesSubscriber.js.map +1 -0
- package/lib/media-sources/CameraKitSource.d.ts +88 -0
- package/lib/media-sources/CameraKitSource.js +140 -0
- package/lib/media-sources/CameraKitSource.js.map +1 -0
- package/lib/media-sources/FunctionSource.d.ts +30 -0
- package/lib/media-sources/FunctionSource.js +132 -0
- package/lib/media-sources/FunctionSource.js.map +1 -0
- package/lib/media-sources/ImageSource.d.ts +13 -0
- package/lib/media-sources/ImageSource.js +28 -0
- package/lib/media-sources/ImageSource.js.map +1 -0
- package/lib/media-sources/MediaStreamSource.d.ts +41 -0
- package/lib/media-sources/MediaStreamSource.js +146 -0
- package/lib/media-sources/MediaStreamSource.js.map +1 -0
- package/lib/media-sources/VideoSource.d.ts +21 -0
- package/lib/media-sources/VideoSource.js +38 -0
- package/lib/media-sources/VideoSource.js.map +1 -0
- package/lib/metrics/businessEventsReporter.d.ts +37 -0
- package/lib/metrics/businessEventsReporter.js +160 -0
- package/lib/metrics/businessEventsReporter.js.map +1 -0
- package/lib/metrics/metricsEventTarget.d.ts +41 -0
- package/lib/metrics/metricsEventTarget.js +11 -0
- package/lib/metrics/metricsEventTarget.js.map +1 -0
- package/lib/metrics/metricsHandler.d.ts +9 -0
- package/lib/metrics/metricsHandler.js +13 -0
- package/lib/metrics/metricsHandler.js.map +1 -0
- package/lib/metrics/operationalMetricsReporter.d.ts +52 -0
- package/lib/metrics/operationalMetricsReporter.js +108 -0
- package/lib/metrics/operationalMetricsReporter.js.map +1 -0
- package/lib/metrics/reporters/reportBenchmarks.d.ts +10 -0
- package/lib/metrics/reporters/reportBenchmarks.js +29 -0
- package/lib/metrics/reporters/reportBenchmarks.js.map +1 -0
- package/lib/metrics/reporters/reportGlobalException.d.ts +19 -0
- package/lib/metrics/reporters/reportGlobalException.js +68 -0
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -0
- package/lib/metrics/reporters/reportHttpMetrics.d.ts +17 -0
- package/lib/metrics/reporters/reportHttpMetrics.js +92 -0
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -0
- package/lib/metrics/reporters/reportLegalState.d.ts +15 -0
- package/lib/metrics/reporters/reportLegalState.js +34 -0
- package/lib/metrics/reporters/reportLegalState.js.map +1 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +38 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.js +88 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -0
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +20 -0
- package/lib/metrics/reporters/reportLensValidationFailed.js +24 -0
- package/lib/metrics/reporters/reportLensValidationFailed.js.map +1 -0
- package/lib/metrics/reporters/reportLensView.d.ts +36 -0
- package/lib/metrics/reporters/reportLensView.js +101 -0
- package/lib/metrics/reporters/reportLensView.js.map +1 -0
- package/lib/metrics/reporters/reportLensWait.d.ts +33 -0
- package/lib/metrics/reporters/reportLensWait.js +56 -0
- package/lib/metrics/reporters/reportLensWait.js.map +1 -0
- package/lib/metrics/reporters/reportSessionException.d.ts +17 -0
- package/lib/metrics/reporters/reportSessionException.js +12 -0
- package/lib/metrics/reporters/reportSessionException.js.map +1 -0
- package/lib/metrics/reporters/reportUserSession.d.ts +14 -0
- package/lib/metrics/reporters/reportUserSession.js +67 -0
- package/lib/metrics/reporters/reportUserSession.js.map +1 -0
- package/lib/metrics/reporters/reporters.d.ts +44 -0
- package/lib/metrics/reporters/reporters.js +33 -0
- package/lib/metrics/reporters/reporters.js.map +1 -0
- package/lib/namedErrors.d.ts +107 -0
- package/lib/namedErrors.js +56 -0
- package/lib/namedErrors.js.map +1 -0
- package/lib/persistence/ExpiringPersistence.d.ts +20 -0
- package/lib/persistence/ExpiringPersistence.js +58 -0
- package/lib/persistence/ExpiringPersistence.js.map +1 -0
- package/lib/persistence/IndexedDBPersistence.d.ts +47 -0
- package/lib/persistence/IndexedDBPersistence.js +180 -0
- package/lib/persistence/IndexedDBPersistence.js.map +1 -0
- package/lib/persistence/Persistence.d.ts +25 -0
- package/lib/persistence/Persistence.js +10 -0
- package/lib/persistence/Persistence.js.map +1 -0
- package/lib/remote-configuration/cofHandler.d.ts +21 -0
- package/lib/remote-configuration/cofHandler.js +75 -0
- package/lib/remote-configuration/cofHandler.js.map +1 -0
- package/lib/remote-configuration/remoteConfiguration.d.ts +13 -0
- package/lib/remote-configuration/remoteConfiguration.js +43 -0
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -0
- package/lib/session/CameraKitSession.d.ts +252 -0
- package/lib/session/CameraKitSession.js +439 -0
- package/lib/session/CameraKitSession.js.map +1 -0
- package/lib/session/CameraKitSessionEvents.d.ts +33 -0
- package/lib/session/CameraKitSessionEvents.js +21 -0
- package/lib/session/CameraKitSessionEvents.js.map +1 -0
- package/lib/session/LensKeyboard.d.ts +89 -0
- package/lib/session/LensKeyboard.js +95 -0
- package/lib/session/LensKeyboard.js.map +1 -0
- package/lib/session/LensPerformanceMeasurement.d.ts +55 -0
- package/lib/session/LensPerformanceMeasurement.js +91 -0
- package/lib/session/LensPerformanceMeasurement.js.map +1 -0
- package/lib/session/LensPerformanceMetrics.d.ts +31 -0
- package/lib/session/LensPerformanceMetrics.js +58 -0
- package/lib/session/LensPerformanceMetrics.js.map +1 -0
- package/lib/session/index.d.ts +1 -0
- package/lib/session/index.js +2 -0
- package/lib/session/index.js.map +1 -0
- package/lib/session/lensState.d.ts +29 -0
- package/lib/session/lensState.js +160 -0
- package/lib/session/lensState.js.map +1 -0
- package/lib/session/sessionState.d.ts +10 -0
- package/lib/session/sessionState.js +12 -0
- package/lib/session/sessionState.js.map +1 -0
- package/lib/transforms/Transform2D.d.ts +17 -0
- package/lib/transforms/Transform2D.js +18 -0
- package/lib/transforms/Transform2D.js.map +1 -0
- package/lib/transforms/index.d.ts +1 -0
- package/lib/transforms/index.js +2 -0
- package/lib/transforms/index.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This implementation is limited by how TypeScript currently implements tag function for template literals.
|
|
3
|
+
*
|
|
4
|
+
* The way tag functions are typed by the TypeScript compiler limits their usefulness, for two reasons:
|
|
5
|
+
*
|
|
6
|
+
* 1. Specific literal types are not inferred from interpolation expressions -- the following does not work:
|
|
7
|
+
* ```ts
|
|
8
|
+
* function tag<K extends readonly string[]>(strings: readonly string[], ...keys: K): string { ... }
|
|
9
|
+
* tag`This is a ${"test"} template.` // the K type parameter is not correctly inferred as `readonly ['test']`
|
|
10
|
+
* ```
|
|
11
|
+
* 2. The return type of a function used as a tag function will always be `string` -- the following does not work:
|
|
12
|
+
* ```ts
|
|
13
|
+
* function tag<K extends readonly string[]>(
|
|
14
|
+
* strings: readonly string[],
|
|
15
|
+
* ...keys: K
|
|
16
|
+
* ): (values: {[k in K[number]]: string}) => string { ... }
|
|
17
|
+
*
|
|
18
|
+
* const template = tag`This is a ${"test"} template` // TS infers the type of `template` as `string` -- clearly wrong.
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* An attempt is made here to work around those limitations and still provide a reasonably amount of type safety without
|
|
22
|
+
* adding too much verbosity.
|
|
23
|
+
*
|
|
24
|
+
* See https://github.com/microsoft/TypeScript/pull/49552
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* We use the en_US string object to define all localizable stringIds and their types (either a TemplateFunction or a
|
|
28
|
+
* plain string).
|
|
29
|
+
*/
|
|
30
|
+
declare type LocalizableStrings = typeof en_US;
|
|
31
|
+
declare type TemplateFunction<K extends readonly string[]> = (values: {
|
|
32
|
+
[key in K[number]]: string;
|
|
33
|
+
}) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Strings for each language are defined blow.
|
|
36
|
+
*/
|
|
37
|
+
declare const en_US: {
|
|
38
|
+
legalPromptMessage: TemplateFunction<readonly ["privacyPolicyUrl", "termsOfServiceUrl", "learnMoreUrl"]>;
|
|
39
|
+
legalPromptAccept: string;
|
|
40
|
+
legalPromptReject: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function localizedString<ID extends keyof LocalizableStrings>(stringId: ID): LocalizableStrings[ID];
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { cameraKitUserAgent } from "./cameraKitUserAgent";
|
|
3
|
+
function makeTemplate(keys) {
|
|
4
|
+
return (template) => (values) => {
|
|
5
|
+
const tag = (readonlyStrings) => {
|
|
6
|
+
const strings = readonlyStrings.slice();
|
|
7
|
+
return [strings.shift()]
|
|
8
|
+
.concat(keys.map((key) => { var _a; return `${(_a = values[key]) !== null && _a !== void 0 ? _a : ""}${strings.shift()}`; }))
|
|
9
|
+
.concat(strings)
|
|
10
|
+
.join("");
|
|
11
|
+
};
|
|
12
|
+
return template(tag);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Any strings which are templated (i.e. require runtime values) are defined below.
|
|
17
|
+
*/
|
|
18
|
+
const legalPromptMessage = makeTemplate(["privacyPolicyUrl", "termsOfServiceUrl", "learnMoreUrl"]);
|
|
19
|
+
/**
|
|
20
|
+
* Strings for each language are defined blow.
|
|
21
|
+
*/
|
|
22
|
+
// en_US is used both to:
|
|
23
|
+
// A) define the set of strings which can be localized and
|
|
24
|
+
// B) provide a default set of strings in case a specific localization cannot be found.
|
|
25
|
+
const en_US = {
|
|
26
|
+
legalPromptMessage: legalPromptMessage((tag) => tag `By using Lenses, you acknowledge reading Snap's <a href="${0}" target="_blank">
|
|
27
|
+
Privacy Policy</a> and agree to Snap's <a href="${0}" target="_blank">Terms of Service</a>.
|
|
28
|
+
Some Lenses use information about your face, hands, and voice to work. <a href="${0}"
|
|
29
|
+
target="_blank">Learn More</a>, and if you want to agree and continue, click or tap below.`),
|
|
30
|
+
legalPromptAccept: "I Agree",
|
|
31
|
+
legalPromptReject: "Dismiss",
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* --- end of string definitions ---
|
|
35
|
+
*/
|
|
36
|
+
const allStrings = {
|
|
37
|
+
en_US,
|
|
38
|
+
};
|
|
39
|
+
const localizedStrings = (_a = allStrings[cameraKitUserAgent.locale]) !== null && _a !== void 0 ? _a : en_US;
|
|
40
|
+
export function localizedString(stringId) {
|
|
41
|
+
return localizedStrings[stringId];
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../../src/common/localization.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAoC1D,SAAS,YAAY,CACjB,IAAO;IAEP,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,MAAsC,EAAE,EAAE;QAC5D,MAAM,GAAG,GAAG,CAAC,eAAkC,EAAE,EAAE;YAC/C,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC;YACxC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;iBACnB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAC,OAAA,GAAG,MAAA,MAAM,CAAC,GAAG,CAAC,mCAAI,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,EAAE,CAAA,EAAA,CAAC,CAAC;iBACnE,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC,CAAC;QACF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,kBAAkB,GAAG,YAAY,CAAC,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,cAAc,CAAU,CAAC,CAAC;AAE5G;;GAEG;AAEH,yBAAyB;AACzB,2DAA2D;AAC3D,wFAAwF;AACxF,MAAM,KAAK,GAAG;IACV,kBAAkB,EAAE,kBAAkB,CAClC,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAA,4DAA4D,CAAC;8DACd,CAAC;8FAC+B,CAAC;uGACQ,CAClG;IACD,iBAAiB,EAAE,SAAS;IAC5B,iBAAiB,EAAE,SAAS;CAC/B,CAAC;AAEF;;GAEG;AAEH,MAAM,UAAU,GAA0C;IACtD,KAAK;CACR,CAAC;AAEF,MAAM,gBAAgB,GAAG,MAAA,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,mCAAI,KAAK,CAAC;AAExE,MAAM,UAAU,eAAe,CAAsC,QAAY;IAC7E,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { cameraKitUserAgent } from \"./cameraKitUserAgent\";\n\n/**\n * This implementation is limited by how TypeScript currently implements tag function for template literals.\n *\n * The way tag functions are typed by the TypeScript compiler limits their usefulness, for two reasons:\n *\n * 1. Specific literal types are not inferred from interpolation expressions -- the following does not work:\n * ```ts\n * function tag<K extends readonly string[]>(strings: readonly string[], ...keys: K): string { ... }\n * tag`This is a ${\"test\"} template.` // the K type parameter is not correctly inferred as `readonly ['test']`\n * ```\n * 2. The return type of a function used as a tag function will always be `string` -- the following does not work:\n * ```ts\n * function tag<K extends readonly string[]>(\n * strings: readonly string[],\n * ...keys: K\n * ): (values: {[k in K[number]]: string}) => string { ... }\n *\n * const template = tag`This is a ${\"test\"} template` // TS infers the type of `template` as `string` -- clearly wrong.\n * ```\n *\n * An attempt is made here to work around those limitations and still provide a reasonably amount of type safety without\n * adding too much verbosity.\n *\n * See https://github.com/microsoft/TypeScript/pull/49552\n */\n\n/**\n * We use the en_US string object to define all localizable stringIds and their types (either a TemplateFunction or a\n * plain string).\n */\ntype LocalizableStrings = typeof en_US;\n\ntype TemplateFunction<K extends readonly string[]> = (values: { [key in K[number]]: string }) => string;\n\nfunction makeTemplate<K extends readonly string[]>(\n keys: K\n): (template: (tag: (strings: readonly string[], ...keys: 0[]) => string) => string) => TemplateFunction<K> {\n return (template) => (values: { [key in K[number]]: string }) => {\n const tag = (readonlyStrings: readonly string[]) => {\n const strings = readonlyStrings.slice();\n return [strings.shift()]\n .concat(keys.map((key) => `${values[key] ?? \"\"}${strings.shift()}`))\n .concat(strings)\n .join(\"\");\n };\n return template(tag);\n };\n}\n\n/**\n * Any strings which are templated (i.e. require runtime values) are defined below.\n */\nconst legalPromptMessage = makeTemplate([\"privacyPolicyUrl\", \"termsOfServiceUrl\", \"learnMoreUrl\"] as const);\n\n/**\n * Strings for each language are defined blow.\n */\n\n// en_US is used both to:\n// A) define the set of strings which can be localized and\n// B) provide a default set of strings in case a specific localization cannot be found.\nconst en_US = {\n legalPromptMessage: legalPromptMessage(\n (tag) =>\n tag`By using Lenses, you acknowledge reading Snap's <a href=\"${0}\" target=\"_blank\">\n Privacy Policy</a> and agree to Snap's <a href=\"${0}\" target=\"_blank\">Terms of Service</a>.\n Some Lenses use information about your face, hands, and voice to work. <a href=\"${0}\"\n target=\"_blank\">Learn More</a>, and if you want to agree and continue, click or tap below.`\n ),\n legalPromptAccept: \"I Agree\",\n legalPromptReject: \"Dismiss\",\n};\n\n/**\n * --- end of string definitions ---\n */\n\nconst allStrings: { [key: string]: LocalizableStrings } = {\n en_US,\n};\n\nconst localizedStrings = allStrings[cameraKitUserAgent.locale] ?? en_US;\n\nexport function localizedString<ID extends keyof LocalizableStrings>(stringId: ID): LocalizableStrings[ID] {\n return localizedStrings[stringId];\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare type AnyFunction<A extends any[] = any[], B = any> = (...args: A) => B;
|
|
2
|
+
export declare type Memoized<Fn extends AnyFunction> = {
|
|
3
|
+
(...args: Parameters<Fn>): ReturnType<Fn>;
|
|
4
|
+
delegate: Fn;
|
|
5
|
+
};
|
|
6
|
+
export declare function isMemoized(fn: unknown): fn is Memoized<AnyFunction>;
|
|
7
|
+
export declare function memoize<Fn extends AnyFunction>(delegate: Fn): Memoized<Fn>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function isMemoized(fn) {
|
|
2
|
+
return typeof fn === "function" && typeof fn.delegate === "function";
|
|
3
|
+
}
|
|
4
|
+
export function memoize(delegate) {
|
|
5
|
+
let memo;
|
|
6
|
+
const memoized = (...args) => {
|
|
7
|
+
if (typeof memo !== "undefined")
|
|
8
|
+
return memo;
|
|
9
|
+
memo = delegate(...args);
|
|
10
|
+
return memo;
|
|
11
|
+
};
|
|
12
|
+
memoized.delegate = delegate;
|
|
13
|
+
return memoized;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=memoize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/common/memoize.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,UAAU,CAAC,EAAW;IAClC,OAAO,OAAO,EAAE,KAAK,UAAU,IAAI,OAAQ,EAAU,CAAC,QAAQ,KAAK,UAAU,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,OAAO,CAAyB,QAAY;IACxD,IAAI,IAAS,CAAC;IACd,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;QAChC,IAAI,OAAO,IAAI,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC7C,IAAI,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IACF,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,OAAO,QAAQ,CAAC;AACpB,CAAC","sourcesContent":["type AnyFunction<A extends any[] = any[], B = any> = (...args: A) => B;\n\nexport type Memoized<Fn extends AnyFunction> = {\n (...args: Parameters<Fn>): ReturnType<Fn>;\n delegate: Fn;\n};\n\nexport function isMemoized(fn: unknown): fn is Memoized<AnyFunction> {\n return typeof fn === \"function\" && typeof (fn as any).delegate === \"function\";\n}\n\nexport function memoize<Fn extends AnyFunction>(delegate: Fn): Memoized<Fn> {\n let memo: any;\n const memoized = (...args: any[]) => {\n if (typeof memo !== \"undefined\") return memo;\n memo = delegate(...args);\n return memo;\n };\n memoized.delegate = delegate;\n return memoized;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function isDuringVisibilityTransition(test: DocumentVisibilityState): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Run a function when the page is hidden. If this occurs due to tab / browser closure, only synchronous functions will
|
|
4
|
+
* run to completion.
|
|
5
|
+
*
|
|
6
|
+
* If the given handler throws an error, it will be silently swallowed.
|
|
7
|
+
*
|
|
8
|
+
* @param handler
|
|
9
|
+
* @returns A function which, when called, removes the function from the set of visibility change handlers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function onPageHidden(handler: () => void): () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Run a function when the page is made visible.
|
|
14
|
+
*
|
|
15
|
+
* If the given handler throws an error, it will be silently swallowed.
|
|
16
|
+
*
|
|
17
|
+
* @param handler
|
|
18
|
+
* @returns A function which, when called, removes the function from the set of visibility change handlers.
|
|
19
|
+
*/
|
|
20
|
+
export declare function onPageVisible(handler: () => void): () => void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const onHiddenHandlers = new Set();
|
|
2
|
+
const onVisibleHandlers = new Set();
|
|
3
|
+
let previousVisibilityState = document.visibilityState;
|
|
4
|
+
let visibilityTransition = false;
|
|
5
|
+
let initialized = false;
|
|
6
|
+
function maybeInitializeVisibilityListeners() {
|
|
7
|
+
if (initialized)
|
|
8
|
+
return;
|
|
9
|
+
initialized = true;
|
|
10
|
+
document.addEventListener("visibilitychange", () => {
|
|
11
|
+
const handlers = previousVisibilityState === "visible" && document.visibilityState === "hidden"
|
|
12
|
+
? onHiddenHandlers
|
|
13
|
+
: previousVisibilityState === "hidden" && document.visibilityState === "visible"
|
|
14
|
+
? onVisibleHandlers
|
|
15
|
+
: new Set();
|
|
16
|
+
visibilityTransition = document.visibilityState;
|
|
17
|
+
for (const handler of handlers) {
|
|
18
|
+
try {
|
|
19
|
+
handler();
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// We'll do the same thing here that we would do if the handler was added directly as an event
|
|
23
|
+
// listener and dispatch an error event if we can.
|
|
24
|
+
if (typeof window === "object")
|
|
25
|
+
window.dispatchEvent(new CustomEvent("error", { detail: error }));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
previousVisibilityState = visibilityTransition;
|
|
29
|
+
visibilityTransition = false;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function isDuringVisibilityTransition(test) {
|
|
33
|
+
return test === visibilityTransition;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Run a function when the page is hidden. If this occurs due to tab / browser closure, only synchronous functions will
|
|
37
|
+
* run to completion.
|
|
38
|
+
*
|
|
39
|
+
* If the given handler throws an error, it will be silently swallowed.
|
|
40
|
+
*
|
|
41
|
+
* @param handler
|
|
42
|
+
* @returns A function which, when called, removes the function from the set of visibility change handlers.
|
|
43
|
+
*/
|
|
44
|
+
export function onPageHidden(handler) {
|
|
45
|
+
maybeInitializeVisibilityListeners();
|
|
46
|
+
onHiddenHandlers.add(handler);
|
|
47
|
+
return () => onHiddenHandlers.delete(handler);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Run a function when the page is made visible.
|
|
51
|
+
*
|
|
52
|
+
* If the given handler throws an error, it will be silently swallowed.
|
|
53
|
+
*
|
|
54
|
+
* @param handler
|
|
55
|
+
* @returns A function which, when called, removes the function from the set of visibility change handlers.
|
|
56
|
+
*/
|
|
57
|
+
export function onPageVisible(handler) {
|
|
58
|
+
maybeInitializeVisibilityListeners();
|
|
59
|
+
onVisibleHandlers.add(handler);
|
|
60
|
+
return () => onVisibleHandlers.delete(handler);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=pageVisibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageVisibility.js","sourceRoot":"","sources":["../../src/common/pageVisibility.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;AAC/C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAc,CAAC;AAEhD,IAAI,uBAAuB,GAAG,QAAQ,CAAC,eAAe,CAAC;AACvD,IAAI,oBAAoB,GAAoC,KAAK,CAAC;AAElE,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,SAAS,kCAAkC;IACvC,IAAI,WAAW;QAAE,OAAO;IACxB,WAAW,GAAG,IAAI,CAAC;IAEnB,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC/C,MAAM,QAAQ,GACV,uBAAuB,KAAK,SAAS,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ;YAC1E,CAAC,CAAC,gBAAgB;YAClB,CAAC,CAAC,uBAAuB,KAAK,QAAQ,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS;gBAChF,CAAC,CAAC,iBAAiB;gBACnB,CAAC,CAAC,IAAI,GAAG,EAAc,CAAC;QAEhC,oBAAoB,GAAG,QAAQ,CAAC,eAAe,CAAC;QAEhD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC5B,IAAI;gBACA,OAAO,EAAE,CAAC;aACb;YAAC,OAAO,KAAK,EAAE;gBACZ,8FAA8F;gBAC9F,kDAAkD;gBAClD,IAAI,OAAO,MAAM,KAAK,QAAQ;oBAAE,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;aACrG;SACJ;QAED,uBAAuB,GAAG,oBAAoB,CAAC;QAC/C,oBAAoB,GAAG,KAAK,CAAC;IACjC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,IAA6B;IACtE,OAAO,IAAI,KAAK,oBAAoB,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAAmB;IAC5C,kCAAkC,EAAE,CAAC;IACrC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,OAAmB;IAC7C,kCAAkC,EAAE,CAAC;IACrC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC","sourcesContent":["const onHiddenHandlers = new Set<() => void>();\nconst onVisibleHandlers = new Set<() => void>();\n\nlet previousVisibilityState = document.visibilityState;\nlet visibilityTransition: false | DocumentVisibilityState = false;\n\nlet initialized = false;\nfunction maybeInitializeVisibilityListeners(): void {\n if (initialized) return;\n initialized = true;\n\n document.addEventListener(\"visibilitychange\", () => {\n const handlers =\n previousVisibilityState === \"visible\" && document.visibilityState === \"hidden\"\n ? onHiddenHandlers\n : previousVisibilityState === \"hidden\" && document.visibilityState === \"visible\"\n ? onVisibleHandlers\n : new Set<() => void>();\n\n visibilityTransition = document.visibilityState;\n\n for (const handler of handlers) {\n try {\n handler();\n } catch (error) {\n // We'll do the same thing here that we would do if the handler was added directly as an event\n // listener and dispatch an error event if we can.\n if (typeof window === \"object\") window.dispatchEvent(new CustomEvent(\"error\", { detail: error }));\n }\n }\n\n previousVisibilityState = visibilityTransition;\n visibilityTransition = false;\n });\n}\n\nexport function isDuringVisibilityTransition(test: DocumentVisibilityState): boolean {\n return test === visibilityTransition;\n}\n\n/**\n * Run a function when the page is hidden. If this occurs due to tab / browser closure, only synchronous functions will\n * run to completion.\n *\n * If the given handler throws an error, it will be silently swallowed.\n *\n * @param handler\n * @returns A function which, when called, removes the function from the set of visibility change handlers.\n */\nexport function onPageHidden(handler: () => void): () => void {\n maybeInitializeVisibilityListeners();\n onHiddenHandlers.add(handler);\n return () => onHiddenHandlers.delete(handler);\n}\n\n/**\n * Run a function when the page is made visible.\n *\n * If the given handler throws an error, it will be silently swallowed.\n *\n * @param handler\n * @returns A function which, when called, removes the function from the set of visibility change handlers.\n */\nexport function onPageVisible(handler: () => void): () => void {\n maybeInitializeVisibilityListeners();\n onVisibleHandlers.add(handler);\n return () => onVisibleHandlers.delete(handler);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getTimeMs: () => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/common/time.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC","sourcesContent":["export const getTimeMs = () => performance.now();\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare type UnknownRecord<T = unknown> = Record<string | number | symbol, T>;
|
|
2
|
+
export declare type Guard<T, U = unknown> = (value: U | T) => value is T;
|
|
3
|
+
export declare function isString(value: unknown): value is string;
|
|
4
|
+
/**
|
|
5
|
+
* Ensures given value is a safe string.
|
|
6
|
+
*
|
|
7
|
+
* Safe strings allow to prevent CRLF attacks. We use encoding approach inspired by:
|
|
8
|
+
* https://community.veracode.com/s/question/0D53n00007hJJV5CAO/is-cwe-id-117-intended-for-consolelog
|
|
9
|
+
*/
|
|
10
|
+
export declare function isSafeString(value: unknown): value is string;
|
|
11
|
+
export declare function isNumber(value: unknown): value is number;
|
|
12
|
+
export declare function isNotNull<T>(value: T): value is Exclude<T, null>;
|
|
13
|
+
export declare function isArrayOfType<T>(elementTypeGuard: Guard<T>, value: unknown): value is T[];
|
|
14
|
+
export declare function isStringArray<T>(value: unknown): value is T[];
|
|
15
|
+
export declare function isSafeStringArray<T>(value: unknown): value is T[];
|
|
16
|
+
/**
|
|
17
|
+
* Guards given value is instance of ArrayBuffer.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
20
|
+
/**
|
|
21
|
+
* Guards given value is a typed array.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isTypedArray<T>(value: unknown): value is T;
|
|
24
|
+
/**
|
|
25
|
+
* Guards given object is not undefined.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isUndefined<T>(value: unknown): value is T;
|
|
28
|
+
/**
|
|
29
|
+
* Narrow an unknown type to a Record (i.e. a non-null JS object). This holds true for class instances, not just
|
|
30
|
+
* plain objects.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isRecord(value: unknown): value is UnknownRecord;
|
|
33
|
+
/**
|
|
34
|
+
* Check if the value is an arbitrary function
|
|
35
|
+
*/
|
|
36
|
+
export declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Apply a given type predicate asserting values are of type T to each value in a Record.
|
|
39
|
+
*
|
|
40
|
+
* @param predicate Any unary type predicate
|
|
41
|
+
* @returns A type predicate which takes an UnknownRecord and tests that all its values are of type T
|
|
42
|
+
*/
|
|
43
|
+
export declare function predicateRecordValues<T>(predicate: (value: unknown) => value is T): (value: UnknownRecord) => value is UnknownRecord<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Checks whether given value is undefined or a safe URL string.
|
|
46
|
+
*
|
|
47
|
+
* The function checks whether given string is a valid URL with https: protocol.
|
|
48
|
+
*
|
|
49
|
+
* @param urlString URL string to check.
|
|
50
|
+
* @returns True if URL is valid.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isEmptyOrSafeUrl(urlString: string | undefined): boolean;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export function isString(value) {
|
|
2
|
+
return typeof value === "string";
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Ensures given value is a safe string.
|
|
6
|
+
*
|
|
7
|
+
* Safe strings allow to prevent CRLF attacks. We use encoding approach inspired by:
|
|
8
|
+
* https://community.veracode.com/s/question/0D53n00007hJJV5CAO/is-cwe-id-117-intended-for-consolelog
|
|
9
|
+
*/
|
|
10
|
+
export function isSafeString(value) {
|
|
11
|
+
return isString(value) && encodeURIComponent(value) === value;
|
|
12
|
+
}
|
|
13
|
+
export function isNumber(value) {
|
|
14
|
+
return typeof value === "number";
|
|
15
|
+
}
|
|
16
|
+
export function isNotNull(value) {
|
|
17
|
+
return value !== null;
|
|
18
|
+
}
|
|
19
|
+
export function isArrayOfType(elementTypeGuard, value) {
|
|
20
|
+
return Array.isArray(value) && value.every((id) => elementTypeGuard(id));
|
|
21
|
+
}
|
|
22
|
+
export function isStringArray(value) {
|
|
23
|
+
return isArrayOfType(isString, value);
|
|
24
|
+
}
|
|
25
|
+
export function isSafeStringArray(value) {
|
|
26
|
+
return isArrayOfType(isSafeString, value);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Guards given value is instance of ArrayBuffer.
|
|
30
|
+
*/
|
|
31
|
+
export function isArrayBuffer(value) {
|
|
32
|
+
return value instanceof ArrayBuffer;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Guards given value is a typed array.
|
|
36
|
+
*/
|
|
37
|
+
export function isTypedArray(value) {
|
|
38
|
+
return value instanceof Object.getPrototypeOf(Uint8Array);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Guards given object is not undefined.
|
|
42
|
+
*/
|
|
43
|
+
export function isUndefined(value) {
|
|
44
|
+
return typeof value === "undefined";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Narrow an unknown type to a Record (i.e. a non-null JS object). This holds true for class instances, not just
|
|
48
|
+
* plain objects.
|
|
49
|
+
*/
|
|
50
|
+
export function isRecord(value) {
|
|
51
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if the value is an arbitrary function
|
|
55
|
+
*/
|
|
56
|
+
export function isFunction(value) {
|
|
57
|
+
return typeof value === "function";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Apply a given type predicate asserting values are of type T to each value in a Record.
|
|
61
|
+
*
|
|
62
|
+
* @param predicate Any unary type predicate
|
|
63
|
+
* @returns A type predicate which takes an UnknownRecord and tests that all its values are of type T
|
|
64
|
+
*/
|
|
65
|
+
export function predicateRecordValues(predicate) {
|
|
66
|
+
return (value) => {
|
|
67
|
+
for (const v of Object.values(value))
|
|
68
|
+
if (!predicate(v))
|
|
69
|
+
return false;
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks whether given value is undefined or a safe URL string.
|
|
75
|
+
*
|
|
76
|
+
* The function checks whether given string is a valid URL with https: protocol.
|
|
77
|
+
*
|
|
78
|
+
* @param urlString URL string to check.
|
|
79
|
+
* @returns True if URL is valid.
|
|
80
|
+
*/
|
|
81
|
+
export function isEmptyOrSafeUrl(urlString) {
|
|
82
|
+
if (!urlString)
|
|
83
|
+
return true;
|
|
84
|
+
try {
|
|
85
|
+
const url = new URL(urlString);
|
|
86
|
+
return url.protocol === "https:" || url.protocol === "http:";
|
|
87
|
+
}
|
|
88
|
+
catch (_a) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=typeguards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeguards.js","sourceRoot":"","sources":["../../src/common/typeguards.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrC,CAAC;AACD,MAAM,UAAU,SAAS,CAAI,KAAQ;IACjC,OAAO,KAAK,KAAK,IAAI,CAAC;AAC1B,CAAC;AACD,MAAM,UAAU,aAAa,CAAI,gBAA0B,EAAE,KAAc;IACvE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7E,CAAC;AACD,MAAM,UAAU,aAAa,CAAI,KAAc;IAC3C,OAAO,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAI,KAAc;IAC/C,OAAO,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IACxC,OAAO,KAAK,YAAY,WAAW,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAI,KAAc;IAC1C,OAAO,KAAK,YAAY,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAI,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,WAAW,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAI,SAAyC;IAC9E,OAAO,CAAC,KAAoB,EAA6B,EAAE;QACvD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;QACtE,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA6B;IAC1D,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,IAAI;QACA,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC;KAChE;IAAC,WAAM;QACJ,OAAO,KAAK,CAAC;KAChB;AACL,CAAC","sourcesContent":["type UnknownRecord<T = unknown> = Record<string | number | symbol, T>;\nexport type Guard<T, U = unknown> = (value: U | T) => value is T;\n\nexport function isString(value: unknown): value is string {\n return typeof value === \"string\";\n}\n\n/**\n * Ensures given value is a safe string.\n *\n * Safe strings allow to prevent CRLF attacks. We use encoding approach inspired by:\n * https://community.veracode.com/s/question/0D53n00007hJJV5CAO/is-cwe-id-117-intended-for-consolelog\n */\nexport function isSafeString(value: unknown): value is string {\n return isString(value) && encodeURIComponent(value) === value;\n}\n\nexport function isNumber(value: unknown): value is number {\n return typeof value === \"number\";\n}\nexport function isNotNull<T>(value: T): value is Exclude<T, null> {\n return value !== null;\n}\nexport function isArrayOfType<T>(elementTypeGuard: Guard<T>, value: unknown): value is T[] {\n return Array.isArray(value) && value.every((id) => elementTypeGuard(id));\n}\nexport function isStringArray<T>(value: unknown): value is T[] {\n return isArrayOfType(isString, value);\n}\n\nexport function isSafeStringArray<T>(value: unknown): value is T[] {\n return isArrayOfType(isSafeString, value);\n}\n\n/**\n * Guards given value is instance of ArrayBuffer.\n */\nexport function isArrayBuffer(value: unknown): value is ArrayBuffer {\n return value instanceof ArrayBuffer;\n}\n\n/**\n * Guards given value is a typed array.\n */\nexport function isTypedArray<T>(value: unknown): value is T {\n return value instanceof Object.getPrototypeOf(Uint8Array);\n}\n\n/**\n * Guards given object is not undefined.\n */\nexport function isUndefined<T>(value: unknown): value is T {\n return typeof value === \"undefined\";\n}\n\n/**\n * Narrow an unknown type to a Record (i.e. a non-null JS object). This holds true for class instances, not just\n * plain objects.\n */\nexport function isRecord(value: unknown): value is UnknownRecord {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Check if the value is an arbitrary function\n */\nexport function isFunction(value: unknown): value is (...args: unknown[]) => unknown {\n return typeof value === \"function\";\n}\n\n/**\n * Apply a given type predicate asserting values are of type T to each value in a Record.\n *\n * @param predicate Any unary type predicate\n * @returns A type predicate which takes an UnknownRecord and tests that all its values are of type T\n */\nexport function predicateRecordValues<T>(predicate: (value: unknown) => value is T) {\n return (value: UnknownRecord): value is UnknownRecord<T> => {\n for (const v of Object.values(value)) if (!predicate(v)) return false;\n return true;\n };\n}\n\n/**\n * Checks whether given value is undefined or a safe URL string.\n *\n * The function checks whether given string is a valid URL with https: protocol.\n *\n * @param urlString URL string to check.\n * @returns True if URL is valid.\n */\nexport function isEmptyOrSafeUrl(urlString: string | undefined): boolean {\n if (!urlString) return true;\n try {\n const url = new URL(urlString);\n return url.protocol === \"https:\" || url.protocol === \"http:\";\n } catch {\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For instances where we'd like to define a Tuple to be of certain type and length.
|
|
3
|
+
* Example: TupleOf<number, 3> // [number, number, number]
|
|
4
|
+
*
|
|
5
|
+
* For more example and use cases regarding Recursive conditional types
|
|
6
|
+
* see: https://github.com/microsoft/TypeScript/pull/40002
|
|
7
|
+
*/
|
|
8
|
+
declare type _TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : _TupleOf<T, N, [T, ...R]>;
|
|
9
|
+
export declare type TupleOf<T, N extends number> = N extends N ? (number extends N ? T[] : _TupleOf<T, N, []>) : never;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * For instances where we'd like to define a Tuple to be of certain type and length.\n * Example: TupleOf<number, 3> // [number, number, number]\n *\n * For more example and use cases regarding Recursive conditional types\n * see: https://github.com/microsoft/TypeScript/pull/40002\n */\ntype _TupleOf<T, N extends number, R extends unknown[]> = R[\"length\"] extends N ? R : _TupleOf<T, N, [T, ...R]>;\nexport type TupleOf<T, N extends number> = N extends N ? (number extends N ? T[] : _TupleOf<T, N, []>) : never;\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Guard } from "./typeguards";
|
|
3
|
+
export declare function guard<T>(predicate: Guard<T>): (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
4
|
+
export declare function validate(target: Object, key: string | symbol, descriptor: PropertyDescriptor): void;
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether given value is assignable to provided type.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isValueOfType(value: unknown, type: any): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns type string of a value. It mostly mimics the behavior of typeof, but for non-primitives
|
|
11
|
+
* (i.e. objects and functions), it returns a more granular type name where possible. Source:
|
|
12
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#custom_method_that_gets_a_more_specific_type
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTypeName(value: unknown): string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
const predicateMetadataKey = Symbol("validate");
|
|
3
|
+
// A map of primitive types accoring to
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
// http://blog.wolksoftware.com/decorators-metadata-reflection-in-typescript-from-novice-to-expert-part-4#3-basic-type-serialization_1
|
|
6
|
+
const primitiveMap = {
|
|
7
|
+
string: String,
|
|
8
|
+
number: Number,
|
|
9
|
+
boolean: Boolean,
|
|
10
|
+
};
|
|
11
|
+
const ordinalSuffixMap = {
|
|
12
|
+
1: "st",
|
|
13
|
+
2: "nd",
|
|
14
|
+
3: "rd",
|
|
15
|
+
};
|
|
16
|
+
function getArgumentInfo(target, methodName, argumentIndex, arg) {
|
|
17
|
+
var _a;
|
|
18
|
+
let argString;
|
|
19
|
+
try {
|
|
20
|
+
argString = JSON.stringify(arg);
|
|
21
|
+
}
|
|
22
|
+
catch (_b) {
|
|
23
|
+
argString = String(arg);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
argPosition: `${argumentIndex + 1}${(_a = ordinalSuffixMap[argumentIndex + 1]) !== null && _a !== void 0 ? _a : "th"}`,
|
|
27
|
+
methodPath: `${getTypeName(target)}.${String(methodName)}()`,
|
|
28
|
+
argTypeName: getTypeName(arg),
|
|
29
|
+
argString,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function guard(predicate) {
|
|
33
|
+
return (target, propertyKey, parameterIndex) => {
|
|
34
|
+
let existingPredicates = Reflect.getOwnMetadata(predicateMetadataKey, target, propertyKey) || [];
|
|
35
|
+
existingPredicates[parameterIndex] = predicate;
|
|
36
|
+
Reflect.defineMetadata(predicateMetadataKey, existingPredicates, target, propertyKey);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function validate(target, key, descriptor) {
|
|
40
|
+
const method = descriptor.value;
|
|
41
|
+
const types = Reflect.getMetadata("design:paramtypes", target, key);
|
|
42
|
+
const predicates = Reflect.getMetadata(predicateMetadataKey, target, key);
|
|
43
|
+
descriptor.value = function (...args) {
|
|
44
|
+
for (const [i, type] of types.entries()) {
|
|
45
|
+
let arg = Array.isArray(args) && args[i];
|
|
46
|
+
if (!!predicates && predicates[i] && !predicates[i](arg)) {
|
|
47
|
+
const { methodPath, argPosition, argString } = getArgumentInfo(target, key, i, arg);
|
|
48
|
+
throw new Error(`The ${argPosition} argument to ${methodPath} method has an invalid value: ${argString}.`);
|
|
49
|
+
}
|
|
50
|
+
if (arg === undefined || arg === null) {
|
|
51
|
+
// TODO: is there a way to check for nullable parameter?
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (!isValueOfType(arg, type)) {
|
|
55
|
+
const { methodPath, argPosition, argTypeName } = getArgumentInfo(target, key, i, arg);
|
|
56
|
+
throw new Error(`The ${argPosition} argument to '${methodPath}' method is of type ` +
|
|
57
|
+
`'${argTypeName}', which is not assignable to parameter of type '${type.name}'.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return method.apply(this, arguments);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether given value is assignable to provided type.
|
|
65
|
+
*/
|
|
66
|
+
export function isValueOfType(value, type) {
|
|
67
|
+
if (value instanceof type) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
// test for primitive value
|
|
71
|
+
const isPrimitive = value !== Object(value);
|
|
72
|
+
return isPrimitive && primitiveMap[typeof value] === type;
|
|
73
|
+
}
|
|
74
|
+
/* eslint-disable max-len */
|
|
75
|
+
/**
|
|
76
|
+
* Returns type string of a value. It mostly mimics the behavior of typeof, but for non-primitives
|
|
77
|
+
* (i.e. objects and functions), it returns a more granular type name where possible. Source:
|
|
78
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#custom_method_that_gets_a_more_specific_type
|
|
79
|
+
*/
|
|
80
|
+
export function getTypeName(value) {
|
|
81
|
+
if (typeof value !== "object" && typeof value !== "function") {
|
|
82
|
+
return typeof value;
|
|
83
|
+
}
|
|
84
|
+
if (value === null) {
|
|
85
|
+
return "null";
|
|
86
|
+
}
|
|
87
|
+
if (Object.getPrototypeOf(value) === Function.prototype && /^class/.test(String(value))) {
|
|
88
|
+
return "class";
|
|
89
|
+
}
|
|
90
|
+
// Symbol.toStringTag often specifies the "display name" of the
|
|
91
|
+
// object's class.
|
|
92
|
+
if (Symbol.toStringTag in value && typeof value[Symbol.toStringTag] === "string") {
|
|
93
|
+
return value[Symbol.toStringTag];
|
|
94
|
+
}
|
|
95
|
+
// The name of the constructor; for example `Array`, `GeneratorFunction`,
|
|
96
|
+
// `Number`, `String`, `Boolean` or `MyCustomObject`
|
|
97
|
+
if (typeof value.constructor.name === "string" && value.constructor.name !== "") {
|
|
98
|
+
return value.constructor.name;
|
|
99
|
+
}
|
|
100
|
+
// At this point there's no robust way to get the type of value,
|
|
101
|
+
// so we use the base implementation.
|
|
102
|
+
return typeof value;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/common/validate.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,MAAM,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAEhD,uCAAuC;AACvC,4BAA4B;AAC5B,sIAAsI;AACtI,MAAM,YAAY,GAAG;IACjB,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,OAAO;CACnB,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACrB,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,IAAI;CACV,CAAC;AAEF,SAAS,eAAe,CAAC,MAAc,EAAE,UAA2B,EAAE,aAAqB,EAAE,GAAY;;IACrG,IAAI,SAAS,CAAC;IACd,IAAI;QACA,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KACnC;IAAC,WAAM;QACJ,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;KAC3B;IACD,OAAO;QACH,WAAW,EAAE,GAAG,aAAa,GAAG,CAAC,GAAG,MAAA,gBAAgB,CAAC,aAAa,GAAG,CAAC,CAAC,mCAAI,IAAI,EAAE;QACjF,UAAU,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI;QAC5D,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC;QAC7B,SAAS;KACZ,CAAC;AACN,CAAC;AAED,MAAM,UAAU,KAAK,CAAI,SAAmB;IACxC,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,cAAsB,EAAE,EAAE;QAC5E,IAAI,kBAAkB,GAClB,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;QAC5E,kBAAkB,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;QAC/C,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC1F,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,GAAoB,EAAE,UAA8B;IACzF,MAAM,MAAM,GAAG,UAAU,CAAC,KAAM,CAAC;IACjC,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACpE,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,oBAAoB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1E,UAAU,CAAC,KAAK,GAAG,UAAU,GAAG,IAAe;QAC3C,KAAK,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE;YACrC,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAEzC,IAAI,CAAC,CAAC,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;gBACtD,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;gBACpF,MAAM,IAAI,KAAK,CACX,OAAO,WAAW,gBAAgB,UAAU,iCAAiC,SAAS,GAAG,CAC5F,CAAC;aACL;YACD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;gBACnC,wDAAwD;gBACxD,MAAM;aACT;YACD,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE;gBAC3B,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;gBACtF,MAAM,IAAI,KAAK,CACX,OAAO,WAAW,iBAAiB,UAAU,sBAAsB;oBAC/D,IAAI,WAAW,oDAAoD,IAAI,CAAC,IAAI,IAAI,CACvF,CAAC;aACL;SACJ;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzC,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,IAAS;IACnD,IAAI,KAAK,YAAY,IAAI,EAAE;QACvB,OAAO,IAAI,CAAC;KACf;IACD,2BAA2B;IAC3B,MAAM,WAAW,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO,WAAW,IAAI,YAAY,CAAC,OAAO,KAAK,CAAC,KAAK,IAAI,CAAC;AAC9D,CAAC;AAED,4BAA4B;AAC5B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;QAC1D,OAAO,OAAO,KAAK,CAAC;KACvB;IACD,IAAI,KAAK,KAAK,IAAI,EAAE;QAChB,OAAO,MAAM,CAAC;KACjB;IAED,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;QACrF,OAAO,OAAO,CAAC;KAClB;IAED,+DAA+D;IAC/D,kBAAkB;IAClB,IAAI,MAAM,CAAC,WAAW,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ,EAAE;QAC9E,OAAO,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;KACpC;IAED,yEAAyE;IACzE,oDAAoD;IACpD,IAAI,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,EAAE,EAAE;QAC7E,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;KACjC;IAED,gEAAgE;IAChE,qCAAqC;IACrC,OAAO,OAAO,KAAK,CAAC;AACxB,CAAC","sourcesContent":["import \"reflect-metadata\";\nimport { Guard } from \"./typeguards\";\n\nconst predicateMetadataKey = Symbol(\"validate\");\n\n// A map of primitive types accoring to\n/* eslint-disable max-len */\n// http://blog.wolksoftware.com/decorators-metadata-reflection-in-typescript-from-novice-to-expert-part-4#3-basic-type-serialization_1\nconst primitiveMap = {\n string: String,\n number: Number,\n boolean: Boolean,\n};\n\nconst ordinalSuffixMap = {\n 1: \"st\",\n 2: \"nd\",\n 3: \"rd\",\n};\n\nfunction getArgumentInfo(target: Object, methodName: string | symbol, argumentIndex: number, arg: unknown) {\n let argString;\n try {\n argString = JSON.stringify(arg);\n } catch {\n argString = String(arg);\n }\n return {\n argPosition: `${argumentIndex + 1}${ordinalSuffixMap[argumentIndex + 1] ?? \"th\"}`,\n methodPath: `${getTypeName(target)}.${String(methodName)}()`,\n argTypeName: getTypeName(arg),\n argString,\n };\n}\n\nexport function guard<T>(predicate: Guard<T>) {\n return (target: Object, propertyKey: string | symbol, parameterIndex: number) => {\n let existingPredicates: Array<Guard<any>> =\n Reflect.getOwnMetadata(predicateMetadataKey, target, propertyKey) || [];\n existingPredicates[parameterIndex] = predicate;\n Reflect.defineMetadata(predicateMetadataKey, existingPredicates, target, propertyKey);\n };\n}\n\nexport function validate(target: Object, key: string | symbol, descriptor: PropertyDescriptor): void {\n const method = descriptor.value!;\n const types = Reflect.getMetadata(\"design:paramtypes\", target, key);\n const predicates = Reflect.getMetadata(predicateMetadataKey, target, key);\n descriptor.value = function (...args: unknown[]) {\n for (const [i, type] of types.entries()) {\n let arg = Array.isArray(args) && args[i];\n\n if (!!predicates && predicates[i] && !predicates[i](arg)) {\n const { methodPath, argPosition, argString } = getArgumentInfo(target, key, i, arg);\n throw new Error(\n `The ${argPosition} argument to ${methodPath} method has an invalid value: ${argString}.`\n );\n }\n if (arg === undefined || arg === null) {\n // TODO: is there a way to check for nullable parameter?\n break;\n }\n if (!isValueOfType(arg, type)) {\n const { methodPath, argPosition, argTypeName } = getArgumentInfo(target, key, i, arg);\n throw new Error(\n `The ${argPosition} argument to '${methodPath}' method is of type ` +\n `'${argTypeName}', which is not assignable to parameter of type '${type.name}'.`\n );\n }\n }\n return method.apply(this, arguments);\n };\n}\n\n/**\n * Checks whether given value is assignable to provided type.\n */\nexport function isValueOfType(value: unknown, type: any) {\n if (value instanceof type) {\n return true;\n }\n // test for primitive value\n const isPrimitive = value !== Object(value);\n return isPrimitive && primitiveMap[typeof value] === type;\n}\n\n/* eslint-disable max-len */\n/**\n * Returns type string of a value. It mostly mimics the behavior of typeof, but for non-primitives\n * (i.e. objects and functions), it returns a more granular type name where possible. Source:\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#custom_method_that_gets_a_more_specific_type\n */\nexport function getTypeName(value: unknown): string {\n if (typeof value !== \"object\" && typeof value !== \"function\") {\n return typeof value;\n }\n if (value === null) {\n return \"null\";\n }\n\n if (Object.getPrototypeOf(value) === Function.prototype && /^class/.test(String(value))) {\n return \"class\";\n }\n\n // Symbol.toStringTag often specifies the \"display name\" of the\n // object's class.\n if (Symbol.toStringTag in value && typeof value[Symbol.toStringTag] === \"string\") {\n return value[Symbol.toStringTag];\n }\n\n // The name of the constructor; for example `Array`, `GeneratorFunction`,\n // `Number`, `String`, `Boolean` or `MyCustomObject`\n if (typeof value.constructor.name === \"string\" && value.constructor.name !== \"\") {\n return value.constructor.name;\n }\n\n // At this point there's no robust way to get the type of value,\n // so we use the base implementation.\n return typeof value;\n}\n"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { EstimatedLensPerformance } from "./benchmark/estimateLensPerformanceCluster";
|
|
2
|
+
import { LogLevelName } from "./logger/logger";
|
|
3
|
+
interface CameraKitRuntimeConfiguration {
|
|
4
|
+
lensPerformance: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;
|
|
5
|
+
logger: "noop" | "console";
|
|
6
|
+
logLevel: LogLevelName;
|
|
7
|
+
shouldUseWorker: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Configuration which must be provided when calling {@link bootstrapCameraKit}. These values are used to create various
|
|
11
|
+
* CameraKit components.
|
|
12
|
+
*
|
|
13
|
+
* @category Bootstrapping and Configuration
|
|
14
|
+
*/
|
|
15
|
+
export interface CameraKitBootstrapConfiguration {
|
|
16
|
+
/**
|
|
17
|
+
* Long-lived token granting your application access to CameraKit APIs. This is found in the SnapKit Dev Portal,
|
|
18
|
+
* where it's called the API Token.
|
|
19
|
+
*/
|
|
20
|
+
apiToken: string;
|
|
21
|
+
/**
|
|
22
|
+
* Determine where to print CameraKit log messages. By default no logs will be printed.
|
|
23
|
+
*
|
|
24
|
+
* CameraKit emits log messages to help diagnose and root cause issues that may occur during the development of a
|
|
25
|
+
* host application. The printing of these can be controlled via the following
|
|
26
|
+
* options:
|
|
27
|
+
* - `noop`: log messages are ignored.
|
|
28
|
+
* - `console`: log messages are printed to console.
|
|
29
|
+
*/
|
|
30
|
+
logger?: "noop" | "console";
|
|
31
|
+
/**
|
|
32
|
+
* Log only if a logged entry level is greater than or equal to this level. Here is the order of levels:
|
|
33
|
+
* error > warn > log = info > debug. Default value is "info".
|
|
34
|
+
*/
|
|
35
|
+
logLevel?: LogLevelName;
|
|
36
|
+
/**
|
|
37
|
+
* Some lenses may decide to modify their behavior based on the performance of the current environment. If you are
|
|
38
|
+
* using such lenses, providing an estimation of lens performance may lead to better user experience (especially on
|
|
39
|
+
* low-performance devices).
|
|
40
|
+
*
|
|
41
|
+
* Running the {@link estimateLensPerformance} function will run benchmarks and estimate an appropriate lens
|
|
42
|
+
* performance cluster (i.e. a performance rating) based on the current environment.
|
|
43
|
+
*
|
|
44
|
+
* Lower cluster = worse expected performance capability.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { bootstrapCameraKit, estimateLensPerformance } from '@snap/camera-kit`
|
|
49
|
+
*
|
|
50
|
+
* const cameraKit = await bootstrapCameraKit({
|
|
51
|
+
* apiToken: '...',
|
|
52
|
+
* lensPerformance: estimateLensPerformance(),
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
lensPerformance?: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;
|
|
57
|
+
/**
|
|
58
|
+
* In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an
|
|
59
|
+
* optimized CDN. But sometimes (e.g. during development or within a CI pipeline), it may be necessary to download
|
|
60
|
+
* these assets from somewhere else.
|
|
61
|
+
*
|
|
62
|
+
* This configuration option allows the application to specify URLs to be used for both the WebAssembly and JS glue
|
|
63
|
+
* file that are used to run and interact with CameraKit's rendering engine.
|
|
64
|
+
*/
|
|
65
|
+
lensCoreOverrideUrls?: {
|
|
66
|
+
wasm: string;
|
|
67
|
+
js: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an
|
|
71
|
+
* optimized CDN. But sometimes during development or within a CI pipeline, it may be necessary to download these
|
|
72
|
+
* assets from somewhere else. With a provided `wasmEndpointOverride`, asset URLs will be automatically generated
|
|
73
|
+
* based on this root endpoint.
|
|
74
|
+
*/
|
|
75
|
+
wasmEndpointOverride?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* This type represents the result of merging user-supplied config with default config -- as such, it has no nullable
|
|
79
|
+
* fields, making it a more convenient type for other components to use.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export declare type CameraKitConfiguration = CameraKitRuntimeConfiguration & CameraKitBootstrapConfiguration;
|
|
84
|
+
/** @internal */
|
|
85
|
+
export declare const configurationToken = "configuration";
|
|
86
|
+
/** @internal */
|
|
87
|
+
export declare const createCameraKitConfigurationFactory: (configuration: CameraKitBootstrapConfiguration) => {
|
|
88
|
+
(): CameraKitConfiguration;
|
|
89
|
+
token: "configuration";
|
|
90
|
+
dependencies: [];
|
|
91
|
+
};
|
|
92
|
+
export {};
|