vovk 3.0.0-draft.120 → 3.0.0-draft.128
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/client/createRPC.d.ts +1 -1
- package/dist/client/createRPC.js +1 -0
- package/dist/client/fetcher.d.ts +6 -8
- package/dist/client/fetcher.js +8 -5
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +2 -1
- package/dist/client/types.d.ts +16 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/types.d.ts +23 -8
- package/dist/utils/getSchema.js +1 -0
- package/dist/utils/parseQuery.js +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { KnownAny, VovkFullSchema } from '../types';
|
|
2
2
|
import type { VovkClientOptions, VovkClient, VovkDefaultFetcherOptions } from './types';
|
|
3
|
-
export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions
|
|
3
|
+
export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions<Record<string, never>>>(fullSchema: VovkFullSchema, segmentName: string, rpcModuleName: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
|
package/dist/client/createRPC.js
CHANGED
|
@@ -77,6 +77,7 @@ const createRPC = (fullSchema, segmentName, rpcModuleName, options) => {
|
|
|
77
77
|
handler.controllerSchema = controllerSchema;
|
|
78
78
|
handler.segmentSchema = segmentSchema;
|
|
79
79
|
handler.fullSchema = fullSchema;
|
|
80
|
+
handler.isRPC = true;
|
|
80
81
|
// @ts-expect-error TODO
|
|
81
82
|
client[staticMethodName] = handler;
|
|
82
83
|
}
|
package/dist/client/fetcher.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { VovkDefaultFetcherOptions, VovkClientFetcher } from './types';
|
|
2
|
+
import { KnownAny } from '../types';
|
|
2
3
|
export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at default fetcher";
|
|
3
|
-
declare function createFetcher<T =
|
|
4
|
-
prepareRequestInit?: (init: RequestInit, options: VovkDefaultFetcherOptions & T) => RequestInit | Promise<RequestInit>;
|
|
5
|
-
transformResponse?: (resp: unknown, options: VovkDefaultFetcherOptions & T, init: RequestInit) => unknown;
|
|
6
|
-
}): VovkClientFetcher<VovkDefaultFetcherOptions
|
|
7
|
-
export declare const fetcher: VovkClientFetcher<VovkDefaultFetcherOptions
|
|
8
|
-
create: typeof createFetcher;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
4
|
+
export declare function createFetcher<T extends Record<string, KnownAny> = Record<string, never>>({ prepareRequestInit, transformResponse, }?: {
|
|
5
|
+
prepareRequestInit?: (init: RequestInit, options: VovkDefaultFetcherOptions<T> & T) => RequestInit | Promise<RequestInit> | void | Promise<void>;
|
|
6
|
+
transformResponse?: (resp: unknown, options: VovkDefaultFetcherOptions<T> & T, init: RequestInit) => unknown;
|
|
7
|
+
}): VovkClientFetcher<VovkDefaultFetcherOptions<T>>;
|
|
8
|
+
export declare const fetcher: VovkClientFetcher<VovkDefaultFetcherOptions<Record<string, never>>>;
|
package/dist/client/fetcher.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetcher = exports.DEFAULT_ERROR_MESSAGE = void 0;
|
|
4
|
+
exports.createFetcher = createFetcher;
|
|
4
5
|
const types_1 = require("../types");
|
|
5
6
|
const HttpException_1 = require("../HttpException");
|
|
6
7
|
exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at default fetcher';
|
|
@@ -50,7 +51,9 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
|
|
|
50
51
|
else if (body) {
|
|
51
52
|
requestInit.body = JSON.stringify(body);
|
|
52
53
|
}
|
|
53
|
-
requestInit = prepareRequestInit
|
|
54
|
+
requestInit = prepareRequestInit
|
|
55
|
+
? ((await prepareRequestInit(requestInit, options)) ?? requestInit)
|
|
56
|
+
: requestInit;
|
|
54
57
|
let response;
|
|
55
58
|
try {
|
|
56
59
|
response = await fetch(endpoint, requestInit);
|
|
@@ -76,10 +79,10 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
|
|
|
76
79
|
resp = response;
|
|
77
80
|
}
|
|
78
81
|
resp = await resp;
|
|
79
|
-
return transformResponse
|
|
82
|
+
return transformResponse
|
|
83
|
+
? ((await transformResponse(resp, options, requestInit)) ?? resp)
|
|
84
|
+
: resp;
|
|
80
85
|
};
|
|
81
86
|
return newFetcher;
|
|
82
87
|
}
|
|
83
|
-
exports.fetcher =
|
|
84
|
-
transformResponse: (resp) => resp,
|
|
85
|
-
}), { create: createFetcher });
|
|
88
|
+
exports.fetcher = createFetcher();
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { createRPC } from './createRPC';
|
|
2
|
-
export { fetcher } from './fetcher';
|
|
2
|
+
export { fetcher, createFetcher } from './fetcher';
|
|
3
3
|
export type { VovkClient, VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient, VovkStreamAsyncIterable, } from './types';
|
package/dist/client/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetcher = exports.createRPC = void 0;
|
|
3
|
+
exports.createFetcher = exports.fetcher = exports.createRPC = void 0;
|
|
4
4
|
var createRPC_1 = require("./createRPC");
|
|
5
5
|
Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return createRPC_1.createRPC; } });
|
|
6
6
|
var fetcher_1 = require("./fetcher");
|
|
7
7
|
Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return fetcher_1.fetcher; } });
|
|
8
|
+
Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return fetcher_1.createFetcher; } });
|
package/dist/client/types.d.ts
CHANGED
|
@@ -26,7 +26,10 @@ export type VovkStreamAsyncIterable<T> = {
|
|
|
26
26
|
};
|
|
27
27
|
type StaticMethodReturn<T extends ControllerStaticMethod> = ReturnType<T> extends NextResponse<infer U> | Promise<NextResponse<infer U>> ? U : ReturnType<T> extends Response | Promise<Response> ? Awaited<ReturnType<T>> : ReturnType<T>;
|
|
28
28
|
type StaticMethodReturnPromise<T extends ControllerStaticMethod> = ToPromise<StaticMethodReturn<T>>;
|
|
29
|
-
type
|
|
29
|
+
type StaticMethodOption<T extends ((...args: KnownAny[]) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>) & {
|
|
30
|
+
__output?: KnownAny;
|
|
31
|
+
__iteration?: KnownAny;
|
|
32
|
+
}, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown, R = KnownAny, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<KnownAny>> = (StaticMethodInput<T> extends {
|
|
30
33
|
body?: undefined | null;
|
|
31
34
|
query?: undefined;
|
|
32
35
|
params?: undefined;
|
|
@@ -34,11 +37,19 @@ type ClientMethod<T extends (...args: KnownAny[]) => void | object | JSONLinesRe
|
|
|
34
37
|
params: StaticMethodInput<T>['params'];
|
|
35
38
|
} : unknown : StaticMethodInput<T>) & (Partial<OPTS & {
|
|
36
39
|
transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
|
|
37
|
-
|
|
40
|
+
fetcher: VovkClientFetcher<F>;
|
|
41
|
+
}> | void) & (Partial<F extends VovkDefaultFetcherOptions<infer U> ? Omit<U, keyof VovkDefaultFetcherOptions<OPTS>> : void> | void);
|
|
42
|
+
type ClientMethod<T extends ((...args: KnownAny[]) => void | object | JSONLinesResponse<STREAM> | Promise<JSONLinesResponse<STREAM>>) & {
|
|
43
|
+
__output?: KnownAny;
|
|
44
|
+
__iteration?: KnownAny;
|
|
45
|
+
}, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = (<R, F extends VovkDefaultFetcherOptions<KnownAny> = VovkDefaultFetcherOptions<OPTS>>(options: StaticMethodOption<T, OPTS, STREAM, R, F>) => ReturnType<T> extends Promise<JSONLinesResponse<infer U>> | JSONLinesResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<VovkStreamAsyncIterable<U>> : R extends object ? Promise<R> : StaticMethodReturnPromise<T>) & {
|
|
46
|
+
isRPC: true;
|
|
38
47
|
schema: VovkHandlerSchema;
|
|
39
48
|
controllerSchema: VovkControllerSchema;
|
|
40
49
|
segmentSchema: VovkSegmentSchema;
|
|
41
50
|
fullSchema: VovkFullSchema;
|
|
51
|
+
__output: T['__output'];
|
|
52
|
+
__iteration: T['__iteration'];
|
|
42
53
|
};
|
|
43
54
|
type OmitNever<T> = {
|
|
44
55
|
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
@@ -51,7 +62,7 @@ type VovkClientWithNever<T, OPTS extends {
|
|
|
51
62
|
export type VovkClient<T, OPTS extends {
|
|
52
63
|
[key: string]: KnownAny;
|
|
53
64
|
}> = OmitNever<VovkClientWithNever<T, OPTS>>;
|
|
54
|
-
export type VovkClientFetcher<OPTS
|
|
65
|
+
export type VovkClientFetcher<OPTS, T = KnownAny> = (options: {
|
|
55
66
|
name: keyof T;
|
|
56
67
|
httpMethod: HttpMethod;
|
|
57
68
|
getEndpoint: (data: {
|
|
@@ -80,11 +91,11 @@ export type VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<str
|
|
|
80
91
|
[key: string]: string;
|
|
81
92
|
};
|
|
82
93
|
} & OPTS) => KnownAny;
|
|
83
|
-
export interface VovkDefaultFetcherOptions {
|
|
94
|
+
export interface VovkDefaultFetcherOptions<T> {
|
|
84
95
|
apiRoot?: string;
|
|
85
96
|
disableClientValidation?: boolean;
|
|
86
97
|
validateOnClient?: VovkValidateOnClient;
|
|
87
|
-
fetcher?: VovkClientFetcher
|
|
98
|
+
fetcher?: VovkClientFetcher<T>;
|
|
88
99
|
interpretAs?: string;
|
|
89
100
|
init?: RequestInit;
|
|
90
101
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createVovkApp } from './createVovkApp';
|
|
2
|
-
import { HttpStatus
|
|
3
|
-
import { type VovkClient, type VovkClientOptions, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher } from './client';
|
|
2
|
+
import { HttpStatus, HttpMethod, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkOutput, type VovkIteration, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkValidationType } from './types';
|
|
3
|
+
import { type VovkClient, type VovkClientOptions, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher } from './client';
|
|
4
4
|
import { HttpException } from './HttpException';
|
|
5
5
|
import { createDecorator } from './createDecorator';
|
|
6
6
|
import { JSONLinesResponse } from './JSONLinesResponse';
|
|
7
7
|
import { generateStaticAPI } from './utils/generateStaticAPI';
|
|
8
8
|
import { withValidation } from './utils/withValidation';
|
|
9
|
-
export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type VovkSegmentSchema, type VovkErrorResponse, type VovkRequest, type
|
|
9
|
+
export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type VovkSegmentSchema, type VovkErrorResponse, type VovkRequest, type VovkOutput, type VovkIteration, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkValidationType, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidation, };
|
|
10
10
|
export declare const get: {
|
|
11
11
|
(givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
12
12
|
auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.initVovk = exports.prefix = exports.options = exports.head = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.withValidation = exports.generateStaticAPI = exports.fetcher = exports.createRPC = exports.createDecorator = exports.createVovkApp = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.JSONLinesResponse = void 0;
|
|
4
|
+
exports.initVovk = exports.prefix = exports.options = exports.head = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.withValidation = exports.generateStaticAPI = exports.createFetcher = exports.fetcher = exports.createRPC = exports.createDecorator = exports.createVovkApp = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.JSONLinesResponse = void 0;
|
|
5
5
|
const createVovkApp_1 = require("./createVovkApp");
|
|
6
6
|
Object.defineProperty(exports, "createVovkApp", { enumerable: true, get: function () { return createVovkApp_1.createVovkApp; } });
|
|
7
7
|
const types_1 = require("./types");
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function (
|
|
|
10
10
|
const client_1 = require("./client");
|
|
11
11
|
Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return client_1.createRPC; } });
|
|
12
12
|
Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return client_1.fetcher; } });
|
|
13
|
+
Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return client_1.createFetcher; } });
|
|
13
14
|
const HttpException_1 = require("./HttpException");
|
|
14
15
|
Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return HttpException_1.HttpException; } });
|
|
15
16
|
const createDecorator_1 = require("./createDecorator");
|
package/dist/types.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type VovkControllerSchema = {
|
|
|
25
25
|
handlers: Record<string, VovkHandlerSchema>;
|
|
26
26
|
};
|
|
27
27
|
export type VovkSegmentSchema = {
|
|
28
|
+
$schema: string;
|
|
28
29
|
emitSchema: boolean;
|
|
29
30
|
segmentName: string;
|
|
30
31
|
controllers: Record<string, VovkControllerSchema>;
|
|
@@ -86,16 +87,28 @@ export type VovkControllerBody<T extends (...args: KnownAny) => KnownAny> = Awai
|
|
|
86
87
|
export type VovkControllerQuery<T extends (...args: KnownAny) => KnownAny> = ReturnType<Parameters<T>[0]['vovk']['query']>;
|
|
87
88
|
export type VovkControllerParams<T extends (...args: KnownAny) => KnownAny> = Parameters<T>[1] extends object ? Parameters<T>[1] : ReturnType<Parameters<T>[0]['vovk']['params']>;
|
|
88
89
|
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<JSONLinesResponse<infer Y>> | JSONLinesResponse<infer Y> ? Y : never;
|
|
89
|
-
export type
|
|
90
|
+
export type VovkOutput<T extends ((...args: KnownAny) => KnownAny) & {
|
|
90
91
|
__output?: KnownAny;
|
|
91
92
|
}> = T['__output'];
|
|
92
|
-
export type
|
|
93
|
+
export type VovkIteration<T extends ((...args: KnownAny) => KnownAny) & {
|
|
93
94
|
__iteration?: KnownAny;
|
|
94
95
|
}> = T['__iteration'];
|
|
95
|
-
export type
|
|
96
|
-
export type
|
|
97
|
-
export type
|
|
98
|
-
export type
|
|
96
|
+
export type VovkClientBody<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['body'];
|
|
97
|
+
export type VovkClientQuery<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['query'];
|
|
98
|
+
export type VovkClientParams<T extends (...args: KnownAny[]) => unknown> = Parameters<T>[0]['params'];
|
|
99
|
+
export type VovkClientYieldType<T extends (...args: KnownAny[]) => unknown> = T extends (...args: KnownAny[]) => Promise<VovkStreamAsyncIterable<infer Y>> ? Y : never;
|
|
100
|
+
export type VovkBody<T extends (...args: KnownAny[]) => unknown> = T extends {
|
|
101
|
+
isRPC: true;
|
|
102
|
+
} ? VovkClientBody<T> : VovkControllerBody<T>;
|
|
103
|
+
export type VovkQuery<T extends (...args: KnownAny[]) => unknown> = T extends {
|
|
104
|
+
isRPC: true;
|
|
105
|
+
} ? VovkClientQuery<T> : VovkControllerQuery<T>;
|
|
106
|
+
export type VovkParams<T extends (...args: KnownAny[]) => unknown> = T extends {
|
|
107
|
+
isRPC: true;
|
|
108
|
+
} ? VovkClientParams<T> : VovkControllerParams<T>;
|
|
109
|
+
export type VovkYieldType<T extends (...args: KnownAny[]) => unknown> = T extends {
|
|
110
|
+
isRPC: true;
|
|
111
|
+
} ? VovkClientYieldType<T> : VovkControllerYieldType<T>;
|
|
99
112
|
export type VovkReturnType<T extends (...args: KnownAny) => unknown> = Awaited<ReturnType<T>>;
|
|
100
113
|
export type StreamAbortMessage = {
|
|
101
114
|
isError: true;
|
|
@@ -103,6 +116,7 @@ export type StreamAbortMessage = {
|
|
|
103
116
|
};
|
|
104
117
|
export type VovkValidationType = 'body' | 'query' | 'params' | 'output' | 'iteration';
|
|
105
118
|
export type VovkFullSchema = {
|
|
119
|
+
$schema: string;
|
|
106
120
|
config: Partial<VovkStrictConfig>;
|
|
107
121
|
segments: Record<string, VovkSegmentSchema>;
|
|
108
122
|
};
|
|
@@ -196,16 +210,17 @@ export type ClientTemplateDef = {
|
|
|
196
210
|
requires?: Record<string, string>;
|
|
197
211
|
};
|
|
198
212
|
export type VovkConfig = {
|
|
213
|
+
$schema?: string;
|
|
199
214
|
emitConfig?: boolean | (keyof VovkStrictConfig)[];
|
|
200
215
|
schemaOutDir?: string;
|
|
201
216
|
fullClient?: ClientConfigFull;
|
|
202
217
|
segmentedClient?: ClientConfigSegmented;
|
|
203
218
|
bundle?: {
|
|
204
219
|
outDir?: string;
|
|
205
|
-
|
|
206
|
-
noPackage?: boolean;
|
|
220
|
+
requires?: Record<string, string>;
|
|
207
221
|
tsClientOutDir?: string;
|
|
208
222
|
dontDeleteTsClientOutDirAfter?: boolean;
|
|
223
|
+
sourcemap?: boolean;
|
|
209
224
|
};
|
|
210
225
|
imports?: {
|
|
211
226
|
fetcher?: string | [string, string] | [string];
|
package/dist/utils/getSchema.js
CHANGED
|
@@ -20,6 +20,7 @@ function getSchema(options) {
|
|
|
20
20
|
const exposeValidation = options?.exposeValidation ?? true;
|
|
21
21
|
const emitSchema = options.emitSchema ?? true;
|
|
22
22
|
const schema = {
|
|
23
|
+
$schema: `https://vovk.dev/api/schema/v3/segment.json`, // TODO use enum from vovk-cli
|
|
23
24
|
emitSchema,
|
|
24
25
|
segmentName: options.segmentName ?? '',
|
|
25
26
|
controllers: {},
|
package/dist/utils/parseQuery.js
CHANGED
|
@@ -145,7 +145,7 @@ function parseQuery(queryString) {
|
|
|
145
145
|
.split('&');
|
|
146
146
|
for (const pair of pairs) {
|
|
147
147
|
const [rawKey, rawVal = ''] = pair.split('=');
|
|
148
|
-
const decodedKey = decodeURIComponent(rawKey
|
|
148
|
+
const decodedKey = decodeURIComponent(rawKey);
|
|
149
149
|
const decodedVal = decodeURIComponent(rawVal);
|
|
150
150
|
// Parse bracket notation
|
|
151
151
|
const pathSegments = parseKey(decodedKey);
|
package/package.json
CHANGED