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.
- package/QUICKSTART.CN.md +35 -8
- package/QUICKSTART.md +35 -8
- package/README.CN.md +439 -36
- package/README.md +496 -30
- package/library/__tests__/channel.test.ts +420 -0
- package/library/__tests__/coverage-branches.test.ts +356 -0
- package/library/__tests__/debug.test.ts +588 -0
- package/library/__tests__/dispatcher.test.ts +481 -0
- package/library/__tests__/requestIframe.test.ts +3163 -185
- package/library/__tests__/server.test.ts +738 -0
- package/library/__tests__/stream.test.ts +46 -15
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +12 -6
- package/library/api/server.d.ts +4 -3
- package/library/api/server.d.ts.map +1 -1
- package/library/api/server.js +25 -7
- package/library/constants/index.d.ts +14 -4
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +15 -7
- package/library/constants/messages.d.ts +37 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +38 -1
- package/library/core/client-server.d.ts +105 -0
- package/library/core/client-server.d.ts.map +1 -0
- package/library/core/client-server.js +289 -0
- package/library/core/client.d.ts +53 -10
- package/library/core/client.d.ts.map +1 -1
- package/library/core/client.js +529 -207
- package/library/core/request.d.ts +3 -1
- package/library/core/request.d.ts.map +1 -1
- package/library/core/request.js +2 -1
- package/library/core/response.d.ts +30 -4
- package/library/core/response.d.ts.map +1 -1
- package/library/core/response.js +176 -100
- package/library/core/server-client.d.ts +3 -1
- package/library/core/server-client.d.ts.map +1 -1
- package/library/core/server-client.js +19 -9
- package/library/core/server.d.ts +22 -1
- package/library/core/server.d.ts.map +1 -1
- package/library/core/server.js +304 -55
- package/library/index.d.ts +3 -2
- package/library/index.d.ts.map +1 -1
- package/library/index.js +34 -5
- package/library/interceptors/index.d.ts.map +1 -1
- package/library/message/channel.d.ts +3 -1
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/dispatcher.d.ts +7 -2
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +48 -2
- package/library/message/index.d.ts.map +1 -1
- package/library/stream/file-stream.d.ts +5 -0
- package/library/stream/file-stream.d.ts.map +1 -1
- package/library/stream/file-stream.js +41 -12
- package/library/stream/index.d.ts +11 -1
- package/library/stream/index.d.ts.map +1 -1
- package/library/stream/index.js +21 -3
- package/library/stream/readable-stream.d.ts.map +1 -1
- package/library/stream/readable-stream.js +32 -30
- package/library/stream/types.d.ts +20 -2
- package/library/stream/types.d.ts.map +1 -1
- package/library/stream/writable-stream.d.ts +2 -1
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +13 -10
- package/library/types/index.d.ts +106 -32
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/cache.d.ts +24 -0
- package/library/utils/cache.d.ts.map +1 -1
- package/library/utils/cache.js +76 -0
- package/library/utils/cookie.d.ts.map +1 -1
- package/library/utils/debug.d.ts.map +1 -1
- package/library/utils/debug.js +382 -20
- package/library/utils/index.d.ts +19 -0
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +113 -2
- package/library/utils/path-match.d.ts +16 -0
- package/library/utils/path-match.d.ts.map +1 -1
- package/library/utils/path-match.js +65 -0
- package/library/utils/protocol.d.ts.map +1 -1
- package/package.json +4 -1
- package/react/library/__tests__/index.test.tsx +274 -281
- package/react/library/index.d.ts +4 -3
- package/react/library/index.d.ts.map +1 -1
- package/react/library/index.js +225 -158
- 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.
|
|
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
|
|
178
|
-
|
|
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 =
|
|
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.
|
|
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
|
|
178
|
-
|
|
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 =
|
|
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:
|