@snap/camera-kit 0.14.1 → 0.15.1
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 +5921 -1485
- package/README.md +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +7 -7
- package/docs/html/classes/CameraKitSession.html +17 -25
- package/docs/html/classes/CameraKitSource.html +15 -10
- package/docs/html/classes/LensPerformanceMeasurement.html +7 -7
- package/docs/html/classes/LensPerformanceMetrics.html +7 -7
- package/docs/html/classes/LensRepository.html +7 -7
- package/docs/html/classes/Transform2D.html +7 -7
- package/docs/html/classes/TypedCustomEvent.html +7 -7
- package/docs/html/classes/TypedEventTarget.html +7 -7
- package/docs/html/functions/ConcatInjectable.html +202 -0
- package/docs/html/functions/Injectable.html +15 -16
- package/docs/html/functions/bootstrapCameraKit.html +7 -7
- package/docs/html/functions/createExtension.html +7 -7
- package/docs/html/functions/createImageSource.html +7 -7
- package/docs/html/functions/createMediaStreamSource.html +7 -7
- package/docs/html/functions/createUserMediaSource.html +7 -7
- package/docs/html/functions/createVideoSource.html +7 -7
- package/docs/html/functions/estimateLensPerformance.html +7 -7
- package/docs/html/functions/getRequiredBootstrapURLs.html +7 -7
- package/docs/html/functions/lensSourcesFactory.html +17 -9
- package/docs/html/functions/remoteApiServicesFactory.html +7 -7
- package/docs/html/index.html +9 -9
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +7 -7
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +7 -7
- package/docs/html/interfaces/ComputedFrameMetrics.html +7 -7
- package/docs/html/interfaces/CreateSessionOptions.html +7 -7
- package/docs/html/interfaces/EstimatedLensPerformance.html +7 -7
- package/docs/html/interfaces/Lens.html +7 -7
- package/docs/html/interfaces/LensLaunchData.html +183 -0
- package/docs/html/interfaces/LensSource.html +28 -46
- package/docs/html/interfaces/MediaStreamSourceOptions.html +7 -7
- package/docs/html/interfaces/Preview.html +7 -7
- package/docs/html/interfaces/RemoteApiRequest.html +7 -7
- package/docs/html/interfaces/RemoteApiResponse.html +7 -7
- package/docs/html/interfaces/RemoteApiService.html +7 -7
- package/docs/html/interfaces/Snapcode.html +7 -7
- package/docs/html/interfaces/UriCancelRequest.html +7 -7
- package/docs/html/interfaces/UriRequest.html +7 -7
- package/docs/html/interfaces/UriResponse.html +7 -7
- package/docs/html/interfaces/VideoSourceOptions.html +7 -7
- package/docs/html/modules.html +12 -12
- package/docs/html/types/AssetLoader.html +7 -7
- package/docs/html/types/AssetTiming.html +7 -7
- package/docs/html/types/BenchmarkError.html +7 -7
- package/docs/html/types/BootstrapError.html +7 -7
- package/docs/html/types/CacheKeyNotFoundError.html +7 -7
- package/docs/html/types/CameraKitDeviceInfo.html +7 -7
- package/docs/html/types/CameraKitDeviceOptions.html +7 -7
- package/docs/html/types/CameraKitSessionEventListener.html +7 -7
- package/docs/html/types/CameraKitSessionEvents.html +7 -7
- package/docs/html/types/CameraKitSourceError.html +7 -7
- package/docs/html/types/CameraKitSourceInfo.html +7 -7
- package/docs/html/types/CameraKitSourceOptions.html +7 -7
- package/docs/html/types/ConfigurationError.html +7 -7
- package/docs/html/types/Keyboard.html +7 -7
- package/docs/html/types/KeyboardEvents.html +7 -7
- package/docs/html/types/LegalError.html +7 -7
- package/docs/html/types/LensAbortError.html +7 -7
- package/docs/html/types/LensAssetError.html +7 -7
- package/docs/html/types/LensContentValidationError.html +7 -7
- package/docs/html/types/LensError.html +7 -7
- package/docs/html/types/LensExecutionError.html +7 -7
- package/docs/html/types/LensImagePickerError.html +7 -7
- package/docs/html/types/LensMetricsEvents.html +7 -7
- package/docs/html/types/LensPerformanceCluster.html +7 -7
- package/docs/html/types/LensView.html +7 -7
- package/docs/html/types/LensWait.html +7 -7
- package/docs/html/types/PersistentStoreError.html +7 -7
- package/docs/html/types/PlatformNotSupportedError.html +7 -7
- package/docs/html/types/PublicContainer.html +7 -7
- package/docs/html/types/RemoteApiRequestHandler.html +7 -7
- package/docs/html/types/RemoteApiServices.html +7 -7
- package/docs/html/types/RemoteApiStatus.html +7 -7
- package/docs/html/types/RenderTarget.html +7 -7
- package/docs/html/types/Uri.html +7 -7
- package/docs/html/types/WebGLError.html +7 -7
- package/docs/html/variables/extensionRequestContext.html +7 -7
- package/docs/md/README.md +1 -1
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +11 -22
- package/docs/md/classes/CameraKitSource.md +11 -5
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +1 -1
- package/docs/md/classes/Transform2D.md +1 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +1 -1
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
- package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
- package/docs/md/interfaces/CreateSessionOptions.md +1 -1
- package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
- package/docs/md/interfaces/Lens.md +1 -1
- package/docs/md/interfaces/LensLaunchData.md +53 -0
- package/docs/md/interfaces/LensSource.md +23 -25
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/Preview.md +1 -1
- package/docs/md/interfaces/RemoteApiRequest.md +1 -1
- package/docs/md/interfaces/RemoteApiResponse.md +1 -1
- package/docs/md/interfaces/RemoteApiService.md +1 -1
- package/docs/md/interfaces/Snapcode.md +1 -1
- package/docs/md/interfaces/UriCancelRequest.md +1 -1
- package/docs/md/interfaces/UriRequest.md +1 -1
- package/docs/md/interfaces/UriResponse.md +1 -1
- package/docs/md/interfaces/VideoSourceOptions.md +1 -1
- package/docs/md/modules.md +125 -28
- package/lib/CameraKit.d.ts +14 -6
- package/lib/__tests__/data.d.ts +2 -2
- package/lib/__tests__/data.js +2 -2
- package/lib/__tests__/data.js.map +1 -1
- package/lib/bootstrapCameraKit.js +12 -3
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/clients/createTsProtoClient.d.ts +47 -0
- package/lib/clients/createTsProtoClient.js +53 -0
- package/lib/clients/createTsProtoClient.js.map +1 -0
- package/lib/clients/grpcHandler.d.ts +23 -0
- package/lib/clients/grpcHandler.js +87 -0
- package/lib/clients/grpcHandler.js.map +1 -0
- package/lib/clients/lensesClient.d.ts +9 -0
- package/lib/clients/lensesClient.js +6 -0
- package/lib/clients/lensesClient.js.map +1 -0
- package/lib/common/entries.d.ts +1 -0
- package/lib/common/entries.js +2 -0
- package/lib/common/entries.js.map +1 -1
- package/lib/common/result.d.ts +36 -0
- package/lib/common/result.js +40 -0
- package/lib/common/result.js.map +1 -0
- package/lib/common/unionBy.d.ts +28 -0
- package/lib/common/unionBy.js +46 -0
- package/lib/common/unionBy.js.map +1 -0
- package/lib/configuration.js +14 -1
- package/lib/configuration.js.map +1 -1
- package/lib/dependency-injection/Injectable.d.ts +67 -11
- package/lib/dependency-injection/Injectable.js +21 -2
- package/lib/dependency-injection/Injectable.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +5 -1
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/extensions/RemoteApiServices.d.ts +1 -1
- package/lib/extensions/RemoteApiServices.js +7 -7
- package/lib/extensions/RemoteApiServices.js.map +1 -1
- package/lib/extensions/uriHandlersRegister.d.ts +6 -6
- package/lib/extensions/uriHandlersRegister.js +1 -1
- package/lib/extensions/uriHandlersRegister.js.map +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +15 -17
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +62 -69
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +6 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +68 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +5 -6
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +11 -25
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +19 -14
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +145 -64
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +2 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +30 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +15 -16
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +36 -62
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +1294 -12
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +200 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +4 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +39 -45
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +74 -192
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -1
- package/lib/handlers/defaultFetchHandler.js +1 -5
- package/lib/handlers/defaultFetchHandler.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -6
- package/lib/index.js.map +1 -1
- package/lib/lens/Lens.d.ts +2 -12
- package/lib/lens/Lens.js +2 -2
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensLaunchData.d.ts +37 -0
- package/lib/lens/LensLaunchData.js +35 -0
- package/lib/lens/LensLaunchData.js.map +1 -0
- package/lib/lens/LensRepository.d.ts +4 -7
- package/lib/lens/LensRepository.js +24 -35
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/LensSource.d.ts +43 -0
- package/lib/lens/LensSource.js +42 -0
- package/lib/lens/LensSource.js.map +1 -0
- package/lib/lens/assets/LensAssetRepository.js +2 -4
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
- package/lib/lens/cameraKitLensSource.d.ts +16 -0
- package/lib/lens/cameraKitLensSource.js +59 -0
- package/lib/lens/cameraKitLensSource.js.map +1 -0
- package/lib/lens-core-module/lensCore.d.ts +2 -1
- package/lib/lens-core-module/lensCore.js +6 -1
- package/lib/lens-core-module/lensCore.js.map +1 -1
- package/lib/lens-core-module/lensCoreError.js +1 -1
- package/lib/lens-core-module/lensCoreError.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/media-sources/CameraKitSource.d.ts +10 -4
- package/lib/media-sources/CameraKitSource.js +11 -4
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/ImageSource.js +1 -11
- package/lib/media-sources/ImageSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.js +1 -5
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/media-sources/VideoSource.js +1 -11
- package/lib/media-sources/VideoSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.js +1 -1
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/reporters/reportGlobalException.d.ts +7 -0
- package/lib/metrics/reporters/reportGlobalException.js +22 -4
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.js +14 -0
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +1 -1
- package/lib/metrics/reporters/reportSessionException.d.ts +1 -1
- package/lib/metrics/reporters/reporters.d.ts +1 -1
- package/lib/persistence/ExpiringPersistence.js +3 -4
- package/lib/persistence/ExpiringPersistence.js.map +1 -1
- package/lib/platform/platformInfo.js +1 -1
- package/lib/platform/platformInfo.js.map +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +1 -0
- package/lib/remote-configuration/cofHandler.js +61 -50
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +9 -11
- package/lib/session/CameraKitSession.js +22 -18
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/CameraKitSessionEvents.d.ts +1 -1
- package/lib/session/CameraKitSessionEvents.js.map +1 -1
- package/lib/session/LensKeyboard.d.ts +7 -1
- package/lib/session/lensState.d.ts +3 -3
- package/lib/session/lensState.js +40 -15
- package/lib/session/lensState.js.map +1 -1
- package/package.json +2 -2
- package/docs/html/classes/LensSources.html +0 -160
- package/docs/html/types/LensLaunchParams.html +0 -115
- package/docs/md/classes/LensSources.md +0 -29
- package/lib/common/any.d.ts +0 -19
- package/lib/common/any.js +0 -53
- package/lib/common/any.js.map +0 -1
- package/lib/extensions/LensSources.d.ts +0 -58
- package/lib/extensions/LensSources.js +0 -54
- package/lib/extensions/LensSources.js.map +0 -1
- package/lib/lens/LensLaunchParams.d.ts +0 -19
- package/lib/lens/LensLaunchParams.js +0 -40
- package/lib/lens/LensLaunchParams.js.map +0 -1
- package/lib/lens/index.d.ts +0 -7
- package/lib/lens/index.js +0 -7
- package/lib/lens/index.js.map +0 -1
- package/lib/lens/lensEnvelopeUtil.d.ts +0 -5
- package/lib/lens/lensEnvelopeUtil.js +0 -19
- package/lib/lens/lensEnvelopeUtil.js.map +0 -1
- package/lib/lens/lensHttpUtil.d.ts +0 -5
- package/lib/lens/lensHttpUtil.js +0 -52
- package/lib/lens/lensHttpUtil.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTsProtoClient.js","sourceRoot":"","sources":["../../src/clients/createTsProtoClient.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA8CzD,SAAS,YAAY,CAAI,OAA0B,EAAE,IAAO;IACxD,OAAO,MAAM,OAAO;QAChB;YACI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,CAAC,iBAAiB,CAAC,IAAgB;YACrC,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAC;YACtC,OAAO,gCAAK,eAAe,GAAK,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAa,CAAC;QACtE,CAAC;QAED,eAAe;YACX,OAAO,OAAO,CAAC,MAAM,CAAC,IAAW,CAAC,CAAC,MAAM,EAAE,CAAC;QAChD,CAAC;QACD,QAAQ;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;KACJ,CAAC;AACN,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAC/B,iBAAoB,EACpB,OAAoB;IAEpB,OAAO,WAAW,CACd,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,gBAAgB,CAAC,EAAE,EAAE;QACtE,OAAO;YACH,UAAU;YACV,CAAO,OAAgB,EAAE,EAAE;gBACvB,MAAM,WAAW,GAAG,YAAY,CAAC,gBAAgB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBACxE,MAAM,YAAY,GAAG,YAAY,CAAC,gBAAgB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBACrE,OAAO,OAAO,CAAC;oBACX,WAAW,EAAE,iBAAiB,CAAC,QAAQ;oBACvC,UAAU,EAAE,gBAAgB,CAAC,IAAI;oBACjC,WAAW;oBACX,YAAY;iBACf,CAAC,CAAC;YACP,CAAC,CAAA;SACJ,CAAC;QACF,yGAAyG;QACzG,8FAA8F;QAC9F,kGAAkG;QAClG,sGAAsG;QACtG,iFAAiF;IACrF,CAAC,CAAC,CACmB,CAAC;AAC9B,CAAC","sourcesContent":["import { grpc } from \"@improbable-eng/grpc-web\";\nimport { Writer } from \"protobufjs\";\nimport { entries, fromEntries } from \"../common/entries\";\nimport { Exact, DeepPartial } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport { Result } from \"../common/result\";\nimport { GrpcHandler } from \"./grpcHandler\";\n\ntype TsProtoServiceDefinition<Methods extends TsProtoMethods> = {\n name: string;\n fullName: string;\n methods: Methods;\n};\n\ntype TsProtoMethods = { [methodName: string]: TsProtoMethodDefinition<any, any> };\n\ntype TsProtoMethodDefinition<Request, Response> = {\n name: string;\n requestType: TsProtoMessage<Request>;\n responseType: TsProtoMessage<Response>;\n};\n\ntype TsProtoMessage<M> = {\n encode: (message: M) => Writer;\n decode: (message: Uint8Array) => M;\n fromPartial: (partialMessage: any) => M;\n};\n\nexport type GrpcServiceClient<S extends TsProtoServiceDefinition<any>> = {\n [MethodName in keyof S[\"methods\"]]: InferGrpcMethod<S[\"methods\"][MethodName]>;\n};\n\ninterface UnaryOutput<M> {\n status: grpc.Code;\n statusMessage: string;\n headers: grpc.Metadata;\n message: M | null;\n trailers: grpc.Metadata;\n}\n\ntype InferGrpcMethod<M extends TsProtoMethodDefinition<any, any>> = M extends TsProtoMethodDefinition<\n infer Request,\n infer Response\n>\n ? <I extends Exact<DeepPartial<Request>, I>>(\n request: I\n ) => Promise<Result<UnaryOutput<Response & grpc.ProtobufMessage>, UnaryOutput<Response & grpc.ProtobufMessage>>>\n : never;\n\nfunction messageClass<M>(message: TsProtoMessage<M>, data: M): grpc.ProtobufMessageClass<grpc.ProtobufMessage> {\n return class Message implements grpc.ProtobufMessage {\n constructor() {\n Object.assign(this, message.fromPartial(data));\n }\n\n static deserializeBinary(data: Uint8Array): Message {\n const protobufMessage = new Message();\n return { ...protobufMessage, ...message.decode(data) } as Message;\n }\n\n serializeBinary(): Uint8Array {\n return message.encode(this as any).finish();\n }\n toObject(): this {\n return this;\n }\n };\n}\n\n/**\n * Convert a service definition generated by ts-proto (using the `outputServices=generic-definitions` CLI option) into\n * a working client.\n *\n * @param serviceDefinition\n * @param handler\n * @returns A client that can make requests to a remote service by sending Protobuf-encoded messages over HTTP using the\n * grpc-web package.\n *\n * @internal\n */\nexport function createTsProtoClient<Methods extends TsProtoMethods, S extends TsProtoServiceDefinition<Methods>>(\n serviceDefinition: S,\n handler: GrpcHandler\n): GrpcServiceClient<S> {\n return fromEntries(\n entries(serviceDefinition.methods).map(([methodName, methodDefinition]) => {\n return [\n methodName,\n async (request: unknown) => {\n const requestType = messageClass(methodDefinition.requestType, request);\n const responseType = messageClass(methodDefinition.responseType, {});\n return handler({\n serviceName: serviceDefinition.fullName,\n methodName: methodDefinition.name,\n requestType,\n responseType,\n });\n },\n ];\n // Safety: We're mapping from the method definitions object into the GrpcServiceClient object in a manner\n // that preserves each key in the method definitions object, pairing it with the corresponding\n // serialization/deserialization logic for that particular method. But in doing this, we lose type\n // specificity by converting the method definition object to a list of entries, mapping them, and then\n // converting back into the client object -- so we're forced into this type cast.\n })\n ) as GrpcServiceClient<S>;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { grpc } from "@improbable-eng/grpc-web";
|
|
2
|
+
import { Handler, RequestMetadata } from "../handlers/HandlerChainBuilder";
|
|
3
|
+
import { CameraKitConfiguration } from "../configuration";
|
|
4
|
+
import { Result } from "../common/result";
|
|
5
|
+
import { FetchHandler } from "../handlers";
|
|
6
|
+
export interface GrpcRequest {
|
|
7
|
+
serviceName: string;
|
|
8
|
+
methodName: string;
|
|
9
|
+
requestType: grpc.ProtobufMessageClass<grpc.ProtobufMessage>;
|
|
10
|
+
responseType: grpc.ProtobufMessageClass<grpc.ProtobufMessage>;
|
|
11
|
+
}
|
|
12
|
+
export type GrpcHandler = Handler<GrpcRequest, Result<grpc.UnaryOutput<grpc.ProtobufMessage>, grpc.UnaryOutput<grpc.ProtobufMessage>>, RequestMetadata>;
|
|
13
|
+
/**
|
|
14
|
+
* An Injectable handler that can make requests to the CameraKit backend service via grpc-web. This handler can be
|
|
15
|
+
* passed to {@link createTsProtoClient} to produce a well-typed service client.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const gprcHandlerFactory: {
|
|
20
|
+
(args_0: CameraKitConfiguration, args_1: FetchHandler): GrpcHandler;
|
|
21
|
+
token: "grpcHandler";
|
|
22
|
+
dependencies: readonly ["configuration", "cameraKitServiceFetchHandler"];
|
|
23
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { grpc } from "@improbable-eng/grpc-web";
|
|
3
|
+
import { Injectable } from "../dependency-injection/Injectable";
|
|
4
|
+
import { configurationToken } from "../configuration";
|
|
5
|
+
import { Err, Ok } from "../common/result";
|
|
6
|
+
import { cameraKitServiceFetchHandlerFactory } from "../handlers";
|
|
7
|
+
/**
|
|
8
|
+
* An Injectable handler that can make requests to the CameraKit backend service via grpc-web. This handler can be
|
|
9
|
+
* passed to {@link createTsProtoClient} to produce a well-typed service client.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export const gprcHandlerFactory = Injectable("grpcHandler", [configurationToken, cameraKitServiceFetchHandlerFactory.token], (configuration, fetchHandler) => {
|
|
14
|
+
const host = `https://${configuration.apiHostname}`;
|
|
15
|
+
// We define our own Transport so that we can use our custom `fetch` implementation. This is important for two
|
|
16
|
+
// reasons:
|
|
17
|
+
// 1. Our custom fetch includes features like retries that we want to use for these requests.
|
|
18
|
+
// 2. Applications may override this fetch implementation (via our DI system) to support more advanced
|
|
19
|
+
// use-cases.
|
|
20
|
+
const transport = (options) => {
|
|
21
|
+
let metadata = undefined;
|
|
22
|
+
const controller = AbortController ? new AbortController() : undefined;
|
|
23
|
+
let cancelled = false;
|
|
24
|
+
return {
|
|
25
|
+
sendMessage(msgBytes) {
|
|
26
|
+
var _a;
|
|
27
|
+
fetchHandler(options.url, {
|
|
28
|
+
headers: (_a = metadata === null || metadata === void 0 ? void 0 : metadata.toHeaders()) !== null && _a !== void 0 ? _a : {},
|
|
29
|
+
method: "POST",
|
|
30
|
+
body: msgBytes,
|
|
31
|
+
signal: controller === null || controller === void 0 ? void 0 : controller.signal,
|
|
32
|
+
})
|
|
33
|
+
.then((response) => {
|
|
34
|
+
options.onHeaders(new grpc.Metadata(response.headers), response.status);
|
|
35
|
+
return response.arrayBuffer();
|
|
36
|
+
})
|
|
37
|
+
.then((body) => {
|
|
38
|
+
if (cancelled)
|
|
39
|
+
return;
|
|
40
|
+
options.onChunk(new Uint8Array(body));
|
|
41
|
+
options.onEnd();
|
|
42
|
+
})
|
|
43
|
+
.catch((error) => {
|
|
44
|
+
if (cancelled)
|
|
45
|
+
return;
|
|
46
|
+
cancelled = true;
|
|
47
|
+
options.onEnd(error);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
start(m) {
|
|
51
|
+
metadata = m;
|
|
52
|
+
},
|
|
53
|
+
finishSend() { },
|
|
54
|
+
cancel() {
|
|
55
|
+
if (cancelled)
|
|
56
|
+
return;
|
|
57
|
+
cancelled = true;
|
|
58
|
+
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
return (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
grpc.unary({
|
|
65
|
+
methodName: request.methodName,
|
|
66
|
+
service: { serviceName: request.serviceName },
|
|
67
|
+
requestStream: false,
|
|
68
|
+
responseStream: false,
|
|
69
|
+
requestType: request.requestType,
|
|
70
|
+
responseType: request.responseType,
|
|
71
|
+
}, {
|
|
72
|
+
request: new request.requestType(),
|
|
73
|
+
host,
|
|
74
|
+
onEnd: (response) => {
|
|
75
|
+
if (response.status === grpc.Code.OK) {
|
|
76
|
+
resolve(Ok(response));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
resolve(Err(response));
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
transport,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=grpcHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpcHandler.js","sourceRoot":"","sources":["../../src/clients/grpcHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAA0B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAgB,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAehF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CACxC,aAAa,EACb,CAAC,kBAAkB,EAAE,mCAAmC,CAAC,KAAK,CAAC,EAC/D,CAAC,aAAqC,EAAE,YAA0B,EAAe,EAAE;IAC/E,MAAM,IAAI,GAAG,WAAW,aAAa,CAAC,WAAW,EAAE,CAAC;IAEpD,8GAA8G;IAC9G,WAAW;IACX,+FAA+F;IAC/F,wGAAwG;IACxG,kBAAkB;IAClB,MAAM,SAAS,GAA0B,CAAC,OAAO,EAAE,EAAE;QACjD,IAAI,QAAQ,GAA8B,SAAS,CAAC;QACpD,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACvE,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,OAAO;YACH,WAAW,CAAC,QAAQ;;gBAChB,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE;oBACtB,OAAO,EAAE,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS,EAAE,mCAAI,EAAE;oBACpC,MAAM,EAAE,MAAM;oBACd,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM;iBAC7B,CAAC;qBACG,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACf,OAAO,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACxE,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;gBAClC,CAAC,CAAC;qBACD,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;oBACX,IAAI,SAAS;wBAAE,OAAO;oBACtB,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;oBACtC,OAAO,CAAC,KAAK,EAAE,CAAC;gBACpB,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBACb,IAAI,SAAS;wBAAE,OAAO;oBACtB,SAAS,GAAG,IAAI,CAAC;oBACjB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACzB,CAAC,CAAC,CAAC;YACX,CAAC;YAED,KAAK,CAAC,CAAC;gBACH,QAAQ,GAAG,CAAC,CAAC;YACjB,CAAC;YAED,UAAU,KAAI,CAAC;YAEf,MAAM;gBACF,IAAI,SAAS;oBAAE,OAAO;gBACtB,SAAS,GAAG,IAAI,CAAC;gBACjB,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,EAAE,CAAC;YACxB,CAAC;SACJ,CAAC;IACN,CAAC,CAAC;IAEF,OAAO,CAAO,OAAO,EAAE,EAAE;QACrB,OAAA,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACpB,IAAI,CAAC,KAAK,CACN;gBACI,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE;gBAC7C,aAAa,EAAE,KAAK;gBACpB,cAAc,EAAE,KAAK;gBACrB,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,YAAY,EAAE,OAAO,CAAC,YAAY;aACrC,EACD;gBACI,OAAO,EAAE,IAAI,OAAO,CAAC,WAAW,EAAE;gBAClC,IAAI;gBACJ,KAAK,EAAE,CAAC,QAAQ,EAAE,EAAE;oBAChB,IAAI,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;wBAClC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;qBACzB;yBAAM;wBACH,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;qBAC1B;gBACL,CAAC;gBACD,SAAS;aACZ,CACJ,CAAC;QACN,CAAC,CAAC,CAAA;MAAA,CAAC;AACX,CAAC,CACJ,CAAC","sourcesContent":["import { grpc } from \"@improbable-eng/grpc-web\";\nimport { Handler, RequestMetadata } from \"../handlers/HandlerChainBuilder\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { Err, Ok, Result } from \"../common/result\";\nimport { FetchHandler, cameraKitServiceFetchHandlerFactory } from \"../handlers\";\n\nexport interface GrpcRequest {\n serviceName: string;\n methodName: string;\n requestType: grpc.ProtobufMessageClass<grpc.ProtobufMessage>;\n responseType: grpc.ProtobufMessageClass<grpc.ProtobufMessage>;\n}\n\nexport type GrpcHandler = Handler<\n GrpcRequest,\n Result<grpc.UnaryOutput<grpc.ProtobufMessage>, grpc.UnaryOutput<grpc.ProtobufMessage>>,\n RequestMetadata\n>;\n\n/**\n * An Injectable handler that can make requests to the CameraKit backend service via grpc-web. This handler can be\n * passed to {@link createTsProtoClient} to produce a well-typed service client.\n *\n * @internal\n */\nexport const gprcHandlerFactory = Injectable(\n \"grpcHandler\",\n [configurationToken, cameraKitServiceFetchHandlerFactory.token],\n (configuration: CameraKitConfiguration, fetchHandler: FetchHandler): GrpcHandler => {\n const host = `https://${configuration.apiHostname}`;\n\n // We define our own Transport so that we can use our custom `fetch` implementation. This is important for two\n // reasons:\n // 1. Our custom fetch includes features like retries that we want to use for these requests.\n // 2. Applications may override this fetch implementation (via our DI system) to support more advanced\n // use-cases.\n const transport: grpc.TransportFactory = (options) => {\n let metadata: grpc.Metadata | undefined = undefined;\n const controller = AbortController ? new AbortController() : undefined;\n let cancelled = false;\n return {\n sendMessage(msgBytes) {\n fetchHandler(options.url, {\n headers: metadata?.toHeaders() ?? {},\n method: \"POST\",\n body: msgBytes,\n signal: controller?.signal,\n })\n .then((response) => {\n options.onHeaders(new grpc.Metadata(response.headers), response.status);\n return response.arrayBuffer();\n })\n .then((body) => {\n if (cancelled) return;\n options.onChunk(new Uint8Array(body));\n options.onEnd();\n })\n .catch((error) => {\n if (cancelled) return;\n cancelled = true;\n options.onEnd(error);\n });\n },\n\n start(m) {\n metadata = m;\n },\n\n finishSend() {},\n\n cancel() {\n if (cancelled) return;\n cancelled = true;\n controller?.abort();\n },\n };\n };\n\n return async (request) =>\n new Promise((resolve) => {\n grpc.unary(\n {\n methodName: request.methodName,\n service: { serviceName: request.serviceName },\n requestStream: false,\n responseStream: false,\n requestType: request.requestType,\n responseType: request.responseType,\n },\n {\n request: new request.requestType(),\n host,\n onEnd: (response) => {\n if (response.status === grpc.Code.OK) {\n resolve(Ok(response));\n } else {\n resolve(Err(response));\n }\n },\n transport,\n }\n );\n });\n }\n);\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LensesDefinition } from "../generated-proto/pb_schema/camera_kit/v3/service";
|
|
2
|
+
import { GrpcServiceClient } from "./createTsProtoClient";
|
|
3
|
+
import { GrpcHandler } from "./grpcHandler";
|
|
4
|
+
export type LensesClient = GrpcServiceClient<typeof LensesDefinition>;
|
|
5
|
+
export declare const lensesClientFactory: {
|
|
6
|
+
(args_0: GrpcHandler): LensesClient;
|
|
7
|
+
token: "lensesClient";
|
|
8
|
+
dependencies: readonly ["grpcHandler"];
|
|
9
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Injectable } from "../dependency-injection/Injectable";
|
|
2
|
+
import { LensesDefinition } from "../generated-proto/pb_schema/camera_kit/v3/service";
|
|
3
|
+
import { createTsProtoClient } from "./createTsProtoClient";
|
|
4
|
+
import { gprcHandlerFactory } from "./grpcHandler";
|
|
5
|
+
export const lensesClientFactory = Injectable("lensesClient", [gprcHandlerFactory.token], (grpcHandler) => createTsProtoClient(LensesDefinition, grpcHandler));
|
|
6
|
+
//# sourceMappingURL=lensesClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lensesClient.js","sourceRoot":"","sources":["../../src/clients/lensesClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAqB,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAe,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CACzC,cAAc,EACd,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAC1B,CAAC,WAAwB,EAAgB,EAAE,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,WAAW,CAAC,CACjG,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { LensesDefinition } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport { GrpcServiceClient, createTsProtoClient } from \"./createTsProtoClient\";\nimport { GrpcHandler, gprcHandlerFactory } from \"./grpcHandler\";\n\nexport type LensesClient = GrpcServiceClient<typeof LensesDefinition>;\n\nexport const lensesClientFactory = Injectable(\n \"lensesClient\",\n [gprcHandlerFactory.token],\n (grpcHandler: GrpcHandler): LensesClient => createTsProtoClient(LensesDefinition, grpcHandler)\n);\n"]}
|
package/lib/common/entries.d.ts
CHANGED
package/lib/common/entries.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
// `Object.entries` does not use `keyof` types, so it loses type specificity. We'll fix this with a wrapper.
|
|
2
2
|
export const entries = (o) => Object.entries(o);
|
|
3
|
+
// `Object.fromEntries` similarly does not preserve key types.
|
|
4
|
+
export const fromEntries = (entries) => Object.fromEntries(entries);
|
|
3
5
|
//# sourceMappingURL=entries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../../src/common/entries.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,MAAM,CAAC,MAAM,OAAO,GAAG,CAAiD,CAAI,EAAgC,EAAE,CAC1G,MAAM,CAAC,OAAO,CAAC,CAAC,CAAiC,CAAC","sourcesContent":["// `Object.entries` does not use `keyof` types, so it loses type specificity. We'll fix this with a wrapper.\nexport const entries = <T extends { [s: string]: U } | ArrayLike<U>, U>(o: T): Array<[keyof T, T[keyof T]]> =>\n Object.entries(o) as Array<[keyof T, T[keyof T]]>;\n"]}
|
|
1
|
+
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../../src/common/entries.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,MAAM,CAAC,MAAM,OAAO,GAAG,CAAiD,CAAI,EAAgC,EAAE,CAC1G,MAAM,CAAC,OAAO,CAAC,CAAC,CAAiC,CAAC;AAEtD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAwC,OAA8B,EAAgB,EAAE,CAC/G,MAAM,CAAC,WAAW,CAAC,OAAO,CAAiB,CAAC","sourcesContent":["// `Object.entries` does not use `keyof` types, so it loses type specificity. We'll fix this with a wrapper.\nexport const entries = <T extends { [s: string]: U } | ArrayLike<U>, U>(o: T): Array<[keyof T, T[keyof T]]> =>\n Object.entries(o) as Array<[keyof T, T[keyof T]]>;\n\n// `Object.fromEntries` similarly does not preserve key types.\nexport const fromEntries = <K extends string | number | symbol, V>(entries: ReadonlyArray<[K, V]>): Record<K, V> =>\n Object.fromEntries(entries) as Record<K, V>;\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
interface BaseResult<T, E> {
|
|
2
|
+
readonly ok: boolean;
|
|
3
|
+
unwrap(): T;
|
|
4
|
+
unwrapErr(): E;
|
|
5
|
+
map<T2>(m: (value: T) => T2): Result<T2, E>;
|
|
6
|
+
flatMap<T2 extends OkResult<unknown>>(m: (value: T) => T2): Result<ValueOf<T2>, E>;
|
|
7
|
+
flatMap<E2 extends ErrResult<unknown>>(m: (value: T) => E2): Result<T, E | ValueOf<E2>>;
|
|
8
|
+
flatMap<R extends Result<unknown, unknown>>(m: (value: T) => R): Result<OkValueOf<R>, E | ErrValueOf<R>>;
|
|
9
|
+
}
|
|
10
|
+
type OkValueOf<R> = R extends OkResult<infer T> ? T : never;
|
|
11
|
+
type ErrValueOf<R> = R extends ErrResult<infer E> ? E : never;
|
|
12
|
+
type ValueOf<R> = OkValueOf<R> | ErrValueOf<R>;
|
|
13
|
+
export declare class OkResult<T> implements BaseResult<T, never> {
|
|
14
|
+
private readonly value;
|
|
15
|
+
readonly ok = true;
|
|
16
|
+
constructor(value: T);
|
|
17
|
+
unwrap(): T;
|
|
18
|
+
unwrapErr(): never;
|
|
19
|
+
map<T2>(m: (value: T) => T2): OkResult<T2>;
|
|
20
|
+
flatMap<T2 extends OkResult<unknown>>(m: (value: T) => T2): T2;
|
|
21
|
+
flatMap<E2 extends ErrResult<unknown>>(m: (value: T) => E2): E2;
|
|
22
|
+
flatMap<R extends Result<unknown, unknown>>(m: (value: T) => R): R;
|
|
23
|
+
}
|
|
24
|
+
export declare const Ok: <T>(value: T) => OkResult<T>;
|
|
25
|
+
export declare class ErrResult<E> implements BaseResult<never, E> {
|
|
26
|
+
private readonly value;
|
|
27
|
+
readonly ok = false;
|
|
28
|
+
constructor(value: E);
|
|
29
|
+
unwrap(): never;
|
|
30
|
+
unwrapErr(): E;
|
|
31
|
+
map(): ErrResult<E>;
|
|
32
|
+
flatMap(): ErrResult<E>;
|
|
33
|
+
}
|
|
34
|
+
export declare const Err: <E>(value: E) => ErrResult<E>;
|
|
35
|
+
export type Result<T, E> = OkResult<T> | ErrResult<E>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
export class OkResult {
|
|
3
|
+
constructor(value) {
|
|
4
|
+
this.value = value;
|
|
5
|
+
this.ok = true;
|
|
6
|
+
}
|
|
7
|
+
unwrap() {
|
|
8
|
+
return this.value;
|
|
9
|
+
}
|
|
10
|
+
unwrapErr() {
|
|
11
|
+
throw new Error("Ok Result cannot unwrapErr.");
|
|
12
|
+
}
|
|
13
|
+
map(m) {
|
|
14
|
+
return new OkResult(m(this.value));
|
|
15
|
+
}
|
|
16
|
+
flatMap(m) {
|
|
17
|
+
return m(this.value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export const Ok = (value) => new OkResult(value);
|
|
21
|
+
export class ErrResult {
|
|
22
|
+
constructor(value) {
|
|
23
|
+
this.value = value;
|
|
24
|
+
this.ok = false;
|
|
25
|
+
}
|
|
26
|
+
unwrap() {
|
|
27
|
+
throw this.value;
|
|
28
|
+
}
|
|
29
|
+
unwrapErr() {
|
|
30
|
+
return this.value;
|
|
31
|
+
}
|
|
32
|
+
map() {
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
flatMap() {
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const Err = (value) => new ErrResult(value);
|
|
40
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/common/result.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAkBzC,MAAM,OAAO,QAAQ;IAEjB,YAA6B,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;QAD5B,OAAE,GAAG,IAAI,CAAC;IACqB,CAAC;IAEzC,MAAM;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,SAAS;QACL,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;IAED,GAAG,CAAK,CAAmB;QACvB,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvC,CAAC;IAKD,OAAO,CAAqC,CAAkB;QAC1D,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,EAAE,GAAG,CAAI,KAAQ,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;AAEvD,MAAM,OAAO,SAAS;IAElB,YAA6B,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;QAD5B,OAAE,GAAG,KAAK,CAAC;IACoB,CAAC;IAEzC,MAAM;QACF,MAAM,IAAI,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,GAAG;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,KAAQ,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC","sourcesContent":["/* eslint-disable max-classes-per-file */\n\ninterface BaseResult<T, E> {\n readonly ok: boolean;\n\n unwrap(): T;\n unwrapErr(): E;\n\n map<T2>(m: (value: T) => T2): Result<T2, E>;\n flatMap<T2 extends OkResult<unknown>>(m: (value: T) => T2): Result<ValueOf<T2>, E>;\n flatMap<E2 extends ErrResult<unknown>>(m: (value: T) => E2): Result<T, E | ValueOf<E2>>;\n flatMap<R extends Result<unknown, unknown>>(m: (value: T) => R): Result<OkValueOf<R>, E | ErrValueOf<R>>;\n}\n\ntype OkValueOf<R> = R extends OkResult<infer T> ? T : never;\ntype ErrValueOf<R> = R extends ErrResult<infer E> ? E : never;\ntype ValueOf<R> = OkValueOf<R> | ErrValueOf<R>;\n\nexport class OkResult<T> implements BaseResult<T, never> {\n readonly ok = true;\n constructor(private readonly value: T) {}\n\n unwrap(): T {\n return this.value;\n }\n\n unwrapErr(): never {\n throw new Error(\"Ok Result cannot unwrapErr.\");\n }\n\n map<T2>(m: (value: T) => T2): OkResult<T2> {\n return new OkResult(m(this.value));\n }\n\n flatMap<T2 extends OkResult<unknown>>(m: (value: T) => T2): T2;\n flatMap<E2 extends ErrResult<unknown>>(m: (value: T) => E2): E2;\n flatMap<R extends Result<unknown, unknown>>(m: (value: T) => R): R;\n flatMap<R extends Result<unknown, unknown>>(m: (value: T) => R): R {\n return m(this.value);\n }\n}\n\nexport const Ok = <T>(value: T) => new OkResult(value);\n\nexport class ErrResult<E> implements BaseResult<never, E> {\n readonly ok = false;\n constructor(private readonly value: E) {}\n\n unwrap(): never {\n throw this.value;\n }\n\n unwrapErr(): E {\n return this.value;\n }\n\n map(): ErrResult<E> {\n return this;\n }\n\n flatMap(): ErrResult<E> {\n return this;\n }\n}\n\nexport const Err = <E>(value: E) => new ErrResult(value);\n\nexport type Result<T, E> = OkResult<T> | ErrResult<E>;\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of unique values, in order, from all given arrays using a specified iteratee.
|
|
3
|
+
* If multiple elements have the same key generated by the iteratee, the last occurrence is kept.
|
|
4
|
+
*
|
|
5
|
+
* @param {((item: T) => unknown) | keyof T} iteratee - The iteratee invoked per element.
|
|
6
|
+
* @param {...T[][]} arrays - The arrays to inspect and unite.
|
|
7
|
+
* @returns {T[]} - Returns the new array of combined elements, preserving the order of last occurrences.
|
|
8
|
+
* @example
|
|
9
|
+
* // Using a property name as iteratee
|
|
10
|
+
* const result = unionBy(
|
|
11
|
+
* 'id',
|
|
12
|
+
* [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],
|
|
13
|
+
* [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }]
|
|
14
|
+
* );
|
|
15
|
+
* console.log(result);
|
|
16
|
+
* // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }]
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Using a function as iteratee
|
|
20
|
+
* const result = unionBy(
|
|
21
|
+
* item => item.id,
|
|
22
|
+
* [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],
|
|
23
|
+
* [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }]
|
|
24
|
+
* );
|
|
25
|
+
* console.log(result);
|
|
26
|
+
* // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }]
|
|
27
|
+
*/
|
|
28
|
+
export declare function unionBy<T>(iteratee: ((item: T) => unknown) | keyof T, ...arrays: T[][]): T[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of unique values, in order, from all given arrays using a specified iteratee.
|
|
3
|
+
* If multiple elements have the same key generated by the iteratee, the last occurrence is kept.
|
|
4
|
+
*
|
|
5
|
+
* @param {((item: T) => unknown) | keyof T} iteratee - The iteratee invoked per element.
|
|
6
|
+
* @param {...T[][]} arrays - The arrays to inspect and unite.
|
|
7
|
+
* @returns {T[]} - Returns the new array of combined elements, preserving the order of last occurrences.
|
|
8
|
+
* @example
|
|
9
|
+
* // Using a property name as iteratee
|
|
10
|
+
* const result = unionBy(
|
|
11
|
+
* 'id',
|
|
12
|
+
* [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],
|
|
13
|
+
* [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }]
|
|
14
|
+
* );
|
|
15
|
+
* console.log(result);
|
|
16
|
+
* // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }]
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Using a function as iteratee
|
|
20
|
+
* const result = unionBy(
|
|
21
|
+
* item => item.id,
|
|
22
|
+
* [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],
|
|
23
|
+
* [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }]
|
|
24
|
+
* );
|
|
25
|
+
* console.log(result);
|
|
26
|
+
* // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }]
|
|
27
|
+
*/
|
|
28
|
+
export function unionBy(iteratee, ...arrays) {
|
|
29
|
+
const throwIterateeError = () => {
|
|
30
|
+
throw new Error("Iteratee must be a function or a valid property key of the item");
|
|
31
|
+
};
|
|
32
|
+
// One helpful feature of Map is maintainig the insertion order of elements. This is particularly nice for the
|
|
33
|
+
// unionBy function since it ensures that the combined array preserves the order of elements as they first appear
|
|
34
|
+
// in the input arrays.
|
|
35
|
+
const seen = new Map();
|
|
36
|
+
for (const item of arrays.flat()) {
|
|
37
|
+
const key = typeof iteratee === "function"
|
|
38
|
+
? iteratee(item)
|
|
39
|
+
: typeof item === "object" && item !== null && iteratee in item
|
|
40
|
+
? item[iteratee]
|
|
41
|
+
: throwIterateeError();
|
|
42
|
+
seen.set(key, item);
|
|
43
|
+
}
|
|
44
|
+
return Array.from(seen.values());
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=unionBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unionBy.js","sourceRoot":"","sources":["../../src/common/unionBy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,OAAO,CAAI,QAA0C,EAAE,GAAG,MAAa;IACnF,MAAM,kBAAkB,GAAG,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACvF,CAAC,CAAC;IAEF,8GAA8G;IAC9G,iHAAiH;IACjH,uBAAuB;IACvB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAc,CAAC;IAEnC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,GAAG,GACL,OAAO,QAAQ,KAAK,UAAU;YAC1B,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChB,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,IAAI;gBAC/D,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAChB,CAAC,CAAC,kBAAkB,EAAE,CAAC;QAE/B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;KACvB;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC","sourcesContent":["/**\n * Creates an array of unique values, in order, from all given arrays using a specified iteratee.\n * If multiple elements have the same key generated by the iteratee, the last occurrence is kept.\n *\n * @param {((item: T) => unknown) | keyof T} iteratee - The iteratee invoked per element.\n * @param {...T[][]} arrays - The arrays to inspect and unite.\n * @returns {T[]} - Returns the new array of combined elements, preserving the order of last occurrences.\n * @example\n * // Using a property name as iteratee\n * const result = unionBy(\n * 'id',\n * [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],\n * [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }]\n * );\n * console.log(result);\n * // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }]\n *\n * @example\n * // Using a function as iteratee\n * const result = unionBy(\n * item => item.id,\n * [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],\n * [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }]\n * );\n * console.log(result);\n * // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }]\n */\nexport function unionBy<T>(iteratee: ((item: T) => unknown) | keyof T, ...arrays: T[][]): T[] {\n const throwIterateeError = () => {\n throw new Error(\"Iteratee must be a function or a valid property key of the item\");\n };\n\n // One helpful feature of Map is maintainig the insertion order of elements. This is particularly nice for the\n // unionBy function since it ensures that the combined array preserves the order of elements as they first appear\n // in the input arrays.\n const seen = new Map<unknown, T>();\n\n for (const item of arrays.flat()) {\n const key =\n typeof iteratee === \"function\"\n ? iteratee(item)\n : typeof item === \"object\" && item !== null && iteratee in item\n ? item[iteratee]\n : throwIterateeError();\n\n seen.set(key, item);\n }\n\n return Array.from(seen.values());\n}\n"]}
|
package/lib/configuration.js
CHANGED
|
@@ -18,6 +18,16 @@ const defaultConfiguration = {
|
|
|
18
18
|
};
|
|
19
19
|
/** @internal */
|
|
20
20
|
export const configurationToken = "configuration";
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if given browser is iPhone, iPad or iPod.
|
|
23
|
+
*/
|
|
24
|
+
function isHandledAppleDevice() {
|
|
25
|
+
// We use the same approach LC uses:
|
|
26
|
+
// eslint-disable-next-line max-len
|
|
27
|
+
// https://github.sc-corp.net/Snapchat/LensCore/blob/285ac47cad7fe5268f38d1bab82d51b7b19d6b48/Src/PlatformSpecific/WebAssembly/WebEnvironmentInfo.cpp#L81
|
|
28
|
+
return (/iPad|iPhone|iPod/.test(navigator.platform) ||
|
|
29
|
+
(navigator.platform === "MacIntel" && navigator.maxTouchPoints > 2));
|
|
30
|
+
}
|
|
21
31
|
/** @internal */
|
|
22
32
|
export const createCameraKitConfigurationFactory = (configuration) => {
|
|
23
33
|
// always leave debug mode warning about overrides in console
|
|
@@ -32,7 +42,10 @@ export const createCameraKitConfigurationFactory = (configuration) => {
|
|
|
32
42
|
? // Safety: defaultConfiguration.lensPerformance is defined (it's hardcoded above).
|
|
33
43
|
configuration.lensPerformance.catch(() => defaultConfiguration.lensPerformance)
|
|
34
44
|
: configuration.lensPerformance });
|
|
35
|
-
return Object.assign(Object.assign(Object.assign({}, defaultConfiguration),
|
|
45
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, defaultConfiguration), {
|
|
46
|
+
// TODO: Safari 17 has an issue with offscreen canvas which results in stuttering effect on iOS.
|
|
47
|
+
// Once Safari has that fixed, we should remove this check, see https://jira.sc-corp.net/browse/CAMKIT-5985
|
|
48
|
+
shouldUseWorker: isHandledAppleDevice() ? false : defaultConfiguration.shouldUseWorker }), copyDefinedProperties(safeConfig)), copyDefinedProperties(overrides !== null && overrides !== void 0 ? overrides : {}));
|
|
36
49
|
});
|
|
37
50
|
};
|
|
38
51
|
//# sourceMappingURL=configuration.js.map
|
package/lib/configuration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAU/D;;;GAGG;AACH,MAAM,oBAAoB,GAAmF;IACzG,mHAAmH;IACnH,6GAA6G;IAC7G,qFAAqF;IACrF,eAAe,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAE;IAC7E,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,2BAA2B;IACxC,eAAe,EAAE,SAAS;CAC7B,CAAC;AAmGF,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAElD,gBAAgB;AAChB,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,aAA8C,EAAE,EAAE;IAClG,6DAA6D;IAC7D,MAAM,SAAS,GAAG,yBAAyB,EAAE,CAAC;IAC9C,IAAI,SAAS,EAAE;QACX,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,SAAS,CAAC,CAAC;KAC9D;IACD,OAAO,UAAU,CAAC,kBAAkB,EAAE,GAA2B,EAAE;QAC/D,uGAAuG;QACvG,kFAAkF;QAClF,MAAM,UAAU,mCACT,aAAa,KAChB,eAAe,EACX,aAAa,CAAC,eAAe,YAAY,OAAO;gBAC5C,CAAC,CAAC,kFAAkF;oBAClF,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,eAAgB,CAAC;gBAClF,CAAC,CAAC,aAAa,CAAC,eAAe,GAC1C,CAAC;QACF,
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAU/D;;;GAGG;AACH,MAAM,oBAAoB,GAAmF;IACzG,mHAAmH;IACnH,6GAA6G;IAC7G,qFAAqF;IACrF,eAAe,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAE;IAC7E,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,2BAA2B;IACxC,eAAe,EAAE,SAAS;CAC7B,CAAC;AAmGF,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAElD;;GAEG;AACH,SAAS,oBAAoB;IACzB,oCAAoC;IACpC,mCAAmC;IACnC,yJAAyJ;IACzJ,OAAO,CACH,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC3C,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU,IAAI,SAAS,CAAC,cAAc,GAAG,CAAC,CAAC,CACtE,CAAC;AACN,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,aAA8C,EAAE,EAAE;IAClG,6DAA6D;IAC7D,MAAM,SAAS,GAAG,yBAAyB,EAAE,CAAC;IAC9C,IAAI,SAAS,EAAE;QACX,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,SAAS,CAAC,CAAC;KAC9D;IACD,OAAO,UAAU,CAAC,kBAAkB,EAAE,GAA2B,EAAE;QAC/D,uGAAuG;QACvG,kFAAkF;QAClF,MAAM,UAAU,mCACT,aAAa,KAChB,eAAe,EACX,aAAa,CAAC,eAAe,YAAY,OAAO;gBAC5C,CAAC,CAAC,kFAAkF;oBAClF,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,eAAgB,CAAC;gBAClF,CAAC,CAAC,aAAa,CAAC,eAAe,GAC1C,CAAC;QACF,mEACO,oBAAoB;YACvB,gGAAgG;YAChG,2GAA2G;YAC3G,eAAe,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,CAAC,eAAe,KACnF,qBAAqB,CAAC,UAAU,CAAC,GACjC,qBAAqB,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC,EAC3C;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import { EstimatedLensPerformance } from \"./benchmark/estimateLensPerformanceCluster\";\nimport { copyDefinedProperties } from \"./common/copyDefinedProperties\";\nimport { getConfigurationOverrides } from \"./configurationOverrides\";\nimport { Injectable } from \"./dependency-injection/Injectable\";\nimport { LogLevelName } from \"./logger/logger\";\n\n/**\n * From T, pick the set of properties whose values are optional. Create a new type containing only those properties.\n */\ntype PickOptionals<T> = {\n [K in keyof T as T[K] extends Exclude<T[K], undefined> ? never : K]: T[K];\n};\n\n/**\n * Defaults are provided for runtime configuration and any optional bootstrap configuration properties which require\n * defaults.\n */\nconst defaultConfiguration: CameraKitRuntimeConfiguration & PickOptionals<CameraKitBootstrapConfiguration> = {\n // If the applications doesn't provide performance data (e.g. via estimateLensPerformance), we'll use 0 to indicate\n // no performance estimation occurred. This is indicative of typical performance-targeting logic, which often\n // defaults to the lowest-tier experience in the absense of performance cluster data.\n lensPerformance: { cluster: 0, benchmarks: [], webglRendererInfo: \"unknown\" },\n logger: \"noop\",\n logLevel: \"info\",\n shouldUseWorker: true,\n apiHostname: \"camera-kit-api.snapar.com\",\n userAgentFlavor: \"release\",\n};\n\ninterface CameraKitRuntimeConfiguration {\n lensPerformance: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;\n logger: \"noop\" | \"console\";\n logLevel: LogLevelName;\n shouldUseWorker: boolean;\n apiHostname: CameraKitApiHostname;\n userAgentFlavor: \"release\" | \"debug\";\n}\n\nexport type CameraKitApiHostname = \"camera-kit-api.snapar.com\" | \"api-kit.snapchat.com\";\n\n/**\n * Configuration which must be provided when calling {@link bootstrapCameraKit}. These values are used to create various\n * CameraKit components.\n *\n * @category Bootstrapping and Configuration\n */\nexport interface CameraKitBootstrapConfiguration {\n /**\n * Long-lived token granting your application access to CameraKit APIs. This is found in the SnapKit Dev Portal,\n * where it's called the API Token.\n */\n apiToken: string;\n\n /**\n * Determine where to print CameraKit log messages. By default no logs will be printed.\n *\n * CameraKit emits log messages to help diagnose and root cause issues that may occur during the development of a\n * host application. The printing of these can be controlled via the following\n * options:\n * - `noop`: log messages are ignored.\n * - `console`: log messages are printed to console.\n */\n logger?: \"noop\" | \"console\";\n\n /**\n * Log only if a logged entry level is greater than or equal to this level. Here is the order of levels:\n * error > warn > log = info > debug. Default value is \"info\".\n */\n logLevel?: LogLevelName;\n\n /**\n * Some lenses may decide to modify their behavior based on the performance of the current environment. If you are\n * using such lenses, providing an estimation of lens performance may lead to better user experience (especially on\n * low-performance devices).\n *\n * Running the {@link estimateLensPerformance} function will run benchmarks and estimate an appropriate lens\n * performance cluster (i.e. a performance rating) based on the current environment.\n *\n * Lower cluster = worse expected performance capability.\n *\n * @example\n * ```ts\n * import { bootstrapCameraKit, estimateLensPerformance } from '@snap/camera-kit`\n *\n * const cameraKit = await bootstrapCameraKit({\n * apiToken: '...',\n * lensPerformance: estimateLensPerformance(),\n * })\n * ```\n */\n lensPerformance?: EstimatedLensPerformance | Promise<EstimatedLensPerformance>;\n\n /**\n * In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an\n * optimized CDN. But sometimes (e.g. during development or within a CI pipeline), it may be necessary to download\n * these assets from somewhere else.\n *\n * This configuration option allows the application to specify URLs to be used for both the WebAssembly and JS glue\n * file that are used to run and interact with CameraKit's rendering engine.\n */\n lensCoreOverrideUrls?: { wasm: string; js: string };\n\n /**\n * In recommended production deployments, the WebAssembly assets required by CameraKit will be downloaded from an\n * optimized CDN. But sometimes during development or within a CI pipeline, it may be necessary to download these\n * assets from somewhere else. With a provided `wasmEndpointOverride`, asset URLs will be automatically generated\n * based on this root endpoint.\n */\n wasmEndpointOverride?: string;\n\n /**\n * Applications may optionally provide a unique identifier called analyticsId. This ID would enable Camera Kit to\n * improve data reporting and accuracy and to better support potential needs related to an application's lens and\n * user analytics.\n */\n analyticsId?: string;\n}\n\n/**\n * This type represents the result of merging user-supplied config with default config -- as such, it has no nullable\n * fields, making it a more convenient type for other components to use.\n *\n * @internal\n */\nexport type CameraKitConfiguration = CameraKitRuntimeConfiguration & CameraKitBootstrapConfiguration;\n\n/** @internal */\nexport const configurationToken = \"configuration\";\n\n/**\n * Returns true if given browser is iPhone, iPad or iPod.\n */\nfunction isHandledAppleDevice() {\n // We use the same approach LC uses:\n // eslint-disable-next-line max-len\n // https://github.sc-corp.net/Snapchat/LensCore/blob/285ac47cad7fe5268f38d1bab82d51b7b19d6b48/Src/PlatformSpecific/WebAssembly/WebEnvironmentInfo.cpp#L81\n return (\n /iPad|iPhone|iPod/.test(navigator.platform) ||\n (navigator.platform === \"MacIntel\" && navigator.maxTouchPoints > 2)\n );\n}\n\n/** @internal */\nexport const createCameraKitConfigurationFactory = (configuration: CameraKitBootstrapConfiguration) => {\n // always leave debug mode warning about overrides in console\n const overrides = getConfigurationOverrides();\n if (overrides) {\n console.warn(\"Configuration overrides applied\", overrides);\n }\n return Injectable(configurationToken, (): CameraKitConfiguration => {\n // We'll ensure that we handle errors on any Promises passed as config values, otherwise we either must\n // handle them separately wherever they're used, or rejections would go unhandled.\n const safeConfig: CameraKitBootstrapConfiguration = {\n ...configuration,\n lensPerformance:\n configuration.lensPerformance instanceof Promise\n ? // Safety: defaultConfiguration.lensPerformance is defined (it's hardcoded above).\n configuration.lensPerformance.catch(() => defaultConfiguration.lensPerformance!)\n : configuration.lensPerformance,\n };\n return {\n ...defaultConfiguration,\n // TODO: Safari 17 has an issue with offscreen canvas which results in stuttering effect on iOS.\n // Once Safari has that fixed, we should remove this check, see https://jira.sc-corp.net/browse/CAMKIT-5985\n shouldUseWorker: isHandledAppleDevice() ? false : defaultConfiguration.shouldUseWorker,\n ...copyDefinedProperties(safeConfig),\n ...copyDefinedProperties(overrides ?? {}),\n };\n });\n};\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { InjectableFunction, ServicesFromTokenizedParams } from "./types";
|
|
2
2
|
/**
|
|
3
|
-
* Create an Injectable function with no dependencies (i.e. arguments).
|
|
3
|
+
* Create an Injectable factory function with no dependencies (i.e. the factory function has no arguments).
|
|
4
4
|
*
|
|
5
5
|
* Ex:
|
|
6
6
|
* ```ts
|
|
7
|
-
* const createMyService =
|
|
7
|
+
* const createMyService = Injectable(
|
|
8
8
|
* 'MyService',
|
|
9
|
-
* () => { ... },
|
|
9
|
+
* () => { return ... },
|
|
10
10
|
* )
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
@@ -15,25 +15,81 @@ import { InjectableFunction, ServicesFromTokenizedParams } from "./types";
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function Injectable<Token extends string, Service>(token: Token, fn: () => Service): InjectableFunction<any, [], Token, Service>;
|
|
17
17
|
/**
|
|
18
|
-
* Create an Injectable function with dependencies (i.e. arguments).
|
|
18
|
+
* Create an Injectable factory function with dependencies (i.e. the factory function has arguments).
|
|
19
19
|
*
|
|
20
|
-
* **Note:** the list of dependencies must
|
|
21
|
-
* contain only string literals or string consts.
|
|
20
|
+
* **Note:** the list of dependencies must contain only string literals or string consts.
|
|
22
21
|
*
|
|
23
22
|
* Ex:
|
|
24
23
|
* ```ts
|
|
25
24
|
* const DependencyB = 'DependencyB'
|
|
26
|
-
* const createMyService =
|
|
25
|
+
* const createMyService = Injectable(
|
|
27
26
|
* 'MyService',
|
|
28
|
-
* ['DependencyA', DependencyB]
|
|
29
|
-
* (a: A, b: B) => { ... },
|
|
27
|
+
* ['DependencyA', DependencyB],
|
|
28
|
+
* (a: A, b: B) => { return ... },
|
|
30
29
|
* )
|
|
31
30
|
* ```
|
|
32
31
|
*
|
|
33
32
|
* @param token A unique string Token which will correspond to the created Service.
|
|
34
33
|
* @param dependencies A *readonly* list of Tokens corresponding to dependencies (i.e. arguments to the Factory), which
|
|
35
|
-
* will be resolved by the Container to which this
|
|
34
|
+
* will be resolved by the Container to which this Injectable is provided.
|
|
36
35
|
* @param fn A function with arguments matching in type and length to the given list of dependencies. When called, it
|
|
37
36
|
* must return the Service.
|
|
38
37
|
*/
|
|
39
|
-
export declare function Injectable<Token extends string, Tokens extends readonly string[], Params extends readonly any[], Service>(token: Token, dependencies: Tokens, fn: (...args: Tokens["length"] extends Params["length"] ? Params : void[]) => Service): Tokens["length"] extends Params["length"] ? InjectableFunction<ServicesFromTokenizedParams<Tokens, Params>, Tokens, Token, Service> : never;
|
|
38
|
+
export declare function Injectable<Token extends string, const Tokens extends readonly string[], Params extends readonly any[], Service>(token: Token, dependencies: Tokens, fn: (...args: Tokens["length"] extends Params["length"] ? Params : void[]) => Service): Tokens["length"] extends Params["length"] ? InjectableFunction<ServicesFromTokenizedParams<Tokens, Params>, Tokens, Token, Service> : never;
|
|
39
|
+
/**
|
|
40
|
+
* Create an Injectable factory function without dependencies (i.e. the factory function has no arguments) that appends
|
|
41
|
+
* a Service onto an existing array of Services of the same type.
|
|
42
|
+
*
|
|
43
|
+
* Ex:
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { myServiceFactory, MyService } from './my-service'
|
|
46
|
+
*
|
|
47
|
+
* const createMyService = ConcatInjectable(
|
|
48
|
+
* myServiceFactory.token,
|
|
49
|
+
* (): MyService => { return ... },
|
|
50
|
+
* )
|
|
51
|
+
*
|
|
52
|
+
* // Consumers then do:
|
|
53
|
+
* const myConsumingServiceFactory = Injectable(
|
|
54
|
+
* 'myConsumingService',
|
|
55
|
+
* [ myServiceFactory.token ],
|
|
56
|
+
* (myServices: MyService[]) => { return ... }
|
|
57
|
+
* )
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param token A string Token identifying an existing Service that has an Array type, to which will be appended the
|
|
61
|
+
* Service created by this factory function.
|
|
62
|
+
* @param fn A function with no arguments which returns the Service.
|
|
63
|
+
*/
|
|
64
|
+
export declare function ConcatInjectable<Token extends string, Service>(token: Token, fn: () => Service): InjectableFunction<{
|
|
65
|
+
[T in keyof Token]: Service[];
|
|
66
|
+
}, [], Token, Service[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Create an Injectable factory function with dependencies (i.e. the factory function has arguments) that appends
|
|
69
|
+
* a Service onto an existing array of Services of the same type.
|
|
70
|
+
*
|
|
71
|
+
* Ex:
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { myServiceFactory, MyService } from './my-service'
|
|
74
|
+
*
|
|
75
|
+
* const createMyService = ConcatInjectable(
|
|
76
|
+
* myServiceFactory.token,
|
|
77
|
+
* ['DependencyA', 'DependencyB'],
|
|
78
|
+
* (a: A, b: B): MyService => { return ... },
|
|
79
|
+
* )
|
|
80
|
+
*
|
|
81
|
+
* // Consumers then do:
|
|
82
|
+
* const myConsumingServiceFactory = Injectable(
|
|
83
|
+
* 'myConsumingService',
|
|
84
|
+
* [ myServiceFactory.token ],
|
|
85
|
+
* (myServices: MyService[]) => { return ... }
|
|
86
|
+
* )
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param token A string Token identifying an existing Service that has an Array type, to which will be appended the
|
|
90
|
+
* Service created by this factory function.
|
|
91
|
+
* @param dependencies A *readonly* list of Tokens corresponding to dependencies (i.e. arguments to the Factory), which
|
|
92
|
+
* will be resolved by the Container to which this Injectable is provided.
|
|
93
|
+
* @param fn A function with no arguments which returns the Service.
|
|
94
|
+
*/
|
|
95
|
+
export declare function ConcatInjectable<Token extends string, const Tokens extends readonly string[], Params extends readonly any[], Service>(token: Token, dependencies: Tokens, fn: (...args: Tokens["length"] extends Params["length"] ? Params : void[]) => Service): InjectableFunction<ServicesFromTokenizedParams<Tokens, Params>, Tokens, Token, Service[]>;
|
|
@@ -2,11 +2,11 @@ export function Injectable(token, dependenciesOrFn, maybeFn) {
|
|
|
2
2
|
const dependencies = Array.isArray(dependenciesOrFn) ? dependenciesOrFn : [];
|
|
3
3
|
const fn = typeof dependenciesOrFn === "function" ? dependenciesOrFn : maybeFn;
|
|
4
4
|
if (!fn) {
|
|
5
|
-
throw new TypeError("[
|
|
5
|
+
throw new TypeError("[Injectable] Received invalid arguments. The factory function must be either the second " +
|
|
6
6
|
"or third argument.");
|
|
7
7
|
}
|
|
8
8
|
if (fn.length !== dependencies.length) {
|
|
9
|
-
throw new TypeError("[
|
|
9
|
+
throw new TypeError("[Injectable] Function arity does not match the number of dependencies. Function has arity " +
|
|
10
10
|
`${fn.length}, but ${dependencies.length} dependencies were specified.` +
|
|
11
11
|
`\nDependencies: ${JSON.stringify(dependencies)}`);
|
|
12
12
|
}
|
|
@@ -15,4 +15,23 @@ export function Injectable(token, dependenciesOrFn, maybeFn) {
|
|
|
15
15
|
factory.dependencies = dependencies;
|
|
16
16
|
return factory;
|
|
17
17
|
}
|
|
18
|
+
export function ConcatInjectable(token, dependenciesOrFn, maybeFn) {
|
|
19
|
+
const dependencies = Array.isArray(dependenciesOrFn) ? dependenciesOrFn : [];
|
|
20
|
+
const fn = typeof dependenciesOrFn === "function" ? dependenciesOrFn : maybeFn;
|
|
21
|
+
if (!fn) {
|
|
22
|
+
throw new TypeError("[ConcatInjectable] Received invalid arguments. The factory function must be either the second " +
|
|
23
|
+
"or third argument.");
|
|
24
|
+
}
|
|
25
|
+
if (fn.length !== dependencies.length) {
|
|
26
|
+
throw new TypeError("[Injectable] Function arity does not match the number of dependencies. Function has arity " +
|
|
27
|
+
`${fn.length}, but ${dependencies.length} dependencies were specified.` +
|
|
28
|
+
`\nDependencies: ${JSON.stringify(dependencies)}`);
|
|
29
|
+
}
|
|
30
|
+
const factory = (array, ...args) => {
|
|
31
|
+
return array.concat(fn(...args));
|
|
32
|
+
};
|
|
33
|
+
factory.token = token;
|
|
34
|
+
factory.dependencies = [token, ...dependencies];
|
|
35
|
+
return factory;
|
|
36
|
+
}
|
|
18
37
|
//# sourceMappingURL=Injectable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Injectable.js","sourceRoot":"","sources":["../../src/dependency-injection/Injectable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Injectable.js","sourceRoot":"","sources":["../../src/dependency-injection/Injectable.ts"],"names":[],"mappings":"AA0DA,MAAM,UAAU,UAAU,CACtB,KAAa,EACb,gBAAkD,EAClD,OAAiC;IAEjC,MAAM,YAAY,GAAa,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,MAAM,EAAE,GAAG,OAAO,gBAAgB,KAAK,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;IAE/E,IAAI,CAAC,EAAE,EAAE;QACL,MAAM,IAAI,SAAS,CACf,0FAA0F;YACtF,oBAAoB,CAC3B,CAAC;KACL;IAED,IAAI,EAAE,CAAC,MAAM,KAAK,YAAY,CAAC,MAAM,EAAE;QACnC,MAAM,IAAI,SAAS,CACf,4FAA4F;YACxF,GAAG,EAAE,CAAC,MAAM,SAAS,YAAY,CAAC,MAAM,+BAA+B;YACvE,mBAAmB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CACxD,CAAC;KACL;IAED,MAAM,OAAO,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IAChD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;IACpC,OAAO,OAAO,CAAC;AACnB,CAAC;AAuED,MAAM,UAAU,gBAAgB,CAC5B,KAAa,EACb,gBAAkD,EAClD,OAAiC;IAEjC,MAAM,YAAY,GAAa,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,MAAM,EAAE,GAAG,OAAO,gBAAgB,KAAK,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;IAE/E,IAAI,CAAC,EAAE,EAAE;QACL,MAAM,IAAI,SAAS,CACf,gGAAgG;YAC5F,oBAAoB,CAC3B,CAAC;KACL;IAED,IAAI,EAAE,CAAC,MAAM,KAAK,YAAY,CAAC,MAAM,EAAE;QACnC,MAAM,IAAI,SAAS,CACf,4FAA4F;YACxF,GAAG,EAAE,CAAC,MAAM,SAAS,YAAY,CAAC,MAAM,+BAA+B;YACvE,mBAAmB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CACxD,CAAC;KACL;IAED,MAAM,OAAO,GAAG,CAAC,KAAY,EAAE,GAAG,IAAW,EAAE,EAAE;QAC7C,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACrC,CAAC,CAAC;IACF,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,OAAO,CAAC,YAAY,GAAG,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import { InjectableFunction, ServicesFromTokenizedParams } from \"./types\";\n\n/**\n * Create an Injectable factory function with no dependencies (i.e. the factory function has no arguments).\n *\n * Ex:\n * ```ts\n * const createMyService = Injectable(\n * 'MyService',\n * () => { return ... },\n * )\n * ```\n *\n * @param token A unique string Token which will correspond to the created Service.\n * @param fn A function with no arguments which returns the Service.\n */\nexport function Injectable<Token extends string, Service>(\n token: Token,\n fn: () => Service\n): InjectableFunction<any, [], Token, Service>;\n\n/**\n * Create an Injectable factory function with dependencies (i.e. the factory function has arguments).\n *\n * **Note:** the list of dependencies must contain only string literals or string consts.\n *\n * Ex:\n * ```ts\n * const DependencyB = 'DependencyB'\n * const createMyService = Injectable(\n * 'MyService',\n * ['DependencyA', DependencyB],\n * (a: A, b: B) => { return ... },\n * )\n * ```\n *\n * @param token A unique string Token which will correspond to the created Service.\n * @param dependencies A *readonly* list of Tokens corresponding to dependencies (i.e. arguments to the Factory), which\n * will be resolved by the Container to which this Injectable is provided.\n * @param fn A function with arguments matching in type and length to the given list of dependencies. When called, it\n * must return the Service.\n */\nexport function Injectable<\n Token extends string,\n const Tokens extends readonly string[],\n Params extends readonly any[],\n Service\n>(\n token: Token,\n dependencies: Tokens,\n // The function arity (number of arguments) must match the number of dependencies specified – if they don't, we'll\n // force a compiler error by saying the arguments should be `void[]`. We'll also throw at runtime, so the return\n // type will be `never`.\n fn: (...args: Tokens[\"length\"] extends Params[\"length\"] ? Params : void[]) => Service\n): Tokens[\"length\"] extends Params[\"length\"]\n ? InjectableFunction<ServicesFromTokenizedParams<Tokens, Params>, Tokens, Token, Service>\n : never;\n\nexport function Injectable(\n token: string,\n dependenciesOrFn?: readonly string[] | (() => any),\n maybeFn?: (...args: any[]) => any\n): InjectableFunction<any, readonly string[], string, any> {\n const dependencies: string[] = Array.isArray(dependenciesOrFn) ? dependenciesOrFn : [];\n const fn = typeof dependenciesOrFn === \"function\" ? dependenciesOrFn : maybeFn;\n\n if (!fn) {\n throw new TypeError(\n \"[Injectable] Received invalid arguments. The factory function must be either the second \" +\n \"or third argument.\"\n );\n }\n\n if (fn.length !== dependencies.length) {\n throw new TypeError(\n \"[Injectable] Function arity does not match the number of dependencies. Function has arity \" +\n `${fn.length}, but ${dependencies.length} dependencies were specified.` +\n `\\nDependencies: ${JSON.stringify(dependencies)}`\n );\n }\n\n const factory = (...args: any[]) => fn(...args);\n factory.token = token;\n factory.dependencies = dependencies;\n return factory;\n}\n\n/**\n * Create an Injectable factory function without dependencies (i.e. the factory function has no arguments) that appends\n * a Service onto an existing array of Services of the same type.\n *\n * Ex:\n * ```ts\n * import { myServiceFactory, MyService } from './my-service'\n *\n * const createMyService = ConcatInjectable(\n * myServiceFactory.token,\n * (): MyService => { return ... },\n * )\n *\n * // Consumers then do:\n * const myConsumingServiceFactory = Injectable(\n * 'myConsumingService',\n * [ myServiceFactory.token ],\n * (myServices: MyService[]) => { return ... }\n * )\n * ```\n *\n * @param token A string Token identifying an existing Service that has an Array type, to which will be appended the\n * Service created by this factory function.\n * @param fn A function with no arguments which returns the Service.\n */\nexport function ConcatInjectable<Token extends string, Service>(\n token: Token,\n fn: () => Service\n): InjectableFunction<{ [T in keyof Token]: Service[] }, [], Token, Service[]>;\n\n/**\n * Create an Injectable factory function with dependencies (i.e. the factory function has arguments) that appends\n * a Service onto an existing array of Services of the same type.\n *\n * Ex:\n * ```ts\n * import { myServiceFactory, MyService } from './my-service'\n *\n * const createMyService = ConcatInjectable(\n * myServiceFactory.token,\n * ['DependencyA', 'DependencyB'],\n * (a: A, b: B): MyService => { return ... },\n * )\n *\n * // Consumers then do:\n * const myConsumingServiceFactory = Injectable(\n * 'myConsumingService',\n * [ myServiceFactory.token ],\n * (myServices: MyService[]) => { return ... }\n * )\n * ```\n *\n * @param token A string Token identifying an existing Service that has an Array type, to which will be appended the\n * Service created by this factory function.\n * @param dependencies A *readonly* list of Tokens corresponding to dependencies (i.e. arguments to the Factory), which\n * will be resolved by the Container to which this Injectable is provided.\n * @param fn A function with no arguments which returns the Service.\n */\nexport function ConcatInjectable<\n Token extends string,\n const Tokens extends readonly string[],\n Params extends readonly any[],\n Service\n>(\n token: Token,\n dependencies: Tokens,\n fn: (...args: Tokens[\"length\"] extends Params[\"length\"] ? Params : void[]) => Service\n): InjectableFunction<ServicesFromTokenizedParams<Tokens, Params>, Tokens, Token, Service[]>;\n\nexport function ConcatInjectable(\n token: string,\n dependenciesOrFn?: readonly string[] | (() => any),\n maybeFn?: (...args: any[]) => any\n): InjectableFunction<any, readonly string[], string, any[]> {\n const dependencies: string[] = Array.isArray(dependenciesOrFn) ? dependenciesOrFn : [];\n const fn = typeof dependenciesOrFn === \"function\" ? dependenciesOrFn : maybeFn;\n\n if (!fn) {\n throw new TypeError(\n \"[ConcatInjectable] Received invalid arguments. The factory function must be either the second \" +\n \"or third argument.\"\n );\n }\n\n if (fn.length !== dependencies.length) {\n throw new TypeError(\n \"[Injectable] Function arity does not match the number of dependencies. Function has arity \" +\n `${fn.length}, but ${dependencies.length} dependencies were specified.` +\n `\\nDependencies: ${JSON.stringify(dependencies)}`\n );\n }\n\n const factory = (array: any[], ...args: any[]) => {\n return array.concat(fn(...args));\n };\n factory.token = token;\n factory.dependencies = [token, ...dependencies];\n return factory;\n}\n"]}
|