vovk 3.0.0-beta.21 → 3.0.0-beta.22

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/Segment.js CHANGED
@@ -128,7 +128,7 @@ class _Segment {
128
128
  req.vovk = {
129
129
  body: () => req.json(),
130
130
  query: () => (0, reqQuery_1.default)(req),
131
- meta: (metadata) => (0, reqMeta_1.default)(req, metadata),
131
+ meta: (meta) => (0, reqMeta_1.default)(req, meta),
132
132
  };
133
133
  try {
134
134
  const result = await staticMethod.call(controller, req, methodParams);
@@ -1,4 +1,4 @@
1
- import { type _VovkControllerMetadata as VovkControllerMetadata, type _KnownAny as KnownAny } from '../types';
1
+ import { type _VovkControllerSchema as VovkControllerSchema, type _KnownAny as KnownAny } from '../types';
2
2
  import { type _VovkClientOptions as VovkClientOptions, type _VovkClient as VovkClient, type _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions } from './types';
3
3
  export declare const ARRAY_QUERY_KEY = "_vovkarr";
4
- export declare const _clientizeController: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(givenController: VovkControllerMetadata, segmentName?: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
4
+ export declare const _clientizeController: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(givenController: VovkControllerSchema, segmentName?: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
@@ -38,13 +38,13 @@ const _clientizeController = (givenController, segmentName, options) => {
38
38
  const controller = givenController;
39
39
  const client = {};
40
40
  if (!controller)
41
- throw new Error(`Unable to clientize. Controller metadata is not provided`);
42
- const metadata = controller._handlers;
43
- if (!metadata)
44
- throw new Error(`Unable to clientize. No metadata for controller ${String(controller?._controllerName)}`);
41
+ throw new Error(`Unable to clientize. Controller schema is not provided`);
42
+ const schema = controller._handlers;
43
+ if (!schema)
44
+ throw new Error(`Unable to clientize. No schema for controller ${String(controller?._controllerName)}`);
45
45
  const controllerPrefix = trimPath(controller._prefix ?? '');
46
46
  const { fetcher: settingsFetcher = defaultFetcher_1.default } = options ?? {};
47
- for (const [staticMethodName, { path, httpMethod, clientValidators }] of Object.entries(metadata)) {
47
+ for (const [staticMethodName, { path, httpMethod, clientValidators }] of Object.entries(schema)) {
48
48
  const getEndpoint = ({ prefix, params, query, }) => {
49
49
  const mainPrefix = (prefix.startsWith('http://') || prefix.startsWith('https://') || prefix.startsWith('/') ? '' : '/') +
50
50
  (prefix.endsWith('/') ? prefix : `${prefix}/`) +
@@ -70,7 +70,6 @@ const _clientizeController = (givenController, segmentName, options) => {
70
70
  body: input.body ?? null,
71
71
  query: input.query ?? {},
72
72
  params: input.params ?? {},
73
- segmentName,
74
73
  // TS workaround
75
74
  fetcher: undefined,
76
75
  validateOnClient: undefined,
package/client/types.d.ts CHANGED
@@ -51,7 +51,6 @@ export type _VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<st
51
51
  httpMethod: HttpMethod;
52
52
  getEndpoint: (data: {
53
53
  prefix: string;
54
- segmentName?: string;
55
54
  params: {
56
55
  [key: string]: string;
57
56
  };
@@ -1,4 +1,4 @@
1
- import type { _HandlerMetadata as HandlerMetadata, _KnownAny as KnownAny, _VovkController as VovkController, _VovkRequest as VovkRequest } from './types';
1
+ import type { _HandlerSchema as HandlerSchema, _KnownAny as KnownAny, _VovkController as VovkController, _VovkRequest as 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<HandlerMetadata, 'path' | 'httpMethod'> | ((handlerMetadata: HandlerMetadata | null) => Omit<HandlerMetadata, '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<HandlerSchema, 'path' | 'httpMethod'> | ((handlerSchema: HandlerSchema | null) => Omit<HandlerSchema, 'path' | 'httpMethod'>) | null | undefined): (...args: ARGS) => (target: KnownAny, propertyKey: string) => void;
4
4
  export {};
@@ -10,16 +10,16 @@ function _createDecorator(handler, initHandler) {
10
10
  throw new Error(`Unable to decorate: ${propertyKey} is not a function`);
11
11
  }
12
12
  const sourceMethod = originalMethod._sourceMethod ?? originalMethod;
13
- const handlerMetadata = controller._handlers?.[propertyKey] ?? null;
13
+ const handlerSchema = controller._handlers?.[propertyKey] ?? null;
14
14
  const initResultReturn = initHandler?.call(controller, ...args);
15
- const initResult = typeof initResultReturn === 'function' ? initResultReturn(handlerMetadata) : initResultReturn;
15
+ const initResult = typeof initResultReturn === 'function' ? initResultReturn(handlerSchema) : initResultReturn;
16
16
  controller._handlers = {
17
17
  ...controller._handlers,
18
18
  [propertyKey]: {
19
- ...handlerMetadata,
19
+ ...handlerSchema,
20
20
  // avoid override of path and httpMethod
21
21
  ...(initResult?.clientValidators ? { clientValidators: initResult.clientValidators } : {}),
22
- ...(initResult?.customMetadata ? { customMetadata: initResult.customMetadata } : {}),
22
+ ...(initResult?.customSchema ? { customSchema: initResult.customSchema } : {}),
23
23
  },
24
24
  };
25
25
  const method = function method(req, params) {
@@ -34,7 +34,7 @@ export declare function _createSegment(): {
34
34
  controllers: Record<string, Function>;
35
35
  workers?: Record<string, Function>;
36
36
  exposeValidation?: boolean;
37
- emitMetadata?: boolean;
37
+ emitSchema?: boolean;
38
38
  onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
39
39
  }) => {
40
40
  GET: (req: VovkRequest, data: {
package/createSegment.js CHANGED
@@ -17,7 +17,7 @@ const toKebabCase = (str) => {
17
17
  function _createSegment() {
18
18
  const segment = new Segment_1._Segment();
19
19
  const getDecoratorCreator = (httpMethod) => {
20
- const assignMetadata = (controller, propertyKey, path, options) => {
20
+ const assignSchema = (controller, propertyKey, path, options) => {
21
21
  if (typeof window !== 'undefined') {
22
22
  throw new Error('Decorators are intended for server-side use only. You have probably imported a controller on the client-side.');
23
23
  }
@@ -47,7 +47,7 @@ function _createSegment() {
47
47
  const path = trimPath(givenPath);
48
48
  function decorator(givenTarget, propertyKey) {
49
49
  const target = givenTarget;
50
- assignMetadata(target, propertyKey, path, options);
50
+ assignSchema(target, propertyKey, path, options);
51
51
  }
52
52
  return decorator;
53
53
  }
@@ -63,7 +63,7 @@ function _createSegment() {
63
63
  httpMethod,
64
64
  },
65
65
  };
66
- assignMetadata(controller, propertyKey, toKebabCase(propertyKey), options);
66
+ assignSchema(controller, propertyKey, toKebabCase(propertyKey), options);
67
67
  }
68
68
  return decorator;
69
69
  };
@@ -80,19 +80,19 @@ function _createSegment() {
80
80
  return givenTarget;
81
81
  };
82
82
  };
83
- const getMetadata = (options) => {
83
+ const getSchema = (options) => {
84
84
  const exposeValidation = options?.exposeValidation ?? true;
85
- const emitMetadata = options.emitMetadata ?? true;
86
- const metadata = {
87
- emitMetadata,
85
+ const emitSchema = options.emitSchema ?? true;
86
+ const schema = {
87
+ emitSchema,
88
88
  segmentName: options.segmentName ?? '',
89
89
  controllers: {},
90
90
  workers: {},
91
91
  };
92
- if (!emitMetadata)
93
- return metadata;
92
+ if (!emitSchema)
93
+ return schema;
94
94
  for (const [controllerName, controller] of Object.entries(options.controllers)) {
95
- metadata.controllers[controllerName] = {
95
+ schema.controllers[controllerName] = {
96
96
  _controllerName: controllerName,
97
97
  _prefix: controller._prefix ?? '',
98
98
  _handlers: {
@@ -106,12 +106,12 @@ function _createSegment() {
106
106
  };
107
107
  }
108
108
  for (const [workerName, worker] of Object.entries(options.workers ?? {})) {
109
- metadata.workers[workerName] = {
109
+ schema.workers[workerName] = {
110
110
  _workerName: workerName,
111
111
  _handlers: { ...worker._handlers },
112
112
  };
113
113
  }
114
- return metadata;
114
+ return schema;
115
115
  };
116
116
  const initVovk = (options) => {
117
117
  for (const [controllerName, controller] of Object.entries(options.controllers)) {
@@ -122,10 +122,10 @@ function _createSegment() {
122
122
  async function GET_DEV(req, data) {
123
123
  const { params } = data;
124
124
  if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
125
- // Wait for metadata to be set (it can be set after decorators are called with another setTimeout)
125
+ // Wait for schema to be set (it can be set after decorators are called with another setTimeout)
126
126
  await new Promise((resolve) => setTimeout(resolve, 10));
127
- const metadata = getMetadata(options);
128
- return segment.respond(200, { metadata });
127
+ const schema = getSchema(options);
128
+ return segment.respond(200, { schema });
129
129
  }
130
130
  return segment.GET(req, data);
131
131
  }
package/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { _createSegment as createSegment } from './createSegment';
2
- import { type _VovkErrorResponse as VovkErrorResponse, type _VovkRequest as VovkRequest, type _VovkControllerBody as VovkControllerBody, type _VovkControllerQuery as VovkControllerQuery, type _VovkControllerParams as VovkControllerParams, type _VovkControllerReturnType as VovkControllerReturnType, type _VovkControlerYieldType as VovkControlerYieldType, type _VovkBody as VovkBody, type _VovkQuery as VovkQuery, type _VovkParams as VovkParams, type _VovkReturnType as VovkReturnType, type _VovkYieldType as VovkYieldType, type _VovkMetadata as VovkMetadata, _HttpStatus as HttpStatus, _HttpMethod as HttpMethod } from './types';
2
+ import { type _VovkErrorResponse as VovkErrorResponse, type _VovkRequest as VovkRequest, type _VovkControllerBody as VovkControllerBody, type _VovkControllerQuery as VovkControllerQuery, type _VovkControllerParams as VovkControllerParams, type _VovkControllerReturnType as VovkControllerReturnType, type _VovkControlerYieldType as VovkControlerYieldType, type _VovkBody as VovkBody, type _VovkQuery as VovkQuery, type _VovkParams as VovkParams, type _VovkReturnType as VovkReturnType, type _VovkYieldType as VovkYieldType, type _VovkSchema as VovkSchema, _HttpStatus as HttpStatus, _HttpMethod as HttpMethod } from './types';
3
3
  import type { _VovkClientOptions as VovkClientOptions, _VovkClientFetcher as VovkClientFetcher, _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions, _VovkValidateOnClient as VovkValidateOnClient } from './client/types';
4
4
  import { _HttpException as HttpException } from './HttpException';
5
5
  import { _createDecorator as createDecorator } from './createDecorator';
6
6
  import { _StreamResponse as StreamResponse } from './StreamResponse';
7
7
  import { worker } from './worker';
8
8
  import { _generateStaticAPI as generateStaticAPI } from './generateStaticAPI';
9
- export { type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkMetadata, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerReturnType, type VovkControlerYieldType, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkClientOptions, StreamResponse, HttpException, HttpStatus, HttpMethod, createSegment, createDecorator, worker, generateStaticAPI, };
9
+ export { type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerReturnType, type VovkControlerYieldType, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkClientOptions, StreamResponse, HttpException, HttpStatus, HttpMethod, createSegment, createDecorator, worker, generateStaticAPI, };
10
10
  export declare const get: {
11
11
  (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
12
12
  auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
@@ -33,7 +33,7 @@ export declare const get: {
33
33
  controllers: Record<string, Function>;
34
34
  workers?: Record<string, Function>;
35
35
  exposeValidation?: boolean;
36
- emitMetadata?: boolean;
36
+ emitSchema?: boolean;
37
37
  onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
38
38
  }) => {
39
39
  GET: (req: VovkRequest, data: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-beta.21",
3
+ "version": "3.0.0-beta.22",
4
4
  "description": "RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.",
5
5
  "repository": {
6
6
  "type": "git",
package/types.d.ts CHANGED
@@ -2,45 +2,45 @@ import type { NextRequest } from 'next/server';
2
2
  import type { _StreamResponse as StreamResponse } from './StreamResponse';
3
3
  import { _StreamAsyncIterator as StreamAsyncIterator } from './client/types';
4
4
  export type _KnownAny = any;
5
- export type _VovkMetadata = {
6
- emitMetadata: boolean;
5
+ export type _VovkSchema = {
6
+ emitSchema: boolean;
7
7
  segmentName: string;
8
- workers: Record<string, _VovkWorkerMetadata>;
9
- controllers: Record<string, _VovkControllerMetadata>;
8
+ workers: Record<string, _VovkWorkerSchema>;
9
+ controllers: Record<string, _VovkControllerSchema>;
10
10
  };
11
11
  export type _VovkErrorResponse = {
12
12
  statusCode: _HttpStatus;
13
13
  message: string;
14
14
  isError: true;
15
15
  };
16
- export type _HandlerMetadata = {
16
+ export type _HandlerSchema = {
17
17
  path: string;
18
18
  httpMethod: _HttpMethod;
19
19
  clientValidators?: {
20
20
  query?: _KnownAny;
21
21
  body?: _KnownAny;
22
22
  };
23
- customMetadata?: Record<string, _KnownAny>;
23
+ customSchema?: Record<string, _KnownAny>;
24
24
  };
25
- export type _VovkControllerMetadata = {
25
+ export type _VovkControllerSchema = {
26
26
  _controllerName: string;
27
27
  _prefix?: string;
28
- _handlers: Record<string, _HandlerMetadata>;
28
+ _handlers: Record<string, _HandlerSchema>;
29
29
  };
30
- export type _VovkWorkerMetadata = {
30
+ export type _VovkWorkerSchema = {
31
31
  _workerName: string;
32
32
  _handlers: Record<string, {
33
33
  isGenerator?: true;
34
34
  }>;
35
35
  };
36
- export type _VovkControllerInternal = _VovkControllerMetadata & {
36
+ export type _VovkControllerInternal = _VovkControllerSchema & {
37
37
  _activated?: true;
38
38
  _onError?: (err: Error, req: _VovkRequest) => void | Promise<void>;
39
39
  };
40
40
  export type _VovkController = Function & _VovkControllerInternal & {
41
41
  [key: string]: unknown;
42
42
  };
43
- export type _VovkWorker = Function & _VovkWorkerMetadata & {
43
+ export type _VovkWorker = Function & _VovkWorkerSchema & {
44
44
  [key: string]: unknown;
45
45
  };
46
46
  export type _DecoratorOptions = {
@@ -66,7 +66,7 @@ export interface _VovkRequest<BODY = undefined, QUERY extends object | undefined
66
66
  vovk: {
67
67
  body: () => Promise<BODY>;
68
68
  query: () => QUERY;
69
- meta: <T = Record<_KnownAny, _KnownAny>>(metadata?: T | null) => T;
69
+ meta: <T = Record<_KnownAny, _KnownAny>>(meta?: T | null) => T;
70
70
  };
71
71
  }
72
72
  export type _ControllerStaticMethod<REQ extends _VovkRequest<undefined, _KnownAny> = _VovkRequest<undefined, Record<string, string | string[]>>, PARAMS extends {
@@ -1,3 +1,3 @@
1
1
  import { VovkRequest } from 'vovk';
2
2
  import { _KnownAny as KnownAny } from '../types';
3
- export default function reqMeta<T = Record<KnownAny, KnownAny>>(req: VovkRequest<KnownAny, KnownAny>, metadata?: T | null): T;
3
+ export default function reqMeta<T = Record<KnownAny, KnownAny>>(req: VovkRequest<KnownAny, KnownAny>, meta?: T | null): T;
package/utils/reqMeta.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = reqMeta;
4
- const metadataMap = new WeakMap();
5
- function reqMeta(req, metadata) {
6
- if (metadata) {
7
- metadataMap.set(req, { ...metadataMap.get(req), ...metadata });
4
+ const metaMap = new WeakMap();
5
+ function reqMeta(req, meta) {
6
+ if (meta) {
7
+ metaMap.set(req, { ...metaMap.get(req), ...meta });
8
8
  }
9
- else if (metadata === null) {
10
- metadataMap.delete(req);
9
+ else if (meta === null) {
10
+ metaMap.delete(req);
11
11
  }
12
- return (metadataMap.get(req) ?? {});
12
+ return (metaMap.get(req) ?? {});
13
13
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._promisifyWorker = _promisifyWorker;
4
4
  function _promisifyWorker(currentWorker, givenWorkerService) {
5
5
  if (!givenWorkerService)
6
- throw new Error('Worker metadata is not provided');
6
+ throw new Error('Worker schema is not provided');
7
7
  const workerService = givenWorkerService;
8
8
  const instance = {
9
9
  worker: currentWorker,
package/worker/worker.js CHANGED
@@ -5,7 +5,7 @@ function _worker() {
5
5
  return (t) => {
6
6
  const target = t;
7
7
  target._handlers = {};
8
- // Experimental: You can pass Worker Service instead of metadata to prommisify worker
8
+ // TODO: Experimental: You can pass Worker Service instead of schema to prommisify worker
9
9
  for (const key of Object.getOwnPropertyNames(target)) {
10
10
  const member = target[key];
11
11
  if (typeof member === 'function') {