@scefira/dfw 1.0.0 → 1.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/lib/DFWCore.d.ts +40 -0
- package/lib/DFWCore.d.ts.map +1 -0
- package/lib/DFWCore.js +123 -0
- package/lib/DFWCore.js.map +1 -0
- package/lib/controller/DFWController.d.ts +1 -1
- package/lib/controller/DFWController.d.ts.map +1 -1
- package/lib/controller/DFWController.js +3 -3
- package/lib/controller/DFWController.js.map +1 -1
- package/lib/index.d.ts +3 -39
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -105
- package/lib/index.js.map +1 -1
- package/lib/lib/APIManager.d.ts +1 -1
- package/lib/lib/APIManager.d.ts.map +1 -1
- package/lib/lib/DFWSessionStore.d.ts +1 -1
- package/lib/lib/DFWSessionStore.d.ts.map +1 -1
- package/lib/types/DFWRequest.d.ts +1 -1
- package/lib/types/DFWRequest.d.ts.map +1 -1
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +1 -1
package/lib/DFWCore.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
import { Express, Router } from "express";
|
|
3
|
+
import { DFWConfig } from "./types/DFWConfig";
|
|
4
|
+
import { APIListener, APIListenerFunction, APIListenerParams } from "./types/APIListener";
|
|
5
|
+
import { DFWRequest, DFWRequestSchema } from "./types/DFWRequest";
|
|
6
|
+
type DFWRegisterItem = APIListener | {
|
|
7
|
+
[key: string]: DFWRegisterItem;
|
|
8
|
+
} | DFWRegisterItem[];
|
|
9
|
+
declare global {
|
|
10
|
+
namespace Express {
|
|
11
|
+
interface Request {
|
|
12
|
+
dfw?: DFWRequestSchema;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare class DFWCore {
|
|
17
|
+
static MAIN_INSTANCE: DFWCore;
|
|
18
|
+
static DFW_PATH: string;
|
|
19
|
+
readonly server: Express;
|
|
20
|
+
readonly RouterAPILevel: Router;
|
|
21
|
+
readonly RouterAccessLevel: Router;
|
|
22
|
+
readonly config: DFWConfig;
|
|
23
|
+
private database;
|
|
24
|
+
private APIManager;
|
|
25
|
+
constructor(config: DFWConfig);
|
|
26
|
+
start(): this;
|
|
27
|
+
addListener(path: string, params: APIListenerParams, listener: APIListenerFunction): any;
|
|
28
|
+
addListener(path: string, params: APIListenerParams): any;
|
|
29
|
+
addListener(path: string, listener: APIListenerFunction): any;
|
|
30
|
+
addAccessValidator(path: string, validator: (req: DFWRequest) => boolean | Promise<boolean>): void;
|
|
31
|
+
/**
|
|
32
|
+
* @param DFW
|
|
33
|
+
* @param node
|
|
34
|
+
* @param path
|
|
35
|
+
*/
|
|
36
|
+
register(node: DFWRegisterItem | DFWRegisterItem[], path?: string): void;
|
|
37
|
+
get db(): PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
38
|
+
}
|
|
39
|
+
export default DFWCore;
|
|
40
|
+
//# sourceMappingURL=DFWCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DFWCore.d.ts","sourceRoot":"","sources":["../src/DFWCore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,EAA4B,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK1F,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAElE,KAAK,eAAe,GAAG,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,GAAG,eAAe,EAAE,CAAA;AAE3F,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAiB,OAAO;YACpB,GAAG,CAAC,EAAE,gBAAgB,CAAA;SACzB;KACJ;CACJ;AAED,qBAAa,OAAO;IAEhB,OAAc,aAAa,EAAE,OAAO,CAAA;IAEpC,OAAc,QAAQ,SAAW;IAEjC,SAAgB,MAAM,EAAE,OAAO,CAAmB;IAClD,SAAgB,cAAc,EAAE,MAAM,CAAY;IAClD,SAAgB,iBAAiB,EAAE,MAAM,CAAY;IAErD,SAAgB,MAAM,EAAE,SAAS,CAAC;IAClC,OAAO,CAAC,QAAQ,CAAe;IAE/B,OAAO,CAAC,UAAU,CAAuB;gBAE7B,MAAM,EAAE,SAAS;IAmBtB,KAAK;IAQL,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,mBAAmB;IAClF,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IACnD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB;IAQvD,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAYlG;;;;OAIG;IACI,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,eAAe,EAAE,EAAE,IAAI,GAAE,MAAW;IAoB5E,IAAI,EAAE,mIAEL;CACJ;AAED,eAAe,OAAO,CAAC"}
|
package/lib/DFWCore.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.DFWCore = void 0;
|
|
39
|
+
const client_1 = require("@prisma/client");
|
|
40
|
+
const express_1 = __importStar(require("express"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const fs_1 = __importDefault(require("fs"));
|
|
43
|
+
const DFWUtils_1 = __importDefault(require("./DFWUtils"));
|
|
44
|
+
const APIManager_1 = __importDefault(require("./lib/APIManager"));
|
|
45
|
+
class DFWCore {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
this.server = (0, express_1.default)();
|
|
49
|
+
this.RouterAPILevel = (0, express_1.Router)();
|
|
50
|
+
this.RouterAccessLevel = (0, express_1.Router)();
|
|
51
|
+
this.APIManager = new APIManager_1.default(this);
|
|
52
|
+
this.config = Object.freeze(config);
|
|
53
|
+
this.database = new client_1.PrismaClient({
|
|
54
|
+
log: config.database ? config.database.log ? ['query', 'info', 'warn', 'error'] : undefined : undefined,
|
|
55
|
+
});
|
|
56
|
+
if (fs_1.default.existsSync(DFWCore.DFW_PATH) == false) {
|
|
57
|
+
fs_1.default.mkdirSync(DFWCore.DFW_PATH);
|
|
58
|
+
}
|
|
59
|
+
if ((_a = config.server) === null || _a === void 0 ? void 0 : _a.trustProxy)
|
|
60
|
+
this.server.set('trust proxy', (_b = config.server) === null || _b === void 0 ? void 0 : _b.trustProxy);
|
|
61
|
+
this.APIManager.installAPILAyer();
|
|
62
|
+
this.APIManager.installSecurityLayer();
|
|
63
|
+
DFWCore.MAIN_INSTANCE = this;
|
|
64
|
+
}
|
|
65
|
+
start() {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const port = (_b = (_a = this.config.server) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 8080;
|
|
68
|
+
this.server.listen(port, () => {
|
|
69
|
+
DFWUtils_1.default.log(`Server listening on port ${chalk_1.default.yellow(port)}`);
|
|
70
|
+
});
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
addListener(path, b, c) {
|
|
74
|
+
const params = (typeof b == 'function' ? c : b);
|
|
75
|
+
const listener = typeof b === 'function' ? b : c;
|
|
76
|
+
this.APIManager.addListener(path, params, listener);
|
|
77
|
+
}
|
|
78
|
+
addAccessValidator(path, validator) {
|
|
79
|
+
this.RouterAccessLevel.use(path, (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const isValid = yield Promise.resolve(validator(req));
|
|
81
|
+
if (!isValid) {
|
|
82
|
+
return res.status(403).json({ error: 'ACCESS_DENIED' }).end();
|
|
83
|
+
}
|
|
84
|
+
next();
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @param DFW
|
|
89
|
+
* @param node
|
|
90
|
+
* @param path
|
|
91
|
+
*/
|
|
92
|
+
register(node, path = "") {
|
|
93
|
+
if (Array.isArray(node)) {
|
|
94
|
+
node.forEach((n) => { this.register(n, path); });
|
|
95
|
+
}
|
|
96
|
+
else if (!!node.listener || !!node.params) {
|
|
97
|
+
if (node.listener) {
|
|
98
|
+
this.addListener(path, node.params, node.listener);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.addListener(path, node.params);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (typeof node == "function") {
|
|
105
|
+
this.addListener(path, node);
|
|
106
|
+
}
|
|
107
|
+
else if (typeof node == "object") {
|
|
108
|
+
for (let okey in node) {
|
|
109
|
+
this.register(node[okey], `${path}/${okey}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
DFWUtils_1.default.log(`Unable to register '${path}' ${typeof node}`, true);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
get db() {
|
|
117
|
+
return this.database;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.DFWCore = DFWCore;
|
|
121
|
+
DFWCore.DFW_PATH = "./.dfw";
|
|
122
|
+
exports.default = DFWCore;
|
|
123
|
+
//# sourceMappingURL=DFWCore.js.map
|
|
@@ -0,0 +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AC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PrismaClient } from "@prisma/client";
|
|
2
2
|
import * as runtime from "@prisma/client/runtime/library";
|
|
3
|
-
import DFWCore from "
|
|
3
|
+
import DFWCore from "../DFWCore";
|
|
4
4
|
declare class DFWController {
|
|
5
5
|
private _db;
|
|
6
6
|
get db(): PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, runtime.DefaultArgs>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DFWController.d.ts","sourceRoot":"","sources":["../../src/controller/DFWController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,OAAO,MAAM,gCAAgC,CAAA;AACzD,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"DFWController.d.ts","sourceRoot":"","sources":["../../src/controller/DFWController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,OAAO,MAAM,gCAAgC,CAAA;AACzD,OAAO,OAAO,MAAM,YAAY,CAAA;AAEhC,cAAM,aAAa;IACf,OAAO,CAAC,GAAG,CAAyC;IAEpD,IAAI,EAAE,kGAEL;IAED,IAAI,GAAG,YAEN;IAED;;;;OAIG;IACI,GAAG,CACN,EAAE,EAAE,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACjE,IAAI;IAKA,WAAW,OACV,CACA,EAAE,EAAE,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,iBAAiB,CAAC,KAC/D,OAAO,CAAC,GAAG,CAAC,kBAOpB;CACJ;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -12,10 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
15
|
+
const DFWCore_1 = __importDefault(require("../DFWCore"));
|
|
16
16
|
class DFWController {
|
|
17
17
|
constructor() {
|
|
18
|
-
this._db =
|
|
18
|
+
this._db = DFWCore_1.default.MAIN_INSTANCE.db;
|
|
19
19
|
this.transaction = (cb) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
if (this.db.$transaction) {
|
|
21
21
|
return this.db.$transaction(cb);
|
|
@@ -29,7 +29,7 @@ class DFWController {
|
|
|
29
29
|
return this._db;
|
|
30
30
|
}
|
|
31
31
|
get DFW() {
|
|
32
|
-
return
|
|
32
|
+
return DFWCore_1.default.MAIN_INSTANCE;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DFWController.js","sourceRoot":"","sources":["../../src/controller/DFWController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"DFWController.js","sourceRoot":"","sources":["../../src/controller/DFWController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,yDAAgC;AAEhC,MAAM,aAAa;IAAnB;QACY,QAAG,GAAiB,iBAAO,CAAC,aAAa,CAAC,EAAE,CAAA;QAsB7C,gBAAW,GAAG,CACjB,EAEiB,EACnB,EAAE;YACA,IAAI,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;YACnC,CAAC;iBAAM,CAAC;gBACJ,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACtB,CAAC;QACL,CAAC,CAAA,CAAA;IACL,CAAC;IA/BG,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAA;IACnB,CAAC;IAED,IAAI,GAAG;QACH,OAAO,iBAAO,CAAC,aAAa,CAAA;IAChC,CAAC;IAED;;;;OAIG;IACI,GAAG,CACN,EAAgE;QAEhE,IAAI,CAAC,GAAG,GAAG,EAAkB,CAAA;QAC7B,OAAO,IAAI,CAAA;IACf,CAAC;CAaJ;AAED,kBAAe,aAAa,CAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { APIListener, APIListenerFunction, APIListenerParams } from "./types/APIListener";
|
|
5
|
-
import { DFWRequest, DFWRequestSchema } from "./types/DFWRequest";
|
|
6
|
-
type DFWRegisterItem = APIListener | {
|
|
7
|
-
[key: string]: DFWRegisterItem;
|
|
8
|
-
} | DFWRegisterItem[];
|
|
9
|
-
declare global {
|
|
10
|
-
namespace Express {
|
|
11
|
-
interface Request {
|
|
12
|
-
dfw?: DFWRequestSchema;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export declare class DFWCore {
|
|
17
|
-
static MAIN_INSTANCE: DFWCore;
|
|
18
|
-
static DFW_PATH: string;
|
|
19
|
-
readonly server: Express;
|
|
20
|
-
readonly RouterAPILevel: Router;
|
|
21
|
-
readonly RouterAccessLevel: Router;
|
|
22
|
-
readonly config: DFWConfig;
|
|
23
|
-
private database;
|
|
24
|
-
private APIManager;
|
|
25
|
-
constructor(config: DFWConfig);
|
|
26
|
-
start(): this;
|
|
27
|
-
addListener(path: string, params: APIListenerParams, listener: APIListenerFunction): any;
|
|
28
|
-
addListener(path: string, params: APIListenerParams): any;
|
|
29
|
-
addListener(path: string, listener: APIListenerFunction): any;
|
|
30
|
-
addAccessValidator(path: string, validator: (req: DFWRequest) => boolean | Promise<boolean>): void;
|
|
31
|
-
/**
|
|
32
|
-
* @param DFW
|
|
33
|
-
* @param node
|
|
34
|
-
* @param path
|
|
35
|
-
*/
|
|
36
|
-
register(node: DFWRegisterItem | DFWRegisterItem[], path?: string): void;
|
|
37
|
-
get db(): PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
38
|
-
}
|
|
39
|
-
export default DFWCore;
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { default as DFWCore } from './DFWCore';
|
|
3
|
+
export { default as DFWUtils } from "./DFWUtils";
|
|
40
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -10,114 +10,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
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);
|
|
33
15
|
};
|
|
34
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
18
|
};
|
|
37
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.DFWCore = void 0;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const APIManager_1 = __importDefault(require("./lib/APIManager"));
|
|
45
|
-
class DFWCore {
|
|
46
|
-
constructor(config) {
|
|
47
|
-
var _a, _b;
|
|
48
|
-
this.server = (0, express_1.default)();
|
|
49
|
-
this.RouterAPILevel = (0, express_1.Router)();
|
|
50
|
-
this.RouterAccessLevel = (0, express_1.Router)();
|
|
51
|
-
this.APIManager = new APIManager_1.default(this);
|
|
52
|
-
this.config = Object.freeze(config);
|
|
53
|
-
this.database = new client_1.PrismaClient({
|
|
54
|
-
log: config.database ? config.database.log ? ['query', 'info', 'warn', 'error'] : undefined : undefined,
|
|
55
|
-
});
|
|
56
|
-
if (fs_1.default.existsSync(DFWCore.DFW_PATH) == false) {
|
|
57
|
-
fs_1.default.mkdirSync(DFWCore.DFW_PATH);
|
|
58
|
-
}
|
|
59
|
-
if ((_a = config.server) === null || _a === void 0 ? void 0 : _a.trustProxy)
|
|
60
|
-
this.server.set('trust proxy', (_b = config.server) === null || _b === void 0 ? void 0 : _b.trustProxy);
|
|
61
|
-
this.APIManager.installAPILAyer();
|
|
62
|
-
this.APIManager.installSecurityLayer();
|
|
63
|
-
DFWCore.MAIN_INSTANCE = this;
|
|
64
|
-
}
|
|
65
|
-
start() {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
const port = (_b = (_a = this.config.server) === null || _a === void 0 ? void 0 : _a.port) !== null && _b !== void 0 ? _b : 8080;
|
|
68
|
-
this.server.listen(port, () => {
|
|
69
|
-
DFWUtils_1.default.log(`Server listening on port ${chalk_1.default.yellow(port)}`);
|
|
70
|
-
});
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
addListener(path, b, c) {
|
|
74
|
-
const params = (typeof b == 'function' ? c : b);
|
|
75
|
-
const listener = typeof b === 'function' ? b : c;
|
|
76
|
-
this.APIManager.addListener(path, params, listener);
|
|
77
|
-
}
|
|
78
|
-
addAccessValidator(path, validator) {
|
|
79
|
-
this.RouterAccessLevel.use(path, (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const isValid = yield Promise.resolve(validator(req));
|
|
81
|
-
if (!isValid) {
|
|
82
|
-
return res.status(403).json({ error: 'ACCESS_DENIED' }).end();
|
|
83
|
-
}
|
|
84
|
-
next();
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* @param DFW
|
|
89
|
-
* @param node
|
|
90
|
-
* @param path
|
|
91
|
-
*/
|
|
92
|
-
register(node, path = "") {
|
|
93
|
-
if (Array.isArray(node)) {
|
|
94
|
-
node.forEach((n) => { this.register(n, path); });
|
|
95
|
-
}
|
|
96
|
-
else if (!!node.listener || !!node.params) {
|
|
97
|
-
if (node.listener) {
|
|
98
|
-
this.addListener(path, node.params, node.listener);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
this.addListener(path, node.params);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else if (typeof node == "function") {
|
|
105
|
-
this.addListener(path, node);
|
|
106
|
-
}
|
|
107
|
-
else if (typeof node == "object") {
|
|
108
|
-
for (let okey in node) {
|
|
109
|
-
this.register(node[okey], `${path}/${okey}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
DFWUtils_1.default.log(`Unable to register '${path}' ${typeof node}`, true);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
get db() {
|
|
117
|
-
return this.database;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.DFWCore = DFWCore;
|
|
121
|
-
DFWCore.DFW_PATH = "./.dfw";
|
|
122
|
-
exports.default = DFWCore;
|
|
20
|
+
exports.DFWUtils = exports.DFWCore = void 0;
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
var DFWCore_1 = require("./DFWCore");
|
|
23
|
+
Object.defineProperty(exports, "DFWCore", { enumerable: true, get: function () { return __importDefault(DFWCore_1).default; } });
|
|
24
|
+
var DFWUtils_1 = require("./DFWUtils");
|
|
25
|
+
Object.defineProperty(exports, "DFWUtils", { enumerable: true, get: function () { return __importDefault(DFWUtils_1).default; } });
|
|
123
26
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,qCAA8C;AAArC,mHAAA,OAAO,OAAW;AAC3B,uCAAgD;AAAvC,qHAAA,OAAO,OAAY"}
|
package/lib/lib/APIManager.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"APIManager.d.ts","sourceRoot":"","sources":["../../src/lib/APIManager.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"APIManager.d.ts","sourceRoot":"","sources":["../../src/lib/APIManager.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,YAAY,CAAC;AAGjC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAW9E,MAAM,CAAC,OAAO,OAAO,UAAU;IAC3B,OAAO,CAAC,GAAG,CAAS;gBAER,GAAG,EAAE,OAAO;IAIjB,eAAe;IAoDf,oBAAoB;IAIpB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,iBAAsB,EAAE,QAAQ,CAAC,EAAE,mBAAmB;CAmDlG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DFWSessionStore.d.ts","sourceRoot":"","sources":["../../src/lib/DFWSessionStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"DFWSessionStore.d.ts","sourceRoot":"","sources":["../../src/lib/DFWSessionStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,OAAO,MAAM,YAAY,CAAC;AAGjC,cAAM,eAAgB,SAAQ,KAAK;IAE/B,OAAO,CAAC,EAAE,CAAc;gBAEZ,GAAG,EAAE,OAAO;IAKxB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAenE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAiBxE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;CAY7D;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DFWRequest.d.ts","sourceRoot":"","sources":["../../src/types/DFWRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"DFWRequest.d.ts","sourceRoot":"","sources":["../../src/types/DFWRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,MAAM,MAAM,UAAU,GAAG;IACrB,GAAG,EAAE,gBAAgB,CAAC;CACzB,GAAG,OAAO,CAAA;AAEX,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,EAAE,OAAO,CAAA;IACjB,eAAe,EAAE,MAAM,OAAO,CAAC;IAC/B,IAAI,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IACzC,OAAO,EAAE;QACL,YAAY,EAAE,MAAM,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;QACjD,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;QACxC,WAAW,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;KACtC,CAAC;IACF,EAAE,EAAE,YAAY,CAAC;IAEjB;;;;OAIG;IACH,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;CACxD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACjH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|