@cargolift-cdi/types 0.1.0 → 0.1.2
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/README.md
CHANGED
|
@@ -1,22 +1,59 @@
|
|
|
1
|
-
# cargolift-types
|
|
1
|
+
# @cargolift-cdi/types
|
|
2
2
|
|
|
3
|
-
Shared TypeScript types and interfaces for Node.js projects.
|
|
3
|
+
Shared TypeScript types and interfaces for Node.js projects. This package is types-only (no runtime JS).
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm
|
|
8
|
+
# npm
|
|
9
|
+
npm install -D @cargolift-cdi/types
|
|
10
|
+
|
|
11
|
+
# pnpm
|
|
12
|
+
pnpm add -D @cargolift-cdi/types
|
|
13
|
+
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add -D @cargolift-cdi/types
|
|
9
16
|
```
|
|
10
17
|
|
|
11
18
|
## Usage
|
|
12
19
|
|
|
20
|
+
Use type-only imports to avoid emitting runtime code:
|
|
21
|
+
|
|
13
22
|
```ts
|
|
14
|
-
import { RabbitMQMessage, RabbitMQChannel } from '@cargolift-cdi/types';
|
|
23
|
+
import type { RabbitMQMessage, RabbitMQChannel } from '@cargolift-cdi/types';
|
|
24
|
+
|
|
25
|
+
function handleMessage(msg: RabbitMQMessage, channel: RabbitMQChannel) {
|
|
26
|
+
const correlationId = msg.properties.headers['x-correlation-id'];
|
|
27
|
+
// ...process...
|
|
28
|
+
channel.ack(msg);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Example with amqplib:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import amqp from 'amqplib';
|
|
36
|
+
import type { RabbitMQMessage } from '@cargolift-cdi/types';
|
|
37
|
+
|
|
38
|
+
const conn = await amqp.connect(process.env.AMQP_URL!);
|
|
39
|
+
const ch = await conn.createChannel();
|
|
40
|
+
await ch.assertQueue('jobs');
|
|
41
|
+
|
|
42
|
+
ch.consume('jobs', (msg) => {
|
|
43
|
+
if (!msg) return;
|
|
44
|
+
const typedMsg = msg as unknown as RabbitMQMessage;
|
|
45
|
+
// use typedMsg.content, typedMsg.properties.headers, etc.
|
|
46
|
+
ch.ack(msg);
|
|
47
|
+
});
|
|
15
48
|
```
|
|
16
49
|
|
|
17
50
|
## What’s inside
|
|
18
51
|
|
|
19
|
-
- `rabbitmq.interfaces`: tipos para mensagens e canal RabbitMQ
|
|
52
|
+
- `rabbitmq.interfaces`: tipos para mensagens e canal RabbitMQ.
|
|
53
|
+
|
|
54
|
+
Notes
|
|
55
|
+
- This package ships only `.d.ts` files. There is no runtime code.
|
|
56
|
+
- Prefer `import type` (TS 4.5+) so bundlers/Node don’t try to load a runtime module.
|
|
20
57
|
|
|
21
58
|
## Development
|
|
22
59
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface AMQPMessage {
|
|
2
2
|
fields: any;
|
|
3
3
|
content: Buffer;
|
|
4
4
|
properties: {
|
|
@@ -6,10 +6,10 @@ export interface RabbitMQMessage {
|
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface AMQPChannel {
|
|
10
10
|
publish: (exchange: string, routingKey: string, content: Buffer, options: {
|
|
11
11
|
headers: Record<string, any>;
|
|
12
12
|
}) => boolean;
|
|
13
|
-
ack: (msg:
|
|
13
|
+
ack: (msg: AMQPMessage) => void;
|
|
14
14
|
}
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=amqp.interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amqp.interfaces.d.ts","sourceRoot":"","sources":["../src/amqp.interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE;QACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,CACP,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,KACtC,OAAO,CAAC;IACb,GAAG,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;CACjC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cargolift-cdi/types",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "TypeScript types e interfaces comuns para projetos Cargolift CDI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"types",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq.interfaces.d.ts","sourceRoot":"","sources":["../src/rabbitmq.interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE;QACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CACP,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,KACtC,OAAO,CAAC;IACb,GAAG,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;CACrC"}
|