@opra/core 0.31.7 → 0.31.9
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/cjs/http/helpers/multipart-helper.js +12 -6
- package/cjs/http/http-adapter-host.js +6 -6
- package/esm/http/helpers/multipart-helper.js +12 -6
- package/esm/http/http-adapter-host.js +6 -6
- package/package.json +2 -2
- package/types/http/helpers/multipart-helper.d.ts +2 -1
- package/types/http/http-adapter-host.d.ts +1 -1
|
@@ -5,9 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const formidable_1 = tslib_1.__importDefault(require("formidable"));
|
|
7
7
|
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
|
8
|
-
const noOp = () => void 0;
|
|
9
8
|
class MultipartIterator extends events_1.EventEmitter {
|
|
10
|
-
constructor(
|
|
9
|
+
constructor(options) {
|
|
11
10
|
super();
|
|
12
11
|
this._cancelled = false;
|
|
13
12
|
this._items = [];
|
|
@@ -36,7 +35,6 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
36
35
|
this._stack.push(item);
|
|
37
36
|
this.emit('item', item);
|
|
38
37
|
});
|
|
39
|
-
form.parse(incoming).catch(noOp);
|
|
40
38
|
}
|
|
41
39
|
get items() {
|
|
42
40
|
return this._items;
|
|
@@ -65,13 +63,16 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
65
63
|
}
|
|
66
64
|
cancel() {
|
|
67
65
|
this._cancelled = true;
|
|
68
|
-
this.
|
|
66
|
+
if (this._form.req)
|
|
67
|
+
this.resume();
|
|
69
68
|
}
|
|
70
69
|
resume() {
|
|
71
|
-
this._form.
|
|
70
|
+
if (this._form.req)
|
|
71
|
+
this._form.resume();
|
|
72
72
|
}
|
|
73
73
|
pause() {
|
|
74
|
-
this._form.
|
|
74
|
+
if (this._form.req)
|
|
75
|
+
this._form.pause();
|
|
75
76
|
}
|
|
76
77
|
async deleteFiles() {
|
|
77
78
|
const promises = [];
|
|
@@ -92,5 +93,10 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
92
93
|
});
|
|
93
94
|
return Promise.allSettled(promises);
|
|
94
95
|
}
|
|
96
|
+
static async create(incoming, options) {
|
|
97
|
+
const out = new MultipartIterator(options);
|
|
98
|
+
await out._form.parse(incoming);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
exports.MultipartIterator = MultipartIterator;
|
|
@@ -155,7 +155,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
155
155
|
return request;
|
|
156
156
|
}
|
|
157
157
|
if (resource instanceof common_1.Storage)
|
|
158
|
-
request = await this._parseRequestStorage(executionContext, resource, searchParams);
|
|
158
|
+
request = await this._parseRequestStorage(executionContext, resource, urlPath.slice(1), searchParams);
|
|
159
159
|
else if (urlPath.length === 1) { // Collection and Singleton resources should be last element in path
|
|
160
160
|
if (resource instanceof common_1.Collection)
|
|
161
161
|
request = await this._parseRequestCollection(executionContext, resource, urlPath, searchParams);
|
|
@@ -419,7 +419,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
419
419
|
message: `Singleton resource doesn't accept http "${incoming.method}" method`
|
|
420
420
|
});
|
|
421
421
|
}
|
|
422
|
-
async _parseRequestStorage(executionContext, resource, searchParams) {
|
|
422
|
+
async _parseRequestStorage(executionContext, resource, urlPath, searchParams) {
|
|
423
423
|
const { incoming } = executionContext.switchToHttp();
|
|
424
424
|
const contentId = incoming.headers['content-id'];
|
|
425
425
|
switch (incoming.method) {
|
|
@@ -432,7 +432,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
432
432
|
handler,
|
|
433
433
|
http: incoming,
|
|
434
434
|
contentId,
|
|
435
|
-
path:
|
|
435
|
+
path: urlPath.toString().substring(1),
|
|
436
436
|
params
|
|
437
437
|
});
|
|
438
438
|
}
|
|
@@ -445,7 +445,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
445
445
|
handler,
|
|
446
446
|
http: incoming,
|
|
447
447
|
contentId,
|
|
448
|
-
path:
|
|
448
|
+
path: urlPath.toString().substring(1),
|
|
449
449
|
params
|
|
450
450
|
});
|
|
451
451
|
}
|
|
@@ -453,7 +453,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
453
453
|
const { controller, endpoint, handler } = await this.getOperationHandler(resource, 'post');
|
|
454
454
|
const params = this.parseParameters(endpoint.parameters, searchParams);
|
|
455
455
|
await promises_1.default.mkdir(this._tempDir, { recursive: true });
|
|
456
|
-
const multipartIterator =
|
|
456
|
+
const multipartIterator = await multipart_helper_js_1.MultipartIterator.create(incoming, {
|
|
457
457
|
...endpoint.options,
|
|
458
458
|
filename: () => this.serviceName + '_p' + process.pid +
|
|
459
459
|
't' + String(Date.now()).substring(8) + 'r' + (0, common_1.uid)(12)
|
|
@@ -471,7 +471,7 @@ class HttpAdapterHost extends platform_adapter_host_js_1.PlatformAdapterHost {
|
|
|
471
471
|
http: incoming,
|
|
472
472
|
contentId,
|
|
473
473
|
parts: multipartIterator,
|
|
474
|
-
path:
|
|
474
|
+
path: urlPath.toString().substring(1),
|
|
475
475
|
params
|
|
476
476
|
});
|
|
477
477
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import formidable from 'formidable';
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
|
-
const noOp = () => void 0;
|
|
5
4
|
export class MultipartIterator extends EventEmitter {
|
|
6
|
-
constructor(
|
|
5
|
+
constructor(options) {
|
|
7
6
|
super();
|
|
8
7
|
this._cancelled = false;
|
|
9
8
|
this._items = [];
|
|
@@ -32,7 +31,6 @@ export class MultipartIterator extends EventEmitter {
|
|
|
32
31
|
this._stack.push(item);
|
|
33
32
|
this.emit('item', item);
|
|
34
33
|
});
|
|
35
|
-
form.parse(incoming).catch(noOp);
|
|
36
34
|
}
|
|
37
35
|
get items() {
|
|
38
36
|
return this._items;
|
|
@@ -61,13 +59,16 @@ export class MultipartIterator extends EventEmitter {
|
|
|
61
59
|
}
|
|
62
60
|
cancel() {
|
|
63
61
|
this._cancelled = true;
|
|
64
|
-
this.
|
|
62
|
+
if (this._form.req)
|
|
63
|
+
this.resume();
|
|
65
64
|
}
|
|
66
65
|
resume() {
|
|
67
|
-
this._form.
|
|
66
|
+
if (this._form.req)
|
|
67
|
+
this._form.resume();
|
|
68
68
|
}
|
|
69
69
|
pause() {
|
|
70
|
-
this._form.
|
|
70
|
+
if (this._form.req)
|
|
71
|
+
this._form.pause();
|
|
71
72
|
}
|
|
72
73
|
async deleteFiles() {
|
|
73
74
|
const promises = [];
|
|
@@ -88,4 +89,9 @@ export class MultipartIterator extends EventEmitter {
|
|
|
88
89
|
});
|
|
89
90
|
return Promise.allSettled(promises);
|
|
90
91
|
}
|
|
92
|
+
static async create(incoming, options) {
|
|
93
|
+
const out = new MultipartIterator(options);
|
|
94
|
+
await out._form.parse(incoming);
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
91
97
|
}
|
|
@@ -151,7 +151,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
151
151
|
return request;
|
|
152
152
|
}
|
|
153
153
|
if (resource instanceof Storage)
|
|
154
|
-
request = await this._parseRequestStorage(executionContext, resource, searchParams);
|
|
154
|
+
request = await this._parseRequestStorage(executionContext, resource, urlPath.slice(1), searchParams);
|
|
155
155
|
else if (urlPath.length === 1) { // Collection and Singleton resources should be last element in path
|
|
156
156
|
if (resource instanceof Collection)
|
|
157
157
|
request = await this._parseRequestCollection(executionContext, resource, urlPath, searchParams);
|
|
@@ -415,7 +415,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
415
415
|
message: `Singleton resource doesn't accept http "${incoming.method}" method`
|
|
416
416
|
});
|
|
417
417
|
}
|
|
418
|
-
async _parseRequestStorage(executionContext, resource, searchParams) {
|
|
418
|
+
async _parseRequestStorage(executionContext, resource, urlPath, searchParams) {
|
|
419
419
|
const { incoming } = executionContext.switchToHttp();
|
|
420
420
|
const contentId = incoming.headers['content-id'];
|
|
421
421
|
switch (incoming.method) {
|
|
@@ -428,7 +428,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
428
428
|
handler,
|
|
429
429
|
http: incoming,
|
|
430
430
|
contentId,
|
|
431
|
-
path:
|
|
431
|
+
path: urlPath.toString().substring(1),
|
|
432
432
|
params
|
|
433
433
|
});
|
|
434
434
|
}
|
|
@@ -441,7 +441,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
441
441
|
handler,
|
|
442
442
|
http: incoming,
|
|
443
443
|
contentId,
|
|
444
|
-
path:
|
|
444
|
+
path: urlPath.toString().substring(1),
|
|
445
445
|
params
|
|
446
446
|
});
|
|
447
447
|
}
|
|
@@ -449,7 +449,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
449
449
|
const { controller, endpoint, handler } = await this.getOperationHandler(resource, 'post');
|
|
450
450
|
const params = this.parseParameters(endpoint.parameters, searchParams);
|
|
451
451
|
await fs.mkdir(this._tempDir, { recursive: true });
|
|
452
|
-
const multipartIterator =
|
|
452
|
+
const multipartIterator = await MultipartIterator.create(incoming, {
|
|
453
453
|
...endpoint.options,
|
|
454
454
|
filename: () => this.serviceName + '_p' + process.pid +
|
|
455
455
|
't' + String(Date.now()).substring(8) + 'r' + uid(12)
|
|
@@ -467,7 +467,7 @@ export class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
467
467
|
http: incoming,
|
|
468
468
|
contentId,
|
|
469
469
|
parts: multipartIterator,
|
|
470
|
-
path:
|
|
470
|
+
path: urlPath.toString().substring(1),
|
|
471
471
|
params
|
|
472
472
|
});
|
|
473
473
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.9",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@browsery/type-is": "^0.6.3",
|
|
32
|
-
"@opra/common": "^0.31.
|
|
32
|
+
"@opra/common": "^0.31.9",
|
|
33
33
|
"accepts": "^1.3.8",
|
|
34
34
|
"content-disposition": "^0.5.4",
|
|
35
35
|
"content-type": "^1.0.5",
|
|
@@ -14,7 +14,7 @@ export declare class MultipartIterator extends EventEmitter {
|
|
|
14
14
|
protected _form: IncomingForm;
|
|
15
15
|
protected _items: MultipartItem[];
|
|
16
16
|
protected _stack: MultipartItem[];
|
|
17
|
-
constructor(
|
|
17
|
+
protected constructor(options?: formidable.Options);
|
|
18
18
|
get items(): MultipartItem[];
|
|
19
19
|
getNext(): Promise<MultipartItem | undefined>;
|
|
20
20
|
getAll(): Promise<MultipartItem[]>;
|
|
@@ -22,4 +22,5 @@ export declare class MultipartIterator extends EventEmitter {
|
|
|
22
22
|
resume(): void;
|
|
23
23
|
pause(): void;
|
|
24
24
|
deleteFiles(): Promise<PromiseSettledResult<any>[]>;
|
|
25
|
+
static create(incoming: HttpIncomingMessage, options?: formidable.Options): Promise<MultipartIterator>;
|
|
25
26
|
}
|
|
@@ -26,7 +26,7 @@ export declare abstract class HttpAdapterHost extends PlatformAdapterHost {
|
|
|
26
26
|
protected _parseRequestAction(executionContext: ExecutionContext, resource: Resource, urlPath: OpraURLPath, searchParams: URLSearchParams): Promise<RequestHost>;
|
|
27
27
|
protected _parseRequestCollection(executionContext: ExecutionContext, resource: Collection, urlPath: OpraURLPath, searchParams: URLSearchParams): Promise<RequestHost>;
|
|
28
28
|
protected _parseRequestSingleton(executionContext: ExecutionContext, resource: Singleton, urlPath: OpraURLPath, searchParams?: URLSearchParams): Promise<RequestHost>;
|
|
29
|
-
protected _parseRequestStorage(executionContext: ExecutionContext, resource: Storage, searchParams: URLSearchParams): Promise<RequestHost>;
|
|
29
|
+
protected _parseRequestStorage(executionContext: ExecutionContext, resource: Storage, urlPath: OpraURLPath, searchParams: URLSearchParams): Promise<RequestHost>;
|
|
30
30
|
protected parseParameters(paramDefs: Map<string, Parameter>, searchParams?: URLSearchParams): Record<string, any>;
|
|
31
31
|
protected executeRequest(context: RequestContext): Promise<void>;
|
|
32
32
|
sendResponse(context: RequestContext): Promise<void>;
|