@yuhere/js-jsonrpc2 2.1.12 → 2.1.13

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.
Files changed (181) hide show
  1. package/dist/cli/cli.d.ts +0 -1
  2. package/dist/cli/cli.js +0 -1
  3. package/dist/cli/demo-methods.d.ts +0 -1
  4. package/dist/cli/demo-methods.js +0 -1
  5. package/dist/cli/express.d.ts +0 -1
  6. package/dist/cli/express.js +0 -1
  7. package/dist/cli/stdio.d.ts +0 -1
  8. package/dist/cli/stdio.js +0 -1
  9. package/dist/core/Repository.d.ts +0 -1
  10. package/dist/core/Repository.js +0 -1
  11. package/dist/core/convert.d.ts +0 -1
  12. package/dist/core/convert.js +0 -1
  13. package/dist/core/descriptor.d.ts +0 -1
  14. package/dist/core/descriptor.js +0 -1
  15. package/dist/core/index.d.ts +0 -1
  16. package/dist/core/index.js +0 -1
  17. package/dist/core/llm-tools.d.ts +0 -1
  18. package/dist/core/llm-tools.js +0 -1
  19. package/dist/core/permission.d.ts +0 -1
  20. package/dist/core/permission.js +0 -1
  21. package/dist/core/spec-check.d.ts +0 -1
  22. package/dist/core/spec-check.js +0 -1
  23. package/dist/core/system-methods.d.ts +0 -1
  24. package/dist/core/system-methods.js +0 -1
  25. package/dist/errors/RPCError.d.ts +0 -1
  26. package/dist/errors/RPCError.js +0 -1
  27. package/dist/errors/codes.d.ts +0 -1
  28. package/dist/errors/codes.js +0 -1
  29. package/dist/errors/index.d.ts +0 -1
  30. package/dist/errors/index.js +0 -1
  31. package/dist/index.d.ts +0 -1
  32. package/dist/index.js +0 -1
  33. package/dist/metrics/memory.d.ts +0 -1
  34. package/dist/metrics/memory.js +0 -1
  35. package/dist/metrics/prom.d.ts +0 -1
  36. package/dist/metrics/prom.js +0 -1
  37. package/dist/schema/json/index.d.ts +0 -1
  38. package/dist/schema/json/index.js +0 -1
  39. package/dist/schema/json/marker.d.ts +0 -1
  40. package/dist/schema/json/marker.js +0 -1
  41. package/dist/schema/json/primitives.d.ts +0 -1
  42. package/dist/schema/json/primitives.js +0 -1
  43. package/dist/schema/z/protocol.d.ts +0 -1
  44. package/dist/schema/z/protocol.js +0 -1
  45. package/dist/schema/z/register.d.ts +0 -1
  46. package/dist/schema/z/register.js +0 -1
  47. package/dist/stream/stringify-stream.d.ts +0 -1
  48. package/dist/stream/stringify-stream.js +94 -70
  49. package/dist/transport/express/body.d.ts +0 -1
  50. package/dist/transport/express/body.js +0 -1
  51. package/dist/transport/express/index.d.ts +0 -1
  52. package/dist/transport/express/index.js +0 -1
  53. package/dist/transport/express/middleware.d.ts +0 -1
  54. package/dist/transport/express/middleware.js +0 -1
  55. package/dist/transport/express/respond.d.ts +0 -1
  56. package/dist/transport/express/respond.js +0 -1
  57. package/dist/transport/stdio/index.d.ts +0 -1
  58. package/dist/transport/stdio/index.js +0 -1
  59. package/dist/transport/stdio/middleware.d.ts +0 -1
  60. package/dist/transport/stdio/middleware.js +0 -1
  61. package/dist/transport/ws/index.d.ts +0 -1
  62. package/dist/transport/ws/index.js +0 -1
  63. package/dist/transport/ws/middleware.d.ts +0 -1
  64. package/dist/transport/ws/middleware.js +0 -1
  65. package/dist/transport/ws/standalone.d.ts +0 -1
  66. package/dist/transport/ws/standalone.js +0 -1
  67. package/dist/types.d.ts +0 -1
  68. package/dist/types.js +0 -1
  69. package/dist/webclient/webui/src/client/httpTransport.d.ts +8 -0
  70. package/dist/webclient/webui/src/client/httpTransport.js +114 -0
  71. package/dist/webclient/webui/src/client/index.d.ts +4 -0
  72. package/dist/webclient/webui/src/client/index.js +2 -0
  73. package/dist/webclient/webui/src/client/rpc.d.ts +24 -0
  74. package/dist/webclient/webui/src/client/rpc.js +32 -0
  75. package/dist/webclient/webui/src/client/types.d.ts +14 -0
  76. package/dist/webclient/webui/src/client/types.js +1 -0
  77. package/dist/webclient/webui/src/client/wsTransport.d.ts +8 -0
  78. package/{webui/src/api/wsTransport.ts → dist/webclient/webui/src/client/wsTransport.js} +263 -305
  79. package/htdoc/assets/favicon-CXdFuLlv.png +0 -0
  80. package/htdoc/assets/{index-Cr0Jnrgb.js → index-CqI7vRAS.js} +1191 -327
  81. package/htdoc/assets/index-CqI7vRAS.js.map +1 -0
  82. package/{webui/src/styles/geek.css → htdoc/assets/index-Rq1yIwo2.css} +58 -0
  83. package/htdoc/index.html +4 -2
  84. package/package.json +10 -7
  85. package/dist/cli/cli.d.ts.map +0 -1
  86. package/dist/cli/cli.js.map +0 -1
  87. package/dist/cli/demo-methods.d.ts.map +0 -1
  88. package/dist/cli/demo-methods.js.map +0 -1
  89. package/dist/cli/express.d.ts.map +0 -1
  90. package/dist/cli/express.js.map +0 -1
  91. package/dist/cli/stdio.d.ts.map +0 -1
  92. package/dist/cli/stdio.js.map +0 -1
  93. package/dist/core/Repository.d.ts.map +0 -1
  94. package/dist/core/Repository.js.map +0 -1
  95. package/dist/core/convert.d.ts.map +0 -1
  96. package/dist/core/convert.js.map +0 -1
  97. package/dist/core/descriptor.d.ts.map +0 -1
  98. package/dist/core/descriptor.js.map +0 -1
  99. package/dist/core/index.d.ts.map +0 -1
  100. package/dist/core/index.js.map +0 -1
  101. package/dist/core/llm-tools.d.ts.map +0 -1
  102. package/dist/core/llm-tools.js.map +0 -1
  103. package/dist/core/permission.d.ts.map +0 -1
  104. package/dist/core/permission.js.map +0 -1
  105. package/dist/core/spec-check.d.ts.map +0 -1
  106. package/dist/core/spec-check.js.map +0 -1
  107. package/dist/core/system-methods.d.ts.map +0 -1
  108. package/dist/core/system-methods.js.map +0 -1
  109. package/dist/errors/RPCError.d.ts.map +0 -1
  110. package/dist/errors/RPCError.js.map +0 -1
  111. package/dist/errors/codes.d.ts.map +0 -1
  112. package/dist/errors/codes.js.map +0 -1
  113. package/dist/errors/index.d.ts.map +0 -1
  114. package/dist/errors/index.js.map +0 -1
  115. package/dist/index.d.ts.map +0 -1
  116. package/dist/index.js.map +0 -1
  117. package/dist/metrics/memory.d.ts.map +0 -1
  118. package/dist/metrics/memory.js.map +0 -1
  119. package/dist/metrics/prom.d.ts.map +0 -1
  120. package/dist/metrics/prom.js.map +0 -1
  121. package/dist/schema/json/index.d.ts.map +0 -1
  122. package/dist/schema/json/index.js.map +0 -1
  123. package/dist/schema/json/marker.d.ts.map +0 -1
  124. package/dist/schema/json/marker.js.map +0 -1
  125. package/dist/schema/json/primitives.d.ts.map +0 -1
  126. package/dist/schema/json/primitives.js.map +0 -1
  127. package/dist/schema/z/protocol.d.ts.map +0 -1
  128. package/dist/schema/z/protocol.js.map +0 -1
  129. package/dist/schema/z/register.d.ts.map +0 -1
  130. package/dist/schema/z/register.js.map +0 -1
  131. package/dist/stream/stringify-stream.d.ts.map +0 -1
  132. package/dist/stream/stringify-stream.js.map +0 -1
  133. package/dist/transport/express/body.d.ts.map +0 -1
  134. package/dist/transport/express/body.js.map +0 -1
  135. package/dist/transport/express/index.d.ts.map +0 -1
  136. package/dist/transport/express/index.js.map +0 -1
  137. package/dist/transport/express/middleware.d.ts.map +0 -1
  138. package/dist/transport/express/middleware.js.map +0 -1
  139. package/dist/transport/express/respond.d.ts.map +0 -1
  140. package/dist/transport/express/respond.js.map +0 -1
  141. package/dist/transport/stdio/index.d.ts.map +0 -1
  142. package/dist/transport/stdio/index.js.map +0 -1
  143. package/dist/transport/stdio/middleware.d.ts.map +0 -1
  144. package/dist/transport/stdio/middleware.js.map +0 -1
  145. package/dist/transport/ws/index.d.ts.map +0 -1
  146. package/dist/transport/ws/index.js.map +0 -1
  147. package/dist/transport/ws/middleware.d.ts.map +0 -1
  148. package/dist/transport/ws/middleware.js.map +0 -1
  149. package/dist/transport/ws/standalone.d.ts.map +0 -1
  150. package/dist/transport/ws/standalone.js.map +0 -1
  151. package/dist/types.d.ts.map +0 -1
  152. package/dist/types.js.map +0 -1
  153. package/htdoc/assets/index-Ck-39Igh.css +0 -963
  154. package/htdoc/assets/index-Cr0Jnrgb.js.map +0 -1
  155. package/webui/index.html +0 -12
  156. package/webui/src/App.tsx +0 -164
  157. package/webui/src/api/docGen.ts +0 -188
  158. package/webui/src/api/glob.ts +0 -90
  159. package/webui/src/api/httpTransport.ts +0 -148
  160. package/webui/src/api/metrics.ts +0 -135
  161. package/webui/src/api/paramForm.ts +0 -80
  162. package/webui/src/api/rpc.ts +0 -57
  163. package/webui/src/api/schema.ts +0 -12
  164. package/webui/src/api/types.ts +0 -16
  165. package/webui/src/components/MethodDetail.tsx +0 -43
  166. package/webui/src/components/MethodTree.tsx +0 -118
  167. package/webui/src/components/MetricsPanel.md +0 -126
  168. package/webui/src/components/MetricsPanel.tsx +0 -290
  169. package/webui/src/components/SchemaForm.tsx +0 -697
  170. package/webui/src/components/SchemaView.tsx +0 -151
  171. package/webui/src/components/TestPanel.tsx +0 -322
  172. package/webui/src/components/Toolbar.tsx +0 -82
  173. package/webui/src/hooks/useMethodDetail.ts +0 -61
  174. package/webui/src/hooks/useMethods.ts +0 -27
  175. package/webui/src/hooks/useMetrics.ts +0 -91
  176. package/webui/src/main.tsx +0 -13
  177. package/webui/src/theme/ThemeProvider.tsx +0 -79
  178. package/webui/src/vite-env.d.ts +0 -1
  179. package/webui/tsconfig.json +0 -34
  180. package/webui/tsconfig.node.json +0 -13
  181. package/webui/vite.config.ts +0 -15
package/dist/cli/cli.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env node
2
2
  export {};
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli/cli.js CHANGED
@@ -137,4 +137,3 @@ main().catch((err) => {
137
137
  console.error('启动失败:', err);
138
138
  process.exit(1);
139
139
  });
140
- //# sourceMappingURL=cli.js.map
@@ -7,4 +7,3 @@ import type { Repository } from '../core/Repository.js';
7
7
  * 被 dev/express.ts 与 src/cli.ts 共用。
8
8
  */
9
9
  export declare function installDemoMethods(repository: Repository): void;
10
- //# sourceMappingURL=demo-methods.d.ts.map
@@ -473,4 +473,3 @@ export function installDemoMethods(repository) {
473
473
  }
474
474
  });
475
475
  }
476
- //# sourceMappingURL=demo-methods.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=express.d.ts.map
@@ -39,4 +39,3 @@ const port = Number(process.env['PORT'] ?? 5000);
39
39
  server.listen(port, () => {
40
40
  console.log(`js-jsonrpc2 debug server listening on http://localhost:${port}`);
41
41
  });
42
- //# sourceMappingURL=express.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=stdio.d.ts.map
package/dist/cli/stdio.js CHANGED
@@ -2,4 +2,3 @@ import { createRepository, serveStdio, s } from '../index.js';
2
2
  const repository = createRepository();
3
3
  repository.register({ namespace: 'echo', signature: [s.string(), s.string()] }, (v) => v);
4
4
  await serveStdio({ repository, framing: 'lines' });
5
- //# sourceMappingURL=stdio.js.map
@@ -19,4 +19,3 @@ export declare class Repository {
19
19
  }
20
20
  export declare function createRepository(options?: RepositoryOptions): Repository;
21
21
  export type { MethodDescriptor };
22
- //# sourceMappingURL=Repository.d.ts.map
@@ -297,4 +297,3 @@ export class Repository {
297
297
  export function createRepository(options = {}) {
298
298
  return new Repository(options);
299
299
  }
300
- //# sourceMappingURL=Repository.js.map
@@ -1,4 +1,3 @@
1
1
  import type { MethodDescriptor } from './descriptor.js';
2
2
  import type { Injections } from '../types.js';
3
3
  export declare function convertParams(descriptor: MethodDescriptor, params: unknown, injections: Injections): Promise<unknown[]>;
4
- //# sourceMappingURL=convert.d.ts.map
@@ -26,4 +26,3 @@ export async function convertParams(descriptor, params, injections) {
26
26
  }
27
27
  return converted;
28
28
  }
29
- //# sourceMappingURL=convert.js.map
@@ -24,4 +24,3 @@ export declare function buildDescriptor(descriptor: RPCDescriptor, fn: RPCHandle
24
24
  export declare function signatureOf(descriptor: MethodDescriptor): unknown[];
25
25
  export declare function lookup(methods: Map<string, MethodDescriptor>, method: string): MethodDescriptor;
26
26
  export declare function invalidParams(message: string, data?: unknown): RPCError;
27
- //# sourceMappingURL=descriptor.d.ts.map
@@ -80,4 +80,3 @@ export function lookup(methods, method) {
80
80
  export function invalidParams(message, data) {
81
81
  return new RPCError(INVALID_PARAMS, message, data);
82
82
  }
83
- //# sourceMappingURL=descriptor.js.map
@@ -1,4 +1,3 @@
1
1
  export { Repository, createRepository } from './Repository.js';
2
2
  export type { MethodDescriptor } from './descriptor.js';
3
3
  export { validateRequest } from './spec-check.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,2 @@
1
1
  export { Repository, createRepository } from './Repository.js';
2
2
  export { validateRequest } from './spec-check.js';
3
- //# sourceMappingURL=index.js.map
@@ -22,4 +22,3 @@ export interface JSONSchema {
22
22
  }
23
23
  export declare function listLlmTools(repository: Repository, injections: Injections, rawOptions?: unknown): Promise<LlmTools>;
24
24
  export declare function invokeLlmTool(repository: Repository, call: LlmToolCall, injections: Injections): Promise<unknown>;
25
- //# sourceMappingURL=llm-tools.d.ts.map
@@ -309,4 +309,3 @@ export async function invokeLlmTool(repository, call, injections) {
309
309
  })();
310
310
  }
311
311
  }
312
- //# sourceMappingURL=llm-tools.js.map
@@ -2,4 +2,3 @@ import type { MethodDescriptor } from './descriptor.js';
2
2
  import type { Injections } from '../types.js';
3
3
  export declare function checkPermission(descriptor: MethodDescriptor, injections: Injections): Promise<void>;
4
4
  export declare function assertAccessible(descriptor: MethodDescriptor, injections: Injections): Promise<void>;
5
- //# sourceMappingURL=permission.d.ts.map
@@ -26,4 +26,3 @@ export async function assertAccessible(descriptor, injections) {
26
26
  throw error;
27
27
  }
28
28
  }
29
- //# sourceMappingURL=permission.js.map
@@ -1,3 +1,2 @@
1
1
  import type { RPCRequestInput } from '../types.js';
2
2
  export declare function validateRequest(input: unknown): RPCRequestInput;
3
- //# sourceMappingURL=spec-check.d.ts.map
@@ -8,4 +8,3 @@ export function validateRequest(input) {
8
8
  }
9
9
  return result.data;
10
10
  }
11
- //# sourceMappingURL=spec-check.js.map
@@ -1,3 +1,2 @@
1
1
  import type { Repository } from './Repository.js';
2
2
  export declare function registerSystemMethods(repository: Repository): void;
3
- //# sourceMappingURL=system-methods.d.ts.map
@@ -111,4 +111,3 @@ export function registerSystemMethods(repository) {
111
111
  return repository.listLlmTools(injections, rawOptions);
112
112
  });
113
113
  }
114
- //# sourceMappingURL=system-methods.js.map
@@ -6,4 +6,3 @@ export declare class RPCError extends Error {
6
6
  toPayload(): RPCErrorPayload;
7
7
  toJSON(): RPCErrorPayload;
8
8
  }
9
- //# sourceMappingURL=RPCError.d.ts.map
@@ -20,4 +20,3 @@ export class RPCError extends Error {
20
20
  return this.toPayload();
21
21
  }
22
22
  }
23
- //# sourceMappingURL=RPCError.js.map
@@ -4,4 +4,3 @@ export declare const METHOD_NOT_FOUND = -32601;
4
4
  export declare const INVALID_PARAMS = -32602;
5
5
  export declare const INTERNAL_ERROR = -32603;
6
6
  export declare const PERMISSION_DENIED = -32604;
7
- //# sourceMappingURL=codes.d.ts.map
@@ -4,4 +4,3 @@ export const METHOD_NOT_FOUND = -32601;
4
4
  export const INVALID_PARAMS = -32602;
5
5
  export const INTERNAL_ERROR = -32603;
6
6
  export const PERMISSION_DENIED = -32604;
7
- //# sourceMappingURL=codes.js.map
@@ -1,3 +1,2 @@
1
1
  export { RPCError } from './RPCError.js';
2
2
  export * from './codes.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,2 @@
1
1
  export { RPCError } from './RPCError.js';
2
2
  export * from './codes.js';
3
- //# sourceMappingURL=index.js.map
package/dist/index.d.ts CHANGED
@@ -15,4 +15,3 @@ export { attachWebSocket, createWebSocketServer, serveStdio };
15
15
  export type { WSOptions, StandaloneWsOptions, StandaloneWsHandle } from './transport/ws/index.js';
16
16
  export type { StdioOptions } from './transport/stdio/index.js';
17
17
  export type { ExpressOptions } from './transport/express/index.js';
18
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,4 +14,3 @@ export { createExpressRouter };
14
14
  import { attachWebSocket, createWebSocketServer } from './transport/ws/index.js';
15
15
  import { serveStdio } from './transport/stdio/index.js';
16
16
  export { attachWebSocket, createWebSocketServer, serveStdio };
17
- //# sourceMappingURL=index.js.map
@@ -56,4 +56,3 @@ export interface MemoryMetrics extends RPCMetrics {
56
56
  reset(): void;
57
57
  }
58
58
  export declare function createMemoryMetrics(options?: MemoryMetricsOptions): MemoryMetrics;
59
- //# sourceMappingURL=memory.d.ts.map
@@ -185,4 +185,3 @@ export function createMemoryMetrics(options = {}) {
185
185
  },
186
186
  };
187
187
  }
188
- //# sourceMappingURL=memory.js.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=prom.d.ts.map
@@ -102,4 +102,3 @@
102
102
  // },
103
103
  // };
104
104
  // }
105
- //# sourceMappingURL=prom.js.map
@@ -17,4 +17,3 @@ export declare const s: {
17
17
  injectable: <const K extends string>(key: K) => import("./marker.js").InjectableMarker<K>;
18
18
  stream: <T>(inner: import("./primitives.js").Schema<T>) => import("./marker.js").StreamMarker<T>;
19
19
  };
20
- //# sourceMappingURL=index.d.ts.map
@@ -3,4 +3,3 @@ import { markers } from "./marker.js";
3
3
  export * from "./primitives.js";
4
4
  export * from "./marker.js";
5
5
  export const s = { ...primitives, ...markers };
6
- //# sourceMappingURL=index.js.map
@@ -20,4 +20,3 @@ export declare const markers: {
20
20
  injectable: <const K extends string>(key: K) => InjectableMarker<K>;
21
21
  stream: <T>(inner: Schema<T>) => StreamMarker<T>;
22
22
  };
23
- //# sourceMappingURL=marker.d.ts.map
@@ -24,4 +24,3 @@ export const markers = {
24
24
  injectable: (key) => new InjectableMarker(key),
25
25
  stream: (inner) => new StreamMarker(inner),
26
26
  };
27
- //# sourceMappingURL=marker.js.map
@@ -238,4 +238,3 @@ export declare const primitives: {
238
238
  null: () => NullSchema;
239
239
  };
240
240
  export {};
241
- //# sourceMappingURL=primitives.d.ts.map
@@ -623,4 +623,3 @@ export const primitives = {
623
623
  unknown: () => new UnknownSchema(),
624
624
  null: () => new NullSchema(),
625
625
  };
626
- //# sourceMappingURL=primitives.js.map
@@ -6,4 +6,3 @@ export declare const RPCRequestSchema: import("../json/index.js").ObjectSchema<{
6
6
  params: import("../json/index.js").ArraySchema<import("../json/index.js").JSONValue>;
7
7
  id: import("../json/index.js").UnionSchema<readonly [import("../json/index.js").StringSchema<"string">, import("../json/index.js").NumberSchema]>;
8
8
  }, true>;
9
- //# sourceMappingURL=protocol.d.ts.map
@@ -6,4 +6,3 @@ export const RPCRequestSchema = s.object({
6
6
  params: s.array(s.unknown()).nullable(),
7
7
  id: s.union([s.string().min(1), s.number()]),
8
8
  }).strict();
9
- //# sourceMappingURL=protocol.js.map
@@ -6,4 +6,3 @@ export declare const registerSchema: z.ZodTuple<[z.ZodObject<{
6
6
  grantTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
7
7
  signature: z.ZodTuple<[z.ZodUnion<readonly [z.ZodInstanceOf<Schema<unknown>>, z.ZodInstanceOf<VoidMarker>, z.ZodInstanceOf<StreamMarker<unknown>>]>], z.ZodUnion<readonly [z.ZodInstanceOf<Schema<unknown>>, z.ZodInstanceOf<InjectableMarker<string>>]>>;
8
8
  }, z.core.$strict>, z.ZodFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>], null>;
9
- //# sourceMappingURL=register.d.ts.map
@@ -18,4 +18,3 @@ export const registerSchema = z.tuple([
18
18
  descriptorSchema,
19
19
  z.function(),
20
20
  ]);
21
- //# sourceMappingURL=register.js.map
@@ -12,4 +12,3 @@ export interface StringifyStreamOptions {
12
12
  }
13
13
  export declare function stringifyStream(input: unknown, options?: StringifyStreamOptions): AsyncGenerator<string, void, unknown>;
14
14
  export declare function stringify(input: unknown, options?: StringifyStreamOptions): Promise<string>;
15
- //# sourceMappingURL=stringify-stream.d.ts.map
@@ -6,7 +6,9 @@ const MAX_GAP_LENGTH = 10;
6
6
  const DEFAULT_BUFFER_SIZE = 16 * 1024;
7
7
  export async function* stringifyStream(input, options = {}) {
8
8
  const { bufferSize: rawBufferSize = DEFAULT_BUFFER_SIZE, space, replacer, } = options;
9
- const bufferSize = Math.max(1, rawBufferSize | 0);
9
+ const bufferSize = Number.isFinite(rawBufferSize)
10
+ ? Math.max(1, Math.floor(rawBufferSize))
11
+ : DEFAULT_BUFFER_SIZE;
10
12
  const seen = new WeakSet();
11
13
  let gap = '';
12
14
  if (typeof space === 'number') {
@@ -31,8 +33,19 @@ export async function* stringifyStream(input, options = {}) {
31
33
  let buffer = '';
32
34
  function* flush(force = false) {
33
35
  while (buffer.length >= bufferSize || (force && buffer.length > 0)) {
34
- const chunk = buffer.slice(0, bufferSize);
35
- buffer = buffer.slice(bufferSize);
36
+ let end = Math.min(bufferSize, buffer.length);
37
+ // 不要在 UTF-16 surrogate pair 中间切分
38
+ if (end < buffer.length) {
39
+ const prev = buffer.charCodeAt(end - 1);
40
+ const next = buffer.charCodeAt(end);
41
+ const isHighSurrogate = prev >= 0xD800 && prev <= 0xDBFF;
42
+ const isLowSurrogate = next >= 0xDC00 && next <= 0xDFFF;
43
+ if (isHighSurrogate && isLowSurrogate) {
44
+ end++;
45
+ }
46
+ }
47
+ const chunk = buffer.slice(0, end);
48
+ buffer = buffer.slice(end);
36
49
  yield chunk;
37
50
  }
38
51
  }
@@ -69,7 +82,7 @@ export async function* stringifyStream(input, options = {}) {
69
82
  function isTypedArray(value) {
70
83
  return ArrayBuffer.isView(value) && !(value instanceof DataView);
71
84
  }
72
- function prepareValue(value, key) {
85
+ function prepareValue(value, key, holder) {
73
86
  // 1. toJSON(跳过 Buffer)
74
87
  if (value !== null &&
75
88
  typeof value === 'object' &&
@@ -79,37 +92,30 @@ export async function* stringifyStream(input, options = {}) {
79
92
  }
80
93
  // 2. replacer
81
94
  if (replacerFn) {
82
- value = replacerFn.call(key === '' ? undefined : null, key, value);
95
+ value = replacerFn.call(holder, key, value);
83
96
  }
84
97
  return value;
85
98
  }
86
- async function* serialize(value, key, depth) {
87
- // ========== 只在这里做一次 prepare ==========
88
- value = prepareValue(value, key);
89
- // undefined / function / symbol → 由调用方决定(对象省略,数组写 null)
90
- if (value === undefined ||
91
- typeof value === 'function' ||
92
- typeof value === 'symbol') {
93
- return;
94
- }
99
+ async function* serialize(value, key, depth, holder) {
100
+ // 只在这里做一次 prepare
101
+ value = prepareValue(value, key, holder);
95
102
  assertNoBigInt(value);
96
- // Promise(replacer 或 toJSON 返回的 Promise 在这里统一处理)
97
103
  if (value instanceof Promise) {
98
104
  value = await Promise.resolve(value);
99
- // 注意:await 之后要重新走完整流程(包括可能的再次 toJSON/replacer?)
100
- // 为了与「只 prepare 一次」一致,这里选择不再 prepare,直接递归时跳过 prepare
101
- // 最简单且安全的做法:再调一次 serialize(此时 value 已是 resolved 后的值)
102
- // 但为了避免对 resolved 后的 number 再次触发 replacer,我们改成内部递归时传一个 flag
103
105
  yield* serializePrepared(value, key, depth);
104
106
  return;
105
107
  }
106
108
  yield* serializePrepared(value, key, depth);
107
109
  }
108
- /** 已经完成 prepare 的值,直接序列化(不再调用 toJSON/replacer) */
110
+ /**
111
+ * 已经完成 prepare 的值,直接序列化
112
+ * 不再调用 toJSON / replacer。
113
+ */
109
114
  async function* serializePrepared(value, key, depth) {
110
115
  if (value === undefined ||
111
116
  typeof value === 'function' ||
112
117
  typeof value === 'symbol') {
118
+ write('null');
113
119
  return;
114
120
  }
115
121
  assertNoBigInt(value);
@@ -152,9 +158,16 @@ export async function* stringifyStream(input, options = {}) {
152
158
  if (!first)
153
159
  write(',');
154
160
  first = false;
155
- if (gap)
161
+ if (gap) {
156
162
  write('\n' + gap.repeat(depth + 1));
157
- let elem = prepareValue(value[i], String(i));
163
+ }
164
+ let rawValue = value[i];
165
+ // 1. 先等待原始值
166
+ if (rawValue instanceof Promise) {
167
+ rawValue = await Promise.resolve(rawValue);
168
+ }
169
+ // 2. 执行 toJSON 和 replacer
170
+ let elem = prepareValue(rawValue, String(i), value);
158
171
  if (elem instanceof Promise) {
159
172
  elem = await Promise.resolve(elem);
160
173
  }
@@ -185,8 +198,9 @@ export async function* stringifyStream(input, options = {}) {
185
198
  if (!first)
186
199
  write(',');
187
200
  first = false;
188
- if (gap)
201
+ if (gap) {
189
202
  write('\n' + gap.repeat(depth + 1));
203
+ }
190
204
  writeJSONString(String(i));
191
205
  write(gap ? ': ' : ':');
192
206
  write(JSON.stringify(arr[i]));
@@ -199,7 +213,7 @@ export async function* stringifyStream(input, options = {}) {
199
213
  uncheckCycle(value);
200
214
  return;
201
215
  }
202
- // 可迭代
216
+ // 可迭代对象
203
217
  const hasAsyncIterator = value != null &&
204
218
  typeof value[Symbol.asyncIterator] === 'function';
205
219
  const hasIterator = value != null &&
@@ -212,10 +226,9 @@ export async function* stringifyStream(input, options = {}) {
212
226
  !(value instanceof WeakMap) &&
213
227
  !(value instanceof WeakSet);
214
228
  if (shouldTreatAsIterable) {
215
- write('[');
216
- let first = true;
217
- let idx = 0;
229
+ checkCycle(value);
218
230
  let iterator;
231
+ let completed = false;
219
232
  if (hasAsyncIterator) {
220
233
  iterator = value[Symbol.asyncIterator]();
221
234
  }
@@ -225,40 +238,52 @@ export async function* stringifyStream(input, options = {}) {
225
238
  else {
226
239
  iterator = value;
227
240
  }
228
- while (true) {
229
- const step = await Promise.resolve(iterator.next());
230
- if (step.done)
231
- break;
232
- if (!first)
233
- write(',');
234
- first = false;
235
- if (gap)
236
- write('\n' + gap.repeat(depth + 1));
237
- // const before = buffer.length;
238
- // yield* serialize(step.value, String(idx), depth + 1);
239
- // if (buffer.length === before) {
240
- // write('null');
241
- // }
242
- // prepare + await 后再决定写 null 还是序列化(与对象路径一致)
243
- let elem = prepareValue(step.value, String(idx));
244
- if (elem instanceof Promise) {
245
- elem = await Promise.resolve(elem);
241
+ try {
242
+ write('[');
243
+ let first = true;
244
+ let idx = 0;
245
+ while (true) {
246
+ const step = await Promise.resolve(iterator.next());
247
+ if (step.done) {
248
+ completed = true;
249
+ break;
250
+ }
251
+ if (!first)
252
+ write(',');
253
+ first = false;
254
+ if (gap) {
255
+ write('\n' + gap.repeat(depth + 1));
256
+ }
257
+ let elem = prepareValue(step.value, String(idx), value);
258
+ if (elem instanceof Promise) {
259
+ elem = await Promise.resolve(elem);
260
+ }
261
+ if (elem === undefined ||
262
+ typeof elem === 'function' ||
263
+ typeof elem === 'symbol') {
264
+ write('null');
265
+ }
266
+ else {
267
+ yield* serializePrepared(elem, String(idx), depth + 1);
268
+ }
269
+ idx++;
270
+ yield* flush();
246
271
  }
247
- if (elem === undefined ||
248
- typeof elem === 'function' ||
249
- typeof elem === 'symbol') {
250
- write('null');
272
+ if (gap && !first) {
273
+ write('\n' + gap.repeat(depth));
251
274
  }
252
- else {
253
- yield* serializePrepared(elem, String(idx), depth + 1);
254
- }
255
- idx++;
256
- yield* flush();
275
+ write(']');
257
276
  }
258
- if (gap && !first) {
259
- write('\n' + gap.repeat(depth));
277
+ finally {
278
+ if (!completed && typeof iterator.return === 'function') {
279
+ try {
280
+ await iterator.return();
281
+ }
282
+ catch {
283
+ }
284
+ }
285
+ uncheckCycle(value);
260
286
  }
261
- write(']');
262
287
  return;
263
288
  }
264
289
  // 普通对象
@@ -277,19 +302,17 @@ export async function* stringifyStream(input, options = {}) {
277
302
  ? [...propertyList].filter((k) => Object.prototype.hasOwnProperty.call(value, k))
278
303
  : Object.keys(value);
279
304
  for (const k of keys) {
280
- // 1. 先 prepare
281
- let propValue = prepareValue(value[k], k);
282
- // 2. 如果是 Promise,先 await(关键!)
305
+ let rawValue = value[k];
306
+ // 1. 先等待原始值(如果它是 Promise)
307
+ if (rawValue instanceof Promise) {
308
+ rawValue = await Promise.resolve(rawValue);
309
+ }
310
+ // 2. 再执行 toJSON 和 replacer
311
+ let propValue = prepareValue(rawValue, k, value);
312
+ // 3. 如果 replacer 自身返回了 Promise,再等待它
283
313
  if (propValue instanceof Promise) {
284
314
  propValue = await Promise.resolve(propValue);
285
315
  }
286
- // 3. 现在再判断是否应该省略
287
- if (propValue === undefined ||
288
- typeof propValue === 'function' ||
289
- typeof propValue === 'symbol') {
290
- continue;
291
- }
292
- // 4. 可以安全地写 key 了
293
316
  if (!first)
294
317
  write(',');
295
318
  first = false;
@@ -298,7 +321,7 @@ export async function* stringifyStream(input, options = {}) {
298
321
  }
299
322
  writeJSONString(k);
300
323
  write(gap ? ': ' : ':');
301
- // 5. 直接序列化已经 prepare + await 过的值
324
+ // 4. 直接序列化已经 prepare + await 过的值
302
325
  yield* serializePrepared(propValue, k, depth + 1);
303
326
  yield* flush();
304
327
  }
@@ -308,7 +331,9 @@ export async function* stringifyStream(input, options = {}) {
308
331
  write('}');
309
332
  uncheckCycle(value);
310
333
  }
311
- yield* serialize(input, '', 0);
334
+ // 根值包装:与 JSON.stringify 的根对象处理方式一致
335
+ const root = { '': input };
336
+ yield* serialize(root[''], '', 0, root);
312
337
  yield* flush(true);
313
338
  }
314
339
  export async function stringify(input, options = {}) {
@@ -319,4 +344,3 @@ export async function stringify(input, options = {}) {
319
344
  }
320
345
  return chunks.join('');
321
346
  }
322
- //# sourceMappingURL=stringify-stream.js.map
@@ -6,4 +6,3 @@ export interface ReadJsonOptions {
6
6
  export declare function createJsonParser(options?: ReadJsonOptions): RequestHandler;
7
7
  export declare function readJson(req: Request, res: Response, parser: RequestHandler): Promise<unknown>;
8
8
  export type { NextFunction };
9
- //# sourceMappingURL=body.d.ts.map
@@ -25,4 +25,3 @@ export function readJson(req, res, parser) {
25
25
  }
26
26
  });
27
27
  }
28
- //# sourceMappingURL=body.js.map
@@ -1,3 +1,2 @@
1
1
  export { createExpressRouter } from './middleware.js';
2
2
  export type { ExpressOptions } from './middleware.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
1
1
  export { createExpressRouter } from './middleware.js';
2
- //# sourceMappingURL=index.js.map
@@ -9,4 +9,3 @@ export interface ExpressOptions {
9
9
  }
10
10
  export declare function createExpressRouter(repository: Repository, { mkInjectable, errorTransform, bodyLimit, useHtdoc, }?: ExpressOptions): Router;
11
11
  export type { RPCResponse };
12
- //# sourceMappingURL=middleware.d.ts.map
@@ -77,4 +77,3 @@ async function handleError(res, error) {
77
77
  },
78
78
  });
79
79
  }
80
- //# sourceMappingURL=middleware.js.map
@@ -1,4 +1,3 @@
1
1
  import type { Response } from 'express';
2
2
  import type { RPCResponse } from '../../types.js';
3
3
  export declare function respond(res: Response, payload: RPCResponse | undefined): Promise<void>;
4
- //# sourceMappingURL=respond.d.ts.map
@@ -122,4 +122,3 @@ async function respondNonStream(rpcRes, res) {
122
122
  if (!res.writableEnded && !res.destroyed)
123
123
  res.end();
124
124
  }
125
- //# sourceMappingURL=respond.js.map
@@ -1,2 +1 @@
1
1
  export { serveStdio, type StdioOptions } from './middleware.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
1
1
  export { serveStdio } from './middleware.js';
2
- //# sourceMappingURL=index.js.map
@@ -31,4 +31,3 @@ export interface StdioOptions {
31
31
  * Resolves when the input stream ends.
32
32
  */
33
33
  export declare function serveStdio(options?: StdioOptions): Promise<void>;
34
- //# sourceMappingURL=middleware.d.ts.map
@@ -276,4 +276,3 @@ function isWs(code) {
276
276
  // space, \t, \n, \r
277
277
  return code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
278
278
  }
279
- //# sourceMappingURL=middleware.js.map
@@ -1,3 +1,2 @@
1
1
  export { attachWebSocket, type WSOptions } from './middleware.js';
2
2
  export { createWebSocketServer, type StandaloneWsOptions, type StandaloneWsHandle, } from './standalone.js';
3
- //# sourceMappingURL=index.d.ts.map