vovk 3.0.0-draft.33 → 3.0.0-draft.331

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 (196) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -96
  3. package/bin/index.mjs +8 -0
  4. package/{HttpException.d.ts → cjs/HttpException.d.ts} +2 -2
  5. package/{HttpException.js → cjs/HttpException.js} +3 -3
  6. package/cjs/JSONLinesResponse.d.ts +19 -0
  7. package/cjs/JSONLinesResponse.js +93 -0
  8. package/{VovkApp.d.ts → cjs/VovkApp.d.ts} +10 -9
  9. package/cjs/VovkApp.js +202 -0
  10. package/cjs/client/createRPC.d.ts +3 -0
  11. package/cjs/client/createRPC.js +90 -0
  12. package/cjs/client/defaultHandler.d.ts +6 -0
  13. package/cjs/client/defaultHandler.js +29 -0
  14. package/cjs/client/defaultStreamHandler.d.ts +9 -0
  15. package/{client → cjs/client}/defaultStreamHandler.js +25 -13
  16. package/cjs/client/fetcher.d.ts +14 -0
  17. package/cjs/client/fetcher.js +93 -0
  18. package/cjs/client/index.d.ts +4 -0
  19. package/cjs/client/index.js +10 -0
  20. package/cjs/client/progressive.d.ts +9 -0
  21. package/cjs/client/progressive.js +45 -0
  22. package/cjs/client/types.d.ts +123 -0
  23. package/{createVovkApp.d.ts → cjs/createVovkApp.d.ts} +12 -11
  24. package/cjs/createVovkApp.js +133 -0
  25. package/cjs/index.d.ts +65 -0
  26. package/cjs/index.js +38 -0
  27. package/cjs/openapi/error.d.ts +2 -0
  28. package/cjs/openapi/error.js +100 -0
  29. package/cjs/openapi/generateFnName.d.ts +23 -0
  30. package/cjs/openapi/generateFnName.js +81 -0
  31. package/cjs/openapi/index.d.ts +12 -0
  32. package/cjs/openapi/index.js +21 -0
  33. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  34. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  35. package/cjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  36. package/cjs/openapi/openAPIToVovkSchema/index.js +192 -0
  37. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  38. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  39. package/cjs/openapi/vovkSchemaToOpenAPI.d.ts +9 -0
  40. package/cjs/openapi/vovkSchemaToOpenAPI.js +233 -0
  41. package/cjs/types.d.ts +400 -0
  42. package/cjs/types.js +74 -0
  43. package/cjs/utils/camelCase.d.ts +6 -0
  44. package/cjs/utils/camelCase.js +37 -0
  45. package/cjs/utils/createCodeExamples.d.ts +19 -0
  46. package/cjs/utils/createCodeExamples.js +110 -0
  47. package/cjs/utils/createDecorator.d.ts +6 -0
  48. package/{createDecorator.js → cjs/utils/createDecorator.js} +26 -16
  49. package/cjs/utils/createLLMTools.d.ts +44 -0
  50. package/cjs/utils/createLLMTools.js +118 -0
  51. package/cjs/utils/createStandardValidation.d.ts +81 -0
  52. package/cjs/utils/createStandardValidation.js +33 -0
  53. package/cjs/utils/generateStaticAPI.d.ts +4 -0
  54. package/cjs/utils/generateStaticAPI.js +30 -0
  55. package/cjs/utils/getJSONSchemaExample.d.ts +8 -0
  56. package/cjs/utils/getJSONSchemaExample.js +234 -0
  57. package/cjs/utils/getJSONSchemaSample.d.ts +2 -0
  58. package/cjs/utils/getJSONSchemaSample.js +167 -0
  59. package/cjs/utils/getSchema.d.ts +21 -0
  60. package/cjs/utils/getSchema.js +38 -0
  61. package/cjs/utils/multitenant.d.ts +24 -0
  62. package/cjs/utils/multitenant.js +170 -0
  63. package/cjs/utils/parseQuery.d.ts +25 -0
  64. package/cjs/utils/parseQuery.js +156 -0
  65. package/{utils → cjs/utils}/reqForm.d.ts +1 -2
  66. package/cjs/utils/reqForm.js +33 -0
  67. package/{utils → cjs/utils}/reqMeta.d.ts +1 -2
  68. package/cjs/utils/reqQuery.d.ts +2 -0
  69. package/cjs/utils/reqQuery.js +10 -0
  70. package/cjs/utils/serializeQuery.d.ts +13 -0
  71. package/cjs/utils/serializeQuery.js +65 -0
  72. package/cjs/utils/setHandlerSchema.d.ts +4 -0
  73. package/cjs/utils/setHandlerSchema.js +15 -0
  74. package/cjs/utils/upperFirst.d.ts +1 -0
  75. package/cjs/utils/upperFirst.js +6 -0
  76. package/cjs/utils/withValidationLibrary.d.ts +76 -0
  77. package/cjs/utils/withValidationLibrary.js +123 -0
  78. package/mjs/HttpException.d.ts +7 -0
  79. package/mjs/HttpException.js +15 -0
  80. package/mjs/JSONLinesResponse.d.ts +19 -0
  81. package/mjs/JSONLinesResponse.js +93 -0
  82. package/mjs/VovkApp.d.ts +29 -0
  83. package/mjs/VovkApp.js +202 -0
  84. package/mjs/client/createRPC.d.ts +3 -0
  85. package/mjs/client/createRPC.js +90 -0
  86. package/mjs/client/defaultHandler.d.ts +6 -0
  87. package/mjs/client/defaultHandler.js +29 -0
  88. package/mjs/client/defaultStreamHandler.d.ts +9 -0
  89. package/mjs/client/defaultStreamHandler.js +94 -0
  90. package/mjs/client/fetcher.d.ts +14 -0
  91. package/mjs/client/fetcher.js +93 -0
  92. package/mjs/client/index.d.ts +4 -0
  93. package/mjs/client/index.js +10 -0
  94. package/mjs/client/progressive.d.ts +9 -0
  95. package/mjs/client/progressive.js +45 -0
  96. package/mjs/client/types.d.ts +123 -0
  97. package/mjs/createVovkApp.d.ts +63 -0
  98. package/mjs/createVovkApp.js +133 -0
  99. package/mjs/index.d.ts +65 -0
  100. package/mjs/index.js +38 -0
  101. package/mjs/openapi/error.d.ts +2 -0
  102. package/mjs/openapi/error.js +100 -0
  103. package/mjs/openapi/generateFnName.d.ts +23 -0
  104. package/mjs/openapi/generateFnName.js +81 -0
  105. package/mjs/openapi/index.d.ts +12 -0
  106. package/mjs/openapi/index.js +21 -0
  107. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  108. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  109. package/mjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  110. package/mjs/openapi/openAPIToVovkSchema/index.js +192 -0
  111. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  112. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  113. package/mjs/openapi/vovkSchemaToOpenAPI.d.ts +9 -0
  114. package/mjs/openapi/vovkSchemaToOpenAPI.js +233 -0
  115. package/mjs/types.d.ts +400 -0
  116. package/mjs/types.js +74 -0
  117. package/mjs/utils/camelCase.d.ts +6 -0
  118. package/mjs/utils/camelCase.js +37 -0
  119. package/mjs/utils/createCodeExamples.d.ts +19 -0
  120. package/mjs/utils/createCodeExamples.js +110 -0
  121. package/mjs/utils/createDecorator.d.ts +6 -0
  122. package/mjs/utils/createDecorator.js +48 -0
  123. package/mjs/utils/createLLMTools.d.ts +44 -0
  124. package/mjs/utils/createLLMTools.js +118 -0
  125. package/mjs/utils/createStandardValidation.d.ts +81 -0
  126. package/mjs/utils/createStandardValidation.js +33 -0
  127. package/mjs/utils/generateStaticAPI.d.ts +4 -0
  128. package/mjs/utils/generateStaticAPI.js +30 -0
  129. package/mjs/utils/getJSONSchemaExample.d.ts +8 -0
  130. package/mjs/utils/getJSONSchemaExample.js +234 -0
  131. package/mjs/utils/getJSONSchemaSample.d.ts +2 -0
  132. package/mjs/utils/getJSONSchemaSample.js +167 -0
  133. package/mjs/utils/getSchema.d.ts +21 -0
  134. package/mjs/utils/getSchema.js +38 -0
  135. package/mjs/utils/multitenant.d.ts +24 -0
  136. package/mjs/utils/multitenant.js +170 -0
  137. package/mjs/utils/parseQuery.d.ts +25 -0
  138. package/mjs/utils/parseQuery.js +156 -0
  139. package/mjs/utils/reqForm.d.ts +2 -0
  140. package/mjs/utils/reqForm.js +33 -0
  141. package/mjs/utils/reqMeta.d.ts +2 -0
  142. package/mjs/utils/reqMeta.js +13 -0
  143. package/mjs/utils/reqQuery.d.ts +2 -0
  144. package/mjs/utils/reqQuery.js +10 -0
  145. package/mjs/utils/serializeQuery.d.ts +13 -0
  146. package/mjs/utils/serializeQuery.js +65 -0
  147. package/mjs/utils/setHandlerSchema.d.ts +4 -0
  148. package/mjs/utils/setHandlerSchema.js +15 -0
  149. package/mjs/utils/shim.d.ts +1 -0
  150. package/mjs/utils/shim.js +18 -0
  151. package/mjs/utils/upperFirst.d.ts +1 -0
  152. package/mjs/utils/upperFirst.js +6 -0
  153. package/mjs/utils/withValidationLibrary.d.ts +76 -0
  154. package/mjs/utils/withValidationLibrary.js +123 -0
  155. package/package.json +29 -6
  156. package/.npmignore +0 -2
  157. package/StreamJSONResponse.d.ts +0 -17
  158. package/StreamJSONResponse.js +0 -54
  159. package/VovkApp.js +0 -185
  160. package/client/clientizeController.d.ts +0 -4
  161. package/client/clientizeController.js +0 -92
  162. package/client/defaultFetcher.d.ts +0 -4
  163. package/client/defaultFetcher.js +0 -49
  164. package/client/defaultHandler.d.ts +0 -2
  165. package/client/defaultHandler.js +0 -22
  166. package/client/defaultStreamHandler.d.ts +0 -4
  167. package/client/index.d.ts +0 -4
  168. package/client/index.js +0 -5
  169. package/client/types.d.ts +0 -100
  170. package/createDecorator.d.ts +0 -4
  171. package/createVovkApp.js +0 -118
  172. package/index.d.ts +0 -60
  173. package/index.js +0 -20
  174. package/types.d.ts +0 -157
  175. package/types.js +0 -65
  176. package/utils/generateStaticAPI.d.ts +0 -4
  177. package/utils/generateStaticAPI.js +0 -18
  178. package/utils/getSchema.d.ts +0 -8
  179. package/utils/getSchema.js +0 -38
  180. package/utils/reqForm.js +0 -13
  181. package/utils/reqQuery.d.ts +0 -3
  182. package/utils/reqQuery.js +0 -25
  183. package/utils/setClientValidatorsForHandler.d.ts +0 -5
  184. package/utils/setClientValidatorsForHandler.js +0 -25
  185. package/worker/index.d.ts +0 -3
  186. package/worker/index.js +0 -7
  187. package/worker/promisifyWorker.d.ts +0 -2
  188. package/worker/promisifyWorker.js +0 -141
  189. package/worker/types.d.ts +0 -31
  190. package/worker/worker.d.ts +0 -1
  191. package/worker/worker.js +0 -43
  192. /package/{client → cjs/client}/types.js +0 -0
  193. /package/{utils → cjs/utils}/reqMeta.js +0 -0
  194. /package/{utils → cjs/utils}/shim.d.ts +0 -0
  195. /package/{utils → cjs/utils}/shim.js +0 -0
  196. /package/{worker → mjs/client}/types.js +0 -0
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 = {}));
@@ -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
- }[];
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._generateStaticAPI = _generateStaticAPI;
4
- function _generateStaticAPI(c, slug = 'vovk') {
5
- const controllers = c;
6
- return [
7
- { [slug]: ['_schema_'] },
8
- ...Object.values(controllers)
9
- .map((controller) => {
10
- const handlers = controller._handlers;
11
- const splitPrefix = controller._prefix?.split('/') ?? [];
12
- return Object.values(handlers).map((handler) => {
13
- return { [slug]: [...splitPrefix, ...handler.path.split('/')].filter(Boolean) };
14
- });
15
- })
16
- .flat(),
17
- ];
18
- }
@@ -1,8 +0,0 @@
1
- import { _VovkSchema as VovkSchema, _StaticClass as StaticClass } from '../types';
2
- export default function getSchema(options: {
3
- emitSchema?: boolean;
4
- segmentName?: string;
5
- controllers: Record<string, StaticClass>;
6
- workers?: Record<string, StaticClass>;
7
- exposeValidation?: boolean;
8
- }): VovkSchema;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = getSchema;
4
- function getSchema(options) {
5
- const exposeValidation = options?.exposeValidation ?? true;
6
- const emitSchema = options.emitSchema ?? true;
7
- const schema = {
8
- emitSchema,
9
- segmentName: options.segmentName ?? '',
10
- controllers: {},
11
- workers: {},
12
- };
13
- if (!emitSchema)
14
- return schema;
15
- for (const [controllerName, controller] of Object.entries(options.controllers)) {
16
- schema.controllers[controllerName] = {
17
- controllerName: controllerName,
18
- originalControllerName: controller.name,
19
- prefix: controller._prefix ?? '',
20
- handlers: {
21
- ...(exposeValidation
22
- ? controller._handlers
23
- : Object.fromEntries(Object.entries(controller._handlers ?? {}).map(([key, value]) => [
24
- key,
25
- { ...value, validation: undefined },
26
- ]))),
27
- },
28
- };
29
- }
30
- for (const [workerName, worker] of Object.entries(options.workers ?? {})) {
31
- schema.workers[workerName] = {
32
- workerName,
33
- originalWorkerName: worker.name,
34
- handlers: { ...worker._handlers },
35
- };
36
- }
37
- return schema;
38
- }
package/utils/reqForm.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = reqForm;
4
- const formMap = new WeakMap();
5
- async function reqForm(req) {
6
- if (formMap.has(req)) {
7
- return formMap.get(req);
8
- }
9
- const body = await req.formData();
10
- const formData = Object.fromEntries(body.entries());
11
- formMap.set(req, formData);
12
- return formData;
13
- }
@@ -1,3 +0,0 @@
1
- import { _KnownAny as KnownAny } from '../types';
2
- import { VovkRequest } from 'vovk';
3
- export default function reqQuery<T extends object | undefined>(req: VovkRequest<KnownAny, T>): T;
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, validation: {
3
- body: unknown;
4
- query: unknown;
5
- }): Promise<void>;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = setClientValidatorsForHandler;
4
- function setClientValidatorsForHandler(h, validation) {
5
- return new Promise((resolve) => {
6
- setTimeout(() => {
7
- const controller = h._controller;
8
- if (!controller) {
9
- throw new Error('Error setting client validators. Controller not found. Did you forget to use an HTTP decorator?');
10
- }
11
- const handlerName = Object.getOwnPropertyNames(controller).find((key) => controller[key]._sourceMethod === h);
12
- if (!handlerName) {
13
- throw new Error('Error setting client validators. Handler not found.');
14
- }
15
- controller._handlers = {
16
- ...controller._handlers,
17
- [handlerName]: {
18
- ...controller._handlers[handlerName],
19
- validation,
20
- },
21
- };
22
- resolve();
23
- }, 0);
24
- });
25
- }
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, workerSchema: object): WorkerPromiseInstance<T>;
@@ -1,141 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._promisifyWorker = _promisifyWorker;
4
- function _promisifyWorker(currentWorker, workerSchema) {
5
- if (!workerSchema)
6
- throw new Error('Worker schema is not provided');
7
- const schema = workerSchema;
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) => _promisifyWorker(worker, schema);
27
- for (const methodName of Object.keys(schema.handlers)) {
28
- const { isGenerator } = schema.handlers[methodName];
29
- if (isGenerator) {
30
- const method = (...args) => {
31
- const key = callsKey;
32
- callsKey += 1;
33
- return {
34
- async *[Symbol.asyncIterator]() {
35
- if (!instance.worker) {
36
- throw new Error('Worker is not provided or terminated');
37
- }
38
- const w = instance.worker;
39
- const messageQueue = [];
40
- let messageResolver = null;
41
- const onMessage = (e) => {
42
- const { methodName: m, key: k } = e.data;
43
- if (k !== key || m !== methodName) {
44
- return;
45
- }
46
- if (messageResolver) {
47
- messageResolver(e.data);
48
- messageResolver = null;
49
- }
50
- else {
51
- messageQueue.push(e.data);
52
- }
53
- };
54
- const onError = (e) => {
55
- if (messageResolver) {
56
- messageResolver({ error: e.error });
57
- messageResolver = null;
58
- }
59
- else {
60
- messageQueue.push({ error: e.error });
61
- }
62
- w.removeEventListener('message', onMessage);
63
- w.removeEventListener('error', onError);
64
- throw e.error;
65
- };
66
- w.addEventListener('message', onMessage);
67
- w.addEventListener('error', onError);
68
- w.postMessage({ key, args, methodName });
69
- try {
70
- while (true) {
71
- let message = null;
72
- if (messageQueue.length > 0) {
73
- message = messageQueue.shift();
74
- }
75
- else {
76
- message = await new Promise((resolve) => {
77
- messageResolver = resolve;
78
- });
79
- }
80
- const { result, error, done } = message;
81
- if (error) {
82
- throw error;
83
- }
84
- if (done) {
85
- break;
86
- }
87
- yield result;
88
- }
89
- w.removeEventListener('message', onMessage);
90
- w.removeEventListener('error', onError);
91
- }
92
- catch (e) {
93
- w.removeEventListener('message', onMessage);
94
- w.removeEventListener('error', onError);
95
- throw e;
96
- }
97
- },
98
- };
99
- };
100
- // @ts-expect-error TODO
101
- instance[methodName] = method;
102
- }
103
- else {
104
- const method = (...args) => {
105
- if (!instance.worker) {
106
- throw new Error('Worker is not provided or terminated');
107
- }
108
- const w = instance.worker;
109
- return new Promise((resolve, reject) => {
110
- const key = callsKey;
111
- callsKey += 1;
112
- const onError = (e) => {
113
- w.removeEventListener('message', onMessage);
114
- w.removeEventListener('error', onError);
115
- reject(e);
116
- };
117
- const onMessage = (e) => {
118
- const { result, error, key: k, methodName: m } = e.data;
119
- if (k !== key || m !== methodName) {
120
- return;
121
- }
122
- w.removeEventListener('message', onMessage);
123
- w.removeEventListener('error', onError);
124
- if (error) {
125
- reject(error);
126
- }
127
- else {
128
- resolve(result);
129
- }
130
- };
131
- w.addEventListener('message', onMessage);
132
- w.addEventListener('error', onError);
133
- w.postMessage({ key, args, methodName });
134
- });
135
- };
136
- // @ts-expect-error TODO
137
- instance[methodName] = method;
138
- }
139
- }
140
- return instance;
141
- }
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 {};
@@ -1 +0,0 @@
1
- export declare function _worker(): (t: object) => void;
package/worker/worker.js DELETED
@@ -1,43 +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
- for (const key of Object.getOwnPropertyNames(target)) {
9
- const member = target[key];
10
- if (typeof member === 'function') {
11
- const prototype = Object.getPrototypeOf(member);
12
- const isGenerator = prototype === Object.getPrototypeOf(function* () { }) ||
13
- prototype === Object.getPrototypeOf(async function* () { });
14
- target._handlers[key] = {};
15
- if (isGenerator) {
16
- target._handlers[key].isGenerator = true;
17
- }
18
- }
19
- }
20
- if (typeof self === 'undefined')
21
- return; // no-op in non-worker environment
22
- const w = self;
23
- w.onmessage = async (evt) => {
24
- const { methodName, args, key } = evt.data;
25
- try {
26
- const result = await target[methodName](...args);
27
- if (result && typeof result === 'object' && 'next' in result && typeof result.next === 'function') {
28
- const iterable = result;
29
- for await (const result of iterable) {
30
- w.postMessage({ result, key, methodName });
31
- }
32
- w.postMessage({ done: true, key, methodName });
33
- }
34
- else {
35
- w.postMessage({ result, key, methodName });
36
- }
37
- }
38
- catch (e) {
39
- w.postMessage({ error: e, key, methodName });
40
- }
41
- };
42
- };
43
- }
File without changes
File without changes
File without changes
File without changes
File without changes