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
package/types.d.ts DELETED
@@ -1,191 +0,0 @@
1
- import type { NextRequest } from 'next/server';
2
- import type { _StreamResponse as StreamResponse } from './StreamResponse';
3
- import { _StreamAsyncIterator as StreamAsyncIterator } from './client/types';
4
- export type _KnownAny = any;
5
- export type _StaticClass = Function;
6
- export type _VovkSchema = {
7
- emitSchema: boolean;
8
- segmentName: string;
9
- workers: Record<string, _VovkWorkerSchema>;
10
- controllers: Record<string, _VovkControllerSchema>;
11
- };
12
- export type _VovkErrorResponse = {
13
- statusCode: _HttpStatus;
14
- message: string;
15
- isError: true;
16
- };
17
- export type _HandlerSchema = {
18
- path: string;
19
- httpMethod: _HttpMethod;
20
- clientValidators?: {
21
- query?: _KnownAny;
22
- body?: _KnownAny;
23
- };
24
- customSchema?: Record<string, _KnownAny>;
25
- };
26
- export type _VovkControllerSchema = {
27
- _controllerName: string;
28
- _originalControllerName: string;
29
- _prefix?: string;
30
- _handlers: Record<string, _HandlerSchema>;
31
- };
32
- export type _VovkWorkerSchema = {
33
- _workerName: string;
34
- _originalWorkerName: string;
35
- _handlers: Record<string, {
36
- isGenerator?: true;
37
- }>;
38
- };
39
- export type _VovkControllerInternal = _VovkControllerSchema & {
40
- _activated?: true;
41
- _onError?: (err: Error, req: _VovkRequest) => void | Promise<void>;
42
- };
43
- export type _VovkController = _StaticClass & _VovkControllerInternal & {
44
- [key: string]: unknown;
45
- };
46
- export type _VovkWorker = _StaticClass & _VovkWorkerSchema & {
47
- [key: string]: unknown;
48
- };
49
- export type _DecoratorOptions = {
50
- cors?: boolean;
51
- headers?: Record<string, string>;
52
- };
53
- export type _RouteHandler = ((req: _VovkRequest, params: Record<string, string>) => Response | Promise<Response> | Iterable<unknown> | AsyncIterable<unknown>) & {
54
- _options?: _DecoratorOptions;
55
- };
56
- export interface _VovkRequest<BODY = undefined, QUERY extends object | undefined = undefined> extends Omit<NextRequest, 'json' | 'nextUrl'> {
57
- json: () => Promise<BODY>;
58
- nextUrl: Omit<NextRequest['nextUrl'], 'searchParams'> & {
59
- searchParams: Omit<NextRequest['nextUrl']['searchParams'], 'get' | 'getAll' | 'entries' | 'forEach' | 'keys' | 'values'> & {
60
- get: <KEY extends keyof QUERY>(key: KEY) => QUERY[KEY] extends readonly (infer ITEM)[] ? ITEM : QUERY[KEY];
61
- getAll: <KEY extends keyof QUERY>(key: KEY) => QUERY[KEY] extends _KnownAny[] ? QUERY[KEY] : QUERY[KEY][];
62
- entries: () => IterableIterator<[keyof QUERY, QUERY[keyof QUERY]]>;
63
- forEach: (callbackfn: (value: QUERY[keyof QUERY], key: keyof QUERY, searchParams: NextRequest['nextUrl']['searchParams']) => void) => void;
64
- keys: () => IterableIterator<keyof QUERY>;
65
- values: () => IterableIterator<QUERY[keyof QUERY]>;
66
- readonly __queryType: QUERY;
67
- };
68
- };
69
- vovk: {
70
- body: () => Promise<BODY>;
71
- query: () => QUERY;
72
- meta: <T = Record<_KnownAny, _KnownAny>>(meta?: T | null) => T;
73
- };
74
- }
75
- export type _ControllerStaticMethod<REQ extends _VovkRequest<undefined, _KnownAny> = _VovkRequest<undefined, Record<string, string | string[]>>, PARAMS extends {
76
- [key: string]: string;
77
- } = _KnownAny> = ((req: REQ, params: PARAMS) => unknown) & {
78
- _controller?: _VovkController;
79
- };
80
- export type _VovkControllerBody<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
81
- [key: string]: string;
82
- } = _KnownAny> = Awaited<ReturnType<Parameters<T>[0]['json']>>;
83
- export type _VovkControllerQuery<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
84
- [key: string]: string;
85
- } = _KnownAny> = Parameters<T>[0]['nextUrl']['searchParams']['__queryType'];
86
- export type _VovkControllerParams<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
87
- [key: string]: string;
88
- } = _KnownAny> = Parameters<T>[1];
89
- export type _VovkControllerReturnType<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
90
- [key: string]: string;
91
- } = _KnownAny> = Awaited<ReturnType<T>>;
92
- export type _VovkControlerYieldType<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
93
- [key: string]: string;
94
- } = _KnownAny> = T extends (...args: _KnownAny[]) => AsyncGenerator<infer Y, _KnownAny, _KnownAny> ? Y : T extends (...args: _KnownAny[]) => Generator<infer Y, _KnownAny, _KnownAny> ? Y : T extends (...args: _KnownAny[]) => Promise<StreamResponse<infer Y>> | StreamResponse<infer Y> ? Y : never;
95
- export type _VovkClientBody<T extends (options: OPTIONS) => _KnownAny, OPTIONS extends {
96
- body: B;
97
- [key: string]: _KnownAny;
98
- } = Parameters<T>[0], B = _KnownAny> = Parameters<T>[0]['body'];
99
- export type _VovkClientQuery<T extends (options: OPTIONS) => _KnownAny, OPTIONS extends {
100
- query: Q;
101
- [key: string]: _KnownAny;
102
- } = Parameters<T>[0], Q = _KnownAny> = Parameters<T>[0]['query'];
103
- export type _VovkClientParams<T extends (options: OPTIONS) => _KnownAny, OPTIONS extends {
104
- params: P;
105
- [key: string]: _KnownAny;
106
- } = Parameters<T>[0], P = _KnownAny> = Parameters<T>[0]['params'];
107
- export type _VovkClientYieldType<T extends (...args: _KnownAny[]) => unknown> = T extends (...args: _KnownAny[]) => Promise<StreamAsyncIterator<infer Y>> ? Y : never;
108
- export type _VovkClientReturnType<T extends (...args: _KnownAny) => unknown> = Awaited<ReturnType<T>>;
109
- type ClientStaticMethod = ((...args: _KnownAny[]) => _KnownAny) & {
110
- __isClientMethod: boolean;
111
- };
112
- export type _VovkBody<T extends ClientStaticMethod | _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
113
- [key: string]: string;
114
- } = _KnownAny> = T extends ClientStaticMethod ? _VovkClientBody<T> : T extends _ControllerStaticMethod<REQ, PARAMS> ? _VovkControllerBody<T, REQ, PARAMS> : never;
115
- export type _VovkQuery<T extends ClientStaticMethod | _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
116
- [key: string]: string;
117
- } = _KnownAny> = T extends _ControllerStaticMethod<REQ, PARAMS> ? _VovkControllerQuery<T, REQ, PARAMS> : T extends ClientStaticMethod ? _VovkClientQuery<T> : never;
118
- export type _VovkParams<T extends ClientStaticMethod | _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
119
- [key: string]: string;
120
- } = _KnownAny> = T extends _ControllerStaticMethod<REQ, PARAMS> ? _VovkControllerParams<T, REQ, PARAMS> : T extends ClientStaticMethod ? _VovkClientParams<T> : never;
121
- export type _VovkYieldType<T extends ClientStaticMethod | _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
122
- [key: string]: string;
123
- } = _KnownAny> = T extends _ControllerStaticMethod<REQ, PARAMS> ? _VovkControlerYieldType<T, REQ, PARAMS> : T extends ClientStaticMethod ? _VovkClientYieldType<T> : never;
124
- export type _VovkReturnType<T extends ClientStaticMethod | _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
125
- [key: string]: string;
126
- } = _KnownAny> = T extends _ControllerStaticMethod<REQ, PARAMS> ? _VovkControllerReturnType<T, REQ, PARAMS> : T extends ClientStaticMethod ? _VovkClientReturnType<T> : never;
127
- export type _StreamAbortMessage = {
128
- isError: true;
129
- reason: _KnownAny;
130
- };
131
- export declare enum _HttpMethod {
132
- GET = "GET",
133
- POST = "POST",
134
- PUT = "PUT",
135
- PATCH = "PATCH",
136
- DELETE = "DELETE",
137
- HEAD = "HEAD",
138
- OPTIONS = "OPTIONS"
139
- }
140
- export declare enum _HttpStatus {
141
- NULL = 0,
142
- CONTINUE = 100,
143
- SWITCHING_PROTOCOLS = 101,
144
- PROCESSING = 102,
145
- EARLYHINTS = 103,
146
- OK = 200,
147
- CREATED = 201,
148
- ACCEPTED = 202,
149
- NON_AUTHORITATIVE_INFORMATION = 203,
150
- NO_CONTENT = 204,
151
- RESET_CONTENT = 205,
152
- PARTIAL_CONTENT = 206,
153
- AMBIGUOUS = 300,
154
- MOVED_PERMANENTLY = 301,
155
- FOUND = 302,
156
- SEE_OTHER = 303,
157
- NOT_MODIFIED = 304,
158
- TEMPORARY_REDIRECT = 307,
159
- PERMANENT_REDIRECT = 308,
160
- BAD_REQUEST = 400,
161
- UNAUTHORIZED = 401,
162
- PAYMENT_REQUIRED = 402,
163
- FORBIDDEN = 403,
164
- NOT_FOUND = 404,
165
- METHOD_NOT_ALLOWED = 405,
166
- NOT_ACCEPTABLE = 406,
167
- PROXY_AUTHENTICATION_REQUIRED = 407,
168
- REQUEST_TIMEOUT = 408,
169
- CONFLICT = 409,
170
- GONE = 410,
171
- LENGTH_REQUIRED = 411,
172
- PRECONDITION_FAILED = 412,
173
- PAYLOAD_TOO_LARGE = 413,
174
- URI_TOO_LONG = 414,
175
- UNSUPPORTED_MEDIA_TYPE = 415,
176
- REQUESTED_RANGE_NOT_SATISFIABLE = 416,
177
- EXPECTATION_FAILED = 417,
178
- I_AM_A_TEAPOT = 418,
179
- MISDIRECTED = 421,
180
- UNPROCESSABLE_ENTITY = 422,
181
- FAILED_DEPENDENCY = 424,
182
- PRECONDITION_REQUIRED = 428,
183
- TOO_MANY_REQUESTS = 429,
184
- INTERNAL_SERVER_ERROR = 500,
185
- NOT_IMPLEMENTED = 501,
186
- BAD_GATEWAY = 502,
187
- SERVICE_UNAVAILABLE = 503,
188
- GATEWAY_TIMEOUT = 504,
189
- HTTP_VERSION_NOT_SUPPORTED = 505
190
- }
191
- export {};
package/types.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._HttpStatus = exports._HttpMethod = void 0;
4
- var _HttpMethod;
5
- (function (_HttpMethod) {
6
- _HttpMethod["GET"] = "GET";
7
- _HttpMethod["POST"] = "POST";
8
- _HttpMethod["PUT"] = "PUT";
9
- _HttpMethod["PATCH"] = "PATCH";
10
- _HttpMethod["DELETE"] = "DELETE";
11
- _HttpMethod["HEAD"] = "HEAD";
12
- _HttpMethod["OPTIONS"] = "OPTIONS";
13
- })(_HttpMethod || (exports._HttpMethod = _HttpMethod = {}));
14
- var _HttpStatus;
15
- (function (_HttpStatus) {
16
- _HttpStatus[_HttpStatus["NULL"] = 0] = "NULL";
17
- _HttpStatus[_HttpStatus["CONTINUE"] = 100] = "CONTINUE";
18
- _HttpStatus[_HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
19
- _HttpStatus[_HttpStatus["PROCESSING"] = 102] = "PROCESSING";
20
- _HttpStatus[_HttpStatus["EARLYHINTS"] = 103] = "EARLYHINTS";
21
- _HttpStatus[_HttpStatus["OK"] = 200] = "OK";
22
- _HttpStatus[_HttpStatus["CREATED"] = 201] = "CREATED";
23
- _HttpStatus[_HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
24
- _HttpStatus[_HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
25
- _HttpStatus[_HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
26
- _HttpStatus[_HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
27
- _HttpStatus[_HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
28
- _HttpStatus[_HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
29
- _HttpStatus[_HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
30
- _HttpStatus[_HttpStatus["FOUND"] = 302] = "FOUND";
31
- _HttpStatus[_HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
32
- _HttpStatus[_HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
33
- _HttpStatus[_HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
34
- _HttpStatus[_HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
35
- _HttpStatus[_HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
36
- _HttpStatus[_HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
37
- _HttpStatus[_HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
38
- _HttpStatus[_HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
39
- _HttpStatus[_HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
40
- _HttpStatus[_HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
41
- _HttpStatus[_HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
42
- _HttpStatus[_HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
43
- _HttpStatus[_HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
44
- _HttpStatus[_HttpStatus["CONFLICT"] = 409] = "CONFLICT";
45
- _HttpStatus[_HttpStatus["GONE"] = 410] = "GONE";
46
- _HttpStatus[_HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
47
- _HttpStatus[_HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
48
- _HttpStatus[_HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
49
- _HttpStatus[_HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
50
- _HttpStatus[_HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
51
- _HttpStatus[_HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
52
- _HttpStatus[_HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
53
- _HttpStatus[_HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
54
- _HttpStatus[_HttpStatus["MISDIRECTED"] = 421] = "MISDIRECTED";
55
- _HttpStatus[_HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
56
- _HttpStatus[_HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
57
- _HttpStatus[_HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
58
- _HttpStatus[_HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
59
- _HttpStatus[_HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
60
- _HttpStatus[_HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
61
- _HttpStatus[_HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
62
- _HttpStatus[_HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
63
- _HttpStatus[_HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
64
- _HttpStatus[_HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
65
- })(_HttpStatus || (exports._HttpStatus = _HttpStatus = {}));
package/utils/reqQuery.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = reqQuery;
4
- const clientizeController_1 = require("../client/clientizeController");
5
- function reqQuery(req) {
6
- const queryArr = req.nextUrl.searchParams.get(clientizeController_1.ARRAY_QUERY_KEY)?.split(',') ?? null;
7
- const entries = [...req.nextUrl.searchParams.entries()];
8
- const query = entries.reduce((acc, [key, value]) => {
9
- if (key === clientizeController_1.ARRAY_QUERY_KEY)
10
- return acc;
11
- if (queryArr?.includes(key)) {
12
- if (!(key in acc)) {
13
- acc[key] = [value];
14
- }
15
- else {
16
- acc[key].push(value);
17
- }
18
- }
19
- else {
20
- acc[key] = value;
21
- }
22
- return acc;
23
- }, {});
24
- return query;
25
- }
@@ -1,5 +0,0 @@
1
- import { _KnownAny as KnownAny } from '../types';
2
- export default function setClientValidatorsForHandler(h: (...args: KnownAny[]) => KnownAny, validators: {
3
- body: unknown;
4
- query: unknown;
5
- }): Promise<void>;
package/worker/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { _worker as worker } from './worker';
2
- import { _promisifyWorker as promisifyWorker } from './promisifyWorker';
3
- export { worker, promisifyWorker };
package/worker/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promisifyWorker = exports.worker = void 0;
4
- const worker_1 = require("./worker");
5
- Object.defineProperty(exports, "worker", { enumerable: true, get: function () { return worker_1._worker; } });
6
- const promisifyWorker_1 = require("./promisifyWorker");
7
- Object.defineProperty(exports, "promisifyWorker", { enumerable: true, get: function () { return promisifyWorker_1._promisifyWorker; } });
@@ -1,2 +0,0 @@
1
- import type { _WorkerPromiseInstance as WorkerPromiseInstance } from './types';
2
- export declare function _promisifyWorker<T extends object>(currentWorker: Worker | null, givenWorkerService: object): WorkerPromiseInstance<T>;
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._promisifyWorker = _promisifyWorker;
4
- function _promisifyWorker(currentWorker, givenWorkerService) {
5
- if (!givenWorkerService)
6
- throw new Error('Worker schema is not provided');
7
- const workerService = givenWorkerService;
8
- const instance = {
9
- worker: currentWorker,
10
- };
11
- let callsKey = 0;
12
- instance.terminate = () => {
13
- if (instance._isTerminated)
14
- return;
15
- instance._isTerminated = true;
16
- instance.worker?.terminate();
17
- instance.worker = null;
18
- };
19
- instance.employ = (worker) => {
20
- if (instance._isTerminated)
21
- return instance;
22
- instance._isTerminated = true;
23
- instance.worker = worker;
24
- return instance;
25
- };
26
- instance.fork = (worker) => {
27
- return _promisifyWorker(worker, givenWorkerService);
28
- };
29
- for (const methodName of Object.keys(workerService._handlers)) {
30
- const { isGenerator } = workerService._handlers[methodName];
31
- if (isGenerator) {
32
- const method = (...args) => {
33
- const key = callsKey;
34
- callsKey += 1;
35
- return {
36
- async *[Symbol.asyncIterator]() {
37
- if (!instance.worker) {
38
- throw new Error('Worker is not provided or terminated');
39
- }
40
- const w = instance.worker;
41
- const messageQueue = [];
42
- let messageResolver = null;
43
- const onMessage = (e) => {
44
- const { methodName: m, key: k } = e.data;
45
- if (k !== key || m !== methodName) {
46
- return;
47
- }
48
- if (messageResolver) {
49
- messageResolver(e.data);
50
- messageResolver = null;
51
- }
52
- else {
53
- messageQueue.push(e.data);
54
- }
55
- };
56
- const onError = (e) => {
57
- if (messageResolver) {
58
- messageResolver({ error: e.error });
59
- messageResolver = null;
60
- }
61
- else {
62
- messageQueue.push({ error: e.error });
63
- }
64
- w.removeEventListener('message', onMessage);
65
- w.removeEventListener('error', onError);
66
- throw e.error;
67
- };
68
- w.addEventListener('message', onMessage);
69
- w.addEventListener('error', onError);
70
- w.postMessage({ key, args, methodName });
71
- try {
72
- while (true) {
73
- let message = null;
74
- if (messageQueue.length > 0) {
75
- message = messageQueue.shift();
76
- }
77
- else {
78
- message = await new Promise((resolve) => {
79
- messageResolver = resolve;
80
- });
81
- }
82
- const { result, error, done } = message;
83
- if (error) {
84
- throw error;
85
- }
86
- if (done) {
87
- break;
88
- }
89
- yield result;
90
- }
91
- w.removeEventListener('message', onMessage);
92
- w.removeEventListener('error', onError);
93
- }
94
- catch (e) {
95
- w.removeEventListener('message', onMessage);
96
- w.removeEventListener('error', onError);
97
- throw e;
98
- }
99
- },
100
- };
101
- };
102
- // @ts-expect-error TODO
103
- instance[methodName] = method;
104
- }
105
- else {
106
- const method = (...args) => {
107
- if (!instance.worker) {
108
- throw new Error('Worker is not provided or terminated');
109
- }
110
- const w = instance.worker;
111
- return new Promise((resolve, reject) => {
112
- const key = callsKey;
113
- callsKey += 1;
114
- const onError = (e) => {
115
- w.removeEventListener('message', onMessage);
116
- w.removeEventListener('error', onError);
117
- reject(e);
118
- };
119
- const onMessage = (e) => {
120
- const { result, error, key: k, methodName: m } = e.data;
121
- if (k !== key || m !== methodName) {
122
- return;
123
- }
124
- w.removeEventListener('message', onMessage);
125
- w.removeEventListener('error', onError);
126
- if (error) {
127
- reject(error);
128
- }
129
- else {
130
- resolve(result);
131
- }
132
- };
133
- w.addEventListener('message', onMessage);
134
- w.addEventListener('error', onError);
135
- w.postMessage({ key, args, methodName });
136
- });
137
- };
138
- // @ts-expect-error TODO
139
- instance[methodName] = method;
140
- }
141
- }
142
- return instance;
143
- }
package/worker/types.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import type { _KnownAny as KnownAny } from '../types';
2
- type ToPromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
3
- type ToAsyncGenerator<T> = T extends AsyncGenerator<unknown, unknown, unknown> ? T : T extends Generator<infer U, unknown, unknown> ? AsyncGenerator<U, unknown, unknown> : AsyncGenerator<T, unknown, unknown>;
4
- type ToProperReturnType<T> = T extends Generator<unknown, unknown, unknown> | AsyncGenerator<unknown, unknown, unknown> ? ToAsyncGenerator<T> : ToPromise<T>;
5
- type OmitNever<T> = {
6
- [K in keyof T as T[K] extends never ? never : K]: T[K];
7
- };
8
- export type _WorkerPromiseInstanceWithNever<T> = {
9
- [K in keyof T]: T[K] extends (...args: KnownAny[]) => KnownAny ? (...args: Parameters<T[K]>) => ToProperReturnType<ReturnType<T[K]>> : never;
10
- };
11
- export type _WorkerPromiseInstance<T> = OmitNever<_WorkerPromiseInstanceWithNever<T>> & {
12
- terminate: () => void;
13
- employ: (w: Worker) => _WorkerPromiseInstance<T>;
14
- fork: (w: Worker) => _WorkerPromiseInstance<T>;
15
- worker: Worker | null;
16
- _isTerminated?: true;
17
- [Symbol.dispose]: () => void;
18
- };
19
- export interface _WorkerInput {
20
- methodName: string;
21
- args: unknown[];
22
- key: number;
23
- }
24
- export interface _WorkerOutput {
25
- methodName: string;
26
- result?: unknown;
27
- error?: unknown;
28
- done?: true;
29
- key: number;
30
- }
31
- export {};
package/worker/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare function _worker(): (t: object) => void;
package/worker/worker.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._worker = _worker;
4
- function _worker() {
5
- return (t) => {
6
- const target = t;
7
- target._handlers = {};
8
- // TODO: Experimental: You can pass Worker Service instead of schema to prommisify worker
9
- for (const key of Object.getOwnPropertyNames(target)) {
10
- const member = target[key];
11
- if (typeof member === 'function') {
12
- const prototype = Object.getPrototypeOf(member);
13
- const isGenerator = prototype === Object.getPrototypeOf(function* () { }) ||
14
- prototype === Object.getPrototypeOf(async function* () { });
15
- target._handlers[key] = {};
16
- if (isGenerator) {
17
- target._handlers[key].isGenerator = true;
18
- }
19
- }
20
- }
21
- if (typeof self === 'undefined')
22
- return; // no-op in non-worker environment
23
- const w = self;
24
- w.onmessage = async (evt) => {
25
- const { methodName, args, key } = evt.data;
26
- try {
27
- const result = await target[methodName](...args);
28
- if (result && typeof result === 'object' && 'next' in result && typeof result.next === 'function') {
29
- const iterable = result;
30
- for await (const result of iterable) {
31
- w.postMessage({ result, key, methodName });
32
- }
33
- w.postMessage({ done: true, key, methodName });
34
- }
35
- else {
36
- w.postMessage({ result, key, methodName });
37
- }
38
- }
39
- catch (e) {
40
- w.postMessage({ error: e, key, methodName });
41
- }
42
- };
43
- };
44
- }
File without changes
File without changes
File without changes
File without changes