request-iframe 0.0.3 → 0.0.5
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 +177 -24
- package/README.md +237 -19
- package/library/__tests__/channel.test.ts +16 -4
- package/library/__tests__/coverage-branches.test.ts +356 -0
- package/library/__tests__/debug.test.ts +22 -0
- package/library/__tests__/dispatcher.test.ts +8 -4
- package/library/__tests__/requestIframe.test.ts +1243 -87
- package/library/__tests__/stream.test.ts +92 -16
- package/library/__tests__/utils.test.ts +41 -1
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +1 -0
- package/library/constants/index.d.ts +2 -0
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +3 -1
- package/library/constants/messages.d.ts +3 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +3 -0
- package/library/core/client-server.d.ts +4 -0
- package/library/core/client-server.d.ts.map +1 -1
- package/library/core/client-server.js +45 -22
- package/library/core/client.d.ts +36 -4
- package/library/core/client.d.ts.map +1 -1
- package/library/core/client.js +508 -285
- 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 +26 -4
- package/library/core/response.d.ts.map +1 -1
- package/library/core/response.js +192 -112
- package/library/core/server.d.ts +13 -0
- package/library/core/server.d.ts.map +1 -1
- package/library/core/server.js +221 -6
- package/library/index.d.ts +2 -1
- package/library/index.d.ts.map +1 -1
- package/library/index.js +39 -3
- package/library/message/channel.d.ts +2 -2
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/channel.js +5 -1
- package/library/message/dispatcher.d.ts +2 -2
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +6 -5
- 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/types.d.ts +2 -2
- package/library/stream/types.d.ts.map +1 -1
- package/library/stream/writable-stream.d.ts +1 -1
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +87 -47
- package/library/types/index.d.ts +29 -5
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/debug.d.ts.map +1 -1
- package/library/utils/debug.js +6 -2
- package/library/utils/error.d.ts +21 -0
- package/library/utils/error.d.ts.map +1 -0
- package/library/utils/error.js +34 -0
- package/library/utils/index.d.ts +21 -0
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +141 -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/package.json +2 -1
- package/react/library/__tests__/index.test.tsx +44 -22
- package/react/library/index.d.ts.map +1 -1
- package/react/library/index.js +81 -23
- package/react/package.json +7 -0
package/library/core/server.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
require("core-js/modules/es.symbol.description.js");
|
|
4
|
+
require("core-js/modules/es.array.filter.js");
|
|
5
|
+
require("core-js/modules/es.array.from.js");
|
|
6
|
+
require("core-js/modules/es.array.slice.js");
|
|
7
|
+
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
8
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
3
9
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
10
|
Object.defineProperty(exports, "__esModule", {
|
|
5
11
|
value: true
|
|
6
12
|
});
|
|
7
13
|
exports.RequestIframeServerImpl = void 0;
|
|
14
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
15
|
require("core-js/modules/es.array.iterator.js");
|
|
9
16
|
require("core-js/modules/es.map.js");
|
|
10
17
|
require("core-js/modules/es.object.entries.js");
|
|
11
18
|
require("core-js/modules/es.promise.js");
|
|
19
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
20
|
+
require("core-js/modules/es.string.includes.js");
|
|
21
|
+
require("core-js/modules/es.string.match.js");
|
|
22
|
+
require("core-js/modules/es.string.replace.js");
|
|
23
|
+
require("core-js/modules/es.string.starts-with.js");
|
|
12
24
|
require("core-js/modules/web.dom-collections.for-each.js");
|
|
13
25
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
26
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
27
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
28
|
var _utils = require("../utils");
|
|
16
29
|
var _pathMatch = require("../utils/path-match");
|
|
@@ -19,6 +32,12 @@ var _response = require("./response");
|
|
|
19
32
|
var _message = require("../message");
|
|
20
33
|
var _cache = require("../utils/cache");
|
|
21
34
|
var _constants = require("../constants");
|
|
35
|
+
var _stream = require("../stream");
|
|
36
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
37
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
38
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
39
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
40
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
41
|
/**
|
|
23
42
|
* Middleware item (contains path matcher and middleware function)
|
|
24
43
|
*/
|
|
@@ -27,6 +46,8 @@ var _constants = require("../constants");
|
|
|
27
46
|
* Pending acknowledgment
|
|
28
47
|
*/
|
|
29
48
|
|
|
49
|
+
/** Pending request waiting for client stream (streamId present) */
|
|
50
|
+
|
|
30
51
|
/**
|
|
31
52
|
* Server configuration options
|
|
32
53
|
*/
|
|
@@ -43,6 +64,10 @@ class RequestIframeServerImpl {
|
|
|
43
64
|
(0, _defineProperty2.default)(this, "middlewares", []);
|
|
44
65
|
/** Responses waiting for client acknowledgment */
|
|
45
66
|
(0, _defineProperty2.default)(this, "pendingAcks", new Map());
|
|
67
|
+
/** Pending requests waiting for client stream_start (streamId present) */
|
|
68
|
+
(0, _defineProperty2.default)(this, "pendingStreamRequests", new Map());
|
|
69
|
+
/** Stream message handlers (streamId -> handler) for client→server streams */
|
|
70
|
+
(0, _defineProperty2.default)(this, "streamHandlers", new Map());
|
|
46
71
|
/** List of functions to unregister handlers */
|
|
47
72
|
(0, _defineProperty2.default)(this, "unregisterFns", []);
|
|
48
73
|
/** Whether it is open */
|
|
@@ -107,6 +132,124 @@ class RequestIframeServerImpl {
|
|
|
107
132
|
|
|
108
133
|
// Handle RECEIVED messages (for confirming response delivery)
|
|
109
134
|
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.RECEIVED, data => this.handleReceived(data), handlerOptions));
|
|
135
|
+
|
|
136
|
+
// Handle stream_* messages (client→server stream)
|
|
137
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.STREAM_START, (data, ctx) => this.handleStreamStart(data, ctx), handlerOptions));
|
|
138
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(type => type.startsWith('stream_') && type !== _constants.MessageType.STREAM_START, (data, _context) => this.dispatchStreamMessage(data), handlerOptions));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Handle stream_start from client (stream request with streamId) */
|
|
142
|
+
handleStreamStart(data, _context) {
|
|
143
|
+
var _body$chunked;
|
|
144
|
+
if (data.role !== _constants.MessageRole.CLIENT) return;
|
|
145
|
+
var body = data.body;
|
|
146
|
+
if (!(body !== null && body !== void 0 && body.streamId)) return;
|
|
147
|
+
var pending = this.pendingStreamRequests.get(data.requestId);
|
|
148
|
+
if (!pending || pending.streamId !== body.streamId) return;
|
|
149
|
+
this.pendingStreamRequests.delete(data.requestId);
|
|
150
|
+
var targetWindow = pending.targetWindow,
|
|
151
|
+
targetOrigin = pending.targetOrigin,
|
|
152
|
+
res = pending.res,
|
|
153
|
+
reqData = pending.data,
|
|
154
|
+
reqContext = pending.context,
|
|
155
|
+
handlerFn = pending.handlerFn;
|
|
156
|
+
var streamHandler = {
|
|
157
|
+
registerStreamHandler: (streamId, handler) => {
|
|
158
|
+
this.streamHandlers.set(streamId, handler);
|
|
159
|
+
},
|
|
160
|
+
unregisterStreamHandler: streamId => {
|
|
161
|
+
this.streamHandlers.delete(streamId);
|
|
162
|
+
},
|
|
163
|
+
postMessage: message => {
|
|
164
|
+
this.dispatcher.send(targetWindow, message, targetOrigin);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var streamType = body.type || _constants.StreamType.DATA;
|
|
168
|
+
var streamChunked = (_body$chunked = body.chunked) !== null && _body$chunked !== void 0 ? _body$chunked : true;
|
|
169
|
+
var streamMetadata = body.metadata;
|
|
170
|
+
var req = new _request.ServerRequestImpl(reqData, reqContext, res, pending.params);
|
|
171
|
+
|
|
172
|
+
// File stream: optionally auto-resolve to File/Blob before calling handler
|
|
173
|
+
if (streamType === _constants.StreamType.FILE) {
|
|
174
|
+
var _body$autoResolve;
|
|
175
|
+
var fileStream = new _stream.IframeFileReadableStream(body.streamId, data.requestId, streamHandler, {
|
|
176
|
+
chunked: streamChunked,
|
|
177
|
+
metadata: streamMetadata,
|
|
178
|
+
filename: streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.filename,
|
|
179
|
+
mimeType: streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.mimeType,
|
|
180
|
+
size: streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.size
|
|
181
|
+
});
|
|
182
|
+
var autoResolve = (_body$autoResolve = body.autoResolve) !== null && _body$autoResolve !== void 0 ? _body$autoResolve : false;
|
|
183
|
+
if (autoResolve) {
|
|
184
|
+
var name = fileStream.filename || (streamMetadata === null || streamMetadata === void 0 ? void 0 : streamMetadata.filename);
|
|
185
|
+
var promise = name ? fileStream.readAsFile(name) : fileStream.readAsBlob();
|
|
186
|
+
promise.then(fileData => {
|
|
187
|
+
req.body = fileData;
|
|
188
|
+
req.stream = undefined;
|
|
189
|
+
this.runMiddlewares(req, res, () => {
|
|
190
|
+
try {
|
|
191
|
+
var result = handlerFn(req, res);
|
|
192
|
+
if ((0, _utils.isPromise)(result)) {
|
|
193
|
+
// Window check is handled in MessageDispatcher
|
|
194
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ASYNC, data.requestId, {
|
|
195
|
+
path: reqData.path,
|
|
196
|
+
targetId: data.creatorId
|
|
197
|
+
});
|
|
198
|
+
result.then(this.handleRequestResult.bind(this, res, targetWindow, targetOrigin, reqData)).catch(this.handleRequestError.bind(this, res, targetWindow, targetOrigin, reqData));
|
|
199
|
+
} else {
|
|
200
|
+
this.handleRequestResult(res, targetWindow, targetOrigin, reqData, result);
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
this.handleRequestError(res, targetWindow, targetOrigin, reqData, error);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}).catch(error => {
|
|
207
|
+
this.handleRequestError(res, targetWindow, targetOrigin, reqData, error);
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Non-autoResolve: expose stream directly
|
|
213
|
+
req.body = fileStream;
|
|
214
|
+
req.stream = fileStream;
|
|
215
|
+
} else {
|
|
216
|
+
// Non-file stream
|
|
217
|
+
var readableStream = new _stream.IframeReadableStream(body.streamId, data.requestId, streamHandler, {
|
|
218
|
+
type: streamType,
|
|
219
|
+
chunked: streamChunked,
|
|
220
|
+
metadata: streamMetadata
|
|
221
|
+
});
|
|
222
|
+
req.body = undefined;
|
|
223
|
+
req.stream = readableStream;
|
|
224
|
+
}
|
|
225
|
+
this.runMiddlewares(req, res, () => {
|
|
226
|
+
try {
|
|
227
|
+
var result = handlerFn(req, res);
|
|
228
|
+
if ((0, _utils.isPromise)(result)) {
|
|
229
|
+
// Window check is handled in MessageDispatcher
|
|
230
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ASYNC, data.requestId, {
|
|
231
|
+
path: reqData.path,
|
|
232
|
+
targetId: data.creatorId
|
|
233
|
+
});
|
|
234
|
+
result.then(this.handleRequestResult.bind(this, res, targetWindow, targetOrigin, reqData)).catch(this.handleRequestError.bind(this, res, targetWindow, targetOrigin, reqData));
|
|
235
|
+
} else {
|
|
236
|
+
this.handleRequestResult(res, targetWindow, targetOrigin, reqData, result);
|
|
237
|
+
}
|
|
238
|
+
} catch (error) {
|
|
239
|
+
this.handleRequestError(res, targetWindow, targetOrigin, reqData, error);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
dispatchStreamMessage(data) {
|
|
244
|
+
var body = data.body;
|
|
245
|
+
if (!(body !== null && body !== void 0 && body.streamId)) return;
|
|
246
|
+
var handler = this.streamHandlers.get(body.streamId);
|
|
247
|
+
if (handler) {
|
|
248
|
+
var messageType = data.type.replace('stream_', '');
|
|
249
|
+
handler(_objectSpread(_objectSpread({}, body), {}, {
|
|
250
|
+
type: messageType
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
110
253
|
}
|
|
111
254
|
|
|
112
255
|
/**
|
|
@@ -116,6 +259,7 @@ class RequestIframeServerImpl {
|
|
|
116
259
|
if (!context.source) return;
|
|
117
260
|
|
|
118
261
|
// Send protocol version incompatibility error
|
|
262
|
+
// Window check is handled in MessageDispatcher
|
|
119
263
|
this.dispatcher.sendMessage(context.source, context.origin, _constants.MessageType.ERROR, data.requestId, {
|
|
120
264
|
path: data.path,
|
|
121
265
|
status: _constants.HttpStatus.BAD_REQUEST,
|
|
@@ -132,6 +276,8 @@ class RequestIframeServerImpl {
|
|
|
132
276
|
*/
|
|
133
277
|
handlePing(data, context) {
|
|
134
278
|
if (!context.source) return;
|
|
279
|
+
|
|
280
|
+
// Window check is handled in MessageDispatcher
|
|
135
281
|
this.dispatcher.sendMessage(context.source, context.origin, _constants.MessageType.PONG, data.requestId);
|
|
136
282
|
}
|
|
137
283
|
|
|
@@ -163,6 +309,8 @@ class RequestIframeServerImpl {
|
|
|
163
309
|
* If statusCode is still the default OK (200), override it to INTERNAL_SERVER_ERROR.
|
|
164
310
|
*/
|
|
165
311
|
var errorStatus = res.statusCode === _constants.HttpStatus.OK ? _constants.HttpStatus.INTERNAL_SERVER_ERROR : res.statusCode;
|
|
312
|
+
|
|
313
|
+
// Window check is handled in MessageDispatcher
|
|
166
314
|
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
167
315
|
path: data.path,
|
|
168
316
|
error: {
|
|
@@ -193,6 +341,50 @@ class RequestIframeServerImpl {
|
|
|
193
341
|
}
|
|
194
342
|
}
|
|
195
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Find matching handler and extract path parameters
|
|
346
|
+
* @param requestPath The actual request path
|
|
347
|
+
* @returns Handler function and extracted parameters, or null if not found
|
|
348
|
+
*/
|
|
349
|
+
findHandler(requestPath) {
|
|
350
|
+
var prefixedRequestPath = this.dispatcher.prefixPath(requestPath);
|
|
351
|
+
|
|
352
|
+
// First try exact match (for backward compatibility and performance)
|
|
353
|
+
var exactHandler = this.handlers.get(prefixedRequestPath);
|
|
354
|
+
if (exactHandler) {
|
|
355
|
+
return {
|
|
356
|
+
handler: exactHandler,
|
|
357
|
+
params: {}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Then try parameter matching (e.g., '/api/users/:id' matches '/api/users/123')
|
|
362
|
+
var _iterator = _createForOfIteratorHelper(this.handlers.entries()),
|
|
363
|
+
_step;
|
|
364
|
+
try {
|
|
365
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
366
|
+
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
|
|
367
|
+
registeredPath = _step$value[0],
|
|
368
|
+
handler = _step$value[1];
|
|
369
|
+
// Check if registered path contains parameters
|
|
370
|
+
if (registeredPath.includes(':')) {
|
|
371
|
+
var matchResult = (0, _pathMatch.matchPathWithParams)(prefixedRequestPath, registeredPath);
|
|
372
|
+
if (matchResult.match) {
|
|
373
|
+
return {
|
|
374
|
+
handler,
|
|
375
|
+
params: matchResult.params
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
} catch (err) {
|
|
381
|
+
_iterator.e(err);
|
|
382
|
+
} finally {
|
|
383
|
+
_iterator.f();
|
|
384
|
+
}
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
|
|
196
388
|
/**
|
|
197
389
|
* Handle request
|
|
198
390
|
*/
|
|
@@ -208,10 +400,9 @@ class RequestIframeServerImpl {
|
|
|
208
400
|
var targetWindow = context.source;
|
|
209
401
|
var targetOrigin = context.origin;
|
|
210
402
|
|
|
211
|
-
//
|
|
212
|
-
var
|
|
213
|
-
|
|
214
|
-
if (!handlerFn) {
|
|
403
|
+
// Find matching handler and extract path parameters
|
|
404
|
+
var handlerMatch = this.findHandler(data.path);
|
|
405
|
+
if (!handlerMatch) {
|
|
215
406
|
// No handler found in this instance
|
|
216
407
|
// Mark as handled by this instance (using special marker) to prevent other instances from processing
|
|
217
408
|
// This ensures only one instance sends the error response
|
|
@@ -219,6 +410,7 @@ class RequestIframeServerImpl {
|
|
|
219
410
|
|
|
220
411
|
// Send METHOD_NOT_FOUND error
|
|
221
412
|
// Use request's creatorId as targetId to route back to the correct client
|
|
413
|
+
// Window check is handled in MessageDispatcher
|
|
222
414
|
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
223
415
|
path: data.path,
|
|
224
416
|
error: {
|
|
@@ -231,12 +423,15 @@ class RequestIframeServerImpl {
|
|
|
231
423
|
});
|
|
232
424
|
return;
|
|
233
425
|
}
|
|
426
|
+
var handlerFn = handlerMatch.handler,
|
|
427
|
+
params = handlerMatch.params;
|
|
234
428
|
|
|
235
429
|
// Mark message as handled by this server instance to prevent other server instances from processing it
|
|
236
430
|
context.handledBy = this.id;
|
|
237
431
|
|
|
238
432
|
// Send ACK immediately via dispatcher
|
|
239
433
|
// Use request's creatorId as targetId to route back to the correct client
|
|
434
|
+
// Window check is handled in MessageDispatcher
|
|
240
435
|
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ACK, data.requestId, {
|
|
241
436
|
path: data.path,
|
|
242
437
|
targetId: data.creatorId
|
|
@@ -253,8 +448,27 @@ class RequestIframeServerImpl {
|
|
|
253
448
|
res._triggerAck(false);
|
|
254
449
|
});
|
|
255
450
|
|
|
256
|
-
//
|
|
257
|
-
|
|
451
|
+
// Client sends body as stream: wait for stream_start, then create readable stream and call handler
|
|
452
|
+
// If streamId is present, this is a stream request
|
|
453
|
+
var streamId = data.streamId;
|
|
454
|
+
if (streamId) {
|
|
455
|
+
this.pendingStreamRequests.set(data.requestId, {
|
|
456
|
+
path: data.path || '',
|
|
457
|
+
requestId: data.requestId,
|
|
458
|
+
streamId,
|
|
459
|
+
handlerFn,
|
|
460
|
+
targetWindow,
|
|
461
|
+
targetOrigin,
|
|
462
|
+
res,
|
|
463
|
+
data,
|
|
464
|
+
context,
|
|
465
|
+
params
|
|
466
|
+
});
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Create request object with path parameters
|
|
471
|
+
var req = new _request.ServerRequestImpl(data, context, res, params);
|
|
258
472
|
|
|
259
473
|
// Execute middleware chain
|
|
260
474
|
this.runMiddlewares(req, res, () => {
|
|
@@ -262,6 +476,7 @@ class RequestIframeServerImpl {
|
|
|
262
476
|
var result = handlerFn(req, res);
|
|
263
477
|
if ((0, _utils.isPromise)(result)) {
|
|
264
478
|
// Async task
|
|
479
|
+
// Window check is handled in MessageDispatcher
|
|
265
480
|
// Use request's creatorId as targetId to route back to the correct client
|
|
266
481
|
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ASYNC, data.requestId, {
|
|
267
482
|
path: data.path,
|
package/library/index.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ export type { MessageContext, MessageHandlerFn, MessageTypeMatcher, VersionValid
|
|
|
8
8
|
export { getOrCreateMessageChannel, releaseMessageChannel, clearMessageChannelCache, } from './utils/cache';
|
|
9
9
|
export { ServerRequestImpl } from './core/request';
|
|
10
10
|
export { ServerResponseImpl } from './core/response';
|
|
11
|
-
export { IframeWritableStream, IframeReadableStream, IframeFileWritableStream, IframeFileReadableStream, isIframeReadableStream,
|
|
11
|
+
export { IframeWritableStream, IframeReadableStream, IframeFileWritableStream, IframeFileReadableStream, isIframeReadableStream, isIframeFileReadableStream, isIframeFileWritableStream, isIframeWritableStream } from './stream';
|
|
12
12
|
export type { StreamType, StreamState, StreamChunk, WritableStreamOptions, ReadableStreamOptions, FileWritableStreamOptions, FileReadableStreamOptions, StreamBindContext, IIframeWritableStream, IIframeReadableStream, IIframeFileReadableStream, StreamMessageData } from './stream';
|
|
13
13
|
export * from './types';
|
|
14
|
+
export { detectContentType, blobToBase64, RequestIframeError } from './utils';
|
|
14
15
|
export { InterceptorManager, RequestInterceptorManager, ResponseInterceptorManager } from './interceptors';
|
|
15
16
|
export * from './constants';
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
package/library/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC3E,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,WAAW,IAAI,gBAAgB,EAChC,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAC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ACZ,kBAAkB,EACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE3G,cAAc,aAAa,CAAC"}
|
package/library/index.js
CHANGED
|
@@ -25,7 +25,12 @@ var _exportNames = {
|
|
|
25
25
|
IframeFileWritableStream: true,
|
|
26
26
|
IframeFileReadableStream: true,
|
|
27
27
|
isIframeReadableStream: true,
|
|
28
|
-
|
|
28
|
+
isIframeFileReadableStream: true,
|
|
29
|
+
isIframeFileWritableStream: true,
|
|
30
|
+
isIframeWritableStream: true,
|
|
31
|
+
detectContentType: true,
|
|
32
|
+
blobToBase64: true,
|
|
33
|
+
RequestIframeError: true,
|
|
29
34
|
InterceptorManager: true,
|
|
30
35
|
RequestInterceptorManager: true,
|
|
31
36
|
ResponseInterceptorManager: true
|
|
@@ -90,6 +95,12 @@ Object.defineProperty(exports, "RequestIframeClientServer", {
|
|
|
90
95
|
return _clientServer.RequestIframeClientServer;
|
|
91
96
|
}
|
|
92
97
|
});
|
|
98
|
+
Object.defineProperty(exports, "RequestIframeError", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function get() {
|
|
101
|
+
return _utils.RequestIframeError;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
93
104
|
Object.defineProperty(exports, "RequestIframeServerImpl", {
|
|
94
105
|
enumerable: true,
|
|
95
106
|
get: function get() {
|
|
@@ -120,6 +131,12 @@ Object.defineProperty(exports, "ServerResponseImpl", {
|
|
|
120
131
|
return _response.ServerResponseImpl;
|
|
121
132
|
}
|
|
122
133
|
});
|
|
134
|
+
Object.defineProperty(exports, "blobToBase64", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function get() {
|
|
137
|
+
return _utils.blobToBase64;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
123
140
|
Object.defineProperty(exports, "clearMessageChannelCache", {
|
|
124
141
|
enumerable: true,
|
|
125
142
|
get: function get() {
|
|
@@ -138,16 +155,28 @@ Object.defineProperty(exports, "clearRequestIframeServerCache", {
|
|
|
138
155
|
return _server.clearRequestIframeServerCache;
|
|
139
156
|
}
|
|
140
157
|
});
|
|
158
|
+
Object.defineProperty(exports, "detectContentType", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: function get() {
|
|
161
|
+
return _utils.detectContentType;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
141
164
|
Object.defineProperty(exports, "getOrCreateMessageChannel", {
|
|
142
165
|
enumerable: true,
|
|
143
166
|
get: function get() {
|
|
144
167
|
return _cache.getOrCreateMessageChannel;
|
|
145
168
|
}
|
|
146
169
|
});
|
|
147
|
-
Object.defineProperty(exports, "
|
|
170
|
+
Object.defineProperty(exports, "isIframeFileReadableStream", {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
get: function get() {
|
|
173
|
+
return _stream.isIframeFileReadableStream;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(exports, "isIframeFileWritableStream", {
|
|
148
177
|
enumerable: true,
|
|
149
178
|
get: function get() {
|
|
150
|
-
return _stream.
|
|
179
|
+
return _stream.isIframeFileWritableStream;
|
|
151
180
|
}
|
|
152
181
|
});
|
|
153
182
|
Object.defineProperty(exports, "isIframeReadableStream", {
|
|
@@ -156,6 +185,12 @@ Object.defineProperty(exports, "isIframeReadableStream", {
|
|
|
156
185
|
return _stream.isIframeReadableStream;
|
|
157
186
|
}
|
|
158
187
|
});
|
|
188
|
+
Object.defineProperty(exports, "isIframeWritableStream", {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function get() {
|
|
191
|
+
return _stream.isIframeWritableStream;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
159
194
|
Object.defineProperty(exports, "releaseMessageChannel", {
|
|
160
195
|
enumerable: true,
|
|
161
196
|
get: function get() {
|
|
@@ -196,6 +231,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
196
231
|
}
|
|
197
232
|
});
|
|
198
233
|
});
|
|
234
|
+
var _utils = require("./utils");
|
|
199
235
|
var _interceptors = require("./interceptors");
|
|
200
236
|
var _constants = require("./constants");
|
|
201
237
|
Object.keys(_constants).forEach(function (key) {
|
|
@@ -87,7 +87,7 @@ export declare class MessageChannel {
|
|
|
87
87
|
* @param message message data (already formatted as PostMessageData)
|
|
88
88
|
* @param targetOrigin target origin (defaults to '*')
|
|
89
89
|
*/
|
|
90
|
-
send(target: Window, message: PostMessageData, targetOrigin?: string):
|
|
90
|
+
send(target: Window, message: PostMessageData, targetOrigin?: string): boolean;
|
|
91
91
|
/**
|
|
92
92
|
* Send typed message to target window (creates PostMessageData automatically)
|
|
93
93
|
* @param target target window
|
|
@@ -96,7 +96,7 @@ export declare class MessageChannel {
|
|
|
96
96
|
* @param requestId request ID
|
|
97
97
|
* @param data additional data
|
|
98
98
|
*/
|
|
99
|
-
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role'>>):
|
|
99
|
+
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role'>>): boolean;
|
|
100
100
|
/**
|
|
101
101
|
* Add path prefix (for secretKey isolation)
|
|
102
102
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/message/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,E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,EAAE,eAAe,CAAC,MAAM,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,mBAAmB,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,MAAM,CAAC,CAAC,GACvG,OAAO;IAQV;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,OAAO,IAAI,IAAI;CAIvB"}
|
|
@@ -148,7 +148,11 @@ class MessageChannel {
|
|
|
148
148
|
* @param targetOrigin target origin (defaults to '*')
|
|
149
149
|
*/
|
|
150
150
|
send(target, message, targetOrigin = '*') {
|
|
151
|
+
if (!(0, _utils.isWindowAvailable)(target)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
151
154
|
target.postMessage(message, targetOrigin);
|
|
155
|
+
return true;
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
/**
|
|
@@ -163,7 +167,7 @@ class MessageChannel {
|
|
|
163
167
|
var message = (0, _utils.createPostMessage)(type, requestId, _objectSpread(_objectSpread({}, data), {}, {
|
|
164
168
|
secretKey: this.secretKey
|
|
165
169
|
}));
|
|
166
|
-
this.send(target, message, targetOrigin);
|
|
170
|
+
return this.send(target, message, targetOrigin);
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
/**
|
|
@@ -98,7 +98,7 @@ export declare class MessageDispatcher {
|
|
|
98
98
|
* @param message message data (already formatted as PostMessageData)
|
|
99
99
|
* @param targetOrigin target origin (defaults to '*')
|
|
100
100
|
*/
|
|
101
|
-
send(target: Window, message: PostMessageData, targetOrigin?: string):
|
|
101
|
+
send(target: Window, message: PostMessageData, targetOrigin?: string): boolean;
|
|
102
102
|
/**
|
|
103
103
|
* Send typed message to target window (creates PostMessageData automatically)
|
|
104
104
|
* @param target target window
|
|
@@ -107,7 +107,7 @@ export declare class MessageDispatcher {
|
|
|
107
107
|
* @param requestId request ID
|
|
108
108
|
* @param data additional data
|
|
109
109
|
*/
|
|
110
|
-
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role' | 'creatorId'>>):
|
|
110
|
+
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role' | 'creatorId'>>): boolean;
|
|
111
111
|
/**
|
|
112
112
|
* Add path prefix
|
|
113
113
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/message/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EACL,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;AAExF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,4DAA4D;IAC5D,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5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;IAEzF,wEAAwE;IACxE,OAAO,CAAC,QAAQ,CAAK;gBAEF,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,gBAAgB,EAAE,UAAU,CAAC,EAAE,MAAM;IAkBvF;;OAEG;IACI,MAAM,IAAI,IAAI;IAIrB;;;OAGG;IACI,OAAO,IAAI,MAAM;IAIxB;;OAEG;IACI,WAAW,IAAI,MAAM;IAM5B;;;;;;OAMG;IACI,eAAe,CACpB,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,gBAAgB,EACzB,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,GAChC,MAAM,IAAI;IAyBb;;OAEG;IACI,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAOzD;;OAEG;IACH,OAAO,CAAC,eAAe;IAkDvB;;OAEG;IACH,OAAO,CAAC,SAAS;IAejB;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,GAAE,MAAY,GAAG,OAAO;IAW1F;;;;;;;OAOG;IACI,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,mBAAmB,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC,CAAC,GACrH,OAAO;IAcV;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,UAAU,IAAI,cAAc;IAInC;;OAEG;IACI,OAAO,IAAI,IAAI;CAIvB"}
|
|
@@ -246,7 +246,7 @@ class MessageDispatcher {
|
|
|
246
246
|
if (message.creatorId === undefined && this.instanceId) {
|
|
247
247
|
message.creatorId = this.instanceId;
|
|
248
248
|
}
|
|
249
|
-
this.channel.send(target, message, targetOrigin);
|
|
249
|
+
return this.channel.send(target, message, targetOrigin);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
@@ -258,13 +258,14 @@ class MessageDispatcher {
|
|
|
258
258
|
* @param data additional data
|
|
259
259
|
*/
|
|
260
260
|
sendMessage(target, targetOrigin, type, requestId, data) {
|
|
261
|
-
// Automatically set role and
|
|
262
|
-
// Create message with role and
|
|
261
|
+
// Automatically set role, creatorId, and secretKey based on dispatcher's properties
|
|
262
|
+
// Create message with role, creatorId, and secretKey using createPostMessage directly
|
|
263
263
|
var message = (0, _utils.createPostMessage)(type, requestId, _objectSpread(_objectSpread({}, data), {}, {
|
|
264
264
|
role: this.role,
|
|
265
|
-
creatorId: this.instanceId
|
|
265
|
+
creatorId: this.instanceId,
|
|
266
|
+
secretKey: this.secretKey
|
|
266
267
|
}));
|
|
267
|
-
this.channel.send(target, message, targetOrigin);
|
|
268
|
+
return this.channel.send(target, message, targetOrigin);
|
|
268
269
|
}
|
|
269
270
|
|
|
270
271
|
// ==================== Utilities ====================
|
|
@@ -3,6 +3,8 @@ export { IframeWritableStream } from './writable-stream';
|
|
|
3
3
|
export { IframeFileWritableStream } from './file-stream';
|
|
4
4
|
export { IframeReadableStream, StreamMessageHandler } from './readable-stream';
|
|
5
5
|
export { IframeFileReadableStream } from './file-stream';
|
|
6
|
+
import { IframeFileWritableStream } from './file-stream';
|
|
7
|
+
import { IframeWritableStream } from './writable-stream';
|
|
6
8
|
import { IIframeReadableStream, IIframeFileReadableStream } from './types';
|
|
7
9
|
/**
|
|
8
10
|
* Check if value is an IframeReadableStream
|
|
@@ -11,5 +13,13 @@ export declare function isIframeReadableStream(value: any): value is IIframeRead
|
|
|
11
13
|
/**
|
|
12
14
|
* Check if value is an IframeFileReadableStream (file stream)
|
|
13
15
|
*/
|
|
14
|
-
export declare function
|
|
16
|
+
export declare function isIframeFileReadableStream(value: any): value is IIframeFileReadableStream;
|
|
17
|
+
/**
|
|
18
|
+
* Check if value is an IframeWritableStream (includes IframeFileWritableStream)
|
|
19
|
+
*/
|
|
20
|
+
export declare function isIframeWritableStream(value: any): value is IframeWritableStream;
|
|
21
|
+
/**
|
|
22
|
+
* Check if value is an IframeFileWritableStream (file writable stream)
|
|
23
|
+
*/
|
|
24
|
+
export declare function isIframeFileWritableStream(value: any): value is IframeFileWritableStream;
|
|
15
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAGzD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAGzD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,EAA4B,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAE3E;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,qBAAqB,CAEjF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,yBAAyB,CAEzF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,oBAAoB,CAEhF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,wBAAwB,CAExF"}
|
package/library/stream/index.js
CHANGED
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
var _exportNames = {
|
|
8
8
|
isIframeReadableStream: true,
|
|
9
|
-
|
|
9
|
+
isIframeFileReadableStream: true,
|
|
10
|
+
isIframeWritableStream: true,
|
|
11
|
+
isIframeFileWritableStream: true,
|
|
10
12
|
IframeWritableStream: true,
|
|
11
13
|
IframeFileWritableStream: true,
|
|
12
14
|
IframeFileReadableStream: true,
|
|
@@ -43,8 +45,10 @@ Object.defineProperty(exports, "StreamMessageHandler", {
|
|
|
43
45
|
return _readableStream.StreamMessageHandler;
|
|
44
46
|
}
|
|
45
47
|
});
|
|
46
|
-
exports.
|
|
48
|
+
exports.isIframeFileReadableStream = isIframeFileReadableStream;
|
|
49
|
+
exports.isIframeFileWritableStream = isIframeFileWritableStream;
|
|
47
50
|
exports.isIframeReadableStream = isIframeReadableStream;
|
|
51
|
+
exports.isIframeWritableStream = isIframeWritableStream;
|
|
48
52
|
var _types = require("./types");
|
|
49
53
|
Object.keys(_types).forEach(function (key) {
|
|
50
54
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -78,6 +82,20 @@ function isIframeReadableStream(value) {
|
|
|
78
82
|
/**
|
|
79
83
|
* Check if value is an IframeFileReadableStream (file stream)
|
|
80
84
|
*/
|
|
81
|
-
function
|
|
85
|
+
function isIframeFileReadableStream(value) {
|
|
82
86
|
return value instanceof _fileStream.IframeFileReadableStream;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Check if value is an IframeWritableStream (includes IframeFileWritableStream)
|
|
91
|
+
*/
|
|
92
|
+
function isIframeWritableStream(value) {
|
|
93
|
+
return value instanceof _writableStream.IframeWritableStream || value instanceof _fileStream.IframeFileWritableStream;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Check if value is an IframeFileWritableStream (file writable stream)
|
|
98
|
+
*/
|
|
99
|
+
function isIframeFileWritableStream(value) {
|
|
100
|
+
return value instanceof _fileStream.IframeFileWritableStream;
|
|
83
101
|
}
|
|
@@ -78,8 +78,8 @@ export interface StreamBindContext {
|
|
|
78
78
|
targetOrigin: string;
|
|
79
79
|
/** secretKey */
|
|
80
80
|
secretKey?: string;
|
|
81
|
-
/** MessageChannel for sending messages
|
|
82
|
-
channel
|
|
81
|
+
/** MessageChannel for sending messages */
|
|
82
|
+
channel: MessageChannel;
|
|
83
83
|
/** Server instance ID (for server-side streams, used as creatorId) */
|
|
84
84
|
serverId?: string;
|
|
85
85
|
/** Client instance ID (for client-side streams, used as creatorId) */
|