vovk 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HttpException.d.ts +6 -0
- package/HttpException.js +13 -0
- package/README.md +844 -1
- package/Segment.d.ts +31 -0
- package/Segment.js +132 -0
- package/StreamResponse.d.ts +16 -0
- package/StreamResponse.js +41 -0
- package/client/clientizeController.d.ts +3 -0
- package/client/clientizeController.js +67 -0
- package/client/defaultFetcher.d.ts +7 -0
- package/client/defaultFetcher.js +55 -0
- package/client/defaultStreamFetcher.d.ts +4 -0
- package/client/defaultStreamFetcher.js +103 -0
- package/client/index.d.ts +5 -0
- package/client/index.js +7 -0
- package/client/types.d.ts +69 -0
- package/client/types.js +2 -0
- package/createDecorator.d.ts +9 -0
- package/createDecorator.js +41 -0
- package/createSegment.d.ts +67 -0
- package/createSegment.js +171 -0
- package/index.d.ts +62 -0
- package/index.js +16 -0
- package/package.json +66 -6
- package/tsconfig.tsbuildinfo +1 -0
- package/types.d.ts +138 -0
- package/types.js +65 -0
- package/worker/index.d.ts +3 -0
- package/worker/index.js +7 -0
- package/worker/promisifyWorker.d.ts +2 -0
- package/worker/promisifyWorker.js +45 -0
- package/worker/types.d.ts +17 -0
- package/worker/types.js +2 -0
- package/worker/worker.d.ts +1 -0
- package/worker/worker.js +30 -0
package/types.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
|
2
|
+
export type _KnownAny = any;
|
|
3
|
+
export type _ErrorResponseBody = {
|
|
4
|
+
statusCode: _HttpStatus;
|
|
5
|
+
message: string;
|
|
6
|
+
isError: true;
|
|
7
|
+
};
|
|
8
|
+
export type _HandlerMetadata = {
|
|
9
|
+
path: string;
|
|
10
|
+
httpMethod: _HttpMethod;
|
|
11
|
+
clientValidators?: {
|
|
12
|
+
query?: _KnownAny;
|
|
13
|
+
body?: _KnownAny;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type _VovkControllerMetadata = {
|
|
17
|
+
controllerName: string;
|
|
18
|
+
_prefix?: string;
|
|
19
|
+
_handlers: Record<string, _HandlerMetadata>;
|
|
20
|
+
};
|
|
21
|
+
export type _HandlerMetadataJson = {
|
|
22
|
+
path: string;
|
|
23
|
+
httpMethod: string;
|
|
24
|
+
clientValidators?: {
|
|
25
|
+
query?: _KnownAny;
|
|
26
|
+
body?: _KnownAny;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type _VovkControllerMetadataJson = {
|
|
30
|
+
controllerName: string;
|
|
31
|
+
_prefix?: string;
|
|
32
|
+
_handlers: Record<string, _HandlerMetadataJson>;
|
|
33
|
+
};
|
|
34
|
+
export type _VovkWorkerMetadata = {
|
|
35
|
+
workerName: string;
|
|
36
|
+
_handlers: Record<string, Record<string, never>>;
|
|
37
|
+
};
|
|
38
|
+
export type _VovkControllerInternal = _VovkControllerMetadata & {
|
|
39
|
+
_activated?: true;
|
|
40
|
+
_onError?: (err: Error) => void;
|
|
41
|
+
};
|
|
42
|
+
export type _VovkController = Function & _VovkControllerInternal & {
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
};
|
|
45
|
+
export type _VovkWorker = Function & _VovkWorkerMetadata & {
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
};
|
|
48
|
+
export type _RouteHandler = (req: NextRequest, params: Record<string, string>) => Response | Promise<Response>;
|
|
49
|
+
export interface _VovkRequest<BODY = undefined, QUERY extends Record<string, string> | undefined = undefined> extends Omit<NextRequest, 'json' | 'nextUrl'> {
|
|
50
|
+
json: () => Promise<BODY>;
|
|
51
|
+
nextUrl: Omit<NextRequest['nextUrl'], 'searchParams'> & {
|
|
52
|
+
searchParams: Omit<NextRequest['nextUrl']['searchParams'], 'get'> & {
|
|
53
|
+
get: <KEY extends keyof QUERY>(key: KEY) => QUERY[KEY];
|
|
54
|
+
readonly __queryType: QUERY;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export type _ControllerStaticMethod<REQ extends _VovkRequest<undefined, _KnownAny> = _VovkRequest<undefined, Record<string, string>>, PARAMS extends {
|
|
59
|
+
[key: string]: string;
|
|
60
|
+
} = _KnownAny> = ((req: REQ, params: PARAMS) => unknown) & {
|
|
61
|
+
_controller?: _VovkController;
|
|
62
|
+
};
|
|
63
|
+
export type _VovkBody<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
64
|
+
[key: string]: string;
|
|
65
|
+
} = _KnownAny> = Awaited<ReturnType<Parameters<T>[0]['json']>>;
|
|
66
|
+
export type _VovkQuery<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
67
|
+
[key: string]: string;
|
|
68
|
+
} = _KnownAny> = Parameters<T>[0]['nextUrl']['searchParams']['__queryType'];
|
|
69
|
+
export type _VovkParams<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
70
|
+
[key: string]: string;
|
|
71
|
+
} = _KnownAny> = Parameters<T>[1];
|
|
72
|
+
export type _VovkReturnType<T extends _ControllerStaticMethod<REQ, PARAMS>, REQ extends _VovkRequest<undefined, _KnownAny> = Parameters<T>[0], PARAMS extends {
|
|
73
|
+
[key: string]: string;
|
|
74
|
+
} = _KnownAny> = Awaited<ReturnType<T>>;
|
|
75
|
+
export type _StreamAbortMessage = {
|
|
76
|
+
isError: true;
|
|
77
|
+
reason: _KnownAny;
|
|
78
|
+
};
|
|
79
|
+
export declare enum _HttpMethod {
|
|
80
|
+
GET = "GET",
|
|
81
|
+
POST = "POST",
|
|
82
|
+
PUT = "PUT",
|
|
83
|
+
PATCH = "PATCH",
|
|
84
|
+
DELETE = "DELETE",
|
|
85
|
+
HEAD = "HEAD",
|
|
86
|
+
OPTIONS = "OPTIONS"
|
|
87
|
+
}
|
|
88
|
+
export declare enum _HttpStatus {
|
|
89
|
+
NULL = 0,
|
|
90
|
+
CONTINUE = 100,
|
|
91
|
+
SWITCHING_PROTOCOLS = 101,
|
|
92
|
+
PROCESSING = 102,
|
|
93
|
+
EARLYHINTS = 103,
|
|
94
|
+
OK = 200,
|
|
95
|
+
CREATED = 201,
|
|
96
|
+
ACCEPTED = 202,
|
|
97
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
98
|
+
NO_CONTENT = 204,
|
|
99
|
+
RESET_CONTENT = 205,
|
|
100
|
+
PARTIAL_CONTENT = 206,
|
|
101
|
+
AMBIGUOUS = 300,
|
|
102
|
+
MOVED_PERMANENTLY = 301,
|
|
103
|
+
FOUND = 302,
|
|
104
|
+
SEE_OTHER = 303,
|
|
105
|
+
NOT_MODIFIED = 304,
|
|
106
|
+
TEMPORARY_REDIRECT = 307,
|
|
107
|
+
PERMANENT_REDIRECT = 308,
|
|
108
|
+
BAD_REQUEST = 400,
|
|
109
|
+
UNAUTHORIZED = 401,
|
|
110
|
+
PAYMENT_REQUIRED = 402,
|
|
111
|
+
FORBIDDEN = 403,
|
|
112
|
+
NOT_FOUND = 404,
|
|
113
|
+
METHOD_NOT_ALLOWED = 405,
|
|
114
|
+
NOT_ACCEPTABLE = 406,
|
|
115
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
116
|
+
REQUEST_TIMEOUT = 408,
|
|
117
|
+
CONFLICT = 409,
|
|
118
|
+
GONE = 410,
|
|
119
|
+
LENGTH_REQUIRED = 411,
|
|
120
|
+
PRECONDITION_FAILED = 412,
|
|
121
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
122
|
+
URI_TOO_LONG = 414,
|
|
123
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
124
|
+
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
125
|
+
EXPECTATION_FAILED = 417,
|
|
126
|
+
I_AM_A_TEAPOT = 418,
|
|
127
|
+
MISDIRECTED = 421,
|
|
128
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
129
|
+
FAILED_DEPENDENCY = 424,
|
|
130
|
+
PRECONDITION_REQUIRED = 428,
|
|
131
|
+
TOO_MANY_REQUESTS = 429,
|
|
132
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
133
|
+
NOT_IMPLEMENTED = 501,
|
|
134
|
+
BAD_GATEWAY = 502,
|
|
135
|
+
SERVICE_UNAVAILABLE = 503,
|
|
136
|
+
GATEWAY_TIMEOUT = 504,
|
|
137
|
+
HTTP_VERSION_NOT_SUPPORTED = 505
|
|
138
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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/worker/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
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; } });
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._promisifyWorker = void 0;
|
|
4
|
+
function _promisifyWorker(w, givenWorkerService) {
|
|
5
|
+
const workerService = givenWorkerService;
|
|
6
|
+
const instance = {};
|
|
7
|
+
let callsKey = 0;
|
|
8
|
+
if (typeof Worker === 'undefined' || !(w instanceof Worker)) {
|
|
9
|
+
throw new Error('Worker is not provided');
|
|
10
|
+
}
|
|
11
|
+
for (const method of Object.keys(workerService._handlers)) {
|
|
12
|
+
const value = workerService[method];
|
|
13
|
+
// @ts-expect-error TODO Fix this
|
|
14
|
+
instance[method] = (...args) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const key = callsKey;
|
|
17
|
+
callsKey += 1;
|
|
18
|
+
const onError = (e) => {
|
|
19
|
+
w.removeEventListener('message', onMessage);
|
|
20
|
+
w.removeEventListener('error', onError);
|
|
21
|
+
reject(e);
|
|
22
|
+
};
|
|
23
|
+
const onMessage = (e) => {
|
|
24
|
+
const { result, error, key: k, method: m } = e.data;
|
|
25
|
+
if (k !== key || m !== method) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
w.removeEventListener('message', onMessage);
|
|
29
|
+
w.removeEventListener('error', onError);
|
|
30
|
+
if (error) {
|
|
31
|
+
reject(error);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
resolve(result);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
w.addEventListener('message', onMessage);
|
|
38
|
+
w.addEventListener('error', onError);
|
|
39
|
+
w.postMessage({ key, args, method });
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return instance;
|
|
44
|
+
}
|
|
45
|
+
exports._promisifyWorker = _promisifyWorker;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { _KnownAny as KnownAny } from '../types';
|
|
2
|
+
type ToPromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
|
|
3
|
+
export type _WorkerPromiseInstance<T> = {
|
|
4
|
+
[K in keyof T]: T[K] extends (...args: KnownAny[]) => KnownAny ? (...args: Parameters<T[K]>) => ToPromise<ReturnType<T[K]>> : never;
|
|
5
|
+
};
|
|
6
|
+
export interface _WorkerInput {
|
|
7
|
+
method: string;
|
|
8
|
+
args: unknown[];
|
|
9
|
+
key: number;
|
|
10
|
+
}
|
|
11
|
+
export interface _WorkerOutput {
|
|
12
|
+
result?: unknown;
|
|
13
|
+
error?: unknown;
|
|
14
|
+
key: number;
|
|
15
|
+
method: string;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
package/worker/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function _worker(): (t: object) => void;
|
package/worker/worker.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._worker = void 0;
|
|
4
|
+
function _worker() {
|
|
5
|
+
return (t) => {
|
|
6
|
+
const target = t;
|
|
7
|
+
target._handlers = {};
|
|
8
|
+
for (const key of Object.getOwnPropertyNames(target)) {
|
|
9
|
+
if (typeof target[key] === 'function') {
|
|
10
|
+
target._handlers[key] = {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line no-undef
|
|
14
|
+
if (typeof self === 'undefined')
|
|
15
|
+
return; // no-op in non-worker environment
|
|
16
|
+
// eslint-disable-next-line no-undef
|
|
17
|
+
const w = self;
|
|
18
|
+
w.onmessage = async (evt) => {
|
|
19
|
+
const { method, args, key } = evt.data;
|
|
20
|
+
try {
|
|
21
|
+
const result = await target[method](...args);
|
|
22
|
+
w.postMessage({ result, key, method });
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
w.postMessage({ error: e, key, method });
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports._worker = _worker;
|