request-iframe 0.1.1 → 0.2.1
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 +4 -2
- package/QUICKSTART.md +4 -2
- package/README.CN.md +129 -33
- package/README.md +116 -15
- package/cdn/request-iframe-react.umd.js +3354 -0
- package/cdn/request-iframe-react.umd.js.map +1 -0
- package/cdn/request-iframe-react.umd.min.js +2 -0
- package/cdn/request-iframe-react.umd.min.js.map +1 -0
- package/cdn/request-iframe.umd.js +19761 -0
- package/cdn/request-iframe.umd.js.map +1 -0
- package/cdn/request-iframe.umd.min.js +4 -0
- package/cdn/request-iframe.umd.min.js.map +1 -0
- package/esm/api/client.js +29 -21
- package/esm/api/endpoint.js +229 -0
- package/esm/api/server.js +16 -8
- package/esm/constants/debug.js +17 -0
- package/esm/constants/index.js +84 -67
- package/esm/constants/log.js +11 -0
- package/esm/constants/messages.js +3 -0
- package/esm/constants/warn-once.js +15 -0
- package/esm/endpoint/facade.js +390 -0
- package/esm/endpoint/heartbeat/heartbeat.js +60 -0
- package/esm/endpoint/heartbeat/ping.js +20 -0
- package/esm/endpoint/index.js +13 -0
- package/esm/endpoint/infra/hub.js +316 -0
- package/esm/endpoint/infra/inbox.js +232 -0
- package/esm/endpoint/infra/outbox.js +408 -0
- package/esm/endpoint/stream/dispatcher.js +58 -0
- package/esm/endpoint/stream/errors.js +27 -0
- package/esm/endpoint/stream/factory.js +76 -0
- package/esm/endpoint/stream/file-auto-resolve.js +34 -0
- package/esm/endpoint/stream/file-writable.js +105 -0
- package/esm/endpoint/stream/handler.js +26 -0
- package/esm/{core → impl}/client.js +240 -317
- package/esm/{core → impl}/response.js +113 -155
- package/esm/impl/server.js +568 -0
- package/esm/index.js +13 -6
- package/esm/message/ack.js +27 -0
- package/esm/message/channel-cache.js +108 -0
- package/esm/message/channel.js +90 -4
- package/esm/message/dispatcher.js +115 -75
- package/esm/stream/error.js +22 -0
- package/esm/stream/index.js +3 -1
- package/esm/stream/readable-stream.js +45 -9
- package/esm/stream/stream-core.js +7 -2
- package/esm/stream/writable-stream.js +97 -26
- package/esm/utils/blob.js +16 -0
- package/esm/utils/cache.js +25 -76
- package/esm/utils/content-type.js +81 -0
- package/esm/utils/debug.js +156 -179
- package/esm/utils/hooks.js +130 -0
- package/esm/utils/id.js +14 -0
- package/esm/utils/iframe.js +20 -0
- package/esm/utils/index.js +11 -163
- package/esm/utils/is.js +3 -0
- package/esm/utils/logger.js +55 -0
- package/esm/utils/promise.js +3 -0
- package/esm/utils/window.js +31 -0
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +30 -22
- package/library/api/endpoint.d.ts +23 -0
- package/library/api/endpoint.d.ts.map +1 -0
- package/library/api/endpoint.js +235 -0
- package/library/api/server.d.ts +4 -1
- package/library/api/server.d.ts.map +1 -1
- package/library/api/server.js +16 -8
- package/library/constants/debug.d.ts +18 -0
- package/library/constants/debug.d.ts.map +1 -0
- package/library/constants/debug.js +23 -0
- package/library/constants/index.d.ts +22 -2
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +110 -67
- package/library/constants/log.d.ts +12 -0
- package/library/constants/log.d.ts.map +1 -0
- package/library/constants/log.js +17 -0
- 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/constants/warn-once.d.ts +12 -0
- package/library/constants/warn-once.d.ts.map +1 -0
- package/library/constants/warn-once.js +22 -0
- package/library/endpoint/facade.d.ts +238 -0
- package/library/endpoint/facade.d.ts.map +1 -0
- package/library/endpoint/facade.js +398 -0
- package/library/endpoint/heartbeat/heartbeat.d.ts +34 -0
- package/library/endpoint/heartbeat/heartbeat.d.ts.map +1 -0
- package/library/endpoint/heartbeat/heartbeat.js +67 -0
- package/library/endpoint/heartbeat/ping.d.ts +18 -0
- package/library/endpoint/heartbeat/ping.d.ts.map +1 -0
- package/library/endpoint/heartbeat/ping.js +26 -0
- package/library/endpoint/index.d.ts +16 -0
- package/library/endpoint/index.d.ts.map +1 -0
- package/library/endpoint/index.js +114 -0
- package/library/endpoint/infra/hub.d.ts +170 -0
- package/library/endpoint/infra/hub.d.ts.map +1 -0
- package/library/endpoint/infra/hub.js +323 -0
- package/library/endpoint/infra/inbox.d.ts +73 -0
- package/library/endpoint/infra/inbox.d.ts.map +1 -0
- package/library/endpoint/infra/inbox.js +239 -0
- package/library/endpoint/infra/outbox.d.ts +149 -0
- package/library/endpoint/infra/outbox.d.ts.map +1 -0
- package/library/endpoint/infra/outbox.js +415 -0
- package/library/endpoint/stream/dispatcher.d.ts +33 -0
- package/library/endpoint/stream/dispatcher.d.ts.map +1 -0
- package/library/endpoint/stream/dispatcher.js +66 -0
- package/library/endpoint/stream/errors.d.ts +20 -0
- package/library/endpoint/stream/errors.d.ts.map +1 -0
- package/library/endpoint/stream/errors.js +32 -0
- package/library/endpoint/stream/factory.d.ts +44 -0
- package/library/endpoint/stream/factory.d.ts.map +1 -0
- package/library/endpoint/stream/factory.js +82 -0
- package/library/endpoint/stream/file-auto-resolve.d.ts +26 -0
- package/library/endpoint/stream/file-auto-resolve.d.ts.map +1 -0
- package/library/endpoint/stream/file-auto-resolve.js +41 -0
- package/library/endpoint/stream/file-writable.d.ts +33 -0
- package/library/endpoint/stream/file-writable.d.ts.map +1 -0
- package/library/endpoint/stream/file-writable.js +115 -0
- package/library/endpoint/stream/handler.d.ts +20 -0
- package/library/endpoint/stream/handler.d.ts.map +1 -0
- package/library/endpoint/stream/handler.js +32 -0
- package/library/{core → impl}/client.d.ts +16 -13
- package/library/impl/client.d.ts.map +1 -0
- package/library/{core → impl}/client.js +251 -330
- package/library/{core → impl}/request.d.ts.map +1 -1
- package/library/{core → impl}/response.d.ts +5 -10
- package/library/impl/response.d.ts.map +1 -0
- package/library/{core → impl}/response.js +113 -155
- package/library/{core → impl}/server.d.ts +22 -55
- package/library/impl/server.d.ts.map +1 -0
- package/library/impl/server.js +575 -0
- package/library/index.d.ts +13 -6
- package/library/index.d.ts.map +1 -1
- package/library/index.js +16 -16
- package/library/message/ack.d.ts +15 -0
- package/library/message/ack.d.ts.map +1 -0
- package/library/message/ack.js +33 -0
- package/library/message/channel-cache.d.ts +26 -0
- package/library/message/channel-cache.d.ts.map +1 -0
- package/library/message/channel-cache.js +115 -0
- package/library/message/channel.d.ts +53 -6
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/channel.js +94 -8
- package/library/message/dispatcher.d.ts +7 -0
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +116 -76
- package/library/stream/error.d.ts +24 -0
- package/library/stream/error.d.ts.map +1 -0
- package/library/stream/error.js +29 -0
- package/library/stream/index.d.ts +4 -1
- package/library/stream/index.d.ts.map +1 -1
- package/library/stream/index.js +7 -4
- package/library/stream/readable-stream.d.ts.map +1 -1
- package/library/stream/readable-stream.js +46 -10
- package/library/stream/stream-core.d.ts.map +1 -1
- package/library/stream/stream-core.js +6 -1
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +99 -28
- package/library/types/index.d.ts +15 -19
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/blob.d.ts +3 -0
- package/library/utils/blob.d.ts.map +1 -0
- package/library/utils/blob.js +22 -0
- package/library/utils/cache.d.ts +10 -20
- package/library/utils/cache.d.ts.map +1 -1
- package/library/utils/cache.js +25 -79
- package/library/utils/content-type.d.ts +13 -0
- package/library/utils/content-type.d.ts.map +1 -0
- package/library/utils/content-type.js +87 -0
- package/library/utils/debug.d.ts.map +1 -1
- package/library/utils/debug.js +155 -177
- package/library/utils/hooks.d.ts +30 -0
- package/library/utils/hooks.d.ts.map +1 -0
- package/library/utils/hooks.js +139 -0
- package/library/utils/id.d.ts +9 -0
- package/library/utils/id.d.ts.map +1 -0
- package/library/utils/id.js +21 -0
- package/library/utils/iframe.d.ts +5 -0
- package/library/utils/iframe.d.ts.map +1 -0
- package/library/utils/iframe.js +25 -0
- package/library/utils/index.d.ts +7 -34
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +58 -194
- package/library/utils/is.d.ts +2 -0
- package/library/utils/is.d.ts.map +1 -0
- package/library/utils/is.js +9 -0
- package/library/utils/logger.d.ts +13 -0
- package/library/utils/logger.d.ts.map +1 -0
- package/library/utils/logger.js +63 -0
- package/library/utils/promise.d.ts +2 -0
- package/library/utils/promise.d.ts.map +1 -0
- package/library/utils/promise.js +9 -0
- package/library/utils/window.d.ts +2 -0
- package/library/utils/window.d.ts.map +1 -0
- package/library/utils/window.js +38 -0
- package/package.json +49 -2
- package/react/package.json +2 -1
- package/esm/core/client-server.js +0 -294
- package/esm/core/server.js +0 -776
- package/library/core/client-server.d.ts +0 -97
- package/library/core/client-server.d.ts.map +0 -1
- package/library/core/client-server.js +0 -301
- package/library/core/client.d.ts.map +0 -1
- package/library/core/response.d.ts.map +0 -1
- package/library/core/server.d.ts.map +0 -1
- package/library/core/server.js +0 -781
- /package/esm/{core → impl}/request.js +0 -0
- /package/library/{core → impl}/request.d.ts +0 -0
- /package/library/{core → impl}/request.js +0 -0
|
@@ -18,9 +18,12 @@ require("core-js/modules/es.promise.finally.js");
|
|
|
18
18
|
require("core-js/modules/es.regexp.to-string.js");
|
|
19
19
|
require("core-js/modules/web.dom-collections.for-each.js");
|
|
20
20
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
21
|
-
var
|
|
21
|
+
var _protocol = require("../utils/protocol");
|
|
22
|
+
var _id = require("../utils/id");
|
|
23
|
+
var _is = require("../utils/is");
|
|
22
24
|
var _constants = require("../constants");
|
|
23
25
|
var _streamCore = require("./stream-core");
|
|
26
|
+
var _error = require("./error");
|
|
24
27
|
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; }
|
|
25
28
|
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; }
|
|
26
29
|
/**
|
|
@@ -74,14 +77,26 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
74
77
|
enqueue(item) {
|
|
75
78
|
var max = this.maxPendingChunks;
|
|
76
79
|
if (typeof max === 'number' && max > 0 && this.pendingQueue.length >= max) {
|
|
77
|
-
|
|
80
|
+
var _this$context;
|
|
81
|
+
throw new _error.RequestIframeStreamError({
|
|
82
|
+
message: (0, _constants.formatMessage)(_constants.Messages.STREAM_PENDING_QUEUE_OVERFLOW, max),
|
|
83
|
+
code: _constants.ErrorCode.STREAM_PENDING_QUEUE_OVERFLOW,
|
|
84
|
+
streamId: this.streamId,
|
|
85
|
+
requestId: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.requestId
|
|
86
|
+
});
|
|
78
87
|
}
|
|
79
88
|
var bytes = this.estimateChunkBytes(item.data);
|
|
80
89
|
var maxBytes = this.maxPendingBytes;
|
|
81
90
|
if (typeof maxBytes === 'number' && maxBytes > 0) {
|
|
82
91
|
var next = this.pendingBytes + bytes;
|
|
83
92
|
if (!Number.isFinite(next) || next > maxBytes) {
|
|
84
|
-
|
|
93
|
+
var _this$context2;
|
|
94
|
+
throw new _error.RequestIframeStreamError({
|
|
95
|
+
message: (0, _constants.formatMessage)(_constants.Messages.STREAM_PENDING_BYTES_OVERFLOW, maxBytes),
|
|
96
|
+
code: _constants.ErrorCode.STREAM_PENDING_BYTES_OVERFLOW,
|
|
97
|
+
streamId: this.streamId,
|
|
98
|
+
requestId: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.requestId
|
|
99
|
+
});
|
|
85
100
|
}
|
|
86
101
|
}
|
|
87
102
|
this.pendingQueue.push(_objectSpread(_objectSpread({}, item), {}, {
|
|
@@ -149,13 +164,13 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
149
164
|
this.context = context;
|
|
150
165
|
}
|
|
151
166
|
registerControlHandler() {
|
|
152
|
-
var _this$
|
|
153
|
-
if (!((_this$
|
|
167
|
+
var _this$context3;
|
|
168
|
+
if (!((_this$context3 = this.context) !== null && _this$context3 !== void 0 && _this$context3.registerStreamHandler)) return;
|
|
154
169
|
this.context.registerStreamHandler(this.streamId, this.handleControlMessage.bind(this));
|
|
155
170
|
}
|
|
156
171
|
unregisterControlHandler() {
|
|
157
|
-
var _this$
|
|
158
|
-
if (!((_this$
|
|
172
|
+
var _this$context4;
|
|
173
|
+
if (!((_this$context4 = this.context) !== null && _this$context4 !== void 0 && _this$context4.unregisterStreamHandler)) return;
|
|
159
174
|
this.context.unregisterStreamHandler(this.streamId);
|
|
160
175
|
}
|
|
161
176
|
handleControlMessage(data) {
|
|
@@ -194,11 +209,11 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
194
209
|
performHeartbeat() {
|
|
195
210
|
var _this = this;
|
|
196
211
|
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
197
|
-
var _this$
|
|
212
|
+
var _this$context5;
|
|
198
213
|
return _regenerator.default.wrap(function (_context) {
|
|
199
214
|
while (1) switch (_context.prev = _context.next) {
|
|
200
215
|
case 0:
|
|
201
|
-
if ((_this$
|
|
216
|
+
if ((_this$context5 = _this.context) !== null && _this$context5 !== void 0 && _this$context5.heartbeat) {
|
|
202
217
|
_context.next = 1;
|
|
203
218
|
break;
|
|
204
219
|
}
|
|
@@ -274,12 +289,16 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
274
289
|
sendMessage(type, data) {
|
|
275
290
|
var _this$context$serverI;
|
|
276
291
|
if (!this.context) {
|
|
277
|
-
throw new
|
|
292
|
+
throw new _error.RequestIframeStreamError({
|
|
293
|
+
message: _constants.Messages.STREAM_NOT_BOUND,
|
|
294
|
+
code: _constants.ErrorCode.STREAM_NOT_BOUND,
|
|
295
|
+
streamId: this.streamId
|
|
296
|
+
});
|
|
278
297
|
}
|
|
279
298
|
var isClientStream = this.context.clientId !== undefined && this.context.serverId === undefined;
|
|
280
299
|
var role = isClientStream ? _constants.MessageRole.CLIENT : _constants.MessageRole.SERVER;
|
|
281
300
|
var creatorId = (_this$context$serverI = this.context.serverId) !== null && _this$context$serverI !== void 0 ? _this$context$serverI : this.context.clientId;
|
|
282
|
-
var message = (0,
|
|
301
|
+
var message = (0, _protocol.createPostMessage)(type, this.context.requestId, {
|
|
283
302
|
secretKey: this.context.secretKey,
|
|
284
303
|
body: _objectSpread({
|
|
285
304
|
streamId: this.streamId
|
|
@@ -294,7 +313,12 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
294
313
|
this.clearExpireTimer();
|
|
295
314
|
// For most stream messages, if we cannot send, treat as a hard cancellation signal
|
|
296
315
|
// so callers can stop further processing immediately.
|
|
297
|
-
throw new
|
|
316
|
+
throw new _error.RequestIframeStreamError({
|
|
317
|
+
message: (0, _constants.formatMessage)(_constants.Messages.STREAM_CANCELLED, _constants.Messages.TARGET_WINDOW_CLOSED),
|
|
318
|
+
code: _constants.ErrorCode.TARGET_WINDOW_CLOSED,
|
|
319
|
+
streamId: this.streamId,
|
|
320
|
+
requestId: this.context.requestId
|
|
321
|
+
});
|
|
298
322
|
}
|
|
299
323
|
return true;
|
|
300
324
|
}
|
|
@@ -302,13 +326,13 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
302
326
|
if (this.ackReceiverRegistered) return;
|
|
303
327
|
if (!this.context) return;
|
|
304
328
|
var ch = this.context.channel;
|
|
305
|
-
if (
|
|
329
|
+
if (!(0, _is.isFunction)(ch.addReceiver) || !(0, _is.isFunction)(ch.removeReceiver)) return;
|
|
306
330
|
this.ackReceiver = (data, context) => {
|
|
307
331
|
if (!data || data.type !== _constants.MessageType.ACK) return;
|
|
308
332
|
var pending = this.ackWaiters.get(data.requestId);
|
|
309
333
|
if (!pending) return;
|
|
310
334
|
if (context && !context.handledBy) {
|
|
311
|
-
context.
|
|
335
|
+
context.markHandledBy(`stream:${this.streamId}`);
|
|
312
336
|
}
|
|
313
337
|
clearTimeout(pending.timeoutId);
|
|
314
338
|
this.ackWaiters.delete(data.requestId);
|
|
@@ -325,7 +349,7 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
325
349
|
this.ackWaiters.clear();
|
|
326
350
|
if (this.ackReceiverRegistered && this.ackReceiver && this.context) {
|
|
327
351
|
var ch = this.context.channel;
|
|
328
|
-
if (
|
|
352
|
+
if ((0, _is.isFunction)(ch.removeReceiver)) {
|
|
329
353
|
try {
|
|
330
354
|
ch.removeReceiver(this.ackReceiver);
|
|
331
355
|
} catch (_unused6) {
|
|
@@ -383,13 +407,22 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
383
407
|
_context3.next = 1;
|
|
384
408
|
break;
|
|
385
409
|
}
|
|
386
|
-
throw new
|
|
410
|
+
throw new _error.RequestIframeStreamError({
|
|
411
|
+
message: _constants.Messages.STREAM_NOT_BOUND,
|
|
412
|
+
code: _constants.ErrorCode.STREAM_NOT_BOUND,
|
|
413
|
+
streamId: _this3.streamId
|
|
414
|
+
});
|
|
387
415
|
case 1:
|
|
388
416
|
if (!(_this3._state !== _constants.StreamState.PENDING)) {
|
|
389
417
|
_context3.next = 2;
|
|
390
418
|
break;
|
|
391
419
|
}
|
|
392
|
-
throw new
|
|
420
|
+
throw new _error.RequestIframeStreamError({
|
|
421
|
+
message: _constants.Messages.STREAM_ALREADY_STARTED,
|
|
422
|
+
code: _constants.ErrorCode.STREAM_ALREADY_STARTED,
|
|
423
|
+
streamId: _this3.streamId,
|
|
424
|
+
requestId: _this3.context.requestId
|
|
425
|
+
});
|
|
393
426
|
case 2:
|
|
394
427
|
_this3.completionPromise = new Promise((resolve, reject) => {
|
|
395
428
|
_this3.resolveCompletion = resolve;
|
|
@@ -462,16 +495,34 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
462
495
|
write(data, doneOrOptions = false, options) {
|
|
463
496
|
var _opts$ackTimeout;
|
|
464
497
|
if (this.mode !== _constants.StreamMode.PUSH) {
|
|
465
|
-
|
|
498
|
+
var _this$context6;
|
|
499
|
+
throw new _error.RequestIframeStreamError({
|
|
500
|
+
message: _constants.Messages.STREAM_WRITE_ONLY_IN_PUSH_MODE,
|
|
501
|
+
code: _constants.ErrorCode.STREAM_WRITE_ONLY_IN_PUSH_MODE,
|
|
502
|
+
streamId: this.streamId,
|
|
503
|
+
requestId: (_this$context6 = this.context) === null || _this$context6 === void 0 ? void 0 : _this$context6.requestId
|
|
504
|
+
});
|
|
466
505
|
}
|
|
467
506
|
if (this._state === _constants.StreamState.PENDING) {
|
|
507
|
+
var _this$context7;
|
|
468
508
|
/**
|
|
469
509
|
* In push mode, users must call start() first so STREAM_START is sent and binding is complete.
|
|
470
510
|
*/
|
|
471
|
-
throw new
|
|
511
|
+
throw new _error.RequestIframeStreamError({
|
|
512
|
+
message: _constants.Messages.STREAM_NOT_BOUND,
|
|
513
|
+
code: _constants.ErrorCode.STREAM_NOT_BOUND,
|
|
514
|
+
streamId: this.streamId,
|
|
515
|
+
requestId: (_this$context7 = this.context) === null || _this$context7 === void 0 ? void 0 : _this$context7.requestId
|
|
516
|
+
});
|
|
472
517
|
}
|
|
473
518
|
if (this._state !== _constants.StreamState.STREAMING) {
|
|
474
|
-
|
|
519
|
+
var _this$context8;
|
|
520
|
+
throw new _error.RequestIframeStreamError({
|
|
521
|
+
message: _constants.Messages.STREAM_ENDED,
|
|
522
|
+
code: _constants.ErrorCode.STREAM_ENDED,
|
|
523
|
+
streamId: this.streamId,
|
|
524
|
+
requestId: (_this$context8 = this.context) === null || _this$context8 === void 0 ? void 0 : _this$context8.requestId
|
|
525
|
+
});
|
|
475
526
|
}
|
|
476
527
|
var done = typeof doneOrOptions === 'boolean' ? doneOrOptions : false;
|
|
477
528
|
var opts = typeof doneOrOptions === 'object' ? doneOrOptions : options;
|
|
@@ -491,7 +542,7 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
491
542
|
return;
|
|
492
543
|
}
|
|
493
544
|
return new Promise(resolve => {
|
|
494
|
-
var ackRequestId = (0,
|
|
545
|
+
var ackRequestId = (0, _id.generateRequestId)();
|
|
495
546
|
this.enqueue({
|
|
496
547
|
data,
|
|
497
548
|
done,
|
|
@@ -658,13 +709,17 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
658
709
|
sendData(data, done = false, options) {
|
|
659
710
|
var _this$context$serverI2, _options$requestId;
|
|
660
711
|
if (!this.context) {
|
|
661
|
-
throw new
|
|
712
|
+
throw new _error.RequestIframeStreamError({
|
|
713
|
+
message: _constants.Messages.STREAM_NOT_BOUND,
|
|
714
|
+
code: _constants.ErrorCode.STREAM_NOT_BOUND,
|
|
715
|
+
streamId: this.streamId
|
|
716
|
+
});
|
|
662
717
|
}
|
|
663
718
|
var seq = this.seq++;
|
|
664
719
|
var isClientStream = this.context.clientId !== undefined && this.context.serverId === undefined;
|
|
665
720
|
var role = isClientStream ? _constants.MessageRole.CLIENT : _constants.MessageRole.SERVER;
|
|
666
721
|
var creatorId = (_this$context$serverI2 = this.context.serverId) !== null && _this$context$serverI2 !== void 0 ? _this$context$serverI2 : this.context.clientId;
|
|
667
|
-
var message = (0,
|
|
722
|
+
var message = (0, _protocol.createPostMessage)(_constants.MessageType.STREAM_DATA, (_options$requestId = options === null || options === void 0 ? void 0 : options.requestId) !== null && _options$requestId !== void 0 ? _options$requestId : this.context.requestId, {
|
|
668
723
|
secretKey: this.context.secretKey,
|
|
669
724
|
requireAck: options === null || options === void 0 ? void 0 : options.requireAck,
|
|
670
725
|
/**
|
|
@@ -690,7 +745,12 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
690
745
|
if (!ok) {
|
|
691
746
|
this._state = _constants.StreamState.CANCELLED;
|
|
692
747
|
this.clearExpireTimer();
|
|
693
|
-
throw new
|
|
748
|
+
throw new _error.RequestIframeStreamError({
|
|
749
|
+
message: (0, _constants.formatMessage)(_constants.Messages.STREAM_CANCELLED, _constants.Messages.TARGET_WINDOW_CLOSED),
|
|
750
|
+
code: _constants.ErrorCode.TARGET_WINDOW_CLOSED,
|
|
751
|
+
streamId: this.streamId,
|
|
752
|
+
requestId: this.context.requestId
|
|
753
|
+
});
|
|
694
754
|
}
|
|
695
755
|
this.emit(_constants.StreamEvent.SEND, {
|
|
696
756
|
seq,
|
|
@@ -726,7 +786,7 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
726
786
|
this.sendData(item.data, item.done);
|
|
727
787
|
}
|
|
728
788
|
} catch (e) {
|
|
729
|
-
var _this$rejectCompletio;
|
|
789
|
+
var _this$rejectCompletio, _this$context9;
|
|
730
790
|
// send failure treated as cancellation
|
|
731
791
|
this._state = _constants.StreamState.CANCELLED;
|
|
732
792
|
this.clearExpireTimer();
|
|
@@ -735,7 +795,13 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
735
795
|
this.pendingQueue.length = 0;
|
|
736
796
|
this.pendingBytes = 0;
|
|
737
797
|
this.cleanupAckWaiters();
|
|
738
|
-
(_this$rejectCompletio = this.rejectCompletion) === null || _this$rejectCompletio === void 0 || _this$rejectCompletio.call(this, e instanceof Error ? e : new
|
|
798
|
+
(_this$rejectCompletio = this.rejectCompletion) === null || _this$rejectCompletio === void 0 || _this$rejectCompletio.call(this, e instanceof Error ? e : new _error.RequestIframeStreamError({
|
|
799
|
+
message: String(e),
|
|
800
|
+
code: _constants.ErrorCode.STREAM_ERROR,
|
|
801
|
+
streamId: this.streamId,
|
|
802
|
+
requestId: (_this$context9 = this.context) === null || _this$context9 === void 0 ? void 0 : _this$context9.requestId,
|
|
803
|
+
cause: e
|
|
804
|
+
}));
|
|
739
805
|
throw e;
|
|
740
806
|
}
|
|
741
807
|
if (item.done) {
|
|
@@ -778,7 +844,7 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
778
844
|
* Send error
|
|
779
845
|
*/
|
|
780
846
|
error(message) {
|
|
781
|
-
var _this$resolveCompleti2;
|
|
847
|
+
var _this$context0, _this$resolveCompleti2;
|
|
782
848
|
if (this._state !== _constants.StreamState.STREAMING) return;
|
|
783
849
|
this._state = _constants.StreamState.ERROR;
|
|
784
850
|
this.clearExpireTimer();
|
|
@@ -790,7 +856,12 @@ class IframeWritableStream extends _streamCore.IframeStreamCore {
|
|
|
790
856
|
error: message
|
|
791
857
|
});
|
|
792
858
|
this.emit(_constants.StreamEvent.ERROR, {
|
|
793
|
-
error: new
|
|
859
|
+
error: new _error.RequestIframeStreamError({
|
|
860
|
+
message,
|
|
861
|
+
code: _constants.ErrorCode.STREAM_ERROR,
|
|
862
|
+
streamId: this.streamId,
|
|
863
|
+
requestId: (_this$context0 = this.context) === null || _this$context0 === void 0 ? void 0 : _this$context0.requestId
|
|
864
|
+
})
|
|
794
865
|
});
|
|
795
866
|
this.emit(_constants.StreamEvent.STATE, {
|
|
796
867
|
state: this._state
|
package/library/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MessageRoleValue } from '../constants';
|
|
2
|
+
import type { LogLevelValue } from '../constants';
|
|
2
3
|
/**
|
|
3
4
|
* Request default configuration
|
|
4
5
|
* Can be set when creating requestIframeClient, and can be overridden on each request
|
|
@@ -146,7 +147,7 @@ export interface PostMessageData {
|
|
|
146
147
|
/**
|
|
147
148
|
* Protocol version identifier
|
|
148
149
|
* - Used to identify request-iframe framework messages
|
|
149
|
-
* - The value represents the protocol version number
|
|
150
|
+
* - The value represents the protocol version number
|
|
150
151
|
* - Future version upgrades can use this field for compatibility handling
|
|
151
152
|
*/
|
|
152
153
|
__requestIframe__: number;
|
|
@@ -159,7 +160,7 @@ export interface PostMessageData {
|
|
|
159
160
|
/** Message isolation key (used to isolate different businesses/instances) */
|
|
160
161
|
secretKey?: string;
|
|
161
162
|
/** Message type */
|
|
162
|
-
type: 'request' | 'ack' | 'async' | 'response' | 'error' | 'ping' | 'pong' | 'stream_start' | 'stream_data' | 'stream_end' | 'stream_error' | 'stream_cancel' | 'stream_pull'
|
|
163
|
+
type: 'request' | 'ack' | 'async' | 'response' | 'error' | 'ping' | 'pong' | 'stream_start' | 'stream_data' | 'stream_end' | 'stream_error' | 'stream_cancel' | 'stream_pull';
|
|
163
164
|
/** Request ID */
|
|
164
165
|
requestId: string;
|
|
165
166
|
/** Request path */
|
|
@@ -425,21 +426,6 @@ export interface RequestIframeClient {
|
|
|
425
426
|
/** Destroy client (close and release resources) */
|
|
426
427
|
destroy(): void;
|
|
427
428
|
}
|
|
428
|
-
/**
|
|
429
|
-
* Client server interface (used on client side, handles responses only)
|
|
430
|
-
*/
|
|
431
|
-
export interface RequestIframeClientServer {
|
|
432
|
-
/** Destroy server (remove message listener) */
|
|
433
|
-
destroy(): void;
|
|
434
|
-
/** Internal method: listen to low-level events */
|
|
435
|
-
_on(event: ServerEventName, fn: (payload: any) => void): void;
|
|
436
|
-
/** Internal method: unsubscribe from low-level events */
|
|
437
|
-
_off(event: ServerEventName, fn?: (payload: any) => void): void;
|
|
438
|
-
/** Internal method: for client to register pending Promise for response */
|
|
439
|
-
_registerPendingRequest(requestId: string, resolve: (data: PostMessageData) => void, reject: (error: Error) => void, origin?: string, originValidator?: OriginValidator): void;
|
|
440
|
-
/** Internal method: for client to cancel waiting */
|
|
441
|
-
_unregisterPendingRequest(requestId: string): void;
|
|
442
|
-
}
|
|
443
429
|
/**
|
|
444
430
|
* Server interface (used on server side, handles requests and responses)
|
|
445
431
|
*/
|
|
@@ -470,6 +456,16 @@ export interface RequestIframeServer {
|
|
|
470
456
|
/** Destroy server (close and release resources) */
|
|
471
457
|
destroy(): void;
|
|
472
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Log level (used by built-in logger and trace option).
|
|
461
|
+
*/
|
|
462
|
+
export type RequestIframeLogLevel = LogLevelValue;
|
|
463
|
+
/**
|
|
464
|
+
* Trace option:
|
|
465
|
+
* - boolean: enable/disable trace (true => 'trace')
|
|
466
|
+
* - level: explicitly set a log level
|
|
467
|
+
*/
|
|
468
|
+
export type RequestIframeTraceOption = boolean | RequestIframeLogLevel;
|
|
473
469
|
/**
|
|
474
470
|
* requestIframeClient entry options
|
|
475
471
|
*/
|
|
@@ -499,7 +495,7 @@ export interface RequestIframeClientOptions extends RequestDefaults {
|
|
|
499
495
|
* Whether to enable trace mode.
|
|
500
496
|
* If true, logs will be printed at various points such as before and after requests.
|
|
501
497
|
*/
|
|
502
|
-
trace?:
|
|
498
|
+
trace?: RequestIframeTraceOption;
|
|
503
499
|
/**
|
|
504
500
|
* Initial request headers.
|
|
505
501
|
* Values can be static strings/arrays or functions that dynamically generate headers based on request config.
|
|
@@ -532,7 +528,7 @@ export interface RequestIframeServerOptions extends Pick<RequestDefaults, 'ackTi
|
|
|
532
528
|
* Whether to enable trace mode.
|
|
533
529
|
* If true, logs will be printed at various points such as before and after requests, server receive/respond, etc.
|
|
534
530
|
*/
|
|
535
|
-
trace?:
|
|
531
|
+
trace?: RequestIframeTraceOption;
|
|
536
532
|
/**
|
|
537
533
|
* Allowed origins for incoming messages (request/ping/received/stream, etc.).
|
|
538
534
|
* This is a best-practice security control for production usage.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;GAGG;AACH,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Aa,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,qBAAqB,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,eAAe;IACjE;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B;;;OAGG;IACH,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,wBAAwB,CAAC;IACjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CAWpB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC;IACrF;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,KAAK,CAAC,EAAE,wBAAwB,CAAC;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B;;;OAGG;IACH,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAC;CAWzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/utils/blob.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAWxD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.blobToBase64 = blobToBase64;
|
|
7
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
|
+
require("core-js/modules/es.promise.js");
|
|
9
|
+
require("core-js/modules/es.string.includes.js");
|
|
10
|
+
/** Convert Blob to base64 string */
|
|
11
|
+
function blobToBase64(blob) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
var reader = new FileReader();
|
|
14
|
+
reader.onloadend = () => {
|
|
15
|
+
var result = reader.result;
|
|
16
|
+
var base64 = result.includes(',') ? result.split(',')[1] : result;
|
|
17
|
+
resolve(base64);
|
|
18
|
+
};
|
|
19
|
+
reader.onerror = reject;
|
|
20
|
+
reader.readAsDataURL(blob);
|
|
21
|
+
});
|
|
22
|
+
}
|
package/library/utils/cache.d.ts
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import { MessageChannel, ChannelType } from '../message';
|
|
2
1
|
import { RequestIframeServer } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Get or create MessageChannel instance
|
|
5
|
-
* - Within the same window, only one channel is created per type + secretKey combination
|
|
6
|
-
* - Uses reference counting to manage lifecycle
|
|
7
|
-
* @param secretKey secret key for message isolation
|
|
8
|
-
* @param type channel type (defaults to postMessage)
|
|
9
|
-
*/
|
|
10
|
-
export declare function getOrCreateMessageChannel(secretKey?: string, type?: ChannelType): MessageChannel;
|
|
11
|
-
/**
|
|
12
|
-
* Release MessageChannel reference
|
|
13
|
-
* - When reference count reaches 0, destroy channel and remove from cache
|
|
14
|
-
*/
|
|
15
|
-
export declare function releaseMessageChannel(channel: MessageChannel): void;
|
|
16
|
-
/**
|
|
17
|
-
* Clear all MessageChannel cache (mainly for testing)
|
|
18
|
-
*/
|
|
19
|
-
export declare function clearMessageChannelCache(): void;
|
|
20
2
|
/**
|
|
21
3
|
* Get cached server instance or null
|
|
22
4
|
* @param secretKey secret key for message isolation
|
|
@@ -37,7 +19,15 @@ export declare function cacheServer(server: RequestIframeServer, secretKey?: str
|
|
|
37
19
|
*/
|
|
38
20
|
export declare function removeCachedServer(secretKey?: string, id?: string): void;
|
|
39
21
|
/**
|
|
40
|
-
* Clear
|
|
22
|
+
* Clear server cache (mainly for testing).
|
|
23
|
+
*
|
|
24
|
+
* - No args: clear all cached servers
|
|
25
|
+
* - With secretKey: only clear servers under that secretKey
|
|
26
|
+
* - With { secretKey, id }: only clear the specified server instance
|
|
27
|
+
* - With { id }: clear the specified id across all secretKeys
|
|
41
28
|
*/
|
|
42
|
-
export declare function clearServerCache(
|
|
29
|
+
export declare function clearServerCache(arg?: string | {
|
|
30
|
+
secretKey?: string;
|
|
31
|
+
id?: string;
|
|
32
|
+
}): void;
|
|
43
33
|
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AA0B/C;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,CAAC,EAAE,MAAM,GACV,mBAAmB,GAAG,IAAI,CAM5B;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,mBAAmB,EAC3B,SAAS,CAAC,EAAE,MAAM,EAClB,EAAE,CAAC,EAAE,MAAM,GACV,IAAI,CAMN;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAMxE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAmBzF"}
|
package/library/utils/cache.js
CHANGED
|
@@ -4,94 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.cacheServer = cacheServer;
|
|
7
|
-
exports.clearMessageChannelCache = clearMessageChannelCache;
|
|
8
7
|
exports.clearServerCache = clearServerCache;
|
|
9
8
|
exports.getCachedServer = getCachedServer;
|
|
10
|
-
exports.getOrCreateMessageChannel = getOrCreateMessageChannel;
|
|
11
|
-
exports.releaseMessageChannel = releaseMessageChannel;
|
|
12
9
|
exports.removeCachedServer = removeCachedServer;
|
|
13
10
|
require("core-js/modules/es.array.iterator.js");
|
|
14
11
|
require("core-js/modules/es.map.js");
|
|
12
|
+
require("core-js/modules/es.string.ends-with.js");
|
|
13
|
+
require("core-js/modules/es.string.starts-with.js");
|
|
15
14
|
require("core-js/modules/web.dom-collections.for-each.js");
|
|
16
15
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
17
|
-
var _message = require("../message");
|
|
18
|
-
/**
|
|
19
|
-
* Global cache Symbol (used to store MessageChannel instance cache on window)
|
|
20
|
-
* Using Symbol.for() ensures multiple library copies share the same cache, avoiding multiple instance creation
|
|
21
|
-
*/
|
|
22
|
-
var MESSAGE_CHANNEL_CACHE_SYMBOL = Symbol.for('__requestIframeMessageChannelCache__');
|
|
23
|
-
|
|
24
16
|
/**
|
|
25
17
|
* Global cache Symbol for server instances
|
|
26
18
|
* Using Symbol.for() ensures multiple library copies share the same cache
|
|
27
19
|
*/
|
|
28
20
|
var SERVER_CACHE_SYMBOL = Symbol.for('__requestIframeServerCache__');
|
|
29
21
|
|
|
30
|
-
/**
|
|
31
|
-
* Get the MessageChannel cache from window
|
|
32
|
-
*/
|
|
33
|
-
function getChannelCacheForWindow(win) {
|
|
34
|
-
if (!(MESSAGE_CHANNEL_CACHE_SYMBOL in win)) {
|
|
35
|
-
win[MESSAGE_CHANNEL_CACHE_SYMBOL] = new Map();
|
|
36
|
-
}
|
|
37
|
-
return win[MESSAGE_CHANNEL_CACHE_SYMBOL];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Generate cache key
|
|
42
|
-
* Cache key format: "type:secretKey" or "type:" when no secretKey
|
|
43
|
-
* Different channel types use separate cache entries
|
|
44
|
-
*/
|
|
45
|
-
function getCacheKey(type, secretKey) {
|
|
46
|
-
return `${type}:${secretKey !== null && secretKey !== void 0 ? secretKey : ''}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Get or create MessageChannel instance
|
|
51
|
-
* - Within the same window, only one channel is created per type + secretKey combination
|
|
52
|
-
* - Uses reference counting to manage lifecycle
|
|
53
|
-
* @param secretKey secret key for message isolation
|
|
54
|
-
* @param type channel type (defaults to postMessage)
|
|
55
|
-
*/
|
|
56
|
-
function getOrCreateMessageChannel(secretKey, type = _message.ChannelType.POST_MESSAGE) {
|
|
57
|
-
var cache = getChannelCacheForWindow(window);
|
|
58
|
-
var key = getCacheKey(type, secretKey);
|
|
59
|
-
var channel = cache.get(key);
|
|
60
|
-
if (!channel) {
|
|
61
|
-
channel = new _message.MessageChannel(secretKey, type);
|
|
62
|
-
cache.set(key, channel);
|
|
63
|
-
}
|
|
64
|
-
channel.addRef();
|
|
65
|
-
return channel;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Release MessageChannel reference
|
|
70
|
-
* - When reference count reaches 0, destroy channel and remove from cache
|
|
71
|
-
*/
|
|
72
|
-
function releaseMessageChannel(channel) {
|
|
73
|
-
var refCount = channel.release();
|
|
74
|
-
if (refCount <= 0) {
|
|
75
|
-
var cache = getChannelCacheForWindow(window);
|
|
76
|
-
var key = getCacheKey(channel.type, channel.secretKey);
|
|
77
|
-
if (cache.get(key) === channel) {
|
|
78
|
-
cache.delete(key);
|
|
79
|
-
channel.destroy();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Clear all MessageChannel cache (mainly for testing)
|
|
86
|
-
*/
|
|
87
|
-
function clearMessageChannelCache() {
|
|
88
|
-
var cache = getChannelCacheForWindow(window);
|
|
89
|
-
cache.forEach(channel => {
|
|
90
|
-
channel.destroy();
|
|
91
|
-
});
|
|
92
|
-
cache.clear();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
22
|
/**
|
|
96
23
|
* Get the server cache from window
|
|
97
24
|
*/
|
|
@@ -148,12 +75,31 @@ function removeCachedServer(secretKey, id) {
|
|
|
148
75
|
}
|
|
149
76
|
|
|
150
77
|
/**
|
|
151
|
-
* Clear
|
|
78
|
+
* Clear server cache (mainly for testing).
|
|
79
|
+
*
|
|
80
|
+
* - No args: clear all cached servers
|
|
81
|
+
* - With secretKey: only clear servers under that secretKey
|
|
82
|
+
* - With { secretKey, id }: only clear the specified server instance
|
|
83
|
+
* - With { id }: clear the specified id across all secretKeys
|
|
152
84
|
*/
|
|
153
|
-
function clearServerCache() {
|
|
85
|
+
function clearServerCache(arg) {
|
|
154
86
|
var cache = getServerCacheForWindow(window);
|
|
155
|
-
|
|
87
|
+
if (!arg) {
|
|
88
|
+
cache.forEach(server => {
|
|
89
|
+
server.destroy();
|
|
90
|
+
});
|
|
91
|
+
cache.clear();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
var params = typeof arg === 'string' ? {
|
|
95
|
+
secretKey: arg
|
|
96
|
+
} : arg;
|
|
97
|
+
var prefix = typeof params.secretKey === 'string' ? `${params.secretKey}:` : undefined;
|
|
98
|
+
var suffix = typeof params.id === 'string' ? `:${params.id}` : undefined;
|
|
99
|
+
cache.forEach((server, key) => {
|
|
100
|
+
if (prefix && !key.startsWith(prefix)) return;
|
|
101
|
+
if (suffix && !key.endsWith(suffix)) return;
|
|
102
|
+
cache.delete(key);
|
|
156
103
|
server.destroy();
|
|
157
104
|
});
|
|
158
|
-
cache.clear();
|
|
159
105
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect Content-Type based on data type
|
|
3
|
+
* @param data The data to detect Content-Type for
|
|
4
|
+
* @param options Options for detection
|
|
5
|
+
* @param options.checkStream Whether to check for IframeWritableStream (default: false)
|
|
6
|
+
* @param options.isIframeWritableStream Optional function to check if data is a stream (required if checkStream is true)
|
|
7
|
+
* @returns The detected Content-Type, or null if Content-Type should not be auto-set
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectContentType(data: any, options?: {
|
|
10
|
+
checkStream?: boolean;
|
|
11
|
+
isIframeWritableStream?: (value: any) => boolean;
|
|
12
|
+
}): string | null;
|
|
13
|
+
//# sourceMappingURL=content-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/utils/content-type.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAA;CAAE,GACpF,MAAM,GAAG,IAAI,CAoEf"}
|