vovk 3.0.0-draft.23 → 3.0.0-draft.26
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/{Segment.d.ts → VovkApp.d.ts} +2 -2
- package/{Segment.js → VovkApp.js} +6 -6
- package/client/clientizeController.js +1 -1
- package/{createSegment.d.ts → createVovkApp.d.ts} +1 -1
- package/{createSegment.js → createVovkApp.js} +25 -25
- package/index.d.ts +3 -3
- package/index.js +5 -5
- package/package.json +1 -1
- package/{generateStaticAPI.d.ts → utils/generateStaticAPI.d.ts} +1 -1
- package/{generateStaticAPI.js → utils/generateStaticAPI.js} +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { _HttpMethod as HttpMethod, _HttpStatus as HttpStatus, type _RouteHandler as RouteHandler, type _VovkController as VovkController, type _DecoratorOptions as DecoratorOptions, type _VovkRequest as VovkRequest } from './types';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class _VovkApp {
|
|
3
3
|
#private;
|
|
4
4
|
private static getHeadersFromOptions;
|
|
5
|
-
|
|
5
|
+
routes: Record<HttpMethod, Map<VovkController, Record<string, RouteHandler>>>;
|
|
6
6
|
GET: (req: VovkRequest, data: {
|
|
7
7
|
params: Promise<Record<string, string[]>>;
|
|
8
8
|
}) => Promise<Response>;
|
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
var _a;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports._VovkApp = void 0;
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
const HttpException_1 = require("./HttpException");
|
|
10
10
|
const StreamJSONResponse_1 = require("./StreamJSONResponse");
|
|
11
11
|
const reqQuery_1 = __importDefault(require("./utils/reqQuery"));
|
|
12
12
|
const reqMeta_1 = __importDefault(require("./utils/reqMeta"));
|
|
13
13
|
const reqForm_1 = __importDefault(require("./utils/reqForm"));
|
|
14
|
-
class
|
|
14
|
+
class _VovkApp {
|
|
15
15
|
static getHeadersFromOptions(options) {
|
|
16
16
|
if (!options)
|
|
17
17
|
return {};
|
|
@@ -26,7 +26,7 @@ class _Segment {
|
|
|
26
26
|
};
|
|
27
27
|
return headers;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
routes = {
|
|
30
30
|
GET: new Map(),
|
|
31
31
|
POST: new Map(),
|
|
32
32
|
PUT: new Map(),
|
|
@@ -60,7 +60,7 @@ class _Segment {
|
|
|
60
60
|
}, options);
|
|
61
61
|
};
|
|
62
62
|
#callMethod = async (httpMethod, req, params) => {
|
|
63
|
-
const controllers = this.
|
|
63
|
+
const controllers = this.routes[httpMethod];
|
|
64
64
|
const methodParams = {};
|
|
65
65
|
const path = params[Object.keys(params)[0]];
|
|
66
66
|
const handlers = {};
|
|
@@ -181,5 +181,5 @@ class _Segment {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
exports.
|
|
185
|
-
_a =
|
|
184
|
+
exports._VovkApp = _VovkApp;
|
|
185
|
+
_a = _VovkApp;
|
|
@@ -84,7 +84,7 @@ const _clientizeController = (controllerSchema, segmentName, options) => {
|
|
|
84
84
|
return Promise.resolve(fetcherPromise);
|
|
85
85
|
return input.transform ? fetcherPromise.then(input.transform) : fetcherPromise;
|
|
86
86
|
};
|
|
87
|
-
// @ts-expect-error TODO
|
|
87
|
+
// @ts-expect-error TODO
|
|
88
88
|
client[staticMethodName] = handler;
|
|
89
89
|
}
|
|
90
90
|
return client;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type _KnownAny as KnownAny, type _DecoratorOptions as DecoratorOptions, type _VovkRequest as VovkRequest, type _StaticClass as StaticClass } from './types';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function _createVovkApp(): {
|
|
3
3
|
get: {
|
|
4
4
|
(givenPath?: string | undefined, options?: DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void>;
|
|
5
5
|
auto: (options?: DecoratorOptions) => (givenTarget: KnownAny, propertyKey: string) => void;
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports._createVovkApp = _createVovkApp;
|
|
7
|
+
const VovkApp_1 = require("./VovkApp");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
const getSchema_1 = __importDefault(require("./utils/getSchema"));
|
|
10
10
|
const trimPath = (path) => path.trim().replace(/^\/|\/$/g, '');
|
|
@@ -13,9 +13,9 @@ const toKebabCase = (str) => str
|
|
|
13
13
|
.replace(/([A-Z])/g, '-$1')
|
|
14
14
|
.toLowerCase()
|
|
15
15
|
.replace(/^-/, '');
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
const
|
|
16
|
+
function _createVovkApp() {
|
|
17
|
+
const vovkApp = new VovkApp_1._VovkApp();
|
|
18
|
+
const createHTTPDecorator = (httpMethod) => {
|
|
19
19
|
const assignSchema = (controller, propertyKey, path, options) => {
|
|
20
20
|
if (typeof window !== 'undefined') {
|
|
21
21
|
throw new Error('Decorators are intended for server-side use only. You have probably imported a controller on the client-side.');
|
|
@@ -26,8 +26,8 @@ function _createSegment() {
|
|
|
26
26
|
decoratorName = 'del';
|
|
27
27
|
throw new Error(`Decorator must be used on a static class method. Check the controller method named "${propertyKey}" used with @${decoratorName}.`);
|
|
28
28
|
}
|
|
29
|
-
const methods =
|
|
30
|
-
|
|
29
|
+
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
30
|
+
vovkApp.routes[httpMethod].set(controller, methods);
|
|
31
31
|
controller._handlers = {
|
|
32
32
|
...controller._handlers,
|
|
33
33
|
[propertyKey]: {
|
|
@@ -53,8 +53,8 @@ function _createSegment() {
|
|
|
53
53
|
const auto = (options) => {
|
|
54
54
|
function decorator(givenTarget, propertyKey) {
|
|
55
55
|
const controller = givenTarget;
|
|
56
|
-
const methods =
|
|
57
|
-
|
|
56
|
+
const methods = vovkApp.routes[httpMethod].get(controller) ?? {};
|
|
57
|
+
vovkApp.routes[httpMethod].set(controller, methods);
|
|
58
58
|
controller._handlers = {
|
|
59
59
|
...controller._handlers,
|
|
60
60
|
[propertyKey]: {
|
|
@@ -90,28 +90,28 @@ function _createSegment() {
|
|
|
90
90
|
// Wait for schema to be set (it can be set after decorators are called with another setTimeout)
|
|
91
91
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
92
92
|
const schema = (0, getSchema_1.default)(options);
|
|
93
|
-
return
|
|
93
|
+
return vovkApp.respond(200, { schema });
|
|
94
94
|
}
|
|
95
|
-
return
|
|
95
|
+
return vovkApp.GET(req, data);
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
|
-
GET: process.env.NODE_ENV === 'development' ? GET_DEV :
|
|
99
|
-
POST:
|
|
100
|
-
PUT:
|
|
101
|
-
PATCH:
|
|
102
|
-
DELETE:
|
|
103
|
-
HEAD:
|
|
104
|
-
OPTIONS:
|
|
98
|
+
GET: process.env.NODE_ENV === 'development' ? GET_DEV : vovkApp.GET,
|
|
99
|
+
POST: vovkApp.POST,
|
|
100
|
+
PUT: vovkApp.PUT,
|
|
101
|
+
PATCH: vovkApp.PATCH,
|
|
102
|
+
DELETE: vovkApp.DELETE,
|
|
103
|
+
HEAD: vovkApp.HEAD,
|
|
104
|
+
OPTIONS: vovkApp.OPTIONS,
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
107
|
return {
|
|
108
|
-
get:
|
|
109
|
-
post:
|
|
110
|
-
put:
|
|
111
|
-
patch:
|
|
112
|
-
del:
|
|
113
|
-
head:
|
|
114
|
-
options:
|
|
108
|
+
get: createHTTPDecorator(types_1._HttpMethod.GET),
|
|
109
|
+
post: createHTTPDecorator(types_1._HttpMethod.POST),
|
|
110
|
+
put: createHTTPDecorator(types_1._HttpMethod.PUT),
|
|
111
|
+
patch: createHTTPDecorator(types_1._HttpMethod.PATCH),
|
|
112
|
+
del: createHTTPDecorator(types_1._HttpMethod.DELETE),
|
|
113
|
+
head: createHTTPDecorator(types_1._HttpMethod.HEAD),
|
|
114
|
+
options: createHTTPDecorator(types_1._HttpMethod.OPTIONS),
|
|
115
115
|
prefix,
|
|
116
116
|
initVovk,
|
|
117
117
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _createVovkApp as createVovkApp } from './createVovkApp';
|
|
2
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 _VovkControllerBody as VovkControllerBody, type _VovkControllerQuery as VovkControllerQuery, type _VovkControllerParams as VovkControllerParams, type _VovkControllerYieldType as VovkControllerYieldType, type _VovkSchema as VovkSchema, _HttpStatus as HttpStatus, _HttpMethod as HttpMethod } from './types';
|
|
3
3
|
import type { _VovkClientOptions as VovkClientOptions, _VovkClientFetcher as VovkClientFetcher, _VovkDefaultFetcherOptions as VovkDefaultFetcherOptions, _VovkValidateOnClient as VovkValidateOnClient } from './client/types';
|
|
4
4
|
import { _HttpException as HttpException } from './HttpException';
|
|
5
5
|
import { _createDecorator as createDecorator } from './createDecorator';
|
|
6
6
|
import { _StreamJSONResponse as StreamJSONResponse } from './StreamJSONResponse';
|
|
7
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 VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, StreamJSONResponse, HttpException, HttpStatus, HttpMethod,
|
|
8
|
+
import { _generateStaticAPI as generateStaticAPI } from './utils/generateStaticAPI';
|
|
9
|
+
export { type VovkClientFetcher, type VovkDefaultFetcherOptions, type VovkValidateOnClient, type VovkSchema, type VovkErrorResponse, type VovkRequest, type VovkControllerBody, type VovkControllerQuery, type VovkControllerParams, type VovkControllerYieldType, type VovkBody, type VovkQuery, type VovkParams, type VovkYieldType, type VovkReturnType, type VovkClientOptions, StreamJSONResponse, HttpException, HttpStatus, HttpMethod, createVovkApp, createDecorator, worker, generateStaticAPI, };
|
|
10
10
|
export declare const get: {
|
|
11
11
|
(givenPath?: string | undefined, options?: import("./types")._DecoratorOptions | undefined): ReturnType<(givenPath?: string, options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void>;
|
|
12
12
|
auto: (options?: import("./types")._DecoratorOptions) => (givenTarget: import("./types")._KnownAny, propertyKey: string) => void;
|
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
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.
|
|
5
|
-
const
|
|
6
|
-
Object.defineProperty(exports, "
|
|
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.createVovkApp = exports.HttpMethod = exports.HttpStatus = exports.HttpException = exports.StreamJSONResponse = void 0;
|
|
5
|
+
const createVovkApp_1 = require("./createVovkApp");
|
|
6
|
+
Object.defineProperty(exports, "createVovkApp", { enumerable: true, get: function () { return createVovkApp_1._createVovkApp; } });
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function () { return types_1._HttpStatus; } });
|
|
9
9
|
Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return types_1._HttpMethod; } });
|
|
@@ -15,6 +15,6 @@ const StreamJSONResponse_1 = require("./StreamJSONResponse");
|
|
|
15
15
|
Object.defineProperty(exports, "StreamJSONResponse", { enumerable: true, get: function () { return StreamJSONResponse_1._StreamJSONResponse; } });
|
|
16
16
|
const worker_1 = require("./worker");
|
|
17
17
|
Object.defineProperty(exports, "worker", { enumerable: true, get: function () { return worker_1.worker; } });
|
|
18
|
-
const generateStaticAPI_1 = require("./generateStaticAPI");
|
|
18
|
+
const generateStaticAPI_1 = require("./utils/generateStaticAPI");
|
|
19
19
|
Object.defineProperty(exports, "generateStaticAPI", { enumerable: true, get: function () { return generateStaticAPI_1._generateStaticAPI; } });
|
|
20
|
-
_a = (0,
|
|
20
|
+
_a = (0, createVovkApp_1._createVovkApp)(), 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;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ exports._generateStaticAPI = _generateStaticAPI;
|
|
|
4
4
|
function _generateStaticAPI(c, slug = 'vovk') {
|
|
5
5
|
const controllers = c;
|
|
6
6
|
return [
|
|
7
|
-
{ [slug]: ['
|
|
7
|
+
{ [slug]: ['_schema_'] },
|
|
8
8
|
...Object.values(controllers)
|
|
9
9
|
.map((controller) => {
|
|
10
10
|
const handlers = controller._handlers;
|