@moostjs/event-http 0.2.2 → 0.2.4
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/dist/index.cjs +20 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +21 -5
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,19 @@ function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
function createProvideRegistry(...args) {
|
|
32
|
+
const provide = {};
|
|
33
|
+
for (const a of args) {
|
|
34
|
+
const [type, fn] = a;
|
|
35
|
+
const key = typeof type === 'string' ? type : Symbol.for(type);
|
|
36
|
+
provide[key] = {
|
|
37
|
+
fn,
|
|
38
|
+
resolved: false,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return provide;
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
class MoostHttp {
|
|
32
45
|
constructor(httpApp) {
|
|
33
46
|
this.pathBuilders = {};
|
|
@@ -50,6 +63,9 @@ class MoostHttp {
|
|
|
50
63
|
listen(...args) {
|
|
51
64
|
return this.httpApp.listen(...args);
|
|
52
65
|
}
|
|
66
|
+
getProvideRegistry() {
|
|
67
|
+
return createProvideRegistry([eventHttp.WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()]);
|
|
68
|
+
}
|
|
53
69
|
bindHandler(opts) {
|
|
54
70
|
let fn;
|
|
55
71
|
for (const handler of opts.handlers) {
|
|
@@ -233,7 +249,7 @@ function useBody() {
|
|
|
233
249
|
return JSON.parse(v);
|
|
234
250
|
}
|
|
235
251
|
catch (e) {
|
|
236
|
-
throw new eventHttp.
|
|
252
|
+
throw new eventHttp.HttpError(400, e.message);
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
function textParser(v) {
|
|
@@ -242,7 +258,7 @@ function useBody() {
|
|
|
242
258
|
function formDataParser(v) {
|
|
243
259
|
const boundary = '--' + (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
|
|
244
260
|
if (!boundary)
|
|
245
|
-
throw new eventHttp.
|
|
261
|
+
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
|
|
246
262
|
const parts = v.trim().split(boundary);
|
|
247
263
|
const result = {};
|
|
248
264
|
let key = '';
|
|
@@ -273,13 +289,13 @@ function useBody() {
|
|
|
273
289
|
if (line.toLowerCase().startsWith('content-disposition: form-data;')) {
|
|
274
290
|
key = (/name=([^;]+)/.exec(line) || [])[1];
|
|
275
291
|
if (!key)
|
|
276
|
-
throw new eventHttp.
|
|
292
|
+
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
|
|
277
293
|
continue;
|
|
278
294
|
}
|
|
279
295
|
if (line.toLowerCase().startsWith('content-type:')) {
|
|
280
296
|
partContentType = (/content-type:\s?([^;]+)/i.exec(line) || [])[1];
|
|
281
297
|
if (!partContentType)
|
|
282
|
-
throw new eventHttp.
|
|
298
|
+
throw new eventHttp.HttpError(eventHttp.EHttpStatusCode.BadRequest, 'Could not read content-type: ' + line);
|
|
283
299
|
continue;
|
|
284
300
|
}
|
|
285
301
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ServerResponse } from 'http';
|
|
|
5
5
|
import { TMoostAdapter } from 'moost';
|
|
6
6
|
import { TMoostAdapterOptions } from 'moost';
|
|
7
7
|
import { TProstoRouterPathBuilder } from '@prostojs/router';
|
|
8
|
+
import { TProvideRegistry } from '@prostojs/infact';
|
|
8
9
|
import { TWooksHttpOptions } from '@wooksjs/event-http';
|
|
9
10
|
import { WooksHttp } from '@wooksjs/event-http';
|
|
10
11
|
|
|
@@ -102,6 +103,7 @@ export declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
|
|
|
102
103
|
DELETE?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
|
|
103
104
|
};
|
|
104
105
|
};
|
|
106
|
+
getProvideRegistry(): TProvideRegistry;
|
|
105
107
|
bindHandler<T extends object = object>(opts: TMoostAdapterOptions<THttpHandlerMeta, T>): void | Promise<void>;
|
|
106
108
|
}
|
|
107
109
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WooksHttp, createHttpApp, useHttpContext, useRequest, useHeaders,
|
|
1
|
+
import { WooksHttp, createHttpApp, useHttpContext, useRequest, useHeaders, HttpError, EHttpStatusCode, WooksURLSearchParams, useStatus, useSetHeader, useSetCookie, useAuthorization, useCookies, useSearchParams, useResponse } from '@wooksjs/event-http';
|
|
2
2
|
import { getMoostMate, Resolve } from 'moost';
|
|
3
3
|
|
|
4
4
|
/******************************************************************************
|
|
@@ -26,6 +26,19 @@ function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function createProvideRegistry(...args) {
|
|
30
|
+
const provide = {};
|
|
31
|
+
for (const a of args) {
|
|
32
|
+
const [type, fn] = a;
|
|
33
|
+
const key = typeof type === 'string' ? type : Symbol.for(type);
|
|
34
|
+
provide[key] = {
|
|
35
|
+
fn,
|
|
36
|
+
resolved: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return provide;
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
class MoostHttp {
|
|
30
43
|
constructor(httpApp) {
|
|
31
44
|
this.pathBuilders = {};
|
|
@@ -48,6 +61,9 @@ class MoostHttp {
|
|
|
48
61
|
listen(...args) {
|
|
49
62
|
return this.httpApp.listen(...args);
|
|
50
63
|
}
|
|
64
|
+
getProvideRegistry() {
|
|
65
|
+
return createProvideRegistry([WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()]);
|
|
66
|
+
}
|
|
51
67
|
bindHandler(opts) {
|
|
52
68
|
let fn;
|
|
53
69
|
for (const handler of opts.handlers) {
|
|
@@ -231,7 +247,7 @@ function useBody() {
|
|
|
231
247
|
return JSON.parse(v);
|
|
232
248
|
}
|
|
233
249
|
catch (e) {
|
|
234
|
-
throw new
|
|
250
|
+
throw new HttpError(400, e.message);
|
|
235
251
|
}
|
|
236
252
|
}
|
|
237
253
|
function textParser(v) {
|
|
@@ -240,7 +256,7 @@ function useBody() {
|
|
|
240
256
|
function formDataParser(v) {
|
|
241
257
|
const boundary = '--' + (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
|
|
242
258
|
if (!boundary)
|
|
243
|
-
throw new
|
|
259
|
+
throw new HttpError(EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
|
|
244
260
|
const parts = v.trim().split(boundary);
|
|
245
261
|
const result = {};
|
|
246
262
|
let key = '';
|
|
@@ -271,13 +287,13 @@ function useBody() {
|
|
|
271
287
|
if (line.toLowerCase().startsWith('content-disposition: form-data;')) {
|
|
272
288
|
key = (/name=([^;]+)/.exec(line) || [])[1];
|
|
273
289
|
if (!key)
|
|
274
|
-
throw new
|
|
290
|
+
throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
|
|
275
291
|
continue;
|
|
276
292
|
}
|
|
277
293
|
if (line.toLowerCase().startsWith('content-type:')) {
|
|
278
294
|
partContentType = (/content-type:\s?([^;]+)/i.exec(line) || [])[1];
|
|
279
295
|
if (!partContentType)
|
|
280
|
-
throw new
|
|
296
|
+
throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read content-type: ' + line);
|
|
281
297
|
continue;
|
|
282
298
|
}
|
|
283
299
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-http",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "@moostjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-http#readme",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"moost": "0.2.
|
|
32
|
-
"wooks": "^0.2.
|
|
31
|
+
"moost": "0.2.4",
|
|
32
|
+
"wooks": "^0.2.5"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@wooksjs/event-http": "^0.2.
|
|
35
|
+
"@wooksjs/event-http": "^0.2.5"
|
|
36
36
|
}
|
|
37
37
|
}
|