vovk 3.0.0-draft.461 → 3.0.0-draft.463
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/README.md +10 -12
- package/cjs/client/fetcher.d.ts +17 -3
- package/cjs/client/fetcher.js +5 -3
- package/cjs/index.d.ts +2 -2
- package/cjs/openapi/vovkSchemaToOpenAPI.d.ts +2 -2
- package/cjs/types.d.ts +12 -9
- package/cjs/utils/resolveGeneratorConfigValues.d.ts +4 -4
- package/cjs/utils/resolveGeneratorConfigValues.js +16 -16
- package/mjs/client/fetcher.d.ts +17 -3
- package/mjs/client/fetcher.js +5 -3
- package/mjs/index.d.ts +2 -2
- package/mjs/openapi/vovkSchemaToOpenAPI.d.ts +2 -2
- package/mjs/types.d.ts +12 -9
- package/mjs/utils/resolveGeneratorConfigValues.d.ts +4 -4
- package/mjs/utils/resolveGeneratorConfigValues.js +16 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<picture>
|
|
3
|
-
<source width="300" media="(prefers-color-scheme: dark)" srcset="https://vovk.dev/vovk-logo-white.svg">
|
|
4
|
-
<source width="300" media="(prefers-color-scheme: light)" srcset="https://vovk.dev/vovk-logo.svg">
|
|
5
|
-
<img width="300" alt="vovk" src="https://vovk.dev/vovk-logo.svg">
|
|
6
|
-
</picture><br>
|
|
7
|
-
<strong>RESTful + RPC = ♥️</strong>
|
|
8
|
-
</p>
|
|
9
|
-
|
|
10
1
|
<p align="center">
|
|
11
|
-
|
|
2
|
+
<a href="https://vovk.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source width="300" media="(prefers-color-scheme: dark)" srcset="https://vovk.dev/vovk-logo-white.svg">
|
|
5
|
+
<source width="300" media="(prefers-color-scheme: light)" srcset="https://vovk.dev/vovk-logo.svg">
|
|
6
|
+
<img width="300" alt="vovk" src="https://vovk.dev/vovk-logo.svg">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
<br>
|
|
10
|
+
<strong>Back-end for <a href="https://nextjs.org/">Next.js</a></strong>
|
|
12
11
|
</p>
|
|
13
12
|
|
|
14
13
|
---
|
|
15
14
|
|
|
16
15
|
## vovk [](https://www.npmjs.com/package/vovk)
|
|
17
16
|
|
|
18
|
-
The main library with [
|
|
17
|
+
The main library with [100% self-composition](https://bundlephobia.com/result?p=vovk) that's going to be used in production. It provides a wrapper for Next.js API routes, client-side RPC tooling, utilities and types.
|
|
19
18
|
|
|
20
19
|
```sh
|
|
21
20
|
npm install vovk
|
|
22
21
|
```
|
|
23
22
|
|
|
24
|
-
For more information, please visit the [getting started guide](https://vovk.dev/getting-started) or check out the [Vovk.ts examples](https://vovk-examples.vercel.app/).
|
package/cjs/client/fetcher.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import type { VovkFetcherOptions, VovkFetcher } from './types';
|
|
2
|
+
import { type VovkHandlerSchema } from '../types';
|
|
2
3
|
import { HttpException } from '../HttpException';
|
|
3
4
|
export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at default fetcher";
|
|
4
5
|
export declare function createFetcher<T>({ prepareRequestInit, transformResponse, onSuccess, onError, }?: {
|
|
5
6
|
prepareRequestInit?: (init: RequestInit, options: VovkFetcherOptions<T>) => RequestInit | Promise<RequestInit>;
|
|
6
|
-
transformResponse?: (respData: unknown, options: VovkFetcherOptions<T>,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
transformResponse?: (respData: unknown, options: VovkFetcherOptions<T>, info: {
|
|
8
|
+
response: Response;
|
|
9
|
+
init: RequestInit;
|
|
10
|
+
schema: VovkHandlerSchema;
|
|
11
|
+
}) => unknown | Promise<unknown>;
|
|
12
|
+
onSuccess?: (respData: unknown, options: VovkFetcherOptions<T>, info: {
|
|
13
|
+
response: Response;
|
|
14
|
+
init: RequestInit;
|
|
15
|
+
schema: VovkHandlerSchema;
|
|
16
|
+
}) => void | Promise<void>;
|
|
17
|
+
onError?: (error: HttpException, options: VovkFetcherOptions<T>, info: {
|
|
18
|
+
response: Response | null;
|
|
19
|
+
init: RequestInit | null;
|
|
20
|
+
respData: unknown | null;
|
|
21
|
+
schema: VovkHandlerSchema;
|
|
22
|
+
}) => void | Promise<void>;
|
|
9
23
|
}): VovkFetcher<VovkFetcherOptions<T>>;
|
|
10
24
|
export declare const fetcher: VovkFetcher<{
|
|
11
25
|
apiRoot?: string;
|
package/cjs/client/fetcher.js
CHANGED
|
@@ -83,12 +83,14 @@ function createFetcher({ prepareRequestInit, transformResponse, onSuccess, onErr
|
|
|
83
83
|
else {
|
|
84
84
|
respData = response;
|
|
85
85
|
}
|
|
86
|
-
respData = transformResponse
|
|
87
|
-
|
|
86
|
+
respData = transformResponse
|
|
87
|
+
? await transformResponse(respData, inputOptions, { response, init: requestInit, schema })
|
|
88
|
+
: respData;
|
|
89
|
+
await onSuccess?.(respData, inputOptions, { response, init: requestInit, schema });
|
|
88
90
|
return [respData, response];
|
|
89
91
|
}
|
|
90
92
|
catch (error) {
|
|
91
|
-
await onError?.(error, inputOptions, response, requestInit, respData);
|
|
93
|
+
await onError?.(error, inputOptions, { response, init: requestInit, respData, schema });
|
|
92
94
|
throw error;
|
|
93
95
|
}
|
|
94
96
|
};
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createVovkApp } from './createVovkApp';
|
|
2
|
-
import { HttpStatus, HttpMethod, VovkSchemaIdEnum, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkOutput, type VovkIteration, type VovkMetaSchema, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type
|
|
2
|
+
import { HttpStatus, HttpMethod, VovkSchemaIdEnum, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkOutput, type VovkIteration, type VovkMetaSchema, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkOutputConfig, type VovkReadmeConfig, type VovkSamplesConfig, type VovkPackageJson, type VovkOpenAPIMixin, type VovkOpenAPIMixinNormalized, type VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, type VovkBasicJSONSchema, type VovkOperationObject } from './types';
|
|
3
3
|
import { type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher, progressive } from './client';
|
|
4
4
|
import { operation, openAPIToVovkSchema, vovkSchemaToOpenAPI } from './openapi';
|
|
5
5
|
import { HttpException } from './HttpException';
|
|
@@ -13,7 +13,7 @@ import { createLLMTools } from './utils/createLLMTools';
|
|
|
13
13
|
import { createCodeSamples } from './utils/createCodeSamples';
|
|
14
14
|
import { createValidateOnClient } from './utils/createValidateOnClient';
|
|
15
15
|
import { resolveGeneratorConfigValues } from './utils/resolveGeneratorConfigValues';
|
|
16
|
-
export { type KnownAny, type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, 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 VovkMetaSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type
|
|
16
|
+
export { type KnownAny, type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, 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 VovkMetaSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkOutputConfig, type VovkPackageJson, type VovkReadmeConfig, type VovkSamplesConfig, type VovkOpenAPIMixin, type VovkOpenAPIMixinNormalized, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, type VovkBasicJSONSchema, type VovkOperationObject, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, createStandardValidation, multitenant, createLLMTools, createCodeSamples, createValidateOnClient, progressive, operation, openAPIToVovkSchema, vovkSchemaToOpenAPI, resolveGeneratorConfigValues, };
|
|
17
17
|
export declare const get: {
|
|
18
18
|
(givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
|
|
19
19
|
auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import { type VovkSchema, type
|
|
2
|
+
import { type VovkSchema, type VovkOutputConfig } from '../types';
|
|
3
3
|
export declare function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, configs, segmentName: givenSegmentName, }: {
|
|
4
4
|
rootEntry?: string;
|
|
5
5
|
schema: VovkSchema;
|
|
6
|
-
configs?:
|
|
6
|
+
configs?: VovkOutputConfig[];
|
|
7
7
|
segmentName?: string;
|
|
8
8
|
}): OpenAPIObject;
|
package/cjs/types.d.ts
CHANGED
|
@@ -346,10 +346,13 @@ type BundleConfig = {
|
|
|
346
346
|
requires?: Record<string, string>;
|
|
347
347
|
prebundleOutDir?: string;
|
|
348
348
|
keepPrebundleDir?: boolean;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
outDir?: string;
|
|
350
|
+
build: (options: {
|
|
351
|
+
outDir: string;
|
|
352
|
+
prebundleDir: string;
|
|
353
|
+
entry: string;
|
|
354
|
+
}) => Promise<void>;
|
|
355
|
+
outputConfig?: VovkOutputConfig<GeneratorConfigImports>;
|
|
353
356
|
} & ({
|
|
354
357
|
excludeSegments?: never;
|
|
355
358
|
includeSegments?: string[];
|
|
@@ -366,7 +369,7 @@ type SegmentConfigImports = {
|
|
|
366
369
|
fetcher?: string | [string, string] | [string];
|
|
367
370
|
validateOnClient?: string | [string, string] | [string] | null;
|
|
368
371
|
};
|
|
369
|
-
export interface
|
|
372
|
+
export interface VovkOutputConfig<TImports extends GeneratorConfigImports = GeneratorConfigImports> {
|
|
370
373
|
origin?: string | null;
|
|
371
374
|
package?: VovkPackageJson;
|
|
372
375
|
readme?: VovkReadmeConfig;
|
|
@@ -381,7 +384,7 @@ export type ClientTemplateDef = {
|
|
|
381
384
|
composedClient?: Omit<ClientConfigComposed, 'fromTemplates' | 'enabled'>;
|
|
382
385
|
segmentedClient?: Omit<ClientConfigSegmented, 'fromTemplates' | 'enabled'>;
|
|
383
386
|
requires?: Record<string, string>;
|
|
384
|
-
|
|
387
|
+
outputConfig?: VovkOutputConfig<GeneratorConfigImports>;
|
|
385
388
|
};
|
|
386
389
|
export type GetOpenAPINameFn = (config: {
|
|
387
390
|
operationObject: VovkOperationObject;
|
|
@@ -413,7 +416,7 @@ export interface VovkOpenAPIMixinNormalized extends Omit<VovkOpenAPIMixin, 'sour
|
|
|
413
416
|
getMethodName: GetOpenAPINameFn;
|
|
414
417
|
getModuleName: GetOpenAPINameFn;
|
|
415
418
|
}
|
|
416
|
-
export interface VovkSegmentConfig extends
|
|
419
|
+
export interface VovkSegmentConfig extends VovkOutputConfig<SegmentConfigImports> {
|
|
417
420
|
rootEntry?: string;
|
|
418
421
|
segmentNameOverride?: string;
|
|
419
422
|
openAPIMixin?: VovkOpenAPIMixin;
|
|
@@ -440,7 +443,7 @@ type VovkUserConfig = {
|
|
|
440
443
|
controller?: string;
|
|
441
444
|
[key: string]: string | undefined;
|
|
442
445
|
};
|
|
443
|
-
|
|
446
|
+
outputConfig?: VovkOutputConfig<GeneratorConfigImports> & {
|
|
444
447
|
segments?: Record<string, VovkSegmentConfig>;
|
|
445
448
|
};
|
|
446
449
|
};
|
|
@@ -451,7 +454,7 @@ export type VovkStrictConfig = Required<Omit<VovkUserConfig, 'emitConfig' | 'lib
|
|
|
451
454
|
libs: Record<string, KnownAny>;
|
|
452
455
|
composedClient: RequireFields<ClientConfigComposed, 'enabled' | 'fromTemplates' | 'outDir' | 'prettifyClient'>;
|
|
453
456
|
segmentedClient: RequireFields<ClientConfigSegmented, 'enabled' | 'fromTemplates' | 'outDir' | 'prettifyClient'>;
|
|
454
|
-
|
|
457
|
+
outputConfig: VovkOutputConfig<GeneratorConfigImports> & {
|
|
455
458
|
segments?: Record<string, Omit<VovkSegmentConfig, 'openAPIMixin'> & {
|
|
456
459
|
openAPIMixin?: VovkOpenAPIMixinNormalized;
|
|
457
460
|
}>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PackageJson } from 'type-fest';
|
|
2
|
-
import type {
|
|
2
|
+
import type { VovkOutputConfig, VovkReadmeConfig, VovkSamplesConfig, VovkSchema } from '../types';
|
|
3
3
|
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
4
4
|
export declare function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle, projectPackageJson, }: {
|
|
5
5
|
schema: VovkSchema;
|
|
6
|
-
configs?:
|
|
6
|
+
configs?: VovkOutputConfig[];
|
|
7
7
|
segmentName: string | null;
|
|
8
8
|
isBundle?: boolean;
|
|
9
9
|
projectPackageJson?: PackageJson;
|
|
@@ -13,6 +13,6 @@ export declare function resolveGeneratorConfigValues({ schema, configs, segmentN
|
|
|
13
13
|
samples: VovkSamplesConfig;
|
|
14
14
|
origin: string;
|
|
15
15
|
package: PackageJson;
|
|
16
|
-
imports:
|
|
17
|
-
reExports:
|
|
16
|
+
imports: VovkOutputConfig['imports'];
|
|
17
|
+
reExports: VovkOutputConfig['reExports'];
|
|
18
18
|
};
|
|
@@ -27,8 +27,8 @@ function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle,
|
|
|
27
27
|
types: './openapi.d.cts',
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
|
-
}, projectPackageJson, schema.meta?.config?.
|
|
31
|
-
? schema.meta?.config?.
|
|
30
|
+
}, projectPackageJson, schema.meta?.config?.outputConfig?.package, isBundle ? schema.meta?.config?.bundle?.outputConfig?.package : undefined, typeof segmentName === 'string' ? schema.segments?.[segmentName]?.meta?.package : undefined, typeof segmentName === 'string'
|
|
31
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.package
|
|
32
32
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.package), {}));
|
|
33
33
|
return {
|
|
34
34
|
package: Object.fromEntries(Object.entries(packageJson).filter(([key]) => ['name', 'version', 'description', 'license', 'authors', 'repository', 'homepage', 'bugs', 'keywords'].includes(key))),
|
|
@@ -39,21 +39,21 @@ function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle,
|
|
|
39
39
|
version: packageJson.version,
|
|
40
40
|
description: packageJson.description,
|
|
41
41
|
},
|
|
42
|
-
}, schema.meta?.config?.
|
|
43
|
-
? schema.meta?.config?.
|
|
42
|
+
}, schema.meta?.config?.outputConfig?.openAPIObject, isBundle ? schema.meta?.config?.bundle?.outputConfig?.openAPIObject : undefined, typeof segmentName === 'string' ? schema?.segments?.[segmentName]?.meta?.openAPIObject : undefined, typeof segmentName === 'string'
|
|
43
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.openAPIObject
|
|
44
44
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.openAPIObject), {})),
|
|
45
|
-
samples: (0, deepExtend_1.default)({}, schema.meta?.config?.
|
|
46
|
-
? schema.meta?.config?.
|
|
45
|
+
samples: (0, deepExtend_1.default)({}, schema.meta?.config?.outputConfig?.samples, isBundle ? schema.meta?.config?.bundle?.outputConfig?.samples : undefined, typeof segmentName === 'string'
|
|
46
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.samples
|
|
47
47
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.samples), {})),
|
|
48
|
-
readme: (0, deepExtend_1.default)({}, schema.meta?.config?.
|
|
49
|
-
? schema.meta?.config?.
|
|
48
|
+
readme: (0, deepExtend_1.default)({}, schema.meta?.config?.outputConfig?.readme, isBundle ? schema.meta?.config?.bundle?.outputConfig?.readme : undefined, typeof segmentName === 'string'
|
|
49
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.readme
|
|
50
50
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.readme), {})),
|
|
51
51
|
origin: [
|
|
52
|
-
isBundle ? schema.meta?.config?.bundle?.
|
|
52
|
+
isBundle ? schema.meta?.config?.bundle?.outputConfig?.origin : undefined,
|
|
53
53
|
typeof segmentName === 'string'
|
|
54
|
-
? schema.meta?.config?.
|
|
54
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.origin
|
|
55
55
|
: undefined,
|
|
56
|
-
schema.meta?.config?.
|
|
56
|
+
schema.meta?.config?.outputConfig?.origin,
|
|
57
57
|
...(configs?.map((config) => config.origin) ?? []),
|
|
58
58
|
]
|
|
59
59
|
.filter(Boolean)
|
|
@@ -64,19 +64,19 @@ function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle,
|
|
|
64
64
|
fetcher: ['vovk'],
|
|
65
65
|
validateOnClient: null,
|
|
66
66
|
createRPC: ['vovk'],
|
|
67
|
-
}, schema.meta?.config?.
|
|
68
|
-
? schema.meta?.config?.
|
|
67
|
+
}, schema.meta?.config?.outputConfig?.imports, isBundle ? schema.meta?.config?.bundle?.outputConfig?.imports : undefined, typeof segmentName === 'string'
|
|
68
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.imports
|
|
69
69
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.imports), {})),
|
|
70
70
|
reExports: (0, deepExtend_1.default)(
|
|
71
71
|
// segmentName can be an empty string (for the root segment) and null (for composed clients)
|
|
72
72
|
// therefore, !segmentName indicates that this either a composed client or a root segment of a segmented client
|
|
73
|
-
{}, !segmentName && schema.meta?.config?.
|
|
73
|
+
{}, !segmentName && schema.meta?.config?.outputConfig?.reExports, !segmentName && isBundle ? schema.meta?.config?.bundle?.outputConfig?.reExports : undefined,
|
|
74
74
|
// for segmented client, apply all reExports from all segments
|
|
75
75
|
typeof segmentName !== 'string' &&
|
|
76
|
-
Object.values(schema.meta?.config?.
|
|
76
|
+
Object.values(schema.meta?.config?.outputConfig?.segments ?? {}).reduce((acc, segmentConfig) => (0, deepExtend_1.default)(acc, segmentConfig.reExports ?? {}), {}),
|
|
77
77
|
// for a specific segment, apply reExports from that segment
|
|
78
78
|
typeof segmentName === 'string'
|
|
79
|
-
? schema.meta?.config?.
|
|
79
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.reExports
|
|
80
80
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.reExports), {})),
|
|
81
81
|
};
|
|
82
82
|
}
|
package/mjs/client/fetcher.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import type { VovkFetcherOptions, VovkFetcher } from './types';
|
|
2
|
+
import { type VovkHandlerSchema } from '../types';
|
|
2
3
|
import { HttpException } from '../HttpException';
|
|
3
4
|
export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at default fetcher";
|
|
4
5
|
export declare function createFetcher<T>({ prepareRequestInit, transformResponse, onSuccess, onError, }?: {
|
|
5
6
|
prepareRequestInit?: (init: RequestInit, options: VovkFetcherOptions<T>) => RequestInit | Promise<RequestInit>;
|
|
6
|
-
transformResponse?: (respData: unknown, options: VovkFetcherOptions<T>,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
transformResponse?: (respData: unknown, options: VovkFetcherOptions<T>, info: {
|
|
8
|
+
response: Response;
|
|
9
|
+
init: RequestInit;
|
|
10
|
+
schema: VovkHandlerSchema;
|
|
11
|
+
}) => unknown | Promise<unknown>;
|
|
12
|
+
onSuccess?: (respData: unknown, options: VovkFetcherOptions<T>, info: {
|
|
13
|
+
response: Response;
|
|
14
|
+
init: RequestInit;
|
|
15
|
+
schema: VovkHandlerSchema;
|
|
16
|
+
}) => void | Promise<void>;
|
|
17
|
+
onError?: (error: HttpException, options: VovkFetcherOptions<T>, info: {
|
|
18
|
+
response: Response | null;
|
|
19
|
+
init: RequestInit | null;
|
|
20
|
+
respData: unknown | null;
|
|
21
|
+
schema: VovkHandlerSchema;
|
|
22
|
+
}) => void | Promise<void>;
|
|
9
23
|
}): VovkFetcher<VovkFetcherOptions<T>>;
|
|
10
24
|
export declare const fetcher: VovkFetcher<{
|
|
11
25
|
apiRoot?: string;
|
package/mjs/client/fetcher.js
CHANGED
|
@@ -83,12 +83,14 @@ function createFetcher({ prepareRequestInit, transformResponse, onSuccess, onErr
|
|
|
83
83
|
else {
|
|
84
84
|
respData = response;
|
|
85
85
|
}
|
|
86
|
-
respData = transformResponse
|
|
87
|
-
|
|
86
|
+
respData = transformResponse
|
|
87
|
+
? await transformResponse(respData, inputOptions, { response, init: requestInit, schema })
|
|
88
|
+
: respData;
|
|
89
|
+
await onSuccess?.(respData, inputOptions, { response, init: requestInit, schema });
|
|
88
90
|
return [respData, response];
|
|
89
91
|
}
|
|
90
92
|
catch (error) {
|
|
91
|
-
await onError?.(error, inputOptions, response, requestInit, respData);
|
|
93
|
+
await onError?.(error, inputOptions, { response, init: requestInit, respData, schema });
|
|
92
94
|
throw error;
|
|
93
95
|
}
|
|
94
96
|
};
|
package/mjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createVovkApp } from './createVovkApp';
|
|
2
|
-
import { HttpStatus, HttpMethod, VovkSchemaIdEnum, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkOutput, type VovkIteration, type VovkMetaSchema, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type
|
|
2
|
+
import { HttpStatus, HttpMethod, VovkSchemaIdEnum, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkOutput, type VovkIteration, type VovkMetaSchema, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkOutputConfig, type VovkReadmeConfig, type VovkSamplesConfig, type VovkPackageJson, type VovkOpenAPIMixin, type VovkOpenAPIMixinNormalized, type VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, type VovkBasicJSONSchema, type VovkOperationObject } from './types';
|
|
3
3
|
import { type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher, progressive } from './client';
|
|
4
4
|
import { operation, openAPIToVovkSchema, vovkSchemaToOpenAPI } from './openapi';
|
|
5
5
|
import { HttpException } from './HttpException';
|
|
@@ -13,7 +13,7 @@ import { createLLMTools } from './utils/createLLMTools';
|
|
|
13
13
|
import { createCodeSamples } from './utils/createCodeSamples';
|
|
14
14
|
import { createValidateOnClient } from './utils/createValidateOnClient';
|
|
15
15
|
import { resolveGeneratorConfigValues } from './utils/resolveGeneratorConfigValues';
|
|
16
|
-
export { type KnownAny, type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, 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 VovkMetaSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type
|
|
16
|
+
export { type KnownAny, type VovkRPCModule, type VovkFetcher, type VovkFetcherOptions, 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 VovkMetaSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkOutputConfig, type VovkPackageJson, type VovkReadmeConfig, type VovkSamplesConfig, type VovkOpenAPIMixin, type VovkOpenAPIMixinNormalized, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, type VovkBasicJSONSchema, type VovkOperationObject, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, createStandardValidation, multitenant, createLLMTools, createCodeSamples, createValidateOnClient, progressive, operation, openAPIToVovkSchema, vovkSchemaToOpenAPI, resolveGeneratorConfigValues, };
|
|
17
17
|
export declare const get: {
|
|
18
18
|
(givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): (givenTarget: KnownAny, propertyKey: string) => void;
|
|
19
19
|
auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import { type VovkSchema, type
|
|
2
|
+
import { type VovkSchema, type VovkOutputConfig } from '../types';
|
|
3
3
|
export declare function vovkSchemaToOpenAPI({ rootEntry, schema: fullSchema, configs, segmentName: givenSegmentName, }: {
|
|
4
4
|
rootEntry?: string;
|
|
5
5
|
schema: VovkSchema;
|
|
6
|
-
configs?:
|
|
6
|
+
configs?: VovkOutputConfig[];
|
|
7
7
|
segmentName?: string;
|
|
8
8
|
}): OpenAPIObject;
|
package/mjs/types.d.ts
CHANGED
|
@@ -346,10 +346,13 @@ type BundleConfig = {
|
|
|
346
346
|
requires?: Record<string, string>;
|
|
347
347
|
prebundleOutDir?: string;
|
|
348
348
|
keepPrebundleDir?: boolean;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
outDir?: string;
|
|
350
|
+
build: (options: {
|
|
351
|
+
outDir: string;
|
|
352
|
+
prebundleDir: string;
|
|
353
|
+
entry: string;
|
|
354
|
+
}) => Promise<void>;
|
|
355
|
+
outputConfig?: VovkOutputConfig<GeneratorConfigImports>;
|
|
353
356
|
} & ({
|
|
354
357
|
excludeSegments?: never;
|
|
355
358
|
includeSegments?: string[];
|
|
@@ -366,7 +369,7 @@ type SegmentConfigImports = {
|
|
|
366
369
|
fetcher?: string | [string, string] | [string];
|
|
367
370
|
validateOnClient?: string | [string, string] | [string] | null;
|
|
368
371
|
};
|
|
369
|
-
export interface
|
|
372
|
+
export interface VovkOutputConfig<TImports extends GeneratorConfigImports = GeneratorConfigImports> {
|
|
370
373
|
origin?: string | null;
|
|
371
374
|
package?: VovkPackageJson;
|
|
372
375
|
readme?: VovkReadmeConfig;
|
|
@@ -381,7 +384,7 @@ export type ClientTemplateDef = {
|
|
|
381
384
|
composedClient?: Omit<ClientConfigComposed, 'fromTemplates' | 'enabled'>;
|
|
382
385
|
segmentedClient?: Omit<ClientConfigSegmented, 'fromTemplates' | 'enabled'>;
|
|
383
386
|
requires?: Record<string, string>;
|
|
384
|
-
|
|
387
|
+
outputConfig?: VovkOutputConfig<GeneratorConfigImports>;
|
|
385
388
|
};
|
|
386
389
|
export type GetOpenAPINameFn = (config: {
|
|
387
390
|
operationObject: VovkOperationObject;
|
|
@@ -413,7 +416,7 @@ export interface VovkOpenAPIMixinNormalized extends Omit<VovkOpenAPIMixin, 'sour
|
|
|
413
416
|
getMethodName: GetOpenAPINameFn;
|
|
414
417
|
getModuleName: GetOpenAPINameFn;
|
|
415
418
|
}
|
|
416
|
-
export interface VovkSegmentConfig extends
|
|
419
|
+
export interface VovkSegmentConfig extends VovkOutputConfig<SegmentConfigImports> {
|
|
417
420
|
rootEntry?: string;
|
|
418
421
|
segmentNameOverride?: string;
|
|
419
422
|
openAPIMixin?: VovkOpenAPIMixin;
|
|
@@ -440,7 +443,7 @@ type VovkUserConfig = {
|
|
|
440
443
|
controller?: string;
|
|
441
444
|
[key: string]: string | undefined;
|
|
442
445
|
};
|
|
443
|
-
|
|
446
|
+
outputConfig?: VovkOutputConfig<GeneratorConfigImports> & {
|
|
444
447
|
segments?: Record<string, VovkSegmentConfig>;
|
|
445
448
|
};
|
|
446
449
|
};
|
|
@@ -451,7 +454,7 @@ export type VovkStrictConfig = Required<Omit<VovkUserConfig, 'emitConfig' | 'lib
|
|
|
451
454
|
libs: Record<string, KnownAny>;
|
|
452
455
|
composedClient: RequireFields<ClientConfigComposed, 'enabled' | 'fromTemplates' | 'outDir' | 'prettifyClient'>;
|
|
453
456
|
segmentedClient: RequireFields<ClientConfigSegmented, 'enabled' | 'fromTemplates' | 'outDir' | 'prettifyClient'>;
|
|
454
|
-
|
|
457
|
+
outputConfig: VovkOutputConfig<GeneratorConfigImports> & {
|
|
455
458
|
segments?: Record<string, Omit<VovkSegmentConfig, 'openAPIMixin'> & {
|
|
456
459
|
openAPIMixin?: VovkOpenAPIMixinNormalized;
|
|
457
460
|
}>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PackageJson } from 'type-fest';
|
|
2
|
-
import type {
|
|
2
|
+
import type { VovkOutputConfig, VovkReadmeConfig, VovkSamplesConfig, VovkSchema } from '../types';
|
|
3
3
|
import type { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
4
4
|
export declare function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle, projectPackageJson, }: {
|
|
5
5
|
schema: VovkSchema;
|
|
6
|
-
configs?:
|
|
6
|
+
configs?: VovkOutputConfig[];
|
|
7
7
|
segmentName: string | null;
|
|
8
8
|
isBundle?: boolean;
|
|
9
9
|
projectPackageJson?: PackageJson;
|
|
@@ -13,6 +13,6 @@ export declare function resolveGeneratorConfigValues({ schema, configs, segmentN
|
|
|
13
13
|
samples: VovkSamplesConfig;
|
|
14
14
|
origin: string;
|
|
15
15
|
package: PackageJson;
|
|
16
|
-
imports:
|
|
17
|
-
reExports:
|
|
16
|
+
imports: VovkOutputConfig['imports'];
|
|
17
|
+
reExports: VovkOutputConfig['reExports'];
|
|
18
18
|
};
|
|
@@ -27,8 +27,8 @@ function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle,
|
|
|
27
27
|
types: './openapi.d.cts',
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
|
-
}, projectPackageJson, schema.meta?.config?.
|
|
31
|
-
? schema.meta?.config?.
|
|
30
|
+
}, projectPackageJson, schema.meta?.config?.outputConfig?.package, isBundle ? schema.meta?.config?.bundle?.outputConfig?.package : undefined, typeof segmentName === 'string' ? schema.segments?.[segmentName]?.meta?.package : undefined, typeof segmentName === 'string'
|
|
31
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.package
|
|
32
32
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.package), {}));
|
|
33
33
|
return {
|
|
34
34
|
package: Object.fromEntries(Object.entries(packageJson).filter(([key]) => ['name', 'version', 'description', 'license', 'authors', 'repository', 'homepage', 'bugs', 'keywords'].includes(key))),
|
|
@@ -39,21 +39,21 @@ function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle,
|
|
|
39
39
|
version: packageJson.version,
|
|
40
40
|
description: packageJson.description,
|
|
41
41
|
},
|
|
42
|
-
}, schema.meta?.config?.
|
|
43
|
-
? schema.meta?.config?.
|
|
42
|
+
}, schema.meta?.config?.outputConfig?.openAPIObject, isBundle ? schema.meta?.config?.bundle?.outputConfig?.openAPIObject : undefined, typeof segmentName === 'string' ? schema?.segments?.[segmentName]?.meta?.openAPIObject : undefined, typeof segmentName === 'string'
|
|
43
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.openAPIObject
|
|
44
44
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.openAPIObject), {})),
|
|
45
|
-
samples: (0, deepExtend_1.default)({}, schema.meta?.config?.
|
|
46
|
-
? schema.meta?.config?.
|
|
45
|
+
samples: (0, deepExtend_1.default)({}, schema.meta?.config?.outputConfig?.samples, isBundle ? schema.meta?.config?.bundle?.outputConfig?.samples : undefined, typeof segmentName === 'string'
|
|
46
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.samples
|
|
47
47
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.samples), {})),
|
|
48
|
-
readme: (0, deepExtend_1.default)({}, schema.meta?.config?.
|
|
49
|
-
? schema.meta?.config?.
|
|
48
|
+
readme: (0, deepExtend_1.default)({}, schema.meta?.config?.outputConfig?.readme, isBundle ? schema.meta?.config?.bundle?.outputConfig?.readme : undefined, typeof segmentName === 'string'
|
|
49
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.readme
|
|
50
50
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.readme), {})),
|
|
51
51
|
origin: [
|
|
52
|
-
isBundle ? schema.meta?.config?.bundle?.
|
|
52
|
+
isBundle ? schema.meta?.config?.bundle?.outputConfig?.origin : undefined,
|
|
53
53
|
typeof segmentName === 'string'
|
|
54
|
-
? schema.meta?.config?.
|
|
54
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.origin
|
|
55
55
|
: undefined,
|
|
56
|
-
schema.meta?.config?.
|
|
56
|
+
schema.meta?.config?.outputConfig?.origin,
|
|
57
57
|
...(configs?.map((config) => config.origin) ?? []),
|
|
58
58
|
]
|
|
59
59
|
.filter(Boolean)
|
|
@@ -64,19 +64,19 @@ function resolveGeneratorConfigValues({ schema, configs, segmentName, isBundle,
|
|
|
64
64
|
fetcher: ['vovk'],
|
|
65
65
|
validateOnClient: null,
|
|
66
66
|
createRPC: ['vovk'],
|
|
67
|
-
}, schema.meta?.config?.
|
|
68
|
-
? schema.meta?.config?.
|
|
67
|
+
}, schema.meta?.config?.outputConfig?.imports, isBundle ? schema.meta?.config?.bundle?.outputConfig?.imports : undefined, typeof segmentName === 'string'
|
|
68
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.imports
|
|
69
69
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.imports), {})),
|
|
70
70
|
reExports: (0, deepExtend_1.default)(
|
|
71
71
|
// segmentName can be an empty string (for the root segment) and null (for composed clients)
|
|
72
72
|
// therefore, !segmentName indicates that this either a composed client or a root segment of a segmented client
|
|
73
|
-
{}, !segmentName && schema.meta?.config?.
|
|
73
|
+
{}, !segmentName && schema.meta?.config?.outputConfig?.reExports, !segmentName && isBundle ? schema.meta?.config?.bundle?.outputConfig?.reExports : undefined,
|
|
74
74
|
// for segmented client, apply all reExports from all segments
|
|
75
75
|
typeof segmentName !== 'string' &&
|
|
76
|
-
Object.values(schema.meta?.config?.
|
|
76
|
+
Object.values(schema.meta?.config?.outputConfig?.segments ?? {}).reduce((acc, segmentConfig) => (0, deepExtend_1.default)(acc, segmentConfig.reExports ?? {}), {}),
|
|
77
77
|
// for a specific segment, apply reExports from that segment
|
|
78
78
|
typeof segmentName === 'string'
|
|
79
|
-
? schema.meta?.config?.
|
|
79
|
+
? schema.meta?.config?.outputConfig?.segments?.[segmentName]?.reExports
|
|
80
80
|
: undefined, configs?.reduce((acc, config) => (0, deepExtend_1.default)(acc, config.reExports), {})),
|
|
81
81
|
};
|
|
82
82
|
}
|