request-iframe 0.0.2 → 0.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.
Files changed (84) hide show
  1. package/QUICKSTART.CN.md +35 -8
  2. package/QUICKSTART.md +35 -8
  3. package/README.CN.md +439 -36
  4. package/README.md +496 -30
  5. package/library/__tests__/channel.test.ts +420 -0
  6. package/library/__tests__/coverage-branches.test.ts +356 -0
  7. package/library/__tests__/debug.test.ts +588 -0
  8. package/library/__tests__/dispatcher.test.ts +481 -0
  9. package/library/__tests__/requestIframe.test.ts +3163 -185
  10. package/library/__tests__/server.test.ts +738 -0
  11. package/library/__tests__/stream.test.ts +46 -15
  12. package/library/api/client.d.ts.map +1 -1
  13. package/library/api/client.js +12 -6
  14. package/library/api/server.d.ts +4 -3
  15. package/library/api/server.d.ts.map +1 -1
  16. package/library/api/server.js +25 -7
  17. package/library/constants/index.d.ts +14 -4
  18. package/library/constants/index.d.ts.map +1 -1
  19. package/library/constants/index.js +15 -7
  20. package/library/constants/messages.d.ts +37 -0
  21. package/library/constants/messages.d.ts.map +1 -1
  22. package/library/constants/messages.js +38 -1
  23. package/library/core/client-server.d.ts +105 -0
  24. package/library/core/client-server.d.ts.map +1 -0
  25. package/library/core/client-server.js +289 -0
  26. package/library/core/client.d.ts +53 -10
  27. package/library/core/client.d.ts.map +1 -1
  28. package/library/core/client.js +529 -207
  29. package/library/core/request.d.ts +3 -1
  30. package/library/core/request.d.ts.map +1 -1
  31. package/library/core/request.js +2 -1
  32. package/library/core/response.d.ts +30 -4
  33. package/library/core/response.d.ts.map +1 -1
  34. package/library/core/response.js +176 -100
  35. package/library/core/server-client.d.ts +3 -1
  36. package/library/core/server-client.d.ts.map +1 -1
  37. package/library/core/server-client.js +19 -9
  38. package/library/core/server.d.ts +22 -1
  39. package/library/core/server.d.ts.map +1 -1
  40. package/library/core/server.js +304 -55
  41. package/library/index.d.ts +3 -2
  42. package/library/index.d.ts.map +1 -1
  43. package/library/index.js +34 -5
  44. package/library/interceptors/index.d.ts.map +1 -1
  45. package/library/message/channel.d.ts +3 -1
  46. package/library/message/channel.d.ts.map +1 -1
  47. package/library/message/dispatcher.d.ts +7 -2
  48. package/library/message/dispatcher.d.ts.map +1 -1
  49. package/library/message/dispatcher.js +48 -2
  50. package/library/message/index.d.ts.map +1 -1
  51. package/library/stream/file-stream.d.ts +5 -0
  52. package/library/stream/file-stream.d.ts.map +1 -1
  53. package/library/stream/file-stream.js +41 -12
  54. package/library/stream/index.d.ts +11 -1
  55. package/library/stream/index.d.ts.map +1 -1
  56. package/library/stream/index.js +21 -3
  57. package/library/stream/readable-stream.d.ts.map +1 -1
  58. package/library/stream/readable-stream.js +32 -30
  59. package/library/stream/types.d.ts +20 -2
  60. package/library/stream/types.d.ts.map +1 -1
  61. package/library/stream/writable-stream.d.ts +2 -1
  62. package/library/stream/writable-stream.d.ts.map +1 -1
  63. package/library/stream/writable-stream.js +13 -10
  64. package/library/types/index.d.ts +106 -32
  65. package/library/types/index.d.ts.map +1 -1
  66. package/library/utils/cache.d.ts +24 -0
  67. package/library/utils/cache.d.ts.map +1 -1
  68. package/library/utils/cache.js +76 -0
  69. package/library/utils/cookie.d.ts.map +1 -1
  70. package/library/utils/debug.d.ts.map +1 -1
  71. package/library/utils/debug.js +382 -20
  72. package/library/utils/index.d.ts +19 -0
  73. package/library/utils/index.d.ts.map +1 -1
  74. package/library/utils/index.js +113 -2
  75. package/library/utils/path-match.d.ts +16 -0
  76. package/library/utils/path-match.d.ts.map +1 -1
  77. package/library/utils/path-match.js +65 -0
  78. package/library/utils/protocol.d.ts.map +1 -1
  79. package/package.json +4 -1
  80. package/react/library/__tests__/index.test.tsx +274 -281
  81. package/react/library/index.d.ts +4 -3
  82. package/react/library/index.d.ts.map +1 -1
  83. package/react/library/index.js +225 -158
  84. package/react/package.json +7 -0
package/QUICKSTART.CN.md CHANGED
@@ -172,22 +172,49 @@ server.on('/api/download', async (req, res) => {
172
172
 
173
173
  // Client 端
174
174
  const response = await client.send('/api/download', {});
175
- if (response.fileData) {
175
+ if (response.data instanceof File || response.data instanceof Blob) {
176
+ const file = response.data instanceof File ? response.data : null;
177
+ const fileName = file?.name || 'download';
178
+
176
179
  // 创建下载链接
177
- const blob = new Blob(
178
- [atob(response.fileData.content)],
179
- { type: response.fileData.mimeType }
180
- );
181
- const url = URL.createObjectURL(blob);
182
-
180
+ const url = URL.createObjectURL(response.data);
181
+
183
182
  // 触发下载
184
183
  const a = document.createElement('a');
185
184
  a.href = url;
186
- a.download = response.fileData.fileName || 'download';
185
+ a.download = fileName;
187
186
  a.click();
187
+ URL.revokeObjectURL(url);
188
188
  }
189
189
  ```
190
190
 
191
+ ### 文件上传(Client → Server)
192
+
193
+ Client 向 Server 发送文件仅走**流式**。默认 `autoResolve: true`,Server 会在进入 handler 前把文件解析成 `File/Blob` 放到 `req.body`。
194
+
195
+ ```typescript
196
+ // Client 端
197
+ const file = new File(['Hello Upload'], 'upload.txt', { type: 'text/plain' });
198
+ await client.send('/api/upload', file); // File/Blob 会自动分发到 sendFile(走流式)
199
+
200
+ // Server 端
201
+ server.on('/api/upload', async (req, res) => {
202
+ const blob = req.body as Blob;
203
+ const text = await blob.text();
204
+ res.send({ ok: true, text });
205
+ });
206
+ ```
207
+
208
+ ### 路由参数(req.params)
209
+
210
+ 支持 Express 风格的 `:param` 路由参数,解析结果在 `req.params`。
211
+
212
+ ```typescript
213
+ server.on('/api/users/:id', (req, res) => {
214
+ res.send({ userId: req.params.id });
215
+ });
216
+ ```
217
+
191
218
  ### 调试模式
192
219
 
193
220
  开启 trace 模式查看详细日志:
package/QUICKSTART.md CHANGED
@@ -172,22 +172,49 @@ server.on('/api/download', async (req, res) => {
172
172
 
173
173
  // Client side
174
174
  const response = await client.send('/api/download', {});
175
- if (response.fileData) {
175
+ if (response.data instanceof File || response.data instanceof Blob) {
176
+ const file = response.data instanceof File ? response.data : null;
177
+ const fileName = file?.name || 'download';
178
+
176
179
  // Create download link
177
- const blob = new Blob(
178
- [atob(response.fileData.content)],
179
- { type: response.fileData.mimeType }
180
- );
181
- const url = URL.createObjectURL(blob);
182
-
180
+ const url = URL.createObjectURL(response.data);
181
+
183
182
  // Trigger download
184
183
  const a = document.createElement('a');
185
184
  a.href = url;
186
- a.download = response.fileData.fileName || 'download';
185
+ a.download = fileName;
187
186
  a.click();
187
+ URL.revokeObjectURL(url);
188
188
  }
189
189
  ```
190
190
 
191
+ ### File Upload (Client → Server)
192
+
193
+ Client sends files via stream only. By default `autoResolve: true`, server will resolve the file to `File/Blob` and put it into `req.body` before calling your handler.
194
+
195
+ ```typescript
196
+ // Client side
197
+ const file = new File(['Hello Upload'], 'upload.txt', { type: 'text/plain' });
198
+ await client.send('/api/upload', file); // File/Blob auto-dispatches to sendFile (stream)
199
+
200
+ // Server side
201
+ server.on('/api/upload', async (req, res) => {
202
+ const blob = req.body as Blob;
203
+ const text = await blob.text();
204
+ res.send({ ok: true, text });
205
+ });
206
+ ```
207
+
208
+ ### Route Params (req.params)
209
+
210
+ Supports Express-style `:param` route parameters. Extracted parameters are available in `req.params`.
211
+
212
+ ```typescript
213
+ server.on('/api/users/:id', (req, res) => {
214
+ res.send({ userId: req.params.id });
215
+ });
216
+ ```
217
+
191
218
  ### Debug Mode
192
219
 
193
220
  Enable trace mode to view detailed logs: