vovk 3.0.0-draft.7 → 3.0.0-draft.70

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 (101) hide show
  1. package/README.md +8 -95
  2. package/{HttpException.d.ts → dist/HttpException.d.ts} +2 -2
  3. package/{HttpException.js → dist/HttpException.js} +3 -3
  4. package/{StreamResponse.d.ts → dist/StreamJSONResponse.d.ts} +3 -3
  5. package/{StreamResponse.js → dist/StreamJSONResponse.js} +5 -5
  6. package/{Segment.d.ts → dist/VovkApp.d.ts} +11 -10
  7. package/{Segment.js → dist/VovkApp.js} +28 -24
  8. package/dist/client/createRPC.d.ts +4 -0
  9. package/{client/clientizeController.js → dist/client/createRPC.js} +22 -40
  10. package/dist/client/defaultFetcher.d.ts +4 -0
  11. package/{client → dist/client}/defaultFetcher.js +19 -8
  12. package/{client → dist/client}/defaultHandler.d.ts +1 -1
  13. package/dist/client/defaultHandler.js +22 -0
  14. package/dist/client/defaultStreamHandler.d.ts +4 -0
  15. package/{client → dist/client}/defaultStreamHandler.js +5 -5
  16. package/dist/client/index.d.ts +2 -0
  17. package/dist/client/index.js +8 -0
  18. package/dist/client/types.d.ts +103 -0
  19. package/dist/createDecorator.d.ts +4 -0
  20. package/{createDecorator.js → dist/createDecorator.js} +5 -4
  21. package/{createSegment.d.ts → dist/createVovkApp.d.ts} +10 -10
  22. package/{createSegment.js → dist/createVovkApp.js} +25 -25
  23. package/dist/index.d.ts +60 -0
  24. package/dist/index.js +24 -0
  25. package/dist/openapi/fromSchema.d.ts +3 -0
  26. package/dist/openapi/fromSchema.js +26 -0
  27. package/dist/openapi/index.d.ts +1 -0
  28. package/dist/openapi/index.js +5 -0
  29. package/dist/openapi/openapi.d.ts +10 -0
  30. package/dist/openapi/openapi.js +16 -0
  31. package/dist/types.d.ts +147 -0
  32. package/dist/types.js +65 -0
  33. package/dist/utils/generateStaticAPI.d.ts +4 -0
  34. package/{generateStaticAPI.js → dist/utils/generateStaticAPI.js} +3 -3
  35. package/{utils → dist/utils}/getSchema.d.ts +1 -2
  36. package/{utils → dist/utils}/getSchema.js +5 -16
  37. package/dist/utils/parseQuery.d.ts +25 -0
  38. package/dist/utils/parseQuery.js +156 -0
  39. package/dist/utils/reqForm.d.ts +2 -0
  40. package/dist/utils/reqForm.js +13 -0
  41. package/{utils → dist/utils}/reqMeta.d.ts +1 -2
  42. package/{utils → dist/utils}/reqQuery.d.ts +1 -2
  43. package/dist/utils/reqQuery.js +10 -0
  44. package/dist/utils/serializeQuery.d.ts +13 -0
  45. package/dist/utils/serializeQuery.js +65 -0
  46. package/dist/utils/setClientValidatorsForHandler.d.ts +5 -0
  47. package/{utils → dist/utils}/setClientValidatorsForHandler.js +4 -6
  48. package/package.json +8 -2
  49. package/src/HttpException.ts +16 -0
  50. package/src/StreamJSONResponse.ts +61 -0
  51. package/src/VovkApp.ts +240 -0
  52. package/src/client/createRPC.ts +120 -0
  53. package/src/client/defaultFetcher.ts +69 -0
  54. package/src/client/defaultHandler.ts +23 -0
  55. package/src/client/defaultStreamHandler.ts +88 -0
  56. package/src/client/index.ts +9 -0
  57. package/src/client/types.ts +120 -0
  58. package/src/createDecorator.ts +61 -0
  59. package/src/createVovkApp.ts +168 -0
  60. package/src/index.ts +71 -0
  61. package/src/openapi/fromSchema.ts +33 -0
  62. package/src/openapi/index.ts +1 -0
  63. package/src/openapi/openapi.ts +23 -0
  64. package/src/types.ts +200 -0
  65. package/src/utils/generateStaticAPI.ts +18 -0
  66. package/src/utils/getSchema.ts +35 -0
  67. package/src/utils/parseQuery.ts +160 -0
  68. package/src/utils/reqForm.ts +16 -0
  69. package/src/utils/reqMeta.ts +16 -0
  70. package/src/utils/reqQuery.ts +6 -0
  71. package/src/utils/serializeQuery.ts +69 -0
  72. package/src/utils/setClientValidatorsForHandler.ts +45 -0
  73. package/src/utils/shim.ts +17 -0
  74. package/.npmignore +0 -2
  75. package/client/clientizeController.d.ts +0 -4
  76. package/client/defaultFetcher.d.ts +0 -4
  77. package/client/defaultHandler.js +0 -21
  78. package/client/defaultStreamHandler.d.ts +0 -4
  79. package/client/index.d.ts +0 -4
  80. package/client/index.js +0 -5
  81. package/client/types.d.ts +0 -102
  82. package/createDecorator.d.ts +0 -4
  83. package/generateStaticAPI.d.ts +0 -4
  84. package/index.d.ts +0 -60
  85. package/index.js +0 -20
  86. package/types.d.ts +0 -191
  87. package/types.js +0 -65
  88. package/utils/reqQuery.js +0 -25
  89. package/utils/setClientValidatorsForHandler.d.ts +0 -5
  90. package/worker/index.d.ts +0 -3
  91. package/worker/index.js +0 -7
  92. package/worker/promisifyWorker.d.ts +0 -2
  93. package/worker/promisifyWorker.js +0 -143
  94. package/worker/types.d.ts +0 -31
  95. package/worker/types.js +0 -2
  96. package/worker/worker.d.ts +0 -1
  97. package/worker/worker.js +0 -44
  98. /package/{client → dist/client}/types.js +0 -0
  99. /package/{utils → dist/utils}/reqMeta.js +0 -0
  100. /package/{utils → dist/utils}/shim.d.ts +0 -0
  101. /package/{utils → dist/utils}/shim.js +0 -0
@@ -0,0 +1,160 @@
1
+ import type { KnownAny } from '../types';
2
+
3
+ /**
4
+ * Parse a bracket-based key (e.g. "z[d][0][x]" or "arr[]")
5
+ * into an array of path segments (strings or special push-markers).
6
+ *
7
+ * Example: "z[d][0][x]" => ["z", "d", "0", "x"]
8
+ * Example: "arr[]" => ["arr", "" ] // "" indicates "push" onto array
9
+ */
10
+ function parseKey(key: string): string[] {
11
+ // The first segment is everything up to the first '[' (or the entire key if no '[')
12
+ const segments: string[] = [];
13
+ const topKeyMatch = key.match(/^([^[\]]+)/);
14
+ if (topKeyMatch) {
15
+ segments.push(topKeyMatch[1]);
16
+ } else {
17
+ // If it starts with brackets, treat it as empty? (edge case)
18
+ segments.push('');
19
+ }
20
+
21
+ // Now capture all bracket parts: [something], [0], []
22
+ const bracketRegex = /\[([^[\]]*)\]/g;
23
+ let match: RegExpExecArray | null;
24
+ while ((match = bracketRegex.exec(key)) !== null) {
25
+ // match[1] is the content inside the brackets
26
+ segments.push(match[1]);
27
+ }
28
+
29
+ return segments;
30
+ }
31
+
32
+ /**
33
+ * Recursively set a value in a nested object/array, given a path of segments.
34
+ * - If segment is numeric => treat as array index
35
+ * - If segment is empty "" => push to array
36
+ * - Else => object property
37
+ */
38
+ function setValue(obj: Record<string, KnownAny>, path: string[], value: KnownAny): void {
39
+ let current: KnownAny = obj;
40
+
41
+ for (let i = 0; i < path.length; i++) {
42
+ const segment = path[i];
43
+
44
+ // If we're at the last segment, set the value
45
+ if (i === path.length - 1) {
46
+ if (segment === '') {
47
+ // Empty bracket => push
48
+ if (!Array.isArray(current)) {
49
+ current = [];
50
+ }
51
+ current.push(value);
52
+ } else if (!isNaN(Number(segment))) {
53
+ // Numeric segment => array index
54
+ const idx = Number(segment);
55
+ if (!Array.isArray(current)) {
56
+ current = [];
57
+ }
58
+ current[idx] = value;
59
+ } else {
60
+ // Object property
61
+ current[segment] = value;
62
+ }
63
+ } else {
64
+ // Not the last segment: descend into existing structure or create it
65
+ const nextSegment = path[i + 1];
66
+
67
+ if (segment === '') {
68
+ // Empty bracket => push
69
+ if (!Array.isArray(current)) {
70
+ // Convert the current node into an array, if not one
71
+ current = [];
72
+ }
73
+ // If we are not at the last path, we need a placeholder object or array
74
+ // for the next segment. We'll push something and move current to that.
75
+ if (current.length === 0) {
76
+ // nothing in array yet
77
+ current.push(typeof nextSegment === 'string' && !isNaN(Number(nextSegment)) ? [] : {});
78
+ } else if (typeof nextSegment === 'string' && !isNaN(Number(nextSegment))) {
79
+ // next is numeric => we want an array
80
+ if (!Array.isArray(current[current.length - 1])) {
81
+ current[current.length - 1] = [];
82
+ }
83
+ } else {
84
+ // next is not numeric => we want an object
85
+ if (typeof current[current.length - 1] !== 'object') {
86
+ current[current.length - 1] = {};
87
+ }
88
+ }
89
+ current = current[current.length - 1];
90
+ } else if (!isNaN(Number(segment))) {
91
+ // segment is numeric => array index
92
+ const idx = Number(segment);
93
+ if (!Array.isArray(current)) {
94
+ current = [];
95
+ }
96
+ if (current[idx] === undefined) {
97
+ // Create placeholder for next segment
98
+ current[idx] = typeof nextSegment === 'string' && !isNaN(Number(nextSegment)) ? [] : {};
99
+ }
100
+ current = current[idx];
101
+ } else {
102
+ // segment is an object key
103
+ if (current[segment] === undefined) {
104
+ // Create placeholder
105
+ current[segment] = typeof nextSegment === 'string' && !isNaN(Number(nextSegment)) ? [] : {};
106
+ }
107
+ current = current[segment];
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Deserialize a bracket-based query string into an object.
115
+ *
116
+ * Supports:
117
+ * - Key/value pairs with nested brackets (e.g. "a[b][0]=value")
118
+ * - Arrays with empty bracket (e.g. "arr[]=1&arr[]=2")
119
+ * - Mixed arrays of objects, etc.
120
+ *
121
+ * @example
122
+ * parseQuery("x=xx&y[0]=yy&y[1]=uu&z[f]=x&z[u][0]=uu&z[u][1]=xx&z[d][x]=ee")
123
+ * => {
124
+ * x: "xx",
125
+ * y: ["yy", "uu"],
126
+ * z: {
127
+ * f: "x",
128
+ * u: ["uu", "xx"],
129
+ * d: { x: "ee" }
130
+ * }
131
+ * }
132
+ *
133
+ * @param queryString - The raw query string (e.g. location.search.slice(1))
134
+ * @returns - A nested object representing the query params
135
+ */
136
+ export default function parseQuery(queryString: string): Record<string, KnownAny> {
137
+ const result: Record<string, KnownAny> = {};
138
+
139
+ if (!queryString) return result;
140
+
141
+ // Split into key=value pairs
142
+ const pairs = queryString
143
+ .replace(/^\?/, '') // Remove leading "?" if present
144
+ .split('&');
145
+
146
+ for (const pair of pairs) {
147
+ const [rawKey, rawVal = ''] = pair.split('=');
148
+
149
+ const decodedKey = decodeURIComponent(rawKey || '');
150
+ const decodedVal = decodeURIComponent(rawVal);
151
+
152
+ // Parse bracket notation
153
+ const pathSegments = parseKey(decodedKey);
154
+
155
+ // Insert into the result object
156
+ setValue(result, pathSegments, decodedVal);
157
+ }
158
+
159
+ return result;
160
+ }
@@ -0,0 +1,16 @@
1
+ import type { KnownAny, VovkRequest } from '../types';
2
+
3
+ const formMap = new WeakMap();
4
+
5
+ export default async function reqForm<T = KnownAny>(req: VovkRequest<KnownAny, KnownAny>): Promise<T> {
6
+ if (formMap.has(req)) {
7
+ return formMap.get(req) as T;
8
+ }
9
+
10
+ const body = await req.formData();
11
+ const formData = Object.fromEntries(body.entries()) as T;
12
+
13
+ formMap.set(req, formData);
14
+
15
+ return formData;
16
+ }
@@ -0,0 +1,16 @@
1
+ import type { KnownAny, VovkRequest } from '../types';
2
+
3
+ const metaMap = new WeakMap();
4
+
5
+ export default function reqMeta<T = Record<KnownAny, KnownAny>>(
6
+ req: VovkRequest<KnownAny, KnownAny>,
7
+ meta?: T | null
8
+ ): T {
9
+ if (meta) {
10
+ metaMap.set(req, { ...metaMap.get(req), ...meta });
11
+ } else if (meta === null) {
12
+ metaMap.delete(req);
13
+ }
14
+
15
+ return (metaMap.get(req) ?? {}) as T;
16
+ }
@@ -0,0 +1,6 @@
1
+ import type { KnownAny, VovkRequest } from '../types';
2
+ import parseQuery from './parseQuery';
3
+
4
+ export default function reqQuery<T extends object | undefined>(req: VovkRequest<KnownAny, T>): T {
5
+ return parseQuery(req.nextUrl.search) as NonNullable<T>;
6
+ }
@@ -0,0 +1,69 @@
1
+ import type { KnownAny } from '../types';
2
+
3
+ /**
4
+ * Recursively build query parameters from an object.
5
+ *
6
+ * @param key - The query key so far (e.g. 'user', 'user[0]', 'user[0][name]')
7
+ * @param value - The current value to serialize
8
+ * @returns - An array of `key=value` strings
9
+ */
10
+ function buildParams(key: string, value: KnownAny): string[] {
11
+ if (value === null || value === undefined) {
12
+ return []; // skip null/undefined values entirely
13
+ }
14
+
15
+ // If value is an object or array, we need to recurse
16
+ if (typeof value === 'object') {
17
+ // Array case
18
+ if (Array.isArray(value)) {
19
+ /**
20
+ * We use index-based bracket notation here:
21
+ * e.g. for value = ['aa', 'bb'] and key = 'foo'
22
+ * => "foo[0]=aa&foo[1]=bb"
23
+ *
24
+ * If you prefer "foo[]=aa&foo[]=bb" style, replace:
25
+ * `${key}[${i}]`
26
+ * with:
27
+ * `${key}[]`
28
+ */
29
+ return value.flatMap((v, i) => {
30
+ const newKey = `${key}[${i}]`;
31
+ return buildParams(newKey, v);
32
+ });
33
+ }
34
+
35
+ // Plain object case
36
+ return Object.keys(value).flatMap((k) => {
37
+ const newKey = `${key}[${k}]`;
38
+ return buildParams(newKey, value[k]);
39
+ });
40
+ }
41
+
42
+ return [`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`];
43
+ }
44
+
45
+ /**
46
+ * Serialize a nested object (including arrays, arrays of objects, etc.)
47
+ * into a bracket-based query string.
48
+ *
49
+ * @example
50
+ * serializeQuery({ x: 'xx', y: [1, 2], z: { f: 'x' } })
51
+ * => "x=xx&y[0]=1&y[1]=2&z[f]=x"
52
+ *
53
+ * @param obj - The input object to be serialized
54
+ * @returns - A bracket-based query string (without leading "?")
55
+ */
56
+ export default function serializeQuery(obj: Record<string, KnownAny>): string {
57
+ if (!obj || typeof obj !== 'object') return '';
58
+
59
+ // Collect query segments
60
+ const segments: string[] = [];
61
+ for (const key in obj) {
62
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
63
+ const value = obj[key];
64
+ segments.push(...buildParams(key, value));
65
+ }
66
+ }
67
+
68
+ return segments.join('&');
69
+ }
@@ -0,0 +1,45 @@
1
+ import type { KnownAny, VovkController } from '../types';
2
+
3
+ export function setClientValidatorsForHandler(
4
+ h: (...args: KnownAny[]) => KnownAny,
5
+ validation: {
6
+ body: unknown;
7
+ query: unknown;
8
+ }
9
+ ) {
10
+ return new Promise<void>((resolve) => {
11
+ // the setTimeout is necessary to ensure that the _controller is already defined
12
+ setTimeout(() => {
13
+ const controller = (h as unknown as { _controller: VovkController })._controller;
14
+
15
+ if (!controller) {
16
+ throw new Error(
17
+ 'Error setting client validators. Controller not found. Did you forget to use an HTTP decorator?'
18
+ );
19
+ }
20
+
21
+ const handlerName = Object.getOwnPropertyNames(controller).find(
22
+ (key) =>
23
+ (
24
+ controller[key] as {
25
+ _sourceMethod?: unknown;
26
+ }
27
+ )._sourceMethod === h
28
+ );
29
+
30
+ if (!handlerName) {
31
+ throw new Error('Error setting client validators. Handler not found.');
32
+ }
33
+
34
+ controller._handlers = {
35
+ ...controller._handlers,
36
+ [handlerName]: {
37
+ ...controller._handlers[handlerName],
38
+ validation,
39
+ },
40
+ };
41
+
42
+ resolve();
43
+ }, 0);
44
+ });
45
+ }
@@ -0,0 +1,17 @@
1
+ if (typeof Symbol.dispose !== 'symbol') {
2
+ Object.defineProperty(Symbol, 'dispose', {
3
+ configurable: false,
4
+ enumerable: false,
5
+ writable: false,
6
+ value: Symbol.for('dispose'),
7
+ });
8
+ }
9
+
10
+ if (typeof Symbol.asyncDispose !== 'symbol') {
11
+ Object.defineProperty(Symbol, 'asyncDispose', {
12
+ configurable: false,
13
+ enumerable: false,
14
+ writable: false,
15
+ value: Symbol.for('asyncDispose'),
16
+ });
17
+ }
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- !*
2
- tsconfig.*
@@ -1,4 +0,0 @@
1
- import { type _VovkControllerSchema as VovkControllerSchema, type _KnownAny as KnownAny } from '../types';
2
- import { type _VovkClientOptions as VovkClientOptions, type _VovkClient as VovkClient, type _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions } from './types';
3
- export declare const ARRAY_QUERY_KEY = "_vovkarr";
4
- export declare const _clientizeController: <T, OPTS extends Record<string, KnownAny> = VovkDefaultFetcherOptions>(givenController: VovkControllerSchema, segmentName?: string, options?: VovkClientOptions<OPTS>) => VovkClient<T, OPTS>;
@@ -1,4 +0,0 @@
1
- import type { _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions, _VovkClientFetcher as VovkClientFetcher } from './types';
2
- export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at defaultFetcher";
3
- declare const defaultFetcher: VovkClientFetcher<VovkDefaultFetcherOptions>;
4
- export default defaultFetcher;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._defaultHandler = exports.DEFAULT_ERROR_MESSAGE = void 0;
4
- const HttpException_1 = require("../HttpException");
5
- exports.DEFAULT_ERROR_MESSAGE = 'Unknown error at defaultHandler';
6
- const _defaultHandler = async (response) => {
7
- let result;
8
- try {
9
- result = await response.json();
10
- }
11
- catch (e) {
12
- // handle parsing errors
13
- throw new HttpException_1._HttpException(response.status, e?.message ?? exports.DEFAULT_ERROR_MESSAGE);
14
- }
15
- if (!response.ok) {
16
- // handle server errors
17
- throw new HttpException_1._HttpException(response.status, result?.message ?? exports.DEFAULT_ERROR_MESSAGE);
18
- }
19
- return result;
20
- };
21
- exports._defaultHandler = _defaultHandler;
@@ -1,4 +0,0 @@
1
- import type { _StreamAsyncIterator as StreamAsyncIterator } from './types';
2
- import '../utils/shim';
3
- export declare const DEFAULT_ERROR_MESSAGE = "Unknown error at defaultStreamHandler";
4
- export declare const _defaultStreamHandler: (response: Response) => Promise<StreamAsyncIterator<unknown>>;
package/client/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { _clientizeController as clientizeController } from './clientizeController';
2
- import type { _VovkClientFetcher as VovkClientFetcher, _VovkClientOptions as VovkClientOptions, _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions } from './types';
3
- export { clientizeController };
4
- export type { VovkClientFetcher, VovkClientOptions, VovkDefaultFetcherOptions };
package/client/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clientizeController = void 0;
4
- const clientizeController_1 = require("./clientizeController");
5
- Object.defineProperty(exports, "clientizeController", { enumerable: true, get: function () { return clientizeController_1._clientizeController; } });
package/client/types.d.ts DELETED
@@ -1,102 +0,0 @@
1
- import type { _KnownAny as KnownAny, _HttpMethod as HttpMethod, _ControllerStaticMethod, _VovkControllerBody, _VovkControllerQuery, _VovkControllerParams } from '../types';
2
- import { _StreamResponse as StreamResponse } from '../StreamResponse';
3
- import type { NextResponse } from 'next/server';
4
- export type _StaticMethodInput<T extends _ControllerStaticMethod> = (_VovkControllerBody<T> extends undefined | void ? {
5
- body?: undefined;
6
- } : _VovkControllerBody<T> extends null ? {
7
- body?: null;
8
- } : {
9
- body: _VovkControllerBody<T>;
10
- }) & (_VovkControllerQuery<T> extends undefined | void ? {
11
- query?: undefined;
12
- } : {
13
- query: _VovkControllerQuery<T>;
14
- }) & (_VovkControllerParams<T> extends undefined | void ? {
15
- params?: undefined;
16
- } : {
17
- params: _VovkControllerParams<T>;
18
- });
19
- type ToPromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
20
- export type _StreamAsyncIterator<T> = {
21
- status: number;
22
- [Symbol.dispose](): Promise<void> | void;
23
- [Symbol.asyncDispose](): Promise<void> | void;
24
- [Symbol.asyncIterator](): AsyncIterator<T>;
25
- cancel: () => Promise<void> | void;
26
- };
27
- type StaticMethodReturn<T extends _ControllerStaticMethod> = ReturnType<T> extends NextResponse<infer U> | Promise<NextResponse<infer U>> ? U : ReturnType<T> extends Response | Promise<Response> ? unknown : ReturnType<T>;
28
- type StaticMethodReturnPromise<T extends _ControllerStaticMethod> = ToPromise<StaticMethodReturn<T>>;
29
- type ClientMethod<T extends (...args: KnownAny[]) => void | object | StreamResponse<STREAM> | Promise<StreamResponse<STREAM>>, OPTS extends Record<string, KnownAny>, STREAM extends KnownAny = unknown> = <R>(options: (_StaticMethodInput<T> extends {
30
- body?: undefined | null;
31
- query?: undefined;
32
- params?: undefined;
33
- } ? unknown : Parameters<T>[0] extends void ? _StaticMethodInput<T>['params'] extends object ? {
34
- params: _StaticMethodInput<T>['params'];
35
- } : unknown : _StaticMethodInput<T>) & (Partial<OPTS & {
36
- transform: (staticMethodReturn: Awaited<StaticMethodReturn<T>>) => R;
37
- }> | void)) => ReturnType<T> extends Promise<StreamResponse<infer U>> | StreamResponse<infer U> | Iterator<infer U> | AsyncIterator<infer U> ? Promise<_StreamAsyncIterator<U>> : R extends object ? Promise<R> : StaticMethodReturnPromise<T>;
38
- type OmitNever<T> = {
39
- [K in keyof T as T[K] extends never ? never : K]: T[K];
40
- };
41
- type _VovkClientWithNever<T, OPTS extends {
42
- [key: string]: KnownAny;
43
- }> = {
44
- [K in keyof T]: T[K] extends (...args: KnownAny) => KnownAny ? ClientMethod<T[K], OPTS> & {
45
- __isClientMethod: boolean;
46
- } : never;
47
- };
48
- export type _VovkClient<T, OPTS extends {
49
- [key: string]: KnownAny;
50
- }> = OmitNever<_VovkClientWithNever<T, OPTS>>;
51
- export type _VovkClientFetcher<OPTS extends Record<string, KnownAny> = Record<string, never>, T = KnownAny> = (options: {
52
- name: keyof T;
53
- httpMethod: HttpMethod;
54
- getEndpoint: (data: {
55
- prefix: string;
56
- params: {
57
- [key: string]: string;
58
- };
59
- query: {
60
- [key: string]: string;
61
- };
62
- }) => string;
63
- validate: (input: {
64
- body?: unknown;
65
- query?: unknown;
66
- endpoint: string;
67
- }) => void | Promise<void>;
68
- defaultStreamHandler: (response: Response) => Promise<_StreamAsyncIterator<unknown>>;
69
- defaultHandler: (response: Response) => Promise<unknown>;
70
- }, input: {
71
- body: unknown;
72
- query: {
73
- [key: string]: string;
74
- };
75
- params: {
76
- [key: string]: string;
77
- };
78
- } & OPTS) => KnownAny;
79
- export interface _VovkDefaultFetcherOptions extends Omit<RequestInit, 'body' | 'method'> {
80
- reactNative?: {
81
- textStreaming: boolean;
82
- };
83
- prefix?: string;
84
- segmentName?: string;
85
- disableClientValidation?: boolean;
86
- validateOnClient?: _VovkValidateOnClient;
87
- fetcher?: _VovkClientFetcher;
88
- }
89
- export type _VovkValidateOnClient = (input: {
90
- body?: unknown;
91
- query?: unknown;
92
- endpoint: string;
93
- }, validators: {
94
- body?: unknown;
95
- query?: unknown;
96
- }) => void | Promise<void>;
97
- export type _VovkClientOptions<OPTS extends Record<string, KnownAny> = Record<string, never>> = {
98
- fetcher?: _VovkClientFetcher<OPTS>;
99
- validateOnClient?: _VovkValidateOnClient;
100
- defaultOptions?: Partial<OPTS>;
101
- };
102
- export {};
@@ -1,4 +0,0 @@
1
- import type { _HandlerSchema as HandlerSchema, _KnownAny as KnownAny, _VovkController as VovkController, _VovkRequest as VovkRequest } from './types';
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;
4
- export {};
@@ -1,4 +0,0 @@
1
- import { _StaticClass as StaticClass } from './types';
2
- export declare function _generateStaticAPI(c: Record<string, StaticClass>, slug?: string): {
3
- [x: string]: string[];
4
- }[];
package/index.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import { _createSegment as createSegment } from './createSegment';
2
- import { type _VovkErrorResponse as VovkErrorResponse, type _VovkRequest as VovkRequest, 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
- import type { _VovkClientOptions as VovkClientOptions, _VovkClientFetcher as VovkClientFetcher, _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions, _VovkValidateOnClient as VovkValidateOnClient } from './client/types';
4
- import { _HttpException as HttpException } from './HttpException';
5
- import { _createDecorator as createDecorator } from './createDecorator';
6
- import { _StreamResponse as StreamResponse } from './StreamResponse';
7
- import { worker } from './worker';
8
- import { _generateStaticAPI as generateStaticAPI } from './generateStaticAPI';
9
- export { type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkSchema, type VovkErrorResponse, type VovkRequest, type VovkBody, type VovkQuery, type VovkParams, type VovkReturnType, type VovkYieldType, type VovkClientOptions, StreamResponse, HttpException, HttpStatus, HttpMethod, createSegment, createDecorator, worker, generateStaticAPI, };
10
- export declare const get: {
11
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
12
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
13
- }, post: {
14
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
15
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
16
- }, put: {
17
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
18
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
19
- }, patch: {
20
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
21
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
22
- }, del: {
23
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
24
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
25
- }, head: {
26
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
27
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
28
- }, options: {
29
- (givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
30
- auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
31
- }, prefix: (givenPath?: string) => (givenTarget: import("./types")._KnownAny) => any, initVovk: (options: {
32
- segmentName?: string;
33
- controllers: Record<string, import("./types")._StaticClass>;
34
- workers?: Record<string, import("./types")._StaticClass>;
35
- exposeValidation?: boolean;
36
- emitSchema?: boolean;
37
- onError?: (err: Error, req: VovkRequest) => void | Promise<void>;
38
- }) => {
39
- GET: (req: VovkRequest, data: {
40
- params: Promise<Record<string, string[]>>;
41
- }) => Promise<Response>;
42
- POST: (req: VovkRequest, data: {
43
- params: Promise<Record<string, string[]>>;
44
- }) => Promise<Response>;
45
- PUT: (req: VovkRequest, data: {
46
- params: Promise<Record<string, string[]>>;
47
- }) => Promise<Response>;
48
- PATCH: (req: VovkRequest, data: {
49
- params: Promise<Record<string, string[]>>;
50
- }) => Promise<Response>;
51
- DELETE: (req: VovkRequest, data: {
52
- params: Promise<Record<string, string[]>>;
53
- }) => Promise<Response>;
54
- HEAD: (req: VovkRequest, data: {
55
- params: Promise<Record<string, string[]>>;
56
- }) => Promise<Response>;
57
- OPTIONS: (req: VovkRequest, data: {
58
- params: Promise<Record<string, string[]>>;
59
- }) => Promise<Response>;
60
- };
package/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var _a;
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.generateStaticAPI = exports.worker = exports.createDecorator = exports.createSegment = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.StreamResponse = void 0;
5
- const createSegment_1 = require("./createSegment");
6
- Object.defineProperty(exports, "createSegment", { enumerable: true, get: function () { return createSegment_1._createSegment; } });
7
- const types_1 = require("./types");
8
- Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function () { return types_1._HttpStatus; } });
9
- Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return types_1._HttpMethod; } });
10
- const HttpException_1 = require("./HttpException");
11
- Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return HttpException_1._HttpException; } });
12
- const createDecorator_1 = require("./createDecorator");
13
- Object.defineProperty(exports, "createDecorator", { enumerable: true, get: function () { return createDecorator_1._createDecorator; } });
14
- const StreamResponse_1 = require("./StreamResponse");
15
- Object.defineProperty(exports, "StreamResponse", { enumerable: true, get: function () { return StreamResponse_1._StreamResponse; } });
16
- const worker_1 = require("./worker");
17
- Object.defineProperty(exports, "worker", { enumerable: true, get: function () { return worker_1.worker; } });
18
- const generateStaticAPI_1 = require("./generateStaticAPI");
19
- Object.defineProperty(exports, "generateStaticAPI", { enumerable: true, get: function () { return generateStaticAPI_1._generateStaticAPI; } });
20
- _a = (0, createSegment_1._createSegment)(), exports.get = _a.get, exports.post = _a.post, exports.put = _a.put, exports.patch = _a.patch, exports.del = _a.del, exports.head = _a.head, exports.options = _a.options, exports.prefix = _a.prefix, exports.initVovk = _a.initVovk;