@effect-aws/commons 0.2.1 → 0.3.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/HttpHandler/package.json +6 -0
- package/dist/cjs/HttpHandler.d.ts +36 -0
- package/dist/cjs/HttpHandler.d.ts.map +1 -0
- package/dist/cjs/HttpHandler.js +35 -0
- package/dist/cjs/HttpHandler.js.map +1 -0
- package/dist/cjs/Service.d.ts +25 -9
- package/dist/cjs/Service.d.ts.map +1 -1
- package/dist/cjs/Service.js +58 -21
- package/dist/cjs/Service.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/httpHandler.d.ts +6 -0
- package/dist/cjs/internal/httpHandler.d.ts.map +1 -0
- package/dist/cjs/internal/{service.js → httpHandler.js} +1 -1
- package/dist/cjs/internal/httpHandler.js.map +1 -0
- package/dist/dts/HttpHandler.d.ts +36 -0
- package/dist/dts/HttpHandler.d.ts.map +1 -0
- package/dist/dts/Service.d.ts +25 -9
- package/dist/dts/Service.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/httpHandler.d.ts +6 -0
- package/dist/dts/internal/httpHandler.d.ts.map +1 -0
- package/dist/esm/HttpHandler.js +30 -0
- package/dist/esm/HttpHandler.js.map +1 -0
- package/dist/esm/Service.js +36 -22
- package/dist/esm/Service.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/httpHandler.js +2 -0
- package/dist/esm/internal/httpHandler.js.map +1 -0
- package/package.json +12 -3
- package/src/HttpHandler.ts +69 -0
- package/src/Service.ts +84 -27
- package/src/index.ts +5 -0
- package/src/internal/httpHandler.ts +6 -0
- package/dist/cjs/internal/service.d.ts +0 -10
- package/dist/cjs/internal/service.d.ts.map +0 -1
- package/dist/cjs/internal/service.js.map +0 -1
- package/dist/dts/internal/service.d.ts +0 -10
- package/dist/dts/internal/service.d.ts.map +0 -1
- package/dist/esm/internal/service.js +0 -2
- package/dist/esm/internal/service.js.map +0 -1
- package/src/internal/service.ts +0 -14
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.3.0
|
|
3
|
+
*/
|
|
4
|
+
import type { HttpRequest, HttpResponse } from "@smithy/protocol-http";
|
|
5
|
+
import type { HttpHandlerOptions, RequestHandler as ClientRequestHandler, RequestHandlerOutput } from "@smithy/types";
|
|
6
|
+
import type { Cause, Effect } from "effect";
|
|
7
|
+
import { Context, Scope } from "effect";
|
|
8
|
+
import type { RuntimeOptions } from "./internal/httpHandler.js";
|
|
9
|
+
declare const TypeId: unique symbol;
|
|
10
|
+
type RequestHandlerConstructorProps = {
|
|
11
|
+
readonly handle: (request: HttpRequest, handlerOptions?: HttpHandlerOptions) => Effect.Effect<RequestHandlerOutput<HttpResponse>, Cause.TimeoutException, Scope.Scope>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.3.0
|
|
15
|
+
* @category model
|
|
16
|
+
*/
|
|
17
|
+
export interface RequestHandler extends RequestHandlerConstructorProps {
|
|
18
|
+
readonly [TypeId]: typeof TypeId;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @since 0.3.0
|
|
22
|
+
* @category tag
|
|
23
|
+
*/
|
|
24
|
+
export declare const RequestHandler: Context.Tag<RequestHandler, RequestHandler>;
|
|
25
|
+
/**
|
|
26
|
+
* @since 0.3.0
|
|
27
|
+
* @category constructors
|
|
28
|
+
*/
|
|
29
|
+
export declare const make: (options: RequestHandlerConstructorProps) => RequestHandler;
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.3.0
|
|
32
|
+
* @category adapters
|
|
33
|
+
*/
|
|
34
|
+
export declare const toClientRequestHandler: (requestHandler: RequestHandler, config: RuntimeOptions) => ClientRequestHandler<HttpRequest, HttpResponse, HttpHandlerOptions>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=HttpHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpHandler.d.ts","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,IAAI,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACtH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAW,KAAK,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,QAAA,MAAM,MAAM,eAAmD,CAAC;AAEhE,KAAK,8BAA8B,GAAG;IACpC,QAAQ,CAAC,MAAM,EAAE,CACf,OAAO,EAAE,WAAW,EACpB,cAAc,CAAC,EAAE,kBAAkB,KAChC,MAAM,CAAC,MAAM,CAChB,oBAAoB,CAAC,YAAY,CAAC,EAClC,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,KAAK,CACZ,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,8BAA8B;IACpE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,6CAA2E,CAAC;AAMvG;;;GAGG;AACH,eAAO,MAAM,IAAI,YAAa,8BAA8B,KAAG,cACjB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,mBACjB,cAAc,UACtB,cAAc,KACrB,qBAAqB,WAAW,EAAE,YAAY,EAAE,kBAAkB,CAcpE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toClientRequestHandler = exports.make = exports.RequestHandler = void 0;
|
|
4
|
+
const effect_1 = require("effect");
|
|
5
|
+
const TypeId = Symbol.for("@effect-aws/commons/RequestHandler");
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.3.0
|
|
8
|
+
* @category tag
|
|
9
|
+
*/
|
|
10
|
+
exports.RequestHandler = effect_1.Context.GenericTag("@effect-aws/commons/RequestHandler");
|
|
11
|
+
const proto = {
|
|
12
|
+
[TypeId]: TypeId,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @since 0.3.0
|
|
16
|
+
* @category constructors
|
|
17
|
+
*/
|
|
18
|
+
const make = (options) => Object.assign(Object.create(proto), options);
|
|
19
|
+
exports.make = make;
|
|
20
|
+
/**
|
|
21
|
+
* @since 0.3.0
|
|
22
|
+
* @category adapters
|
|
23
|
+
*/
|
|
24
|
+
const toClientRequestHandler = (requestHandler, config) => {
|
|
25
|
+
const runPromise = effect_1.Runtime.runPromise(config.runtime);
|
|
26
|
+
const scoped = effect_1.Scope.extend(config.scope);
|
|
27
|
+
class HttpHandler {
|
|
28
|
+
handle(request, options = {}) {
|
|
29
|
+
return runPromise(requestHandler.handle(request, options).pipe(scoped), { signal: options.abortSignal });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return new HttpHandler();
|
|
33
|
+
};
|
|
34
|
+
exports.toClientRequestHandler = toClientRequestHandler;
|
|
35
|
+
//# sourceMappingURL=HttpHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpHandler.js","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":";;;AAMA,mCAAiD;AAGjD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAqBhE;;;GAGG;AACU,QAAA,cAAc,GAAG,gBAAO,CAAC,UAAU,CAAiB,oCAAoC,CAAC,CAAC;AAEvG,MAAM,KAAK,GAAG;IACZ,CAAC,MAAM,CAAC,EAAE,MAAM;CACjB,CAAC;AAEF;;;GAGG;AACI,MAAM,IAAI,GAAG,CAAC,OAAuC,EAAkB,EAAE,CAC9E,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;AADlC,QAAA,IAAI,QAC8B;AAE/C;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CACpC,cAA8B,EAC9B,MAAsB,EAC+C,EAAE;IACvE,MAAM,UAAU,GAAG,gBAAO,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,cAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE1C,MAAM,WAAW;QACf,MAAM,CAAC,OAAoB,EAAE,UAA8B,EAAE;YAC3D,OAAO,UAAU,CACf,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EACpD,EAAE,MAAM,EAAE,OAAO,CAAC,WAA0B,EAAE,CAC/C,CAAC;QACJ,CAAC;KACF;IAED,OAAO,IAAI,WAAW,EAAE,CAAC;AAC3B,CAAC,CAAC;AAjBW,QAAA,sBAAsB,0BAiBjC"}
|
package/dist/cjs/Service.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.1.0
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import type { Client } from "@smithy/types";
|
|
4
|
+
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
5
|
+
import type { Client, HandlerOptions, Logger, RequestHandler } from "@smithy/types";
|
|
6
6
|
import type { Array } from "effect";
|
|
7
7
|
import { Effect } from "effect";
|
|
8
|
-
import type { TaggedException } from "./Errors.js";
|
|
9
|
-
import { SdkError } from "./Errors.js";
|
|
10
|
-
import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/service.js";
|
|
11
8
|
import type { HttpHandlerOptions } from "./Types.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.3.0
|
|
11
|
+
* @category models
|
|
12
|
+
*/
|
|
13
|
+
export interface LoggerResolvedConfig {
|
|
14
|
+
logger?: Logger;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.0
|
|
18
|
+
* @category models
|
|
19
|
+
*/
|
|
20
|
+
export interface BaseResolvedConfig extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions> {
|
|
21
|
+
requestHandler: RequestHandler<any, any, any>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.3.0
|
|
25
|
+
* @category models
|
|
26
|
+
*/
|
|
27
|
+
export type CommandCtor<I> = new (input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|
|
12
28
|
type ServiceFnOptions = {
|
|
13
29
|
errorTags?: Array.NonEmptyReadonlyArray<string>;
|
|
14
30
|
resolveClientConfig: Effect.Effect<LoggerResolvedConfig>;
|
|
@@ -17,21 +33,21 @@ type ServiceFnOptions = {
|
|
|
17
33
|
* @since 0.1.0
|
|
18
34
|
* @category errors
|
|
19
35
|
*/
|
|
20
|
-
export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) =>
|
|
36
|
+
export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => unknown;
|
|
21
37
|
/**
|
|
22
38
|
* @since 0.1.0
|
|
23
39
|
* @category constructors
|
|
24
40
|
*/
|
|
25
|
-
export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any,
|
|
41
|
+
export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, unknown, never>;
|
|
26
42
|
/**
|
|
27
43
|
* @since 0.1.0
|
|
28
44
|
* @category constructors
|
|
29
45
|
*/
|
|
30
|
-
export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Service
|
|
46
|
+
export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Effect.Effect<Service>;
|
|
31
47
|
/**
|
|
32
48
|
* @since 0.1.0
|
|
33
49
|
* @category constructors
|
|
34
50
|
*/
|
|
35
|
-
export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Service
|
|
51
|
+
export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Effect.Effect<Service>;
|
|
36
52
|
export {};
|
|
37
53
|
//# sourceMappingURL=Service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAEtF,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAmB,cAAc,EAAE,MAAM,eAAe,CAAC;AACrG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,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AACH,eAAO,MAAM,qBAAqB,oBACxB,OAAO,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,YAClC,OAAO,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,WACjC,gBAAgB,KACxB,OAAO,MAAM,CAAC,OAAO,CAC0E,CAAC"}
|
package/dist/cjs/Service.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.fromClientAndCommands = exports.fromCommandsAndServiceFn = exports.makeServiceFn = exports.catchServiceExceptions = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @since 0.1.0
|
|
6
|
-
*/
|
|
7
27
|
const smithy_client_1 = require("@smithy/smithy-client");
|
|
8
28
|
const effect_1 = require("effect");
|
|
9
29
|
const Errors_js_1 = require("./Errors.js");
|
|
30
|
+
const HttpHandler = __importStar(require("./HttpHandler.js"));
|
|
10
31
|
/**
|
|
11
32
|
* @since 0.1.0
|
|
12
33
|
* @category errors
|
|
@@ -17,6 +38,12 @@ const catchServiceExceptions = (errorTags) => (e) => {
|
|
|
17
38
|
return ServiceException({ ...e, message: e.message, stack: e.stack });
|
|
18
39
|
}
|
|
19
40
|
if (e instanceof Error) {
|
|
41
|
+
if (effect_1.Runtime.isFiberFailure(e) && effect_1.Cause.isFailType(e[effect_1.Runtime.FiberFailureCauseId])) {
|
|
42
|
+
return e[effect_1.Runtime.FiberFailureCauseId].error;
|
|
43
|
+
}
|
|
44
|
+
if (e.name === "TimeoutError") {
|
|
45
|
+
return new effect_1.Cause.TimeoutException(e.message);
|
|
46
|
+
}
|
|
20
47
|
return (0, Errors_js_1.SdkError)({ ...e, name: "SdkError", message: e.message, stack: e.stack });
|
|
21
48
|
}
|
|
22
49
|
throw e;
|
|
@@ -29,10 +56,11 @@ exports.catchServiceExceptions = catchServiceExceptions;
|
|
|
29
56
|
const makeServiceFn = (client, CommandCtor, fnOptions) => {
|
|
30
57
|
return (args, options) => effect_1.Effect.gen(function* () {
|
|
31
58
|
const config = yield* fnOptions.resolveClientConfig;
|
|
32
|
-
|
|
33
|
-
|
|
59
|
+
const runtime = yield* effect_1.Effect.runtime();
|
|
60
|
+
return yield* effect_1.Effect.acquireUseRelease(effect_1.Scope.make(), (scope) => effect_1.Effect.tryPromise({
|
|
61
|
+
try: (abortSignal) => client.send(new CommandCtor(args, config, { runtime, scope }), { ...(options ?? {}), abortSignal }),
|
|
34
62
|
catch: (0, exports.catchServiceExceptions)(fnOptions.errorTags),
|
|
35
|
-
});
|
|
63
|
+
}), effect_1.Scope.close);
|
|
36
64
|
});
|
|
37
65
|
};
|
|
38
66
|
exports.makeServiceFn = makeServiceFn;
|
|
@@ -40,21 +68,30 @@ exports.makeServiceFn = makeServiceFn;
|
|
|
40
68
|
* @since 0.1.0
|
|
41
69
|
* @category constructors
|
|
42
70
|
*/
|
|
43
|
-
const fromCommandsAndServiceFn = (commands, serviceFnMaker) => effect_1.
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
71
|
+
const fromCommandsAndServiceFn = (commands, serviceFnMaker) => effect_1.Effect.gen(function* () {
|
|
72
|
+
const maybeRequestHandler = yield* effect_1.Effect.serviceOption(HttpHandler.RequestHandler);
|
|
73
|
+
return (0, effect_1.pipe)(commands, effect_1.Record.filter(Boolean), effect_1.Record.mapEntries((CommandCtor, command) => {
|
|
74
|
+
const ExtendedCommand = class extends CommandCtor {
|
|
75
|
+
config;
|
|
76
|
+
runtimeOptions;
|
|
77
|
+
constructor(args, config, runtimeOptions) {
|
|
78
|
+
super(args);
|
|
79
|
+
this.config = config;
|
|
80
|
+
this.runtimeOptions = runtimeOptions;
|
|
81
|
+
}
|
|
82
|
+
resolveMiddleware(stack, configuration, options) {
|
|
83
|
+
return super.resolveMiddleware(stack, {
|
|
84
|
+
...configuration,
|
|
85
|
+
...(this.config.logger ? { logger: this.config.logger } : {}),
|
|
86
|
+
...(effect_1.Option.isSome(maybeRequestHandler)
|
|
87
|
+
? { requestHandler: HttpHandler.toClientRequestHandler(maybeRequestHandler.value, this.runtimeOptions) }
|
|
88
|
+
: {}),
|
|
89
|
+
}, options);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const serviceFnName = effect_1.String.uncapitalize(command).replace(/Command$/, "");
|
|
93
|
+
return [serviceFnName, serviceFnMaker(ExtendedCommand)];
|
|
94
|
+
}));
|
|
58
95
|
});
|
|
59
96
|
exports.fromCommandsAndServiceFn = fromCommandsAndServiceFn;
|
|
60
97
|
/**
|
package/dist/cjs/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yDAAyD;AAGzD,mCAA2F;AAE3F,2CAAuC;AACvC,8DAAgD;AAiChD;;;GAGG;AACI,MAAM,sBAAsB,GAAG,CAAC,SAA+C,EAAE,EAAE,CAAC,CAAC,CAAU,EAAE,EAAE;IACxG,IAAI,CAAC,YAAY,gCAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAChF,MAAM,gBAAgB,GAAG,aAAI,CAAC,MAAM,CAAoC,CAAC,CAAC,IAAI,CAAC,CAAC;QAEhF,OAAO,gBAAgB,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QACvB,IAAI,gBAAO,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,cAAK,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAO,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC;YAClF,OAAO,CAAC,CAAC,gBAAO,CAAC,mBAAmB,CAAC,CAAC,KAAK,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YAC9B,OAAO,IAAI,cAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAA,oBAAQ,EAAC,EAAE,GAAG,CAAC,EAAE,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AAM,qBAAqB,GAAG,CACnC,MAA4C,EAC5C,QAA0C,EAC1C,OAAyB,EACD,EAAE,CAC1B,IAAA,gCAAwB,EAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AALtF,QAAA,qBAAqB,yBAKiE"}
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.ServiceLogger = exports.Service = void 0;
|
|
29
|
+
exports.HttpHandler = exports.ServiceLogger = exports.Service = void 0;
|
|
30
30
|
/**
|
|
31
31
|
* @since 0.1.0
|
|
32
32
|
*/
|
|
@@ -43,4 +43,8 @@ __exportStar(require("./Errors.js"), exports);
|
|
|
43
43
|
* @since 0.1.0
|
|
44
44
|
*/
|
|
45
45
|
__exportStar(require("./Types.js"), exports);
|
|
46
|
+
/**
|
|
47
|
+
* @since 0.3.0
|
|
48
|
+
*/
|
|
49
|
+
exports.HttpHandler = __importStar(require("./HttpHandler.js"));
|
|
46
50
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,wDAAwC;AAExC;;GAEG;AACH,oEAAoD;AAEpD;;GAEG;AACH,8CAA4B;AAE5B;;GAEG;AACH,6CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,wDAAwC;AAExC;;GAEG;AACH,oEAAoD;AAEpD;;GAEG;AACH,8CAA4B;AAE5B;;GAEG;AACH,6CAA2B;AAE3B;;GAEG;AACH,gEAAgD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpHandler.d.ts","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpHandler.js","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.3.0
|
|
3
|
+
*/
|
|
4
|
+
import type { HttpRequest, HttpResponse } from "@smithy/protocol-http";
|
|
5
|
+
import type { HttpHandlerOptions, RequestHandler as ClientRequestHandler, RequestHandlerOutput } from "@smithy/types";
|
|
6
|
+
import type { Cause, Effect } from "effect";
|
|
7
|
+
import { Context, Scope } from "effect";
|
|
8
|
+
import type { RuntimeOptions } from "./internal/httpHandler.js";
|
|
9
|
+
declare const TypeId: unique symbol;
|
|
10
|
+
type RequestHandlerConstructorProps = {
|
|
11
|
+
readonly handle: (request: HttpRequest, handlerOptions?: HttpHandlerOptions) => Effect.Effect<RequestHandlerOutput<HttpResponse>, Cause.TimeoutException, Scope.Scope>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.3.0
|
|
15
|
+
* @category model
|
|
16
|
+
*/
|
|
17
|
+
export interface RequestHandler extends RequestHandlerConstructorProps {
|
|
18
|
+
readonly [TypeId]: typeof TypeId;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @since 0.3.0
|
|
22
|
+
* @category tag
|
|
23
|
+
*/
|
|
24
|
+
export declare const RequestHandler: Context.Tag<RequestHandler, RequestHandler>;
|
|
25
|
+
/**
|
|
26
|
+
* @since 0.3.0
|
|
27
|
+
* @category constructors
|
|
28
|
+
*/
|
|
29
|
+
export declare const make: (options: RequestHandlerConstructorProps) => RequestHandler;
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.3.0
|
|
32
|
+
* @category adapters
|
|
33
|
+
*/
|
|
34
|
+
export declare const toClientRequestHandler: (requestHandler: RequestHandler, config: RuntimeOptions) => ClientRequestHandler<HttpRequest, HttpResponse, HttpHandlerOptions>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=HttpHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpHandler.d.ts","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,IAAI,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACtH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAW,KAAK,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,QAAA,MAAM,MAAM,eAAmD,CAAC;AAEhE,KAAK,8BAA8B,GAAG;IACpC,QAAQ,CAAC,MAAM,EAAE,CACf,OAAO,EAAE,WAAW,EACpB,cAAc,CAAC,EAAE,kBAAkB,KAChC,MAAM,CAAC,MAAM,CAChB,oBAAoB,CAAC,YAAY,CAAC,EAClC,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,KAAK,CACZ,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,8BAA8B;IACpE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,6CAA2E,CAAC;AAMvG;;;GAGG;AACH,eAAO,MAAM,IAAI,YAAa,8BAA8B,KAAG,cACjB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,mBACjB,cAAc,UACtB,cAAc,KACrB,qBAAqB,WAAW,EAAE,YAAY,EAAE,kBAAkB,CAcpE,CAAC"}
|
package/dist/dts/Service.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.1.0
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import type { Client } from "@smithy/types";
|
|
4
|
+
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
5
|
+
import type { Client, HandlerOptions, Logger, RequestHandler } from "@smithy/types";
|
|
6
6
|
import type { Array } from "effect";
|
|
7
7
|
import { Effect } from "effect";
|
|
8
|
-
import type { TaggedException } from "./Errors.js";
|
|
9
|
-
import { SdkError } from "./Errors.js";
|
|
10
|
-
import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/service.js";
|
|
11
8
|
import type { HttpHandlerOptions } from "./Types.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.3.0
|
|
11
|
+
* @category models
|
|
12
|
+
*/
|
|
13
|
+
export interface LoggerResolvedConfig {
|
|
14
|
+
logger?: Logger;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.0
|
|
18
|
+
* @category models
|
|
19
|
+
*/
|
|
20
|
+
export interface BaseResolvedConfig extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions> {
|
|
21
|
+
requestHandler: RequestHandler<any, any, any>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.3.0
|
|
25
|
+
* @category models
|
|
26
|
+
*/
|
|
27
|
+
export type CommandCtor<I> = new (input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|
|
12
28
|
type ServiceFnOptions = {
|
|
13
29
|
errorTags?: Array.NonEmptyReadonlyArray<string>;
|
|
14
30
|
resolveClientConfig: Effect.Effect<LoggerResolvedConfig>;
|
|
@@ -17,21 +33,21 @@ type ServiceFnOptions = {
|
|
|
17
33
|
* @since 0.1.0
|
|
18
34
|
* @category errors
|
|
19
35
|
*/
|
|
20
|
-
export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) =>
|
|
36
|
+
export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => unknown;
|
|
21
37
|
/**
|
|
22
38
|
* @since 0.1.0
|
|
23
39
|
* @category constructors
|
|
24
40
|
*/
|
|
25
|
-
export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any,
|
|
41
|
+
export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, unknown, never>;
|
|
26
42
|
/**
|
|
27
43
|
* @since 0.1.0
|
|
28
44
|
* @category constructors
|
|
29
45
|
*/
|
|
30
|
-
export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Service
|
|
46
|
+
export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Effect.Effect<Service>;
|
|
31
47
|
/**
|
|
32
48
|
* @since 0.1.0
|
|
33
49
|
* @category constructors
|
|
34
50
|
*/
|
|
35
|
-
export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Service
|
|
51
|
+
export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Effect.Effect<Service>;
|
|
36
52
|
export {};
|
|
37
53
|
//# sourceMappingURL=Service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,2BAA2B,EAA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AAO,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,kBAC1B,CAAC,aAAa,YAAY,GAAG,CAAC,KAAK,WAAW,oBAAoB,CAAC,KAClF,OAAO,MAAM,CAAC,OAAO,CAoCpB,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,qBAAqB,oBACxB,OAAO,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,YAClC,OAAO,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,WACjC,gBAAgB,KACxB,OAAO,MAAM,CAAC,OAAO,CAC0E,CAAC"}
|
package/dist/dts/index.d.ts
CHANGED
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpHandler.d.ts","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;CACpB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Runtime, Scope } from "effect";
|
|
2
|
+
const TypeId = Symbol.for("@effect-aws/commons/RequestHandler");
|
|
3
|
+
/**
|
|
4
|
+
* @since 0.3.0
|
|
5
|
+
* @category tag
|
|
6
|
+
*/
|
|
7
|
+
export const RequestHandler = Context.GenericTag("@effect-aws/commons/RequestHandler");
|
|
8
|
+
const proto = {
|
|
9
|
+
[TypeId]: TypeId,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.3.0
|
|
13
|
+
* @category constructors
|
|
14
|
+
*/
|
|
15
|
+
export const make = (options) => Object.assign(Object.create(proto), options);
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.3.0
|
|
18
|
+
* @category adapters
|
|
19
|
+
*/
|
|
20
|
+
export const toClientRequestHandler = (requestHandler, config) => {
|
|
21
|
+
const runPromise = Runtime.runPromise(config.runtime);
|
|
22
|
+
const scoped = Scope.extend(config.scope);
|
|
23
|
+
class HttpHandler {
|
|
24
|
+
handle(request, options = {}) {
|
|
25
|
+
return runPromise(requestHandler.handle(request, options).pipe(scoped), { signal: options.abortSignal });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return new HttpHandler();
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=HttpHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpHandler.js","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGjD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAqBhE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,CAAiB,oCAAoC,CAAC,CAAC;AAEvG,MAAM,KAAK,GAAG;IACZ,CAAC,MAAM,CAAC,EAAE,MAAM;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAuC,EAAkB,EAAE,CAC9E,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,cAA8B,EAC9B,MAAsB,EAC+C,EAAE;IACvE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE1C,MAAM,WAAW;QACf,MAAM,CAAC,OAAoB,EAAE,UAA8B,EAAE;YAC3D,OAAO,UAAU,CACf,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EACpD,EAAE,MAAM,EAAE,OAAO,CAAC,WAA0B,EAAE,CAC/C,CAAC;QACJ,CAAC;KACF;IAED,OAAO,IAAI,WAAW,EAAE,CAAC;AAC3B,CAAC,CAAC"}
|
package/dist/esm/Service.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 0.1.0
|
|
3
|
-
*/
|
|
4
1
|
import { ServiceException } from "@smithy/smithy-client";
|
|
5
|
-
import { Data, Effect, Record, String } from "effect";
|
|
2
|
+
import { Cause, Data, Effect, Option, pipe, Record, Runtime, Scope, String } from "effect";
|
|
6
3
|
import { SdkError } from "./Errors.js";
|
|
4
|
+
import * as HttpHandler from "./HttpHandler.js";
|
|
7
5
|
/**
|
|
8
6
|
* @since 0.1.0
|
|
9
7
|
* @category errors
|
|
@@ -14,6 +12,12 @@ export const catchServiceExceptions = (errorTags) => (e) => {
|
|
|
14
12
|
return ServiceException({ ...e, message: e.message, stack: e.stack });
|
|
15
13
|
}
|
|
16
14
|
if (e instanceof Error) {
|
|
15
|
+
if (Runtime.isFiberFailure(e) && Cause.isFailType(e[Runtime.FiberFailureCauseId])) {
|
|
16
|
+
return e[Runtime.FiberFailureCauseId].error;
|
|
17
|
+
}
|
|
18
|
+
if (e.name === "TimeoutError") {
|
|
19
|
+
return new Cause.TimeoutException(e.message);
|
|
20
|
+
}
|
|
17
21
|
return SdkError({ ...e, name: "SdkError", message: e.message, stack: e.stack });
|
|
18
22
|
}
|
|
19
23
|
throw e;
|
|
@@ -25,31 +29,41 @@ export const catchServiceExceptions = (errorTags) => (e) => {
|
|
|
25
29
|
export const makeServiceFn = (client, CommandCtor, fnOptions) => {
|
|
26
30
|
return (args, options) => Effect.gen(function* () {
|
|
27
31
|
const config = yield* fnOptions.resolveClientConfig;
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const runtime = yield* Effect.runtime();
|
|
33
|
+
return yield* Effect.acquireUseRelease(Scope.make(), (scope) => Effect.tryPromise({
|
|
34
|
+
try: (abortSignal) => client.send(new CommandCtor(args, config, { runtime, scope }), { ...(options ?? {}), abortSignal }),
|
|
30
35
|
catch: catchServiceExceptions(fnOptions.errorTags),
|
|
31
|
-
});
|
|
36
|
+
}), Scope.close);
|
|
32
37
|
});
|
|
33
38
|
};
|
|
34
39
|
/**
|
|
35
40
|
* @since 0.1.0
|
|
36
41
|
* @category constructors
|
|
37
42
|
*/
|
|
38
|
-
export const fromCommandsAndServiceFn = (commands, serviceFnMaker) =>
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
export const fromCommandsAndServiceFn = (commands, serviceFnMaker) => Effect.gen(function* () {
|
|
44
|
+
const maybeRequestHandler = yield* Effect.serviceOption(HttpHandler.RequestHandler);
|
|
45
|
+
return pipe(commands, Record.filter(Boolean), Record.mapEntries((CommandCtor, command) => {
|
|
46
|
+
const ExtendedCommand = class extends CommandCtor {
|
|
47
|
+
config;
|
|
48
|
+
runtimeOptions;
|
|
49
|
+
constructor(args, config, runtimeOptions) {
|
|
50
|
+
super(args);
|
|
51
|
+
this.config = config;
|
|
52
|
+
this.runtimeOptions = runtimeOptions;
|
|
53
|
+
}
|
|
54
|
+
resolveMiddleware(stack, configuration, options) {
|
|
55
|
+
return super.resolveMiddleware(stack, {
|
|
56
|
+
...configuration,
|
|
57
|
+
...(this.config.logger ? { logger: this.config.logger } : {}),
|
|
58
|
+
...(Option.isSome(maybeRequestHandler)
|
|
59
|
+
? { requestHandler: HttpHandler.toClientRequestHandler(maybeRequestHandler.value, this.runtimeOptions) }
|
|
60
|
+
: {}),
|
|
61
|
+
}, options);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
|
|
65
|
+
return [serviceFnName, serviceFnMaker(ExtendedCommand)];
|
|
66
|
+
}));
|
|
53
67
|
});
|
|
54
68
|
/**
|
|
55
69
|
* @since 0.1.0
|
package/dist/esm/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3F,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OA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EG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,cAAc,aAAa,CAAC;AAE5B;;GAEG;AACH,cAAc,YAAY,CAAC;AAE3B;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpHandler.js","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-aws/commons",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Effectful AWS common library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"homepage": "https://floydspace.github.io/effect-aws/docs/commons",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@smithy/
|
|
19
|
-
"@smithy/
|
|
18
|
+
"@smithy/protocol-http": "^5.3.5",
|
|
19
|
+
"@smithy/smithy-client": "^4.9.9",
|
|
20
|
+
"@smithy/types": "^4.9.0"
|
|
20
21
|
},
|
|
21
22
|
"peerDependencies": {
|
|
22
23
|
"effect": ">=3.0.4 <4.0.0"
|
|
@@ -36,6 +37,11 @@
|
|
|
36
37
|
"import": "./dist/esm/Errors.js",
|
|
37
38
|
"default": "./dist/cjs/Errors.js"
|
|
38
39
|
},
|
|
40
|
+
"./HttpHandler": {
|
|
41
|
+
"types": "./dist/dts/HttpHandler.d.ts",
|
|
42
|
+
"import": "./dist/esm/HttpHandler.js",
|
|
43
|
+
"default": "./dist/cjs/HttpHandler.js"
|
|
44
|
+
},
|
|
39
45
|
"./Service": {
|
|
40
46
|
"types": "./dist/dts/Service.d.ts",
|
|
41
47
|
"import": "./dist/esm/Service.js",
|
|
@@ -57,6 +63,9 @@
|
|
|
57
63
|
"Errors": [
|
|
58
64
|
"./dist/dts/Errors.d.ts"
|
|
59
65
|
],
|
|
66
|
+
"HttpHandler": [
|
|
67
|
+
"./dist/dts/HttpHandler.d.ts"
|
|
68
|
+
],
|
|
60
69
|
"Service": [
|
|
61
70
|
"./dist/dts/Service.d.ts"
|
|
62
71
|
],
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.3.0
|
|
3
|
+
*/
|
|
4
|
+
import type { HttpRequest, HttpResponse } from "@smithy/protocol-http";
|
|
5
|
+
import type { HttpHandlerOptions, RequestHandler as ClientRequestHandler, RequestHandlerOutput } from "@smithy/types";
|
|
6
|
+
import type { Cause, Effect } from "effect";
|
|
7
|
+
import { Context, Runtime, Scope } from "effect";
|
|
8
|
+
import type { RuntimeOptions } from "./internal/httpHandler.js";
|
|
9
|
+
|
|
10
|
+
const TypeId = Symbol.for("@effect-aws/commons/RequestHandler");
|
|
11
|
+
|
|
12
|
+
type RequestHandlerConstructorProps = {
|
|
13
|
+
readonly handle: (
|
|
14
|
+
request: HttpRequest,
|
|
15
|
+
handlerOptions?: HttpHandlerOptions,
|
|
16
|
+
) => Effect.Effect<
|
|
17
|
+
RequestHandlerOutput<HttpResponse>,
|
|
18
|
+
Cause.TimeoutException,
|
|
19
|
+
Scope.Scope
|
|
20
|
+
>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.3.0
|
|
25
|
+
* @category model
|
|
26
|
+
*/
|
|
27
|
+
export interface RequestHandler extends RequestHandlerConstructorProps {
|
|
28
|
+
readonly [TypeId]: typeof TypeId;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @since 0.3.0
|
|
33
|
+
* @category tag
|
|
34
|
+
*/
|
|
35
|
+
export const RequestHandler = Context.GenericTag<RequestHandler>("@effect-aws/commons/RequestHandler");
|
|
36
|
+
|
|
37
|
+
const proto = {
|
|
38
|
+
[TypeId]: TypeId,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @since 0.3.0
|
|
43
|
+
* @category constructors
|
|
44
|
+
*/
|
|
45
|
+
export const make = (options: RequestHandlerConstructorProps): RequestHandler =>
|
|
46
|
+
Object.assign(Object.create(proto), options);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @since 0.3.0
|
|
50
|
+
* @category adapters
|
|
51
|
+
*/
|
|
52
|
+
export const toClientRequestHandler = (
|
|
53
|
+
requestHandler: RequestHandler,
|
|
54
|
+
config: RuntimeOptions,
|
|
55
|
+
): ClientRequestHandler<HttpRequest, HttpResponse, HttpHandlerOptions> => {
|
|
56
|
+
const runPromise = Runtime.runPromise(config.runtime);
|
|
57
|
+
const scoped = Scope.extend(config.scope);
|
|
58
|
+
|
|
59
|
+
class HttpHandler implements ClientRequestHandler<HttpRequest, HttpResponse, HttpHandlerOptions> {
|
|
60
|
+
handle(request: HttpRequest, options: HttpHandlerOptions = {}) {
|
|
61
|
+
return runPromise(
|
|
62
|
+
requestHandler.handle(request, options).pipe(scoped),
|
|
63
|
+
{ signal: options.abortSignal as AbortSignal },
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return new HttpHandler();
|
|
69
|
+
};
|
package/src/Service.ts
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.1.0
|
|
3
3
|
*/
|
|
4
|
+
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
4
5
|
import { ServiceException } from "@smithy/smithy-client";
|
|
5
|
-
import type { Client, MiddlewareStack } from "@smithy/types";
|
|
6
|
+
import type { Client, HandlerOptions, Logger, MiddlewareStack, RequestHandler } from "@smithy/types";
|
|
6
7
|
import type { Array } from "effect";
|
|
7
|
-
import { Data, Effect, Record, String } from "effect";
|
|
8
|
+
import { Cause, Data, Effect, Option, pipe, Record, Runtime, Scope, String } from "effect";
|
|
8
9
|
import type { TaggedException } from "./Errors.js";
|
|
9
10
|
import { SdkError } from "./Errors.js";
|
|
10
|
-
import
|
|
11
|
+
import * as HttpHandler from "./HttpHandler.js";
|
|
12
|
+
import type { RuntimeOptions } from "./internal/httpHandler.js";
|
|
11
13
|
import type { HttpHandlerOptions } from "./Types.js";
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.3.0
|
|
17
|
+
* @category models
|
|
18
|
+
*/
|
|
19
|
+
export interface LoggerResolvedConfig {
|
|
20
|
+
logger?: Logger;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.3.0
|
|
25
|
+
* @category models
|
|
26
|
+
*/
|
|
27
|
+
export interface BaseResolvedConfig
|
|
28
|
+
extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions>
|
|
29
|
+
{
|
|
30
|
+
requestHandler: RequestHandler<any, any, any>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @since 0.3.0
|
|
35
|
+
* @category models
|
|
36
|
+
*/
|
|
37
|
+
export type CommandCtor<I> = new(input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|
|
38
|
+
|
|
13
39
|
type ServiceFnOptions = {
|
|
14
40
|
errorTags?: Array.NonEmptyReadonlyArray<string>;
|
|
15
41
|
resolveClientConfig: Effect.Effect<LoggerResolvedConfig>;
|
|
@@ -26,6 +52,12 @@ export const catchServiceExceptions = (errorTags?: Array.NonEmptyReadonlyArray<s
|
|
|
26
52
|
return ServiceException({ ...e, message: e.message, stack: e.stack });
|
|
27
53
|
}
|
|
28
54
|
if (e instanceof Error) {
|
|
55
|
+
if (Runtime.isFiberFailure(e) && Cause.isFailType(e[Runtime.FiberFailureCauseId])) {
|
|
56
|
+
return e[Runtime.FiberFailureCauseId].error;
|
|
57
|
+
}
|
|
58
|
+
if (e.name === "TimeoutError") {
|
|
59
|
+
return new Cause.TimeoutException(e.message);
|
|
60
|
+
}
|
|
29
61
|
return SdkError({ ...e, name: "SdkError", message: e.message, stack: e.stack });
|
|
30
62
|
}
|
|
31
63
|
throw e;
|
|
@@ -43,10 +75,18 @@ export const makeServiceFn = (
|
|
|
43
75
|
return (args: any, options?: HttpHandlerOptions) =>
|
|
44
76
|
Effect.gen(function*() {
|
|
45
77
|
const config = yield* fnOptions.resolveClientConfig;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
78
|
+
const runtime = yield* Effect.runtime();
|
|
79
|
+
|
|
80
|
+
return yield* Effect.acquireUseRelease(
|
|
81
|
+
Scope.make(),
|
|
82
|
+
(scope) =>
|
|
83
|
+
Effect.tryPromise({
|
|
84
|
+
try: (abortSignal) =>
|
|
85
|
+
client.send(new CommandCtor(args, config, { runtime, scope }), { ...(options ?? {}), abortSignal }),
|
|
86
|
+
catch: catchServiceExceptions(fnOptions.errorTags),
|
|
87
|
+
}),
|
|
88
|
+
Scope.close,
|
|
89
|
+
);
|
|
50
90
|
});
|
|
51
91
|
};
|
|
52
92
|
|
|
@@ -57,27 +97,43 @@ export const makeServiceFn = (
|
|
|
57
97
|
export const fromCommandsAndServiceFn = <Service>(
|
|
58
98
|
commands: Record<string, CommandCtor<any>>,
|
|
59
99
|
serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>,
|
|
60
|
-
): Service =>
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
100
|
+
): Effect.Effect<Service> =>
|
|
101
|
+
Effect.gen(function*() {
|
|
102
|
+
const maybeRequestHandler = yield* Effect.serviceOption(HttpHandler.RequestHandler);
|
|
103
|
+
|
|
104
|
+
return pipe(
|
|
105
|
+
commands,
|
|
106
|
+
Record.filter(Boolean),
|
|
107
|
+
Record.mapEntries((CommandCtor, command) => {
|
|
108
|
+
const ExtendedCommand = class extends CommandCtor {
|
|
109
|
+
constructor(
|
|
110
|
+
args: any,
|
|
111
|
+
private config: LoggerResolvedConfig,
|
|
112
|
+
private runtimeOptions: RuntimeOptions,
|
|
113
|
+
) {
|
|
114
|
+
super(args);
|
|
115
|
+
}
|
|
66
116
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
117
|
+
resolveMiddleware(
|
|
118
|
+
stack: MiddlewareStack<any, any>,
|
|
119
|
+
configuration: BaseResolvedConfig,
|
|
120
|
+
options: any,
|
|
121
|
+
) {
|
|
122
|
+
return super.resolveMiddleware(stack, {
|
|
123
|
+
...configuration,
|
|
124
|
+
...(this.config.logger ? { logger: this.config.logger } : {}),
|
|
125
|
+
...(Option.isSome(maybeRequestHandler)
|
|
126
|
+
? { requestHandler: HttpHandler.toClientRequestHandler(maybeRequestHandler.value, this.runtimeOptions) }
|
|
127
|
+
: {}),
|
|
128
|
+
}, options);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
77
131
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
132
|
+
const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
|
|
133
|
+
return [serviceFnName, serviceFnMaker(ExtendedCommand)];
|
|
134
|
+
}),
|
|
135
|
+
) as Service;
|
|
136
|
+
});
|
|
81
137
|
|
|
82
138
|
/**
|
|
83
139
|
* @since 0.1.0
|
|
@@ -87,4 +143,5 @@ export const fromClientAndCommands = <Service>(
|
|
|
87
143
|
client: Client<any, any, BaseResolvedConfig>,
|
|
88
144
|
commands: Record<string, CommandCtor<any>>,
|
|
89
145
|
options: ServiceFnOptions,
|
|
90
|
-
): Service =>
|
|
146
|
+
): Effect.Effect<Service> =>
|
|
147
|
+
fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, options));
|
package/src/index.ts
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
2
|
-
import type { HandlerOptions, Logger, RequestHandler } from "@smithy/types";
|
|
3
|
-
export interface LoggerResolvedConfig {
|
|
4
|
-
logger?: Logger;
|
|
5
|
-
}
|
|
6
|
-
export interface BaseResolvedConfig extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions> {
|
|
7
|
-
requestHandler: RequestHandler<any, any, any>;
|
|
8
|
-
}
|
|
9
|
-
export type CommandCtor<I> = new (input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|
|
10
|
-
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/internal/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBACf,SAAQ,QAAQ,CAAC,oBAAoB,CAAC,EAAE,2BAA2B,CAAC,cAAc,CAAC;IAEnF,cAAc,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,KAAI,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/internal/service.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
2
|
-
import type { HandlerOptions, Logger, RequestHandler } from "@smithy/types";
|
|
3
|
-
export interface LoggerResolvedConfig {
|
|
4
|
-
logger?: Logger;
|
|
5
|
-
}
|
|
6
|
-
export interface BaseResolvedConfig extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions> {
|
|
7
|
-
requestHandler: RequestHandler<any, any, any>;
|
|
8
|
-
}
|
|
9
|
-
export type CommandCtor<I> = new (input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|
|
10
|
-
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/internal/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBACf,SAAQ,QAAQ,CAAC,oBAAoB,CAAC,EAAE,2BAA2B,CAAC,cAAc,CAAC;IAEnF,cAAc,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,KAAI,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/internal/service.ts"],"names":[],"mappings":""}
|
package/src/internal/service.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
2
|
-
import type { HandlerOptions, Logger, RequestHandler } from "@smithy/types";
|
|
3
|
-
|
|
4
|
-
export interface LoggerResolvedConfig {
|
|
5
|
-
logger?: Logger;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface BaseResolvedConfig
|
|
9
|
-
extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions>
|
|
10
|
-
{
|
|
11
|
-
requestHandler: RequestHandler<any, any, any>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type CommandCtor<I> = new(input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|