vovk 3.0.0-draft.81 → 3.0.0-draft.83

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/VovkApp.js CHANGED
@@ -131,6 +131,7 @@ class VovkApp {
131
131
  query: () => (0, reqQuery_1.default)(req),
132
132
  meta: (meta) => (0, reqMeta_1.default)(req, meta),
133
133
  form: () => (0, reqForm_1.default)(req),
134
+ params: () => methodParams,
134
135
  };
135
136
  try {
136
137
  const result = await staticMethod.call(controller, req, methodParams);
@@ -35,8 +35,8 @@ const createRPC = (controllerSchema, segmentName, options) => {
35
35
  };
36
36
  const handler = (input = {}) => {
37
37
  const fetcher = input.fetcher ?? settingsFetcher;
38
- const validate = async ({ body, query, endpoint }) => {
39
- await (input.validateOnClient ?? options?.validateOnClient)?.({ body, query, endpoint }, validation ?? {});
38
+ const validate = async ({ body, query, params, endpoint, }) => {
39
+ await (input.validateOnClient ?? options?.validateOnClient)?.({ body, query, params, endpoint }, validation ?? {});
40
40
  };
41
41
  const internalOptions = {
42
42
  name: staticMethodName,
@@ -10,7 +10,7 @@ const defaultFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandle
10
10
  const endpoint = getEndpoint({ apiRoot, params, query });
11
11
  if (!options.disableClientValidation) {
12
12
  try {
13
- await validate({ body, query, endpoint });
13
+ await validate({ body, query, params, endpoint });
14
14
  }
15
15
  catch (e) {
16
16
  // if HttpException is thrown, rethrow it
@@ -64,6 +64,7 @@ export type VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<str
64
64
  validate: (input: {
65
65
  body?: unknown;
66
66
  query?: unknown;
67
+ params?: unknown;
67
68
  endpoint: string;
68
69
  }) => void | Promise<void>;
69
70
  defaultStreamHandler: (response: Response) => Promise<VovkStreamAsyncIterable<unknown>>;
@@ -90,6 +91,7 @@ export interface VovkDefaultFetcherOptions extends Omit<RequestInit, 'body' | 'm
90
91
  export type VovkValidateOnClient = (input: {
91
92
  body?: unknown;
92
93
  query?: unknown;
94
+ params?: unknown;
93
95
  endpoint: string;
94
96
  }, validation: Exclude<VovkHandlerSchema['validation'], undefined>) => void | Promise<void>;
95
97
  export type VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
@@ -7,7 +7,11 @@ function fromSchema(apiRoot, vovkSchema, extendWith) {
7
7
  for (const c of Object.values(schema.controllers)) {
8
8
  for (const h of Object.values(c.handlers)) {
9
9
  if (h.openapi) {
10
- const path = '/' + [apiRoot.replace(/^\/+|\/+$/g, ''), segmentName, c.prefix, h.path].filter(Boolean).join('/');
10
+ const path = '/' +
11
+ [apiRoot.replace(/^\/+|\/+$/g, ''), segmentName, c.prefix, h.path]
12
+ .filter(Boolean)
13
+ .join('/')
14
+ .replace(/:([a-zA-Z0-9_]+)/g, '{$1}');
11
15
  paths[path] = paths[path] ?? {};
12
16
  paths[path][h.httpMethod.toLowerCase()] = { ...h.openapi };
13
17
  }
@@ -47,9 +47,7 @@ const openapiDecorator = (0, createDecorator_1.createDecorator)(null, (openAPIOp
47
47
  'type' in handlerSchema.validation.query &&
48
48
  'properties' in handlerSchema.validation.query
49
49
  ? {
50
- parameters: Object.entries(handlerSchema.validation.query.properties)
51
- // .filter(([, propSchema]) => propSchema.type !== 'object')
52
- .map(([propName, propSchema]) => ({
50
+ parameters: Object.entries(handlerSchema.validation.query.properties).map(([propName, propSchema]) => ({
53
51
  name: propName,
54
52
  in: 'query',
55
53
  description: propSchema.description || '',
@@ -62,6 +60,23 @@ const openapiDecorator = (0, createDecorator_1.createDecorator)(null, (openAPIOp
62
60
  })),
63
61
  }
64
62
  : {}),
63
+ ...(handlerSchema?.validation?.params &&
64
+ 'type' in handlerSchema.validation.params &&
65
+ 'properties' in handlerSchema.validation.params
66
+ ? {
67
+ parameters: Object.entries(handlerSchema.validation.params.properties).map(([propName, propSchema]) => ({
68
+ name: propName,
69
+ in: 'path',
70
+ description: propSchema.description || '',
71
+ required: handlerSchema.validation?.params.required
72
+ ? handlerSchema.validation.params.required.includes(propName)
73
+ : false,
74
+ schema: {
75
+ type: 'string',
76
+ },
77
+ })),
78
+ }
79
+ : {}),
65
80
  ...openAPIOperationObject,
66
81
  },
67
82
  });
package/dist/types.d.ts CHANGED
@@ -11,6 +11,7 @@ export type VovkHandlerSchema = {
11
11
  query?: KnownAny;
12
12
  body?: KnownAny;
13
13
  output?: KnownAny;
14
+ params?: KnownAny;
14
15
  };
15
16
  openapi?: OperationObject;
16
17
  custom?: Record<string, KnownAny>;
@@ -66,6 +67,7 @@ export interface VovkRequest<BODY = undefined, QUERY extends object | undefined
66
67
  query: () => QUERY;
67
68
  meta: <T = Record<KnownAny, KnownAny>>(meta?: T | null) => T;
68
69
  form: <T = KnownAny>() => Promise<T>;
70
+ params: <T extends Record<string, string> = Record<string, string>>() => T;
69
71
  };
70
72
  }
71
73
  export type ControllerStaticMethod<REQ extends VovkRequest<KnownAny, KnownAny> = VovkRequest<undefined, Record<string, KnownAny>>, PARAMS extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.81",
3
+ "version": "3.0.0-draft.83",
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": {