@effect-aws/commons 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/HttpHandler/package.json +6 -0
  2. package/dist/cjs/HttpHandler.d.ts +36 -0
  3. package/dist/cjs/HttpHandler.d.ts.map +1 -0
  4. package/dist/cjs/HttpHandler.js +35 -0
  5. package/dist/cjs/HttpHandler.js.map +1 -0
  6. package/dist/cjs/Service.d.ts +4 -10
  7. package/dist/cjs/Service.d.ts.map +1 -1
  8. package/dist/cjs/Service.js +58 -18
  9. package/dist/cjs/Service.js.map +1 -1
  10. package/dist/cjs/index.d.ts +4 -0
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +5 -1
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/internal/httpHandler.d.ts +6 -0
  15. package/dist/cjs/internal/httpHandler.d.ts.map +1 -0
  16. package/dist/cjs/internal/httpHandler.js +3 -0
  17. package/dist/cjs/internal/httpHandler.js.map +1 -0
  18. package/dist/dts/HttpHandler.d.ts +36 -0
  19. package/dist/dts/HttpHandler.d.ts.map +1 -0
  20. package/dist/dts/Service.d.ts +4 -10
  21. package/dist/dts/Service.d.ts.map +1 -1
  22. package/dist/dts/index.d.ts +4 -0
  23. package/dist/dts/index.d.ts.map +1 -1
  24. package/dist/dts/internal/httpHandler.d.ts +6 -0
  25. package/dist/dts/internal/httpHandler.d.ts.map +1 -0
  26. package/dist/esm/HttpHandler.js +30 -0
  27. package/dist/esm/HttpHandler.js.map +1 -0
  28. package/dist/esm/Service.js +36 -19
  29. package/dist/esm/Service.js.map +1 -1
  30. package/dist/esm/index.js +4 -0
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/internal/httpHandler.js +2 -0
  33. package/dist/esm/internal/httpHandler.js.map +1 -0
  34. package/package.json +12 -3
  35. package/src/HttpHandler.ts +69 -0
  36. package/src/Service.ts +54 -25
  37. package/src/index.ts +5 -0
  38. package/src/internal/httpHandler.ts +6 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/HttpHandler.js",
3
+ "module": "../dist/esm/HttpHandler.js",
4
+ "types": "../dist/dts/HttpHandler.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -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"}
@@ -1,12 +1,6 @@
1
- /**
2
- * @since 0.1.0
3
- */
4
- import { ServiceException } from "@smithy/smithy-client";
5
1
  import type { Client } from "@smithy/types";
6
2
  import type { Array } from "effect";
7
3
  import { Effect } from "effect";
8
- import type { TaggedException } from "./Errors.js";
9
- import { SdkError } from "./Errors.js";
10
4
  import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/service.js";
11
5
  import type { HttpHandlerOptions } from "./Types.js";
12
6
  type ServiceFnOptions = {
@@ -17,21 +11,21 @@ type ServiceFnOptions = {
17
11
  * @since 0.1.0
18
12
  * @category errors
19
13
  */
20
- export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => SdkError | TaggedException<ServiceException>;
14
+ export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => unknown;
21
15
  /**
22
16
  * @since 0.1.0
23
17
  * @category constructors
24
18
  */
25
- export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, SdkError | TaggedException<ServiceException>, never>;
19
+ export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, unknown, never>;
26
20
  /**
27
21
  * @since 0.1.0
28
22
  * @category constructors
29
23
  */
30
- export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Service;
24
+ export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Effect.Effect<Service>;
31
25
  /**
32
26
  * @since 0.1.0
33
27
  * @category constructors
34
28
  */
35
- export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Service;
29
+ export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Effect.Effect<Service>;
36
30
  export {};
37
31
  //# 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,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAmB,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAQ,MAAM,EAAkB,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,KAAK,gBAAgB,GAAG;IACtB,SAAS,CAAC,EAAE,KAAK,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAChD,mBAAmB,EAAE,MA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;;;GAGG;AACH,eAAO,MAAM,sBAAsB,eAAgB,MAAM,qBAAqB,CAAC,MAAM,CAAC,SAAS,OAAO,YAgBrG,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,WAChB,OAAO,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,eAC/B,YAAY,GAAG,CAAC,aAClB,gBAAgB,YAEb,GAAG,YAAY,kBAAkB,uCAgBhD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,sBACzB,OAAO,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,kBAC1B,CAAC,aAAa,YAAY,GAAG,CAAC,KAAK,WAAW,oBAAoB,CAAC,KAClF,OAAO,MAAM,CAAC,OAAO,CAgCpB,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"}
@@ -1,4 +1,27 @@
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
27
  /**
@@ -7,6 +30,7 @@ exports.fromClientAndCommands = exports.fromCommandsAndServiceFn = exports.makeS
7
30
  const smithy_client_1 = require("@smithy/smithy-client");
8
31
  const effect_1 = require("effect");
9
32
  const Errors_js_1 = require("./Errors.js");
33
+ const HttpHandler = __importStar(require("./HttpHandler.js"));
10
34
  /**
11
35
  * @since 0.1.0
12
36
  * @category errors
@@ -17,6 +41,12 @@ const catchServiceExceptions = (errorTags) => (e) => {
17
41
  return ServiceException({ ...e, message: e.message, stack: e.stack });
18
42
  }
19
43
  if (e instanceof Error) {
44
+ if (effect_1.Runtime.isFiberFailure(e) && effect_1.Cause.isFailType(e[effect_1.Runtime.FiberFailureCauseId])) {
45
+ return e[effect_1.Runtime.FiberFailureCauseId].error;
46
+ }
47
+ if (e.name === "TimeoutError") {
48
+ return new effect_1.Cause.TimeoutException(e.message);
49
+ }
20
50
  return (0, Errors_js_1.SdkError)({ ...e, name: "SdkError", message: e.message, stack: e.stack });
21
51
  }
22
52
  throw e;
@@ -29,10 +59,11 @@ exports.catchServiceExceptions = catchServiceExceptions;
29
59
  const makeServiceFn = (client, CommandCtor, fnOptions) => {
30
60
  return (args, options) => effect_1.Effect.gen(function* () {
31
61
  const config = yield* fnOptions.resolveClientConfig;
32
- return yield* effect_1.Effect.tryPromise({
33
- try: (abortSignal) => client.send(new CommandCtor(args, config), { ...(options ?? {}), abortSignal }),
62
+ const runtime = yield* effect_1.Effect.runtime();
63
+ return yield* effect_1.Effect.acquireUseRelease(effect_1.Scope.make(), (scope) => effect_1.Effect.tryPromise({
64
+ try: (abortSignal) => client.send(new CommandCtor(args, config, { runtime, scope }), { ...(options ?? {}), abortSignal }),
34
65
  catch: (0, exports.catchServiceExceptions)(fnOptions.errorTags),
35
- });
66
+ }), effect_1.Scope.close);
36
67
  });
37
68
  };
38
69
  exports.makeServiceFn = makeServiceFn;
@@ -40,21 +71,30 @@ exports.makeServiceFn = makeServiceFn;
40
71
  * @since 0.1.0
41
72
  * @category constructors
42
73
  */
43
- const fromCommandsAndServiceFn = (commands, serviceFnMaker) => effect_1.Record.mapEntries(commands, (CommandCtor, command) => {
44
- const ExtendedCommand = class extends CommandCtor {
45
- config;
46
- constructor(args, config) {
47
- super(args);
48
- this.config = config;
49
- }
50
- resolveMiddleware(stack, configuration, options) {
51
- return this.config?.logger
52
- ? super.resolveMiddleware(stack, { ...configuration, logger: this.config.logger }, options)
53
- : super.resolveMiddleware(stack, configuration, options);
54
- }
55
- };
56
- const serviceFnName = effect_1.String.uncapitalize(command).replace(/Command$/, "");
57
- return [serviceFnName, serviceFnMaker(ExtendedCommand)];
74
+ const fromCommandsAndServiceFn = (commands, serviceFnMaker) => effect_1.Effect.gen(function* () {
75
+ const maybeRequestHandler = yield* effect_1.Effect.serviceOption(HttpHandler.RequestHandler);
76
+ return effect_1.Record.mapEntries(commands, (CommandCtor, command) => {
77
+ const ExtendedCommand = class extends CommandCtor {
78
+ config;
79
+ runtimeOptions;
80
+ constructor(args, config, runtimeOptions) {
81
+ super(args);
82
+ this.config = config;
83
+ this.runtimeOptions = runtimeOptions;
84
+ }
85
+ resolveMiddleware(stack, configuration, options) {
86
+ return super.resolveMiddleware(stack, {
87
+ ...configuration,
88
+ ...(this.config.logger ? { logger: this.config.logger } : {}),
89
+ ...(effect_1.Option.isSome(maybeRequestHandler)
90
+ ? { requestHandler: HttpHandler.toClientRequestHandler(maybeRequestHandler.value, this.runtimeOptions) }
91
+ : {}),
92
+ }, options);
93
+ }
94
+ };
95
+ const serviceFnName = effect_1.String.uncapitalize(command).replace(/Command$/, "");
96
+ return [serviceFnName, serviceFnMaker(ExtendedCommand)];
97
+ });
58
98
  });
59
99
  exports.fromCommandsAndServiceFn = fromCommandsAndServiceFn;
60
100
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAAyD;AAGzD,mCAAsD;AAEtD,2CAAuC;AASvC;;;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,OAAO,IAAA,oBAAQ,EAAC,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,CAAC,CAAC;AACV,CAAC,CAAC;AAVW,QAAA,sBAAsB,0BAUjC;AAEF;;;GAGG;AACI,MAAM,aAAa,GAAG,CAC3B,MAA4C,EAC5C,WAA6B,EAC7B,SAA2B,EAC3B,EAAE;IACF,OAAO,CAAC,IAAS,EAAE,OAA4B,EAAE,EAAE,CACjD,eAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC;QACpD,OAAO,KAAK,CAAC,CAAC,eAAM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,CAAC;AAChB,CAAC,CAAC,CAAC;AAnCQ,QAAA,wBAAwB,4BAmChC;AAEL;;;GAGG;AACI,MAAM,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"}
@@ -14,4 +14,8 @@ export * from "./Errors.js";
14
14
  * @since 0.1.0
15
15
  */
16
16
  export * from "./Types.js";
17
+ /**
18
+ * @since 0.3.0
19
+ */
20
+ export * as HttpHandler from "./HttpHandler.js";
17
21
  //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -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,6 @@
1
+ import type { Runtime, Scope } from "effect";
2
+ export interface RuntimeOptions {
3
+ runtime: Runtime.Runtime<never>;
4
+ scope: Scope.Scope;
5
+ }
6
+ //# sourceMappingURL=httpHandler.d.ts.map
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=httpHandler.js.map
@@ -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"}
@@ -1,12 +1,6 @@
1
- /**
2
- * @since 0.1.0
3
- */
4
- import { ServiceException } from "@smithy/smithy-client";
5
1
  import type { Client } from "@smithy/types";
6
2
  import type { Array } from "effect";
7
3
  import { Effect } from "effect";
8
- import type { TaggedException } from "./Errors.js";
9
- import { SdkError } from "./Errors.js";
10
4
  import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/service.js";
11
5
  import type { HttpHandlerOptions } from "./Types.js";
12
6
  type ServiceFnOptions = {
@@ -17,21 +11,21 @@ type ServiceFnOptions = {
17
11
  * @since 0.1.0
18
12
  * @category errors
19
13
  */
20
- export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => SdkError | TaggedException<ServiceException>;
14
+ export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => unknown;
21
15
  /**
22
16
  * @since 0.1.0
23
17
  * @category constructors
24
18
  */
25
- export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, SdkError | TaggedException<ServiceException>, never>;
19
+ export declare const makeServiceFn: (client: Client<any, any, BaseResolvedConfig>, CommandCtor: CommandCtor<any>, fnOptions: ServiceFnOptions) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, unknown, never>;
26
20
  /**
27
21
  * @since 0.1.0
28
22
  * @category constructors
29
23
  */
30
- export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Service;
24
+ export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Effect.Effect<Service>;
31
25
  /**
32
26
  * @since 0.1.0
33
27
  * @category constructors
34
28
  */
35
- export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Service;
29
+ export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Effect.Effect<Service>;
36
30
  export {};
37
31
  //# sourceMappingURL=Service.d.ts.map
@@ -1 +1 @@
1
- {"version":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AE,YAAY,GAAG,CAAC,CAAC,WACjC,gBAAgB,KACxB,OAAO,MAAM,CAAC,OAAO,CAC0E,CAAC"}
@@ -14,4 +14,8 @@ export * from "./Errors.js";
14
14
  * @since 0.1.0
15
15
  */
16
16
  export * from "./Types.js";
17
+ /**
18
+ * @since 0.3.0
19
+ */
20
+ export * as HttpHandler from "./HttpHandler.js";
17
21
  //# sourceMappingURL=index.d.ts.map
@@ -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,6 @@
1
+ import type { Runtime, Scope } from "effect";
2
+ export interface RuntimeOptions {
3
+ runtime: Runtime.Runtime<never>;
4
+ scope: Scope.Scope;
5
+ }
6
+ //# sourceMappingURL=httpHandler.d.ts.map
@@ -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"}
@@ -2,8 +2,9 @@
2
2
  * @since 0.1.0
3
3
  */
4
4
  import { ServiceException } from "@smithy/smithy-client";
5
- import { Data, Effect, Record, String } from "effect";
5
+ import { Cause, Data, Effect, Option, Record, Runtime, Scope, String } from "effect";
6
6
  import { SdkError } from "./Errors.js";
7
+ import * as HttpHandler from "./HttpHandler.js";
7
8
  /**
8
9
  * @since 0.1.0
9
10
  * @category errors
@@ -14,6 +15,12 @@ export const catchServiceExceptions = (errorTags) => (e) => {
14
15
  return ServiceException({ ...e, message: e.message, stack: e.stack });
15
16
  }
16
17
  if (e instanceof Error) {
18
+ if (Runtime.isFiberFailure(e) && Cause.isFailType(e[Runtime.FiberFailureCauseId])) {
19
+ return e[Runtime.FiberFailureCauseId].error;
20
+ }
21
+ if (e.name === "TimeoutError") {
22
+ return new Cause.TimeoutException(e.message);
23
+ }
17
24
  return SdkError({ ...e, name: "SdkError", message: e.message, stack: e.stack });
18
25
  }
19
26
  throw e;
@@ -25,31 +32,41 @@ export const catchServiceExceptions = (errorTags) => (e) => {
25
32
  export const makeServiceFn = (client, CommandCtor, fnOptions) => {
26
33
  return (args, options) => Effect.gen(function* () {
27
34
  const config = yield* fnOptions.resolveClientConfig;
28
- return yield* Effect.tryPromise({
29
- try: (abortSignal) => client.send(new CommandCtor(args, config), { ...(options ?? {}), abortSignal }),
35
+ const runtime = yield* Effect.runtime();
36
+ return yield* Effect.acquireUseRelease(Scope.make(), (scope) => Effect.tryPromise({
37
+ try: (abortSignal) => client.send(new CommandCtor(args, config, { runtime, scope }), { ...(options ?? {}), abortSignal }),
30
38
  catch: catchServiceExceptions(fnOptions.errorTags),
31
- });
39
+ }), Scope.close);
32
40
  });
33
41
  };
34
42
  /**
35
43
  * @since 0.1.0
36
44
  * @category constructors
37
45
  */
38
- export const fromCommandsAndServiceFn = (commands, serviceFnMaker) => Record.mapEntries(commands, (CommandCtor, command) => {
39
- const ExtendedCommand = class extends CommandCtor {
40
- config;
41
- constructor(args, config) {
42
- super(args);
43
- this.config = config;
44
- }
45
- resolveMiddleware(stack, configuration, options) {
46
- return this.config?.logger
47
- ? super.resolveMiddleware(stack, { ...configuration, logger: this.config.logger }, options)
48
- : super.resolveMiddleware(stack, configuration, options);
49
- }
50
- };
51
- const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
52
- return [serviceFnName, serviceFnMaker(ExtendedCommand)];
46
+ export const fromCommandsAndServiceFn = (commands, serviceFnMaker) => Effect.gen(function* () {
47
+ const maybeRequestHandler = yield* Effect.serviceOption(HttpHandler.RequestHandler);
48
+ return Record.mapEntries(commands, (CommandCtor, command) => {
49
+ const ExtendedCommand = class extends CommandCtor {
50
+ config;
51
+ runtimeOptions;
52
+ constructor(args, config, runtimeOptions) {
53
+ super(args);
54
+ this.config = config;
55
+ this.runtimeOptions = runtimeOptions;
56
+ }
57
+ resolveMiddleware(stack, configuration, options) {
58
+ return super.resolveMiddleware(stack, {
59
+ ...configuration,
60
+ ...(this.config.logger ? { logger: this.config.logger } : {}),
61
+ ...(Option.isSome(maybeRequestHandler)
62
+ ? { requestHandler: HttpHandler.toClientRequestHandler(maybeRequestHandler.value, this.runtimeOptions) }
63
+ : {}),
64
+ }, options);
65
+ }
66
+ };
67
+ const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
68
+ return [serviceFnName, serviceFnMaker(ExtendedCommand)];
69
+ });
53
70
  });
54
71
  /**
55
72
  * @since 0.1.0
@@ -1 +1 @@
1
- {"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AASvC;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,SAA+C,EAAE,EAAE,CAAC,CAAC,CAAU,EAAE,EAAE;IACxG,IAAI,CAAC,YAAY,gBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAChF,MAAM,gBAAgB,GAAG,IAAI,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,OAAO,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,CAAC,CAAC;AACV,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,aAA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AmB,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,EAAE;wBACxG,CAAC,CAAC,EAAE,CAAC;iBACR,EAAE,OAAO,CAAC,CAAC;YACd,CAAC;SACF,CAAC;QAEF,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC3E,OAAO,CAAC,aAAa,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAY,CAAC;AAChB,CAAC,CAAC,CAAC;AAEL;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAA4C,EAC5C,QAA0C,EAC1C,OAAyB,EACD,EAAE,CAC1B,wBAAwB,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC"}
package/dist/esm/index.js CHANGED
@@ -14,4 +14,8 @@ export * from "./Errors.js";
14
14
  * @since 0.1.0
15
15
  */
16
16
  export * from "./Types.js";
17
+ /**
18
+ * @since 0.3.0
19
+ */
20
+ export * as HttpHandler from "./HttpHandler.js";
17
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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"}
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=httpHandler.js.map
@@ -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.2.1",
3
+ "version": "0.3.0",
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/smithy-client": "^4.1.6",
19
- "@smithy/types": "^4.1.0"
18
+ "@smithy/protocol-http": "^5.1.0",
19
+ "@smithy/smithy-client": "^4.2.0",
20
+ "@smithy/types": "^4.2.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
@@ -4,9 +4,11 @@
4
4
  import { ServiceException } from "@smithy/smithy-client";
5
5
  import type { Client, MiddlewareStack } from "@smithy/types";
6
6
  import type { Array } from "effect";
7
- import { Data, Effect, Record, String } from "effect";
7
+ import { Cause, Data, Effect, Option, Record, Runtime, Scope, String } from "effect";
8
8
  import type { TaggedException } from "./Errors.js";
9
9
  import { SdkError } from "./Errors.js";
10
+ import * as HttpHandler from "./HttpHandler.js";
11
+ import type { RuntimeOptions } from "./internal/httpHandler.js";
10
12
  import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/service.js";
11
13
  import type { HttpHandlerOptions } from "./Types.js";
12
14
 
@@ -26,6 +28,12 @@ export const catchServiceExceptions = (errorTags?: Array.NonEmptyReadonlyArray<s
26
28
  return ServiceException({ ...e, message: e.message, stack: e.stack });
27
29
  }
28
30
  if (e instanceof Error) {
31
+ if (Runtime.isFiberFailure(e) && Cause.isFailType(e[Runtime.FiberFailureCauseId])) {
32
+ return e[Runtime.FiberFailureCauseId].error;
33
+ }
34
+ if (e.name === "TimeoutError") {
35
+ return new Cause.TimeoutException(e.message);
36
+ }
29
37
  return SdkError({ ...e, name: "SdkError", message: e.message, stack: e.stack });
30
38
  }
31
39
  throw e;
@@ -43,10 +51,18 @@ export const makeServiceFn = (
43
51
  return (args: any, options?: HttpHandlerOptions) =>
44
52
  Effect.gen(function*() {
45
53
  const config = yield* fnOptions.resolveClientConfig;
46
- return yield* Effect.tryPromise({
47
- try: (abortSignal) => client.send(new CommandCtor(args, config), { ...(options ?? {}), abortSignal }),
48
- catch: catchServiceExceptions(fnOptions.errorTags),
49
- });
54
+ const runtime = yield* Effect.runtime();
55
+
56
+ return yield* Effect.acquireUseRelease(
57
+ Scope.make(),
58
+ (scope) =>
59
+ Effect.tryPromise({
60
+ try: (abortSignal) =>
61
+ client.send(new CommandCtor(args, config, { runtime, scope }), { ...(options ?? {}), abortSignal }),
62
+ catch: catchServiceExceptions(fnOptions.errorTags),
63
+ }),
64
+ Scope.close,
65
+ );
50
66
  });
51
67
  };
52
68
 
@@ -57,27 +73,39 @@ export const makeServiceFn = (
57
73
  export const fromCommandsAndServiceFn = <Service>(
58
74
  commands: Record<string, CommandCtor<any>>,
59
75
  serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>,
60
- ): Service =>
61
- Record.mapEntries(commands, (CommandCtor, command) => {
62
- const ExtendedCommand = class extends CommandCtor {
63
- constructor(args: any, private config?: LoggerResolvedConfig) {
64
- super(args);
65
- }
76
+ ): Effect.Effect<Service> =>
77
+ Effect.gen(function*() {
78
+ const maybeRequestHandler = yield* Effect.serviceOption(HttpHandler.RequestHandler);
79
+
80
+ return Record.mapEntries(commands, (CommandCtor, command) => {
81
+ const ExtendedCommand = class extends CommandCtor {
82
+ constructor(
83
+ args: any,
84
+ private config: LoggerResolvedConfig,
85
+ private runtimeOptions: RuntimeOptions,
86
+ ) {
87
+ super(args);
88
+ }
66
89
 
67
- resolveMiddleware(
68
- stack: MiddlewareStack<any, any>,
69
- configuration: BaseResolvedConfig,
70
- options: any,
71
- ) {
72
- return this.config?.logger
73
- ? super.resolveMiddleware(stack, { ...configuration, logger: this.config.logger }, options)
74
- : super.resolveMiddleware(stack, configuration, options);
75
- }
76
- };
90
+ resolveMiddleware(
91
+ stack: MiddlewareStack<any, any>,
92
+ configuration: BaseResolvedConfig,
93
+ options: any,
94
+ ) {
95
+ return super.resolveMiddleware(stack, {
96
+ ...configuration,
97
+ ...(this.config.logger ? { logger: this.config.logger } : {}),
98
+ ...(Option.isSome(maybeRequestHandler)
99
+ ? { requestHandler: HttpHandler.toClientRequestHandler(maybeRequestHandler.value, this.runtimeOptions) }
100
+ : {}),
101
+ }, options);
102
+ }
103
+ };
77
104
 
78
- const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
79
- return [serviceFnName, serviceFnMaker(ExtendedCommand)];
80
- }) as Service;
105
+ const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
106
+ return [serviceFnName, serviceFnMaker(ExtendedCommand)];
107
+ }) as Service;
108
+ });
81
109
 
82
110
  /**
83
111
  * @since 0.1.0
@@ -87,4 +115,5 @@ export const fromClientAndCommands = <Service>(
87
115
  client: Client<any, any, BaseResolvedConfig>,
88
116
  commands: Record<string, CommandCtor<any>>,
89
117
  options: ServiceFnOptions,
90
- ): Service => fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, options));
118
+ ): Effect.Effect<Service> =>
119
+ fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, options));
package/src/index.ts CHANGED
@@ -17,3 +17,8 @@ export * from "./Errors.js";
17
17
  * @since 0.1.0
18
18
  */
19
19
  export * from "./Types.js";
20
+
21
+ /**
22
+ * @since 0.3.0
23
+ */
24
+ export * as HttpHandler from "./HttpHandler.js";
@@ -0,0 +1,6 @@
1
+ import type { Runtime, Scope } from "effect";
2
+
3
+ export interface RuntimeOptions {
4
+ runtime: Runtime.Runtime<never>;
5
+ scope: Scope.Scope;
6
+ }