@btravstack/amqp-client 0.0.0-stage → 0.21.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/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +15 -0
- package/package.json +58 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benoit TRAVERS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@btravstack/amqp-client`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Bind a contract-specific `TypedAmqpClient` to a DI port. Define the client
|
|
4
|
+
port in the application and pass it, the contract, and a settings port to
|
|
5
|
+
`amqpClient(port, contract, settings)`. Settings provide `url` and optionally
|
|
6
|
+
`connectTimeoutMs` (default 5 seconds). The provider acquires the client at
|
|
7
|
+
scope opening, returns the upstream `ConnectionError` on failure, and closes
|
|
8
|
+
the client when the scope ends.
|
|
9
|
+
|
|
10
|
+
The [order publisher](../../examples/order-amqp-worker/src/outbox-publisher.ts)
|
|
11
|
+
is a complete example. Its `OutboxPublisher` maps committed rows to the
|
|
12
|
+
application's event envelope; that mapping stays in the application.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _amqp_contract_client = require("@amqp-contract/client");
|
|
3
|
+
let _btravstack_di = require("@btravstack/di");
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
/** Bind a typed AMQP client to an application port for the lifetime of the DI scope. */
|
|
6
|
+
const amqpClient = (port, contract, settings) => (0, _btravstack_di.Provider)(port)({
|
|
7
|
+
inject: { settings },
|
|
8
|
+
acquire: ({ settings: { url, connectTimeoutMs } }) => _amqp_contract_client.TypedAmqpClient.create({
|
|
9
|
+
contract,
|
|
10
|
+
urls: [url],
|
|
11
|
+
connectTimeoutMs: connectTimeoutMs ?? 5e3
|
|
12
|
+
}),
|
|
13
|
+
release: (client) => client.close().get()
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.amqpClient = amqpClient;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConnectionError, TypedAmqpClient } from "@amqp-contract/client";
|
|
2
|
+
import { PortClassOf, Provider } from "@btravstack/di";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** A contract accepted by the underlying typed AMQP client. */
|
|
5
|
+
export type AnyAmqpContract = Parameters<typeof TypedAmqpClient.create>[0]["contract"];
|
|
6
|
+
/** The deployment settings needed to open a publisher connection. */
|
|
7
|
+
export type AmqpClientSettings = {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly connectTimeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
/** Bind a typed AMQP client to an application port for the lifetime of the DI scope. */
|
|
12
|
+
export declare const amqpClient: <C extends AnyAmqpContract, Settings extends AmqpClientSettings, const ClientId extends string, const SettingsId extends string>(port: PortClassOf<ClientId, TypedAmqpClient<C>>, contract: C, settings: PortClassOf<SettingsId, Settings>) => Provider<import("@btravstack/di").PortInstance<ClientId, TypedAmqpClient<C>>, ConnectionError, import("@btravstack/di").PortInstance<SettingsId, Settings> | import("@btravstack/di").Scope> & {
|
|
13
|
+
readonly port: PortClassOf<ClientId, TypedAmqpClient<C>>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConnectionError, TypedAmqpClient } from "@amqp-contract/client";
|
|
2
|
+
import { PortClassOf, Provider } from "@btravstack/di";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** A contract accepted by the underlying typed AMQP client. */
|
|
5
|
+
export type AnyAmqpContract = Parameters<typeof TypedAmqpClient.create>[0]["contract"];
|
|
6
|
+
/** The deployment settings needed to open a publisher connection. */
|
|
7
|
+
export type AmqpClientSettings = {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly connectTimeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
/** Bind a typed AMQP client to an application port for the lifetime of the DI scope. */
|
|
12
|
+
export declare const amqpClient: <C extends AnyAmqpContract, Settings extends AmqpClientSettings, const ClientId extends string, const SettingsId extends string>(port: PortClassOf<ClientId, TypedAmqpClient<C>>, contract: C, settings: PortClassOf<SettingsId, Settings>) => Provider<import("@btravstack/di").PortInstance<ClientId, TypedAmqpClient<C>>, ConnectionError, import("@btravstack/di").PortInstance<SettingsId, Settings> | import("@btravstack/di").Scope> & {
|
|
13
|
+
readonly port: PortClassOf<ClientId, TypedAmqpClient<C>>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TypedAmqpClient } from "@amqp-contract/client";
|
|
2
|
+
import { Provider } from "@btravstack/di";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/** Bind a typed AMQP client to an application port for the lifetime of the DI scope. */
|
|
5
|
+
const amqpClient = (port, contract, settings) => Provider(port)({
|
|
6
|
+
inject: { settings },
|
|
7
|
+
acquire: ({ settings: { url, connectTimeoutMs } }) => TypedAmqpClient.create({
|
|
8
|
+
contract,
|
|
9
|
+
urls: [url],
|
|
10
|
+
connectTimeoutMs: connectTimeoutMs ?? 5e3
|
|
11
|
+
}),
|
|
12
|
+
release: (client) => client.close().get()
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { amqpClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btravstack/amqp-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.21.0",
|
|
4
|
+
"description": "Scoped DI binding for @amqp-contract/client",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/btravstack/btravstack.git",
|
|
10
|
+
"directory": "packages/amqp-client"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
|
+
"default": "./dist/index.mjs"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/index.d.cts",
|
|
28
|
+
"default": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@amqp-contract/client": "3.0.0-beta.11",
|
|
35
|
+
"@btravstack/di": "0.21.0",
|
|
36
|
+
"@btravstack/tsconfig": "0.4.0",
|
|
37
|
+
"@opentelemetry/api": "1.9.1",
|
|
38
|
+
"@types/node": "26.6.4",
|
|
39
|
+
"@unthrown/vitest": "5.12.0",
|
|
40
|
+
"@vitest/coverage-v8": "5.0.3",
|
|
41
|
+
"tsdown": "0.23.0",
|
|
42
|
+
"typescript": "7.0.2",
|
|
43
|
+
"unthrown": "5.12.0",
|
|
44
|
+
"vitest": "5.0.3"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@amqp-contract/client": "^3.0.0-beta.11",
|
|
48
|
+
"@btravstack/di": "^0.21.0",
|
|
49
|
+
"@opentelemetry/api": "^1",
|
|
50
|
+
"unthrown": "^5.12.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=22.22"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|
|
57
|
+
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
58
|
+
"test": "vitest run --coverage",
|
|
59
|
+
"typecheck": "tsc --noEmit"
|
|
60
|
+
}
|
|
6
61
|
}
|