vovk 3.0.0-draft.53 → 3.0.0-draft.55

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > vovk@3.0.0-draft.53 build
3
+ > vovk@3.0.0-draft.55 build
4
4
  > tsc
5
5
 
6
6
  \
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > vovk@3.0.0-draft.52 tsc
3
+ > vovk@3.0.0-draft.53 tsc
4
4
  > tsc --noEmit
5
5
 
6
6
  \
@@ -26,7 +26,8 @@ const createRPC = (controllerSchema, segmentName, options) => {
26
26
  throw new Error(`Unable to clientize. No schema for controller ${String(schema?.controllerName)} provided`);
27
27
  const controllerPrefix = trimPath(schema.prefix ?? '');
28
28
  const { fetcher: settingsFetcher = defaultFetcher_1.default } = options ?? {};
29
- for (const [staticMethodName, { path, httpMethod, validation }] of Object.entries(schema.handlers)) {
29
+ for (const [staticMethodName, handlerSchema] of Object.entries(schema.handlers)) {
30
+ const { path, httpMethod, validation } = handlerSchema;
30
31
  const getEndpoint = ({ apiRoot, params, query, }) => {
31
32
  const mainPrefix = (apiRoot.startsWith('http://') || apiRoot.startsWith('https://') || apiRoot.startsWith('/') ? '' : '/') +
32
33
  (apiRoot.endsWith('/') ? apiRoot : `${apiRoot}/`) +
@@ -65,6 +66,7 @@ const createRPC = (controllerSchema, segmentName, options) => {
65
66
  return Promise.resolve(fetcherPromise);
66
67
  return input.transform ? fetcherPromise.then(input.transform) : fetcherPromise;
67
68
  };
69
+ handler.schema = handlerSchema;
68
70
  // @ts-expect-error TODO
69
71
  client[staticMethodName] = handler;
70
72
  }
@@ -1,4 +1,2 @@
1
- import { createRPC } from './createRPC';
2
- import type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient } from './types';
3
- export { createRPC };
4
- export type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient };
1
+ export { createRPC } from './createRPC';
2
+ export type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient } from './types';
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRPC = void 0;
4
- const createRPC_1 = require("./createRPC");
4
+ var createRPC_1 = require("./createRPC");
5
5
  Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return createRPC_1.createRPC; } });
@@ -1,4 +1,4 @@
1
- import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkControllerBody, VovkControllerQuery, VovkControllerParams } from '../types';
1
+ import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkControllerBody, VovkControllerQuery, VovkControllerParams, VovkHandlerSchema } from '../types';
2
2
  import type { StreamJSONResponse } from '../StreamJSONResponse';
3
3
  import type { NextResponse } from 'next/server';
4
4
  export type StaticMethodInput<T extends ControllerStaticMethod> = (VovkControllerBody<T> extends undefined | void ? {
@@ -26,7 +26,7 @@ export type StreamAsyncIterator<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 ClientMethod<T extends (...args: KnownAny[]) => void | object | StreamJSONResponse<STREAM> | Promise<StreamJSONResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = <R>(options: (StaticMethodInput<T> extends {
29
+ type ClientMethod<T extends (...args: KnownAny[]) => void | object | StreamJSONResponse<STREAM> | Promise<StreamJSONResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = (<R>(options: (StaticMethodInput<T> extends {
30
30
  body?: undefined | null;
31
31
  query?: undefined;
32
32
  params?: undefined;
@@ -34,7 +34,9 @@ type ClientMethod<T extends (...args: KnownAny[]) => void | object | StreamJSONR
34
34
  params: StaticMethodInput<T>['params'];
35
35
  } : unknown : StaticMethodInput<T>) & (Partial<OPTS & {
36
36
  transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
37
- }> | void)) => ReturnType<T> extends Promise<StreamJSONResponse<infer U>> | StreamJSONResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<StreamAsyncIterator<U>> : R extends object ? Promise<R> : StaticMethodReturnPromise<T>;
37
+ }> | void)) => ReturnType<T> extends Promise<StreamJSONResponse<infer U>> | StreamJSONResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<StreamAsyncIterator<U>> : R extends object ? Promise<R> : StaticMethodReturnPromise<T>) & {
38
+ schema: VovkHandlerSchema;
39
+ };
38
40
  type OmitNever<T> = {
39
41
  [K in keyof T as T[K] extends never ? never : K]: T[K];
40
42
  };
@@ -1,4 +1,4 @@
1
- import type { HandlerSchema, KnownAny, VovkController, VovkRequest } from './types';
1
+ import type { VovkHandlerSchema, KnownAny, VovkController, VovkRequest } from './types';
2
2
  type Next = () => Promise<unknown>;
3
- export declare function createDecorator<ARGS extends unknown[], REQUEST = VovkRequest>(handler: null | ((this: VovkController, req: REQUEST, next: Next, ...args: ARGS) => unknown), initHandler?: (this: VovkController, ...args: ARGS) => Omit<HandlerSchema, 'path' | 'httpMethod'> | ((handlerSchema: HandlerSchema | null) => Omit<HandlerSchema, 'path' | 'httpMethod'>) | null | undefined): (...args: ARGS) => (target: KnownAny, propertyKey: string) => void;
3
+ export declare function createDecorator<ARGS extends unknown[], REQUEST = VovkRequest>(handler: null | ((this: VovkController, req: REQUEST, next: Next, ...args: ARGS) => unknown), initHandler?: (this: VovkController, ...args: ARGS) => Omit<VovkHandlerSchema, 'path' | 'httpMethod'> | ((handlerSchema: VovkHandlerSchema | null) => Omit<VovkHandlerSchema, 'path' | 'httpMethod'>) | null | undefined): (...args: ARGS) => (target: KnownAny, propertyKey: string) => void;
4
4
  export {};
@@ -31,9 +31,11 @@ function createVovkApp() {
31
31
  controller._handlers = {
32
32
  ...controller._handlers,
33
33
  [propertyKey]: {
34
- ...(controller._handlers ?? {})[propertyKey],
35
34
  path,
36
35
  httpMethod,
36
+ validation: {},
37
+ custom: {},
38
+ ...(controller._handlers ?? {})[propertyKey],
37
39
  },
38
40
  };
39
41
  const originalMethod = controller[propertyKey];
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createVovkApp } from './createVovkApp';
2
- import { HttpStatus as HttpStatus, HttpMethod as HttpMethod, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkSchema, type VovkWorkerSchema, type VovkControllerSchema } from './types';
2
+ import { HttpStatus as HttpStatus, HttpMethod as HttpMethod, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkSchema, type VovkWorkerSchema, type VovkControllerSchema, type VovkHandlerSchema } from './types';
3
3
  import { type VovkClientOptions, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, createRPC } from './client';
4
4
  import { HttpException } from './HttpException';
5
5
  import { createDecorator } from './createDecorator';
@@ -7,7 +7,7 @@ import { StreamJSONResponse } from './StreamJSONResponse';
7
7
  import { worker, createWPC } from './worker';
8
8
  import { generateStaticAPI } from './utils/generateStaticAPI';
9
9
  import { setClientValidatorsForHandler } from './utils/setClientValidatorsForHandler';
10
- export { type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, type VovkWorkerSchema, type VovkControllerSchema, StreamJSONResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, worker, createWPC, createRPC, generateStaticAPI, setClientValidatorsForHandler, };
10
+ export { type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, type VovkWorkerSchema, type VovkControllerSchema, type VovkHandlerSchema, StreamJSONResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, worker, createWPC, createRPC, generateStaticAPI, setClientValidatorsForHandler, };
11
11
  export declare const get: {
12
12
  (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: import("./types").KnownAny, propertyKey: string) => void>;
13
13
  auto: (options?: import("./types").DecoratorOptions) => (givenTarget: import("./types").KnownAny, propertyKey: string) => void;
package/dist/types.d.ts CHANGED
@@ -3,20 +3,20 @@ import type { StreamJSONResponse } from './StreamJSONResponse';
3
3
  import { StreamAsyncIterator } from './client/types';
4
4
  export type KnownAny = any;
5
5
  export type StaticClass = Function;
6
- export type HandlerSchema = {
6
+ export type VovkHandlerSchema = {
7
7
  path: string;
8
8
  httpMethod: HttpMethod;
9
- validation?: {
9
+ validation: {
10
10
  query?: KnownAny;
11
11
  body?: KnownAny;
12
12
  };
13
- custom?: Record<string, KnownAny>;
13
+ custom: Record<string, KnownAny>;
14
14
  };
15
15
  export type VovkControllerSchema = {
16
16
  controllerName: string;
17
17
  originalControllerName: string;
18
18
  prefix?: string;
19
- handlers: Record<string, HandlerSchema>;
19
+ handlers: Record<string, VovkHandlerSchema>;
20
20
  };
21
21
  export type VovkWorkerSchema = {
22
22
  workerName: string;
@@ -22,7 +22,7 @@ function getSchema(options) {
22
22
  ? controller._handlers
23
23
  : Object.fromEntries(Object.entries(controller._handlers ?? {}).map(([key, value]) => [
24
24
  key,
25
- { ...value, validation: undefined },
25
+ { ...value, validation: {} },
26
26
  ]))),
27
27
  },
28
28
  };
@@ -1,3 +1,2 @@
1
- import { worker } from './worker';
2
- import { createWPC } from './createWPC';
3
- export { worker, createWPC };
1
+ export { worker } from './worker';
2
+ export { createWPC } from './createWPC';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createWPC = exports.worker = void 0;
4
- const worker_1 = require("./worker");
4
+ var worker_1 = require("./worker");
5
5
  Object.defineProperty(exports, "worker", { enumerable: true, get: function () { return worker_1.worker; } });
6
- const createWPC_1 = require("./createWPC");
6
+ var createWPC_1 = require("./createWPC");
7
7
  Object.defineProperty(exports, "createWPC", { enumerable: true, get: function () { return createWPC_1.createWPC; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.53",
3
+ "version": "3.0.0-draft.55",
4
4
  "main": "dist/index.js",
5
5
  "description": "RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.",
6
6
  "repository": {
@@ -42,7 +42,8 @@ export const createRPC = <T, OPTS extends Record<string, KnownAny> = VovkDefault
42
42
  const controllerPrefix = trimPath(schema.prefix ?? '');
43
43
  const { fetcher: settingsFetcher = defaultFetcher } = options ?? {};
44
44
 
45
- for (const [staticMethodName, { path, httpMethod, validation }] of Object.entries(schema.handlers)) {
45
+ for (const [staticMethodName, handlerSchema] of Object.entries(schema.handlers)) {
46
+ const { path, httpMethod, validation } = handlerSchema;
46
47
  const getEndpoint = ({
47
48
  apiRoot,
48
49
  params,
@@ -105,6 +106,8 @@ export const createRPC = <T, OPTS extends Record<string, KnownAny> = VovkDefault
105
106
  return input.transform ? fetcherPromise.then(input.transform) : fetcherPromise;
106
107
  };
107
108
 
109
+ handler.schema = handlerSchema;
110
+
108
111
  // @ts-expect-error TODO
109
112
  client[staticMethodName] = handler;
110
113
  }
@@ -1,5 +1,2 @@
1
- import { createRPC } from './createRPC';
2
- import type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient } from './types';
3
-
4
- export { createRPC };
5
- export type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient };
1
+ export { createRPC } from './createRPC';
2
+ export type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient } from './types';
@@ -5,6 +5,7 @@ import type {
5
5
  VovkControllerBody,
6
6
  VovkControllerQuery,
7
7
  VovkControllerParams,
8
+ VovkHandlerSchema,
8
9
  } from '../types';
9
10
  import type { StreamJSONResponse } from '../StreamJSONResponse';
10
11
  import type { NextResponse } from 'next/server';
@@ -40,7 +41,7 @@ type ClientMethod<
40
41
  T extends (...args: KnownAny[]) => void | object | StreamJSONResponse<STREAM> | Promise<StreamJSONResponse<STREAM>>,
41
42
  OPTS extends Record<string, KnownAny>,
42
43
  STREAM extends KnownAny = unknown,
43
- > = <R>(
44
+ > = (<R>(
44
45
  options: (StaticMethodInput<T> extends { body?: undefined | null; query?: undefined; params?: undefined }
45
46
  ? unknown
46
47
  : Parameters<T>[0] extends void
@@ -61,7 +62,9 @@ type ClientMethod<
61
62
  ? Promise<StreamAsyncIterator<U>>
62
63
  : R extends object
63
64
  ? Promise<R>
64
- : StaticMethodReturnPromise<T>;
65
+ : StaticMethodReturnPromise<T>) & {
66
+ schema: VovkHandlerSchema;
67
+ };
65
68
 
66
69
  type OmitNever<T> = {
67
70
  [K in keyof T as T[K] extends never ? never : K]: T[K];
@@ -1,4 +1,4 @@
1
- import type { HandlerSchema, KnownAny, VovkController, VovkRequest } from './types';
1
+ import type { VovkHandlerSchema, KnownAny, VovkController, VovkRequest } from './types';
2
2
 
3
3
  type Next = () => Promise<unknown>;
4
4
 
@@ -8,8 +8,8 @@ export function createDecorator<ARGS extends unknown[], REQUEST = VovkRequest>(
8
8
  this: VovkController,
9
9
  ...args: ARGS
10
10
  ) =>
11
- | Omit<HandlerSchema, 'path' | 'httpMethod'>
12
- | ((handlerSchema: HandlerSchema | null) => Omit<HandlerSchema, 'path' | 'httpMethod'>)
11
+ | Omit<VovkHandlerSchema, 'path' | 'httpMethod'>
12
+ | ((handlerSchema: VovkHandlerSchema | null) => Omit<VovkHandlerSchema, 'path' | 'httpMethod'>)
13
13
  | null
14
14
  | undefined
15
15
  ) {
@@ -25,7 +25,7 @@ export function createDecorator<ARGS extends unknown[], REQUEST = VovkRequest>(
25
25
  }
26
26
  const sourceMethod = originalMethod._sourceMethod ?? originalMethod;
27
27
 
28
- const handlerSchema: HandlerSchema | null = controller._handlers?.[propertyKey] ?? null;
28
+ const handlerSchema: VovkHandlerSchema | null = controller._handlers?.[propertyKey] ?? null;
29
29
  const initResultReturn = initHandler?.call(controller, ...args);
30
30
  const initResult = typeof initResultReturn === 'function' ? initResultReturn(handlerSchema) : initResultReturn;
31
31
 
@@ -7,6 +7,7 @@ import {
7
7
  type DecoratorOptions,
8
8
  type VovkRequest,
9
9
  type StaticClass,
10
+ VovkHandlerSchema,
10
11
  } from './types';
11
12
  import getSchema from './utils/getSchema';
12
13
 
@@ -47,9 +48,11 @@ export function createVovkApp() {
47
48
  controller._handlers = {
48
49
  ...controller._handlers,
49
50
  [propertyKey]: {
50
- ...(controller._handlers ?? {})[propertyKey],
51
51
  path,
52
52
  httpMethod,
53
+ validation: {},
54
+ custom: {},
55
+ ...((controller._handlers ?? {})[propertyKey] as Partial<VovkHandlerSchema>),
53
56
  },
54
57
  };
55
58
 
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  type VovkSchema,
17
17
  type VovkWorkerSchema,
18
18
  type VovkControllerSchema,
19
+ type VovkHandlerSchema,
19
20
  } from './types';
20
21
  import {
21
22
  type VovkClientOptions,
@@ -50,6 +51,7 @@ export {
50
51
  type VovkClientOptions,
51
52
  type VovkWorkerSchema,
52
53
  type VovkControllerSchema,
54
+ type VovkHandlerSchema,
53
55
  StreamJSONResponse,
54
56
  HttpException,
55
57
  HttpStatus,
package/src/types.ts CHANGED
@@ -6,18 +6,18 @@ export type KnownAny = any; // eslint-disable-line @typescript-eslint/no-explici
6
6
 
7
7
  export type StaticClass = Function; // eslint-disable-line @typescript-eslint/no-unsafe-function-type
8
8
 
9
- export type HandlerSchema = {
9
+ export type VovkHandlerSchema = {
10
10
  path: string;
11
11
  httpMethod: HttpMethod;
12
- validation?: { query?: KnownAny; body?: KnownAny };
13
- custom?: Record<string, KnownAny>;
12
+ validation: { query?: KnownAny; body?: KnownAny };
13
+ custom: Record<string, KnownAny>;
14
14
  };
15
15
 
16
16
  export type VovkControllerSchema = {
17
17
  controllerName: string;
18
18
  originalControllerName: string;
19
19
  prefix?: string;
20
- handlers: Record<string, HandlerSchema>;
20
+ handlers: Record<string, VovkHandlerSchema>;
21
21
  };
22
22
 
23
23
  export type VovkWorkerSchema = {
@@ -27,10 +27,7 @@ export default function getSchema(options: {
27
27
  ...(exposeValidation
28
28
  ? controller._handlers
29
29
  : Object.fromEntries(
30
- Object.entries(controller._handlers ?? {}).map(([key, value]) => [
31
- key,
32
- { ...value, validation: undefined },
33
- ])
30
+ Object.entries(controller._handlers ?? {}).map(([key, value]) => [key, { ...value, validation: {} }])
34
31
  )),
35
32
  },
36
33
  };
@@ -1,4 +1,2 @@
1
- import { worker } from './worker';
2
- import { createWPC } from './createWPC';
3
-
4
- export { worker, createWPC };
1
+ export { worker } from './worker';
2
+ export { createWPC } from './createWPC';