@effect-aws/commons 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Service.d.ts +8 -4
- package/dist/cjs/Service.d.ts.map +1 -1
- package/dist/cjs/Service.js +21 -6
- package/dist/cjs/Service.js.map +1 -1
- package/dist/cjs/internal/types.d.ts +2 -0
- package/dist/cjs/internal/types.d.ts.map +1 -0
- package/dist/cjs/internal/types.js +3 -0
- package/dist/cjs/internal/types.js.map +1 -0
- package/dist/dts/Service.d.ts +8 -4
- package/dist/dts/Service.d.ts.map +1 -1
- package/dist/dts/internal/types.d.ts +2 -0
- package/dist/dts/internal/types.d.ts.map +1 -0
- package/dist/esm/Service.js +21 -6
- package/dist/esm/Service.js.map +1 -1
- package/dist/esm/internal/types.js +2 -0
- package/dist/esm/internal/types.js.map +1 -0
- package/package.json +2 -2
- package/src/Service.ts +35 -12
- package/src/internal/types.ts +23 -0
package/dist/cjs/Service.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.1.0
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { ServiceException } from "@smithy/smithy-client";
|
|
5
5
|
import type { Client } from "@smithy/types";
|
|
6
6
|
import type { Array } from "effect";
|
|
7
7
|
import { Effect } from "effect";
|
|
8
8
|
import type { TaggedException } from "./Errors.js";
|
|
9
9
|
import { SdkError } from "./Errors.js";
|
|
10
|
+
import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/types.js";
|
|
10
11
|
import type { HttpHandlerOptions } from "./Types.js";
|
|
11
|
-
type
|
|
12
|
+
type ServiceFnOptions = {
|
|
13
|
+
errorTags?: Array.NonEmptyReadonlyArray<string>;
|
|
14
|
+
resolveClientConfig: Effect.Effect<LoggerResolvedConfig>;
|
|
15
|
+
};
|
|
12
16
|
/**
|
|
13
17
|
* @since 0.1.0
|
|
14
18
|
* @category errors
|
|
@@ -18,7 +22,7 @@ export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonly
|
|
|
18
22
|
* @since 0.1.0
|
|
19
23
|
* @category constructors
|
|
20
24
|
*/
|
|
21
|
-
export declare const makeServiceFn: (client: Client<any, any,
|
|
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>;
|
|
22
26
|
/**
|
|
23
27
|
* @since 0.1.0
|
|
24
28
|
* @category constructors
|
|
@@ -28,6 +32,6 @@ export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string
|
|
|
28
32
|
* @since 0.1.0
|
|
29
33
|
* @category constructors
|
|
30
34
|
*/
|
|
31
|
-
export declare const fromClientAndCommands: <Service>(client: Client<any, any,
|
|
35
|
+
export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Service;
|
|
32
36
|
export {};
|
|
33
37
|
//# 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,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,qBAAqB,CAAC;AACjG,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,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;CAC1D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,eAAgB,MAAM,qBAAqB,CAAC,MAAM,CAAC,SAAS,OAAO,iDAUrG,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,4EAQhD,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,OAoBY,CAAC;AAEhB;;;GAGG;AACH,eAAO,MAAM,qBAAqB,oBACxB,OAAO,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,YAClC,OAAO,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,WACjC,gBAAgB,KACxB,OAA2G,CAAC"}
|
package/dist/cjs/Service.js
CHANGED
|
@@ -26,10 +26,13 @@ exports.catchServiceExceptions = catchServiceExceptions;
|
|
|
26
26
|
* @since 0.1.0
|
|
27
27
|
* @category constructors
|
|
28
28
|
*/
|
|
29
|
-
const makeServiceFn = (client, CommandCtor,
|
|
30
|
-
return (args, options) => effect_1.Effect.
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const makeServiceFn = (client, CommandCtor, fnOptions) => {
|
|
30
|
+
return (args, options) => effect_1.Effect.gen(function* () {
|
|
31
|
+
const config = yield* fnOptions.resolveClientConfig;
|
|
32
|
+
return yield* effect_1.Effect.tryPromise({
|
|
33
|
+
try: (abortSignal) => client.send(new CommandCtor(args, config), { ...(options ?? {}), abortSignal }),
|
|
34
|
+
catch: (0, exports.catchServiceExceptions)(fnOptions.errorTags),
|
|
35
|
+
});
|
|
33
36
|
});
|
|
34
37
|
};
|
|
35
38
|
exports.makeServiceFn = makeServiceFn;
|
|
@@ -38,14 +41,26 @@ exports.makeServiceFn = makeServiceFn;
|
|
|
38
41
|
* @category constructors
|
|
39
42
|
*/
|
|
40
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
|
+
};
|
|
41
56
|
const serviceFnName = effect_1.String.uncapitalize(command).replace(/Command$/, "");
|
|
42
|
-
return [serviceFnName, serviceFnMaker(
|
|
57
|
+
return [serviceFnName, serviceFnMaker(ExtendedCommand)];
|
|
43
58
|
});
|
|
44
59
|
exports.fromCommandsAndServiceFn = fromCommandsAndServiceFn;
|
|
45
60
|
/**
|
|
46
61
|
* @since 0.1.0
|
|
47
62
|
* @category constructors
|
|
48
63
|
*/
|
|
49
|
-
const fromClientAndCommands = (client, commands,
|
|
64
|
+
const fromClientAndCommands = (client, commands, options) => (0, exports.fromCommandsAndServiceFn)(commands, (CommandCtor) => (0, exports.makeServiceFn)(client, CommandCtor, options));
|
|
50
65
|
exports.fromClientAndCommands = fromClientAndCommands;
|
|
51
66
|
//# sourceMappingURL=Service.js.map
|
package/dist/cjs/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,
|
|
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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,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3E,OAAO,CAAC,aAAa,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;AAC1D,CAAC,CAAY,CAAC;AAvBH,QAAA,wBAAwB,4BAuBrB;AAEhB;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CACnC,MAA4C,EAC5C,QAA0C,EAC1C,OAAyB,EAChB,EAAE,CAAC,IAAA,gCAAwB,EAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAJlG,QAAA,qBAAqB,yBAI6E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/internal/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internal/types.ts"],"names":[],"mappings":""}
|
package/dist/dts/Service.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.1.0
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { ServiceException } from "@smithy/smithy-client";
|
|
5
5
|
import type { Client } from "@smithy/types";
|
|
6
6
|
import type { Array } from "effect";
|
|
7
7
|
import { Effect } from "effect";
|
|
8
8
|
import type { TaggedException } from "./Errors.js";
|
|
9
9
|
import { SdkError } from "./Errors.js";
|
|
10
|
+
import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/types.js";
|
|
10
11
|
import type { HttpHandlerOptions } from "./Types.js";
|
|
11
|
-
type
|
|
12
|
+
type ServiceFnOptions = {
|
|
13
|
+
errorTags?: Array.NonEmptyReadonlyArray<string>;
|
|
14
|
+
resolveClientConfig: Effect.Effect<LoggerResolvedConfig>;
|
|
15
|
+
};
|
|
12
16
|
/**
|
|
13
17
|
* @since 0.1.0
|
|
14
18
|
* @category errors
|
|
@@ -18,7 +22,7 @@ export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonly
|
|
|
18
22
|
* @since 0.1.0
|
|
19
23
|
* @category constructors
|
|
20
24
|
*/
|
|
21
|
-
export declare const makeServiceFn: (client: Client<any, any,
|
|
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>;
|
|
22
26
|
/**
|
|
23
27
|
* @since 0.1.0
|
|
24
28
|
* @category constructors
|
|
@@ -28,6 +32,6 @@ export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string
|
|
|
28
32
|
* @since 0.1.0
|
|
29
33
|
* @category constructors
|
|
30
34
|
*/
|
|
31
|
-
export declare const fromClientAndCommands: <Service>(client: Client<any, any,
|
|
35
|
+
export declare const fromClientAndCommands: <Service>(client: Client<any, any, BaseResolvedConfig>, commands: Record<string, CommandCtor<any>>, options: ServiceFnOptions) => Service;
|
|
32
36
|
export {};
|
|
33
37
|
//# 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,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,qBAAqB,CAAC;AACjG,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,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;CAC1D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,eAAgB,MAAM,qBAAqB,CAAC,MAAM,CAAC,SAAS,OAAO,iDAUrG,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,4EAQhD,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,OAoBY,CAAC;AAEhB;;;GAGG;AACH,eAAO,MAAM,qBAAqB,oBACxB,OAAO,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,YAClC,OAAO,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,WACjC,gBAAgB,KACxB,OAA2G,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/internal/types.ts"],"names":[],"mappings":""}
|
package/dist/esm/Service.js
CHANGED
|
@@ -22,10 +22,13 @@ export const catchServiceExceptions = (errorTags) => (e) => {
|
|
|
22
22
|
* @since 0.1.0
|
|
23
23
|
* @category constructors
|
|
24
24
|
*/
|
|
25
|
-
export const makeServiceFn = (client, CommandCtor,
|
|
26
|
-
return (args, options) => Effect.
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
export const makeServiceFn = (client, CommandCtor, fnOptions) => {
|
|
26
|
+
return (args, options) => Effect.gen(function* () {
|
|
27
|
+
const config = yield* fnOptions.resolveClientConfig;
|
|
28
|
+
return yield* Effect.tryPromise({
|
|
29
|
+
try: (abortSignal) => client.send(new CommandCtor(args, config), { ...(options ?? {}), abortSignal }),
|
|
30
|
+
catch: catchServiceExceptions(fnOptions.errorTags),
|
|
31
|
+
});
|
|
29
32
|
});
|
|
30
33
|
};
|
|
31
34
|
/**
|
|
@@ -33,12 +36,24 @@ export const makeServiceFn = (client, CommandCtor, errorTags) => {
|
|
|
33
36
|
* @category constructors
|
|
34
37
|
*/
|
|
35
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
|
+
};
|
|
36
51
|
const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
|
|
37
|
-
return [serviceFnName, serviceFnMaker(
|
|
52
|
+
return [serviceFnName, serviceFnMaker(ExtendedCommand)];
|
|
38
53
|
});
|
|
39
54
|
/**
|
|
40
55
|
* @since 0.1.0
|
|
41
56
|
* @category constructors
|
|
42
57
|
*/
|
|
43
|
-
export const fromClientAndCommands = (client, commands,
|
|
58
|
+
export const fromClientAndCommands = (client, commands, options) => fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, options));
|
|
44
59
|
//# sourceMappingURL=Service.js.map
|
package/dist/esm/Service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,
|
|
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,aAAa,GAAG,C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AAC;QAC7D,CAAC;KACF,CAAC;IAEF,MAAM,aAAa,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3E,OAAO,CAAC,aAAa,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;AAC1D,CAAC,CAAY,CAAC;AAEhB;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAA4C,EAC5C,QAA0C,EAC1C,OAAyB,EAChB,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internal/types.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.2.0",
|
|
4
4
|
"description": "Effectful AWS common library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"homepage": "https://floydspace.github.io/effect-aws/docs/commons",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@smithy/smithy-client": "^4.1.
|
|
18
|
+
"@smithy/smithy-client": "^4.1.6",
|
|
19
19
|
"@smithy/types": "^4.1.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
package/src/Service.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 0.1.0
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import type { Client } from "@smithy/types";
|
|
4
|
+
import { ServiceException } from "@smithy/smithy-client";
|
|
5
|
+
import type { Client, MiddlewareStack } from "@smithy/types";
|
|
6
6
|
import type { Array } from "effect";
|
|
7
7
|
import { Data, Effect, Record, String } from "effect";
|
|
8
8
|
import type { TaggedException } from "./Errors.js";
|
|
9
9
|
import { SdkError } from "./Errors.js";
|
|
10
|
+
import type { BaseResolvedConfig, CommandCtor, LoggerResolvedConfig } from "./internal/types.js";
|
|
10
11
|
import type { HttpHandlerOptions } from "./Types.js";
|
|
11
12
|
|
|
12
|
-
type
|
|
13
|
+
type ServiceFnOptions = {
|
|
14
|
+
errorTags?: Array.NonEmptyReadonlyArray<string>;
|
|
15
|
+
resolveClientConfig: Effect.Effect<LoggerResolvedConfig>;
|
|
16
|
+
};
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* @since 0.1.0
|
|
@@ -32,14 +36,17 @@ export const catchServiceExceptions = (errorTags?: Array.NonEmptyReadonlyArray<s
|
|
|
32
36
|
* @category constructors
|
|
33
37
|
*/
|
|
34
38
|
export const makeServiceFn = (
|
|
35
|
-
client: Client<any, any,
|
|
39
|
+
client: Client<any, any, BaseResolvedConfig>,
|
|
36
40
|
CommandCtor: CommandCtor<any>,
|
|
37
|
-
|
|
41
|
+
fnOptions: ServiceFnOptions,
|
|
38
42
|
) => {
|
|
39
43
|
return (args: any, options?: HttpHandlerOptions) =>
|
|
40
|
-
Effect.
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
Effect.gen(function*() {
|
|
45
|
+
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
|
+
});
|
|
43
50
|
});
|
|
44
51
|
};
|
|
45
52
|
|
|
@@ -52,8 +59,24 @@ export const fromCommandsAndServiceFn = <Service>(
|
|
|
52
59
|
serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>,
|
|
53
60
|
): Service =>
|
|
54
61
|
Record.mapEntries(commands, (CommandCtor, command) => {
|
|
62
|
+
const ExtendedCommand = class extends CommandCtor {
|
|
63
|
+
constructor(args: any, private config?: LoggerResolvedConfig) {
|
|
64
|
+
super(args);
|
|
65
|
+
}
|
|
66
|
+
|
|
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
|
+
};
|
|
77
|
+
|
|
55
78
|
const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
|
|
56
|
-
return [serviceFnName, serviceFnMaker(
|
|
79
|
+
return [serviceFnName, serviceFnMaker(ExtendedCommand)];
|
|
57
80
|
}) as Service;
|
|
58
81
|
|
|
59
82
|
/**
|
|
@@ -61,7 +84,7 @@ export const fromCommandsAndServiceFn = <Service>(
|
|
|
61
84
|
* @category constructors
|
|
62
85
|
*/
|
|
63
86
|
export const fromClientAndCommands = <Service>(
|
|
64
|
-
client: Client<any, any,
|
|
87
|
+
client: Client<any, any, BaseResolvedConfig>,
|
|
65
88
|
commands: Record<string, CommandCtor<any>>,
|
|
66
|
-
|
|
67
|
-
): Service => fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor,
|
|
89
|
+
options: ServiceFnOptions,
|
|
90
|
+
): Service => fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, options));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CommandImpl, SmithyResolvedConfiguration } from "@smithy/smithy-client";
|
|
2
|
+
import type { HandlerOptions, Logger, RequestHandler } from "@smithy/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface LoggerResolvedConfig {
|
|
8
|
+
logger?: Logger;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export interface BaseResolvedConfig
|
|
15
|
+
extends Required<LoggerResolvedConfig>, SmithyResolvedConfiguration<HandlerOptions>
|
|
16
|
+
{
|
|
17
|
+
requestHandler: RequestHandler<any, any, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export type CommandCtor<I> = new(input: I, ...args: Array<any>) => CommandImpl<I, any, BaseResolvedConfig>;
|