@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,81 @@
|
|
|
1
|
+
import { Container, Factories } from "./Container";
|
|
2
|
+
import { AddService, InjectableFunction, ServicesFromTokenizedParams, ValidTokens } from "./types";
|
|
3
|
+
declare type AddDependencies<ParentDependencies, Dependencies> = ParentDependencies extends any ? {
|
|
4
|
+
[K in keyof ParentDependencies | keyof Dependencies]: K extends keyof ParentDependencies ? ParentDependencies[K] : K extends keyof Dependencies ? Dependencies[K] : never;
|
|
5
|
+
} : never;
|
|
6
|
+
declare type ExcludeKey<T, U> = T extends any ? {
|
|
7
|
+
[K in Exclude<keyof T, U>]: T[K];
|
|
8
|
+
} : never;
|
|
9
|
+
declare type PartialInjectableFunction<Params extends readonly any[], Tokens extends readonly string[], Token extends string, Service> = {
|
|
10
|
+
(...args: Params): Service;
|
|
11
|
+
token: Token;
|
|
12
|
+
dependencies: Tokens;
|
|
13
|
+
};
|
|
14
|
+
declare type Injectables<Services, Dependencies> = {
|
|
15
|
+
[K in keyof Services]: K extends string ? InjectableFunction<Services & Dependencies, readonly ValidTokens<Services & Dependencies>[], K, Services[K]> : never;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Similar to [Container], with the exception that Services may be provided to a PartialContainer which *does not*
|
|
19
|
+
* contain all of that Services dependencies.
|
|
20
|
+
*
|
|
21
|
+
* For this to remain safe, Services can not be resolved by PartialContainer – it has no `get` method.
|
|
22
|
+
*
|
|
23
|
+
* Instead, the PartialContainer must be provided to a [Container] which *does* contain all the dependencies required
|
|
24
|
+
* by all the Service in the PartialContainer. The resulting [Container] can then resolve these Services.
|
|
25
|
+
*
|
|
26
|
+
* PartialContainers are used to create a collection of Services which can then be provided via a simple one-line syntax
|
|
27
|
+
* to an existing Container (which fulfills the collection's dependencies). It is an organizational tool, allowing
|
|
28
|
+
* coherent groupings of Services to be defined in one place, then combined elsewhere to form a complete [Container].
|
|
29
|
+
*
|
|
30
|
+
* Here's an example of PartialContainer usage:
|
|
31
|
+
* ```ts
|
|
32
|
+
* // We can provide fooFactory, even though the PartialContainer doesn't fulfill the Bar dependency.
|
|
33
|
+
* const fooFactory = Injectable('Foo', ['Bar'] as const, (bar: Bar) => new Foo(bar))
|
|
34
|
+
* const partialContainer = new PartialContainer({}).provide(fooFactory)
|
|
35
|
+
*
|
|
36
|
+
* const barFactory = Injectable('Bar', () => new Bar())
|
|
37
|
+
* const dependenciesContainer = Container.provides(barFactory)
|
|
38
|
+
*
|
|
39
|
+
* const combinedContainer = dependenciesContainer.provides(partialContainer)
|
|
40
|
+
*
|
|
41
|
+
* // We can resolve Foo, because the combined container includes Bar, so all of Foo's dependencies are now met.
|
|
42
|
+
* const foo = combinedContainer.get('Foo')
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
/** @internal */
|
|
46
|
+
export declare class PartialContainer<Services = {}, Dependencies = {}> {
|
|
47
|
+
private readonly injectables;
|
|
48
|
+
constructor(injectables: Injectables<Services, Dependencies>);
|
|
49
|
+
/**
|
|
50
|
+
* Create a new PartialContainer which provides a Service created by the given InjectableFunction.
|
|
51
|
+
*
|
|
52
|
+
* The InjectableFunction contains metadata specifying the Token by which the created Service will be known, as well
|
|
53
|
+
* as an ordered list of Tokens to be resolved and provided to the InjectableFunction as arguments.
|
|
54
|
+
*
|
|
55
|
+
* This dependencies are allowed to be missing from the PartialContainer, but these dependencies are maintained as a
|
|
56
|
+
* parameter of the returned PartialContainer. This allows `[Container.provides]` to type check the dependencies and
|
|
57
|
+
* ensure they can be provided by the Container.
|
|
58
|
+
*
|
|
59
|
+
* @param fn A InjectableFunction, taking dependencies as arguments, which returns the Service.
|
|
60
|
+
*/
|
|
61
|
+
provides<AdditionalDependencies extends readonly any[], Tokens extends readonly string[], Token extends string, Service>(fn: PartialInjectableFunction<AdditionalDependencies, Tokens, Token, Service>): PartialContainer<AddService<Services, Token, Service>, ExcludeKey<AddDependencies<ExcludeKey<Dependencies, Token>, ServicesFromTokenizedParams<Tokens, AdditionalDependencies>>, keyof Services>>;
|
|
62
|
+
/**
|
|
63
|
+
* In order to create a [Container], the InjectableFunctions maintained by the PartialContainer must be memoized
|
|
64
|
+
* into Factories that can resolve their dependencies and return the correct Service.
|
|
65
|
+
*
|
|
66
|
+
* In particular, this requires access to a "parent" Container to avoid infinite looping in cases where Service A
|
|
67
|
+
* depends on Service A – this is allowed (as long as the parent container provides Service A), but requires access
|
|
68
|
+
* to the parent Container to provide the parent implementation of Service A.
|
|
69
|
+
*
|
|
70
|
+
* This also means that Services provided by a PartialContainer to a Container via this function will always be
|
|
71
|
+
* scoped to the Container. In other words, if a PartialContainer containing Service A is provided to both
|
|
72
|
+
* Container X and Container Y, when Service A is resolved by Container X the InjectableFunction used to create
|
|
73
|
+
* Service A will be invoked – and when Service A is resolved by Container Y, the InjectableFunction will be invoked
|
|
74
|
+
* again.
|
|
75
|
+
*
|
|
76
|
+
* @param parent A [Container] which provides all the required Dependencies of this PartialContainer.
|
|
77
|
+
*/
|
|
78
|
+
getFactories(parent: Container<Dependencies>): Factories<Services>;
|
|
79
|
+
getTokens(): Array<keyof Services>;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { entries } from "../common/entries";
|
|
2
|
+
import { memoize } from "../common/memoize";
|
|
3
|
+
/**
|
|
4
|
+
* Similar to [Container], with the exception that Services may be provided to a PartialContainer which *does not*
|
|
5
|
+
* contain all of that Services dependencies.
|
|
6
|
+
*
|
|
7
|
+
* For this to remain safe, Services can not be resolved by PartialContainer – it has no `get` method.
|
|
8
|
+
*
|
|
9
|
+
* Instead, the PartialContainer must be provided to a [Container] which *does* contain all the dependencies required
|
|
10
|
+
* by all the Service in the PartialContainer. The resulting [Container] can then resolve these Services.
|
|
11
|
+
*
|
|
12
|
+
* PartialContainers are used to create a collection of Services which can then be provided via a simple one-line syntax
|
|
13
|
+
* to an existing Container (which fulfills the collection's dependencies). It is an organizational tool, allowing
|
|
14
|
+
* coherent groupings of Services to be defined in one place, then combined elsewhere to form a complete [Container].
|
|
15
|
+
*
|
|
16
|
+
* Here's an example of PartialContainer usage:
|
|
17
|
+
* ```ts
|
|
18
|
+
* // We can provide fooFactory, even though the PartialContainer doesn't fulfill the Bar dependency.
|
|
19
|
+
* const fooFactory = Injectable('Foo', ['Bar'] as const, (bar: Bar) => new Foo(bar))
|
|
20
|
+
* const partialContainer = new PartialContainer({}).provide(fooFactory)
|
|
21
|
+
*
|
|
22
|
+
* const barFactory = Injectable('Bar', () => new Bar())
|
|
23
|
+
* const dependenciesContainer = Container.provides(barFactory)
|
|
24
|
+
*
|
|
25
|
+
* const combinedContainer = dependenciesContainer.provides(partialContainer)
|
|
26
|
+
*
|
|
27
|
+
* // We can resolve Foo, because the combined container includes Bar, so all of Foo's dependencies are now met.
|
|
28
|
+
* const foo = combinedContainer.get('Foo')
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/** @internal */
|
|
32
|
+
export class PartialContainer {
|
|
33
|
+
constructor(injectables) {
|
|
34
|
+
this.injectables = injectables;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a new PartialContainer which provides a Service created by the given InjectableFunction.
|
|
38
|
+
*
|
|
39
|
+
* The InjectableFunction contains metadata specifying the Token by which the created Service will be known, as well
|
|
40
|
+
* as an ordered list of Tokens to be resolved and provided to the InjectableFunction as arguments.
|
|
41
|
+
*
|
|
42
|
+
* This dependencies are allowed to be missing from the PartialContainer, but these dependencies are maintained as a
|
|
43
|
+
* parameter of the returned PartialContainer. This allows `[Container.provides]` to type check the dependencies and
|
|
44
|
+
* ensure they can be provided by the Container.
|
|
45
|
+
*
|
|
46
|
+
* @param fn A InjectableFunction, taking dependencies as arguments, which returns the Service.
|
|
47
|
+
*/
|
|
48
|
+
provides(fn) {
|
|
49
|
+
return new PartialContainer(Object.assign(Object.assign({}, this.injectables), { [fn.token]: fn }));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* In order to create a [Container], the InjectableFunctions maintained by the PartialContainer must be memoized
|
|
53
|
+
* into Factories that can resolve their dependencies and return the correct Service.
|
|
54
|
+
*
|
|
55
|
+
* In particular, this requires access to a "parent" Container to avoid infinite looping in cases where Service A
|
|
56
|
+
* depends on Service A – this is allowed (as long as the parent container provides Service A), but requires access
|
|
57
|
+
* to the parent Container to provide the parent implementation of Service A.
|
|
58
|
+
*
|
|
59
|
+
* This also means that Services provided by a PartialContainer to a Container via this function will always be
|
|
60
|
+
* scoped to the Container. In other words, if a PartialContainer containing Service A is provided to both
|
|
61
|
+
* Container X and Container Y, when Service A is resolved by Container X the InjectableFunction used to create
|
|
62
|
+
* Service A will be invoked – and when Service A is resolved by Container Y, the InjectableFunction will be invoked
|
|
63
|
+
* again.
|
|
64
|
+
*
|
|
65
|
+
* @param parent A [Container] which provides all the required Dependencies of this PartialContainer.
|
|
66
|
+
*/
|
|
67
|
+
getFactories(parent) {
|
|
68
|
+
return Object.fromEntries(entries(this.injectables).map(([token, fn]) => {
|
|
69
|
+
return [
|
|
70
|
+
token,
|
|
71
|
+
memoize((c) => {
|
|
72
|
+
return fn(...fn.dependencies.map((t) => {
|
|
73
|
+
return t === token
|
|
74
|
+
? parent.get(t)
|
|
75
|
+
: c.get(t);
|
|
76
|
+
}));
|
|
77
|
+
}),
|
|
78
|
+
];
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
getTokens() {
|
|
82
|
+
return Object.keys(this.injectables);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=PartialContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PartialContainer.js","sourceRoot":"","sources":["../../src/dependency-injection/PartialContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAoC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,gBAAgB;AAChB,MAAM,OAAO,gBAAgB;IACzB,YAA6B,WAAgD;QAAhD,gBAAW,GAAX,WAAW,CAAqC;IAAG,CAAC;IAEjF;;;;;;;;;;;OAWG;IACH,QAAQ,CAMJ,EAA6E;QAc7E,OAAO,IAAI,gBAAgB,CAAC,gCAAK,IAAI,CAAC,WAAW,KAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,GAAS,CAAC,CAAC;IAChF,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,MAA+B;QACxC,OAAO,MAAM,CAAC,WAAW,CACrB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;YAC1C,OAAO;gBACH,KAAK;gBACL,OAAO,CAAC,CAAC,CAAqC,EAAE,EAAE;oBAC9C,OAAO,EAAE,CACL,GAAI,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;wBAC1B,OAAO,CAAC,KAAK,KAAK;4BACd,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAuB,CAAC;4BACrC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAkC,CAAC,CAAC;oBACpD,CAAC,CAAS,CACb,CAAC;gBACN,CAAC,CAAC;aACL,CAAC;QACN,CAAC,CAAC,CACkB,CAAC;IAC7B,CAAC;IAED,SAAS;QACL,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAA0B,CAAC;IAClE,CAAC;CACJ","sourcesContent":["import { entries } from \"../common/entries\";\nimport { memoize } from \"../common/memoize\";\nimport { Container, Factories } from \"./Container\";\nimport { AddService, InjectableFunction, ServicesFromTokenizedParams, ValidTokens } from \"./types\";\n\n// Using a conditional type forces TS language services to evaluate the type -- so when showing e.g. type hints, we\n// will see the mapped type instead of the AddDependencies type alias. This produces better hints.\ntype AddDependencies<ParentDependencies, Dependencies> = ParentDependencies extends any\n ? // A mapped type produces better, more concise type hints than an intersection type.\n {\n [K in keyof ParentDependencies | keyof Dependencies]: K extends keyof ParentDependencies\n ? ParentDependencies[K]\n : K extends keyof Dependencies\n ? Dependencies[K]\n : never;\n }\n : never;\n\ntype ExcludeKey<T, U> = T extends any ? { [K in Exclude<keyof T, U>]: T[K] } : never;\n\ntype PartialInjectableFunction<\n Params extends readonly any[],\n Tokens extends readonly string[],\n Token extends string,\n Service\n> = {\n (...args: Params): Service;\n token: Token;\n dependencies: Tokens;\n};\n\ntype Injectables<Services, Dependencies> = {\n [K in keyof Services]: K extends string\n ? InjectableFunction<Services & Dependencies, readonly ValidTokens<Services & Dependencies>[], K, Services[K]>\n : never;\n};\n\n/**\n * Similar to [Container], with the exception that Services may be provided to a PartialContainer which *does not*\n * contain all of that Services dependencies.\n *\n * For this to remain safe, Services can not be resolved by PartialContainer – it has no `get` method.\n *\n * Instead, the PartialContainer must be provided to a [Container] which *does* contain all the dependencies required\n * by all the Service in the PartialContainer. The resulting [Container] can then resolve these Services.\n *\n * PartialContainers are used to create a collection of Services which can then be provided via a simple one-line syntax\n * to an existing Container (which fulfills the collection's dependencies). It is an organizational tool, allowing\n * coherent groupings of Services to be defined in one place, then combined elsewhere to form a complete [Container].\n *\n * Here's an example of PartialContainer usage:\n * ```ts\n * // We can provide fooFactory, even though the PartialContainer doesn't fulfill the Bar dependency.\n * const fooFactory = Injectable('Foo', ['Bar'] as const, (bar: Bar) => new Foo(bar))\n * const partialContainer = new PartialContainer({}).provide(fooFactory)\n *\n * const barFactory = Injectable('Bar', () => new Bar())\n * const dependenciesContainer = Container.provides(barFactory)\n *\n * const combinedContainer = dependenciesContainer.provides(partialContainer)\n *\n * // We can resolve Foo, because the combined container includes Bar, so all of Foo's dependencies are now met.\n * const foo = combinedContainer.get('Foo')\n * ```\n */\n/** @internal */\nexport class PartialContainer<Services = {}, Dependencies = {}> {\n constructor(private readonly injectables: Injectables<Services, Dependencies>) {}\n\n /**\n * Create a new PartialContainer which provides a Service created by the given InjectableFunction.\n *\n * The InjectableFunction contains metadata specifying the Token by which the created Service will be known, as well\n * as an ordered list of Tokens to be resolved and provided to the InjectableFunction as arguments.\n *\n * This dependencies are allowed to be missing from the PartialContainer, but these dependencies are maintained as a\n * parameter of the returned PartialContainer. This allows `[Container.provides]` to type check the dependencies and\n * ensure they can be provided by the Container.\n *\n * @param fn A InjectableFunction, taking dependencies as arguments, which returns the Service.\n */\n provides<\n AdditionalDependencies extends readonly any[],\n Tokens extends readonly string[],\n Token extends string,\n Service\n >(\n fn: PartialInjectableFunction<AdditionalDependencies, Tokens, Token, Service>\n ): PartialContainer<\n AddService<Services, Token, Service>,\n // The dependencies of the new PartialContainer are the combined dependencies of this container and the\n // PartialInjectableFunction -- but we exclude any dependencies already provided by this container (i.e. this\n // container's Services) as well as the new Service being provided.\n ExcludeKey<\n AddDependencies<\n ExcludeKey<Dependencies, Token>,\n ServicesFromTokenizedParams<Tokens, AdditionalDependencies>\n >,\n keyof Services\n >\n > {\n return new PartialContainer({ ...this.injectables, [fn.token]: fn } as any);\n }\n\n /**\n * In order to create a [Container], the InjectableFunctions maintained by the PartialContainer must be memoized\n * into Factories that can resolve their dependencies and return the correct Service.\n *\n * In particular, this requires access to a \"parent\" Container to avoid infinite looping in cases where Service A\n * depends on Service A – this is allowed (as long as the parent container provides Service A), but requires access\n * to the parent Container to provide the parent implementation of Service A.\n *\n * This also means that Services provided by a PartialContainer to a Container via this function will always be\n * scoped to the Container. In other words, if a PartialContainer containing Service A is provided to both\n * Container X and Container Y, when Service A is resolved by Container X the InjectableFunction used to create\n * Service A will be invoked – and when Service A is resolved by Container Y, the InjectableFunction will be invoked\n * again.\n *\n * @param parent A [Container] which provides all the required Dependencies of this PartialContainer.\n */\n getFactories(parent: Container<Dependencies>): Factories<Services> {\n return Object.fromEntries(\n entries(this.injectables).map(([token, fn]) => {\n return [\n token,\n memoize((c: Container<Services & Dependencies>) => {\n return fn(\n ...(fn.dependencies.map((t) => {\n return t === token\n ? parent.get(t as keyof Dependencies)\n : c.get(t as keyof Services & Dependencies);\n }) as any)\n );\n }),\n ];\n })\n ) as Factories<Services>;\n }\n\n getTokens(): Array<keyof Services> {\n return Object.keys(this.injectables) as Array<keyof Services>;\n }\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { lensRepositoryFactory } from "../lens/LensRepository";
|
|
2
|
+
import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
|
|
3
|
+
import { remoteMediaAssetLoaderFactory } from "../lens/assets/remoteMediaAssetLoaderFactory";
|
|
4
|
+
import { deviceDependentAssetLoaderFactory } from "../lens/assets/deviceDependentAssetLoader";
|
|
5
|
+
import { staticAssetLoaderFactory } from "../lens/assets/staticAssetLoader";
|
|
6
|
+
import { defaultFetchHandlerFactory } from "../handlers/defaultFetchHandler";
|
|
7
|
+
import { cameraKitServiceFetchHandlerFactory } from "../handlers/cameraKitServiceFetchHandlerFactory";
|
|
8
|
+
import { createCameraKitConfigurationFactory } from "../configuration";
|
|
9
|
+
import { LensCoreModule } from "../lens-core-module/generated-types";
|
|
10
|
+
import { metricsEventTargetFactory } from "../metrics/metricsEventTarget";
|
|
11
|
+
import { metricsHandlerFactory } from "../metrics/metricsHandler";
|
|
12
|
+
import { operationalMetricReporterFactory } from "../metrics/operationalMetricsReporter";
|
|
13
|
+
import { lensSourcesFactory } from "../extensions/LensSources";
|
|
14
|
+
import { uriHandlersFactory } from "../extensions/UriHandlers";
|
|
15
|
+
import { lensPersistenceStoreFactory } from "../lens/LensPersistenceStore";
|
|
16
|
+
import { remoteConfigurationFactory } from "../remote-configuration/remoteConfiguration";
|
|
17
|
+
import { lensAssetRepositoryFactory } from "../lens/assets/LensAssetRepository";
|
|
18
|
+
import { legalStateFactory } from "../legal/legalState";
|
|
19
|
+
import { legalPromptFactory } from "../legal/legalPrompt";
|
|
20
|
+
import { logEntriesFactory } from "../logger/logEntries";
|
|
21
|
+
import { reportGlobalException } from "../metrics/reporters/reportGlobalException";
|
|
22
|
+
import { ServicesFromInjectables } from "./types";
|
|
23
|
+
/**
|
|
24
|
+
* All services available to be customized by client app.
|
|
25
|
+
*/
|
|
26
|
+
export declare type PublicServices = ServicesFromInjectables<[
|
|
27
|
+
ReturnType<typeof createCameraKitConfigurationFactory>,
|
|
28
|
+
typeof defaultFetchHandlerFactory,
|
|
29
|
+
typeof remoteMediaAssetLoaderFactory,
|
|
30
|
+
typeof lensSourcesFactory,
|
|
31
|
+
typeof uriHandlersFactory
|
|
32
|
+
]>;
|
|
33
|
+
/**
|
|
34
|
+
* Define all the Services contained in CameraKit's root dependency injection container.
|
|
35
|
+
*
|
|
36
|
+
* Note: we do end up defining this list of Services twice (once here to create the type, once when we actually
|
|
37
|
+
* create the Container inside the `bootstrapCameraKit` function). We could avoid doing this and just infer the
|
|
38
|
+
* RootContainer type from the constructed container – but since we can only do that *inside* `bootstrapCameraKit`, it
|
|
39
|
+
* makes it more awkward to provide a type for the `provide` user-supplied function (or use the type elsewhere, like in
|
|
40
|
+
* CameraKitSession).
|
|
41
|
+
*
|
|
42
|
+
* There may be a way to eliminate this extra boilerplate, but for now it's required in order to present a cleaner
|
|
43
|
+
* `bootstrapCameraKit` API to applications.
|
|
44
|
+
*/
|
|
45
|
+
export declare type RootServices = {
|
|
46
|
+
[lensCoreFactory.token]: LensCoreModule;
|
|
47
|
+
} & PublicServices & ServicesFromInjectables<[
|
|
48
|
+
typeof metricsEventTargetFactory,
|
|
49
|
+
typeof cameraKitServiceFetchHandlerFactory,
|
|
50
|
+
typeof remoteConfigurationFactory,
|
|
51
|
+
typeof lensRepositoryFactory,
|
|
52
|
+
typeof lensPersistenceStoreFactory,
|
|
53
|
+
typeof metricsHandlerFactory,
|
|
54
|
+
typeof operationalMetricReporterFactory,
|
|
55
|
+
typeof lensAssetRepositoryFactory,
|
|
56
|
+
typeof deviceDependentAssetLoaderFactory,
|
|
57
|
+
typeof staticAssetLoaderFactory,
|
|
58
|
+
typeof legalStateFactory,
|
|
59
|
+
typeof legalPromptFactory,
|
|
60
|
+
typeof logEntriesFactory,
|
|
61
|
+
typeof reportGlobalException
|
|
62
|
+
]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RootServices.js","sourceRoot":"","sources":["../../src/dependency-injection/RootServices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC","sourcesContent":["import { lensRepositoryFactory } from \"../lens/LensRepository\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { remoteMediaAssetLoaderFactory } from \"../lens/assets/remoteMediaAssetLoaderFactory\";\nimport { deviceDependentAssetLoaderFactory } from \"../lens/assets/deviceDependentAssetLoader\";\nimport { staticAssetLoaderFactory } from \"../lens/assets/staticAssetLoader\";\nimport { defaultFetchHandlerFactory } from \"../handlers/defaultFetchHandler\";\nimport { cameraKitServiceFetchHandlerFactory } from \"../handlers/cameraKitServiceFetchHandlerFactory\";\nimport { createCameraKitConfigurationFactory } from \"../configuration\";\nimport { LensCoreModule } from \"../lens-core-module/generated-types\";\nimport { metricsEventTargetFactory } from \"../metrics/metricsEventTarget\";\nimport { metricsHandlerFactory } from \"../metrics/metricsHandler\";\nimport { operationalMetricReporterFactory } from \"../metrics/operationalMetricsReporter\";\nimport { lensSourcesFactory } from \"../extensions/LensSources\";\nimport { uriHandlersFactory } from \"../extensions/UriHandlers\";\nimport { lensPersistenceStoreFactory } from \"../lens/LensPersistenceStore\";\nimport { remoteConfigurationFactory } from \"../remote-configuration/remoteConfiguration\";\nimport { lensAssetRepositoryFactory } from \"../lens/assets/LensAssetRepository\";\nimport { legalStateFactory } from \"../legal/legalState\";\nimport { legalPromptFactory } from \"../legal/legalPrompt\";\nimport { logEntriesFactory } from \"../logger/logEntries\";\nimport { reportGlobalException } from \"../metrics/reporters/reportGlobalException\";\nimport { ServicesFromInjectables } from \"./types\";\n\n/**\n * All services available to be customized by client app.\n */\nexport type PublicServices = ServicesFromInjectables<\n [\n ReturnType<typeof createCameraKitConfigurationFactory>,\n typeof defaultFetchHandlerFactory,\n typeof remoteMediaAssetLoaderFactory,\n typeof lensSourcesFactory,\n typeof uriHandlersFactory\n ]\n>;\n\n/**\n * Define all the Services contained in CameraKit's root dependency injection container.\n *\n * Note: we do end up defining this list of Services twice (once here to create the type, once when we actually\n * create the Container inside the `bootstrapCameraKit` function). We could avoid doing this and just infer the\n * RootContainer type from the constructed container – but since we can only do that *inside* `bootstrapCameraKit`, it\n * makes it more awkward to provide a type for the `provide` user-supplied function (or use the type elsewhere, like in\n * CameraKitSession).\n *\n * There may be a way to eliminate this extra boilerplate, but for now it's required in order to present a cleaner\n * `bootstrapCameraKit` API to applications.\n */\nexport type RootServices = {\n // bootstrapCameraKit replaces the lensCoreFactory token's value with the resolved LensCoreModule (rather than the\n // Promise of the LensCoreModule), so we need to do the same re-mapping here.\n [lensCoreFactory.token]: LensCoreModule;\n} & PublicServices &\n ServicesFromInjectables<\n [\n typeof metricsEventTargetFactory,\n typeof cameraKitServiceFetchHandlerFactory,\n typeof remoteConfigurationFactory,\n typeof lensRepositoryFactory,\n typeof lensPersistenceStoreFactory,\n typeof metricsHandlerFactory,\n typeof operationalMetricReporterFactory,\n typeof lensAssetRepositoryFactory,\n typeof deviceDependentAssetLoaderFactory,\n typeof staticAssetLoaderFactory,\n typeof legalStateFactory,\n typeof legalPromptFactory,\n typeof logEntriesFactory,\n typeof reportGlobalException\n ]\n >;\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Container, ContainerToken } from "./Container";
|
|
2
|
+
declare type AsTuple<T> = T extends readonly any[] ? T : never;
|
|
3
|
+
declare type CorrespondingService<Services, Token extends ValidTokens<Services>> = Token extends ContainerToken ? Container<Services> : Token extends keyof Services ? Services[Token] : never;
|
|
4
|
+
/**
|
|
5
|
+
* Given a Services object, the valid Tokens are simply the keys of that object or the special Container Token.
|
|
6
|
+
*/
|
|
7
|
+
export declare type ValidTokens<Services> = ContainerToken | keyof Services;
|
|
8
|
+
/**
|
|
9
|
+
* Given Services, map from a list of Tokens to a list of Service types.
|
|
10
|
+
*/
|
|
11
|
+
export declare type CorrespondingServices<Services, Tokens extends readonly ValidTokens<Services>[]> = {
|
|
12
|
+
[K in keyof Tokens]: Tokens[K] extends ValidTokens<Services> ? CorrespondingService<Services, Tokens[K]> : never;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A valid InjectableFunction is one that can be successfully called, given some Services, to return a new Service. That
|
|
16
|
+
* is, it must satisfy two conditions:
|
|
17
|
+
*
|
|
18
|
+
* 1. All the Tokens it specifies as dependencies are valid given the Services (i.e. they are either the Container
|
|
19
|
+
* Token or keys of the Services type).
|
|
20
|
+
* 2. The function argument types correspond to the Services specified by the dependency Tokens.
|
|
21
|
+
*
|
|
22
|
+
* A InjectableFunction also includes its own key Token and dependency Tokens as metadata, so it may be resolved by
|
|
23
|
+
* Container<Services> later.
|
|
24
|
+
*/
|
|
25
|
+
export declare type InjectableFunction<Services, Tokens, Token extends string, Service> = Tokens extends readonly ValidTokens<Services>[] ? {
|
|
26
|
+
(...args: AsTuple<CorrespondingServices<Services, Tokens>>): Service;
|
|
27
|
+
token: Token;
|
|
28
|
+
dependencies: Tokens;
|
|
29
|
+
} : never;
|
|
30
|
+
export declare type AnyInjectable = InjectableFunction<any, readonly string[], string, any>;
|
|
31
|
+
export declare type ServicesFromInjectables<Injectables extends readonly AnyInjectable[]> = {
|
|
32
|
+
[Name in Injectables[number]["token"]]: ReturnType<Extract<Injectables[number], {
|
|
33
|
+
token: Name;
|
|
34
|
+
}>>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Add a Service with a Token to an existing set of Services.
|
|
38
|
+
*/
|
|
39
|
+
export declare type AddService<ParentServices, Token extends string, Service> = ParentServices extends any ? {
|
|
40
|
+
[K in keyof ParentServices | Token]: K extends keyof ParentServices ? ParentServices[K] : Service;
|
|
41
|
+
} : never;
|
|
42
|
+
/**
|
|
43
|
+
* Create an object type from two tuples of the same length. The first tuple contains the object keys (strings) and the
|
|
44
|
+
* second contains the value types corresponding to those keys.
|
|
45
|
+
*
|
|
46
|
+
* Ex:
|
|
47
|
+
* ```ts
|
|
48
|
+
* type FooBar = ServicesFromTokenizedParams<['foo', 'bar'], [string, number]>
|
|
49
|
+
* const foobar: FooBar = {foo: 'foo', bar: 1}
|
|
50
|
+
* const badfoobar: FooBar = {foo: 1, bar: 'bar'} // any extra, missing, or mis-typed properties raise an error.
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare type ServicesFromTokenizedParams<Tokens, Params> = Tokens extends readonly [] ? Params extends readonly [] ? {} : never : Tokens extends readonly [infer Token, ...infer RemainingTokens] ? Params extends readonly [infer Param, ...infer RemainingParams] ? Tokens["length"] extends Params["length"] ? Token extends ContainerToken ? Param extends Container<infer S> ? S & ServicesFromTokenizedParams<RemainingTokens, RemainingParams> : never : Token extends string ? {
|
|
54
|
+
[K in Token]: Param extends Container<infer S> ? S : Param;
|
|
55
|
+
} & ServicesFromTokenizedParams<RemainingTokens, RemainingParams> : never : never : never : never;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/dependency-injection/types.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable import/exports-last */\nimport { Container, ContainerToken } from \"./Container\";\n\ntype AsTuple<T> = T extends readonly any[] ? T : never;\n\ntype CorrespondingService<Services, Token extends ValidTokens<Services>> = Token extends ContainerToken\n ? Container<Services>\n : Token extends keyof Services\n ? Services[Token]\n : never;\n\n/**\n * Given a Services object, the valid Tokens are simply the keys of that object or the special Container Token.\n */\nexport type ValidTokens<Services> = ContainerToken | keyof Services;\n\n/**\n * Given Services, map from a list of Tokens to a list of Service types.\n */\nexport type CorrespondingServices<Services, Tokens extends readonly ValidTokens<Services>[]> = {\n [K in keyof Tokens]: Tokens[K] extends ValidTokens<Services> ? CorrespondingService<Services, Tokens[K]> : never;\n};\n\n/**\n * A valid InjectableFunction is one that can be successfully called, given some Services, to return a new Service. That\n * is, it must satisfy two conditions:\n *\n * 1. All the Tokens it specifies as dependencies are valid given the Services (i.e. they are either the Container\n * Token or keys of the Services type).\n * 2. The function argument types correspond to the Services specified by the dependency Tokens.\n *\n * A InjectableFunction also includes its own key Token and dependency Tokens as metadata, so it may be resolved by\n * Container<Services> later.\n */\nexport type InjectableFunction<\n Services,\n Tokens,\n Token extends string,\n Service\n> = Tokens extends readonly ValidTokens<Services>[]\n ? {\n (...args: AsTuple<CorrespondingServices<Services, Tokens>>): Service;\n token: Token;\n dependencies: Tokens;\n }\n : never;\n\nexport type AnyInjectable = InjectableFunction<any, readonly string[], string, any>;\n\nexport type ServicesFromInjectables<Injectables extends readonly AnyInjectable[]> = {\n [Name in Injectables[number][\"token\"]]: ReturnType<Extract<Injectables[number], { token: Name }>>;\n};\n\n/**\n * Add a Service with a Token to an existing set of Services.\n */\n// Using a conditional type forces TS language services to evaluate the type -- so when showing e.g. type hints, we\n// will see the mapped type instead of the AddService type alias. This produces better hints.\nexport type AddService<ParentServices, Token extends string, Service> = ParentServices extends any\n ? // A mapped type produces better, more concise type hints than an intersection type.\n { [K in keyof ParentServices | Token]: K extends keyof ParentServices ? ParentServices[K] : Service }\n : never;\n\n/**\n * Create an object type from two tuples of the same length. The first tuple contains the object keys (strings) and the\n * second contains the value types corresponding to those keys.\n *\n * Ex:\n * ```ts\n * type FooBar = ServicesFromTokenizedParams<['foo', 'bar'], [string, number]>\n * const foobar: FooBar = {foo: 'foo', bar: 1}\n * const badfoobar: FooBar = {foo: 1, bar: 'bar'} // any extra, missing, or mis-typed properties raise an error.\n * ```\n */\nexport type ServicesFromTokenizedParams<Tokens, Params> = Tokens extends readonly []\n ? Params extends readonly []\n ? {}\n : never\n : Tokens extends readonly [infer Token, ...infer RemainingTokens]\n ? Params extends readonly [infer Param, ...infer RemainingParams]\n ? Tokens[\"length\"] extends Params[\"length\"]\n ? Token extends ContainerToken\n ? Param extends Container<infer S>\n ? S & ServicesFromTokenizedParams<RemainingTokens, RemainingParams>\n : never\n : Token extends string\n ? { [K in Token]: Param extends Container<infer S> ? S : Param } &\n ServicesFromTokenizedParams<RemainingTokens, RemainingParams>\n : never\n : never\n : never\n : never;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "PACKAGE_VERSION": "0.7.0-alpha.1" }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type EventOfType<K extends string, Event extends TypedCustomEvent> = Extract<Event, TypedCustomEvent<K, any>>;
|
|
2
|
+
/**
|
|
3
|
+
* This wrapper around CustomEvent provides more descriptive type information. By using this class, the `type` property
|
|
4
|
+
* of the CustomEvent will be typed as a string literal – this allows [TypedEventTarget] to provide more useful type
|
|
5
|
+
* checking of events.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TypedCustomEvent<N extends string = string, T = any> extends CustomEvent<T> {
|
|
8
|
+
readonly type: N;
|
|
9
|
+
constructor(type: N, detail: T, eventInitDict?: Omit<CustomEventInit<T>, "detail">);
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This wrapper around CustomEvent provides more descriptive type information. By using this class, the `type` property
|
|
3
|
+
* of the CustomEvent will be typed as a string literal – this allows [TypedEventTarget] to provide more useful type
|
|
4
|
+
* checking of events.
|
|
5
|
+
*/
|
|
6
|
+
export class TypedCustomEvent extends CustomEvent {
|
|
7
|
+
constructor(type, detail, eventInitDict = {}) {
|
|
8
|
+
super(type, Object.assign(Object.assign({}, eventInitDict), { detail }));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=TypedCustomEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedCustomEvent.js","sourceRoot":"","sources":["../../src/events/TypedCustomEvent.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,gBAAqD,SAAQ,WAAc;IAMpF,YAAY,IAAO,EAAE,MAAS,EAAE,gBAAoD,EAAE;QAClF,KAAK,CAAC,IAAI,kCAAO,aAAa,KAAE,MAAM,IAAG,CAAC;IAC9C,CAAC;CACJ","sourcesContent":["export type EventOfType<K extends string, Event extends TypedCustomEvent> = Extract<Event, TypedCustomEvent<K, any>>;\n\n/**\n * This wrapper around CustomEvent provides more descriptive type information. By using this class, the `type` property\n * of the CustomEvent will be typed as a string literal – this allows [TypedEventTarget] to provide more useful type\n * checking of events.\n */\nexport class TypedCustomEvent<N extends string = string, T = any> extends CustomEvent<T> {\n // @ts-ignore: The compiler complains that this property \"has no initializer and is not definitely set in the\n // constructor\" – we must rely on the superclass constructor to set this, because CustomEvent only implements a\n // getter for type, so if we try to do `this.type = type` we get a runtime error. We do need to re-define type,\n // though, so we can give it the specific type N instead of the less-useful string type defined by the superclass.\n readonly type: N;\n constructor(type: N, detail: T, eventInitDict: Omit<CustomEventInit<T>, \"detail\"> = {}) {\n super(type, { ...eventInitDict, detail });\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventOfType, TypedCustomEvent } from "./TypedCustomEvent";
|
|
2
|
+
export declare type TypedEventListener<Event extends TypedCustomEvent> = (evt: Event) => void;
|
|
3
|
+
export interface TypedEventListenerOptions {
|
|
4
|
+
once?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Extract the generic Events type (which must extend {@link TypedCustomEvent}) from a {@link TypedEventTarget}
|
|
8
|
+
*/
|
|
9
|
+
export declare type EventsFromTarget<Target extends TypedEventTarget> = Target extends TypedEventTarget<infer Events> ? Events : never;
|
|
10
|
+
/**
|
|
11
|
+
* This wrapper around EventTarget provides more descriptive type information. By using this class, calls to EventTarget
|
|
12
|
+
* methods are correctly type checked to ensure only allowed event types are used, and that events and their type
|
|
13
|
+
* strings are correctly associated.
|
|
14
|
+
*
|
|
15
|
+
* For example, when calling TypedEventTarget::addEventListener, the event passed to the callback will have the correct
|
|
16
|
+
* type corresponding to the type of event for which the listener has been added.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TypedEventTarget<Events extends TypedCustomEvent = TypedCustomEvent> {
|
|
19
|
+
private readonly listeners;
|
|
20
|
+
private readonly options;
|
|
21
|
+
constructor();
|
|
22
|
+
addEventListener<K extends Events["type"]>(type: K, callback: TypedEventListener<EventOfType<K, Events>>, options?: TypedEventListenerOptions): void;
|
|
23
|
+
dispatchEvent(event: Events): true;
|
|
24
|
+
removeEventListener<K extends Events["type"]>(type: K, callback: TypedEventListener<EventOfType<K, Events>>): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This wrapper around EventTarget provides more descriptive type information. By using this class, calls to EventTarget
|
|
3
|
+
* methods are correctly type checked to ensure only allowed event types are used, and that events and their type
|
|
4
|
+
* strings are correctly associated.
|
|
5
|
+
*
|
|
6
|
+
* For example, when calling TypedEventTarget::addEventListener, the event passed to the callback will have the correct
|
|
7
|
+
* type corresponding to the type of event for which the listener has been added.
|
|
8
|
+
*/
|
|
9
|
+
export class TypedEventTarget {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.listeners = new Map();
|
|
12
|
+
this.options = new Map();
|
|
13
|
+
}
|
|
14
|
+
addEventListener(type, callback, options) {
|
|
15
|
+
var _a;
|
|
16
|
+
// Safety: the type in the method signature ensures the callback handles events of type K, and we use that type
|
|
17
|
+
// as the key when storing the callback – we only ever invoke callbacks obtained by mapping from that event
|
|
18
|
+
// type to the callback, so even though we store the callback with a wider type, we only ever call it with the
|
|
19
|
+
// specific event type specified by K.
|
|
20
|
+
const listener = callback;
|
|
21
|
+
const listeners = (_a = this.listeners.get(type)) !== null && _a !== void 0 ? _a : [];
|
|
22
|
+
this.listeners.set(type, [...listeners, listener]);
|
|
23
|
+
if (options)
|
|
24
|
+
this.options.set(listener, options);
|
|
25
|
+
}
|
|
26
|
+
dispatchEvent(event) {
|
|
27
|
+
const listeners = this.listeners.get(event.type);
|
|
28
|
+
if (!listeners)
|
|
29
|
+
return true;
|
|
30
|
+
listeners.forEach((listener) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const options = (_a = this.options.get(listener)) !== null && _a !== void 0 ? _a : {};
|
|
33
|
+
try {
|
|
34
|
+
listener(event);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// We'll do our best to immitate native behavior, where if a listener throws an error it is caught and
|
|
38
|
+
// emitted as an error event on the window – this might be slightly different from native behavior since
|
|
39
|
+
// we have to use a CustomEvent, but it's as close as we can get.
|
|
40
|
+
if (window)
|
|
41
|
+
window.dispatchEvent(new CustomEvent("error", { detail: error }));
|
|
42
|
+
}
|
|
43
|
+
if (options.once)
|
|
44
|
+
this.removeEventListener(event.type, listener);
|
|
45
|
+
});
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
removeEventListener(type, callback) {
|
|
49
|
+
const listener = callback;
|
|
50
|
+
const listeners = this.listeners.get(type);
|
|
51
|
+
if (!listeners)
|
|
52
|
+
return;
|
|
53
|
+
this.listeners.set(type, listeners.filter((l) => l !== listener));
|
|
54
|
+
this.options.delete(listener);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=TypedEventTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedEventTarget.js","sourceRoot":"","sources":["../../src/events/TypedEventTarget.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IAIzB;QACI,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB,CACZ,IAAO,EACP,QAAoD,EACpD,OAAmC;;QAEnC,+GAA+G;QAC/G,2GAA2G;QAC3G,8GAA8G;QAC9G,sCAAsC;QACtC,MAAM,QAAQ,GAAG,QAAgD,CAAC;QAClE,MAAM,SAAS,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;QACnD,IAAI,OAAO;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,aAAa,CAAC,KAAa;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC;QAE5B,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;;YAC3B,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;YACjD,IAAI;gBACA,QAAQ,CAAC,KAAK,CAAC,CAAC;aACnB;YAAC,OAAO,KAAK,EAAE;gBACZ,sGAAsG;gBACtG,wGAAwG;gBACxG,iEAAiE;gBACjE,IAAI,MAAM;oBAAE,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;aACjF;YACD,IAAI,OAAO,CAAC,IAAI;gBAAE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,mBAAmB,CAA2B,IAAO,EAAE,QAAoD;QACvG,MAAM,QAAQ,GAAG,QAAgD,CAAC;QAClE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,SAAS;YAAE,OAAO;QACvB,IAAI,CAAC,SAAS,CAAC,GAAG,CACd,IAAI,EACJ,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAC1C,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;CACJ","sourcesContent":["import { EventOfType, TypedCustomEvent } from \"./TypedCustomEvent\";\n\nexport type TypedEventListener<Event extends TypedCustomEvent> = (evt: Event) => void;\n\nexport interface TypedEventListenerOptions {\n once?: boolean;\n}\n\n/**\n * Extract the generic Events type (which must extend {@link TypedCustomEvent}) from a {@link TypedEventTarget}\n */\nexport type EventsFromTarget<Target extends TypedEventTarget> = Target extends TypedEventTarget<infer Events>\n ? Events\n : never;\n\n/**\n * This wrapper around EventTarget provides more descriptive type information. By using this class, calls to EventTarget\n * methods are correctly type checked to ensure only allowed event types are used, and that events and their type\n * strings are correctly associated.\n *\n * For example, when calling TypedEventTarget::addEventListener, the event passed to the callback will have the correct\n * type corresponding to the type of event for which the listener has been added.\n */\nexport class TypedEventTarget<Events extends TypedCustomEvent = TypedCustomEvent> {\n private readonly listeners: Map<string, TypedEventListener<TypedCustomEvent>[]>;\n private readonly options: Map<TypedEventListener<TypedCustomEvent>, TypedEventListenerOptions>;\n\n constructor() {\n this.listeners = new Map();\n this.options = new Map();\n }\n\n addEventListener<K extends Events[\"type\"]>(\n type: K,\n callback: TypedEventListener<EventOfType<K, Events>>,\n options?: TypedEventListenerOptions\n ): void {\n // Safety: the type in the method signature ensures the callback handles events of type K, and we use that type\n // as the key when storing the callback – we only ever invoke callbacks obtained by mapping from that event\n // type to the callback, so even though we store the callback with a wider type, we only ever call it with the\n // specific event type specified by K.\n const listener = callback as TypedEventListener<TypedCustomEvent>;\n const listeners = this.listeners.get(type) ?? [];\n this.listeners.set(type, [...listeners, listener]);\n if (options) this.options.set(listener, options);\n }\n\n dispatchEvent(event: Events): true {\n const listeners = this.listeners.get(event.type);\n if (!listeners) return true;\n\n listeners.forEach((listener) => {\n const options = this.options.get(listener) ?? {};\n try {\n listener(event);\n } catch (error) {\n // We'll do our best to immitate native behavior, where if a listener throws an error it is caught and\n // emitted as an error event on the window – this might be slightly different from native behavior since\n // we have to use a CustomEvent, but it's as close as we can get.\n if (window) window.dispatchEvent(new CustomEvent(\"error\", { detail: error }));\n }\n if (options.once) this.removeEventListener(event.type, listener);\n });\n\n return true;\n }\n\n removeEventListener<K extends Events[\"type\"]>(type: K, callback: TypedEventListener<EventOfType<K, Events>>): void {\n const listener = callback as TypedEventListener<TypedCustomEvent>;\n const listeners = this.listeners.get(type);\n if (!listeners) return;\n this.listeners.set(\n type,\n listeners.filter((l) => l !== listener)\n );\n this.options.delete(listener);\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventOfType, TypedCustomEvent } from "./TypedCustomEvent";
|
|
2
|
+
import { EventsFromTarget, TypedEventTarget } from "./TypedEventTarget";
|
|
3
|
+
/**
|
|
4
|
+
* Each time an event is emitted, call a given accumulator function with two arguments: some state of type S and the
|
|
5
|
+
* event. The accumulator returns a new state. `scan` returns a new event emitter which emits an event each time a new
|
|
6
|
+
* state is produced by the accumulator.
|
|
7
|
+
*
|
|
8
|
+
* This can be used to implement a Redux-style state management architecture.
|
|
9
|
+
*
|
|
10
|
+
* @param seedState Some initial state, passed to the accumulator when the first event is emitted.
|
|
11
|
+
* @returns A function which takes a source {@link TypedEventTarget}, a list of event types emitted by that target to
|
|
12
|
+
* which to listen, and the accumulator function. The accumulator is called each time an event of the given type(s) is
|
|
13
|
+
* emitted on the source. It is passed the current state and the event, and must return a new state.
|
|
14
|
+
*/
|
|
15
|
+
export declare const scan: <S>(seedState: S) => <Target extends TypedEventTarget<TypedCustomEvent<string, any>>, Events extends EventsFromTarget<Target>, EventType extends Events["type"]>(source: Target, eventTypes: EventType[], accumulator: (state: S, event: Extract<Events, TypedCustomEvent<EventType, any>>) => S) => TypedEventTarget<TypedCustomEvent<"state", S>>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TypedCustomEvent } from "./TypedCustomEvent";
|
|
2
|
+
import { TypedEventTarget } from "./TypedEventTarget";
|
|
3
|
+
/**
|
|
4
|
+
* Each time an event is emitted, call a given accumulator function with two arguments: some state of type S and the
|
|
5
|
+
* event. The accumulator returns a new state. `scan` returns a new event emitter which emits an event each time a new
|
|
6
|
+
* state is produced by the accumulator.
|
|
7
|
+
*
|
|
8
|
+
* This can be used to implement a Redux-style state management architecture.
|
|
9
|
+
*
|
|
10
|
+
* @param seedState Some initial state, passed to the accumulator when the first event is emitted.
|
|
11
|
+
* @returns A function which takes a source {@link TypedEventTarget}, a list of event types emitted by that target to
|
|
12
|
+
* which to listen, and the accumulator function. The accumulator is called each time an event of the given type(s) is
|
|
13
|
+
* emitted on the source. It is passed the current state and the event, and must return a new state.
|
|
14
|
+
*/
|
|
15
|
+
export const scan = (seedState) => (source, eventTypes, accumulator) => {
|
|
16
|
+
let state = seedState;
|
|
17
|
+
const sink = new TypedEventTarget();
|
|
18
|
+
const listener = (event) => {
|
|
19
|
+
state = accumulator(state, event);
|
|
20
|
+
sink.dispatchEvent(new TypedCustomEvent("state", state));
|
|
21
|
+
};
|
|
22
|
+
// We'll use Proxies to make sure that event listeners are added/removed at the appropriate time. Callers can then
|
|
23
|
+
// control when to clean up the listeners we add here in a transparent way – by just removing the listener on the
|
|
24
|
+
// returned event target.
|
|
25
|
+
//
|
|
26
|
+
// We also prevent multiple listeners on the sink, as a simplification.
|
|
27
|
+
let hasListener = false;
|
|
28
|
+
sink.addEventListener = new Proxy(sink.addEventListener, {
|
|
29
|
+
apply: (target, thisArg, args) => {
|
|
30
|
+
if (hasListener)
|
|
31
|
+
throw new Error("Cannot addEventListener. The TypedEventTarget returned by scan only " +
|
|
32
|
+
"supports a single listener, and one has already been added.");
|
|
33
|
+
hasListener = true;
|
|
34
|
+
eventTypes.forEach((eventType) => source.addEventListener(eventType, listener));
|
|
35
|
+
target.apply(thisArg, args);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
sink.removeEventListener = new Proxy(sink.removeEventListener, {
|
|
39
|
+
apply: (target, thisArg, args) => {
|
|
40
|
+
eventTypes.forEach((eventType) => source.removeEventListener(eventType, listener));
|
|
41
|
+
target.apply(thisArg, args);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return sink;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/events/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAoB,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAI,SAAY,EAAE,EAAE,CAAC,CAKrC,MAAc,EACd,UAAuB,EACvB,WAAmE,EACrB,EAAE;IAChD,IAAI,KAAK,GAAG,SAAS,CAAC;IACtB,MAAM,IAAI,GAAG,IAAI,gBAAgB,EAAgC,CAAC;IAClE,MAAM,QAAQ,GAAG,CAAC,KAAuB,EAAE,EAAE;QACzC,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAuC,CAAC,CAAC;QACpE,IAAI,CAAC,aAAa,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC;IAEF,kHAAkH;IAClH,iHAAiH;IACjH,yBAAyB;IACzB,EAAE;IACF,uEAAuE;IACvE,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,CAAC,gBAAgB,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE;QACrD,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,IAAiD,EAAE,EAAE;YAC1E,IAAI,WAAW;gBACX,MAAM,IAAI,KAAK,CACX,sEAAsE;oBAClE,6DAA6D,CACpE,CAAC;YACN,WAAW,GAAG,IAAI,CAAC;YACnB,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;YAChF,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;KACJ,CAAC,CAAC;IACH,IAAI,CAAC,mBAAmB,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE;QAC3D,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,IAAoD,EAAE,EAAE;YAC7E,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;YACnF,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;KACJ,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { EventOfType, TypedCustomEvent } from \"./TypedCustomEvent\";\nimport { EventsFromTarget, TypedEventTarget } from \"./TypedEventTarget\";\n\n/**\n * Each time an event is emitted, call a given accumulator function with two arguments: some state of type S and the\n * event. The accumulator returns a new state. `scan` returns a new event emitter which emits an event each time a new\n * state is produced by the accumulator.\n *\n * This can be used to implement a Redux-style state management architecture.\n *\n * @param seedState Some initial state, passed to the accumulator when the first event is emitted.\n * @returns A function which takes a source {@link TypedEventTarget}, a list of event types emitted by that target to\n * which to listen, and the accumulator function. The accumulator is called each time an event of the given type(s) is\n * emitted on the source. It is passed the current state and the event, and must return a new state.\n */\nexport const scan = <S>(seedState: S) => <\n Target extends TypedEventTarget,\n Events extends EventsFromTarget<Target>,\n EventType extends Events[\"type\"]\n>(\n source: Target,\n eventTypes: EventType[],\n accumulator: (state: S, event: EventOfType<EventType, Events>) => S\n): TypedEventTarget<TypedCustomEvent<\"state\", S>> => {\n let state = seedState;\n const sink = new TypedEventTarget<TypedCustomEvent<\"state\", S>>();\n const listener = (event: TypedCustomEvent) => {\n state = accumulator(state, event as EventOfType<EventType, Events>);\n sink.dispatchEvent(new TypedCustomEvent(\"state\", state));\n };\n\n // We'll use Proxies to make sure that event listeners are added/removed at the appropriate time. Callers can then\n // control when to clean up the listeners we add here in a transparent way – by just removing the listener on the\n // returned event target.\n //\n // We also prevent multiple listeners on the sink, as a simplification.\n let hasListener = false;\n sink.addEventListener = new Proxy(sink.addEventListener, {\n apply: (target, thisArg, args: Parameters<typeof sink[\"addEventListener\"]>) => {\n if (hasListener)\n throw new Error(\n \"Cannot addEventListener. The TypedEventTarget returned by scan only \" +\n \"supports a single listener, and one has already been added.\"\n );\n hasListener = true;\n eventTypes.forEach((eventType) => source.addEventListener(eventType, listener));\n target.apply(thisArg, args);\n },\n });\n sink.removeEventListener = new Proxy(sink.removeEventListener, {\n apply: (target, thisArg, args: Parameters<typeof sink[\"removeEventListener\"]>) => {\n eventTypes.forEach((eventType) => source.removeEventListener(eventType, listener));\n target.apply(thisArg, args);\n },\n });\n\n return sink;\n};\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A source of a lens group.
|
|
3
|
+
*/
|
|
4
|
+
export interface LensSource {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the given source is able to load lenses of the supplied group.
|
|
7
|
+
* @param groupId Group ID to check.
|
|
8
|
+
*/
|
|
9
|
+
isGroupOwner(groupId: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns an encoded lens object.
|
|
12
|
+
* @param lensId Lens ID to get.
|
|
13
|
+
* @param groupId Group ID the lens belongs to.
|
|
14
|
+
*/
|
|
15
|
+
getLens(lensId: string, groupId: string): Promise<ArrayBuffer>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns encoded lens objects.
|
|
18
|
+
* @param groupId Group ID to get lenses of.
|
|
19
|
+
*/
|
|
20
|
+
getLensGroup(groupId: string): Promise<ArrayBuffer[]>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A chain of {@link LensSource} objects to be registered in Camera Kit on bootstrap. Camera Kit evaluates all
|
|
24
|
+
* registered {@link LensSource} objects for a group ownership during Lens retrieval ({@link CameraKit.lenses}).
|
|
25
|
+
* And if a source claims the ownership, its {@link LensSource.getLens} or {@link LensSource.getLensGroup}
|
|
26
|
+
* methods are called.
|
|
27
|
+
*/
|
|
28
|
+
export declare class LensSources {
|
|
29
|
+
private readonly fallbackSources;
|
|
30
|
+
private readonly source;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an instance of Lens sources.
|
|
33
|
+
* @param fallbackSources A fallback sources if given {@link LensSource} doesn't claim a group ownership.
|
|
34
|
+
* @param source Lens source.
|
|
35
|
+
*/
|
|
36
|
+
constructor(fallbackSources: LensSources, source: LensSource);
|
|
37
|
+
/**
|
|
38
|
+
* Returns empty LensSources instance.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
static empty(): LensSources;
|
|
42
|
+
/**
|
|
43
|
+
* Returns envelopes of lens/groups taking into account group ownership.
|
|
44
|
+
* @internal
|
|
45
|
+
* @param groupId A group to test ownership and get lens envelopes of.
|
|
46
|
+
* @param lensId An optional lens ID to narrow envelopes down to a single lens.
|
|
47
|
+
* @returns Envelopes or undefined if not applicable.
|
|
48
|
+
*/
|
|
49
|
+
retrieveLenses({ groupId, lensId }: {
|
|
50
|
+
groupId: string;
|
|
51
|
+
lensId?: string;
|
|
52
|
+
}): Promise<ArrayBuffer[] | void>;
|
|
53
|
+
}
|
|
54
|
+
export declare const lensSourcesFactory: {
|
|
55
|
+
(): LensSources;
|
|
56
|
+
token: "lensSources";
|
|
57
|
+
dependencies: [];
|
|
58
|
+
};
|