vovk 3.0.0-draft.239 → 3.0.0-draft.241

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.
Files changed (81) hide show
  1. package/cjs/HttpException.d.ts +1 -1
  2. package/cjs/JSONLinesResponse.d.ts +0 -12
  3. package/cjs/JSONLinesResponse.js +0 -20
  4. package/cjs/VovkApp.d.ts +1 -1
  5. package/cjs/VovkApp.js +38 -28
  6. package/cjs/client/createRPC.d.ts +2 -2
  7. package/cjs/client/createRPC.js +17 -14
  8. package/cjs/client/defaultHandler.js +3 -3
  9. package/cjs/client/defaultStreamHandler.d.ts +2 -2
  10. package/cjs/client/defaultStreamHandler.js +5 -5
  11. package/cjs/client/fetcher.d.ts +2 -2
  12. package/cjs/client/fetcher.js +7 -9
  13. package/cjs/client/index.d.ts +4 -3
  14. package/cjs/client/index.js +8 -6
  15. package/cjs/{utils → client}/progressive.d.ts +1 -1
  16. package/cjs/{utils → client}/progressive.js +5 -17
  17. package/cjs/client/types.d.ts +2 -2
  18. package/cjs/createVovkApp.d.ts +2 -2
  19. package/cjs/createVovkApp.js +14 -14
  20. package/cjs/index.d.ts +4 -5
  21. package/cjs/index.js +3 -4
  22. package/cjs/openapi/openAPIToVovkSchema.d.ts +3 -1
  23. package/cjs/openapi/openAPIToVovkSchema.js +95 -18
  24. package/cjs/openapi/vovkSchemaToOpenAPI.js +1 -5
  25. package/cjs/types.d.ts +13 -12
  26. package/cjs/utils/createDecorator.d.ts +1 -1
  27. package/cjs/utils/generateStaticAPI.d.ts +1 -1
  28. package/cjs/utils/generateStaticAPI.js +1 -1
  29. package/cjs/utils/getSchema.d.ts +3 -3
  30. package/cjs/utils/getSchema.js +3 -2
  31. package/cjs/utils/jsonSchemaSampler.js +2 -0
  32. package/cjs/utils/parseQuery.d.ts +1 -1
  33. package/cjs/utils/reqForm.d.ts +1 -1
  34. package/cjs/utils/reqMeta.d.ts +1 -1
  35. package/cjs/utils/reqQuery.d.ts +1 -1
  36. package/cjs/utils/reqQuery.js +2 -2
  37. package/cjs/utils/serializeQuery.d.ts +1 -1
  38. package/cjs/utils/setHandlerSchema.d.ts +1 -1
  39. package/cjs/utils/withValidationLibrary.d.ts +1 -1
  40. package/cjs/utils/withValidationLibrary.js +10 -10
  41. package/mjs/HttpException.d.ts +1 -1
  42. package/mjs/JSONLinesResponse.d.ts +0 -12
  43. package/mjs/JSONLinesResponse.js +0 -20
  44. package/mjs/VovkApp.d.ts +1 -1
  45. package/mjs/VovkApp.js +38 -28
  46. package/mjs/client/createRPC.d.ts +2 -2
  47. package/mjs/client/createRPC.js +17 -14
  48. package/mjs/client/defaultHandler.js +3 -3
  49. package/mjs/client/defaultStreamHandler.d.ts +2 -2
  50. package/mjs/client/defaultStreamHandler.js +5 -5
  51. package/mjs/client/fetcher.d.ts +2 -2
  52. package/mjs/client/fetcher.js +7 -9
  53. package/mjs/client/index.d.ts +4 -3
  54. package/mjs/client/index.js +8 -6
  55. package/mjs/{utils → client}/progressive.d.ts +1 -1
  56. package/mjs/{utils → client}/progressive.js +5 -17
  57. package/mjs/client/types.d.ts +2 -2
  58. package/mjs/createVovkApp.d.ts +2 -2
  59. package/mjs/createVovkApp.js +14 -14
  60. package/mjs/index.d.ts +4 -5
  61. package/mjs/index.js +3 -4
  62. package/mjs/openapi/openAPIToVovkSchema.d.ts +3 -1
  63. package/mjs/openapi/openAPIToVovkSchema.js +95 -18
  64. package/mjs/openapi/vovkSchemaToOpenAPI.js +1 -5
  65. package/mjs/types.d.ts +13 -12
  66. package/mjs/utils/createDecorator.d.ts +1 -1
  67. package/mjs/utils/generateStaticAPI.d.ts +1 -1
  68. package/mjs/utils/generateStaticAPI.js +1 -1
  69. package/mjs/utils/getSchema.d.ts +2 -2
  70. package/mjs/utils/getSchema.js +3 -2
  71. package/mjs/utils/jsonSchemaSampler.js +2 -0
  72. package/mjs/utils/parseQuery.d.ts +1 -1
  73. package/mjs/utils/reqForm.d.ts +1 -1
  74. package/mjs/utils/reqMeta.d.ts +1 -1
  75. package/mjs/utils/reqQuery.d.ts +1 -1
  76. package/mjs/utils/reqQuery.js +2 -2
  77. package/mjs/utils/serializeQuery.d.ts +1 -1
  78. package/mjs/utils/setHandlerSchema.d.ts +1 -1
  79. package/mjs/utils/withValidationLibrary.d.ts +1 -1
  80. package/mjs/utils/withValidationLibrary.js +10 -10
  81. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { HttpStatus } from './types.js';
1
+ import type { HttpStatus } from './types';
2
2
  export declare class HttpException extends Error {
3
3
  statusCode: HttpStatus;
4
4
  message: string;
@@ -12,16 +12,4 @@ export declare class JSONLinesResponse<T> extends Response {
12
12
  throw(e: KnownAny): void;
13
13
  [Symbol.dispose](): void;
14
14
  [Symbol.asyncDispose](): void;
15
- private nextValueReject;
16
- private nextValueResolve;
17
- private nextValue;
18
- [Symbol.asyncIterator](): {
19
- next: () => Promise<{
20
- done: boolean;
21
- value: null;
22
- } | {
23
- done: boolean;
24
- value: Awaited<T>;
25
- }>;
26
- };
27
15
  }
@@ -39,7 +39,6 @@ class JSONLinesResponse extends Response {
39
39
  const { controller, encoder } = this;
40
40
  if (this.isClosed)
41
41
  return;
42
- this.nextValueResolve(data);
43
42
  return controller?.enqueue(encoder.encode(JSON.stringify(data) + '\n'));
44
43
  }
45
44
  close() {
@@ -51,7 +50,6 @@ class JSONLinesResponse extends Response {
51
50
  }
52
51
  throw(e) {
53
52
  this.send({ isError: true, reason: e instanceof Error ? e.message : e });
54
- this.nextValueReject(e);
55
53
  return this.close();
56
54
  }
57
55
  [Symbol.dispose]() {
@@ -60,23 +58,5 @@ class JSONLinesResponse extends Response {
60
58
  [Symbol.asyncDispose]() {
61
59
  this.close();
62
60
  }
63
- nextValueReject = () => { };
64
- nextValueResolve = () => { };
65
- nextValue() {
66
- const { resolve, reject, promise } = Promise.withResolvers();
67
- this.nextValueResolve = resolve;
68
- this.nextValueReject = reject;
69
- return promise;
70
- }
71
- [Symbol.asyncIterator]() {
72
- return {
73
- next: async () => {
74
- if (this.isClosed) {
75
- return { done: true, value: null };
76
- }
77
- return { done: false, value: await this.nextValue() };
78
- },
79
- };
80
- }
81
61
  }
82
62
  exports.JSONLinesResponse = JSONLinesResponse;
package/cjs/VovkApp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { NextRequest } from 'next/server';
2
- import { HttpMethod, HttpStatus, type RouteHandler, type VovkController, type DecoratorOptions } from './types.js';
2
+ import { HttpMethod, HttpStatus, type RouteHandler, type VovkController, type DecoratorOptions } from './types';
3
3
  export declare class VovkApp {
4
4
  #private;
5
5
  private static getHeadersFromOptions;
package/cjs/VovkApp.js CHANGED
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.VovkApp = void 0;
8
- const types_js_1 = require("./types.js");
9
- const HttpException_js_1 = require("./HttpException.js");
10
- const JSONLinesResponse_js_1 = require("./JSONLinesResponse.js");
11
- const reqQuery_js_1 = __importDefault(require("./utils/reqQuery.js"));
12
- const reqMeta_js_1 = __importDefault(require("./utils/reqMeta.js"));
13
- const reqForm_js_1 = __importDefault(require("./utils/reqForm.js"));
8
+ const types_1 = require("./types");
9
+ const HttpException_1 = require("./HttpException");
10
+ const JSONLinesResponse_1 = require("./JSONLinesResponse");
11
+ const reqQuery_1 = __importDefault(require("./utils/reqQuery"));
12
+ const reqMeta_1 = __importDefault(require("./utils/reqMeta"));
13
+ const reqForm_1 = __importDefault(require("./utils/reqForm"));
14
14
  const headers_1 = require("next/headers");
15
15
  class VovkApp {
16
16
  static getHeadersFromOptions(options) {
@@ -36,13 +36,13 @@ class VovkApp {
36
36
  HEAD: new Map(),
37
37
  OPTIONS: new Map(),
38
38
  };
39
- GET = async (req, data) => this.#callMethod(types_js_1.HttpMethod.GET, req, await data.params);
40
- POST = async (req, data) => this.#callMethod(types_js_1.HttpMethod.POST, req, await data.params);
41
- PUT = async (req, data) => this.#callMethod(types_js_1.HttpMethod.PUT, req, await data.params);
42
- PATCH = async (req, data) => this.#callMethod(types_js_1.HttpMethod.PATCH, req, await data.params);
43
- DELETE = async (req, data) => this.#callMethod(types_js_1.HttpMethod.DELETE, req, await data.params);
44
- HEAD = async (req, data) => this.#callMethod(types_js_1.HttpMethod.HEAD, req, await data.params);
45
- OPTIONS = async (req, data) => this.#callMethod(types_js_1.HttpMethod.OPTIONS, req, await data.params);
39
+ GET = async (req, data) => this.#callMethod(types_1.HttpMethod.GET, req, await data.params);
40
+ POST = async (req, data) => this.#callMethod(types_1.HttpMethod.POST, req, await data.params);
41
+ PUT = async (req, data) => this.#callMethod(types_1.HttpMethod.PUT, req, await data.params);
42
+ PATCH = async (req, data) => this.#callMethod(types_1.HttpMethod.PATCH, req, await data.params);
43
+ DELETE = async (req, data) => this.#callMethod(types_1.HttpMethod.DELETE, req, await data.params);
44
+ HEAD = async (req, data) => this.#callMethod(types_1.HttpMethod.HEAD, req, await data.params);
45
+ OPTIONS = async (req, data) => this.#callMethod(types_1.HttpMethod.OPTIONS, req, await data.params);
46
46
  respond = (status, body, options) => {
47
47
  return new Response(JSON.stringify(body), {
48
48
  status,
@@ -61,7 +61,7 @@ class VovkApp {
61
61
  }, options);
62
62
  };
63
63
  #getHandler = ({ handlers, path, params, }) => {
64
- const methodParams = {};
64
+ let methodParams = {};
65
65
  if (Object.keys(params).length === 0) {
66
66
  return { handler: handlers[''], methodParams };
67
67
  }
@@ -71,7 +71,7 @@ class VovkApp {
71
71
  methodKeys = allMethodKeys
72
72
  // First, try to match literal routes exactly.
73
73
  .filter((p) => {
74
- if (p.includes(':'))
74
+ if (p.includes('{'))
75
75
  return false; // Skip parameterized paths
76
76
  return p === pathStr;
77
77
  });
@@ -80,27 +80,37 @@ class VovkApp {
80
80
  const routeSegments = p.split('/');
81
81
  if (routeSegments.length !== path.length)
82
82
  return false;
83
+ const params = {};
83
84
  for (let i = 0; i < routeSegments.length; i++) {
84
85
  const routeSegment = routeSegments[i];
85
86
  const pathSegment = path[i];
86
- if (routeSegment.startsWith(':')) {
87
- const parameter = routeSegment.slice(1);
88
- if (parameter in methodParams) {
89
- throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.INTERNAL_SERVER_ERROR, `Duplicate parameter "${parameter}" at ${p}`);
87
+ if (routeSegment.includes('{')) {
88
+ // const parameter = routeSegment.slice(1);
89
+ const regexPattern = routeSegment
90
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // Escape special chars
91
+ .replace(/\\{(\w+)\\}/g, '(?<$1>[^/]+)'); // Replace {var} with named groups
92
+ const values = pathSegment.match(new RegExp(`^${regexPattern}$`))?.groups ?? {};
93
+ for (const parameter in values) {
94
+ if (!Object.prototype.hasOwnProperty.call(values, parameter))
95
+ continue;
96
+ if (parameter in params) {
97
+ throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Duplicate parameter "${parameter}" at ${p}`);
98
+ }
99
+ // If it's a parameterized segment, capture the parameter value.
100
+ params[parameter] = values[parameter];
90
101
  }
91
- // If it's a parameterized segment, capture the parameter value.
92
- methodParams[parameter] = pathSegment;
93
102
  }
94
103
  else if (routeSegment !== pathSegment) {
95
104
  // If it's a literal segment and it does not match the corresponding path segment, return false.
96
105
  return false;
97
106
  }
98
107
  }
108
+ methodParams = params;
99
109
  return true;
100
110
  });
101
111
  }
102
112
  if (methodKeys.length > 1) {
103
- throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.INTERNAL_SERVER_ERROR, `Conflicting routes found: ${methodKeys.join(', ')}`);
113
+ throw new HttpException_1.HttpException(types_1.HttpStatus.INTERNAL_SERVER_ERROR, `Conflicting routes found: ${methodKeys.join(', ')}`);
104
114
  }
105
115
  const [methodKey] = methodKeys;
106
116
  if (methodKey) {
@@ -122,14 +132,14 @@ class VovkApp {
122
132
  });
123
133
  const { handler, methodParams } = this.#getHandler({ handlers, path, params });
124
134
  if (!handler) {
125
- return this.#respondWithError(types_js_1.HttpStatus.NOT_FOUND, `${Object.keys(handlers)} - Route ${path.join('/')} is not found`);
135
+ return this.#respondWithError(types_1.HttpStatus.NOT_FOUND, `${Object.keys(handlers)} - Route ${path.join('/')} is not found`);
126
136
  }
127
137
  const { staticMethod, controller } = handler;
128
138
  req.vovk = {
129
139
  body: () => req.json(),
130
- query: () => (0, reqQuery_js_1.default)(req),
131
- meta: (meta) => (0, reqMeta_js_1.default)(req, meta),
132
- form: () => (0, reqForm_js_1.default)(req),
140
+ query: () => (0, reqQuery_1.default)(req),
141
+ meta: (meta) => (0, reqMeta_1.default)(req, meta),
142
+ form: () => (0, reqForm_1.default)(req),
133
143
  params: () => methodParams,
134
144
  };
135
145
  try {
@@ -142,7 +152,7 @@ class VovkApp {
142
152
  (Reflect.has(result, Symbol.asyncIterator) &&
143
153
  typeof result[Symbol.asyncIterator] === 'function'));
144
154
  if (isIterator && !(result instanceof Array)) {
145
- const streamResponse = new JSONLinesResponse_js_1.JSONLinesResponse(await (0, headers_1.headers)(), {
155
+ const streamResponse = new JSONLinesResponse_1.JSONLinesResponse(await (0, headers_1.headers)(), {
146
156
  headers: {
147
157
  ..._a.getHeadersFromOptions(staticMethod._options),
148
158
  },
@@ -175,7 +185,7 @@ class VovkApp {
175
185
  console.error(onErrorError);
176
186
  }
177
187
  if (err.message !== 'NEXT_REDIRECT' && err.message !== 'NEXT_NOT_FOUND') {
178
- const statusCode = err.statusCode || types_js_1.HttpStatus.INTERNAL_SERVER_ERROR;
188
+ const statusCode = err.statusCode || types_1.HttpStatus.INTERNAL_SERVER_ERROR;
179
189
  return this.#respondWithError(statusCode, err.message, staticMethod._options, err.cause);
180
190
  }
181
191
  throw e; // if NEXT_REDIRECT or NEXT_NOT_FOUND, rethrow it
@@ -1,3 +1,3 @@
1
- import type { KnownAny, VovkSchema } from '../types.js';
2
- import type { VovkClient, VovkClientFetcher, VovkDefaultFetcherOptions } from './types.js';
1
+ import type { KnownAny, VovkSchema } from '../types';
2
+ import type { VovkClient, VovkClientFetcher, VovkDefaultFetcherOptions } from './types';
3
3
  export declare const createRPC: <T, OPTS extends Record<string, KnownAny> = Record<string, never>>(schema: VovkSchema, segmentName: string, rpcModuleName: string, fetcher?: VovkClientFetcher<OPTS>, options?: VovkDefaultFetcherOptions<OPTS>) => VovkClient<T, OPTS>;
@@ -4,37 +4,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createRPC = void 0;
7
- const fetcher_js_1 = require("./fetcher.js");
8
- const defaultHandler_js_1 = require("./defaultHandler.js");
9
- const defaultStreamHandler_js_1 = require("./defaultStreamHandler.js");
10
- const serializeQuery_js_1 = __importDefault(require("../utils/serializeQuery.js"));
7
+ const fetcher_1 = require("./fetcher");
8
+ const defaultHandler_1 = require("./defaultHandler");
9
+ const defaultStreamHandler_1 = require("./defaultStreamHandler");
10
+ const serializeQuery_1 = __importDefault(require("../utils/serializeQuery"));
11
11
  const trimPath = (path) => path.trim().replace(/^\/|\/$/g, '');
12
12
  const getHandlerPath = (endpoint, params, query) => {
13
13
  let result = endpoint;
14
- const queryStr = query ? (0, serializeQuery_js_1.default)(query) : null;
14
+ const queryStr = query ? (0, serializeQuery_1.default)(query) : null;
15
15
  for (const [key, value] of Object.entries(params ?? {})) {
16
- result = result.replace(`:${key}`, value);
16
+ result = result.replace(`{${key}}`, value);
17
17
  }
18
18
  return `${result}${queryStr ? '?' : ''}${queryStr}`;
19
19
  };
20
- const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_js_1.fetcher, options) => {
20
+ const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_1.fetcher, options) => {
21
21
  const segmentNamePath = options?.segmentNameOverride ?? segmentName;
22
22
  const segmentSchema = schema.segments[segmentName];
23
23
  if (!segmentSchema)
24
- throw new Error(`Unable to create RPC module. Segment schema is missing. Check client template.`);
24
+ throw new Error(`Unable to create RPC module. Segment schema is missing for segment "${segmentName}".`);
25
25
  const controllerSchema = schema.segments[segmentName]?.controllers[rpcModuleName];
26
26
  const client = {};
27
- if (!controllerSchema)
28
- throw new Error(`Unable to create RPC module. Controller schema is missing. Check client template.`);
27
+ if (!controllerSchema) {
28
+ console.log('schema.segments[segmentName]', schema.segments[segmentName]);
29
+ throw new Error(`Unable to create RPC module. Controller schema is missing for module "${rpcModuleName}" from segment "${segmentName}".`);
30
+ }
29
31
  const controllerPrefix = trimPath(controllerSchema.prefix ?? '');
30
32
  for (const [staticMethodName, handlerSchema] of Object.entries(controllerSchema.handlers ?? {})) {
31
33
  const { path, httpMethod, validation } = handlerSchema;
32
34
  const getEndpoint = ({ apiRoot, params, query, }) => {
33
- apiRoot = apiRoot ?? controllerSchema.forceApiRoot ?? options?.apiRoot ?? '/api';
35
+ const forceApiRoot = controllerSchema.forceApiRoot ?? segmentSchema.forceApiRoot;
36
+ apiRoot = apiRoot ?? forceApiRoot ?? options?.apiRoot ?? '/api';
34
37
  const endpoint = [
35
38
  apiRoot.startsWith('http://') || apiRoot.startsWith('https://') || apiRoot.startsWith('/') ? '' : '/',
36
39
  apiRoot,
37
- controllerSchema.forceApiRoot ? '' : segmentNamePath,
40
+ forceApiRoot ? '' : segmentNamePath,
38
41
  getHandlerPath([controllerPrefix, path].filter(Boolean).join('/'), params, query),
39
42
  ]
40
43
  .filter(Boolean)
@@ -57,8 +60,8 @@ const createRPC = (schema, segmentName, rpcModuleName, fetcher = fetcher_js_1.fe
57
60
  httpMethod: httpMethod,
58
61
  getEndpoint,
59
62
  validate,
60
- defaultHandler: defaultHandler_js_1.defaultHandler,
61
- defaultStreamHandler: defaultStreamHandler_js_1.defaultStreamHandler,
63
+ defaultHandler: defaultHandler_1.defaultHandler,
64
+ defaultStreamHandler: defaultStreamHandler_1.defaultStreamHandler,
62
65
  };
63
66
  const internalInput = {
64
67
  ...options,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultHandler = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
- const HttpException_js_1 = require("../HttpException.js");
4
+ const HttpException_1 = require("../HttpException");
5
5
  exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at defaultHandler';
6
6
  const defaultHandler = async (response) => {
7
7
  let result;
@@ -10,12 +10,12 @@ const defaultHandler = async (response) => {
10
10
  }
11
11
  catch (e) {
12
12
  // handle parsing errors
13
- throw new HttpException_js_1.HttpException(response.status, e?.message ?? exports.DEFAULT_ERROR_MESSAGE);
13
+ throw new HttpException_1.HttpException(response.status, e?.message ?? exports.DEFAULT_ERROR_MESSAGE);
14
14
  }
15
15
  if (!response.ok) {
16
16
  // handle server errors
17
17
  const errorResponse = result;
18
- throw new HttpException_js_1.HttpException(response.status, errorResponse?.message ?? exports.DEFAULT_ERROR_MESSAGE, errorResponse?.cause);
18
+ throw new HttpException_1.HttpException(response.status, errorResponse?.message ?? exports.DEFAULT_ERROR_MESSAGE, errorResponse?.cause);
19
19
  }
20
20
  return result;
21
21
  };
@@ -1,4 +1,4 @@
1
- import type { VovkStreamAsyncIterable } from './types.js';
2
- import '../utils/shim.js';
1
+ import type { VovkStreamAsyncIterable } from './types';
2
+ import '../utils/shim';
3
3
  export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at defaultStreamHandler";
4
4
  export declare const defaultStreamHandler: (response: Response) => Promise<VovkStreamAsyncIterable<unknown>>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultStreamHandler = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
- const types_js_1 = require("../types.js");
5
- const HttpException_js_1 = require("../HttpException.js");
6
- require("../utils/shim.js");
4
+ const types_1 = require("../types");
5
+ const HttpException_1 = require("../HttpException");
6
+ require("../utils/shim");
7
7
  exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at defaultStreamHandler';
8
8
  const defaultStreamHandler = async (response) => {
9
9
  if (!response.ok) {
@@ -15,10 +15,10 @@ const defaultStreamHandler = async (response) => {
15
15
  // ignore parsing errors
16
16
  }
17
17
  // handle server errors
18
- throw new HttpException_js_1.HttpException(response.status, result.message ?? exports.DEFAULT_ERROR_MESSAGE);
18
+ throw new HttpException_1.HttpException(response.status, result.message ?? exports.DEFAULT_ERROR_MESSAGE);
19
19
  }
20
20
  if (!response.body)
21
- throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, 'Stream body is falsy. Check your controller code.');
21
+ throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, 'Stream body is falsy. Check your controller code.');
22
22
  const reader = response.body.getReader();
23
23
  // if streaming is too rapid, we need to make sure that the loop is stopped
24
24
  let canceled = false;
@@ -1,4 +1,4 @@
1
- import type { VovkDefaultFetcherOptions, VovkClientFetcher } from './types.js';
1
+ import type { VovkDefaultFetcherOptions, VovkClientFetcher } from './types';
2
2
  export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at default fetcher";
3
3
  export declare function createFetcher<T>({ prepareRequestInit, transformResponse, }?: {
4
4
  prepareRequestInit?: (init: RequestInit, options: VovkDefaultFetcherOptions<T>) => RequestInit | Promise<RequestInit> | void | Promise<void>;
@@ -7,7 +7,7 @@ export declare function createFetcher<T>({ prepareRequestInit, transformResponse
7
7
  export declare const fetcher: VovkClientFetcher<{
8
8
  apiRoot?: string;
9
9
  disableClientValidation?: boolean;
10
- validateOnClient?: import("./types.js").VovkValidateOnClient;
10
+ validateOnClient?: import("./types").VovkValidateOnClient;
11
11
  interpretAs?: string;
12
12
  init?: RequestInit;
13
13
  }>;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetcher = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
4
  exports.createFetcher = createFetcher;
5
- const types_js_1 = require("../types.js");
6
- const HttpException_js_1 = require("../HttpException.js");
5
+ const types_1 = require("../types");
6
+ const HttpException_1 = require("../HttpException");
7
7
  exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at default fetcher';
8
8
  function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
9
9
  // fetcher uses HttpException class to throw errors of fake HTTP status 0 if client-side error occurs
@@ -11,11 +11,9 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
11
11
  const newFetcher = async ({ httpMethod, getEndpoint, validate, defaultHandler, defaultStreamHandler }, options) => {
12
12
  const { params, query, body, apiRoot, disableClientValidation, init, interpretAs } = options;
13
13
  const endpoint = getEndpoint({ apiRoot, params, query });
14
- const unusedParams = new URL(endpoint.startsWith('/') ? `http://localhost${endpoint}` : endpoint).pathname
15
- .split('/')
16
- .filter((segment) => segment.startsWith(':'));
14
+ const unusedParams = Array.from(new URL(endpoint.startsWith('/') ? `http://localhost${endpoint}` : endpoint).pathname.matchAll(/\{([^}]+)\}/g)).map((m) => m[1]);
17
15
  if (unusedParams.length) {
18
- throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, `Unused params: ${unusedParams.join(', ')} in ${endpoint}`, {
16
+ throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, `Unused params: ${unusedParams.join(', ')} in ${endpoint}`, {
19
17
  body,
20
18
  query,
21
19
  params,
@@ -28,10 +26,10 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
28
26
  }
29
27
  catch (e) {
30
28
  // if HttpException is thrown, rethrow it
31
- if (e instanceof HttpException_js_1.HttpException)
29
+ if (e instanceof HttpException_1.HttpException)
32
30
  throw e;
33
31
  // otherwise, throw HttpException with status 0
34
- throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, e.message ?? exports.DEFAULT_ERROR_MESSAGE, {
32
+ throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, e.message ?? exports.DEFAULT_ERROR_MESSAGE, {
35
33
  body,
36
34
  query,
37
35
  params,
@@ -62,7 +60,7 @@ function createFetcher({ prepareRequestInit, transformResponse, } = {}) {
62
60
  }
63
61
  catch (e) {
64
62
  // handle network errors
65
- throw new HttpException_js_1.HttpException(types_js_1.HttpStatus.NULL, (e?.message ?? exports.DEFAULT_ERROR_MESSAGE) + ' ' + endpoint, {
63
+ throw new HttpException_1.HttpException(types_1.HttpStatus.NULL, (e?.message ?? exports.DEFAULT_ERROR_MESSAGE) + ' ' + endpoint, {
66
64
  body,
67
65
  query,
68
66
  params,
@@ -1,3 +1,4 @@
1
- export { createRPC } from './createRPC.js';
2
- export { fetcher, createFetcher } from './fetcher.js';
3
- export type { VovkClient, VovkClientFetcher, VovkDefaultFetcherOptions, VovkValidateOnClient, VovkStreamAsyncIterable, } from './types.js';
1
+ export { createRPC } from './createRPC';
2
+ export { fetcher, createFetcher } from './fetcher';
3
+ export { progressive } from './progressive';
4
+ export type { VovkClient, VovkClientFetcher, VovkDefaultFetcherOptions, VovkValidateOnClient, VovkStreamAsyncIterable, } from './types';
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFetcher = exports.fetcher = exports.createRPC = void 0;
4
- var createRPC_js_1 = require("./createRPC.js");
5
- Object.defineProperty(exports, "createRPC", { enumerable: true, get: function () { return createRPC_js_1.createRPC; } });
6
- var fetcher_js_1 = require("./fetcher.js");
7
- Object.defineProperty(exports, "fetcher", { enumerable: true, get: function () { return fetcher_js_1.fetcher; } });
8
- Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return fetcher_js_1.createFetcher; } });
3
+ exports.progressive = exports.createFetcher = exports.fetcher = exports.createRPC = void 0;
4
+ var createRPC_1 = require("./createRPC");
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; } });
8
+ Object.defineProperty(exports, "createFetcher", { enumerable: true, get: function () { return fetcher_1.createFetcher; } });
9
+ var progressive_1 = require("./progressive");
10
+ Object.defineProperty(exports, "progressive", { enumerable: true, get: function () { return progressive_1.progressive; } });
@@ -1,4 +1,4 @@
1
- import type { VovkStreamAsyncIterable } from '../client/types';
1
+ import type { VovkStreamAsyncIterable } from './types';
2
2
  import type { KnownAny, VovkIteration } from '../types';
3
3
  type UnionToIntersection<U> = (U extends KnownAny ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
4
4
  type PromisifyProperties<T> = {
@@ -8,8 +8,8 @@ function progressive(fn, ...args) {
8
8
  .then(async (result) => {
9
9
  for await (const item of result) {
10
10
  for (const [key, value] of Object.entries(item)) {
11
- if (key in reg && !reg[key].isFulfilled) {
12
- reg[key].isFulfilled = true;
11
+ if (key in reg && !reg[key].isSettled) {
12
+ reg[key].isSettled = true;
13
13
  reg[key].resolve(value);
14
14
  }
15
15
  }
@@ -18,9 +18,9 @@ function progressive(fn, ...args) {
18
18
  })
19
19
  .catch((error) => {
20
20
  Object.keys(reg).forEach((key) => {
21
- if (reg[key].isFulfilled)
21
+ if (reg[key].isSettled)
22
22
  return;
23
- reg[key].isFulfilled = true;
23
+ reg[key].isSettled = true;
24
24
  reg[key].reject(error);
25
25
  });
26
26
  return error;
@@ -31,20 +31,8 @@ function progressive(fn, ...args) {
31
31
  return reg[prop].promise;
32
32
  }
33
33
  const { promise, resolve, reject } = Promise.withResolvers();
34
- reg[prop] = { resolve, reject, promise, isFulfilled: false };
34
+ reg[prop] = { resolve, reject, promise, isSettled: false };
35
35
  return promise;
36
36
  },
37
37
  });
38
38
  }
39
- /*
40
- type OriginalType = {
41
- users: string[];
42
- } | {
43
- tasks: string[];
44
- } | {
45
- config: string;
46
- } | {
47
- metadata: string;
48
- };
49
-
50
- type Result = UnionToIntersection<OriginalType>; */
@@ -1,5 +1,5 @@
1
- import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkHandlerSchema, VovkControllerSchema, VovkSegmentSchema, VovkSchema, VovkRequest } from '../types.js';
2
- import type { JSONLinesResponse } from '../JSONLinesResponse.js';
1
+ import type { KnownAny, HttpMethod, ControllerStaticMethod, VovkHandlerSchema, VovkControllerSchema, VovkSegmentSchema, VovkSchema, VovkRequest } from '../types';
2
+ import type { JSONLinesResponse } from '../JSONLinesResponse';
3
3
  import type { NextResponse } from 'next/server';
4
4
  type OmitNullable<T> = {
5
5
  [K in keyof T as T[K] extends null | undefined ? never : K]: T[K];
@@ -1,5 +1,5 @@
1
1
  import type { NextRequest } from 'next/server';
2
- import { type KnownAny, type DecoratorOptions, type VovkRequest, type StaticClass } from './types.js';
2
+ import { type KnownAny, type DecoratorOptions, type VovkRequest, type StaticClass } from './types';
3
3
  export declare function createVovkApp(): {
4
4
  get: {
5
5
  (givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
@@ -30,7 +30,7 @@ export declare function createVovkApp(): {
30
30
  auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
31
31
  };
32
32
  prefix: (givenPath?: string) => (givenTarget: KnownAny) => any;
33
- initVovk: (options: {
33
+ initSegment: (options: {
34
34
  segmentName?: string;
35
35
  controllers: Record<string, StaticClass>;
36
36
  exposeValidation?: boolean;
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createVovkApp = createVovkApp;
7
- const VovkApp_js_1 = require("./VovkApp.js");
8
- const types_js_1 = require("./types.js");
9
- const getSchema_js_1 = __importDefault(require("./utils/getSchema.js"));
7
+ const VovkApp_1 = require("./VovkApp");
8
+ const types_1 = require("./types");
9
+ const getSchema_1 = __importDefault(require("./utils/getSchema"));
10
10
  const trimPath = (path) => path.trim().replace(/^\/|\/$/g, '');
11
11
  const isClass = (func) => typeof func === 'function' && /class/.test(func.toString());
12
12
  const toKebabCase = (str) => str
@@ -52,7 +52,7 @@ const assignSchema = ({ controller, propertyKey, path, options, httpMethod, vovk
52
52
  };
53
53
  };
54
54
  function createVovkApp() {
55
- const vovkApp = new VovkApp_js_1.VovkApp();
55
+ const vovkApp = new VovkApp_1.VovkApp();
56
56
  const createHTTPDecorator = (httpMethod) => {
57
57
  function decoratorCreator(givenPath = '', options) {
58
58
  const path = trimPath(givenPath);
@@ -93,7 +93,7 @@ function createVovkApp() {
93
93
  return givenTarget;
94
94
  };
95
95
  };
96
- const initVovk = (options) => {
96
+ const initSegment = (options) => {
97
97
  options.segmentName = trimPath(options.segmentName ?? '');
98
98
  for (const [rpcModuleName, controller] of Object.entries(options.controllers ?? {})) {
99
99
  controller._rpcModuleName = rpcModuleName;
@@ -102,7 +102,7 @@ function createVovkApp() {
102
102
  async function GET_DEV(req, data) {
103
103
  const params = await data.params;
104
104
  if (params[Object.keys(params)[0]]?.[0] === '_schema_') {
105
- const schema = await (0, getSchema_js_1.default)(options);
105
+ const schema = await (0, getSchema_1.default)(options);
106
106
  return vovkApp.respond(200, { schema });
107
107
  }
108
108
  return vovkApp.GET(req, data);
@@ -118,14 +118,14 @@ function createVovkApp() {
118
118
  };
119
119
  };
120
120
  return {
121
- get: createHTTPDecorator(types_js_1.HttpMethod.GET),
122
- post: createHTTPDecorator(types_js_1.HttpMethod.POST),
123
- put: createHTTPDecorator(types_js_1.HttpMethod.PUT),
124
- patch: createHTTPDecorator(types_js_1.HttpMethod.PATCH),
125
- del: createHTTPDecorator(types_js_1.HttpMethod.DELETE),
126
- head: createHTTPDecorator(types_js_1.HttpMethod.HEAD),
127
- options: createHTTPDecorator(types_js_1.HttpMethod.OPTIONS),
121
+ get: createHTTPDecorator(types_1.HttpMethod.GET),
122
+ post: createHTTPDecorator(types_1.HttpMethod.POST),
123
+ put: createHTTPDecorator(types_1.HttpMethod.PUT),
124
+ patch: createHTTPDecorator(types_1.HttpMethod.PATCH),
125
+ del: createHTTPDecorator(types_1.HttpMethod.DELETE),
126
+ head: createHTTPDecorator(types_1.HttpMethod.HEAD),
127
+ options: createHTTPDecorator(types_1.HttpMethod.OPTIONS),
128
128
  prefix,
129
- initVovk,
129
+ initSegment,
130
130
  };
131
131
  }
package/cjs/index.d.ts CHANGED
@@ -1,6 +1,6 @@
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 VovkSegmentSchema, type VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod } from './types';
3
- import { type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher } from './client/index';
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 VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod } from './types';
3
+ import { type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkStreamAsyncIterable, createRPC, fetcher, createFetcher, progressive } from './client/index';
4
4
  import { openapi, openAPIToVovkSchema, vovkSchemaToOpenAPI } from './openapi/index';
5
5
  import { HttpException } from './HttpException';
6
6
  import { createDecorator } from './utils/createDecorator';
@@ -11,8 +11,7 @@ import { withStandard } from './utils/withStandard';
11
11
  import { multitenant } from './utils/multitenant';
12
12
  import { createLLMTools } from './utils/createLLMTools';
13
13
  import { createCodeExamples } from './utils/createCodeExamples';
14
- import { progressive } from './utils/progressive';
15
- export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, 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 VovkControllerSchema, type VovkHandlerSchema, type VovkSchema, type VovkConfig, type VovkStrictConfig, type VovkValidationType, type VovkLLMTool, type VovkTypedMethod, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, withStandard, multitenant, createLLMTools, createCodeExamples, progressive, openapi, openAPIToVovkSchema, vovkSchemaToOpenAPI, };
14
+ export { type KnownAny, type VovkClient, type VovkClientFetcher, type VovkDefaultFetcherOptions, 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 VovkValidationType, type VovkLLMTool, type VovkTypedMethod, VovkSchemaIdEnum, JSONLinesResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, createRPC, fetcher, createFetcher, generateStaticAPI, withValidationLibrary, withStandard, multitenant, createLLMTools, createCodeExamples, progressive, openapi, openAPIToVovkSchema, vovkSchemaToOpenAPI, };
16
15
  export declare const get: {
17
16
  (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
18
17
  auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
@@ -34,7 +33,7 @@ export declare const get: {
34
33
  }, options: {
35
34
  (givenPath?: string | undefined, options?: import("./types").DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
36
35
  auto: (options?: import("./types").DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
37
- }, prefix: (givenPath?: string) => (givenTarget: KnownAny) => any, initVovk: (options: {
36
+ }, prefix: (givenPath?: string) => (givenTarget: KnownAny) => any, initSegment: (options: {
38
37
  segmentName?: string;
39
38
  controllers: Record<string, import("./types").StaticClass>;
40
39
  exposeValidation?: boolean;