request-iframe 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/QUICKSTART.CN.md +33 -11
  2. package/QUICKSTART.md +33 -11
  3. package/README.CN.md +157 -44
  4. package/README.md +159 -41
  5. package/cdn/request-iframe.umd.js +4814 -4026
  6. package/cdn/request-iframe.umd.js.map +1 -1
  7. package/cdn/request-iframe.umd.min.js +2 -2
  8. package/cdn/request-iframe.umd.min.js.map +1 -1
  9. package/esm/api/client.js +45 -22
  10. package/esm/api/endpoint.js +30 -13
  11. package/esm/api/server.js +22 -13
  12. package/esm/constants/warn-once.js +7 -1
  13. package/esm/endpoint/index.js +1 -2
  14. package/esm/endpoint/infra/inbox.js +5 -4
  15. package/esm/endpoint/infra/outbox.js +8 -8
  16. package/esm/endpoint/stream/file-auto-resolve.js +9 -8
  17. package/esm/impl/client.js +3 -2
  18. package/esm/impl/response.js +4 -2
  19. package/esm/impl/server.js +8 -6
  20. package/esm/message/channel.js +15 -3
  21. package/esm/message/dispatcher.js +27 -0
  22. package/esm/stream/file-stream.js +311 -72
  23. package/esm/stream/writable-stream.js +21 -4
  24. package/esm/utils/blob.js +17 -0
  25. package/esm/utils/debug-lazy.js +76 -0
  26. package/esm/utils/logger.js +33 -1
  27. package/esm/utils/strict-mode.js +85 -0
  28. package/esm/utils/warn-once.js +30 -0
  29. package/esm/utils/warnings.js +47 -0
  30. package/library/api/client.d.ts.map +1 -1
  31. package/library/api/client.js +45 -22
  32. package/library/api/endpoint.d.ts.map +1 -1
  33. package/library/api/endpoint.js +30 -13
  34. package/library/api/server.d.ts.map +1 -1
  35. package/library/api/server.js +22 -13
  36. package/library/constants/warn-once.d.ts +6 -0
  37. package/library/constants/warn-once.d.ts.map +1 -1
  38. package/library/constants/warn-once.js +7 -1
  39. package/library/endpoint/index.d.ts +0 -1
  40. package/library/endpoint/index.d.ts.map +1 -1
  41. package/library/endpoint/index.js +1 -8
  42. package/library/endpoint/infra/inbox.d.ts.map +1 -1
  43. package/library/endpoint/infra/inbox.js +4 -3
  44. package/library/endpoint/infra/outbox.d.ts +2 -0
  45. package/library/endpoint/infra/outbox.d.ts.map +1 -1
  46. package/library/endpoint/infra/outbox.js +7 -7
  47. package/library/endpoint/stream/file-auto-resolve.d.ts +1 -1
  48. package/library/endpoint/stream/file-auto-resolve.d.ts.map +1 -1
  49. package/library/endpoint/stream/file-auto-resolve.js +8 -8
  50. package/library/impl/client.d.ts +2 -0
  51. package/library/impl/client.d.ts.map +1 -1
  52. package/library/impl/client.js +3 -2
  53. package/library/impl/response.d.ts.map +1 -1
  54. package/library/impl/response.js +4 -2
  55. package/library/impl/server.d.ts.map +1 -1
  56. package/library/impl/server.js +7 -5
  57. package/library/message/channel.d.ts +2 -2
  58. package/library/message/channel.d.ts.map +1 -1
  59. package/library/message/channel.js +15 -3
  60. package/library/message/dispatcher.d.ts.map +1 -1
  61. package/library/message/dispatcher.js +27 -0
  62. package/library/stream/file-stream.d.ts +70 -5
  63. package/library/stream/file-stream.d.ts.map +1 -1
  64. package/library/stream/file-stream.js +310 -70
  65. package/library/stream/types.d.ts +2 -0
  66. package/library/stream/types.d.ts.map +1 -1
  67. package/library/stream/writable-stream.d.ts.map +1 -1
  68. package/library/stream/writable-stream.js +21 -4
  69. package/library/types/index.d.ts +38 -0
  70. package/library/types/index.d.ts.map +1 -1
  71. package/library/utils/blob.d.ts +7 -0
  72. package/library/utils/blob.d.ts.map +1 -1
  73. package/library/utils/blob.js +18 -0
  74. package/library/utils/debug-lazy.d.ts +26 -0
  75. package/library/utils/debug-lazy.d.ts.map +1 -0
  76. package/library/utils/debug-lazy.js +85 -0
  77. package/library/utils/logger.d.ts +20 -0
  78. package/library/utils/logger.d.ts.map +1 -1
  79. package/library/utils/logger.js +34 -1
  80. package/library/utils/strict-mode.d.ts +37 -0
  81. package/library/utils/strict-mode.d.ts.map +1 -0
  82. package/library/utils/strict-mode.js +94 -0
  83. package/library/utils/warn-once.d.ts +9 -0
  84. package/library/utils/warn-once.d.ts.map +1 -0
  85. package/library/utils/warn-once.js +36 -0
  86. package/library/utils/warnings.d.ts +48 -0
  87. package/library/utils/warnings.d.ts.map +1 -0
  88. package/library/utils/warnings.js +54 -0
  89. package/package.json +1 -1
  90. package/esm/endpoint/stream/file-writable.js +0 -105
  91. package/library/endpoint/stream/file-writable.d.ts +0 -33
  92. package/library/endpoint/stream/file-writable.d.ts.map +0 -1
  93. package/library/endpoint/stream/file-writable.js +0 -115
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "request-iframe",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Communicate with iframes like sending HTTP requests",
5
5
  "main": "library/index.js",
6
6
  "module": "esm/index.js",
@@ -1,105 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import "core-js/modules/es.promise.js";
4
- import { blobToBase64 } from '../../utils/blob';
5
-
6
- /**
7
- * Endpoint Stream integration layer (`src/endpoint/stream`)
8
- *
9
- * This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
10
- * - Endpoint-side File/Blob -> IframeFileWritableStream adaptation (for sendFile / res.sendFile)
11
- * - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
12
- *
13
- * Create an IframeFileWritableStream from content.
14
- *
15
- * Shared by:
16
- * - client: sendFile(...) -> sendStream(...)
17
- * - server response: res.sendFile(...) -> sendStream(...)
18
- */
19
- export function createIframeFileWritableStreamFromContent(_x) {
20
- return _createIframeFileWritableStreamFromContent.apply(this, arguments);
21
- }
22
- function _createIframeFileWritableStreamFromContent() {
23
- _createIframeFileWritableStreamFromContent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
24
- var _params$chunked, _params$autoResolve;
25
- var _yield$import, IframeFileWritableStream, mimeType, fileName, t, fileContent, streamFileName, stream, _t;
26
- return _regeneratorRuntime.wrap(function (_context2) {
27
- while (1) switch (_context2.prev = _context2.next) {
28
- case 0:
29
- _context2.next = 1;
30
- return import('../../stream');
31
- case 1:
32
- _yield$import = _context2.sent;
33
- IframeFileWritableStream = _yield$import.IframeFileWritableStream;
34
- mimeType = params.mimeType || params.defaultMimeType || 'application/octet-stream';
35
- fileName = params.fileName;
36
- try {
37
- if (typeof File !== 'undefined' && params.content instanceof File) {
38
- mimeType = params.content.type || mimeType;
39
- fileName = fileName || params.content.name;
40
- }
41
- } catch (_unused) {
42
- /** ignore */
43
- }
44
- try {
45
- if (!fileName && typeof Blob !== 'undefined' && params.content instanceof Blob) {
46
- t = params.content.type;
47
- if (t) mimeType = t;
48
- }
49
- } catch (_unused2) {
50
- /** ignore */
51
- }
52
- if (!(typeof params.content === 'string')) {
53
- _context2.next = 2;
54
- break;
55
- }
56
- _t = btoa(unescape(encodeURIComponent(params.content)));
57
- _context2.next = 4;
58
- break;
59
- case 2:
60
- _context2.next = 3;
61
- return blobToBase64(params.content);
62
- case 3:
63
- _t = _context2.sent;
64
- case 4:
65
- fileContent = _t;
66
- streamFileName = fileName || params.defaultFileName || 'file';
67
- stream = new IframeFileWritableStream({
68
- filename: streamFileName,
69
- mimeType,
70
- chunked: (_params$chunked = params.chunked) !== null && _params$chunked !== void 0 ? _params$chunked : false,
71
- autoResolve: (_params$autoResolve = params.autoResolve) !== null && _params$autoResolve !== void 0 ? _params$autoResolve : true,
72
- next: function () {
73
- var _next = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
74
- return _regeneratorRuntime.wrap(function (_context) {
75
- while (1) switch (_context.prev = _context.next) {
76
- case 0:
77
- return _context.abrupt("return", {
78
- data: fileContent,
79
- done: true
80
- });
81
- case 1:
82
- case "end":
83
- return _context.stop();
84
- }
85
- }, _callee);
86
- }));
87
- function next() {
88
- return _next.apply(this, arguments);
89
- }
90
- return next;
91
- }()
92
- });
93
- return _context2.abrupt("return", {
94
- stream,
95
- fileName,
96
- mimeType
97
- });
98
- case 5:
99
- case "end":
100
- return _context2.stop();
101
- }
102
- }, _callee2);
103
- }));
104
- return _createIframeFileWritableStreamFromContent.apply(this, arguments);
105
- }
@@ -1,33 +0,0 @@
1
- import type { IframeFileWritableStream } from '../../stream';
2
- /**
3
- * Endpoint Stream integration layer (`src/endpoint/stream`)
4
- *
5
- * This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
6
- * - Endpoint-side File/Blob -> IframeFileWritableStream adaptation (for sendFile / res.sendFile)
7
- * - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
8
- *
9
- * Create an IframeFileWritableStream from content.
10
- *
11
- * Shared by:
12
- * - client: sendFile(...) -> sendStream(...)
13
- * - server response: res.sendFile(...) -> sendStream(...)
14
- */
15
- export declare function createIframeFileWritableStreamFromContent(params: {
16
- content: string | Blob | File;
17
- fileName?: string;
18
- mimeType?: string;
19
- /** default: false (file is sent in one chunk) */
20
- chunked?: boolean;
21
- /** default: true (receiver may auto-resolve) */
22
- autoResolve?: boolean;
23
- /** stream filename fallback when fileName cannot be inferred */
24
- defaultFileName?: string;
25
- /** mimeType fallback when mimeType cannot be inferred */
26
- defaultMimeType?: string;
27
- }): Promise<{
28
- stream: IframeFileWritableStream;
29
- /** inferred filename (may be undefined if content is not File and fileName not provided) */
30
- fileName?: string;
31
- mimeType: string;
32
- }>;
33
- //# sourceMappingURL=file-writable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-writable.d.ts","sourceRoot":"","sources":["../../../src/endpoint/stream/file-writable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAG7D;;;;;;;;;;;;GAYG;AACH,wBAAsB,yCAAyC,CAAC,MAAM,EAAE;IACtE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,wBAAwB,CAAC;IACjC,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC,CA0CD"}
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createIframeFileWritableStreamFromContent = createIframeFileWritableStreamFromContent;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- require("core-js/modules/es.array.iterator.js");
10
- require("core-js/modules/es.promise.js");
11
- require("core-js/modules/es.weak-map.js");
12
- require("core-js/modules/web.dom-collections.iterator.js");
13
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
- var _blob = require("../../utils/blob");
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
16
- /**
17
- * Endpoint Stream integration layer (`src/endpoint/stream`)
18
- *
19
- * This directory integrates postMessage `stream_*` messages with the stream object system in `src/stream`:
20
- * - Endpoint-side File/Blob -> IframeFileWritableStream adaptation (for sendFile / res.sendFile)
21
- * - Does NOT implement the stream protocol itself (protocol lives in `src/stream`)
22
- *
23
- * Create an IframeFileWritableStream from content.
24
- *
25
- * Shared by:
26
- * - client: sendFile(...) -> sendStream(...)
27
- * - server response: res.sendFile(...) -> sendStream(...)
28
- */
29
- function createIframeFileWritableStreamFromContent(_x) {
30
- return _createIframeFileWritableStreamFromContent.apply(this, arguments);
31
- }
32
- function _createIframeFileWritableStreamFromContent() {
33
- _createIframeFileWritableStreamFromContent = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(params) {
34
- var _params$chunked, _params$autoResolve;
35
- var _yield$import, IframeFileWritableStream, mimeType, fileName, t, fileContent, streamFileName, stream, _t;
36
- return _regenerator.default.wrap(function (_context2) {
37
- while (1) switch (_context2.prev = _context2.next) {
38
- case 0:
39
- _context2.next = 1;
40
- return Promise.resolve().then(() => _interopRequireWildcard(require('../../stream')));
41
- case 1:
42
- _yield$import = _context2.sent;
43
- IframeFileWritableStream = _yield$import.IframeFileWritableStream;
44
- mimeType = params.mimeType || params.defaultMimeType || 'application/octet-stream';
45
- fileName = params.fileName;
46
- try {
47
- if (typeof File !== 'undefined' && params.content instanceof File) {
48
- mimeType = params.content.type || mimeType;
49
- fileName = fileName || params.content.name;
50
- }
51
- } catch (_unused) {
52
- /** ignore */
53
- }
54
- try {
55
- if (!fileName && typeof Blob !== 'undefined' && params.content instanceof Blob) {
56
- t = params.content.type;
57
- if (t) mimeType = t;
58
- }
59
- } catch (_unused2) {
60
- /** ignore */
61
- }
62
- if (!(typeof params.content === 'string')) {
63
- _context2.next = 2;
64
- break;
65
- }
66
- _t = btoa(unescape(encodeURIComponent(params.content)));
67
- _context2.next = 4;
68
- break;
69
- case 2:
70
- _context2.next = 3;
71
- return (0, _blob.blobToBase64)(params.content);
72
- case 3:
73
- _t = _context2.sent;
74
- case 4:
75
- fileContent = _t;
76
- streamFileName = fileName || params.defaultFileName || 'file';
77
- stream = new IframeFileWritableStream({
78
- filename: streamFileName,
79
- mimeType,
80
- chunked: (_params$chunked = params.chunked) !== null && _params$chunked !== void 0 ? _params$chunked : false,
81
- autoResolve: (_params$autoResolve = params.autoResolve) !== null && _params$autoResolve !== void 0 ? _params$autoResolve : true,
82
- next: function () {
83
- var _next = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
84
- return _regenerator.default.wrap(function (_context) {
85
- while (1) switch (_context.prev = _context.next) {
86
- case 0:
87
- return _context.abrupt("return", {
88
- data: fileContent,
89
- done: true
90
- });
91
- case 1:
92
- case "end":
93
- return _context.stop();
94
- }
95
- }, _callee);
96
- }));
97
- function next() {
98
- return _next.apply(this, arguments);
99
- }
100
- return next;
101
- }()
102
- });
103
- return _context2.abrupt("return", {
104
- stream,
105
- fileName,
106
- mimeType
107
- });
108
- case 5:
109
- case "end":
110
- return _context2.stop();
111
- }
112
- }, _callee2);
113
- }));
114
- return _createIframeFileWritableStreamFromContent.apply(this, arguments);
115
- }