vovk 3.0.0-draft.91 → 3.0.0-draft.93

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/LICENSE CHANGED
@@ -16,7 +16,7 @@
16
16
  "nextjs",
17
17
  "router"
18
18
  ],
19
- "author": "Andrii Gubanov",
19
+ "author": "Andrey Gubanov",
20
20
  "license": "MIT",
21
21
  "bugs": {
22
22
  "url": "https://github.com/finom/vovk/issues"
package/dist/VovkApp.js CHANGED
@@ -177,7 +177,7 @@ class VovkApp {
177
177
  console.error(onErrorError);
178
178
  }
179
179
  if (err.message !== 'NEXT_REDIRECT' && err.message !== 'NEXT_NOT_FOUND') {
180
- const statusCode = err.statusCode ?? types_1.HttpStatus.INTERNAL_SERVER_ERROR;
180
+ const statusCode = err.statusCode || types_1.HttpStatus.INTERNAL_SERVER_ERROR;
181
181
  return this.#respondWithError(statusCode, err.message, staticMethod._options, err.cause);
182
182
  }
183
183
  throw e; // if NEXT_REDIRECT or NEXT_NOT_FOUND, rethrow it
@@ -1,4 +1,3 @@
1
1
  import type { KnownAny, VovkFullSchema } from '../types';
2
2
  import type { VovkClientOptions, VovkClient, VovkDefaultFetcherOptions } from './types';
3
- declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(fullSchema: VovkFullSchema, segmentName: string, controllerName: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
4
- export default createRPC;
3
+ export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(fullSchema: VovkFullSchema, segmentName: string, controllerName: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const defaultFetcher_1 = __importDefault(require("./defaultFetcher"));
6
+ exports.createRPC = void 0;
7
+ const fetcher_1 = require("./fetcher");
7
8
  const defaultHandler_1 = require("./defaultHandler");
8
9
  const defaultStreamHandler_1 = require("./defaultStreamHandler");
9
10
  const serializeQuery_1 = __importDefault(require("../utils/serializeQuery"));
@@ -25,7 +26,7 @@ const createRPC = (fullSchema, segmentName, controllerName, options) => {
25
26
  if (!controllerSchema)
26
27
  throw new Error(`Unable to create RPC object. Controller schema is missing. Check client template.`);
27
28
  const controllerPrefix = trimPath(controllerSchema.prefix ?? '');
28
- const { fetcher: settingsFetcher = defaultFetcher_1.default } = options ?? {};
29
+ const { fetcher: settingsFetcher = fetcher_1.fetcher } = options ?? {};
29
30
  for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers)) {
30
31
  const { path, httpMethod, validation } = handlerSchema;
31
32
  const getEndpoint = ({ apiRoot, params, query, }) => {
@@ -42,7 +43,7 @@ const createRPC = (fullSchema, segmentName, controllerName, options) => {
42
43
  if (typeof validateOnClient !== 'function') {
43
44
  throw new Error('validateOnClient must be a function');
44
45
  }
45
- await validateOnClient({ body, query, params, endpoint }, validation ?? {});
46
+ await validateOnClient({ body, query, params, endpoint }, validation ?? {}, fullSchema);
46
47
  }
47
48
  };
48
49
  const internalOptions = {
@@ -81,4 +82,4 @@ const createRPC = (fullSchema, segmentName, controllerName, options) => {
81
82
  }
82
83
  return client;
83
84
  };
84
- exports.default = createRPC;
85
+ exports.createRPC = createRPC;
@@ -1,4 +1,3 @@
1
1
  import type { VovkDefaultFetcherOptions, VovkClientFetcher } from './types';
2
2
  export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at the defaultFetcher";
3
- declare const defaultFetcher: VovkClientFetcher<VovkDefaultFetcherOptions>;
4
- export default defaultFetcher;
3
+ export declare const fetcher: VovkClientFetcher<VovkDefaultFetcherOptions>;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_ERROR_MESSAGE = void 0;
3
+ exports.fetcher = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
4
  const types_1 = require("../types");
5
5
  const HttpException_1 = require("../HttpException");
6
6
  exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at the 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, apiRoot = '/api', ...options }) => {
9
+ const fetcher = async ({ httpMethod, getEndpoint, validate, defaultHandler, defaultStreamHandler }, { params, query, body, apiRoot = '/api', ...options }) => {
10
10
  const endpoint = getEndpoint({ apiRoot, params, query });
11
11
  if (!options.disableClientValidation) {
12
12
  try {
@@ -57,4 +57,4 @@ const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandle
57
57
  }
58
58
  return response;
59
59
  };
60
- exports.default = defaultFetcher;
60
+ exports.fetcher = fetcher;
@@ -1,2 +1,3 @@
1
- export { default as createRPC } from './createRPC';
1
+ export { createRPC } from './createRPC';
2
+ export { fetcher } from './fetcher';
2
3
  export type { VovkClient, VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions, VovkValidateOnClient, VovkStreamAsyncIterable, } from './types';
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createRPC = void 0;
3
+ exports.fetcher = exports.createRPC = void 0;
7
4
  var createRPC_1 = require("./createRPC");
8
- Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return __importDefault(createRPC_1).default; } });
5
+ Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return createRPC_1.createRPC; } });
6
+ var fetcher_1 = require("./fetcher");
7
+ Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return fetcher_1.fetcher; } });
@@ -95,7 +95,7 @@ export type VovkValidateOnClient = (input: {
95
95
  query?: unknown;
96
96
  params?: unknown;
97
97
  endpoint: string;
98
- }, validation: Exclude<VovkHandlerSchema['validation'], undefined>) => void | Promise<void>;
98
+ }, validation: Exclude<VovkHandlerSchema['validation'], undefined>, fullSchema: VovkFullSchema) => void | Promise<void>;
99
99
  export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
100
100
  fetcher?: VovkClientFetcher<OPTS>;
101
101
  validateOnClient?: VovkValidateOnClient;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { createVovkApp } from './createVovkApp';
2
2
  import { HttpStatus as HttpStatus, HttpMethod as HttpMethod, type KnownAny, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkControllerOutput, type VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkEnv } from './types';
3
- import { type VovkClient, type VovkClientOptions, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC } from './client';
3
+ import { type VovkClient, type VovkClientOptions, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher } from './client';
4
4
  import { HttpException } from './HttpException';
5
5
  import { createDecorator } from './createDecorator';
6
6
  import { StreamJSONResponse } from './StreamJSONResponse';
7
7
  import { generateStaticAPI } from './utils/generateStaticAPI';
8
8
  import { setHandlerValidation } from './utils/setHandlerValidation';
9
- export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type VovkSegmentSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkControllerOutput, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkEnv, StreamJSONResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, generateStaticAPI, setHandlerValidation, };
9
+ export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkStreamAsyncIterable, type VovkValidateOnClient, type VovkSegmentSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkControllerOutput, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, type VovkControllerSchema, type VovkHandlerSchema, type VovkFullSchema, type VovkConfig, type VovkStrictConfig, type VovkEnv, StreamJSONResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, generateStaticAPI, setHandlerValidation, };
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.setHandlerValidation = exports.generateStaticAPI = exports.createRPC = exports.createDecorator = exports.createVovkApp = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.StreamJSONResponse = void 0;
4
+ exports.initVovk = exports.prefix = exports.options = exports.head = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.setHandlerValidation = exports.generateStaticAPI = exports.fetcher = exports.createRPC = exports.createDecorator = exports.createVovkApp = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.StreamJSONResponse = 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");
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function (
9
9
  Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return types_1.HttpMethod; } });
10
10
  const client_1 = require("./client");
11
11
  Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return client_1.createRPC; } });
12
+ Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return client_1.fetcher; } });
12
13
  const HttpException_1 = require("./HttpException");
13
14
  Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return HttpException_1.HttpException; } });
14
15
  const createDecorator_1 = require("./createDecorator");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.91",
3
+ "version": "3.0.0-draft.93",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "description": "RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.",
@@ -20,7 +20,7 @@
20
20
  "nextjs",
21
21
  "router"
22
22
  ],
23
- "author": "Andrii Gubanov",
23
+ "author": "Andrey Gubanov",
24
24
  "license": "MIT",
25
25
  "bugs": {
26
26
  "url": "https://github.com/finom/vovk/issues"