@effect-aws/commons 0.1.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/Errors/package.json +6 -0
- package/LICENSE +19 -0
- package/README.md +12 -0
- package/Service/package.json +6 -0
- package/ServiceLogger/package.json +6 -0
- package/Types/package.json +6 -0
- package/dist/cjs/Errors.d.ts +11 -0
- package/dist/cjs/Errors.d.ts.map +1 -0
- package/dist/cjs/Errors.js +6 -0
- package/dist/cjs/Errors.js.map +1 -0
- package/dist/cjs/Service.d.ts +33 -0
- package/dist/cjs/Service.d.ts.map +1 -0
- package/dist/cjs/Service.js +51 -0
- package/dist/cjs/Service.js.map +1 -0
- package/dist/cjs/ServiceLogger.d.ts +49 -0
- package/dist/cjs/ServiceLogger.d.ts.map +1 -0
- package/dist/cjs/ServiceLogger.js +46 -0
- package/dist/cjs/ServiceLogger.js.map +1 -0
- package/dist/cjs/Types.d.ts +11 -0
- package/dist/cjs/Types.d.ts.map +1 -0
- package/dist/cjs/Types.js +3 -0
- package/dist/cjs/Types.js.map +1 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/dts/Errors.d.ts +11 -0
- package/dist/dts/Errors.d.ts.map +1 -0
- package/dist/dts/Service.d.ts +33 -0
- package/dist/dts/Service.d.ts.map +1 -0
- package/dist/dts/ServiceLogger.d.ts +49 -0
- package/dist/dts/ServiceLogger.d.ts.map +1 -0
- package/dist/dts/Types.d.ts +11 -0
- package/dist/dts/Types.d.ts.map +1 -0
- package/dist/dts/index.d.ts +17 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/esm/Errors.js +3 -0
- package/dist/esm/Errors.js.map +1 -0
- package/dist/esm/Service.js +44 -0
- package/dist/esm/Service.js.map +1 -0
- package/dist/esm/ServiceLogger.js +41 -0
- package/dist/esm/ServiceLogger.js.map +1 -0
- package/dist/esm/Types.js +2 -0
- package/dist/esm/Types.js.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +4 -0
- package/package.json +71 -0
- package/src/Errors.ts +8 -0
- package/src/Service.ts +67 -0
- package/src/ServiceLogger.ts +77 -0
- package/src/Types.ts +10 -0
- package/src/index.ts +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 Victor Korzunin
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @effect-aws/commons
|
|
2
|
+
|
|
3
|
+
Common utilities for Effectful AWS clients.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@effect-aws/commons)
|
|
6
|
+
[](https://www.npmjs.com/package/@effect-aws/commons)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install --save @effect-aws/commons
|
|
12
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
export type TaggedException<T extends {
|
|
3
|
+
name: string;
|
|
4
|
+
}> = T & {
|
|
5
|
+
readonly _tag: T["name"];
|
|
6
|
+
};
|
|
7
|
+
export type SdkError = TaggedException<Error & {
|
|
8
|
+
name: "SdkError";
|
|
9
|
+
}>;
|
|
10
|
+
export declare const SdkError: Data.Case.Constructor<SdkError, "_tag">;
|
|
11
|
+
//# sourceMappingURL=Errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../src/Errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,IAAI,CAAC,GAAG;IAC5D,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AACrE,eAAO,MAAM,QAAQ,yCAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.js","sourceRoot":"","sources":["../../src/Errors.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAOjB,QAAA,QAAQ,GAAG,aAAI,CAAC,MAAM,CAAW,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import { type CommandImpl, ServiceException } from "@smithy/smithy-client";
|
|
5
|
+
import type { Client } from "@smithy/types";
|
|
6
|
+
import type { Array } from "effect";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import type { TaggedException } from "./Errors.js";
|
|
9
|
+
import { SdkError } from "./Errors.js";
|
|
10
|
+
import type { HttpHandlerOptions } from "./Types.js";
|
|
11
|
+
type CommandCtor<I> = new (input: I) => CommandImpl<I, any, any>;
|
|
12
|
+
/**
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
* @category errors
|
|
15
|
+
*/
|
|
16
|
+
export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => SdkError | TaggedException<ServiceException>;
|
|
17
|
+
/**
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
* @category constructors
|
|
20
|
+
*/
|
|
21
|
+
export declare const makeServiceFn: (client: Client<any, any, any>, CommandCtor: CommandCtor<any>, errorTags?: Array.NonEmptyReadonlyArray<string>) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, SdkError | TaggedException<ServiceException>, never>;
|
|
22
|
+
/**
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
* @category constructors
|
|
25
|
+
*/
|
|
26
|
+
export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Service;
|
|
27
|
+
/**
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
* @category constructors
|
|
30
|
+
*/
|
|
31
|
+
export declare const fromClientAndCommands: <Service>(client: Client<any, any, any>, commands: Record<string, CommandCtor<any>>, errorTags?: Array.NonEmptyReadonlyArray<string>) => Service;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=Service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/Service.ts"],"names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|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromClientAndCommands = exports.fromCommandsAndServiceFn = exports.makeServiceFn = exports.catchServiceExceptions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @since 0.1.0
|
|
6
|
+
*/
|
|
7
|
+
const smithy_client_1 = require("@smithy/smithy-client");
|
|
8
|
+
const effect_1 = require("effect");
|
|
9
|
+
const Errors_js_1 = require("./Errors.js");
|
|
10
|
+
/**
|
|
11
|
+
* @since 0.1.0
|
|
12
|
+
* @category errors
|
|
13
|
+
*/
|
|
14
|
+
const catchServiceExceptions = (errorTags) => (e) => {
|
|
15
|
+
if (e instanceof smithy_client_1.ServiceException && (!errorTags || errorTags.includes(e.name))) {
|
|
16
|
+
const ServiceException = effect_1.Data.tagged(e.name);
|
|
17
|
+
return ServiceException({ ...e, message: e.message, stack: e.stack });
|
|
18
|
+
}
|
|
19
|
+
if (e instanceof Error) {
|
|
20
|
+
return (0, Errors_js_1.SdkError)({ ...e, name: "SdkError", message: e.message, stack: e.stack });
|
|
21
|
+
}
|
|
22
|
+
throw e;
|
|
23
|
+
};
|
|
24
|
+
exports.catchServiceExceptions = catchServiceExceptions;
|
|
25
|
+
/**
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
* @category constructors
|
|
28
|
+
*/
|
|
29
|
+
const makeServiceFn = (client, CommandCtor, errorTags) => {
|
|
30
|
+
return (args, options) => effect_1.Effect.tryPromise({
|
|
31
|
+
try: (abortSignal) => client.send(new CommandCtor(args), { ...(options ?? {}), abortSignal }),
|
|
32
|
+
catch: (0, exports.catchServiceExceptions)(errorTags),
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.makeServiceFn = makeServiceFn;
|
|
36
|
+
/**
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
* @category constructors
|
|
39
|
+
*/
|
|
40
|
+
const fromCommandsAndServiceFn = (commands, serviceFnMaker) => effect_1.Record.mapEntries(commands, (CommandCtor, command) => {
|
|
41
|
+
const serviceFnName = effect_1.String.uncapitalize(command).replace(/Command$/, "");
|
|
42
|
+
return [serviceFnName, serviceFnMaker(CommandCtor)];
|
|
43
|
+
});
|
|
44
|
+
exports.fromCommandsAndServiceFn = fromCommandsAndServiceFn;
|
|
45
|
+
/**
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
* @category constructors
|
|
48
|
+
*/
|
|
49
|
+
const fromClientAndCommands = (client, commands, errorTags) => (0, exports.fromCommandsAndServiceFn)(commands, (CommandCtor) => (0, exports.makeServiceFn)(client, CommandCtor, errorTags));
|
|
50
|
+
exports.fromClientAndCommands = fromClientAndCommands;
|
|
51
|
+
//# sourceMappingURL=Service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAA2E;AAG3E,mCAAsD;AAEtD,2CAAuC;AAKvC;;;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,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}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import type { Logger } from "@smithy/types";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @category type ids
|
|
9
|
+
*/
|
|
10
|
+
export declare const TypeId: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
* @category type ids
|
|
14
|
+
*/
|
|
15
|
+
export type TypeId = typeof TypeId;
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
* @category constructors
|
|
19
|
+
*/
|
|
20
|
+
export type ServiceLoggerConstructorProps = {
|
|
21
|
+
readonly trace?: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
22
|
+
readonly debug: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
23
|
+
readonly info: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
24
|
+
readonly warn: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
25
|
+
readonly error: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
* @category models
|
|
30
|
+
*/
|
|
31
|
+
export interface ServiceLogger extends ServiceLoggerConstructorProps {
|
|
32
|
+
readonly [TypeId]: TypeId;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
* @category constructors
|
|
37
|
+
*/
|
|
38
|
+
export declare const make: (props: ServiceLoggerConstructorProps) => ServiceLogger;
|
|
39
|
+
/**
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
* @category constructors
|
|
42
|
+
*/
|
|
43
|
+
export declare const defaultServiceLogger: ServiceLogger;
|
|
44
|
+
/**
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
* @category adapters
|
|
47
|
+
*/
|
|
48
|
+
export declare const toClientLogger: (logger: ServiceLogger) => Effect.Effect<Logger>;
|
|
49
|
+
//# sourceMappingURL=ServiceLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLogger.d.ts","sourceRoot":"","sources":["../../src/ServiceLogger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAW,MAAM,QAAQ,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,MAAM,eAAkD,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAMnC;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACvF,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACtF,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACrF,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACrF,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CACvF,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,6BAA6B;IAClE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,UAAW,6BAA6B,KAAG,aAA2D,CAAC;AAExH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAM/B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAYxE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toClientLogger = exports.defaultServiceLogger = exports.make = exports.TypeId = void 0;
|
|
4
|
+
const effect_1 = require("effect");
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
* @category type ids
|
|
8
|
+
*/
|
|
9
|
+
exports.TypeId = Symbol.for("@effect-aws/commons/ServiceLogger");
|
|
10
|
+
const proto = {
|
|
11
|
+
[exports.TypeId]: exports.TypeId,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
* @category constructors
|
|
16
|
+
*/
|
|
17
|
+
const make = (props) => Object.assign(Object.create(proto), props);
|
|
18
|
+
exports.make = make;
|
|
19
|
+
/**
|
|
20
|
+
* @since 0.1.0
|
|
21
|
+
* @category constructors
|
|
22
|
+
*/
|
|
23
|
+
exports.defaultServiceLogger = (0, exports.make)({
|
|
24
|
+
trace: effect_1.Effect.logTrace,
|
|
25
|
+
debug: effect_1.Effect.logDebug,
|
|
26
|
+
info: effect_1.Effect.logInfo,
|
|
27
|
+
warn: effect_1.Effect.logWarning,
|
|
28
|
+
error: effect_1.Effect.logError,
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
* @category adapters
|
|
33
|
+
*/
|
|
34
|
+
const toClientLogger = (logger) => effect_1.Effect.gen(function* () {
|
|
35
|
+
const runtime = yield* effect_1.Effect.runtime();
|
|
36
|
+
const runSync = effect_1.Runtime.runSync(runtime);
|
|
37
|
+
return {
|
|
38
|
+
info: (...m) => logger.info(...m).pipe(runSync),
|
|
39
|
+
warn: (...m) => logger.warn(...m).pipe(runSync),
|
|
40
|
+
error: (...m) => logger.error(...m).pipe(runSync),
|
|
41
|
+
debug: (...m) => logger.debug(...m).pipe(runSync),
|
|
42
|
+
...(logger.trace ? { trace: (...m) => logger.trace(...m).pipe(runSync) } : {}),
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
exports.toClientLogger = toClientLogger;
|
|
46
|
+
//# sourceMappingURL=ServiceLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLogger.js","sourceRoot":"","sources":["../../src/ServiceLogger.ts"],"names":[],"mappings":";;;AAIA,mCAAyC;AAEzC;;;GAGG;AACU,QAAA,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAQtE,MAAM,KAAK,GAAG;IACZ,CAAC,cAAM,CAAC,EAAE,cAAM;CACjB,CAAC;AAsBF;;;GAGG;AACI,MAAM,IAAI,GAAG,CAAC,KAAoC,EAAiB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAA3G,QAAA,IAAI,QAAuG;AAExH;;;GAGG;AACU,QAAA,oBAAoB,GAAG,IAAA,YAAI,EAAC;IACvC,KAAK,EAAE,eAAM,CAAC,QAAQ;IACtB,KAAK,EAAE,eAAM,CAAC,QAAQ;IACtB,IAAI,EAAE,eAAM,CAAC,OAAO;IACpB,IAAI,EAAE,eAAM,CAAC,UAAU;IACvB,KAAK,EAAE,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time in milliseconds that the connection phase of a request
|
|
7
|
+
* may take before the connection attempt is abandoned.
|
|
8
|
+
*/
|
|
9
|
+
requestTimeout?: number;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../src/Types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.js","sourceRoot":"","sources":["../../src/Types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
export * as Service from "./Service.js";
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
*/
|
|
8
|
+
export * as ServiceLogger from "./ServiceLogger.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
export * from "./Errors.js";
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
*/
|
|
16
|
+
export * from "./Types.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ServiceLogger = exports.Service = void 0;
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
*/
|
|
33
|
+
exports.Service = __importStar(require("./Service.js"));
|
|
34
|
+
/**
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
*/
|
|
37
|
+
exports.ServiceLogger = __importStar(require("./ServiceLogger.js"));
|
|
38
|
+
/**
|
|
39
|
+
* @since 0.1.0
|
|
40
|
+
*/
|
|
41
|
+
__exportStar(require("./Errors.js"), exports);
|
|
42
|
+
/**
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
__exportStar(require("./Types.js"), exports);
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
export type TaggedException<T extends {
|
|
3
|
+
name: string;
|
|
4
|
+
}> = T & {
|
|
5
|
+
readonly _tag: T["name"];
|
|
6
|
+
};
|
|
7
|
+
export type SdkError = TaggedException<Error & {
|
|
8
|
+
name: "SdkError";
|
|
9
|
+
}>;
|
|
10
|
+
export declare const SdkError: Data.Case.Constructor<SdkError, "_tag">;
|
|
11
|
+
//# sourceMappingURL=Errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../src/Errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,IAAI,CAAC,GAAG;IAC5D,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AACrE,eAAO,MAAM,QAAQ,yCAAoC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import { type CommandImpl, ServiceException } from "@smithy/smithy-client";
|
|
5
|
+
import type { Client } from "@smithy/types";
|
|
6
|
+
import type { Array } from "effect";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import type { TaggedException } from "./Errors.js";
|
|
9
|
+
import { SdkError } from "./Errors.js";
|
|
10
|
+
import type { HttpHandlerOptions } from "./Types.js";
|
|
11
|
+
type CommandCtor<I> = new (input: I) => CommandImpl<I, any, any>;
|
|
12
|
+
/**
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
* @category errors
|
|
15
|
+
*/
|
|
16
|
+
export declare const catchServiceExceptions: (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => SdkError | TaggedException<ServiceException>;
|
|
17
|
+
/**
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
* @category constructors
|
|
20
|
+
*/
|
|
21
|
+
export declare const makeServiceFn: (client: Client<any, any, any>, CommandCtor: CommandCtor<any>, errorTags?: Array.NonEmptyReadonlyArray<string>) => (args: any, options?: HttpHandlerOptions) => Effect.Effect<any, SdkError | TaggedException<ServiceException>, never>;
|
|
22
|
+
/**
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
* @category constructors
|
|
25
|
+
*/
|
|
26
|
+
export declare const fromCommandsAndServiceFn: <Service>(commands: Record<string, CommandCtor<any>>, serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>) => Service;
|
|
27
|
+
/**
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
* @category constructors
|
|
30
|
+
*/
|
|
31
|
+
export declare const fromClientAndCommands: <Service>(client: Client<any, any, any>, commands: Record<string, CommandCtor<any>>, errorTags?: Array.NonEmptyReadonlyArray<string>) => Service;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=Service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../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0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import type { Logger } from "@smithy/types";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @category type ids
|
|
9
|
+
*/
|
|
10
|
+
export declare const TypeId: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
* @category type ids
|
|
14
|
+
*/
|
|
15
|
+
export type TypeId = typeof TypeId;
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
* @category constructors
|
|
19
|
+
*/
|
|
20
|
+
export type ServiceLoggerConstructorProps = {
|
|
21
|
+
readonly trace?: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
22
|
+
readonly debug: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
23
|
+
readonly info: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
24
|
+
readonly warn: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
25
|
+
readonly error: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
* @category models
|
|
30
|
+
*/
|
|
31
|
+
export interface ServiceLogger extends ServiceLoggerConstructorProps {
|
|
32
|
+
readonly [TypeId]: TypeId;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @since 0.1.0
|
|
36
|
+
* @category constructors
|
|
37
|
+
*/
|
|
38
|
+
export declare const make: (props: ServiceLoggerConstructorProps) => ServiceLogger;
|
|
39
|
+
/**
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
* @category constructors
|
|
42
|
+
*/
|
|
43
|
+
export declare const defaultServiceLogger: ServiceLogger;
|
|
44
|
+
/**
|
|
45
|
+
* @since 0.1.0
|
|
46
|
+
* @category adapters
|
|
47
|
+
*/
|
|
48
|
+
export declare const toClientLogger: (logger: ServiceLogger) => Effect.Effect<Logger>;
|
|
49
|
+
//# sourceMappingURL=ServiceLogger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLogger.d.ts","sourceRoot":"","sources":["../../src/ServiceLogger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAW,MAAM,QAAQ,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,MAAM,eAAkD,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AAMnC;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACvF,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACtF,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACrF,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACrF,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CACvF,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,6BAA6B;IAClE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,UAAW,6BAA6B,KAAG,aAA2D,CAAC;AAExH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,eAM/B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAYxE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
export interface HttpHandlerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The maximum time in milliseconds that the connection phase of a request
|
|
7
|
+
* may take before the connection attempt is abandoned.
|
|
8
|
+
*/
|
|
9
|
+
requestTimeout?: number;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../src/Types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
export * as Service from "./Service.js";
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
*/
|
|
8
|
+
export * as ServiceLogger from "./ServiceLogger.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
export * from "./Errors.js";
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
*/
|
|
16
|
+
export * from "./Types.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Errors.js","sourceRoot":"","sources":["../../src/Errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAO9B,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAW,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import { ServiceException } from "@smithy/smithy-client";
|
|
5
|
+
import { Data, Effect, Record, String } from "effect";
|
|
6
|
+
import { SdkError } from "./Errors.js";
|
|
7
|
+
/**
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @category errors
|
|
10
|
+
*/
|
|
11
|
+
export const catchServiceExceptions = (errorTags) => (e) => {
|
|
12
|
+
if (e instanceof ServiceException && (!errorTags || errorTags.includes(e.name))) {
|
|
13
|
+
const ServiceException = Data.tagged(e.name);
|
|
14
|
+
return ServiceException({ ...e, message: e.message, stack: e.stack });
|
|
15
|
+
}
|
|
16
|
+
if (e instanceof Error) {
|
|
17
|
+
return SdkError({ ...e, name: "SdkError", message: e.message, stack: e.stack });
|
|
18
|
+
}
|
|
19
|
+
throw e;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @since 0.1.0
|
|
23
|
+
* @category constructors
|
|
24
|
+
*/
|
|
25
|
+
export const makeServiceFn = (client, CommandCtor, errorTags) => {
|
|
26
|
+
return (args, options) => Effect.tryPromise({
|
|
27
|
+
try: (abortSignal) => client.send(new CommandCtor(args), { ...(options ?? {}), abortSignal }),
|
|
28
|
+
catch: catchServiceExceptions(errorTags),
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
* @category constructors
|
|
34
|
+
*/
|
|
35
|
+
export const fromCommandsAndServiceFn = (commands, serviceFnMaker) => Record.mapEntries(commands, (CommandCtor, command) => {
|
|
36
|
+
const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
|
|
37
|
+
return [serviceFnName, serviceFnMaker(CommandCtor)];
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
* @category constructors
|
|
42
|
+
*/
|
|
43
|
+
export const fromClientAndCommands = (client, commands, errorTags) => fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, errorTags));
|
|
44
|
+
//# sourceMappingURL=Service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/Service.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAoB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG3E,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC;;;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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AAC,WAAW,CAAC,CAAC,CAAC;AACtD,CAAC,CAAY,CAAC;AAEhB;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAA6B,EAC7B,QAA0C,EAC1C,SAA+C,EACtC,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Effect, Runtime } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* @since 0.1.0
|
|
4
|
+
* @category type ids
|
|
5
|
+
*/
|
|
6
|
+
export const TypeId = Symbol.for("@effect-aws/commons/ServiceLogger");
|
|
7
|
+
const proto = {
|
|
8
|
+
[TypeId]: TypeId,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @since 0.1.0
|
|
12
|
+
* @category constructors
|
|
13
|
+
*/
|
|
14
|
+
export const make = (props) => Object.assign(Object.create(proto), props);
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.1.0
|
|
17
|
+
* @category constructors
|
|
18
|
+
*/
|
|
19
|
+
export const defaultServiceLogger = make({
|
|
20
|
+
trace: Effect.logTrace,
|
|
21
|
+
debug: Effect.logDebug,
|
|
22
|
+
info: Effect.logInfo,
|
|
23
|
+
warn: Effect.logWarning,
|
|
24
|
+
error: Effect.logError,
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* @since 0.1.0
|
|
28
|
+
* @category adapters
|
|
29
|
+
*/
|
|
30
|
+
export const toClientLogger = (logger) => Effect.gen(function* () {
|
|
31
|
+
const runtime = yield* Effect.runtime();
|
|
32
|
+
const runSync = Runtime.runSync(runtime);
|
|
33
|
+
return {
|
|
34
|
+
info: (...m) => logger.info(...m).pipe(runSync),
|
|
35
|
+
warn: (...m) => logger.warn(...m).pipe(runSync),
|
|
36
|
+
error: (...m) => logger.error(...m).pipe(runSync),
|
|
37
|
+
debug: (...m) => logger.debug(...m).pipe(runSync),
|
|
38
|
+
...(logger.trace ? { trace: (...m) => logger.trace(...m).pipe(runSync) } : {}),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=ServiceLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLogger.js","sourceRoot":"","sources":["../../src/ServiceLogger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAQtE,MAAM,KAAK,GAAG;IACZ,CAAC,MAAM,CAAC,EAAE,MAAM;CACjB,CAAC;AAsBF;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAoC,EAAiB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAExH;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;IACvC,KAAK,EAAE,MAAM,CAAC,QAAQ;IACtB,KAAK,EAAE,MAAM,CAAC,QAAQ;IACtB,IAAI,EAAE,MAAM,CAAC,OAAO;IACpB,IAAI,EAAE,MAAM,CAAC,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC,QAAQ;CACvB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAqD,CAAC,MAAM,EAAE,EAAE,CACzF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAS,CAAC;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC,OAAO;QACL,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/C,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/C,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QACjD,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QACjD,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.js","sourceRoot":"","sources":["../../src/Types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
export * as Service from "./Service.js";
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.1.0
|
|
7
|
+
*/
|
|
8
|
+
export * as ServiceLogger from "./ServiceLogger.js";
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
export * from "./Errors.js";
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
*/
|
|
16
|
+
export * from "./Types.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effect-aws/commons",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Effectful AWS common library",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "github:floydspace/effect-aws",
|
|
9
|
+
"directory": "packages/commons"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": [],
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Victor Korzunin",
|
|
14
|
+
"email": "ifloydrose@gmail.com"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://floydspace.github.io/effect-aws/docs/commons",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@smithy/smithy-client": "^4.1.2",
|
|
19
|
+
"@smithy/types": "^4.1.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"effect": ">=3.0.4 <4.0.0"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/cjs/index.js",
|
|
25
|
+
"module": "./dist/esm/index.js",
|
|
26
|
+
"types": "./dist/dts/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
"./package.json": "./package.json",
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/dts/index.d.ts",
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"default": "./dist/cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./Errors": {
|
|
35
|
+
"types": "./dist/dts/Errors.d.ts",
|
|
36
|
+
"import": "./dist/esm/Errors.js",
|
|
37
|
+
"default": "./dist/cjs/Errors.js"
|
|
38
|
+
},
|
|
39
|
+
"./Service": {
|
|
40
|
+
"types": "./dist/dts/Service.d.ts",
|
|
41
|
+
"import": "./dist/esm/Service.js",
|
|
42
|
+
"default": "./dist/cjs/Service.js"
|
|
43
|
+
},
|
|
44
|
+
"./ServiceLogger": {
|
|
45
|
+
"types": "./dist/dts/ServiceLogger.d.ts",
|
|
46
|
+
"import": "./dist/esm/ServiceLogger.js",
|
|
47
|
+
"default": "./dist/cjs/ServiceLogger.js"
|
|
48
|
+
},
|
|
49
|
+
"./Types": {
|
|
50
|
+
"types": "./dist/dts/Types.d.ts",
|
|
51
|
+
"import": "./dist/esm/Types.js",
|
|
52
|
+
"default": "./dist/cjs/Types.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"typesVersions": {
|
|
56
|
+
"*": {
|
|
57
|
+
"Errors": [
|
|
58
|
+
"./dist/dts/Errors.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"Service": [
|
|
61
|
+
"./dist/dts/Service.d.ts"
|
|
62
|
+
],
|
|
63
|
+
"ServiceLogger": [
|
|
64
|
+
"./dist/dts/ServiceLogger.d.ts"
|
|
65
|
+
],
|
|
66
|
+
"Types": [
|
|
67
|
+
"./dist/dts/Types.d.ts"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/Errors.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
export type TaggedException<T extends { name: string }> = T & {
|
|
4
|
+
readonly _tag: T["name"];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type SdkError = TaggedException<Error & { name: "SdkError" }>;
|
|
8
|
+
export const SdkError = Data.tagged<SdkError>("SdkError");
|
package/src/Service.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import { type CommandImpl, ServiceException } from "@smithy/smithy-client";
|
|
5
|
+
import type { Client } from "@smithy/types";
|
|
6
|
+
import type { Array } from "effect";
|
|
7
|
+
import { Data, Effect, Record, String } from "effect";
|
|
8
|
+
import type { TaggedException } from "./Errors.js";
|
|
9
|
+
import { SdkError } from "./Errors.js";
|
|
10
|
+
import type { HttpHandlerOptions } from "./Types.js";
|
|
11
|
+
|
|
12
|
+
type CommandCtor<I> = new(input: I) => CommandImpl<I, any, any>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @since 0.1.0
|
|
16
|
+
* @category errors
|
|
17
|
+
*/
|
|
18
|
+
export const catchServiceExceptions = (errorTags?: Array.NonEmptyReadonlyArray<string>) => (e: unknown) => {
|
|
19
|
+
if (e instanceof ServiceException && (!errorTags || errorTags.includes(e.name))) {
|
|
20
|
+
const ServiceException = Data.tagged<TaggedException<ServiceException>>(e.name);
|
|
21
|
+
|
|
22
|
+
return ServiceException({ ...e, message: e.message, stack: e.stack });
|
|
23
|
+
}
|
|
24
|
+
if (e instanceof Error) {
|
|
25
|
+
return SdkError({ ...e, name: "SdkError", message: e.message, stack: e.stack });
|
|
26
|
+
}
|
|
27
|
+
throw e;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
* @category constructors
|
|
33
|
+
*/
|
|
34
|
+
export const makeServiceFn = (
|
|
35
|
+
client: Client<any, any, any>,
|
|
36
|
+
CommandCtor: CommandCtor<any>,
|
|
37
|
+
errorTags?: Array.NonEmptyReadonlyArray<string>,
|
|
38
|
+
) => {
|
|
39
|
+
return (args: any, options?: HttpHandlerOptions) =>
|
|
40
|
+
Effect.tryPromise({
|
|
41
|
+
try: (abortSignal) => client.send(new CommandCtor(args), { ...(options ?? {}), abortSignal }),
|
|
42
|
+
catch: catchServiceExceptions(errorTags),
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @since 0.1.0
|
|
48
|
+
* @category constructors
|
|
49
|
+
*/
|
|
50
|
+
export const fromCommandsAndServiceFn = <Service>(
|
|
51
|
+
commands: Record<string, CommandCtor<any>>,
|
|
52
|
+
serviceFnMaker: (CommandCtor: CommandCtor<any>) => ReturnType<typeof makeServiceFn>,
|
|
53
|
+
): Service =>
|
|
54
|
+
Record.mapEntries(commands, (CommandCtor, command) => {
|
|
55
|
+
const serviceFnName = String.uncapitalize(command).replace(/Command$/, "");
|
|
56
|
+
return [serviceFnName, serviceFnMaker(CommandCtor)];
|
|
57
|
+
}) as Service;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @since 0.1.0
|
|
61
|
+
* @category constructors
|
|
62
|
+
*/
|
|
63
|
+
export const fromClientAndCommands = <Service>(
|
|
64
|
+
client: Client<any, any, any>,
|
|
65
|
+
commands: Record<string, CommandCtor<any>>,
|
|
66
|
+
errorTags?: Array.NonEmptyReadonlyArray<string>,
|
|
67
|
+
): Service => fromCommandsAndServiceFn(commands, (CommandCtor) => makeServiceFn(client, CommandCtor, errorTags));
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
import type { Logger } from "@smithy/types";
|
|
5
|
+
import { Effect, Runtime } from "effect";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @category type ids
|
|
10
|
+
*/
|
|
11
|
+
export const TypeId = Symbol.for("@effect-aws/commons/ServiceLogger");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
* @category type ids
|
|
16
|
+
*/
|
|
17
|
+
export type TypeId = typeof TypeId;
|
|
18
|
+
|
|
19
|
+
const proto = {
|
|
20
|
+
[TypeId]: TypeId,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
* @category constructors
|
|
26
|
+
*/
|
|
27
|
+
export type ServiceLoggerConstructorProps = {
|
|
28
|
+
readonly trace?: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
29
|
+
readonly debug: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
30
|
+
readonly info: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
31
|
+
readonly warn: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
32
|
+
readonly error: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @since 0.1.0
|
|
37
|
+
* @category models
|
|
38
|
+
*/
|
|
39
|
+
export interface ServiceLogger extends ServiceLoggerConstructorProps {
|
|
40
|
+
readonly [TypeId]: TypeId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @since 0.1.0
|
|
45
|
+
* @category constructors
|
|
46
|
+
*/
|
|
47
|
+
export const make = (props: ServiceLoggerConstructorProps): ServiceLogger => Object.assign(Object.create(proto), props);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @since 0.1.0
|
|
51
|
+
* @category constructors
|
|
52
|
+
*/
|
|
53
|
+
export const defaultServiceLogger = make({
|
|
54
|
+
trace: Effect.logTrace,
|
|
55
|
+
debug: Effect.logDebug,
|
|
56
|
+
info: Effect.logInfo,
|
|
57
|
+
warn: Effect.logWarning,
|
|
58
|
+
error: Effect.logError,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @since 0.1.0
|
|
63
|
+
* @category adapters
|
|
64
|
+
*/
|
|
65
|
+
export const toClientLogger: (logger: ServiceLogger) => Effect.Effect<Logger> = (logger) =>
|
|
66
|
+
Effect.gen(function*() {
|
|
67
|
+
const runtime = yield* Effect.runtime<never>();
|
|
68
|
+
const runSync = Runtime.runSync(runtime);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
info: (...m) => logger.info(...m).pipe(runSync),
|
|
72
|
+
warn: (...m) => logger.warn(...m).pipe(runSync),
|
|
73
|
+
error: (...m) => logger.error(...m).pipe(runSync),
|
|
74
|
+
debug: (...m) => logger.debug(...m).pipe(runSync),
|
|
75
|
+
...(logger.trace ? { trace: (...m) => logger.trace!(...m).pipe(runSync) } : {}),
|
|
76
|
+
};
|
|
77
|
+
});
|
package/src/Types.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.1.0
|
|
3
|
+
*/
|
|
4
|
+
export * as Service from "./Service.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
*/
|
|
9
|
+
export * as ServiceLogger from "./ServiceLogger.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
*/
|
|
14
|
+
export * from "./Errors.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @since 0.1.0
|
|
18
|
+
*/
|
|
19
|
+
export * from "./Types.js";
|