vovk 3.0.0-draft.63 → 3.0.0-draft.65
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/VovkApp.d.ts +9 -8
- package/dist/VovkApp.js +2 -1
- package/dist/client/defaultFetcher.js +2 -2
- package/dist/createVovkApp.d.ts +8 -7
- package/dist/index.d.ts +7 -7
- package/package.json +1 -1
- package/src/VovkApp.ts +13 -11
- package/src/client/defaultFetcher.ts +2 -4
- package/src/createVovkApp.ts +2 -1
package/dist/VovkApp.d.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
|
2
|
+
import { HttpMethod, HttpStatus, type RouteHandler, type VovkController, type DecoratorOptions } from './types';
|
|
2
3
|
export declare class VovkApp {
|
|
3
4
|
#private;
|
|
4
5
|
private static getHeadersFromOptions;
|
|
5
6
|
routes: Record<HttpMethod, Map<VovkController, Record<string, RouteHandler>>>;
|
|
6
|
-
GET: (req:
|
|
7
|
+
GET: (req: NextRequest, data: {
|
|
7
8
|
params: Promise<Record<string, string[]>>;
|
|
8
9
|
}) => Promise<Response>;
|
|
9
|
-
POST: (req:
|
|
10
|
+
POST: (req: NextRequest, data: {
|
|
10
11
|
params: Promise<Record<string, string[]>>;
|
|
11
12
|
}) => Promise<Response>;
|
|
12
|
-
PUT: (req:
|
|
13
|
+
PUT: (req: NextRequest, data: {
|
|
13
14
|
params: Promise<Record<string, string[]>>;
|
|
14
15
|
}) => Promise<Response>;
|
|
15
|
-
PATCH: (req:
|
|
16
|
+
PATCH: (req: NextRequest, data: {
|
|
16
17
|
params: Promise<Record<string, string[]>>;
|
|
17
18
|
}) => Promise<Response>;
|
|
18
|
-
DELETE: (req:
|
|
19
|
+
DELETE: (req: NextRequest, data: {
|
|
19
20
|
params: Promise<Record<string, string[]>>;
|
|
20
21
|
}) => Promise<Response>;
|
|
21
|
-
HEAD: (req:
|
|
22
|
+
HEAD: (req: NextRequest, data: {
|
|
22
23
|
params: Promise<Record<string, string[]>>;
|
|
23
24
|
}) => Promise<Response>;
|
|
24
|
-
OPTIONS: (req:
|
|
25
|
+
OPTIONS: (req: NextRequest, data: {
|
|
25
26
|
params: Promise<Record<string, string[]>>;
|
|
26
27
|
}) => Promise<Response>;
|
|
27
28
|
respond: (status: HttpStatus, body: unknown, options?: DecoratorOptions) => Response;
|
package/dist/VovkApp.js
CHANGED
|
@@ -59,7 +59,8 @@ class VovkApp {
|
|
|
59
59
|
isError: true,
|
|
60
60
|
}, options);
|
|
61
61
|
};
|
|
62
|
-
#callMethod = async (httpMethod,
|
|
62
|
+
#callMethod = async (httpMethod, nextReq, params) => {
|
|
63
|
+
const req = nextReq;
|
|
63
64
|
const controllers = this.routes[httpMethod];
|
|
64
65
|
const methodParams = {};
|
|
65
66
|
const path = params[Object.keys(params)[0]];
|
|
@@ -17,7 +17,7 @@ const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandle
|
|
|
17
17
|
if (e instanceof HttpException_1.HttpException)
|
|
18
18
|
throw e;
|
|
19
19
|
// otherwise, throw HttpException with status 0
|
|
20
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, e.message ?? exports.DEFAULT_ERROR_MESSAGE);
|
|
20
|
+
throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, e.message ?? exports.DEFAULT_ERROR_MESSAGE, { body, query, params, endpoint });
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
const init = {
|
|
@@ -36,7 +36,7 @@ const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandle
|
|
|
36
36
|
}
|
|
37
37
|
catch (e) {
|
|
38
38
|
// handle network errors
|
|
39
|
-
throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, e?.message ?? exports.DEFAULT_ERROR_MESSAGE);
|
|
39
|
+
throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, e?.message ?? exports.DEFAULT_ERROR_MESSAGE, { body, query, params, endpoint });
|
|
40
40
|
}
|
|
41
41
|
const contentType = response.headers.get('content-type');
|
|
42
42
|
if (contentType?.startsWith('application/json')) {
|
package/dist/createVovkApp.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
|
1
2
|
import { type KnownAny, type DecoratorOptions, type VovkRequest, type StaticClass } from './types';
|
|
2
3
|
export declare function createVovkApp(): {
|
|
3
4
|
get: {
|
|
@@ -36,25 +37,25 @@ export declare function createVovkApp(): {
|
|
|
36
37
|
emitSchema?: boolean;
|
|
37
38
|
onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
|
|
38
39
|
}) => {
|
|
39
|
-
GET: (req:
|
|
40
|
+
GET: (req: NextRequest, data: {
|
|
40
41
|
params: Promise<Record<string, string[]>>;
|
|
41
42
|
}) => Promise<Response>;
|
|
42
|
-
POST: (req:
|
|
43
|
+
POST: (req: NextRequest, data: {
|
|
43
44
|
params: Promise<Record<string, string[]>>;
|
|
44
45
|
}) => Promise<Response>;
|
|
45
|
-
PUT: (req:
|
|
46
|
+
PUT: (req: NextRequest, data: {
|
|
46
47
|
params: Promise<Record<string, string[]>>;
|
|
47
48
|
}) => Promise<Response>;
|
|
48
|
-
PATCH: (req:
|
|
49
|
+
PATCH: (req: NextRequest, data: {
|
|
49
50
|
params: Promise<Record<string, string[]>>;
|
|
50
51
|
}) => Promise<Response>;
|
|
51
|
-
DELETE: (req:
|
|
52
|
+
DELETE: (req: NextRequest, data: {
|
|
52
53
|
params: Promise<Record<string, string[]>>;
|
|
53
54
|
}) => Promise<Response>;
|
|
54
|
-
HEAD: (req:
|
|
55
|
+
HEAD: (req: NextRequest, data: {
|
|
55
56
|
params: Promise<Record<string, string[]>>;
|
|
56
57
|
}) => Promise<Response>;
|
|
57
|
-
OPTIONS: (req:
|
|
58
|
+
OPTIONS: (req: NextRequest, data: {
|
|
58
59
|
params: Promise<Record<string, string[]>>;
|
|
59
60
|
}) => Promise<Response>;
|
|
60
61
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -35,25 +35,25 @@ export declare const get: {
|
|
|
35
35
|
emitSchema?: boolean;
|
|
36
36
|
onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
|
|
37
37
|
}) => {
|
|
38
|
-
GET: (req:
|
|
38
|
+
GET: (req: import("next/server").NextRequest, data: {
|
|
39
39
|
params: Promise<Record<string, string[]>>;
|
|
40
40
|
}) => Promise<Response>;
|
|
41
|
-
POST: (req:
|
|
41
|
+
POST: (req: import("next/server").NextRequest, data: {
|
|
42
42
|
params: Promise<Record<string, string[]>>;
|
|
43
43
|
}) => Promise<Response>;
|
|
44
|
-
PUT: (req:
|
|
44
|
+
PUT: (req: import("next/server").NextRequest, data: {
|
|
45
45
|
params: Promise<Record<string, string[]>>;
|
|
46
46
|
}) => Promise<Response>;
|
|
47
|
-
PATCH: (req:
|
|
47
|
+
PATCH: (req: import("next/server").NextRequest, data: {
|
|
48
48
|
params: Promise<Record<string, string[]>>;
|
|
49
49
|
}) => Promise<Response>;
|
|
50
|
-
DELETE: (req:
|
|
50
|
+
DELETE: (req: import("next/server").NextRequest, data: {
|
|
51
51
|
params: Promise<Record<string, string[]>>;
|
|
52
52
|
}) => Promise<Response>;
|
|
53
|
-
HEAD: (req:
|
|
53
|
+
HEAD: (req: import("next/server").NextRequest, data: {
|
|
54
54
|
params: Promise<Record<string, string[]>>;
|
|
55
55
|
}) => Promise<Response>;
|
|
56
|
-
OPTIONS: (req:
|
|
56
|
+
OPTIONS: (req: import("next/server").NextRequest, data: {
|
|
57
57
|
params: Promise<Record<string, string[]>>;
|
|
58
58
|
}) => Promise<Response>;
|
|
59
59
|
};
|
package/package.json
CHANGED
package/src/VovkApp.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
|
1
2
|
import {
|
|
2
3
|
HttpMethod,
|
|
3
4
|
HttpStatus,
|
|
@@ -5,10 +6,10 @@ import {
|
|
|
5
6
|
type VovkErrorResponse,
|
|
6
7
|
type VovkController,
|
|
7
8
|
type DecoratorOptions,
|
|
8
|
-
type VovkRequest,
|
|
9
9
|
type KnownAny,
|
|
10
|
+
type VovkRequest,
|
|
10
11
|
} from './types';
|
|
11
|
-
import { HttpException
|
|
12
|
+
import { HttpException } from './HttpException';
|
|
12
13
|
import { StreamJSONResponse } from './StreamJSONResponse';
|
|
13
14
|
import reqQuery from './utils/reqQuery';
|
|
14
15
|
import reqMeta from './utils/reqMeta';
|
|
@@ -42,25 +43,25 @@ export class VovkApp {
|
|
|
42
43
|
OPTIONS: new Map(),
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
GET = async (req:
|
|
46
|
+
GET = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
46
47
|
this.#callMethod(HttpMethod.GET, req, await data.params);
|
|
47
48
|
|
|
48
|
-
POST = async (req:
|
|
49
|
+
POST = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
49
50
|
this.#callMethod(HttpMethod.POST, req, await data.params);
|
|
50
51
|
|
|
51
|
-
PUT = async (req:
|
|
52
|
+
PUT = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
52
53
|
this.#callMethod(HttpMethod.PUT, req, await data.params);
|
|
53
54
|
|
|
54
|
-
PATCH = async (req:
|
|
55
|
+
PATCH = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
55
56
|
this.#callMethod(HttpMethod.PATCH, req, await data.params);
|
|
56
57
|
|
|
57
|
-
DELETE = async (req:
|
|
58
|
+
DELETE = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
58
59
|
this.#callMethod(HttpMethod.DELETE, req, await data.params);
|
|
59
60
|
|
|
60
|
-
HEAD = async (req:
|
|
61
|
+
HEAD = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
61
62
|
this.#callMethod(HttpMethod.HEAD, req, await data.params);
|
|
62
63
|
|
|
63
|
-
OPTIONS = async (req:
|
|
64
|
+
OPTIONS = async (req: NextRequest, data: { params: Promise<Record<string, string[]>> }) =>
|
|
64
65
|
this.#callMethod(HttpMethod.OPTIONS, req, await data.params);
|
|
65
66
|
|
|
66
67
|
respond = (status: HttpStatus, body: unknown, options?: DecoratorOptions) => {
|
|
@@ -88,9 +89,10 @@ export class VovkApp {
|
|
|
88
89
|
|
|
89
90
|
#callMethod = async (
|
|
90
91
|
httpMethod: HttpMethod,
|
|
91
|
-
|
|
92
|
+
nextReq: NextRequest,
|
|
92
93
|
params: Record<string, string[]>
|
|
93
94
|
) => {
|
|
95
|
+
const req = nextReq as unknown as VovkRequest;
|
|
94
96
|
const controllers = this.routes[httpMethod];
|
|
95
97
|
const methodParams: Record<string, string> = {};
|
|
96
98
|
const path = params[Object.keys(params)[0]];
|
|
@@ -178,7 +180,7 @@ export class VovkApp {
|
|
|
178
180
|
|
|
179
181
|
req.vovk = {
|
|
180
182
|
body: () => req.json(),
|
|
181
|
-
query: () => reqQuery(req),
|
|
183
|
+
query: () => reqQuery(req as VovkRequest),
|
|
182
184
|
meta: <T = KnownAny>(meta?: T | null) => reqMeta<T>(req, meta),
|
|
183
185
|
form: <T = KnownAny>() => reqForm<T>(req),
|
|
184
186
|
};
|
|
@@ -19,7 +19,7 @@ const defaultFetcher: VovkClientFetcher<VovkDefaultFetcherOptions> = async (
|
|
|
19
19
|
// if HttpException is thrown, rethrow it
|
|
20
20
|
if (e instanceof HttpException) throw e;
|
|
21
21
|
// otherwise, throw HttpException with status 0
|
|
22
|
-
throw new HttpException(HttpStatus.NULL, (e as Error).message ?? DEFAULT_ERROR_MESSAGE);
|
|
22
|
+
throw new HttpException(HttpStatus.NULL, (e as Error).message ?? DEFAULT_ERROR_MESSAGE, { body, query, params, endpoint });
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -40,13 +40,11 @@ const defaultFetcher: VovkClientFetcher<VovkDefaultFetcherOptions> = async (
|
|
|
40
40
|
response = await fetch(endpoint, init);
|
|
41
41
|
} catch (e) {
|
|
42
42
|
// handle network errors
|
|
43
|
-
throw new HttpException(HttpStatus.NULL, (e as Error)?.message ?? DEFAULT_ERROR_MESSAGE);
|
|
43
|
+
throw new HttpException(HttpStatus.NULL, (e as Error)?.message ?? DEFAULT_ERROR_MESSAGE, { body, query, params, endpoint });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const contentType = response.headers.get('content-type');
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
48
|
if (contentType?.startsWith('application/json')) {
|
|
51
49
|
return defaultHandler(response);
|
|
52
50
|
}
|
package/src/createVovkApp.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
|
1
2
|
import { VovkApp as VovkApp } from './VovkApp';
|
|
2
3
|
import {
|
|
3
4
|
HttpMethod,
|
|
@@ -131,7 +132,7 @@ export function createVovkApp() {
|
|
|
131
132
|
controller._onError = options?.onError;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
async function GET_DEV(req:
|
|
135
|
+
async function GET_DEV(req: NextRequest, data: { params: Promise<Record<string, string[]>> }) {
|
|
135
136
|
const params = await data.params;
|
|
136
137
|
if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
|
|
137
138
|
// Wait for schema to be set (it can be set after decorators are called with another setTimeout)
|