@hile/micro-dynamic-configs 4.0.1 → 4.0.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/AI.md +27 -15
- package/README.md +13 -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,12 +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.
|
|
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.
|
|
135
141
|
|
|
136
142
|
## Install
|
|
137
143
|
|
|
138
144
|
```bash
|
|
139
|
-
pnpm add @hile/micro @hile/message-loader @hile/message-ws
|
|
145
|
+
pnpm add @hile/context @hile/micro @hile/message-loader @hile/message-ws
|
|
140
146
|
```
|
|
141
147
|
|
|
142
148
|
Use transport-specific packages only when you need to build custom IPC or worker-thread bridges.
|
|
@@ -145,7 +151,8 @@ Use transport-specific packages only when you need to build custom IPC or worker
|
|
|
145
151
|
|
|
146
152
|
```ts
|
|
147
153
|
import { defineMessage, MessageLoader } from '@hile/message-loader'
|
|
148
|
-
import {
|
|
154
|
+
import { createExecutionContext } from '@hile/context'
|
|
155
|
+
import { Application, defineMicroMessage, Registry, Server } from '@hile/micro'
|
|
149
156
|
import { MessageWs } from '@hile/message-ws'
|
|
150
157
|
import { MessageIpc } from '@hile/message-ipc'
|
|
151
158
|
import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
@@ -153,7 +160,7 @@ import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
|
153
160
|
|
|
154
161
|
## Compose With
|
|
155
162
|
|
|
156
|
-
-
|
|
163
|
+
- Pass `ExecutionContext` explicitly in every business call or stream option; the receiver gets it in `invocation.context`.
|
|
157
164
|
- `@hile/redis-idempotency` protects retryable side effects in message handlers.
|
|
158
165
|
- `@hile/redis-stream-queue` is better for durable background jobs.
|
|
159
166
|
|
|
@@ -162,10 +169,14 @@ import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
|
162
169
|
- `MessageLoader` maps `*.msg.*` files to routes using `@hile/loader`.
|
|
163
170
|
- `MessageLoader.dispatch(path, data, extras?)` invokes the matched handler.
|
|
164
171
|
- `MessageModem._send()` returns a `Promise`.
|
|
172
|
+
- `MessageModem._send()` and `_push()` use a `30_000` ms timeout when none is provided. An explicit timeout must be a safe integer from `1` through `2_147_483_647`; invalid values throw `TypeError` before a message is sent.
|
|
165
173
|
- `MessageModem._stream()` returns a Node `Readable` in object mode.
|
|
174
|
+
- Stream `timeout` and `idleTimeout` values use the same `1` through `2_147_483_647` ms range. The stream `window` must be a safe integer from `1` through `64` and defaults to `1`.
|
|
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.
|
|
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.
|
|
166
177
|
- A stream request requires `exec()` to return an async iterable.
|
|
167
|
-
- `Application.call(namespace, url, data, options
|
|
168
|
-
- `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.
|
|
169
180
|
- `Application.publish(topic, payload)` returns an object with `update()` and `unpublish()`.
|
|
170
181
|
- `Application.subscribe(topic, callback)` returns an unsubscribe function.
|
|
171
182
|
- `Registry` stores service addresses and retained config/topic state under `~/.registry`.
|
|
@@ -179,9 +190,10 @@ import { MessageWorkerThread } from '@hile/message-worker-thread'
|
|
|
179
190
|
|
|
180
191
|
## Verification Checklist
|
|
181
192
|
|
|
182
|
-
-
|
|
183
|
-
- 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 })`.
|
|
184
195
|
- Streaming handlers are async generators.
|
|
196
|
+
- Custom modem timeout values use the documented safe-integer range.
|
|
185
197
|
- Registry is started before application nodes need discovery.
|
|
186
198
|
- Micro apps use stable namespaces and advertise reachable hosts.
|
|
187
199
|
|
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,19 @@ 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.
|
|
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.
|
|
72
78
|
|
|
73
79
|
- Appending a secondary response getter to `client.request('/x', data)`
|
|
74
80
|
- Returning a plain object from a handler called through `stream()`.
|
|
@@ -77,9 +83,10 @@ const result = await app.call('example.service', '/ping', { hello: 'world' })
|
|
|
77
83
|
|
|
78
84
|
## Verify
|
|
79
85
|
|
|
80
|
-
-
|
|
81
|
-
- 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 })`.
|
|
82
88
|
- Streaming handlers are async generators.
|
|
89
|
+
- Custom modem timeout values use the documented safe-integer range.
|
|
83
90
|
- Registry is started before application nodes need discovery.
|
|
84
91
|
- Micro apps use stable namespaces and advertise reachable hosts.
|
|
85
92
|
|
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.3",
|
|
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.3",
|
|
28
28
|
"ioredis": "^5.11.0",
|
|
29
29
|
"zod": "^4.4.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "3ea69973f9373ddb1f7d5d37338966fd7d081d66"
|
|
32
32
|
}
|