fastify-flux 2.19.0
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/LICENSE +19 -0
- package/dist/__tests__/foo.d.ts +1 -0
- package/dist/__tests__/foo.d.ts.map +1 -0
- package/dist/__tests__/foo.js +5 -0
- package/dist/__tests__/foo.js.map +1 -0
- package/dist/chili/controllers.d.ts +4 -0
- package/dist/chili/controllers.js +48 -0
- package/dist/chili/controllers.js.map +1 -0
- package/dist/chili/index.d.ts +9 -0
- package/dist/chili/index.js +42 -0
- package/dist/chili/index.js.map +1 -0
- package/dist/chili/meta.d.ts +2 -0
- package/dist/chili/meta.js +20 -0
- package/dist/chili/meta.js.map +1 -0
- package/dist/decorator.d.ts +11 -0
- package/dist/decorator.d.ts.map +1 -0
- package/dist/decorator.js +68 -0
- package/dist/decorator.js.map +1 -0
- package/dist/fastify.d.ts +3 -0
- package/dist/fastify.d.ts.map +1 -0
- package/dist/fastify.js +35 -0
- package/dist/fastify.js.map +1 -0
- package/dist/flux/controllers.d.ts +5 -0
- package/dist/flux/controllers.d.ts.map +1 -0
- package/dist/flux/controllers.js +48 -0
- package/dist/flux/controllers.js.map +1 -0
- package/dist/flux/index.d.ts +9 -0
- package/dist/flux/index.d.ts.map +1 -0
- package/dist/flux/index.js +30 -0
- package/dist/flux/index.js.map +1 -0
- package/dist/helper/call-parameter.d.ts +11 -0
- package/dist/helper/call-parameter.d.ts.map +1 -0
- package/dist/helper/call-parameter.js +60 -0
- package/dist/helper/call-parameter.js.map +1 -0
- package/dist/helper/schema.d.ts +48 -0
- package/dist/helper/schema.d.ts.map +1 -0
- package/dist/helper/schema.js +106 -0
- package/dist/helper/schema.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/meta.d.ts +3 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +20 -0
- package/dist/meta.js.map +1 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +52 -0
- package/dist/openapi.js.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2021 Jakob Niggel
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=foo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foo.d.ts","sourceRoot":"","sources":["../../src/__tests__/foo.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foo.js","sourceRoot":"","sources":["../../src/__tests__/foo.ts"],"names":[],"mappings":";AAAA,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACjC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerController = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const call_parameter_1 = require("../helper/call-parameter");
|
|
6
|
+
const schema_1 = require("../helper/schema");
|
|
7
|
+
const controllerMeta = (0, __1.getFluxControllerMeta)();
|
|
8
|
+
const schema = (0, __1.getFluxJsonSchema)();
|
|
9
|
+
function handleRoute(config, route, f) {
|
|
10
|
+
const { url, method, tags, statusCode } = route;
|
|
11
|
+
config.fastify.route({
|
|
12
|
+
method,
|
|
13
|
+
handler: async (request, reply) => {
|
|
14
|
+
if (config.preHandler) {
|
|
15
|
+
await config.preHandler({ request, reply });
|
|
16
|
+
}
|
|
17
|
+
const result = await f(...(0, call_parameter_1.getCallParameters)({ request: request, reply: reply, route }));
|
|
18
|
+
reply.code(statusCode).send(result);
|
|
19
|
+
},
|
|
20
|
+
url: '/api' + url,
|
|
21
|
+
schema: {
|
|
22
|
+
operationId: f.name,
|
|
23
|
+
tags,
|
|
24
|
+
params: (0, schema_1.getSchemaParams)(route),
|
|
25
|
+
querystring: (0, schema_1.getSchemaQuerystring)(route, schema),
|
|
26
|
+
body: (0, schema_1.getSchemaBody)(route, schema),
|
|
27
|
+
response: (0, schema_1.getSchemaResponse)(route, schema),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function registerController(controller, options) {
|
|
32
|
+
if (!controller.name.endsWith('Controller')) {
|
|
33
|
+
throw new Error(`${controller.name} is invalid. Name must end with Controller.`);
|
|
34
|
+
}
|
|
35
|
+
const instance = new controller();
|
|
36
|
+
const chili = controller.prototype
|
|
37
|
+
.chili;
|
|
38
|
+
Object.keys(chili).forEach((functioName) => {
|
|
39
|
+
const found = controllerMeta.find((x) => x.className === controller.name && x.method === functioName);
|
|
40
|
+
if (!found) {
|
|
41
|
+
throw new Error(`No definition found for controller ${controller.name} and function ${functioName}`);
|
|
42
|
+
}
|
|
43
|
+
const meta = { ...chili[functioName], params: found.params };
|
|
44
|
+
handleRoute(options, meta, instance[functioName]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.registerController = registerController;
|
|
48
|
+
//# sourceMappingURL=controllers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controllers.js","sourceRoot":"","sources":["../../src/chili/controllers.ts"],"names":[],"mappings":";;;AACA,0BAKY;AACZ,6DAA6D;AAC7D,6CAK0B;AAE1B,MAAM,cAAc,GAAG,IAAA,yBAAqB,GAAE,CAAC;AAC/C,MAAM,MAAM,GAAG,IAAA,qBAAiB,GAAE,CAAC;AAEnC,SAAS,WAAW,CAAC,MAAkB,EAAE,KAAgB,EAAE,CAAW;IACpE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QACnB,MAAM;QACN,OAAO,EAAE,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAE,EAAE;YAC9D,IAAI,MAAM,CAAC,UAAU,EAAE;gBACrB,MAAM,MAAM,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;aAC7C;YAED,MAAM,MAAM,GAAG,MAAM,CAAC,CACpB,GAAG,IAAA,kCAAiB,EAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,C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AAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC7D,WAAW,CAAC,OAAO,EAAE,IAAI,EAAG,QAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC;AA1BD,gDA0BC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { FluxController, FluxPlugin, FluxPrehandler } from '../types';
|
|
4
|
+
export declare function flux({ fastifyInstance, controllers, plugins, preHandler, }: {
|
|
5
|
+
fastifyInstance?: FastifyInstance;
|
|
6
|
+
controllers?: FluxController[];
|
|
7
|
+
plugins?: FluxPlugin[];
|
|
8
|
+
preHandler?: FluxPrehandler;
|
|
9
|
+
}): FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.flux = void 0;
|
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
+
const controllers_1 = require("./controllers");
|
|
9
|
+
class Flux {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.controllersRegistered = false;
|
|
13
|
+
}
|
|
14
|
+
plugins(...plugins) {
|
|
15
|
+
if (this.controllersRegistered) {
|
|
16
|
+
throw new Error('Plugins must be registered before Controllers.');
|
|
17
|
+
}
|
|
18
|
+
plugins.forEach((plugin) => plugin(this.config.fastify));
|
|
19
|
+
}
|
|
20
|
+
controllers(...controllers) {
|
|
21
|
+
controllers.forEach((controller) => (0, controllers_1.registerController)(controller, this.config));
|
|
22
|
+
this.controllersRegistered = true;
|
|
23
|
+
}
|
|
24
|
+
getFastify() {
|
|
25
|
+
return this.config.fastify;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function flux({ fastifyInstance, controllers, plugins, preHandler, }) {
|
|
29
|
+
const instance = new Flux({
|
|
30
|
+
fastify: fastifyInstance ? fastifyInstance : (0, fastify_1.default)(),
|
|
31
|
+
preHandler,
|
|
32
|
+
});
|
|
33
|
+
if (plugins) {
|
|
34
|
+
instance.plugins(...plugins);
|
|
35
|
+
}
|
|
36
|
+
if (controllers) {
|
|
37
|
+
instance.controllers(...controllers);
|
|
38
|
+
}
|
|
39
|
+
return instance.getFastify();
|
|
40
|
+
}
|
|
41
|
+
exports.flux = flux;
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chili/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAmD;AAOnD,+CAAmD;AAEnD,MAAM,IAAI;IAGR,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAFtC,0BAAqB,GAAG,KAAK,CAAC;IAEW,CAAC;IAE1C,OAAO,CAAC,GAAG,OAAqB;QAC9B,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;SACnE;QACD,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,WAAW,CAAC,GAAG,WAA6B;QAC1C,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CACjC,IAAA,gCAAkB,EAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAC5C,CAAC;QACF,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;IACpC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;CACF;AAED,SAAgB,IAAI,CAAC,EACnB,eAAe,EACf,WAAW,EACX,OAAO,EACP,UAAU,GAMX;IACC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC;QACxB,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,IAAA,iBAAO,GAAE;QACtD,UAAU;KACX,CAAC,CAAC;IAEH,IAAI,OAAO,EAAE;QACX,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;KAC9B;IAED,IAAI,WAAW,EAAE;QACf,QAAQ,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC,CAAC;KACtC;IAED,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC;AAC/B,CAAC;AAzBD,oBAyBC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getControllerMeta = exports.getSchema = void 0;
|
|
4
|
+
const schema = require(process.cwd() + '/dist/chili-schema.json');
|
|
5
|
+
const controllerMeta = require(process.cwd() + '/dist/chili-controller.json');
|
|
6
|
+
function getSchema() {
|
|
7
|
+
if (!schema) {
|
|
8
|
+
throw new Error('The file chili-schema.json is missing. Please run chili start to generate it.');
|
|
9
|
+
}
|
|
10
|
+
return schema;
|
|
11
|
+
}
|
|
12
|
+
exports.getSchema = getSchema;
|
|
13
|
+
function getControllerMeta() {
|
|
14
|
+
if (!controllerMeta) {
|
|
15
|
+
throw new Error('The file chili-controller.json is missing. Please run chili start to generate it.');
|
|
16
|
+
}
|
|
17
|
+
return controllerMeta;
|
|
18
|
+
}
|
|
19
|
+
exports.getControllerMeta = getControllerMeta;
|
|
20
|
+
//# sourceMappingURL=meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/chili/meta.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,yBAAyB,CAAC,CAAC;AAClE,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,6BAA6B,CAAC,CAAC;AAE9E,SAAgB,SAAS;IACvB,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,8BAQC;AAED,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;KACH;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AARD,8CAQC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function Controller(url: string, params: {
|
|
2
|
+
tags: string[];
|
|
3
|
+
}): ClassDecorator;
|
|
4
|
+
export declare function Delete(url?: string): MethodDecorator;
|
|
5
|
+
export declare function Get(url?: string): MethodDecorator;
|
|
6
|
+
export declare function Post(url?: string): MethodDecorator;
|
|
7
|
+
export declare function Status(code: number): MethodDecorator;
|
|
8
|
+
export declare function Auth(value: unknown): MethodDecorator;
|
|
9
|
+
export declare function Custom(key: string, value: unknown): MethodDecorator;
|
|
10
|
+
export declare function Description(key: string, value: unknown): MethodDecorator;
|
|
11
|
+
//# sourceMappingURL=decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../src/decorator.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GACzB,cAAc,CAQhB;AAmBD,wBAAgB,MAAM,CAAC,GAAG,GAAE,MAAW,GAAG,eAAe,CAKxD;AAED,wBAAgB,GAAG,CAAC,GAAG,GAAE,MAAW,GAAG,eAAe,CAKrD;AAED,wBAAgB,IAAI,CAAC,GAAG,GAAE,MAAW,GAAG,eAAe,CAKtD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAIpD;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAIpD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,eAAe,CAInE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,eAAe,CAIxE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Description = exports.Custom = exports.Auth = exports.Status = exports.Post = exports.Get = exports.Delete = exports.Controller = void 0;
|
|
4
|
+
function Controller(url, params) {
|
|
5
|
+
return function (constructor) {
|
|
6
|
+
const routes = constructor.prototype.routes;
|
|
7
|
+
Object.keys(routes).forEach((functionName) => {
|
|
8
|
+
routes[functionName].url = url + routes[functionName].url;
|
|
9
|
+
routes[functionName].tags = params.tags;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.Controller = Controller;
|
|
14
|
+
function addProperty(target, functionName, key, value) {
|
|
15
|
+
if (!target.routes) {
|
|
16
|
+
target.routes = {};
|
|
17
|
+
}
|
|
18
|
+
if (!target.routes[functionName]) {
|
|
19
|
+
target.routes[functionName] = { statusCode: 200 };
|
|
20
|
+
}
|
|
21
|
+
target.routes[functionName][key] = value;
|
|
22
|
+
}
|
|
23
|
+
function Delete(url = '') {
|
|
24
|
+
return function (target, functionName) {
|
|
25
|
+
addProperty(target, functionName, 'url', url);
|
|
26
|
+
addProperty(target, functionName, 'method', 'DELETE');
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.Delete = Delete;
|
|
30
|
+
function Get(url = '') {
|
|
31
|
+
return function async(target, functionName) {
|
|
32
|
+
addProperty(target, functionName, 'url', url);
|
|
33
|
+
addProperty(target, functionName, 'method', 'GET');
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.Get = Get;
|
|
37
|
+
function Post(url = '') {
|
|
38
|
+
return function (target, functionName) {
|
|
39
|
+
addProperty(target, functionName, 'url', url);
|
|
40
|
+
addProperty(target, functionName, 'method', 'POST');
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.Post = Post;
|
|
44
|
+
function Status(code) {
|
|
45
|
+
return function (target, functionName) {
|
|
46
|
+
addProperty(target, functionName, 'statusCode', code);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.Status = Status;
|
|
50
|
+
function Auth(value) {
|
|
51
|
+
return function (target, functionName) {
|
|
52
|
+
addProperty(target, functionName, 'auth', value);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.Auth = Auth;
|
|
56
|
+
function Custom(key, value) {
|
|
57
|
+
return function (target, functionName) {
|
|
58
|
+
addProperty(target, functionName, key, value);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.Custom = Custom;
|
|
62
|
+
function Description(key, value) {
|
|
63
|
+
return function (target, functionName) {
|
|
64
|
+
addProperty(target, functionName, key, value);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
exports.Description = Description;
|
|
68
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../src/decorator.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CACxB,GAAW,EACX,MAA0B;IAE1B,OAAO,UAAU,WAAqB;QACpC,MAAM,MAAM,GAAI,WAAW,CAAC,SAAiB,CAAC,MAAM,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;YAC3C,MAAM,CAAC,YAAY,CAAC,CA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,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9C,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AALD,oBAKC;AAED,SAAgB,MAAM,CAAC,IAAY;IACjC,OAAO,UAAU,MAAc,EAAE,YAA6B;QAC5D,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC;AAJD,wBAIC;AAED,SAAgB,IAAI,CAAC,KAAc;IACjC,OAAO,UAAU,MAAc,EAAE,YAA6B;QAC5D,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC;AAJD,oBAIC;AAED,SAAgB,MAAM,CAAC,GAAW,EAAE,KAAc;IAChD,OAAO,UAAU,MAAc,EAAE,YAA6B;QAC5D,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC;AAJD,wBAIC;AAED,SAAgB,WAAW,CAAC,GAAW,EAAE,KAAc;IACrD,OAAO,UAAU,MAAc,EAAE,YAA6B;QAC5D,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC;AAJD,kCAIC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function createFastifyInstance(): import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
|
|
3
|
+
//# sourceMappingURL=fastify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":";AAqBA,wBAAgB,qBAAqB,yaASpC"}
|
package/dist/fastify.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createFastifyInstance = void 0;
|
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
+
function getLoggerConfig() {
|
|
9
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
10
|
+
return {
|
|
11
|
+
transport: {
|
|
12
|
+
target: 'pino-pretty',
|
|
13
|
+
options: {
|
|
14
|
+
colorize: true,
|
|
15
|
+
ignore: 'req.hostname,req.remotePort,req.remoteAddress,time,hostname,pid',
|
|
16
|
+
singleLine: true,
|
|
17
|
+
sync: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
function createFastifyInstance() {
|
|
25
|
+
return (0, fastify_1.default)({
|
|
26
|
+
logger: getLoggerConfig(),
|
|
27
|
+
ajv: {
|
|
28
|
+
customOptions: {
|
|
29
|
+
removeAdditional: false, //throw error instead
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.createFastifyInstance = createFastifyInstance;
|
|
35
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAE9B,SAAS,eAAe;IACtB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,OAAO;YACL,SAAS,EAAE;gBACT,MAAM,EAAE,aAAa;gBACrB,OAAO,EAAE;oBACP,QAAQ,EAAE,IAAI;oBACd,MAAM,EACJ,iEAAiE;oBACnE,UAAU,EAAE,IAAI;oBAChB,IAAI,EAAE,IAAI;iBACX;aACF;SACF,CAAC;KACH;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAgB,qBAAqB;IACnC,OAAO,IAAA,iBAAO,EAAC;QACb,MAAM,EAAE,eAAe,EAAE;QACzB,GAAG,EAAE;YACH,aAAa,EAAE;gBACb,gBAAgB,EAAE,KAAK,EAAE,qBAAqB;aAC/C;SACF;KACF,CAAC,CAAC;AACL,CAAC;AATD,sDASC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controllers.d.ts","sourceRoot":"","sources":["../../src/flux/controllers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAyB,MAAM,IAAI,CAAC;AAwCvD,wBAAgB,kBAAkB,CAChC,UAAU,EAAE;IAAE,QAAQ,GAAG,CAAA;CAAE,EAC3B,OAAO,EAAE,UAAU,QAyBpB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerController = void 0;
|
|
4
|
+
const call_parameter_1 = require("../helper/call-parameter");
|
|
5
|
+
const schema_1 = require("../helper/schema");
|
|
6
|
+
const meta_1 = require("../meta");
|
|
7
|
+
const controllerMeta = (0, meta_1.getFluxControllerMeta)();
|
|
8
|
+
const schema = (0, meta_1.getFluxJsonSchema)();
|
|
9
|
+
function handleRoute(config, route, f) {
|
|
10
|
+
const { url, method, tags, statusCode } = route;
|
|
11
|
+
const routeMappers = (0, call_parameter_1.getRouteMappers)(config, route);
|
|
12
|
+
config.fastify.route({
|
|
13
|
+
method,
|
|
14
|
+
handler: async (request, reply) => {
|
|
15
|
+
const result = await f(...routeMappers.map((x) => x({ request, reply })));
|
|
16
|
+
if (!reply.sent) {
|
|
17
|
+
reply.code(statusCode).send(result);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
url,
|
|
21
|
+
schema: {
|
|
22
|
+
operationId: f.name,
|
|
23
|
+
tags,
|
|
24
|
+
params: (0, schema_1.getSchemaParams)(route),
|
|
25
|
+
querystring: (0, schema_1.getSchemaQuerystring)(config, route, schema),
|
|
26
|
+
body: (0, schema_1.getSchemaBody)(config, route, schema),
|
|
27
|
+
response: (0, schema_1.getSchemaResponse)(config, route, schema),
|
|
28
|
+
},
|
|
29
|
+
config: route,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function registerController(controller, options) {
|
|
33
|
+
if (!controller.name.endsWith('Controller')) {
|
|
34
|
+
throw new Error(`${controller.name} is invalid. Name must end with Controller.`);
|
|
35
|
+
}
|
|
36
|
+
const routes = controller.prototype.routes;
|
|
37
|
+
const instance = new controller();
|
|
38
|
+
Object.keys(routes).forEach((functionName) => {
|
|
39
|
+
const found = controllerMeta.find((x) => x.className === controller.name && x.functionName === functionName);
|
|
40
|
+
if (!found) {
|
|
41
|
+
throw new Error(`No definition found for controller ${controller.name} and function ${functionName}`);
|
|
42
|
+
}
|
|
43
|
+
const meta = { ...routes[functionName], ...found };
|
|
44
|
+
handleRoute(options, meta, instance[functionName]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.registerController = registerController;
|
|
48
|
+
//# sourceMappingURL=controllers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controllers.js","sourceRoot":"","sources":["../../src/flux/controllers.ts"],"names":[],"mappings":";;;AAEA,6DAA2D;AAC3D,6CAK0B;AAC1B,kCAAmE;AAEnE,MAAM,cAAc,GAAG,IAAA,4BAAqB,GAAE,CAAC;AAC/C,MAAM,MAAM,GAAG,IAAA,wBAAiB,GAAE,CAAC;AAEnC,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,CAAC;KACH;IAED,MAAM,MAAM,GAAgB,UAAU,CAAC,SAAiB,CAAC,MAAM,CAAC;IAEhE,MAAM,QAAQ,GAAG,IAAI,UAAU,EAAE,CAAC;IAElC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,YAAoB,EAAE,EAAE;QACnD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAC/B,CAAC,CAAM,EAAE,EAAE,CACT,CAAC,CAAC,SAAS,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC,CAAC,YAAY,KAAK,YAAY,CACrE,CAAC;QACF,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CACb,sCAAsC,UAAU,CAAC,IAAI,iBAAiB,YAAY,EAAE,CACrF,CAAC;SACH;QACD,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;QACnD,WAAW,CAAC,OAAO,EAAE,IAAI,EAAG,QAAgB,CAAC,YAAY,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC;AA3BD,gDA2BC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { FluxController, FluxConfig } from '../types';
|
|
4
|
+
export declare function flux({ fastify, controllers, mapping, }: {
|
|
5
|
+
fastify?: FastifyInstance;
|
|
6
|
+
controllers?: FluxController[];
|
|
7
|
+
mapping?: FluxConfig['mapping'];
|
|
8
|
+
}): Promise<FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance, import("fastify").FastifyTypeProviderDefault>>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/flux/index.ts"],"names":[],"mappings":";AAAA,OAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAoBtD,wBAAsB,IAAI,CAAC,EACzB,OAAO,EACP,WAAW,EACX,OAAO,GACR,EAAE;IACD,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;CACjC,yMAWA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flux = void 0;
|
|
4
|
+
const fastify_1 = require("../fastify");
|
|
5
|
+
const controllers_1 = require("./controllers");
|
|
6
|
+
class Flux {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.controllersRegistered = false;
|
|
10
|
+
}
|
|
11
|
+
controllers(...controllers) {
|
|
12
|
+
controllers.forEach((controller) => (0, controllers_1.registerController)(controller, this.config));
|
|
13
|
+
this.controllersRegistered = true;
|
|
14
|
+
}
|
|
15
|
+
getFastify() {
|
|
16
|
+
return this.config.fastify;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function flux({ fastify, controllers, mapping, }) {
|
|
20
|
+
const instance = new Flux({
|
|
21
|
+
fastify: fastify ? fastify : (0, fastify_1.createFastifyInstance)(),
|
|
22
|
+
mapping,
|
|
23
|
+
});
|
|
24
|
+
if (controllers) {
|
|
25
|
+
instance.controllers(...controllers);
|
|
26
|
+
}
|
|
27
|
+
return instance.getFastify();
|
|
28
|
+
}
|
|
29
|
+
exports.flux = flux;
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/flux/index.ts"],"names":[],"mappings":";;;AACA,wCAAmD;AAEnD,+CAAmD;AAEnD,MAAM,IAAI;IAGR,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAFtC,0BAAqB,GAAG,KAAK,CAAC;IAEW,CAAC;IAE1C,WAAW,CAAC,GAAG,WAA6B;QAC1C,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CACjC,IAAA,gCAAkB,EAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAC5C,CAAC;QACF,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;IACpC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;CACF;AAEM,KAAK,UAAU,IAAI,CAAC,EACzB,OAAO,EACP,WAAW,EACX,OAAO,GAKR;IACC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC;QACxB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,+BAAqB,GAAE;QACpD,OAAO;KACR,CAAC,CAAC;IAEH,IAAI,WAAW,EAAE;QACf,QAAQ,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC,CAAC;KACtC;IAED,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC;AAC/B,CAAC;AAnBD,oBAmBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FluxConfig, FluxRoute } from '..';
|
|
3
|
+
export declare function getRouteMapper(config: FluxConfig, param: FluxRoute['params'][number]): (data: {
|
|
4
|
+
request: import("fastify").FastifyRequest<import("fastify/types/route").RouteGenericInterface, import("http").Server, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify/types/type-provider").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify/types/route").RouteGenericInterface>, import("fastify").FastifyLoggerInstance>;
|
|
5
|
+
reply: import("fastify").FastifyReply<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify/types/route").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
|
|
6
|
+
}) => unknown;
|
|
7
|
+
export declare function getRouteMappers(config: FluxConfig, route: FluxRoute): ((data: {
|
|
8
|
+
request: import("fastify").FastifyRequest<import("fastify/types/route").RouteGenericInterface, import("http").Server, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify/types/type-provider").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify/types/route").RouteGenericInterface>, import("fastify").FastifyLoggerInstance>;
|
|
9
|
+
reply: import("fastify").FastifyReply<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify/types/route").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
|
|
10
|
+
}) => unknown)[];
|
|
11
|
+
//# sourceMappingURL=call-parameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-parameter.d.ts","sourceRoot":"","sources":["../../src/helper/call-parameter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAe,MAAM,IAAI,CAAC;AA2CxD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;;;cAmBnC;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS;;;iBAEnE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRouteMappers = exports.getRouteMapper = void 0;
|
|
4
|
+
const defaultMapping = [
|
|
5
|
+
{
|
|
6
|
+
name: 'query',
|
|
7
|
+
mapper({ request }) {
|
|
8
|
+
return request.query;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'body',
|
|
13
|
+
mapper({ request }) {
|
|
14
|
+
return request.body;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'FastifyReply',
|
|
19
|
+
mapper({ reply }) {
|
|
20
|
+
return reply;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'FastifyRequest',
|
|
25
|
+
mapper({ request }) {
|
|
26
|
+
return request;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
function getParamMapper(name) {
|
|
31
|
+
return ({ request }) => {
|
|
32
|
+
const { params } = request;
|
|
33
|
+
if (params && params.hasOwnProperty(name)) {
|
|
34
|
+
return params[name];
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`Couldn't find url parameter ${name} for url ${request.url}.`);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getRouteMapper(config, param) {
|
|
40
|
+
const mapping = [...defaultMapping, ...(config.mapping || [])];
|
|
41
|
+
if (param.type) {
|
|
42
|
+
const typeFound = mapping.find((x) => x.type === param.type);
|
|
43
|
+
if (typeFound) {
|
|
44
|
+
return typeFound.mapper;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (param.name) {
|
|
48
|
+
const nameFound = mapping.find((x) => x.name === param.name);
|
|
49
|
+
if (nameFound) {
|
|
50
|
+
return nameFound.mapper;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return getParamMapper(param.name);
|
|
54
|
+
}
|
|
55
|
+
exports.getRouteMapper = getRouteMapper;
|
|
56
|
+
function getRouteMappers(config, route) {
|
|
57
|
+
return route.params.map((x) => getRouteMapper(config, x));
|
|
58
|
+
}
|
|
59
|
+
exports.getRouteMappers = getRouteMappers;
|
|
60
|
+
//# sourceMappingURL=call-parameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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IAAI,SAAS,EAAE;YACb,OAAO,SAAS,CAAC,MAAM,CAAC;SACzB;KACF;IAED,IAAI,KAAK,CAAC,IAAI,EAAE;QACd,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7D,IAAI,SAAS,EAAE;YACb,OAAO,SAAS,CAAC,MAAM,CAAC;SACzB;KACF;IAED,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AArBD,wCAqBC;AAED,SAAgB,eAAe,CAAC,MAAkB,EAAE,KAAgB;IAClE,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FluxConfig, FluxRoute } from '../types';
|
|
2
|
+
interface schemas {
|
|
3
|
+
[k: string]: any;
|
|
4
|
+
}
|
|
5
|
+
export declare function getSchemaParams(route: FluxRoute): {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
[key: string]: {
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
} | undefined;
|
|
13
|
+
export declare function getSchemaQuerystring(config: FluxConfig, route: FluxRoute, s: schemas): {
|
|
14
|
+
$id: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: string;
|
|
17
|
+
items: {
|
|
18
|
+
$id: string;
|
|
19
|
+
};
|
|
20
|
+
} | undefined;
|
|
21
|
+
export declare function getSchemaResponse(config: FluxConfig, route: FluxRoute, s: schemas): {
|
|
22
|
+
[x: number]: {
|
|
23
|
+
type: string;
|
|
24
|
+
};
|
|
25
|
+
} | {
|
|
26
|
+
[x: number]: {
|
|
27
|
+
type: string;
|
|
28
|
+
items: {
|
|
29
|
+
$id: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
} | {
|
|
33
|
+
[x: number]: {
|
|
34
|
+
$id: string;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
[x: number]: {};
|
|
38
|
+
};
|
|
39
|
+
export declare function getSchemaBody(config: FluxConfig, route: FluxRoute, s: schemas): {
|
|
40
|
+
$id: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: string;
|
|
43
|
+
items: {
|
|
44
|
+
$id: string;
|
|
45
|
+
};
|
|
46
|
+
} | undefined;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/helper/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEjD,UAAU,OAAO;IACf,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAeD,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS;;;;kBASD,MAAM;;;cAYpD;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,EAChB,CAAC,EAAE,OAAO;;;;;;;cAoBX;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,EAChB,CAAC,EAAE,OAAO;;;;;;;;;;;;;;;;;EA0CX;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,EAChB,CAAC,EAAE,OAAO;;;;;;;cAoBX"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSchemaBody = exports.getSchemaResponse = exports.getSchemaQuerystring = exports.getSchemaParams = void 0;
|
|
4
|
+
function getSchemaOrThrow(config, name, s) {
|
|
5
|
+
if (!s[name]) {
|
|
6
|
+
throw new Error(`Schema ${name} not found.`);
|
|
7
|
+
}
|
|
8
|
+
const schema = s[name];
|
|
9
|
+
if (!config.fastify.getSchema(schema['$id'])) {
|
|
10
|
+
config.fastify.addSchema(schema);
|
|
11
|
+
}
|
|
12
|
+
return schema;
|
|
13
|
+
}
|
|
14
|
+
function getSchemaParams(route) {
|
|
15
|
+
const matches = route.url.match(/:[a-zA-Z]+/g);
|
|
16
|
+
if (!matches || !matches.length) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const params = {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {},
|
|
22
|
+
};
|
|
23
|
+
matches.forEach((element) => {
|
|
24
|
+
const nameShort = element.replace(':', '');
|
|
25
|
+
const found = route.params.find((x) => x.name === nameShort);
|
|
26
|
+
if (found) {
|
|
27
|
+
params.properties[nameShort] = { type: found.type };
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return params;
|
|
31
|
+
}
|
|
32
|
+
exports.getSchemaParams = getSchemaParams;
|
|
33
|
+
function getSchemaQuerystring(config, route, s) {
|
|
34
|
+
const query = route.params.filter((x) => x.name === 'query');
|
|
35
|
+
if (query.length > 1) {
|
|
36
|
+
throw new Error(`too many potential query params for ${route.url}`);
|
|
37
|
+
}
|
|
38
|
+
if (!query.length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
let name = query[0].type;
|
|
42
|
+
if (name.includes('[]')) {
|
|
43
|
+
name = name.replace('[]', '');
|
|
44
|
+
return { type: 'array', items: getSchemaOrThrow(config, name, s) };
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return getSchemaOrThrow(config, name, s);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.getSchemaQuerystring = getSchemaQuerystring;
|
|
51
|
+
function getSchemaResponse(config, route, s) {
|
|
52
|
+
const name = route.returnType;
|
|
53
|
+
if (name === 'any') {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
if (name === 'string') {
|
|
57
|
+
return {
|
|
58
|
+
[route.statusCode]: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (name === 'number') {
|
|
64
|
+
return {
|
|
65
|
+
[route.statusCode]: {
|
|
66
|
+
type: 'number',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (name && name.includes('[]')) {
|
|
71
|
+
return {
|
|
72
|
+
[route.statusCode]: {
|
|
73
|
+
type: 'array',
|
|
74
|
+
items: getSchemaOrThrow(config, name.replace('[]', ''), s),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (name) {
|
|
79
|
+
return {
|
|
80
|
+
[route.statusCode]: getSchemaOrThrow(config, name, s),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
[route.statusCode]: {},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.getSchemaResponse = getSchemaResponse;
|
|
88
|
+
function getSchemaBody(config, route, s) {
|
|
89
|
+
const body = route.params.filter((x) => x.name === 'body');
|
|
90
|
+
if (body.length > 1) {
|
|
91
|
+
throw new Error(`too many potential body params for ${route.url}`);
|
|
92
|
+
}
|
|
93
|
+
if (!body.length) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let name = body[0].type;
|
|
97
|
+
if (name.includes('[]')) {
|
|
98
|
+
name = name.replace('[]', '');
|
|
99
|
+
return { type: 'array', items: getSchemaOrThrow(config, name, s) };
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return getSchemaOrThrow(config, name, s);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.getSchemaBody = getSchemaBody;
|
|
106
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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QACL,OAAO,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;KAC1C;AACH,CAAC;AAvBD,sCAuBC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FastifyPluginAsync } from 'fastify';
|
|
3
|
+
import { FluxConfig } from './types';
|
|
4
|
+
import { FastifyDynamicSwaggerOptions } from '@fastify/swagger';
|
|
5
|
+
export * from './decorator';
|
|
6
|
+
export * from './flux';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './meta';
|
|
9
|
+
export * from './fastify';
|
|
10
|
+
interface ControllerOptions {
|
|
11
|
+
controllers: {
|
|
12
|
+
new (): any;
|
|
13
|
+
}[];
|
|
14
|
+
mapping?: FluxConfig['mapping'];
|
|
15
|
+
}
|
|
16
|
+
export declare const FluxOpenapi: FastifyPluginAsync<FastifyDynamicSwaggerOptions, import("http").Server, import("fastify").FastifyTypeProviderDefault>;
|
|
17
|
+
export declare const FluxController: FastifyPluginAsync<ControllerOptions, import("http").Server, import("fastify").FastifyTypeProviderDefault>;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAmB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAG9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAEhE,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAQ1B,UAAU,iBAAiB;IACzB,WAAW,EAAE;QAAE,QAAQ,GAAG,CAAA;KAAE,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;CACjC;AAWD,eAAO,MAAM,WAAW,uHAAwB,CAAC;AACjD,eAAO,MAAM,cAAc,4GAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.FluxController = exports.FluxOpenapi = void 0;
|
|
21
|
+
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
22
|
+
const controllers_1 = require("./flux/controllers");
|
|
23
|
+
const openapi_1 = require("./openapi");
|
|
24
|
+
__exportStar(require("./decorator"), exports);
|
|
25
|
+
__exportStar(require("./flux"), exports);
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./meta"), exports);
|
|
28
|
+
__exportStar(require("./fastify"), exports);
|
|
29
|
+
const FluxOpenapiHelper = async (fastify, options) => {
|
|
30
|
+
(0, openapi_1.openapi)(fastify, options);
|
|
31
|
+
};
|
|
32
|
+
const FluxControllerHelper = async (fastify, options) => {
|
|
33
|
+
options.controllers.forEach((controller) => {
|
|
34
|
+
(0, controllers_1.registerController)(controller, { fastify, mapping: options.mapping });
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
exports.FluxOpenapi = (0, fastify_plugin_1.default)(FluxOpenapiHelper);
|
|
38
|
+
exports.FluxController = (0, fastify_plugin_1.default)(FluxControllerHelper);
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,oEAAgC;AAGhC,oDAAwD;AACxD,uCAAoC;AAIpC,8CAA4B;AAC5B,yCAAuB;AACvB,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAE1B,MAAM,iBAAiB,GAEnB,KAAK,EAAE,OAAwB,EAAE,OAAO,EAAE,EAAE;IAC9C,IAAA,iBAAO,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC,CAAC;AAOF,MAAM,oBAAoB,GAA0C,KAAK,EACvE,OAAwB,EACxB,OAAO,EACP,EAAE;IACF,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACzC,IAAA,gCAAkB,EAAC,UAAU,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,IAAA,wBAAE,EAAC,iBAAiB,CAAC,CAAC;AACpC,QAAA,cAAc,GAAG,IAAA,wBAAE,EAAC,oBAAoB,CAAC,CAAC"}
|
package/dist/meta.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAGA,wBAAgB,iBAAiB,QAQhC;AAED,wBAAgB,qBAAqB,QAQpC"}
|
package/dist/meta.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFluxControllerMeta = exports.getFluxJsonSchema = void 0;
|
|
4
|
+
const schema = require(process.cwd() + '/dist/flux-schema.json');
|
|
5
|
+
const controllerMeta = require(process.cwd() + '/dist/flux-controller.json');
|
|
6
|
+
function getFluxJsonSchema() {
|
|
7
|
+
if (!schema) {
|
|
8
|
+
throw new Error('The file flux-schema.json is missing. Please run flux start to generate it.');
|
|
9
|
+
}
|
|
10
|
+
return schema;
|
|
11
|
+
}
|
|
12
|
+
exports.getFluxJsonSchema = getFluxJsonSchema;
|
|
13
|
+
function getFluxControllerMeta() {
|
|
14
|
+
if (!controllerMeta) {
|
|
15
|
+
throw new Error('The file flux-controller.json is missing. Please run flux start to generate it.');
|
|
16
|
+
}
|
|
17
|
+
return controllerMeta;
|
|
18
|
+
}
|
|
19
|
+
exports.getFluxControllerMeta = getFluxControllerMeta;
|
|
20
|
+
//# sourceMappingURL=meta.js.map
|
package/dist/meta.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.js","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,wBAAwB,CAAC,CAAC;AACjE,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,4BAA4B,CAAC,CAAC;AAE7E,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,8CAQC;AAED,SAAgB,qBAAqB;IACnC,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;KACH;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AARD,sDAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAgB,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAGzE,wBAAgB,OAAO,CACrB,OAAO,EAAE,eAAe,EACxB,iBAAiB,CAAC,EAAE,4BAA4B,QA8CjD"}
|
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.openapi = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const swagger_1 = __importDefault(require("@fastify/swagger"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
function openapi(fastify, additionalOptions) {
|
|
11
|
+
const options = {
|
|
12
|
+
routePrefix: '/',
|
|
13
|
+
refResolver: {
|
|
14
|
+
buildLocalReference(json) {
|
|
15
|
+
return json.$id;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
openapi: {
|
|
19
|
+
info: {
|
|
20
|
+
title: 'Api',
|
|
21
|
+
description: '',
|
|
22
|
+
version: '',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
uiConfig: {
|
|
26
|
+
docExpansion: 'list',
|
|
27
|
+
deepLinking: false,
|
|
28
|
+
},
|
|
29
|
+
exposeRoute: true,
|
|
30
|
+
};
|
|
31
|
+
fastify.register(swagger_1.default, lodash_1.default.merge(options, additionalOptions));
|
|
32
|
+
fastify.ready(async () => {
|
|
33
|
+
const { FLUX_PROJECT_INDEX } = process.env;
|
|
34
|
+
if (!FLUX_PROJECT_INDEX) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const oas = fastify.swagger();
|
|
38
|
+
const file = `${process.cwd()}/dist/openapi-${FLUX_PROJECT_INDEX}.json`;
|
|
39
|
+
const schema = JSON.stringify(oas, null, 2);
|
|
40
|
+
let old = '';
|
|
41
|
+
try {
|
|
42
|
+
old = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
43
|
+
// eslint-disable-next-line no-empty
|
|
44
|
+
}
|
|
45
|
+
catch (err) { }
|
|
46
|
+
if (old !== schema) {
|
|
47
|
+
(0, fs_1.writeFileSync)(file, schema);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.openapi = openapi;
|
|
52
|
+
//# sourceMappingURL=openapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":";;;;;;AACA,oDAAuB;AACvB,+DAAyE;AACzE,2BAAiD;AAEjD,SAAgB,OAAO,CACrB,OAAwB,EACxB,iBAAgD;IAEhD,MAAM,OAAO,GAAiC;QAC5C,WAAW,EAAE,GAAG;QAChB,WAAW,EAAE;YACX,mBAAmB,CAAC,IAAS;gBAC3B,OAAO,IAAI,CAAC,GAAG,CAAC;YAClB,CAAC;SACF;QACD,OAAO,EAAE;YACP,IAAI,EAAE;gBACJ,KAAK,EAAE,KAAK;gBACZ,WAAW,EAAE,EAAE;gBACf,OAAO,EAAE,EAAE;aACZ;SACF;QACD,QAAQ,EAAE;YACR,YAAY,EAAE,MAAM;YACpB,WAAW,EAAE,KAAK;SACnB;QACD,WAAW,EAAE,IAAI;KAClB,CAAC;IAEF,OAAO,CAAC,QAAQ,CAAC,iBAAO,EAAE,gBAAC,CAAC,KAAK,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAE/D,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;QACvB,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;QAC3C,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO;SACR;QAED,MAAM,GAAG,GAAS,OAAe,CAAC,OAAO,EAAE,CAAC;QAE5C,MAAM,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,iBAAiB,kBAAkB,OAAO,CAAC;QACxE,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAE5C,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,IAAI;YACF,GAAG,GAAG,IAAA,iBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAClC,oCAAoC;SACrC;QAAC,OAAO,GAAG,EAAE,GAAE;QAEhB,IAAI,GAAG,KAAK,MAAM,EAAE;YAClB,IAAA,kBAAa,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;SAC7B;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAhDD,0BAgDC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyReply, FastifyRequest, HTTPMethods } from 'fastify';
|
|
2
|
+
export interface FluxContext {
|
|
3
|
+
request: FastifyRequest;
|
|
4
|
+
reply: FastifyReply;
|
|
5
|
+
route: FluxRoute;
|
|
6
|
+
}
|
|
7
|
+
export interface FluxRoutes {
|
|
8
|
+
[functionName: string]: FluxRoute;
|
|
9
|
+
}
|
|
10
|
+
export interface FluxRoute {
|
|
11
|
+
url: string;
|
|
12
|
+
method: HTTPMethods;
|
|
13
|
+
tags: string[];
|
|
14
|
+
statusCode: number;
|
|
15
|
+
returnType: string;
|
|
16
|
+
params: {
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
}[];
|
|
20
|
+
auth?: unknown;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface FluxMapping {
|
|
24
|
+
type?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
mapper: (data: {
|
|
27
|
+
request: FastifyRequest;
|
|
28
|
+
reply: FastifyReply;
|
|
29
|
+
}) => unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface FluxConfig {
|
|
32
|
+
fastify: FastifyInstance;
|
|
33
|
+
mapping?: FluxMapping[];
|
|
34
|
+
}
|
|
35
|
+
export declare type FluxController = new () => any;
|
|
36
|
+
declare module 'fastify' {
|
|
37
|
+
interface FastifyContextConfig extends FluxRoute {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,YAAY,CAAA;KAAE,KAAK,OAAO,CAAC;CAC7E;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,oBAAY,cAAc,GAAG,UAAU,GAAG,CAAC;AAE3C,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,oBAAqB,SAAQ,SAAS;KAAG;CACpD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fastify-flux",
|
|
3
|
+
"version": "2.19.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@fastify/swagger": "7.4.1",
|
|
10
|
+
"@types/jest": "^28.1.6",
|
|
11
|
+
"@types/lodash": "^4.14.182",
|
|
12
|
+
"esbuild-jest": "^0.5.0",
|
|
13
|
+
"fastify": "~4.2.1",
|
|
14
|
+
"jest": "^28.1.3",
|
|
15
|
+
"typescript": "4.7.4"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@fastify/swagger": "7.x",
|
|
19
|
+
"fastify": "4.x"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"lodash": "^4.17.21"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"clean": "rm -rf dist/",
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"dev": "tsc --watch",
|
|
31
|
+
"test": "jest src/",
|
|
32
|
+
"release:minor": "yarn build && yarn publish --access public"
|
|
33
|
+
}
|
|
34
|
+
}
|