vovk 3.0.0-draft.17 → 3.0.0-draft.19
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/client/clientizeController.js +3 -3
- package/client/defaultFetcher.js +2 -2
- package/client/types.d.ts +2 -2
- package/package.json +1 -1
- package/types.d.ts +6 -17
|
@@ -47,9 +47,9 @@ const _clientizeController = (givenController, segmentName, options) => {
|
|
|
47
47
|
const controllerPrefix = trimPath(controller._prefix ?? '');
|
|
48
48
|
const { fetcher: settingsFetcher = defaultFetcher_1.default } = options ?? {};
|
|
49
49
|
for (const [staticMethodName, { path, httpMethod, clientValidators }] of Object.entries(schema)) {
|
|
50
|
-
const getEndpoint = ({
|
|
51
|
-
const mainPrefix = (
|
|
52
|
-
(
|
|
50
|
+
const getEndpoint = ({ apiRoot, params, query, }) => {
|
|
51
|
+
const mainPrefix = (apiRoot.startsWith('http://') || apiRoot.startsWith('https://') || apiRoot.startsWith('/') ? '' : '/') +
|
|
52
|
+
(apiRoot.endsWith('/') ? apiRoot : `${apiRoot}/`) +
|
|
53
53
|
(segmentName ? `${segmentName}/` : '');
|
|
54
54
|
return mainPrefix + getHandlerPath([controllerPrefix, path].filter(Boolean).join('/'), params, query);
|
|
55
55
|
};
|
package/client/defaultFetcher.js
CHANGED
|
@@ -6,8 +6,8 @@ const HttpException_1 = require("../HttpException");
|
|
|
6
6
|
exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at defaultFetcher';
|
|
7
7
|
// defaultFetcher uses HttpException class to throw errors of fake HTTP status 0 if client-side error occurs
|
|
8
8
|
// For normal HTTP errors, it uses message and status code from the response of VovkErrorResponse type
|
|
9
|
-
const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandler, defaultStreamHandler }, { params, query, body,
|
|
10
|
-
const endpoint = getEndpoint({
|
|
9
|
+
const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandler, defaultStreamHandler }, { params, query, body, apiRoot = '/api', ...options }) => {
|
|
10
|
+
const endpoint = getEndpoint({ apiRoot, params, query });
|
|
11
11
|
if (!options.disableClientValidation) {
|
|
12
12
|
try {
|
|
13
13
|
await validate({ body, query, endpoint });
|
package/client/types.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type _VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<st
|
|
|
50
50
|
name: keyof T;
|
|
51
51
|
httpMethod: HttpMethod;
|
|
52
52
|
getEndpoint: (data: {
|
|
53
|
-
|
|
53
|
+
apiRoot: string;
|
|
54
54
|
params: {
|
|
55
55
|
[key: string]: string;
|
|
56
56
|
};
|
|
@@ -78,7 +78,7 @@ export interface _VovkDefaultFetcherOptions extends Omit<RequestInit, 'body' | '
|
|
|
78
78
|
reactNative?: {
|
|
79
79
|
textStreaming: boolean;
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
apiRoot?: string;
|
|
82
82
|
segmentName?: string;
|
|
83
83
|
disableClientValidation?: boolean;
|
|
84
84
|
validateOnClient?: _VovkValidateOnClient;
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -63,7 +63,6 @@ export interface _VovkRequest<BODY = undefined, QUERY extends object | undefined
|
|
|
63
63
|
forEach: (callbackfn: (value: QUERY[keyof QUERY], key: keyof QUERY, searchParams: NextRequest['nextUrl']['searchParams']) => void) => void;
|
|
64
64
|
keys: () => IterableIterator<keyof QUERY>;
|
|
65
65
|
values: () => IterableIterator<QUERY[keyof QUERY]>;
|
|
66
|
-
readonly __queryType: QUERY;
|
|
67
66
|
};
|
|
68
67
|
};
|
|
69
68
|
vovk: {
|
|
@@ -72,26 +71,16 @@ export interface _VovkRequest<BODY = undefined, QUERY extends object | undefined
|
|
|
72
71
|
meta: <T = Record<_KnownAny, _KnownAny>>(meta?: T | null) => T;
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
|
-
export type _ControllerStaticMethod<REQ extends _VovkRequest<
|
|
74
|
+
export type _ControllerStaticMethod<REQ extends _VovkRequest<_KnownAny, _KnownAny> = _VovkRequest<undefined, Record<string, string | string[]>>, PARAMS extends {
|
|
76
75
|
[key: string]: string;
|
|
77
76
|
} = _KnownAny> = ((req: REQ, params: PARAMS) => unknown) & {
|
|
78
77
|
_controller?: _VovkController;
|
|
79
78
|
};
|
|
80
|
-
export type _VovkControllerBody<T extends _ControllerStaticMethod<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export type
|
|
84
|
-
|
|
85
|
-
} = _KnownAny> = Parameters<T>[0]['nextUrl']['searchParams']['__queryType'];
|
|
86
|
-
export type _VovkControllerParams<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
87
|
-
[key: string]: string;
|
|
88
|
-
} = _KnownAny> = Parameters<T>[1];
|
|
89
|
-
export type _VovkControllerReturnType<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
90
|
-
[key: string]: string;
|
|
91
|
-
} = _KnownAny> = Awaited<ReturnType<T>>;
|
|
92
|
-
export type _VovkControllerYieldType<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
93
|
-
[key: string]: string;
|
|
94
|
-
} = _KnownAny> = T extends (...args: _KnownAny[]) => AsyncGenerator<infer Y, _KnownAny, _KnownAny> ? Y : T extends (...args: _KnownAny[]) => Generator<infer Y, _KnownAny, _KnownAny> ? Y : T extends (...args: _KnownAny[]) => Promise<StreamResponse<infer Y>> | StreamResponse<infer Y> ? Y : never;
|
|
79
|
+
export type _VovkControllerBody<T extends _ControllerStaticMethod<_KnownAny, _KnownAny>> = Awaited<ReturnType<Parameters<T>[0]['vovk']['body']>>;
|
|
80
|
+
export type _VovkControllerQuery<T extends _ControllerStaticMethod<_KnownAny, _KnownAny>> = ReturnType<Parameters<T>[0]['vovk']['query']>;
|
|
81
|
+
export type _VovkControllerParams<T extends _ControllerStaticMethod<_KnownAny, _KnownAny>> = Parameters<T>[1];
|
|
82
|
+
export type _VovkControllerReturnType<T extends _ControllerStaticMethod<_KnownAny, _KnownAny>> = Awaited<ReturnType<T>>;
|
|
83
|
+
export type _VovkControllerYieldType<T extends (req: _VovkRequest<_KnownAny, _KnownAny>) => _KnownAny> = T extends (...args: _KnownAny[]) => AsyncGenerator<infer Y, _KnownAny, _KnownAny> ? Y : T extends (...args: _KnownAny[]) => Generator<infer Y, _KnownAny, _KnownAny> ? Y : T extends (...args: _KnownAny[]) => Promise<StreamResponse<infer Y>> | StreamResponse<infer Y> ? Y : never;
|
|
95
84
|
export type _VovkClientBody<T extends (options: OPTIONS) => _KnownAny, OPTIONS extends {
|
|
96
85
|
body: B;
|
|
97
86
|
[key: string]: _KnownAny;
|