@rocketmq/core 0.1.2 → 0.1.3
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/.turbo/turbo-build.log +10 -8
- package/CHANGELOG.md +14 -0
- package/README.md +67 -6
- package/dist/index.cjs +4829 -163
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +255 -33
- package/dist/index.d.ts +255 -33
- package/dist/index.js +4825 -165
- package/dist/index.js.map +1 -0
- package/package.json +6 -5
- package/src/client.test.ts +256 -13
- package/src/client.ts +195 -81
- package/src/error-codes.ts +30 -0
- package/src/error-parser.test.ts +223 -0
- package/src/error-parser.ts +189 -0
- package/src/errors.test.ts +14 -11
- package/src/errors.ts +40 -3
- package/src/index.ts +31 -1
- package/src/queue-handle.test.ts +14 -140
- package/src/queue-handle.ts +8 -66
- package/src/schema-resolver.test.ts +112 -0
- package/src/schema-resolver.ts +99 -0
- package/tsup.config.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @rocketmq/core@0.1.
|
|
3
|
+
> @rocketmq/core@0.1.3 build /home/edilson/learnspace/rocketmq-broker/rocketmq.js/packages/core
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
CLI Building entry: src/index.ts
|
|
@@ -11,11 +11,13 @@ CLI Target: es2022
|
|
|
11
11
|
CLI Cleaning output folder
|
|
12
12
|
ESM Build start
|
|
13
13
|
CJS Build start
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ESM
|
|
17
|
-
|
|
14
|
+
ESM dist/index.js 140.69 KB
|
|
15
|
+
ESM dist/index.js.map 287.29 KB
|
|
16
|
+
ESM ⚡️ Build success in 93ms
|
|
17
|
+
CJS dist/index.cjs 142.39 KB
|
|
18
|
+
CJS dist/index.cjs.map 287.10 KB
|
|
19
|
+
CJS ⚡️ Build success in 93ms
|
|
18
20
|
DTS Build start
|
|
19
|
-
DTS ⚡️ Build success in
|
|
20
|
-
DTS dist/index.d.ts
|
|
21
|
-
DTS dist/index.d.cts
|
|
21
|
+
DTS ⚡️ Build success in 719ms
|
|
22
|
+
DTS dist/index.d.ts 15.18 KB
|
|
23
|
+
DTS dist/index.d.cts 15.18 KB
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @rocketmq/core
|
|
2
|
+
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- docs: comprehensive README and API docs like Python SDK
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @rocketmq/schema@0.1.2
|
|
11
|
+
- @rocketmq/amqp@0.1.2
|
|
12
|
+
- @rocketmq/zod@0.1.1
|
|
13
|
+
- @rocketmq/protobuf@0.1.2
|
|
14
|
+
- @rocketmq/serializer@0.1.2
|
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ class Order {
|
|
|
30
30
|
|
|
31
31
|
async function main() {
|
|
32
32
|
const mq = await connect();
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
// Creates a typed queue handle and registers the schema with the broker
|
|
35
35
|
const orders = await mq.queue('orders', Order);
|
|
36
36
|
|
|
@@ -55,16 +55,77 @@ async function classicApiExample() {
|
|
|
55
55
|
// Asserts the queue and registers the schema with the broker
|
|
56
56
|
await mq.assertQueue('orders', Order);
|
|
57
57
|
|
|
58
|
-
// Type-safe consumption
|
|
59
|
-
await mq.consume('orders', (order) => {
|
|
60
|
-
console.log(`Received order: ${order.id} for ${order.quantity} items`);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
58
|
// Type-safe publishing
|
|
64
59
|
mq.sendToQueue('orders', { id: '123', quantity: 5 });
|
|
60
|
+
|
|
61
|
+
// Type-safe consumption — annotate the handler parameter for
|
|
62
|
+
// compile-time safety, and pass consumerSchema for broker-side
|
|
63
|
+
// validation (TypeScript erases types at runtime).
|
|
64
|
+
await mq.consume('orders', (order: Order) => {
|
|
65
|
+
console.log(`Received order: ${order.id} for ${order.quantity} items`);
|
|
66
|
+
}, { consumerSchema: Order });
|
|
65
67
|
}
|
|
66
68
|
```
|
|
67
69
|
|
|
70
|
+
### Schema Lifecycle
|
|
71
|
+
|
|
72
|
+
The broker enforces schema contracts on every publish. You can evolve or remove schemas at runtime using `schemaOverride` and `schemaDelete`.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { connect, Schema, Field } from '@rocketmq/core';
|
|
76
|
+
|
|
77
|
+
@Schema()
|
|
78
|
+
class OrderV1 {
|
|
79
|
+
@Field()
|
|
80
|
+
id!: string;
|
|
81
|
+
|
|
82
|
+
@Field({ type: 'int32' })
|
|
83
|
+
quantity!: number;
|
|
84
|
+
|
|
85
|
+
@Field()
|
|
86
|
+
customer!: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Schema()
|
|
90
|
+
class OrderV2 {
|
|
91
|
+
@Field()
|
|
92
|
+
id!: string;
|
|
93
|
+
|
|
94
|
+
@Field({ type: 'int32' })
|
|
95
|
+
quantity!: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function schemaLifecycle() {
|
|
99
|
+
const mq = await connect();
|
|
100
|
+
|
|
101
|
+
// ── Step 1: Declare with schema ────────────────────────────
|
|
102
|
+
// The broker compiles OrderV1 into a proto descriptor and
|
|
103
|
+
// validates every published message against it.
|
|
104
|
+
await mq.assertQueue('orders', OrderV1);
|
|
105
|
+
|
|
106
|
+
mq.sendToQueue('orders', { id: '1', quantity: 5, customer: 'Acme' });
|
|
107
|
+
// ✅ Accepted — payload matches OrderV1
|
|
108
|
+
|
|
109
|
+
// ── Step 2: Override with a new schema ─────────────────────
|
|
110
|
+
// OrderV2 drops the "customer" field. Without schemaOverride
|
|
111
|
+
// this would fail with a PRECONDITION_FAILED (406) error.
|
|
112
|
+
await mq.assertQueue('orders', OrderV2, { schemaOverride: true });
|
|
113
|
+
|
|
114
|
+
mq.sendToQueue('orders', { id: '2', quantity: 10 });
|
|
115
|
+
// ✅ Accepted — payload matches OrderV2
|
|
116
|
+
|
|
117
|
+
// ── Step 3: Delete schema (schemaless mode) ────────────────
|
|
118
|
+
// Removes the schema binding entirely. The queue now accepts
|
|
119
|
+
// any JSON payload without validation.
|
|
120
|
+
await mq.assertQueue('orders', OrderV2, { schemaDelete: true });
|
|
121
|
+
|
|
122
|
+
mq.sendToQueue('orders', { anything: 'goes', nested: { ok: true } });
|
|
123
|
+
// ✅ Accepted — no schema to enforce
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> **Note**: `schemaOverride` and `schemaDelete` map to the AMQP queue arguments `x-schema-override` and `x-schema-delete` respectively.
|
|
128
|
+
|
|
68
129
|
## License
|
|
69
130
|
|
|
70
131
|
Apache 2.0
|