@hile/micro 3.0.6 → 4.0.0

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
  import { Client } from './client.js';
2
2
  import { Server, type MicroServerProps } from './server.js';
3
- import { RegistryAddress } from './registry.js';
3
+ import type { RegistryAddress, RegistryTopicSnapshot, RegistryTopicSummary } from './registry';
4
4
  type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
5
5
  type EnvRequest<T extends Record<string, Record<string, any>>> = {
6
6
  [N in keyof T]: {
@@ -120,6 +120,12 @@ export declare class Application extends Server {
120
120
  update: (payload: T) => Promise</*elided*/ any>;
121
121
  unpublish: () => Promise</*elided*/ any>;
122
122
  }>;
123
+ /** Reads Registry topic metadata without creating a pub/sub subscription. */
124
+ listRegistryTopics(prefix?: string): Promise<RegistryTopicSummary[]>;
125
+ /** Reads one retained/current Registry topic payload without subscribing to it. */
126
+ getRegistryTopic<T = unknown>(topic: string): Promise<RegistryTopicSnapshot & {
127
+ payload: T;
128
+ } | undefined>;
123
129
  /**
124
130
  * 对同一 topic 可多次 subscribe,各自独立回调。
125
131
  * 传入同一个 callback 引用第二次调用时幂等返回 unsubscribe,不重复注册。
@@ -848,6 +848,29 @@ export class Application extends Server {
848
848
  };
849
849
  return ref;
850
850
  }
851
+ /** Reads Registry topic metadata without creating a pub/sub subscription. */
852
+ async listRegistryTopics(prefix) {
853
+ const registry = this.registry;
854
+ if (!registry) {
855
+ this.ensureRegistryReconnectScheduled();
856
+ throw new Error('Registry is not connected');
857
+ }
858
+ const result = await registry.request('/-/topics', prefix === undefined ? {} : { prefix }, this.registryRequestOptions());
859
+ return structuredClone(result.topics);
860
+ }
861
+ /** Reads one retained/current Registry topic payload without subscribing to it. */
862
+ async getRegistryTopic(topic) {
863
+ if (typeof topic !== 'string' || topic.length === 0) {
864
+ throw new TypeError('Registry topic must not be empty');
865
+ }
866
+ const registry = this.registry;
867
+ if (!registry) {
868
+ this.ensureRegistryReconnectScheduled();
869
+ throw new Error('Registry is not connected');
870
+ }
871
+ const snapshot = await registry.request('/-/topic/get', { topic }, this.registryRequestOptions());
872
+ return snapshot === undefined ? undefined : structuredClone(snapshot);
873
+ }
851
874
  /**
852
875
  * 对同一 topic 可多次 subscribe,各自独立回调。
853
876
  * 传入同一个 callback 引用第二次调用时幂等返回 unsubscribe,不重复注册。
package/dist/client.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare class Client extends MessageWs {
30
30
  readonly events: EventEmitter<any>;
31
31
  constructor(props: ClientProps);
32
32
  private startHeartbeat;
33
- protected exec(data: MicroMessage): Promise<any>;
33
+ protected exec(data: MicroMessage, signal?: AbortSignal): Promise<any>;
34
34
  request<T = any>(url: string, data: any, options?: {
35
35
  timeout?: number;
36
36
  signal?: AbortSignal;
package/dist/client.js CHANGED
@@ -87,7 +87,7 @@ export class Client extends MessageWs {
87
87
  }
88
88
  }, checkInterval);
89
89
  }
90
- async exec(data) {
90
+ async exec(data, signal) {
91
91
  if (data.url === '/-/heartbeat') {
92
92
  this.lastHeartbeat = Date.now();
93
93
  return;
@@ -99,6 +99,7 @@ export class Client extends MessageWs {
99
99
  const result = await this.server.dispatch(data.url, data.data, {
100
100
  client: this,
101
101
  metadata: data.metadata,
102
+ signal,
102
103
  });
103
104
  if (context && isAsyncIterable(result)) {
104
105
  return bindAsyncIterableToContext(result, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/micro",
3
- "version": "3.0.6",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -18,18 +18,19 @@
18
18
  "access": "public"
19
19
  },
20
20
  "devDependencies": {
21
+ "@types/node": "^26.2.0",
21
22
  "@types/ws": "^8.18.1",
22
23
  "fix-esm-import-path": "^1.10.3",
23
24
  "vitest": "^4.0.18"
24
25
  },
25
26
  "dependencies": {
26
- "@hile/context": "^3.0.2",
27
- "@hile/logger": "^3.0.0",
28
- "@hile/message-loader": "^3.0.0",
29
- "@hile/message-ws": "^3.0.0",
27
+ "@hile/context": "^4.0.0",
28
+ "@hile/logger": "^4.0.0",
29
+ "@hile/message-loader": "^4.0.0",
30
+ "@hile/message-ws": "^4.0.0",
30
31
  "internal-ip": "^9.0.0",
31
32
  "ws": "^8.21.0",
32
33
  "yaml": "^2.9.0"
33
34
  },
34
- "gitHead": "f0ca6e772602138dd50bf5acd2f9d940b4fe505e"
35
+ "gitHead": "b46cb7f3705a226f58e4d65a2ff985ea54b9a159"
35
36
  }