@hile/micro-dynamic-configs 4.0.2 → 4.0.4
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/AI.md +21 -15
- package/README.md +11 -6
- package/package.json +4 -4
package/AI.md
CHANGED
|
@@ -34,13 +34,14 @@ Message handler file:
|
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
36
|
// src/messages/ping.msg.ts
|
|
37
|
-
import {
|
|
37
|
+
import { defineMicroMessage } from '@hile/micro'
|
|
38
38
|
|
|
39
|
-
export default
|
|
39
|
+
export default defineMicroMessage(async ({ data, params, invocation }) => {
|
|
40
40
|
return {
|
|
41
41
|
type: 'pong',
|
|
42
42
|
data,
|
|
43
43
|
params,
|
|
44
|
+
requestId: invocation.context.values.requestId,
|
|
44
45
|
timestamp: Date.now(),
|
|
45
46
|
}
|
|
46
47
|
})
|
|
@@ -73,7 +74,11 @@ export default defineService('micro.app', async (shutdown) => {
|
|
|
73
74
|
Caller:
|
|
74
75
|
|
|
75
76
|
```ts
|
|
76
|
-
|
|
77
|
+
import { randomUUID } from 'node:crypto'
|
|
78
|
+
import { createExecutionContext } from '@hile/context'
|
|
79
|
+
|
|
80
|
+
const context = createExecutionContext({ requestId: randomUUID() })
|
|
81
|
+
const result = await app.call('example.service', '/ping', { hello: 'world' }, { context })
|
|
77
82
|
```
|
|
78
83
|
|
|
79
84
|
## More Examples
|
|
@@ -82,11 +87,11 @@ Streaming handler:
|
|
|
82
87
|
|
|
83
88
|
```ts
|
|
84
89
|
// src/messages/events.msg.ts
|
|
85
|
-
import {
|
|
90
|
+
import { defineMicroMessage } from '@hile/micro'
|
|
86
91
|
|
|
87
|
-
export default
|
|
92
|
+
export default defineMicroMessage(async function* ({ invocation }) {
|
|
88
93
|
for (let i = 0; i < 3; i++) {
|
|
89
|
-
yield { seq: i }
|
|
94
|
+
yield { seq: i, requestId: invocation.context.values.requestId }
|
|
90
95
|
}
|
|
91
96
|
})
|
|
92
97
|
```
|
|
@@ -94,7 +99,7 @@ export default defineMessage(async function* () {
|
|
|
94
99
|
Streaming caller:
|
|
95
100
|
|
|
96
101
|
```ts
|
|
97
|
-
const stream = await app.stream('example.service', '/events', {})
|
|
102
|
+
const stream = await app.stream('example.service', '/events', {}, { context })
|
|
98
103
|
for await (const chunk of stream) {
|
|
99
104
|
console.log(chunk)
|
|
100
105
|
}
|
|
@@ -131,13 +136,13 @@ Use the message packages for request/response messaging over WebSocket, process
|
|
|
131
136
|
|
|
132
137
|
- Do not use `stream()` for normal single-result calls.
|
|
133
138
|
- Do not rely on message IDs for business idempotency. They are transport IDs.
|
|
134
|
-
-
|
|
139
|
+
- Use `defineMicroMessage()` for Micro business handlers; reserve generic `defineMessage()` for transport-neutral loaders.
|
|
135
140
|
- Do not pass zero, fractional, non-finite, or oversized message timeouts. Explicit timeout values must be safe integers from `1` through `2_147_483_647` milliseconds.
|
|
136
141
|
|
|
137
142
|
## Install
|
|
138
143
|
|
|
139
144
|
```bash
|
|
140
|
-
pnpm add @hile/micro @hile/message-loader @hile/message-ws
|
|
145
|
+
pnpm add @hile/context @hile/micro @hile/message-loader @hile/message-ws
|
|
141
146
|
```
|
|
142
147
|
|
|
143
148
|
Use transport-specific packages only when you need to build custom IPC or worker-thread bridges.
|
|
@@ -146,7 +151,8 @@ Use transport-specific packages only when you need to build custom IPC or worker
|
|
|
146
151
|
|
|
147
152
|
```ts
|
|
148
153
|
import { defineMessage, MessageLoader } from '@hile/message-loader'
|
|
149
|
-
import {
|
|
154
|
+
import { createExecutionContext } from '@hile/context'
|
|
155
|
+
import { Application, defineMicroMessage, Registry, Server } from '@hile/micro'
|
|
150
156
|
import { MessageWs } from '@hile/message-ws'
|
|
151
157
|
import { MessageIpc } from '@hile/message-ipc'
|
|
152
158
|
import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
@@ -154,7 +160,7 @@ import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
|
154
160
|
|
|
155
161
|
## Compose With
|
|
156
162
|
|
|
157
|
-
-
|
|
163
|
+
- Pass `ExecutionContext` explicitly in every business call or stream option; the receiver gets it in `invocation.context`.
|
|
158
164
|
- `@hile/redis-idempotency` protects retryable side effects in message handlers.
|
|
159
165
|
- `@hile/redis-stream-queue` is better for durable background jobs.
|
|
160
166
|
|
|
@@ -169,8 +175,8 @@ import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
|
169
175
|
- Each modem schedules request, total-stream, and idle-stream deadlines through one internal deadline scheduler. This reduces active Node.js timers without changing timeout, cancellation, ordering, or error semantics.
|
|
170
176
|
- `@hile/message-ws` keeps public `decodeMessageFrame()` payloads isolated from caller-owned input by default. Its owned WebSocket `RawData` path uses a zero-copy binary Flight payload view internally.
|
|
171
177
|
- A stream request requires `exec()` to return an async iterable.
|
|
172
|
-
- `Application.call(namespace, url, data, options
|
|
173
|
-
- `Application.stream(namespace, url, data, options
|
|
178
|
+
- `Application.call(namespace, url, data, options)` requires `options.context` and returns a promise.
|
|
179
|
+
- `Application.stream(namespace, url, data, options)` requires `options.context` and returns a readable stream.
|
|
174
180
|
- `Application.publish(topic, payload)` returns an object with `update()` and `unpublish()`.
|
|
175
181
|
- `Application.subscribe(topic, callback)` returns an unsubscribe function.
|
|
176
182
|
- `Registry` stores service addresses and retained config/topic state under `~/.registry`.
|
|
@@ -184,8 +190,8 @@ import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
|
184
190
|
|
|
185
191
|
## Verification Checklist
|
|
186
192
|
|
|
187
|
-
-
|
|
188
|
-
- RPC callers use `await app.call(
|
|
193
|
+
- Micro message files default-export `defineMicroMessage(...)` and receive `invocation.context`.
|
|
194
|
+
- RPC callers use `await app.call(..., { context })`.
|
|
189
195
|
- Streaming handlers are async generators.
|
|
190
196
|
- Custom modem timeout values use the documented safe-integer range.
|
|
191
197
|
- Registry is started before application nodes need discovery.
|
package/README.md
CHANGED
|
@@ -22,13 +22,14 @@ Message handler file:
|
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
// src/messages/ping.msg.ts
|
|
25
|
-
import {
|
|
25
|
+
import { defineMicroMessage } from '@hile/micro'
|
|
26
26
|
|
|
27
|
-
export default
|
|
27
|
+
export default defineMicroMessage(async ({ data, params, invocation }) => {
|
|
28
28
|
return {
|
|
29
29
|
type: 'pong',
|
|
30
30
|
data,
|
|
31
31
|
params,
|
|
32
|
+
requestId: invocation.context.values.requestId,
|
|
32
33
|
timestamp: Date.now(),
|
|
33
34
|
}
|
|
34
35
|
})
|
|
@@ -61,14 +62,18 @@ export default defineService('micro.app', async (shutdown) => {
|
|
|
61
62
|
Caller:
|
|
62
63
|
|
|
63
64
|
```ts
|
|
64
|
-
|
|
65
|
+
import { randomUUID } from 'node:crypto'
|
|
66
|
+
import { createExecutionContext } from '@hile/context'
|
|
67
|
+
|
|
68
|
+
const context = createExecutionContext({ requestId: randomUUID() })
|
|
69
|
+
const result = await app.call('example.service', '/ping', { hello: 'world' }, { context })
|
|
65
70
|
```
|
|
66
71
|
|
|
67
72
|
## Boundaries
|
|
68
73
|
|
|
69
74
|
- Do not use `stream()` for normal single-result calls.
|
|
70
75
|
- Do not rely on message IDs for business idempotency. They are transport IDs.
|
|
71
|
-
-
|
|
76
|
+
- Use `defineMicroMessage()` for Micro business handlers; reserve generic `defineMessage()` for transport-neutral loaders.
|
|
72
77
|
- Do not pass zero, fractional, non-finite, or oversized message timeouts. Explicit timeout values must be safe integers from `1` through `2_147_483_647` milliseconds.
|
|
73
78
|
|
|
74
79
|
- Appending a secondary response getter to `client.request('/x', data)`
|
|
@@ -78,8 +83,8 @@ const result = await app.call('example.service', '/ping', { hello: 'world' })
|
|
|
78
83
|
|
|
79
84
|
## Verify
|
|
80
85
|
|
|
81
|
-
-
|
|
82
|
-
- RPC callers use `await app.call(
|
|
86
|
+
- Micro message files default-export `defineMicroMessage(...)` and receive `invocation.context`.
|
|
87
|
+
- RPC callers use `await app.call(..., { context })`.
|
|
83
88
|
- Streaming handlers are async generators.
|
|
84
89
|
- Custom modem timeout values use the documented safe-integer range.
|
|
85
90
|
- Registry is started before application nodes need discovery.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/micro-dynamic-configs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"vitest": "^4.0.18"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@hile/ioredis": "^4.0.
|
|
27
|
-
"@hile/micro": "^4.0.
|
|
26
|
+
"@hile/ioredis": "^4.0.1",
|
|
27
|
+
"@hile/micro": "^4.0.4",
|
|
28
28
|
"ioredis": "^5.11.0",
|
|
29
29
|
"zod": "^4.4.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "c89cb395e014c1973dcc0053a533cfea039a91fe"
|
|
32
32
|
}
|