@rocketmq/core 0.1.1 → 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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- > @rocketmq/core@0.1.0 build /home/edilson/learnspace/rocketmq-broker/rocketmq.js/packages/core
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
- CJS dist/index.cjs 11.01 KB
15
- CJS ⚡️ Build success in 14ms
16
- ESM dist/index.js 9.47 KB
17
- ESM ⚡️ Build success in 15ms
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 521ms
20
- DTS dist/index.d.ts 6.69 KB
21
- DTS dist/index.d.cts 6.69 KB
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
 
@@ -44,6 +44,88 @@ async function main() {
44
44
  }
45
45
  ```
46
46
 
47
+ ### Classic API Style
48
+
49
+ If you prefer the classic AMQP interface over the `QueueHandle` abstraction, you can use `assertQueue` directly while still benefiting from broker-side schema validation and client-side type inference:
50
+
51
+ ```typescript
52
+ async function classicApiExample() {
53
+ const mq = await connect();
54
+
55
+ // Asserts the queue and registers the schema with the broker
56
+ await mq.assertQueue('orders', Order);
57
+
58
+ // Type-safe publishing
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 });
67
+ }
68
+ ```
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
+
47
129
  ## License
48
130
 
49
131
  Apache 2.0