typespeed 0.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/dist/core.decorator.d.ts +18 -0
  4. package/dist/core.decorator.js +185 -0
  5. package/dist/core.decorator.js.map +1 -0
  6. package/dist/database.decorator.d.ts +24 -0
  7. package/dist/database.decorator.js +335 -0
  8. package/dist/database.decorator.js.map +1 -0
  9. package/dist/default/express-server.class.d.ts +15 -0
  10. package/dist/default/express-server.class.js +148 -0
  11. package/dist/default/express-server.class.js.map +1 -0
  12. package/dist/default/log-default.class.d.ts +6 -0
  13. package/dist/default/log-default.class.js +32 -0
  14. package/dist/default/log-default.class.js.map +1 -0
  15. package/dist/default/node-cache.class.d.ts +13 -0
  16. package/dist/default/node-cache.class.js +51 -0
  17. package/dist/default/node-cache.class.js.map +1 -0
  18. package/dist/default/pages/404.html +226 -0
  19. package/dist/default/pages/500.html +713 -0
  20. package/dist/default/read-write-db.class.d.ts +10 -0
  21. package/dist/default/read-write-db.class.js +66 -0
  22. package/dist/default/read-write-db.class.js.map +1 -0
  23. package/dist/default/redis.class.d.ts +5 -0
  24. package/dist/default/redis.class.js +32 -0
  25. package/dist/default/redis.class.js.map +1 -0
  26. package/dist/factory/cache-factory.class.d.ts +7 -0
  27. package/dist/factory/cache-factory.class.js +6 -0
  28. package/dist/factory/cache-factory.class.js.map +1 -0
  29. package/dist/factory/data-source-factory.class.d.ts +4 -0
  30. package/dist/factory/data-source-factory.class.js +6 -0
  31. package/dist/factory/data-source-factory.class.js.map +1 -0
  32. package/dist/factory/log-factory.class.d.ts +4 -0
  33. package/dist/factory/log-factory.class.js +6 -0
  34. package/dist/factory/log-factory.class.js.map +1 -0
  35. package/dist/factory/server-factory.class.d.ts +6 -0
  36. package/dist/factory/server-factory.class.js +9 -0
  37. package/dist/factory/server-factory.class.js.map +1 -0
  38. package/dist/route.decorator.d.ts +8 -0
  39. package/dist/route.decorator.js +87 -0
  40. package/dist/route.decorator.js.map +1 -0
  41. package/dist/typespeed.d.ts +12 -0
  42. package/dist/typespeed.js +39 -0
  43. package/dist/typespeed.js.map +1 -0
  44. package/package.json +39 -6
  45. package/src/core.decorator.ts +183 -0
  46. package/src/database.decorator.ts +342 -0
  47. package/src/default/express-server.class.ts +133 -0
  48. package/src/default/log-default.class.ts +19 -0
  49. package/src/default/node-cache.class.ts +39 -0
  50. package/src/default/pages/404.html +226 -0
  51. package/src/default/pages/500.html +713 -0
  52. package/src/default/read-write-db.class.ts +53 -0
  53. package/src/default/redis.class.ts +18 -0
  54. package/src/factory/cache-factory.class.ts +7 -0
  55. package/src/factory/data-source-factory.class.ts +4 -0
  56. package/src/factory/log-factory.class.ts +4 -0
  57. package/src/factory/server-factory.class.ts +6 -0
  58. package/src/route.decorator.ts +82 -0
  59. package/src/typespeed.ts +15 -0
  60. package/test/nodemon.json +6 -0
  61. package/test/package.json +18 -0
  62. package/test/src/aop-test.class.ts +29 -0
  63. package/test/src/config-development.json +15 -0
  64. package/test/src/config-production.json +15 -0
  65. package/test/src/config.json +46 -0
  66. package/test/src/custom-log.class.ts +26 -0
  67. package/test/src/entities/user-dto.class.ts +3 -0
  68. package/test/src/first-page.class.ts +46 -0
  69. package/test/src/main.ts +17 -0
  70. package/test/src/second-page.class.ts +43 -0
  71. package/test/src/test-database.class.ts +85 -0
  72. package/test/src/test-log.class.ts +9 -0
  73. package/test/src/test-orm.class.ts +74 -0
  74. package/test/src/user-model.class.ts +45 -0
  75. package/test/src/views/index.html +1 -0
  76. package/test/src/views/upload.html +14 -0
  77. package/test/static/favicon.ico +0 -0
  78. package/test/static/k.jpg +0 -0
  79. package/test/tsconfig.json +20 -0
  80. package/tsconfig.json +25 -0
@@ -0,0 +1,10 @@
1
+ import DataSourceFactory from "../factory/data-source-factory.class";
2
+ export default class ReadWriteDb extends DataSourceFactory {
3
+ private readonly readSession;
4
+ private readonly writeSession;
5
+ getDataSource(): DataSourceFactory;
6
+ constructor();
7
+ private getConnectionByConfig;
8
+ readConnection(): any;
9
+ writeConnection(): any;
10
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const mysql2_1 = require("mysql2");
13
+ const data_source_factory_class_1 = require("../factory/data-source-factory.class");
14
+ const core_decorator_1 = require("../core.decorator");
15
+ class ReadWriteDb extends data_source_factory_class_1.default {
16
+ constructor() {
17
+ super();
18
+ const dbConfig = (0, core_decorator_1.config)("mysql");
19
+ if (dbConfig["master"] && dbConfig["slave"]) {
20
+ this.writeSession = this.getConnectionByConfig(dbConfig["master"]);
21
+ if (Array.isArray(dbConfig["slave"])) {
22
+ this.readSession = dbConfig["slave"].map(config => this.getConnectionByConfig(config));
23
+ }
24
+ else {
25
+ this.readSession = [this.getConnectionByConfig(dbConfig["slave"])];
26
+ }
27
+ }
28
+ else {
29
+ this.writeSession = this.getConnectionByConfig(dbConfig);
30
+ this.readSession = [this.writeSession];
31
+ }
32
+ }
33
+ getDataSource() {
34
+ if (!(0, core_decorator_1.config)("mysql")) {
35
+ return null;
36
+ }
37
+ return new ReadWriteDb();
38
+ }
39
+ getConnectionByConfig(config) {
40
+ if (config["PoolOptions"] !== undefined) {
41
+ // we need pool
42
+ if (Object.keys(config["PoolOptions"]).length !== 0) {
43
+ config = Object.assign(config, config["PoolOptions"]);
44
+ }
45
+ return (0, mysql2_1.createPool)(config).promise();
46
+ }
47
+ else {
48
+ // only connection
49
+ return (0, mysql2_1.createConnection)(config).promise();
50
+ }
51
+ }
52
+ readConnection() {
53
+ return this.readSession[Math.floor(Math.random() * this.readSession.length)];
54
+ }
55
+ writeConnection() {
56
+ return this.writeSession;
57
+ }
58
+ }
59
+ __decorate([
60
+ core_decorator_1.bean,
61
+ __metadata("design:type", Function),
62
+ __metadata("design:paramtypes", []),
63
+ __metadata("design:returntype", data_source_factory_class_1.default)
64
+ ], ReadWriteDb.prototype, "getDataSource", null);
65
+ exports.default = ReadWriteDb;
66
+ //# sourceMappingURL=read-write-db.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-write-db.class.js","sourceRoot":"","sources":["../../src/default/read-write-db.class.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAsD;AACtD,oFAAqE;AACrE,sDAAiD;AAEjD,MAAqB,WAAY,SAAQ,mCAAiB;IAYtD;QACI,KAAK,EAAE,CAAC;QACR,MAAM,QAAQ,GAAG,IAAA,uBAAM,EAAC,OAAO,CAAC,CAAC;QACjC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE;YACzC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;YACnE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE;gBAClC,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC;aAC1F;iBAAM;gBACH,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,qBAAq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 }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const core_decorator_1 = require("../core.decorator");
13
+ const ioredis_1 = require("ioredis");
14
+ class Redis extends ioredis_1.default {
15
+ getRedis() {
16
+ if (!(0, core_decorator_1.config)("redis")) {
17
+ return null;
18
+ }
19
+ return new Redis((0, core_decorator_1.config)("redis"));
20
+ }
21
+ constructor(config) {
22
+ super(config);
23
+ }
24
+ }
25
+ __decorate([
26
+ core_decorator_1.bean,
27
+ __metadata("design:type", Function),
28
+ __metadata("design:paramtypes", []),
29
+ __metadata("design:returntype", Redis)
30
+ ], Redis.prototype, "getRedis", null);
31
+ exports.default = Redis;
32
+ //# sourceMappingURL=redis.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.class.js","sourceRoot":"","sources":["../../src/default/redis.class.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,qCAA8B;AAE9B,MAAqB,KAAM,SAAQ,iBAAO;IAG/B,QAAQ;QACX,IAAI,CAAC,IAAA,uBAAM,EAAC,OAAO,CAAC,EAAE;YAClB,OAAO,IAAI,CAAC;SACf;QACD,OAAO,IAAI,KAAK,CAAC,IAAA,uBAAM,EAAC,OAAO,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,YAAY,MAAW;QACnB,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;CAEJ;AAZG;IAAC,qBAAI;;;oCACc,KAAK;qCAKvB;AARL,wBAcC"}
@@ -0,0 +1,7 @@
1
+ export default abstract class CacheFactory {
2
+ abstract get(key: string): any;
3
+ abstract set(key: string, value: any, expire?: number): void;
4
+ abstract del(key: string): void;
5
+ abstract has(key: string): boolean;
6
+ abstract flush(): void;
7
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CacheFactory {
4
+ }
5
+ exports.default = CacheFactory;
6
+ //# sourceMappingURL=cache-factory.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-factory.class.js","sourceRoot":"","sources":["../../src/factory/cache-factory.class.ts"],"names":[],"mappings":";;AAAA,MAA8B,YAAY;CAMzC;AAND,+BAMC"}
@@ -0,0 +1,4 @@
1
+ export default abstract class DataSourceFactory {
2
+ abstract readConnection(): any;
3
+ abstract writeConnection(): any;
4
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class DataSourceFactory {
4
+ }
5
+ exports.default = DataSourceFactory;
6
+ //# sourceMappingURL=data-source-factory.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-source-factory.class.js","sourceRoot":"","sources":["../../src/factory/data-source-factory.class.ts"],"names":[],"mappings":";;AAAA,MAA8B,iBAAiB;CAG9C;AAHD,oCAGC"}
@@ -0,0 +1,4 @@
1
+ export default abstract class LogFactory {
2
+ abstract log(message?: any, ...optionalParams: any[]): void;
3
+ abstract error(message?: any, ...optionalParams: any[]): void;
4
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class LogFactory {
4
+ }
5
+ exports.default = LogFactory;
6
+ //# sourceMappingURL=log-factory.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-factory.class.js","sourceRoot":"","sources":["../../src/factory/log-factory.class.ts"],"names":[],"mappings":";;AAAA,MAA8B,UAAU;CAGvC;AAHD,6BAGC"}
@@ -0,0 +1,6 @@
1
+ export default abstract class ServerFactory {
2
+ app: any;
3
+ protected middlewareList: Array<any>;
4
+ abstract setMiddleware(middleware: any): any;
5
+ abstract start(port: number): any;
6
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ServerFactory {
4
+ constructor() {
5
+ this.middlewareList = [];
6
+ }
7
+ }
8
+ exports.default = ServerFactory;
9
+ //# sourceMappingURL=server-factory.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-factory.class.js","sourceRoot":"","sources":["../../src/factory/server-factory.class.ts"],"names":[],"mappings":";;AAAA,MAA8B,aAAa;IAA3C;QAEc,mBAAc,GAAe,EAAE,CAAC;IAG9C,CAAC;CAAA;AALD,gCAKC"}
@@ -0,0 +1,8 @@
1
+ import * as express from "express";
2
+ declare function setRouter(app: express.Application): void;
3
+ declare function upload(target: any, propertyKey: string): void;
4
+ declare function jwt(jwtConfig: any): (target: any, propertyKey: string) => void;
5
+ declare const getMapping: (value: string) => (target: any, propertyKey: string) => void;
6
+ declare const postMapping: (value: string) => (target: any, propertyKey: string) => void;
7
+ declare const requestMapping: (value: string) => (target: any, propertyKey: string) => void;
8
+ export { getMapping, postMapping, requestMapping, setRouter, upload, jwt };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jwt = exports.upload = exports.setRouter = exports.requestMapping = exports.postMapping = exports.getMapping = void 0;
4
+ const multiparty = require("multiparty");
5
+ const express_jwt_1 = require("express-jwt");
6
+ const core_decorator_1 = require("./core.decorator");
7
+ const routerMapper = {
8
+ "get": {},
9
+ "post": {},
10
+ "all": {}
11
+ };
12
+ const routerMiddleware = {};
13
+ function setRouter(app) {
14
+ ["get", "post", "all"].forEach(method => {
15
+ for (let key in routerMapper[method]) {
16
+ let rounterFunction = routerMapper[method][key];
17
+ if (routerMiddleware[rounterFunction["name"]]) {
18
+ let args = [key, ...routerMiddleware[rounterFunction["name"]], rounterFunction["invoker"]];
19
+ app[method].apply(app, args);
20
+ }
21
+ else {
22
+ app[method](key, rounterFunction["invoker"]);
23
+ }
24
+ }
25
+ });
26
+ }
27
+ exports.setRouter = setRouter;
28
+ function mapperFunction(method, value) {
29
+ return (target, propertyKey) => {
30
+ routerMapper[method][value] = {
31
+ "path": value,
32
+ "name": [target.constructor.name, propertyKey].toString(),
33
+ "invoker": async (req, res, next) => {
34
+ const routerBean = (0, core_decorator_1.getComponent)(target.constructor);
35
+ try {
36
+ const testResult = await routerBean[propertyKey](req, res);
37
+ if (typeof testResult === "object") {
38
+ res.json(testResult);
39
+ }
40
+ else if (typeof testResult !== "undefined") {
41
+ res.send(testResult);
42
+ }
43
+ return testResult;
44
+ }
45
+ catch (err) {
46
+ next(err);
47
+ }
48
+ }
49
+ };
50
+ };
51
+ }
52
+ function upload(target, propertyKey) {
53
+ const key = [target.constructor.name, propertyKey].toString();
54
+ if (routerMiddleware[key]) {
55
+ routerMiddleware[key].push(uploadMiddleware);
56
+ }
57
+ else {
58
+ routerMiddleware[key] = [uploadMiddleware];
59
+ }
60
+ }
61
+ exports.upload = upload;
62
+ function uploadMiddleware(req, res, next) {
63
+ const form = new multiparty.Form();
64
+ form.parse(req, (err, fields, files) => {
65
+ req.files = files || undefined;
66
+ next();
67
+ });
68
+ }
69
+ function jwt(jwtConfig) {
70
+ return (target, propertyKey) => {
71
+ const key = [target.constructor.name, propertyKey].toString();
72
+ if (routerMiddleware[key]) {
73
+ routerMiddleware[key].push((0, express_jwt_1.expressjwt)(jwtConfig));
74
+ }
75
+ else {
76
+ routerMiddleware[key] = [(0, express_jwt_1.expressjwt)(jwtConfig)];
77
+ }
78
+ };
79
+ }
80
+ exports.jwt = jwt;
81
+ const getMapping = (value) => mapperFunction("get", value);
82
+ exports.getMapping = getMapping;
83
+ const postMapping = (value) => mapperFunction("post", value);
84
+ exports.postMapping = postMapping;
85
+ const requestMapping = (value) => mapperFunction("all", value);
86
+ exports.requestMapping = requestMapping;
87
+ //# sourceMappingURL=route.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.decorator.js","sourceRoot":"","sources":["../src/route.decorator.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AACzC,6CAAyC;AACzC,qDAAgD;AAEhD,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,SAAS,SAAS,CAAC,GAAwB;IACzC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACtC,KAAK,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE;YACpC,IAAI,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;YAChD,IAAI,gBAAgB,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE;gBAC7C,IAAI,IAAI,GAAe,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;gBACvG,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;aAC9B;iBAAM;gBACL,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC;aAC9C;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAyDiD,8BAAS;AAvD3D,SAAS,cAAc,CAAC,MAAc,EAAE,KAAa;IACnD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YA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,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;QACrC,GAAG,CAAC,KAAK,GAAG,KAAK,IAAI,SAAS,CAAC;QAC/B,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,GAAG,CAAC,SAAS;IACpB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC9D,IAAI,gBAAgB,CAAC,GAAG,CAAC,EAAE;YACzB,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,wBAAU,EAAC,SAAS,CAAC,CAAC,CAAC;SACnD;aAAM;YACL,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,wBAAU,EAAC,SAAS,CAAC,CAAC,CAAC;SACjD;IACH,CAAC,CAAA;AACH,CAAC;AAMoE,kBAAG;AAJxE,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAI1D,gCAAU;AAHnB,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAGhD,kCAAW;AAFhC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAErC,wCAAc"}
@@ -0,0 +1,12 @@
1
+ export * from "./core.decorator";
2
+ export * from "./route.decorator";
3
+ export * from "./database.decorator";
4
+ export { default as LogFactory } from "./factory/log-factory.class";
5
+ export { default as CacheFactory } from "./factory/cache-factory.class";
6
+ export { default as DataSourceFactory } from "./factory/data-source-factory.class";
7
+ export { default as ServerFactory } from "./factory/server-factory.class";
8
+ export { default as ExpressServer } from "./default/express-server.class";
9
+ export { default as LogDefault } from "./default/log-default.class";
10
+ export { default as NodeCache } from "./default/node-cache.class";
11
+ export { default as Redis } from "./default/redis.class";
12
+ export { default as ReadWriteDb } from "./default/read-write-db.class";
@@ -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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ReadWriteDb = exports.Redis = exports.NodeCache = exports.LogDefault = exports.ExpressServer = exports.ServerFactory = exports.DataSourceFactory = exports.CacheFactory = exports.LogFactory = void 0;
18
+ __exportStar(require("./core.decorator"), exports);
19
+ __exportStar(require("./route.decorator"), exports);
20
+ __exportStar(require("./database.decorator"), exports);
21
+ var log_factory_class_1 = require("./factory/log-factory.class");
22
+ Object.defineProperty(exports, "LogFactory", { enumerable: true, get: function () { return log_factory_class_1.default; } });
23
+ var cache_factory_class_1 = require("./factory/cache-factory.class");
24
+ Object.defineProperty(exports, "CacheFactory", { enumerable: true, get: function () { return cache_factory_class_1.default; } });
25
+ var data_source_factory_class_1 = require("./factory/data-source-factory.class");
26
+ Object.defineProperty(exports, "DataSourceFactory", { enumerable: true, get: function () { return data_source_factory_class_1.default; } });
27
+ var server_factory_class_1 = require("./factory/server-factory.class");
28
+ Object.defineProperty(exports, "ServerFactory", { enumerable: true, get: function () { return server_factory_class_1.default; } });
29
+ var express_server_class_1 = require("./default/express-server.class");
30
+ Object.defineProperty(exports, "ExpressServer", { enumerable: true, get: function () { return express_server_class_1.default; } });
31
+ var log_default_class_1 = require("./default/log-default.class");
32
+ Object.defineProperty(exports, "LogDefault", { enumerable: true, get: function () { return log_default_class_1.default; } });
33
+ var node_cache_class_1 = require("./default/node-cache.class");
34
+ Object.defineProperty(exports, "NodeCache", { enumerable: true, get: function () { return node_cache_class_1.default; } });
35
+ var redis_class_1 = require("./default/redis.class");
36
+ Object.defineProperty(exports, "Redis", { enumerable: true, get: function () { return redis_class_1.default; } });
37
+ var read_write_db_class_1 = require("./default/read-write-db.class");
38
+ Object.defineProperty(exports, "ReadWriteDb", { enumerable: true, get: function () { return read_write_db_class_1.default; } });
39
+ //# sourceMappingURL=typespeed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typespeed.js","sourceRoot":"","sources":["../src/typespeed.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,oDAAkC;AAClC,uDAAqC;AAGrC,iEAAmE;AAA1D,+GAAA,OAAO,OAAc;AAC9B,qEAAuE;AAA9D,mHAAA,OAAO,OAAgB;AAChC,iFAAkF;AAAzE,8HAAA,OAAO,OAAqB;AACrC,uEAAyE;AAAhE,qHAAA,OAAO,OAAiB;AAEjC,uEAAyE;AAAhE,qHAAA,OAAO,OAAiB;AACjC,iEAAmE;AAA1D,+GAAA,OAAO,OAAc;AAC9B,+DAAiE;AAAxD,6GAAA,OAAO,OAAa;AAC7B,qDAAwD;AAA/C,oGAAA,OAAO,OAAS;AACzB,qEAAsE;AAA7D,kHAAA,OAAO,OAAe"}
package/package.json CHANGED
@@ -1,11 +1,44 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "2.0.2",
4
+ "description": "A new Framework for TypeScript.",
5
+ "author": "speedphp",
6
+ "license": "MIT License",
6
7
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
+ "build": "tsc -p .",
9
+ "postbuild": "cp -r src/default/pages dist/default/pages",
10
+ "prebuild": "rm -rf dist",
11
+ "prepare": "npm version patch && npm run build",
12
+ "upgrade": "npm version minor",
13
+ "postpublish": "git push && git push --tags"
8
14
  },
9
- "author": "speed",
10
- "license": "MIT"
15
+ "main": "dist/typespeed.js",
16
+ "homepage": "https://github.com/speedphp/typespeed#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/speedphp/typespeed.git"
20
+ },
21
+ "dependencies": {
22
+ "@types/node": "^18.0.6",
23
+ "reflect-metadata": "^0.1.13",
24
+ "typescript": "^4.7.4",
25
+ "walk-sync": "^3.0.0",
26
+ "tracer": "^1.1.6",
27
+ "express": "^4.18.1",
28
+ "consolidate": "^0.16.0",
29
+ "mustache": "^4.2.0",
30
+ "serve-favicon": "^2.5.0",
31
+ "compression": "^1.7.4",
32
+ "cookie-parser": "^1.4.6",
33
+ "express-session": "^1.17.3",
34
+ "multiparty": "^4.2.3",
35
+ "express-basic-auth": "^1.2.1",
36
+ "express-jwt": "^7.7.5",
37
+ "jsonwebtoken": "^8.5.1",
38
+ "mysql2": "^2.3.3",
39
+ "node-cache": "^5.1.2",
40
+ "ioredis": "^5.2.3",
41
+ "connect-redis": "^6.1.3",
42
+ "cron": "^2.1.0"
43
+ }
11
44
  }
@@ -0,0 +1,183 @@
1
+ import "reflect-metadata";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import * as walkSync from "walk-sync";
5
+ import * as cron from "cron";
6
+ import LogFactory from "./factory/log-factory.class";
7
+
8
+ let globalConfig = {};
9
+ const resourceObjects = new Map<string, object>();
10
+ const beanMapper: Map<string, any> = new Map<string, any>();
11
+ const objectMapper: Map<string, any> = new Map<string, any>();
12
+ const coreDir = __dirname;
13
+ const mainPath = path.dirname(process.argv[1]);
14
+
15
+ const configFile = mainPath + "/config.json";
16
+ if (fs.existsSync(configFile)) {
17
+ globalConfig = JSON.parse(fs.readFileSync(configFile, "utf-8"));
18
+ const nodeEnv = process.env.NODE_ENV || "development";
19
+ const envConfigFile = mainPath + "/config-" + nodeEnv + ".json";
20
+ if (fs.existsSync(envConfigFile)) {
21
+ globalConfig = Object.assign(globalConfig, JSON.parse(fs.readFileSync(envConfigFile, "utf-8")));
22
+ }
23
+ }
24
+
25
+ function app<T extends { new(...args: any[]): {} }>(constructor: T) {
26
+ const coreFiles = walkSync(coreDir, { globs: ['**/*.ts'] });
27
+ const mainFiles = walkSync(mainPath, { globs: ['**/*.ts'] });
28
+
29
+ (async function () {
30
+ try {
31
+ for (let p of coreFiles) {
32
+ let moduleName = p.replace(".d.ts", "").replace(".ts", "");
33
+ await import(coreDir + "/" + moduleName);
34
+ }
35
+
36
+ for (let p of mainFiles) {
37
+ let moduleName = p.replace(".d.ts", "").replace(".ts", "");
38
+ await import(mainPath + "/" + moduleName);
39
+ }
40
+ } catch (err) {
41
+ console.error(err);
42
+ }
43
+ //log("main start")
44
+ const main = new constructor();
45
+ main["main"]();
46
+ }());
47
+ }
48
+
49
+ function config(node: string) {
50
+ return globalConfig[node] || null;
51
+ }
52
+
53
+ function component(constructorFunction) {
54
+ objectMapper.set(constructorFunction.name, new constructorFunction());
55
+ }
56
+
57
+ function getComponent(constructorFunction) {
58
+ return objectMapper.get(constructorFunction.name);
59
+ }
60
+
61
+ function bean(target: any, propertyKey: string) {
62
+ let returnType = Reflect.getMetadata("design:returntype", target, propertyKey);
63
+ //const targetObject = new target.constructor();
64
+ beanMapper.set(returnType.name, {
65
+ "target": target, "propertyKey": propertyKey,
66
+ "factory": target[propertyKey]()
67
+ });
68
+ }
69
+
70
+ function getBean(mappingClass: Function): any {
71
+ const bean = beanMapper.get(mappingClass.name);
72
+ return bean["factory"];
73
+ }
74
+
75
+ function value(configPath: string): any {
76
+ return function (target: any, propertyKey: string) {
77
+ if (globalConfig === undefined) {
78
+ Object.defineProperty(target, propertyKey, {
79
+ get: () => {
80
+ return undefined;
81
+ }
82
+ });
83
+ } else {
84
+ let pathNodes = configPath.split(".");
85
+ let nodeValue = globalConfig;
86
+ for (let i = 0; i < pathNodes.length; i++) {
87
+ nodeValue = nodeValue[pathNodes[i]];
88
+ }
89
+ Object.defineProperty(target, propertyKey, {
90
+ get: () => {
91
+ return nodeValue;
92
+ }
93
+ });
94
+ }
95
+ };
96
+ }
97
+
98
+ function autoware(target: any, propertyKey: string): void {
99
+ const type = Reflect.getMetadata("design:type", target, propertyKey);
100
+ Object.defineProperty(target, propertyKey, {
101
+ get: () => {
102
+ const targetObject = beanMapper.get(type.name);
103
+ if (targetObject === undefined) {
104
+ const resourceKey = [target.constructor.name, propertyKey, type.name].toString();
105
+ if (!resourceObjects[resourceKey]) {
106
+ resourceObjects[resourceKey] = new type();
107
+ }
108
+ return resourceObjects[resourceKey];
109
+ }
110
+ return targetObject["factory"];
111
+ }
112
+ });
113
+ }
114
+
115
+ function resource(...args): any {
116
+ return (target: any, propertyKey: string) => {
117
+ const type = Reflect.getMetadata("design:type", target, propertyKey);
118
+ Object.defineProperty(target, propertyKey, {
119
+ get: () => {
120
+ const resourceKey = [target.constructor.name, propertyKey, type.name].toString();
121
+ if (!resourceObjects[resourceKey]) {
122
+ resourceObjects[resourceKey] = new type(...args);
123
+ }
124
+ return resourceObjects[resourceKey];
125
+ }
126
+ });
127
+ }
128
+ }
129
+
130
+ function log(message?: any, ...optionalParams: any[]) {
131
+ const logObject = beanMapper.get(LogFactory.name);
132
+ if (logObject) {
133
+ logObject["factory"].log(message, ...optionalParams);
134
+ } else {
135
+ console.log(message, ...optionalParams);
136
+ }
137
+ }
138
+
139
+ function error(message?: any, ...optionalParams: any[]) {
140
+ const logObject = beanMapper.get(LogFactory.name);
141
+ if (logObject) {
142
+ logObject["factory"].error(message, ...optionalParams);
143
+ } else {
144
+ console.error(message, ...optionalParams);
145
+ }
146
+ }
147
+
148
+ function before(constructorFunction, methodName: string) {
149
+ const targetBean = getComponent(constructorFunction);
150
+ return function (target, propertyKey: string) {
151
+ const currentMethod = targetBean[methodName];
152
+ Object.assign(targetBean, {
153
+ [methodName]: function (...args) {
154
+ target[propertyKey](...args);
155
+ log("========== before ==========");
156
+ return currentMethod.apply(targetBean, args);
157
+ }
158
+ })
159
+ };
160
+ }
161
+
162
+ function after(constructorFunction, methodName: string) {
163
+ const targetBean = getComponent(constructorFunction);
164
+ return function (target, propertyKey: string) {
165
+ const currentMethod = targetBean[methodName];
166
+ Object.assign(targetBean, {
167
+ [methodName]: function (...args) {
168
+ const result = currentMethod.apply(targetBean, args);
169
+ const afterResult = target[propertyKey](result);
170
+ log("========== after ==========");
171
+ return afterResult ?? result;
172
+ }
173
+ })
174
+ };
175
+ }
176
+
177
+ function schedule(cronTime: string | Date) {
178
+ return (target: any, propertyKey: string) => {
179
+ new cron.CronJob(cronTime, target[propertyKey]).start();
180
+ }
181
+ }
182
+
183
+ export { component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule };