request-iframe 0.0.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 +269 -0
- package/QUICKSTART.md +269 -0
- package/README.CN.md +1369 -0
- package/README.md +1016 -0
- package/library/__tests__/interceptors.test.ts +124 -0
- package/library/__tests__/requestIframe.test.ts +2216 -0
- package/library/__tests__/stream.test.ts +650 -0
- package/library/__tests__/utils.test.ts +433 -0
- package/library/api/client.d.ts +16 -0
- package/library/api/client.d.ts.map +1 -0
- package/library/api/client.js +72 -0
- package/library/api/server.d.ts +16 -0
- package/library/api/server.d.ts.map +1 -0
- package/library/api/server.js +44 -0
- package/library/constants/index.d.ts +209 -0
- package/library/constants/index.d.ts.map +1 -0
- package/library/constants/index.js +260 -0
- package/library/constants/messages.d.ts +80 -0
- package/library/constants/messages.d.ts.map +1 -0
- package/library/constants/messages.js +123 -0
- package/library/core/client.d.ts +99 -0
- package/library/core/client.d.ts.map +1 -0
- package/library/core/client.js +440 -0
- package/library/core/message-handler.d.ts +110 -0
- package/library/core/message-handler.d.ts.map +1 -0
- package/library/core/message-handler.js +320 -0
- package/library/core/request-response.d.ts +59 -0
- package/library/core/request-response.d.ts.map +1 -0
- package/library/core/request-response.js +337 -0
- package/library/core/request.d.ts +17 -0
- package/library/core/request.d.ts.map +1 -0
- package/library/core/request.js +34 -0
- package/library/core/response.d.ts +51 -0
- package/library/core/response.d.ts.map +1 -0
- package/library/core/response.js +323 -0
- package/library/core/server-base.d.ts +86 -0
- package/library/core/server-base.d.ts.map +1 -0
- package/library/core/server-base.js +257 -0
- package/library/core/server-client.d.ts +99 -0
- package/library/core/server-client.d.ts.map +1 -0
- package/library/core/server-client.js +256 -0
- package/library/core/server.d.ts +82 -0
- package/library/core/server.d.ts.map +1 -0
- package/library/core/server.js +338 -0
- package/library/index.d.ts +16 -0
- package/library/index.d.ts.map +1 -0
- package/library/index.js +211 -0
- package/library/interceptors/index.d.ts +41 -0
- package/library/interceptors/index.d.ts.map +1 -0
- package/library/interceptors/index.js +126 -0
- package/library/message/channel.d.ts +107 -0
- package/library/message/channel.d.ts.map +1 -0
- package/library/message/channel.js +184 -0
- package/library/message/dispatcher.d.ts +119 -0
- package/library/message/dispatcher.d.ts.map +1 -0
- package/library/message/dispatcher.js +249 -0
- package/library/message/index.d.ts +5 -0
- package/library/message/index.d.ts.map +1 -0
- package/library/message/index.js +25 -0
- package/library/stream/file-stream.d.ts +48 -0
- package/library/stream/file-stream.d.ts.map +1 -0
- package/library/stream/file-stream.js +240 -0
- package/library/stream/index.d.ts +15 -0
- package/library/stream/index.d.ts.map +1 -0
- package/library/stream/index.js +83 -0
- package/library/stream/readable-stream.d.ts +83 -0
- package/library/stream/readable-stream.d.ts.map +1 -0
- package/library/stream/readable-stream.js +249 -0
- package/library/stream/types.d.ts +165 -0
- package/library/stream/types.d.ts.map +1 -0
- package/library/stream/types.js +5 -0
- package/library/stream/writable-stream.d.ts +60 -0
- package/library/stream/writable-stream.d.ts.map +1 -0
- package/library/stream/writable-stream.js +348 -0
- package/library/types/index.d.ts +408 -0
- package/library/types/index.d.ts.map +1 -0
- package/library/types/index.js +5 -0
- package/library/utils/cache.d.ts +19 -0
- package/library/utils/cache.d.ts.map +1 -0
- package/library/utils/cache.js +83 -0
- package/library/utils/cookie.d.ts +117 -0
- package/library/utils/cookie.d.ts.map +1 -0
- package/library/utils/cookie.js +365 -0
- package/library/utils/debug.d.ts +11 -0
- package/library/utils/debug.d.ts.map +1 -0
- package/library/utils/debug.js +162 -0
- package/library/utils/index.d.ts +13 -0
- package/library/utils/index.d.ts.map +1 -0
- package/library/utils/index.js +132 -0
- package/library/utils/path-match.d.ts +17 -0
- package/library/utils/path-match.d.ts.map +1 -0
- package/library/utils/path-match.js +90 -0
- package/library/utils/protocol.d.ts +61 -0
- package/library/utils/protocol.d.ts.map +1 -0
- package/library/utils/protocol.js +169 -0
- package/package.json +58 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.symbol.description.js");
|
|
4
|
+
require("core-js/modules/es.array.from.js");
|
|
5
|
+
require("core-js/modules/es.array.iterator.js");
|
|
6
|
+
require("core-js/modules/es.array.slice.js");
|
|
7
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
exports.MessageDispatcher = void 0;
|
|
13
|
+
require("core-js/modules/es.array.index-of.js");
|
|
14
|
+
require("core-js/modules/es.array.sort.js");
|
|
15
|
+
require("core-js/modules/es.array.splice.js");
|
|
16
|
+
require("core-js/modules/es.regexp.constructor.js");
|
|
17
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
18
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
19
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
20
|
+
var _utils = require("../utils");
|
|
21
|
+
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; } } }; }
|
|
22
|
+
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; } }
|
|
23
|
+
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; }
|
|
24
|
+
/**
|
|
25
|
+
* Message handler function type
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Message type matcher
|
|
30
|
+
* - string: exact match message type
|
|
31
|
+
* - RegExp: regex match message type
|
|
32
|
+
* - function: custom match function
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Protocol version validator function
|
|
37
|
+
* @param version protocol version in message
|
|
38
|
+
* @returns true if version is compatible, false otherwise
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Message handler registration options
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Message handler entry
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* MessageDispatcher - Message dispatcher for client/server interaction
|
|
51
|
+
*
|
|
52
|
+
* Responsibilities:
|
|
53
|
+
* - Using MessageChannel for receiving and sending messages
|
|
54
|
+
* - Dispatching received messages to registered handlers
|
|
55
|
+
* - Managing handler registration/unregistration
|
|
56
|
+
* - Protocol version validation
|
|
57
|
+
*
|
|
58
|
+
* This is the high-level interface used by client and server implementations.
|
|
59
|
+
* It works with transport-agnostic MessageContext instead of transport-specific MessageEvent.
|
|
60
|
+
*/
|
|
61
|
+
class MessageDispatcher {
|
|
62
|
+
constructor(channel) {
|
|
63
|
+
/** Secret key for message isolation */
|
|
64
|
+
/** Channel type */
|
|
65
|
+
/** Underlying message channel */
|
|
66
|
+
/** Message handler list */
|
|
67
|
+
(0, _defineProperty2.default)(this, "handlers", []);
|
|
68
|
+
/** Reference count (for determining if can be destroyed when cached) */
|
|
69
|
+
(0, _defineProperty2.default)(this, "refCount", 0);
|
|
70
|
+
this.channel = channel;
|
|
71
|
+
this.secretKey = channel.secretKey;
|
|
72
|
+
this.type = channel.type;
|
|
73
|
+
|
|
74
|
+
// Create bound receiver callback
|
|
75
|
+
this.boundReceiver = (data, context) => {
|
|
76
|
+
this.dispatchMessage(data, context);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Add receiver callback to handle incoming messages
|
|
80
|
+
this.channel.addReceiver(this.boundReceiver);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ==================== Reference Counting ====================
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Increment reference count
|
|
87
|
+
*/
|
|
88
|
+
addRef() {
|
|
89
|
+
this.refCount++;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Decrement reference count
|
|
94
|
+
* @returns current reference count
|
|
95
|
+
*/
|
|
96
|
+
release() {
|
|
97
|
+
return --this.refCount;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get reference count
|
|
102
|
+
*/
|
|
103
|
+
getRefCount() {
|
|
104
|
+
return this.refCount;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ==================== Message Handling ====================
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Register message handler
|
|
111
|
+
* @param matcher message type matcher
|
|
112
|
+
* @param handler handler function
|
|
113
|
+
* @param options registration options (priority, version validation, etc.)
|
|
114
|
+
* @returns function to unregister
|
|
115
|
+
*/
|
|
116
|
+
registerHandler(matcher, handler, options) {
|
|
117
|
+
var _opts$priority;
|
|
118
|
+
var opts = typeof options === 'number' ? {
|
|
119
|
+
priority: options
|
|
120
|
+
} : options || {};
|
|
121
|
+
var entry = {
|
|
122
|
+
matcher,
|
|
123
|
+
handler,
|
|
124
|
+
priority: (_opts$priority = opts.priority) !== null && _opts$priority !== void 0 ? _opts$priority : 0,
|
|
125
|
+
versionValidator: opts.versionValidator,
|
|
126
|
+
onVersionError: opts.onVersionError
|
|
127
|
+
};
|
|
128
|
+
this.handlers.push(entry);
|
|
129
|
+
// Sort by priority in descending order
|
|
130
|
+
this.handlers.sort((a, b) => b.priority - a.priority);
|
|
131
|
+
return () => {
|
|
132
|
+
var index = this.handlers.indexOf(entry);
|
|
133
|
+
if (index >= 0) {
|
|
134
|
+
this.handlers.splice(index, 1);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Unregister message handler
|
|
141
|
+
*/
|
|
142
|
+
unregisterHandler(handler) {
|
|
143
|
+
var index = this.handlers.findIndex(entry => entry.handler === handler);
|
|
144
|
+
if (index >= 0) {
|
|
145
|
+
this.handlers.splice(index, 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Dispatch message to matching handlers
|
|
151
|
+
*/
|
|
152
|
+
dispatchMessage(data, context) {
|
|
153
|
+
var type = data.type;
|
|
154
|
+
var version = (0, _utils.getProtocolVersion)(data);
|
|
155
|
+
var _iterator = _createForOfIteratorHelper(this.handlers),
|
|
156
|
+
_step;
|
|
157
|
+
try {
|
|
158
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
159
|
+
var entry = _step.value;
|
|
160
|
+
if (this.matchType(type, entry.matcher)) {
|
|
161
|
+
// If handler specified version validation
|
|
162
|
+
if (entry.versionValidator && version !== undefined) {
|
|
163
|
+
if (!entry.versionValidator(version)) {
|
|
164
|
+
var _entry$onVersionError;
|
|
165
|
+
// Version incompatible, call error handler (if any)
|
|
166
|
+
(_entry$onVersionError = entry.onVersionError) === null || _entry$onVersionError === void 0 || _entry$onVersionError.call(entry, data, context, version);
|
|
167
|
+
continue; // Skip this handler, try other handlers
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
entry.handler(data, context);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
// Ignore handler exception, continue executing other handlers
|
|
174
|
+
console.error('[request-iframe] Handler error:', e);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
_iterator.e(err);
|
|
180
|
+
} finally {
|
|
181
|
+
_iterator.f();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Check if message type matches
|
|
187
|
+
*/
|
|
188
|
+
matchType(type, matcher) {
|
|
189
|
+
if (typeof matcher === 'string') {
|
|
190
|
+
return type === matcher;
|
|
191
|
+
}
|
|
192
|
+
if (matcher instanceof RegExp) {
|
|
193
|
+
return matcher.test(type);
|
|
194
|
+
}
|
|
195
|
+
if (typeof matcher === 'function') {
|
|
196
|
+
return matcher(type);
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ==================== Sending (Delegated to Channel) ====================
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Send raw message to target window
|
|
205
|
+
* @param target target window
|
|
206
|
+
* @param message message data (already formatted as PostMessageData)
|
|
207
|
+
* @param targetOrigin target origin (defaults to '*')
|
|
208
|
+
*/
|
|
209
|
+
send(target, message, targetOrigin = '*') {
|
|
210
|
+
this.channel.send(target, message, targetOrigin);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Send typed message to target window (creates PostMessageData automatically)
|
|
215
|
+
* @param target target window
|
|
216
|
+
* @param targetOrigin target origin
|
|
217
|
+
* @param type message type
|
|
218
|
+
* @param requestId request ID
|
|
219
|
+
* @param data additional data
|
|
220
|
+
*/
|
|
221
|
+
sendMessage(target, targetOrigin, type, requestId, data) {
|
|
222
|
+
this.channel.sendMessage(target, targetOrigin, type, requestId, data);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ==================== Utilities ====================
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Add path prefix
|
|
229
|
+
*/
|
|
230
|
+
prefixPath(path) {
|
|
231
|
+
return this.channel.prefixPath(path);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Get the underlying message channel
|
|
236
|
+
*/
|
|
237
|
+
getChannel() {
|
|
238
|
+
return this.channel;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Destroy dispatcher (clear handlers, but don't destroy channel as it may be shared)
|
|
243
|
+
*/
|
|
244
|
+
destroy() {
|
|
245
|
+
this.handlers.length = 0;
|
|
246
|
+
this.channel.removeReceiver(this.boundReceiver);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.MessageDispatcher = MessageDispatcher;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MessageChannel, ChannelType } from './channel';
|
|
2
|
+
export type { MessageContext, MessageReceiver } from './channel';
|
|
3
|
+
export { MessageDispatcher } from './dispatcher';
|
|
4
|
+
export type { MessageHandlerFn, MessageTypeMatcher, VersionValidator, HandlerOptions } from './dispatcher';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ChannelType", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _channel.ChannelType;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "MessageChannel", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _channel.MessageChannel;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "MessageDispatcher", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _dispatcher.MessageDispatcher;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _channel = require("./channel");
|
|
25
|
+
var _dispatcher = require("./dispatcher");
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IframeWritableStream } from './writable-stream';
|
|
2
|
+
import { IframeReadableStream, StreamMessageHandler } from './readable-stream';
|
|
3
|
+
import { FileWritableStreamOptions, FileReadableStreamOptions, IIframeFileReadableStream } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* IframeFileWritableStream - Server-side file writable stream
|
|
6
|
+
* Automatically handles Base64 encoding of file content
|
|
7
|
+
*/
|
|
8
|
+
export declare class IframeFileWritableStream extends IframeWritableStream {
|
|
9
|
+
readonly filename: string;
|
|
10
|
+
readonly mimeType: string;
|
|
11
|
+
readonly size?: number;
|
|
12
|
+
constructor(options: FileWritableStreamOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Override encode method to convert Uint8Array to Base64
|
|
15
|
+
*/
|
|
16
|
+
protected encodeData(data: any): string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* IframeFileReadableStream - Client-side file readable stream
|
|
20
|
+
* Automatically handles Base64 decoding of file content
|
|
21
|
+
*/
|
|
22
|
+
export declare class IframeFileReadableStream extends IframeReadableStream<Uint8Array> implements IIframeFileReadableStream {
|
|
23
|
+
readonly filename?: string;
|
|
24
|
+
readonly mimeType?: string;
|
|
25
|
+
readonly size?: number;
|
|
26
|
+
constructor(streamId: string, requestId: string, messageHandler: StreamMessageHandler, options?: FileReadableStreamOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Override decode method to convert Base64 to Uint8Array
|
|
29
|
+
*/
|
|
30
|
+
protected decodeData(data: any): Uint8Array;
|
|
31
|
+
/**
|
|
32
|
+
* Override merge method to merge all Uint8Array chunks
|
|
33
|
+
*/
|
|
34
|
+
protected mergeChunks(): Uint8Array;
|
|
35
|
+
/**
|
|
36
|
+
* Read as Blob
|
|
37
|
+
*/
|
|
38
|
+
readAsBlob(): Promise<Blob>;
|
|
39
|
+
/**
|
|
40
|
+
* Read as ArrayBuffer
|
|
41
|
+
*/
|
|
42
|
+
readAsArrayBuffer(): Promise<ArrayBuffer>;
|
|
43
|
+
/**
|
|
44
|
+
* Read as Data URL
|
|
45
|
+
*/
|
|
46
|
+
readAsDataURL(): Promise<string>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=file-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-stream.d.ts","sourceRoot":"","sources":["../../src/stream/file-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AA0BjB;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,oBAAoB;IAChE,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,yBAAyB;IAiBrD;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;CAcxC;AAED;;;GAGG;AACH,qBAAa,wBACX,SAAQ,oBAAoB,CAAC,UAAU,CACvC,YAAW,yBAAyB;IAEpC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAG5B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,oBAAoB,EACpC,OAAO,GAAE,yBAA8B;IAYzC;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,UAAU;IAa3C;;OAEG;IACH,SAAS,CAAC,WAAW,IAAI,UAAU;IAuBnC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOxC;;OAEG;IACU,iBAAiB,IAAI,OAAO,CAAC,WAAW,CAAC;IAQtD;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAK9C"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
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.object.get-own-property-descriptors.js");
|
|
7
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
8
|
+
require("core-js/modules/es.regexp.to-string.js");
|
|
9
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
10
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
11
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
exports.IframeFileWritableStream = exports.IframeFileReadableStream = void 0;
|
|
16
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
17
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
18
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
+
require("core-js/modules/es.array.iterator.js");
|
|
20
|
+
require("core-js/modules/es.array.reduce.js");
|
|
21
|
+
require("core-js/modules/es.array.slice.js");
|
|
22
|
+
require("core-js/modules/es.typed-array.uint8-array.js");
|
|
23
|
+
require("core-js/modules/es.typed-array.fill.js");
|
|
24
|
+
require("core-js/modules/es.typed-array.iterator.js");
|
|
25
|
+
require("core-js/modules/es.typed-array.set.js");
|
|
26
|
+
require("core-js/modules/es.typed-array.sort.js");
|
|
27
|
+
require("core-js/modules/es.typed-array.to-string.js");
|
|
28
|
+
var _writableStream = require("./writable-stream");
|
|
29
|
+
var _readableStream = require("./readable-stream");
|
|
30
|
+
var _constants = require("../constants");
|
|
31
|
+
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; } } }; }
|
|
32
|
+
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; } }
|
|
33
|
+
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; }
|
|
34
|
+
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; }
|
|
35
|
+
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; }
|
|
36
|
+
/**
|
|
37
|
+
* Convert Uint8Array to Base64 string
|
|
38
|
+
*/
|
|
39
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
40
|
+
var binary = '';
|
|
41
|
+
for (var i = 0; i < uint8Array.length; i++) {
|
|
42
|
+
binary += String.fromCharCode(uint8Array[i]);
|
|
43
|
+
}
|
|
44
|
+
return btoa(binary);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Convert Base64 string to Uint8Array
|
|
49
|
+
*/
|
|
50
|
+
function base64ToUint8Array(base64) {
|
|
51
|
+
var binary = atob(base64);
|
|
52
|
+
var uint8Array = new Uint8Array(binary.length);
|
|
53
|
+
for (var i = 0; i < binary.length; i++) {
|
|
54
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
55
|
+
}
|
|
56
|
+
return uint8Array;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* IframeFileWritableStream - Server-side file writable stream
|
|
61
|
+
* Automatically handles Base64 encoding of file content
|
|
62
|
+
*/
|
|
63
|
+
class IframeFileWritableStream extends _writableStream.IframeWritableStream {
|
|
64
|
+
constructor(options) {
|
|
65
|
+
super(_objectSpread(_objectSpread({}, options), {}, {
|
|
66
|
+
type: _constants.StreamType.FILE,
|
|
67
|
+
metadata: _objectSpread(_objectSpread({}, options.metadata), {}, {
|
|
68
|
+
filename: options.filename,
|
|
69
|
+
mimeType: options.mimeType || 'application/octet-stream',
|
|
70
|
+
size: options.size
|
|
71
|
+
})
|
|
72
|
+
}));
|
|
73
|
+
this.filename = options.filename;
|
|
74
|
+
this.mimeType = options.mimeType || 'application/octet-stream';
|
|
75
|
+
this.size = options.size;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Override encode method to convert Uint8Array to Base64
|
|
80
|
+
*/
|
|
81
|
+
encodeData(data) {
|
|
82
|
+
if (data instanceof Uint8Array) {
|
|
83
|
+
return uint8ArrayToBase64(data);
|
|
84
|
+
}
|
|
85
|
+
if (data instanceof ArrayBuffer) {
|
|
86
|
+
return uint8ArrayToBase64(new Uint8Array(data));
|
|
87
|
+
}
|
|
88
|
+
if (typeof data === 'string') {
|
|
89
|
+
// Already a base64 string
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
// Try to convert other types
|
|
93
|
+
return String(data);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* IframeFileReadableStream - Client-side file readable stream
|
|
99
|
+
* Automatically handles Base64 decoding of file content
|
|
100
|
+
*/
|
|
101
|
+
exports.IframeFileWritableStream = IframeFileWritableStream;
|
|
102
|
+
class IframeFileReadableStream extends _readableStream.IframeReadableStream {
|
|
103
|
+
constructor(streamId, requestId, messageHandler, options = {}) {
|
|
104
|
+
var _options$metadata, _options$metadata2, _options$metadata3;
|
|
105
|
+
super(streamId, requestId, messageHandler, _objectSpread(_objectSpread({}, options), {}, {
|
|
106
|
+
type: _constants.StreamType.FILE
|
|
107
|
+
}));
|
|
108
|
+
this.filename = options.filename || ((_options$metadata = options.metadata) === null || _options$metadata === void 0 ? void 0 : _options$metadata.filename);
|
|
109
|
+
this.mimeType = options.mimeType || ((_options$metadata2 = options.metadata) === null || _options$metadata2 === void 0 ? void 0 : _options$metadata2.mimeType);
|
|
110
|
+
this.size = options.size || ((_options$metadata3 = options.metadata) === null || _options$metadata3 === void 0 ? void 0 : _options$metadata3.size);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Override decode method to convert Base64 to Uint8Array
|
|
115
|
+
*/
|
|
116
|
+
decodeData(data) {
|
|
117
|
+
if (typeof data === 'string') {
|
|
118
|
+
return base64ToUint8Array(data);
|
|
119
|
+
}
|
|
120
|
+
if (data instanceof Uint8Array) {
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
if (data instanceof ArrayBuffer) {
|
|
124
|
+
return new Uint8Array(data);
|
|
125
|
+
}
|
|
126
|
+
return new Uint8Array();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Override merge method to merge all Uint8Array chunks
|
|
131
|
+
*/
|
|
132
|
+
mergeChunks() {
|
|
133
|
+
var chunks = this.chunks;
|
|
134
|
+
if (chunks.length === 0) {
|
|
135
|
+
return new Uint8Array();
|
|
136
|
+
}
|
|
137
|
+
if (chunks.length === 1) {
|
|
138
|
+
return chunks[0];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Calculate total length
|
|
142
|
+
var totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
143
|
+
var result = new Uint8Array(totalLength);
|
|
144
|
+
|
|
145
|
+
// Merge all chunks
|
|
146
|
+
var offset = 0;
|
|
147
|
+
var _iterator = _createForOfIteratorHelper(chunks),
|
|
148
|
+
_step;
|
|
149
|
+
try {
|
|
150
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
151
|
+
var chunk = _step.value;
|
|
152
|
+
result.set(chunk, offset);
|
|
153
|
+
offset += chunk.length;
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
_iterator.e(err);
|
|
157
|
+
} finally {
|
|
158
|
+
_iterator.f();
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Read as Blob
|
|
165
|
+
*/
|
|
166
|
+
readAsBlob() {
|
|
167
|
+
var _this = this;
|
|
168
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
169
|
+
var data, buffer;
|
|
170
|
+
return _regenerator.default.wrap(function (_context) {
|
|
171
|
+
while (1) switch (_context.prev = _context.next) {
|
|
172
|
+
case 0:
|
|
173
|
+
_context.next = 1;
|
|
174
|
+
return _this.read();
|
|
175
|
+
case 1:
|
|
176
|
+
data = _context.sent;
|
|
177
|
+
// Use slice to create a pure ArrayBuffer copy to avoid type issues
|
|
178
|
+
buffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
179
|
+
return _context.abrupt("return", new Blob([buffer], {
|
|
180
|
+
type: _this.mimeType || 'application/octet-stream'
|
|
181
|
+
}));
|
|
182
|
+
case 2:
|
|
183
|
+
case "end":
|
|
184
|
+
return _context.stop();
|
|
185
|
+
}
|
|
186
|
+
}, _callee);
|
|
187
|
+
}))();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Read as ArrayBuffer
|
|
192
|
+
*/
|
|
193
|
+
readAsArrayBuffer() {
|
|
194
|
+
var _this2 = this;
|
|
195
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
196
|
+
var data, buffer;
|
|
197
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
198
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
199
|
+
case 0:
|
|
200
|
+
_context2.next = 1;
|
|
201
|
+
return _this2.read();
|
|
202
|
+
case 1:
|
|
203
|
+
data = _context2.sent;
|
|
204
|
+
// Create a new ArrayBuffer copy
|
|
205
|
+
buffer = new ArrayBuffer(data.byteLength);
|
|
206
|
+
new Uint8Array(buffer).set(data);
|
|
207
|
+
return _context2.abrupt("return", buffer);
|
|
208
|
+
case 2:
|
|
209
|
+
case "end":
|
|
210
|
+
return _context2.stop();
|
|
211
|
+
}
|
|
212
|
+
}, _callee2);
|
|
213
|
+
}))();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Read as Data URL
|
|
218
|
+
*/
|
|
219
|
+
readAsDataURL() {
|
|
220
|
+
var _this3 = this;
|
|
221
|
+
return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
222
|
+
var data, base64;
|
|
223
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
224
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
225
|
+
case 0:
|
|
226
|
+
_context3.next = 1;
|
|
227
|
+
return _this3.read();
|
|
228
|
+
case 1:
|
|
229
|
+
data = _context3.sent;
|
|
230
|
+
base64 = uint8ArrayToBase64(data);
|
|
231
|
+
return _context3.abrupt("return", `data:${_this3.mimeType || 'application/octet-stream'};base64,${base64}`);
|
|
232
|
+
case 2:
|
|
233
|
+
case "end":
|
|
234
|
+
return _context3.stop();
|
|
235
|
+
}
|
|
236
|
+
}, _callee3);
|
|
237
|
+
}))();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.IframeFileReadableStream = IframeFileReadableStream;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { IframeWritableStream } from './writable-stream';
|
|
3
|
+
export { IframeFileWritableStream } from './file-stream';
|
|
4
|
+
export { IframeReadableStream, StreamMessageHandler } from './readable-stream';
|
|
5
|
+
export { IframeFileReadableStream } from './file-stream';
|
|
6
|
+
import { IIframeReadableStream, IIframeFileReadableStream } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Check if value is an IframeReadableStream
|
|
9
|
+
*/
|
|
10
|
+
export declare function isIframeReadableStream(value: any): value is IIframeReadableStream;
|
|
11
|
+
/**
|
|
12
|
+
* Check if value is an IframeFileReadableStream (file stream)
|
|
13
|
+
*/
|
|
14
|
+
export declare function isIframeFileStream(value: any): value is IIframeFileReadableStream;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAKzD,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,kBAAkB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,yBAAyB,CAEjF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
isIframeReadableStream: true,
|
|
9
|
+
isIframeFileStream: true,
|
|
10
|
+
IframeWritableStream: true,
|
|
11
|
+
IframeFileWritableStream: true,
|
|
12
|
+
IframeFileReadableStream: true,
|
|
13
|
+
IframeReadableStream: true,
|
|
14
|
+
StreamMessageHandler: true
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "IframeFileReadableStream", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function get() {
|
|
19
|
+
return _fileStream.IframeFileReadableStream;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "IframeFileWritableStream", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function get() {
|
|
25
|
+
return _fileStream.IframeFileWritableStream;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "IframeReadableStream", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function get() {
|
|
31
|
+
return _readableStream.IframeReadableStream;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "IframeWritableStream", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function get() {
|
|
37
|
+
return _writableStream.IframeWritableStream;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "StreamMessageHandler", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function get() {
|
|
43
|
+
return _readableStream.StreamMessageHandler;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
exports.isIframeFileStream = isIframeFileStream;
|
|
47
|
+
exports.isIframeReadableStream = isIframeReadableStream;
|
|
48
|
+
var _types = require("./types");
|
|
49
|
+
Object.keys(_types).forEach(function (key) {
|
|
50
|
+
if (key === "default" || key === "__esModule") return;
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
52
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
53
|
+
Object.defineProperty(exports, key, {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function get() {
|
|
56
|
+
return _types[key];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
var _writableStream = require("./writable-stream");
|
|
61
|
+
var _fileStream = require("./file-stream");
|
|
62
|
+
var _readableStream = require("./readable-stream");
|
|
63
|
+
// Type exports
|
|
64
|
+
|
|
65
|
+
// Writable stream (server-side)
|
|
66
|
+
|
|
67
|
+
// Readable stream (client-side)
|
|
68
|
+
|
|
69
|
+
// Type checking utility functions
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check if value is an IframeReadableStream
|
|
73
|
+
*/
|
|
74
|
+
function isIframeReadableStream(value) {
|
|
75
|
+
return value instanceof _readableStream.IframeReadableStream;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if value is an IframeFileReadableStream (file stream)
|
|
80
|
+
*/
|
|
81
|
+
function isIframeFileStream(value) {
|
|
82
|
+
return value instanceof _fileStream.IframeFileReadableStream;
|
|
83
|
+
}
|