@snap/camera-kit 0.8.0 → 0.9.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/docs/html/assets/main.js +57 -53
- package/docs/html/assets/search.js +1 -1
- package/docs/html/assets/style.css +504 -362
- package/docs/html/classes/CameraKit.html +113 -47
- package/docs/html/classes/CameraKitSession.html +202 -142
- package/docs/html/classes/CameraKitSource.html +124 -60
- package/docs/html/classes/LensPerformanceMeasurement.html +112 -46
- package/docs/html/classes/LensPerformanceMetrics.html +97 -32
- package/docs/html/classes/LensRepository.html +130 -66
- package/docs/html/classes/LensSources.html +98 -32
- package/docs/html/classes/Transform2D.html +111 -43
- package/docs/html/classes/TypedCustomEvent.html +109 -47
- package/docs/html/classes/TypedEventTarget.html +125 -65
- package/docs/html/functions/Injectable.html +113 -120
- package/docs/html/functions/bootstrapCameraKit.html +100 -104
- package/docs/html/functions/createExtension.html +90 -94
- package/docs/html/functions/createImageSource.html +90 -93
- package/docs/html/functions/createMediaStreamSource.html +90 -93
- package/docs/html/functions/createUserMediaSource.html +92 -96
- package/docs/html/functions/createVideoSource.html +90 -93
- package/docs/html/functions/estimateLensPerformance.html +88 -92
- package/docs/html/functions/getRequiredBootstrapURLs.html +90 -94
- package/docs/html/functions/lensSourcesFactory.html +88 -91
- package/docs/html/functions/uriHandlersFactory.html +88 -91
- package/docs/html/index.html +134 -170
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +115 -49
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +111 -45
- package/docs/html/interfaces/ComputedFrameMetrics.html +98 -32
- package/docs/html/interfaces/CreateSessionOptions.html +95 -29
- package/docs/html/interfaces/EstimatedLensPerformance.html +98 -32
- package/docs/html/interfaces/Lens.html +115 -49
- package/docs/html/interfaces/LensSource.html +107 -41
- package/docs/html/interfaces/MediaStreamSourceOptions.html +94 -28
- package/docs/html/interfaces/UriCancelRequest.html +94 -28
- package/docs/html/interfaces/UriHandler.html +108 -42
- package/docs/html/interfaces/UriRequest.html +106 -40
- package/docs/html/interfaces/UriResponse.html +106 -40
- package/docs/html/interfaces/VideoSourceOptions.html +90 -24
- package/docs/html/modules.html +161 -164
- package/docs/html/types/AssetLoader.html +91 -94
- package/docs/html/types/AssetTiming.html +85 -88
- package/docs/html/types/BenchmarkError.html +85 -88
- package/docs/html/types/BootstrapError.html +86 -89
- package/docs/html/types/CacheKeyNotFoundError.html +85 -88
- package/docs/html/types/CameraKitDeviceInfo.html +87 -90
- package/docs/html/types/CameraKitSessionEventListener.html +86 -89
- package/docs/html/types/CameraKitSessionEvents.html +88 -91
- package/docs/html/types/CameraKitSourceError.html +85 -88
- package/docs/html/types/CameraKitSourceInfo.html +85 -88
- package/docs/html/types/CameraKitSourceOptions.html +88 -92
- package/docs/html/types/ConfigurationError.html +86 -89
- package/docs/html/types/Keyboard.html +108 -111
- package/docs/html/types/KeyboardEvents.html +86 -89
- package/docs/html/types/LegalError.html +85 -88
- package/docs/html/types/LensAssetError.html +85 -88
- package/docs/html/types/LensContentValidationError.html +85 -88
- package/docs/html/types/LensError.html +85 -88
- package/docs/html/types/LensExecutionError.html +86 -89
- package/docs/html/types/LensImagePickerError.html +85 -88
- package/docs/html/types/LensLaunchParams.html +85 -88
- package/docs/html/types/LensMetricsEvents.html +86 -89
- package/docs/html/types/LensPerformanceCluster.html +85 -88
- package/docs/html/types/LensView.html +85 -88
- package/docs/html/types/LensWait.html +85 -88
- package/docs/html/types/PersistentStoreError.html +85 -88
- package/docs/html/types/PlatformNotSupportedError.html +86 -89
- package/docs/html/types/PublicContainer.html +85 -88
- package/docs/html/types/RenderTarget.html +85 -88
- package/docs/html/types/Uri.html +85 -88
- package/docs/html/types/UriHandlers.html +86 -89
- package/docs/html/types/WebGLError.html +85 -88
- package/docs/html/variables/extensionRequestContext.html +85 -88
- package/docs/md/README.md +1 -1
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +1 -1
- package/docs/md/classes/CameraKitSource.md +1 -1
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +3 -3
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +3 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +3 -3
- 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/LensSource.md +1 -1
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/UriCancelRequest.md +1 -1
- package/docs/md/interfaces/UriHandler.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 +3 -3
- package/lib/CameraKit.d.ts +9 -9
- package/lib/__tests__/data.d.ts +1 -1
- package/lib/__tests__/deferred.d.ts +1 -1
- package/lib/__tests__/jest.matchers.d.ts +1 -1
- package/lib/benchmark/estimateLensPerformanceCluster.d.ts +2 -2
- package/lib/bootstrapCameraKit.d.ts +1 -1
- package/lib/common/cameraKitUserAgent.d.ts +1 -1
- package/lib/common/localization.d.ts +8 -4
- package/lib/common/localization.js.map +1 -1
- package/lib/common/memoize.d.ts +2 -2
- package/lib/common/pageVisibility.js +1 -1
- package/lib/common/pageVisibility.js.map +1 -1
- package/lib/common/typeguards.d.ts +2 -2
- package/lib/common/types.d.ts +2 -2
- package/lib/common/validate.js +20 -12
- package/lib/common/validate.js.map +1 -1
- package/lib/configuration.d.ts +1 -1
- package/lib/configuration.js.map +1 -1
- package/lib/configurationOverrides.d.ts +1 -1
- package/lib/dependency-injection/Container.d.ts +5 -6
- package/lib/dependency-injection/Container.js +1 -1
- package/lib/dependency-injection/Container.js.map +1 -1
- package/lib/dependency-injection/PartialContainer.d.ts +10 -6
- package/lib/dependency-injection/PartialContainer.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +2 -2
- package/lib/dependency-injection/types.d.ts +9 -9
- package/lib/dependency-injection/types.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/events/TypedCustomEvent.d.ts +1 -1
- package/lib/events/TypedEventTarget.d.ts +2 -2
- package/lib/events/scan.d.ts +1 -1
- package/lib/events/scan.js +3 -3
- package/lib/events/scan.js.map +1 -1
- package/lib/extensions/UriHandlers.d.ts +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +3 -3
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +9 -9
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +2 -2
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +17 -17
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +4 -4
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +3 -3
- 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 +4 -4
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +25 -25
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +4 -4
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +4533 -333
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +4 -4
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +572 -32
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4 -4
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +4 -4
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +4 -4
- package/lib/generated-proto/pb_schema/common/value.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/api/http.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +4 -4
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/lures.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +4 -4
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +4 -4
- package/lib/handlers/HandlerChainBuilder.d.ts +18 -3
- package/lib/handlers/HandlerChainBuilder.js +8 -1
- package/lib/handlers/HandlerChainBuilder.js.map +1 -1
- package/lib/handlers/arrayBufferParsingHandler.d.ts +2 -2
- package/lib/handlers/arrayBufferParsingHandler.js.map +1 -1
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +1 -1
- package/lib/handlers/defaultFetchHandler.d.ts +1 -1
- package/lib/handlers/headersModifyingFetchHandler.js +5 -1
- package/lib/handlers/headersModifyingFetchHandler.js.map +1 -1
- package/lib/handlers/noCorsRetryingFetchHandler.js +4 -3
- package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -1
- package/lib/handlers/requestStateEmittingHandler.d.ts +2 -2
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
- package/lib/handlers/responseCachingHandler.d.ts +10 -2
- package/lib/handlers/responseCachingHandler.js +12 -3
- package/lib/handlers/responseCachingHandler.js.map +1 -1
- package/lib/handlers/retryingHandler.d.ts +7 -0
- package/lib/handlers/retryingHandler.js +14 -5
- package/lib/handlers/retryingHandler.js.map +1 -1
- package/lib/legal/legalPrompt.d.ts +1 -1
- package/lib/legal/legalPrompt.js.map +1 -1
- package/lib/legal/legalState.d.ts +1 -1
- package/lib/legal/legalState.js.map +1 -1
- package/lib/lens/Lens.d.ts +1 -1
- package/lib/lens/LensLaunchParams.d.ts +2 -2
- package/lib/lens/LensRepository.d.ts +7 -8
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetRepository.d.ts +2 -2
- package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
- package/lib/lens/assets/deviceDependentAssetLoader.d.ts +1 -1
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +1 -1
- package/lib/lens/assets/staticAssetLoader.d.ts +1 -1
- package/lib/lens-core-module/generated-types.d.ts +29 -29
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/logger/logger.d.ts +2 -2
- package/lib/media-sources/CameraKitSource.d.ts +3 -3
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/FunctionSource.d.ts +1 -1
- package/lib/media-sources/MediaStreamSource.js +25 -5
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.d.ts +4 -4
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/metricsEventTarget.d.ts +5 -5
- package/lib/metrics/metricsHandler.d.ts +1 -1
- package/lib/metrics/operationalMetricsReporter.d.ts +2 -2
- package/lib/metrics/reporters/reportBenchmarks.d.ts +1 -1
- package/lib/metrics/reporters/reportLegalState.d.ts +1 -1
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +4 -4
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.js +1 -1
- package/lib/metrics/reporters/reportLensView.js.map +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +1 -1
- package/lib/metrics/reporters/reportUserSession.d.ts +1 -1
- package/lib/metrics/reporters/reporters.d.ts +2 -2
- package/lib/namedErrors.d.ts +17 -17
- package/lib/persistence/Persistence.d.ts +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +4 -2
- package/lib/remote-configuration/cofHandler.js +10 -5
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/remoteConfiguration.d.ts +4 -3
- package/lib/remote-configuration/remoteConfiguration.js +5 -4
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +1 -1
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/CameraKitSessionEvents.d.ts +3 -3
- package/lib/session/LensKeyboard.d.ts +2 -2
- package/lib/session/LensPerformanceMetrics.js.map +1 -1
- package/lib/session/lensState.d.ts +2 -2
- package/lib/session/lensState.js.map +1 -1
- package/lib/session/sessionState.d.ts +1 -1
- package/lib/transforms/Transform2D.js +2 -1
- package/lib/transforms/Transform2D.js.map +1 -1
- package/package.json +14 -14
- package/docs/html/assets/widgets.png +0 -0
- package/docs/html/assets/widgets@2x.png +0 -0
|
@@ -4197,12 +4197,12 @@ export declare const ClientTargetingExpression_PropertyMetadata: {
|
|
|
4197
4197
|
abSeedForHashing?: string | undefined;
|
|
4198
4198
|
} & Record<Exclude<keyof I, keyof ClientTargetingExpression_PropertyMetadata>, never>>(object: I): ClientTargetingExpression_PropertyMetadata;
|
|
4199
4199
|
};
|
|
4200
|
-
|
|
4201
|
-
export
|
|
4200
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
4201
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
4202
4202
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
4203
4203
|
} : Partial<T>;
|
|
4204
|
-
|
|
4205
|
-
export
|
|
4204
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
4205
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
4206
4206
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
4207
4207
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
4208
4208
|
export {};
|
|
@@ -91,12 +91,12 @@ export declare const DebugTrace: {
|
|
|
91
91
|
budgetGroupId?: number | undefined;
|
|
92
92
|
} & Record<Exclude<keyof I, keyof DebugTrace>, never>>(object: I): DebugTrace;
|
|
93
93
|
};
|
|
94
|
-
|
|
95
|
-
export
|
|
94
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
95
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
96
96
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
97
97
|
} : Partial<T>;
|
|
98
|
-
|
|
99
|
-
export
|
|
98
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
99
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
100
100
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
101
101
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
102
102
|
export {};
|
|
@@ -64,12 +64,12 @@ export declare const Ruid: {
|
|
|
64
64
|
loggingIdValue?: string | undefined;
|
|
65
65
|
} & Record<Exclude<keyof I, keyof Ruid>, never>>(object: I): Ruid;
|
|
66
66
|
};
|
|
67
|
-
|
|
68
|
-
export
|
|
67
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
68
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
69
69
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
70
70
|
} : Partial<T>;
|
|
71
|
-
|
|
72
|
-
export
|
|
71
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
72
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
73
73
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
74
74
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
75
75
|
export {};
|
|
@@ -120,12 +120,12 @@ export declare const Value: {
|
|
|
120
120
|
intPairValue?: number | undefined;
|
|
121
121
|
} & Record<Exclude<keyof I, keyof Value>, never>>(object: I): Value;
|
|
122
122
|
};
|
|
123
|
-
|
|
124
|
-
export
|
|
123
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
124
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
125
125
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
126
126
|
} : Partial<T>;
|
|
127
|
-
|
|
128
|
-
export
|
|
127
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
128
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
129
129
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
130
130
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
131
131
|
export {};
|
|
@@ -3619,8 +3619,8 @@ export declare const CustomHttpPattern: {
|
|
|
3619
3619
|
path?: string | undefined;
|
|
3620
3620
|
} & Record<Exclude<keyof I, keyof CustomHttpPattern>, never>>(object: I): CustomHttpPattern;
|
|
3621
3621
|
};
|
|
3622
|
-
|
|
3623
|
-
export
|
|
3622
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
3623
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
3624
3624
|
$case: string;
|
|
3625
3625
|
} ? {
|
|
3626
3626
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -3629,8 +3629,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
3629
3629
|
} : T extends {} ? {
|
|
3630
3630
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
3631
3631
|
} : Partial<T>;
|
|
3632
|
-
|
|
3633
|
-
export
|
|
3632
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
3633
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
3634
3634
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
3635
3635
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
3636
3636
|
export {};
|
|
@@ -122,8 +122,8 @@ export declare const Any: {
|
|
|
122
122
|
value?: Uint8Array | undefined;
|
|
123
123
|
} & Record<Exclude<keyof I, keyof Any>, never>>(object: I): Any;
|
|
124
124
|
};
|
|
125
|
-
|
|
126
|
-
export
|
|
125
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
126
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
127
127
|
$case: string;
|
|
128
128
|
} ? {
|
|
129
129
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -132,8 +132,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
132
132
|
} : T extends {} ? {
|
|
133
133
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
134
134
|
} : Partial<T>;
|
|
135
|
-
|
|
136
|
-
export
|
|
135
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
136
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
137
137
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
138
138
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
139
139
|
export {};
|
|
@@ -50951,8 +50951,8 @@ export declare const GeneratedCodeInfo_Annotation: {
|
|
|
50951
50951
|
end?: number | undefined;
|
|
50952
50952
|
} & Record<Exclude<keyof I, keyof GeneratedCodeInfo_Annotation>, never>>(object: I): GeneratedCodeInfo_Annotation;
|
|
50953
50953
|
};
|
|
50954
|
-
|
|
50955
|
-
export
|
|
50954
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
50955
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
50956
50956
|
$case: string;
|
|
50957
50957
|
} ? {
|
|
50958
50958
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -50961,8 +50961,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
50961
50961
|
} : T extends {} ? {
|
|
50962
50962
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
50963
50963
|
} : Partial<T>;
|
|
50964
|
-
|
|
50965
|
-
export
|
|
50964
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
50965
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
50966
50966
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
50967
50967
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
50968
50968
|
export {};
|
|
@@ -81,8 +81,8 @@ export declare const Timestamp: {
|
|
|
81
81
|
nanos?: number | undefined;
|
|
82
82
|
} & Record<Exclude<keyof I, keyof Timestamp>, never>>(object: I): Timestamp;
|
|
83
83
|
};
|
|
84
|
-
|
|
85
|
-
export
|
|
84
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
85
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
86
86
|
$case: string;
|
|
87
87
|
} ? {
|
|
88
88
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -91,8 +91,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
91
91
|
} : T extends {} ? {
|
|
92
92
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
93
93
|
} : Partial<T>;
|
|
94
|
-
|
|
95
|
-
export
|
|
94
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
95
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
96
96
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
97
97
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
98
98
|
export {};
|
|
@@ -162,12 +162,12 @@ export declare const BytesValue: {
|
|
|
162
162
|
value?: Uint8Array | undefined;
|
|
163
163
|
} & Record<Exclude<keyof I, "value">, never>>(object: I): BytesValue;
|
|
164
164
|
};
|
|
165
|
-
|
|
166
|
-
export
|
|
165
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
166
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
167
167
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
168
168
|
} : Partial<T>;
|
|
169
|
-
|
|
170
|
-
export
|
|
169
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
170
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
171
171
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
172
172
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
173
173
|
export {};
|
|
@@ -25,8 +25,8 @@ export declare const Geocircle: {
|
|
|
25
25
|
} & Record<Exclude<keyof I["center"], keyof Geopoint>, never>) | undefined;
|
|
26
26
|
} & Record<Exclude<keyof I, keyof Geocircle>, never>>(object: I): Geocircle;
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
export
|
|
28
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
29
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
30
30
|
$case: string;
|
|
31
31
|
} ? {
|
|
32
32
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -35,8 +35,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
35
35
|
} : T extends {} ? {
|
|
36
36
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
37
37
|
} : Partial<T>;
|
|
38
|
-
|
|
39
|
-
export
|
|
38
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
39
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
40
40
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
41
41
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
42
42
|
export {};
|
|
@@ -15,8 +15,8 @@ export declare const Geopoint: {
|
|
|
15
15
|
longitude?: number | undefined;
|
|
16
16
|
} & Record<Exclude<keyof I, keyof Geopoint>, never>>(object: I): Geopoint;
|
|
17
17
|
};
|
|
18
|
-
|
|
19
|
-
export
|
|
18
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
19
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
20
20
|
$case: string;
|
|
21
21
|
} ? {
|
|
22
22
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -25,8 +25,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
25
25
|
} : T extends {} ? {
|
|
26
26
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
27
27
|
} : Partial<T>;
|
|
28
|
-
|
|
29
|
-
export
|
|
28
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
29
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
30
30
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
31
31
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
32
32
|
export {};
|
|
@@ -12,8 +12,8 @@ export declare const LaunchParams: {
|
|
|
12
12
|
data?: Uint8Array | undefined;
|
|
13
13
|
} & Record<Exclude<keyof I, "data">, never>>(object: I): LaunchParams;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
16
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
17
17
|
$case: string;
|
|
18
18
|
} ? {
|
|
19
19
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -22,8 +22,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
22
22
|
} : T extends {} ? {
|
|
23
23
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
24
24
|
} : Partial<T>;
|
|
25
|
-
|
|
26
|
-
export
|
|
25
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
26
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
27
27
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
28
28
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
29
29
|
export {};
|
|
@@ -348,8 +348,8 @@ export declare const LaunchData: {
|
|
|
348
348
|
apiDescriptors?: (LaunchData_ApiDescriptor[] & LaunchData_ApiDescriptor[] & Record<Exclude<keyof I["apiDescriptors"], keyof LaunchData_ApiDescriptor[]>, never>) | undefined;
|
|
349
349
|
} & Record<Exclude<keyof I, keyof LaunchData>, never>>(object: I): LaunchData;
|
|
350
350
|
};
|
|
351
|
-
|
|
352
|
-
export
|
|
351
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
352
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
353
353
|
$case: string;
|
|
354
354
|
} ? {
|
|
355
355
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -358,8 +358,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
358
358
|
} : T extends {} ? {
|
|
359
359
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
360
360
|
} : Partial<T>;
|
|
361
|
-
|
|
362
|
-
export
|
|
361
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
362
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
363
363
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
364
364
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
365
365
|
export {};
|
|
@@ -96,8 +96,8 @@ export declare const Lures: {
|
|
|
96
96
|
} & Record<Exclude<keyof I["closestLure"], keyof Geocircle>, never>) | undefined;
|
|
97
97
|
} & Record<Exclude<keyof I, keyof Lures>, never>>(object: I): Lures;
|
|
98
98
|
};
|
|
99
|
-
|
|
100
|
-
export
|
|
99
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
100
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
101
101
|
$case: string;
|
|
102
102
|
} ? {
|
|
103
103
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -106,8 +106,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
106
106
|
} : T extends {} ? {
|
|
107
107
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
108
108
|
} : Partial<T>;
|
|
109
|
-
|
|
110
|
-
export
|
|
109
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
110
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
111
111
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
112
112
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
113
113
|
export {};
|
|
@@ -12,8 +12,8 @@ export declare const PersistentStore: {
|
|
|
12
12
|
store?: Uint8Array | undefined;
|
|
13
13
|
} & Record<Exclude<keyof I, "store">, never>>(object: I): PersistentStore;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
16
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
17
17
|
$case: string;
|
|
18
18
|
} ? {
|
|
19
19
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -22,8 +22,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
22
22
|
} : T extends {} ? {
|
|
23
23
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
24
24
|
} : Partial<T>;
|
|
25
|
-
|
|
26
|
-
export
|
|
25
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
26
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
27
27
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
28
28
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
29
29
|
export {};
|
|
@@ -904,8 +904,8 @@ export declare const SnappableEncryptedKey: {
|
|
|
904
904
|
encryptionKeyIv?: Uint8Array | undefined;
|
|
905
905
|
} & Record<Exclude<keyof I, keyof SnappableEncryptedKey>, never>>(object: I): SnappableEncryptedKey;
|
|
906
906
|
};
|
|
907
|
-
|
|
908
|
-
export
|
|
907
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
908
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
909
909
|
$case: string;
|
|
910
910
|
} ? {
|
|
911
911
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -914,8 +914,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
914
914
|
} : T extends {} ? {
|
|
915
915
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
916
916
|
} : Partial<T>;
|
|
917
|
-
|
|
918
|
-
export
|
|
917
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
918
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
919
919
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
920
920
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
921
921
|
export {};
|
|
@@ -230,8 +230,8 @@ export declare const UserDataList: {
|
|
|
230
230
|
}[]>, never>) | undefined;
|
|
231
231
|
} & Record<Exclude<keyof I, "userData">, never>>(object: I): UserDataList;
|
|
232
232
|
};
|
|
233
|
-
|
|
234
|
-
export
|
|
233
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
234
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
|
235
235
|
$case: string;
|
|
236
236
|
} ? {
|
|
237
237
|
[K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
|
|
@@ -240,8 +240,8 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Array<inf
|
|
|
240
240
|
} : T extends {} ? {
|
|
241
241
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
242
242
|
} : Partial<T>;
|
|
243
|
-
|
|
244
|
-
export
|
|
243
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
244
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
245
245
|
[K in keyof P]: Exact<P[K], I[K]>;
|
|
246
246
|
} & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
|
|
247
247
|
export {};
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type RequestMetadata = {
|
|
2
2
|
signal?: AbortSignal | null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* When calling a handler, if that handler is part of a handler chain, then by default an abort signal will be
|
|
5
|
+
* sent to that handler if another handler higher up in the chain completes first. Usually this is desirable,
|
|
6
|
+
* since we know if a handler higher up in the chain has completed and returned a response to its caller, then
|
|
7
|
+
* the response from all the handlers below it in the chain will not be used.
|
|
8
|
+
*
|
|
9
|
+
* But in some cases, a handler in a handler chain wants to call the next handler in the chain as a
|
|
10
|
+
* side-effect. If a handler is called as a side-effect, it will not be sent an abort signal when handlers
|
|
11
|
+
* higher up in the chain complete.
|
|
12
|
+
*
|
|
13
|
+
* For example: a caching handler might return a cached value immediately, but then call the next handler as
|
|
14
|
+
* a side-effect to fetch an updated value to refresh the cache in the background. In that case, the next
|
|
15
|
+
* handler should not be sent an abort signal when the caching handler returns the cached value.
|
|
16
|
+
*/
|
|
17
|
+
isSideEffect?: boolean;
|
|
3
18
|
} | undefined;
|
|
4
|
-
export
|
|
5
|
-
export
|
|
19
|
+
export type Handler<Req, Res, Meta extends RequestMetadata> = (req: Req, metadata?: Meta) => Promise<Res>;
|
|
20
|
+
export type ChainableHandler<Req, Res, NextReq, NextRes, Meta extends RequestMetadata | undefined> = (next: Handler<NextReq, NextRes, Meta>) => Handler<Req, Res, Meta>;
|
|
6
21
|
/**
|
|
7
22
|
* Creates a Handler chain – a series of functions composed such that each function may call a supplied `next` function
|
|
8
23
|
* which passes execution down the chain. When the final Handler in the chain returns, execution passes back up the
|
|
@@ -149,6 +149,13 @@ export class HandlerChainBuilder {
|
|
|
149
149
|
const innerHandler = new Proxy(this.inner, {
|
|
150
150
|
apply: (target, thisArg, args) => {
|
|
151
151
|
const [req, metadata] = args;
|
|
152
|
+
// When calling the inner handler, we may not care about the result and don't want the handler's
|
|
153
|
+
// operation to be interrupted by an abort signal. For example, we might be calling the inner
|
|
154
|
+
// handler as a side-effect which we want to continue after the outer handler has completed.
|
|
155
|
+
//
|
|
156
|
+
// A concrete example: returning a value from cache immediately, but then calling the inner handler
|
|
157
|
+
// as a side-effect to refresh the cache "in the background."
|
|
158
|
+
const innerSignal = (metadata === null || metadata === void 0 ? void 0 : metadata.isSideEffect) ? undefined : signal;
|
|
152
159
|
// To help Handler authors out, we'll do some bookkeeping and cleanup for them – if they forget to
|
|
153
160
|
// remove an abort event listener, we'll remove it for them when the Promise they return resolves.
|
|
154
161
|
// Note: No need to proxy removeEventListener, since removing a non-existent listener just no-ops.
|
|
@@ -169,7 +176,7 @@ export class HandlerChainBuilder {
|
|
|
169
176
|
};
|
|
170
177
|
const innerResponse = Reflect.apply(target, thisArg, [
|
|
171
178
|
req,
|
|
172
|
-
Object.assign(Object.assign({}, metadata), { signal }),
|
|
179
|
+
Object.assign(Object.assign({}, metadata), { signal: innerSignal }),
|
|
173
180
|
]);
|
|
174
181
|
// Using `finally` is more idiomatic, but causes trouble in some environments (e.g. some testing
|
|
175
182
|
// runtimes which detect uncaught rejected promises).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HandlerChainBuilder.js","sourceRoot":"","sources":["../../src/handlers/HandlerChainBuilder.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,MAAM,OAAO,mBAAmB;IAG5B,YAAY,KAAiD;QACzD,8CAA8C;QAC9C,EAAE;QACF,qFAAqF;QACrF,iCAAiC;QACjC,yBAAyB;QACzB,EAAE;QACF,gHAAgH;QAChH,+GAA+G;QAC/G,iEAAiE;QACjE,EAAE;QACF,oFAAoF;QACpF,iCAAiC;QACjC,yBAAyB;QACzB,EAAE;QACF,2DAA2D;QAC3D,EAAE;QACF,+EAA+E;QAC/E,EAAE;QACF,uGAAuG;QACvG,8GAA8G;QAC9G,2FAA2F;QAC3F,EAAE;QACF,wGAAwG;QACxG,6GAA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UAAU,CAAC,CAAC;YAC/C,OAAO,aAAa,CAAC;QACzB,CAAC,CAAC;QACF,OAAO,IAAI,mBAAmB,CAAC,YAAiD,CAAC,CAAC;IACtF,CAAC;CACJ","sourcesContent":["export type RequestMetadata =\n | {\n signal?: AbortSignal | null | undefined;\n }\n | undefined;\nexport type Handler<Req, Res, Meta extends RequestMetadata> = (req: Req, metadata?: Meta) => Promise<Res>;\nexport type ChainableHandler<Req, Res, NextReq, NextRes, Meta extends RequestMetadata | undefined> = (\n next: Handler<NextReq, NextRes, Meta>\n) => Handler<Req, Res, Meta>;\n\n/**\n * Creates a Handler chain – a series of functions composed such that each function may call a supplied `next` function\n * which passes execution down the chain. When the final Handler in the chain returns, execution passes back up the\n * chain eventually returning to the caller.\n *\n * Each Handler chain begins with a \"raw\" Handler – this is a function which takes some request and returns some\n * response. A chain is then created by supplying a series of mapping functions – the ChainableHandler type – which will\n * be called with the `next` Handler in the chain.\n *\n * Ex:\n * ```ts\n * const handler = (request: string, metadata?: RequestMetadata) => Promise.resolve(`Responded to ${request}`)\n * const chainable = (next: Handler<string, string>) => (request: string, metadata?: RequestMetadata) => {\n * return next(`modified ${request}`, metadata)\n * }\n *\n * const chain = new HandlerChainBuilder(handler)\n * .map(chainable)\n * .handler\n *\n * const response = await chain('hello')\n * expect(response).toBe('Responded to modified hello; 0')\n * ```\n * You can largely ignore the `metadata` argument present in the above example. This is the mechanism by which an\n * AbortSignal is passed to each Handler in the chain, but the only real requirement when implementing a Handler is\n * to pass this argument along to the `next` function. In fact, many Handlers will want to be generic over the type\n * of metadata:\n * ```ts\n * const chainable = <Meta>(next: Handler<string, string, Meta>) => (request: string, metadata: Meta) => {\n * return next(`modified ${request}`, metadata)\n * }\n * ```\n * Actually, it's a very good idea for Handlers to be as generic as possible, since that will allow greater re-use. In\n * the above example, we don't do anything with the response from `next`, so we can let that be generic, too:\n * ```ts\n * const chainable = <Res, Meta>(next: Handler<string, Res, Meta>) => (request: string, metadata: Meta) => {\n * return next(`modified ${request}`, metadata)\n * }\n * ```\n * Now if some other Handler in the chain decides to return a different response type, our Handler won't require any\n * changes to compile.\n *\n * ---\n *\n * Since execution passes from handler to handler in the chain, and then back, handlers have the opportunity to modify\n * or observe both the request and response. This might be useful for implementing serialization/deserialization, but\n * the simplest example that demonstrates this feature is measuring request latency:\n * ```ts\n * const latencyMeasuringHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) =>\n * async (req: Req, metadata: Meta) => {\n * const start = performance.now()\n * const response = await next(req, metadata)\n * const latency = performance.now() - start\n * console.log(`latency for request ${request} was ${latency}`)\n * return response\n * }\n * ```\n * Execution is first passed to our measuring handler, which marks the `start` timestamp. Then it passes execution on\n * down the chain. After a response is received (by some handler down the chain), execution passes back up to our\n * handler here, which records the amount of time spent inside `next`.\n *\n * ---\n *\n * Handlers may also abort requests. They can do this in two ways:\n * 1. Create an `AbortController` and add its `AbortSignal` to the `metadata` object when calling `next`.\n * 2. Resolve its returned Promise.\n *\n * The first approach is straightforward, but the second may benefit from an example – the simplest is a handler which\n * will timeout a request:\n * ```ts\n * const timeoutHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) => (req: Req, metadata: Meta) => {\n * return Promise.race([\n * next(req, metadata),\n * sleep(1000),\n * ])\n * }\n * ```\n * The Promise returned by this handler will resolve either when the `next` handler resolves or 1 second has elapsed,\n * whichever happens first. If the timeout happens first, we want the `next` handler to recieve an abort signal so that\n * it can terminate early (since its result is no longer needed).\n *\n * HandlerChainBuilder makes this happen by observing when each handler completes, and sending an abort signal to all\n * the handlers \"downstream\" from the aborting handler.\n */\nexport class HandlerChainBuilder<Req, Res, Meta extends RequestMetadata> {\n private readonly inner: Handler<Req, Res, Meta>;\n\n constructor(inner: (req: Req, metadata: Meta) => Promise<Res>) {\n // The TS compiler has the following behavior:\n //\n // class Infer<T extends SomeType | undefined> { constructor(f: (t?: T) => void) {} }\n // const f = (t?: SomeType) => {}\n // const i = new Infer(f)\n //\n // The type of `i` is inferred to be `Infer<SomeType>` instead of `Infer<SomeType | undefined>`, even though the\n // type of `f`'s argument is `SomeType | undefined`. This seems to be a bug in type inference. Note that making\n // the constructor argument required gives the expected behavior:\n //\n // class Infer<T extends SomeType | undefined> { constructor(f: (t: T) => void) {} }\n // const f = (t?: SomeType) => {}\n // const i = new Infer(f)\n //\n // Now `i` is inferred to be `Infer<SomeType | undefined>`.\n //\n // This has consequences if the inferred type T is used elsewhere in the class.\n //\n // In this case, we need to make sure that if the given `inner` function marks the metadata argument as\n // optional, that HandlerChainBuilder correctly infers that the Meta type includes undefined. So we don't mark\n // metadata as optional, and so we must cast to `Handler` (which does mark it as optional).\n //\n // Safety: We're adding `| undefined` to the metadata type, which may be unsafe – `undefined` may not be\n // assignable to Meta. But when handling the argument of type Meta, we simply pass it through from handler to\n // handler – we never call `inner` without passing the metadata argument we've received from some call to an\n // outer handler. The typing visible to callers remains safe.\n this.inner = inner as Handler<Req, Res, Meta>;\n }\n\n get handler(): Handler<Req, Res, Meta> {\n return this.inner;\n }\n\n map<PriorReq, PriorRes>(\n outer: ChainableHandler<PriorReq, PriorRes, Req, Res, Meta>\n ): HandlerChainBuilder<PriorReq, PriorRes, Meta> {\n // To create the next handler in the chain, we compose the \"outer\" handler with the \"inner\" handler.\n //\n // The outer handler observes its own completion and sends an abort signal to the inner handler when it has\n // resolved. To prevent unexpected behavior, the inner handler also observes its own completion, setting a flag\n // when it resolves so that – if it resolves before the outer handler – the outer handler can skip sending the\n // abort signal (since the inner handler has already completed).\n const outerHandler = (req: PriorReq, metadata: Meta): Promise<PriorRes> => {\n const abort = new AbortController();\n const signal = abort.signal;\n\n // It's important to not signal an abort to an inner handler which has already completed – it seems like\n // this would be a non-issue (shouldn't aborting after completion be a no-op?), but specifically for the\n // browser's implementation of `fetch`, aborting even after the `fetch` Promise resolves can cause an abort\n // error if e.g. the Fetch Response's body has not yet been read.\n //\n // So, for safety, we will only abort inner handlers which are still executing.\n let innerCompleted = false;\n\n const maybeAbort = () => {\n // Safety: we never give `abort` to anyone else, so we know if the signal is aborted, this function\n // has already run, so we can return early without fear of leaking. We also know if inner has completed,\n // it has already performed cleanup.\n if (signal.aborted || innerCompleted) return;\n\n // If we've gotten here, the outer handler has either completed, or we heard an abort event while the\n // inner handler is still executing – so we pass the abort signal down to the inner handler.\n abort.abort();\n metadata?.signal?.removeEventListener(\"abort\", maybeAbort);\n };\n\n metadata?.signal?.addEventListener(\"abort\", maybeAbort);\n\n const innerHandler = new Proxy(this.inner, {\n apply: (target, thisArg, args) => {\n const [req, metadata] = args as Parameters<typeof target>;\n\n // To help Handler authors out, we'll do some bookkeeping and cleanup for them – if they forget to\n // remove an abort event listener, we'll remove it for them when the Promise they return resolves.\n // Note: No need to proxy removeEventListener, since removing a non-existent listener just no-ops.\n const abortListeners: EventListenerOrEventListenerObject[] = [];\n signal.addEventListener = new Proxy(signal.addEventListener, {\n apply: (target, thisArg, args) => {\n abortListeners.push(args[1]);\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n const cleanupAndMarkComplete = () => {\n // The only reason we listen to upstream aborts is to pass them to the inner handler – since the\n // inner handler has completed, we no longer need the listener.\n metadata?.signal?.removeEventListener(\"abort\", maybeAbort);\n abortListeners.forEach((listener) => signal.removeEventListener(\"abort\", listener));\n innerCompleted = true;\n };\n\n const innerResponse: ReturnType<typeof target> = Reflect.apply(target, thisArg, [\n req,\n { ...metadata, signal },\n ]);\n\n // Using `finally` is more idiomatic, but causes trouble in some environments (e.g. some testing\n // runtimes which detect uncaught rejected promises).\n innerResponse.catch(() => {}).then(cleanupAndMarkComplete);\n return innerResponse;\n },\n });\n\n const outerResponse = outer(innerHandler)(req, metadata);\n outerResponse.catch(() => {}).then(maybeAbort);\n return outerResponse;\n };\n return new HandlerChainBuilder(outerHandler as Handler<PriorReq, PriorRes, Meta>);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HandlerChainBuilder.js","sourceRoot":"","sources":["../../src/handlers/HandlerChainBuilder.ts"],"names":[],"mappings":"AAy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AAmB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;wBAC3D,cAAc,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;wBACpF,cAAc,GAAG,IAAI,CAAC;oBAC1B,CAAC,CAAC;oBAEF,MAAM,aAAa,GAA8B,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE;wBAC5E,GAAG;wDACE,QAAQ,KAAE,MAAM,EAAE,WAAW;qBACrC,CAAC,CAAC;oBAEH,gGAAgG;oBAChG,qDAAqD;oBACrD,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;oBAC3D,OAAO,aAAa,CAAC;gBACzB,CAAC;aACJ,CAAC,CAAC;YAEH,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACzD,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC/C,OAAO,aAAa,CAAC;QACzB,CAAC,CAAC;QACF,OAAO,IAAI,mBAAmB,CAAC,YAAiD,CAAC,CAAC;IACtF,CAAC;CACJ","sourcesContent":["export type RequestMetadata =\n | {\n signal?: AbortSignal | null | undefined;\n /**\n * When calling a handler, if that handler is part of a handler chain, then by default an abort signal will be\n * sent to that handler if another handler higher up in the chain completes first. Usually this is desirable,\n * since we know if a handler higher up in the chain has completed and returned a response to its caller, then\n * the response from all the handlers below it in the chain will not be used.\n *\n * But in some cases, a handler in a handler chain wants to call the next handler in the chain as a\n * side-effect. If a handler is called as a side-effect, it will not be sent an abort signal when handlers\n * higher up in the chain complete.\n *\n * For example: a caching handler might return a cached value immediately, but then call the next handler as\n * a side-effect to fetch an updated value to refresh the cache in the background. In that case, the next\n * handler should not be sent an abort signal when the caching handler returns the cached value.\n */\n isSideEffect?: boolean;\n }\n | undefined;\nexport type Handler<Req, Res, Meta extends RequestMetadata> = (req: Req, metadata?: Meta) => Promise<Res>;\nexport type ChainableHandler<Req, Res, NextReq, NextRes, Meta extends RequestMetadata | undefined> = (\n next: Handler<NextReq, NextRes, Meta>\n) => Handler<Req, Res, Meta>;\n\n/**\n * Creates a Handler chain – a series of functions composed such that each function may call a supplied `next` function\n * which passes execution down the chain. When the final Handler in the chain returns, execution passes back up the\n * chain eventually returning to the caller.\n *\n * Each Handler chain begins with a \"raw\" Handler – this is a function which takes some request and returns some\n * response. A chain is then created by supplying a series of mapping functions – the ChainableHandler type – which will\n * be called with the `next` Handler in the chain.\n *\n * Ex:\n * ```ts\n * const handler = (request: string, metadata?: RequestMetadata) => Promise.resolve(`Responded to ${request}`)\n * const chainable = (next: Handler<string, string>) => (request: string, metadata?: RequestMetadata) => {\n * return next(`modified ${request}`, metadata)\n * }\n *\n * const chain = new HandlerChainBuilder(handler)\n * .map(chainable)\n * .handler\n *\n * const response = await chain('hello')\n * expect(response).toBe('Responded to modified hello; 0')\n * ```\n * You can largely ignore the `metadata` argument present in the above example. This is the mechanism by which an\n * AbortSignal is passed to each Handler in the chain, but the only real requirement when implementing a Handler is\n * to pass this argument along to the `next` function. In fact, many Handlers will want to be generic over the type\n * of metadata:\n * ```ts\n * const chainable = <Meta>(next: Handler<string, string, Meta>) => (request: string, metadata: Meta) => {\n * return next(`modified ${request}`, metadata)\n * }\n * ```\n * Actually, it's a very good idea for Handlers to be as generic as possible, since that will allow greater re-use. In\n * the above example, we don't do anything with the response from `next`, so we can let that be generic, too:\n * ```ts\n * const chainable = <Res, Meta>(next: Handler<string, Res, Meta>) => (request: string, metadata: Meta) => {\n * return next(`modified ${request}`, metadata)\n * }\n * ```\n * Now if some other Handler in the chain decides to return a different response type, our Handler won't require any\n * changes to compile.\n *\n * ---\n *\n * Since execution passes from handler to handler in the chain, and then back, handlers have the opportunity to modify\n * or observe both the request and response. This might be useful for implementing serialization/deserialization, but\n * the simplest example that demonstrates this feature is measuring request latency:\n * ```ts\n * const latencyMeasuringHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) =>\n * async (req: Req, metadata: Meta) => {\n * const start = performance.now()\n * const response = await next(req, metadata)\n * const latency = performance.now() - start\n * console.log(`latency for request ${request} was ${latency}`)\n * return response\n * }\n * ```\n * Execution is first passed to our measuring handler, which marks the `start` timestamp. Then it passes execution on\n * down the chain. After a response is received (by some handler down the chain), execution passes back up to our\n * handler here, which records the amount of time spent inside `next`.\n *\n * ---\n *\n * Handlers may also abort requests. They can do this in two ways:\n * 1. Create an `AbortController` and add its `AbortSignal` to the `metadata` object when calling `next`.\n * 2. Resolve its returned Promise.\n *\n * The first approach is straightforward, but the second may benefit from an example – the simplest is a handler which\n * will timeout a request:\n * ```ts\n * const timeoutHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) => (req: Req, metadata: Meta) => {\n * return Promise.race([\n * next(req, metadata),\n * sleep(1000),\n * ])\n * }\n * ```\n * The Promise returned by this handler will resolve either when the `next` handler resolves or 1 second has elapsed,\n * whichever happens first. If the timeout happens first, we want the `next` handler to recieve an abort signal so that\n * it can terminate early (since its result is no longer needed).\n *\n * HandlerChainBuilder makes this happen by observing when each handler completes, and sending an abort signal to all\n * the handlers \"downstream\" from the aborting handler.\n */\nexport class HandlerChainBuilder<Req, Res, Meta extends RequestMetadata> {\n private readonly inner: Handler<Req, Res, Meta>;\n\n constructor(inner: (req: Req, metadata: Meta) => Promise<Res>) {\n // The TS compiler has the following behavior:\n //\n // class Infer<T extends SomeType | undefined> { constructor(f: (t?: T) => void) {} }\n // const f = (t?: SomeType) => {}\n // const i = new Infer(f)\n //\n // The type of `i` is inferred to be `Infer<SomeType>` instead of `Infer<SomeType | undefined>`, even though the\n // type of `f`'s argument is `SomeType | undefined`. This seems to be a bug in type inference. Note that making\n // the constructor argument required gives the expected behavior:\n //\n // class Infer<T extends SomeType | undefined> { constructor(f: (t: T) => void) {} }\n // const f = (t?: SomeType) => {}\n // const i = new Infer(f)\n //\n // Now `i` is inferred to be `Infer<SomeType | undefined>`.\n //\n // This has consequences if the inferred type T is used elsewhere in the class.\n //\n // In this case, we need to make sure that if the given `inner` function marks the metadata argument as\n // optional, that HandlerChainBuilder correctly infers that the Meta type includes undefined. So we don't mark\n // metadata as optional, and so we must cast to `Handler` (which does mark it as optional).\n //\n // Safety: We're adding `| undefined` to the metadata type, which may be unsafe – `undefined` may not be\n // assignable to Meta. But when handling the argument of type Meta, we simply pass it through from handler to\n // handler – we never call `inner` without passing the metadata argument we've received from some call to an\n // outer handler. The typing visible to callers remains safe.\n this.inner = inner as Handler<Req, Res, Meta>;\n }\n\n get handler(): Handler<Req, Res, Meta> {\n return this.inner;\n }\n\n map<PriorReq, PriorRes>(\n outer: ChainableHandler<PriorReq, PriorRes, Req, Res, Meta>\n ): HandlerChainBuilder<PriorReq, PriorRes, Meta> {\n // To create the next handler in the chain, we compose the \"outer\" handler with the \"inner\" handler.\n //\n // The outer handler observes its own completion and sends an abort signal to the inner handler when it has\n // resolved. To prevent unexpected behavior, the inner handler also observes its own completion, setting a flag\n // when it resolves so that – if it resolves before the outer handler – the outer handler can skip sending the\n // abort signal (since the inner handler has already completed).\n const outerHandler = (req: PriorReq, metadata: Meta): Promise<PriorRes> => {\n const abort = new AbortController();\n const signal = abort.signal;\n\n // It's important to not signal an abort to an inner handler which has already completed – it seems like\n // this would be a non-issue (shouldn't aborting after completion be a no-op?), but specifically for the\n // browser's implementation of `fetch`, aborting even after the `fetch` Promise resolves can cause an abort\n // error if e.g. the Fetch Response's body has not yet been read.\n //\n // So, for safety, we will only abort inner handlers which are still executing.\n let innerCompleted = false;\n\n const maybeAbort = () => {\n // Safety: we never give `abort` to anyone else, so we know if the signal is aborted, this function\n // has already run, so we can return early without fear of leaking. We also know if inner has completed,\n // it has already performed cleanup.\n if (signal.aborted || innerCompleted) return;\n\n // If we've gotten here, the outer handler has either completed, or we heard an abort event while the\n // inner handler is still executing – so we pass the abort signal down to the inner handler.\n abort.abort();\n metadata?.signal?.removeEventListener(\"abort\", maybeAbort);\n };\n\n metadata?.signal?.addEventListener(\"abort\", maybeAbort);\n\n const innerHandler = new Proxy(this.inner, {\n apply: (target, thisArg, args) => {\n const [req, metadata] = args as Parameters<typeof target>;\n\n // When calling the inner handler, we may not care about the result and don't want the handler's\n // operation to be interrupted by an abort signal. For example, we might be calling the inner\n // handler as a side-effect which we want to continue after the outer handler has completed.\n //\n // A concrete example: returning a value from cache immediately, but then calling the inner handler\n // as a side-effect to refresh the cache \"in the background.\"\n const innerSignal = metadata?.isSideEffect ? undefined : signal;\n\n // To help Handler authors out, we'll do some bookkeeping and cleanup for them – if they forget to\n // remove an abort event listener, we'll remove it for them when the Promise they return resolves.\n // Note: No need to proxy removeEventListener, since removing a non-existent listener just no-ops.\n const abortListeners: EventListenerOrEventListenerObject[] = [];\n signal.addEventListener = new Proxy(signal.addEventListener, {\n apply: (target, thisArg, args) => {\n abortListeners.push(args[1]);\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n const cleanupAndMarkComplete = () => {\n // The only reason we listen to upstream aborts is to pass them to the inner handler – since the\n // inner handler has completed, we no longer need the listener.\n metadata?.signal?.removeEventListener(\"abort\", maybeAbort);\n abortListeners.forEach((listener) => signal.removeEventListener(\"abort\", listener));\n innerCompleted = true;\n };\n\n const innerResponse: ReturnType<typeof target> = Reflect.apply(target, thisArg, [\n req,\n { ...metadata, signal: innerSignal },\n ]);\n\n // Using `finally` is more idiomatic, but causes trouble in some environments (e.g. some testing\n // runtimes which detect uncaught rejected promises).\n innerResponse.catch(() => {}).then(cleanupAndMarkComplete);\n return innerResponse;\n },\n });\n\n const outerResponse = outer(innerHandler)(req, metadata);\n outerResponse.catch(() => {}).then(maybeAbort);\n return outerResponse;\n };\n return new HandlerChainBuilder(outerHandler as Handler<PriorReq, PriorRes, Meta>);\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainableHandler, RequestMetadata } from "./HandlerChainBuilder";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type ArrayBufferResponse = [ArrayBuffer, Response];
|
|
3
|
+
type ChainableArrayBufferHandler<Req, Meta extends RequestMetadata> = ChainableHandler<Req, ArrayBufferResponse, Req, Response, Meta>;
|
|
4
4
|
/**
|
|
5
5
|
* Parse a Fetch Response body into an ArrayBuffer.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayBufferParsingHandler.js","sourceRoot":"","sources":["../../src/handlers/arrayBufferParsingHandler.ts"],"names":[],"mappings":";AAWA;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,
|
|
1
|
+
{"version":3,"file":"arrayBufferParsingHandler.js","sourceRoot":"","sources":["../../src/handlers/arrayBufferParsingHandler.ts"],"names":[],"mappings":";AAWA;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GACxC,GAA8E,EAAE,CAChF,CAAC,IAAI,EAAE,EAAE,CACT,CAAO,GAAG,EAAE,QAAQ,EAAE,EAAE;IACpB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC3C,IAAI,MAAmB,CAAC;IACxB,IAAI;QACA,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;KAC/B;IACD,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC9B,CAAC,CAAA,CAAC","sourcesContent":["import { ChainableHandler, RequestMetadata } from \"./HandlerChainBuilder\";\n\ntype ArrayBufferResponse = [ArrayBuffer, Response];\ntype ChainableArrayBufferHandler<Req, Meta extends RequestMetadata> = ChainableHandler<\n Req,\n ArrayBufferResponse,\n Req,\n Response,\n Meta\n>;\n\n/**\n * Parse a Fetch Response body into an ArrayBuffer.\n *\n * @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}\n */\nexport const createArrayBufferParsingHandler =\n <Req, Meta extends RequestMetadata>(): ChainableArrayBufferHandler<Req, Meta> =>\n (next) =>\n async (req, metadata) => {\n const response = await next(req, metadata);\n let buffer: ArrayBuffer;\n try {\n buffer = await response.arrayBuffer();\n } catch (_) {\n buffer = new ArrayBuffer(0);\n }\n return [buffer, response];\n };\n"]}
|
|
@@ -6,7 +6,7 @@ import { FetchHandler } from "./defaultFetchHandler";
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export declare const cameraKitServiceFetchHandlerFactory: {
|
|
9
|
-
(args_0: CameraKitConfiguration, args_1: FetchHandler
|
|
9
|
+
(args_0: CameraKitConfiguration, args_1: FetchHandler): import("./HandlerChainBuilder").Handler<RequestInfo, Response, RequestInit | undefined>;
|
|
10
10
|
token: "cameraKitServiceFetchHandler";
|
|
11
11
|
dependencies: readonly ["configuration", "defaultFetchHandler"];
|
|
12
12
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type FetchHandler<R = Response> = (input: RequestInfo, init?: RequestInit) => Promise<R>;
|
|
2
2
|
/**
|
|
3
3
|
* The default Fetch implementation, used to make a simple HTTP requests without any custom headers. This can be passed
|
|
4
4
|
* to `HandlerChainBuilder` to form the basis for other Fetch implementations (e.g. with custom headers, which extract
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
6
6
|
*/
|
|
7
7
|
export const createHeadersModifyingFetchHandler = (modifyHeaders) => (next) => (input, init) => {
|
|
8
|
-
const headers = init && init.headers
|
|
8
|
+
const headers = init && init.headers
|
|
9
|
+
? new Headers(init.headers)
|
|
10
|
+
: typeof input === "string"
|
|
11
|
+
? new Headers()
|
|
12
|
+
: input.headers;
|
|
9
13
|
const modifiedHeaders = modifyHeaders(headers);
|
|
10
14
|
// When `init` contains headers, `fetch` uses these *instead* of any headers found in the `input` Request.
|
|
11
15
|
return next(input, Object.assign(Object.assign({}, init), { headers: modifiedHeaders }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headersModifyingFetchHandler.js","sourceRoot":"","sources":["../../src/handlers/headersModifyingFetchHandler.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kCAAkC,
|
|
1
|
+
{"version":3,"file":"headersModifyingFetchHandler.js","sourceRoot":"","sources":["../../src/handlers/headersModifyingFetchHandler.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC3C,CACI,aAA4C,EACiC,EAAE,CACnF,CAAC,IAAI,EAAE,EAAE,CACT,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IACZ,MAAM,OAAO,GACT,IAAI,IAAI,IAAI,CAAC,OAAO;QAChB,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;QAC3B,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ;YAC3B,CAAC,CAAC,IAAI,OAAO,EAAE;YACf,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAExB,MAAM,eAAe,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAE/C,0GAA0G;IAC1G,OAAO,IAAI,CAAC,KAAK,kCAAO,IAAI,KAAE,OAAO,EAAE,eAAe,IAAG,CAAC;AAC9D,CAAC,CAAC","sourcesContent":["import { ChainableHandler } from \"./HandlerChainBuilder\";\n\n/**\n * Modify a Fetch Request's headers.\n *\n * @param modifyHeaders\n * @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}\n */\nexport const createHeadersModifyingFetchHandler =\n <Res>(\n modifyHeaders: (headers: Headers) => Headers\n ): ChainableHandler<RequestInfo, Res, RequestInfo, Res, RequestInit | undefined> =>\n (next) =>\n (input, init) => {\n const headers =\n init && init.headers\n ? new Headers(init.headers)\n : typeof input === \"string\"\n ? new Headers()\n : input.headers;\n\n const modifiedHeaders = modifyHeaders(headers);\n\n // When `init` contains headers, `fetch` uses these *instead* of any headers found in the `input` Request.\n return next(input, { ...init, headers: modifiedHeaders });\n };\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { getLogger } from "../logger/logger";
|
|
3
|
+
import { ensureClonedRequest } from "./retryingHandler";
|
|
3
4
|
const logger = getLogger("noCorsRetryingFetchHandler");
|
|
4
5
|
const logRetry = (error) => {
|
|
5
6
|
logger.warn(`NoCorsRetrying handler got failed response:`, error, `Retrying request with {mode: "no-cors"}.`);
|
|
@@ -72,7 +73,7 @@ export const createNoCorsRetryingFetchHandler = () => {
|
|
|
72
73
|
// of the request (e.g. the expiration time for a credential). We just make the request, and if it
|
|
73
74
|
// fails, this tells us we've made an invalid request. This does result in one additional request, but
|
|
74
75
|
// it makes this much more flexible and avoids having to maintain state (which can be a source of bugs).
|
|
75
|
-
return yield next(input, init);
|
|
76
|
+
return yield next(ensureClonedRequest(input), init);
|
|
76
77
|
}
|
|
77
78
|
catch (error) {
|
|
78
79
|
// If the request fails because it was aborted, we assume this was done intentionally and we can stop.
|
|
@@ -83,11 +84,11 @@ export const createNoCorsRetryingFetchHandler = () => {
|
|
|
83
84
|
// throw), and we'll just assume it's a CORs error. If it's not, we'll perform a "no-cors" retry anyway,
|
|
84
85
|
// which will presumably also fail, and that failure will be returned to the caller.
|
|
85
86
|
logRetry(error);
|
|
86
|
-
const noCorsRequest = (_a = noCorsRequests.get(requestKey)) !== null && _a !== void 0 ? _a : next(input, Object.assign(Object.assign({}, init), { mode: "no-cors" }));
|
|
87
|
+
const noCorsRequest = (_a = noCorsRequests.get(requestKey)) !== null && _a !== void 0 ? _a : next(ensureClonedRequest(input), Object.assign(Object.assign({}, init), { mode: "no-cors" }));
|
|
87
88
|
noCorsRequests.set(requestKey, noCorsRequest);
|
|
88
89
|
yield noCorsRequest;
|
|
89
90
|
noCorsRequests.delete(requestKey);
|
|
90
|
-
return next(input, init);
|
|
91
|
+
return next(ensureClonedRequest(input), init);
|
|
91
92
|
}
|
|
92
93
|
});
|
|
93
94
|
};
|