ctx-router 1.0.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 +21 -0
- package/README.md +130 -0
- package/dist/ctx/ctx.err.d.ts +28 -0
- package/dist/ctx/ctx.err.d.ts.map +1 -0
- package/dist/ctx/ctx.err.js +43 -0
- package/dist/ctx/ctx.err.js.map +1 -0
- package/dist/ctx/ctx.router.d.ts +9 -0
- package/dist/ctx/ctx.router.d.ts.map +1 -0
- package/dist/ctx/ctx.router.js +45 -0
- package/dist/ctx/ctx.router.js.map +1 -0
- package/dist/ctx/ctx.types.d.ts +96 -0
- package/dist/ctx/ctx.types.d.ts.map +1 -0
- package/dist/ctx/ctx.types.js +10 -0
- package/dist/ctx/ctx.types.js.map +1 -0
- package/dist/ctx.types.d.ts +96 -0
- package/dist/ctx.types.d.ts.map +1 -0
- package/dist/ctx.types.js +10 -0
- package/dist/ctx.types.js.map +1 -0
- package/dist/ctxErr.d.ts +28 -0
- package/dist/ctxErr.d.ts.map +1 -0
- package/dist/ctxErr.js +43 -0
- package/dist/ctxErr.js.map +1 -0
- package/dist/example/api/health/healthPing.api.d.ts +14 -0
- package/dist/example/api/health/healthPing.api.d.ts.map +1 -0
- package/dist/example/api/health/healthPing.api.js +30 -0
- package/dist/example/api/health/healthPing.api.js.map +1 -0
- package/dist/example/api/health/index.d.ts +3 -0
- package/dist/example/api/health/index.d.ts.map +1 -0
- package/dist/example/api/health/index.js +43 -0
- package/dist/example/api/health/index.js.map +1 -0
- package/dist/example/api/index.d.ts +3 -0
- package/dist/example/api/index.d.ts.map +1 -0
- package/dist/example/api/index.js +39 -0
- package/dist/example/api/index.js.map +1 -0
- package/dist/example/api/user/index.d.ts +4 -0
- package/dist/example/api/user/index.d.ts.map +1 -0
- package/dist/example/api/user/index.js +50 -0
- package/dist/example/api/user/index.js.map +1 -0
- package/dist/example/api/user/userDetail.api.d.ts +15 -0
- package/dist/example/api/user/userDetail.api.d.ts.map +1 -0
- package/dist/example/api/user/userDetail.api.js +29 -0
- package/dist/example/api/user/userDetail.api.js.map +1 -0
- package/dist/example/api/user/userUpdate.api.d.ts +14 -0
- package/dist/example/api/user/userUpdate.api.d.ts.map +1 -0
- package/dist/example/api/user/userUpdate.api.js +27 -0
- package/dist/example/api/user/userUpdate.api.js.map +1 -0
- package/dist/example/express.d.ts +2 -0
- package/dist/example/express.d.ts.map +1 -0
- package/dist/example/express.js +25 -0
- package/dist/example/express.js.map +1 -0
- package/dist/example/router.d.ts +4 -0
- package/dist/example/router.d.ts.map +1 -0
- package/dist/example/router.js +51 -0
- package/dist/example/router.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/producer/express.d.ts +4 -0
- package/dist/producer/express.d.ts.map +1 -0
- package/dist/producer/express.js +22 -0
- package/dist/producer/express.js.map +1 -0
- package/dist/router.d.ts +9 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +45 -0
- package/dist/router.js.map +1 -0
- package/dist/transform.d.ts +91 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +121 -0
- package/dist/transform.js.map +1 -0
- package/dist/transformer/express.d.ts +4 -0
- package/dist/transformer/express.d.ts.map +1 -0
- package/dist/transformer/express.js +22 -0
- package/dist/transformer/express.js.map +1 -0
- package/dist/transformer/index.d.ts +91 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +121 -0
- package/dist/transformer/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/api/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIhC,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,iBAInC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ping = ping;
|
|
37
|
+
const healthPing = __importStar(require("./healthPing.api"));
|
|
38
|
+
async function ping(ctx) {
|
|
39
|
+
const { auth, validate, execute } = healthPing;
|
|
40
|
+
ctx.res.data = await auth(ctx).then(validate).then(execute);
|
|
41
|
+
return ctx;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/example/api/health/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAIC;AAND,6DAA+C;AAExC,KAAK,UAAU,IAAI,CAAC,GAAS;IAClC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAC/C,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/example/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
|
|
@@ -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 __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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.user = exports.health = void 0;
|
|
37
|
+
exports.health = __importStar(require("./health"));
|
|
38
|
+
exports.user = __importStar(require("./user"));
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/example/api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAmC;AACnC,+CAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAKhC,wBAAsB,MAAM,CAAC,GAAG,EAAE,IAAI,iBAIrC;AAED,wBAAsB,MAAM,CAAC,GAAG,EAAE,IAAI,iBAIrC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.update = update;
|
|
37
|
+
exports.detail = detail;
|
|
38
|
+
const userUpdate = __importStar(require("./userUpdate.api"));
|
|
39
|
+
const userDetail = __importStar(require("./userDetail.api"));
|
|
40
|
+
async function update(ctx) {
|
|
41
|
+
const { auth, validate, execute } = userUpdate;
|
|
42
|
+
ctx.res.data = await auth(ctx).then(validate).then(execute);
|
|
43
|
+
return ctx;
|
|
44
|
+
}
|
|
45
|
+
async function detail(ctx) {
|
|
46
|
+
const { auth, validate, execute } = userDetail;
|
|
47
|
+
ctx.res.data = await auth(ctx).then(validate).then(execute);
|
|
48
|
+
return ctx;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/example/api/user/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wBAIC;AAED,wBAIC;AAbD,6DAA+C;AAC/C,6DAA+C;AAExC,KAAK,UAAU,MAAM,CAAC,GAAS;IACpC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAC/C,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC;AAEM,KAAK,UAAU,MAAM,CAAC,GAAS;IACpC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAC/C,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TCtx } from "../../..";
|
|
2
|
+
export declare function execute(reqData: TReqData): Promise<TResData>;
|
|
3
|
+
export declare function auth(ctx: TCtx): Promise<TCtx>;
|
|
4
|
+
export declare function validate(ctx: TCtx): Promise<TReqData>;
|
|
5
|
+
type TReqData = {
|
|
6
|
+
userId: string;
|
|
7
|
+
};
|
|
8
|
+
type TResData = {
|
|
9
|
+
userDetail: {
|
|
10
|
+
userId: string;
|
|
11
|
+
userName: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=userDetail.api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userDetail.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/userDetail.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,UAAU,CAAC;AAG3C,wBAAsB,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAOlE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG3D;AAED,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,KAAK,QAAQ,GAAG;IACd,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = execute;
|
|
4
|
+
exports.auth = auth;
|
|
5
|
+
exports.validate = validate;
|
|
6
|
+
const __1 = require("../../..");
|
|
7
|
+
const ctx_err_1 = require("../../../ctx/ctx.err");
|
|
8
|
+
async function execute(reqData) {
|
|
9
|
+
return {
|
|
10
|
+
userDetail: {
|
|
11
|
+
userId: reqData.userId,
|
|
12
|
+
userName: "kaushik",
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async function auth(ctx) {
|
|
17
|
+
// authenticate the request, and return the context if the request is authenticated
|
|
18
|
+
// await authRequest(ctx);
|
|
19
|
+
if (__1.USER_ROLE.user === ctx.user.role)
|
|
20
|
+
return ctx;
|
|
21
|
+
if (__1.USER_ROLE.admin === ctx.user.role)
|
|
22
|
+
return ctx;
|
|
23
|
+
throw ctx_err_1.ctxErr.general.notAuthorized();
|
|
24
|
+
}
|
|
25
|
+
async function validate(ctx) {
|
|
26
|
+
// Validate request data and return the request data
|
|
27
|
+
return ctx.req.data;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=userDetail.api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userDetail.api.js","sourceRoot":"","sources":["../../../../src/example/api/user/userDetail.api.ts"],"names":[],"mappings":";;AAGA,0BAOC;AAED,oBAMC;AAED,4BAGC;AAvBD,gCAA2C;AAC3C,kDAA8C;AAEvC,KAAK,UAAU,OAAO,CAAC,OAAiB;IAC7C,OAAO;QACL,UAAU,EAAE;YACV,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,SAAS;SACpB;KACF,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAS;IAClC,mFAAmF;IACnF,0BAA0B;IAC1B,IAAI,aAAS,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IACjD,IAAI,aAAS,CAAC,KAAK,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IAClD,MAAM,gBAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;AACvC,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,GAAS;IACtC,oDAAoD;IACpD,OAAO,GAAG,CAAC,GAAG,CAAC,IAAgB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TCtx } from "../../..";
|
|
2
|
+
export declare function execute(reqData: TReqData): Promise<TResData>;
|
|
3
|
+
export declare function auth(ctx: TCtx): Promise<TCtx>;
|
|
4
|
+
export declare function validate(ctx: TCtx): Promise<TReqData>;
|
|
5
|
+
type TReqData = {
|
|
6
|
+
userId: string;
|
|
7
|
+
userName: string;
|
|
8
|
+
};
|
|
9
|
+
type TResData = {
|
|
10
|
+
userId: string;
|
|
11
|
+
userName: string;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=userUpdate.api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userUpdate.api.d.ts","sourceRoot":"","sources":["../../../../src/example/api/user/userUpdate.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,UAAU,CAAC;AAG3C,wBAAsB,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAKlE;AAED,wBAAsB,IAAI,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnD;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAG3D;AAED,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AACF,KAAK,QAAQ,GAAG;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = execute;
|
|
4
|
+
exports.auth = auth;
|
|
5
|
+
exports.validate = validate;
|
|
6
|
+
const __1 = require("../../..");
|
|
7
|
+
const ctx_err_1 = require("../../../ctx/ctx.err");
|
|
8
|
+
async function execute(reqData) {
|
|
9
|
+
return {
|
|
10
|
+
userId: reqData.userId,
|
|
11
|
+
userName: reqData.userName,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async function auth(ctx) {
|
|
15
|
+
// authenticate the request, and return the context if the request is authenticated
|
|
16
|
+
// await authRequest(ctx);
|
|
17
|
+
if (__1.USER_ROLE.user === ctx.user.role)
|
|
18
|
+
return ctx;
|
|
19
|
+
if (__1.USER_ROLE.admin === ctx.user.role)
|
|
20
|
+
return ctx;
|
|
21
|
+
throw ctx_err_1.ctxErr.general.notAuthorized();
|
|
22
|
+
}
|
|
23
|
+
async function validate(ctx) {
|
|
24
|
+
// Validate request data and return the request data
|
|
25
|
+
return ctx.req.data;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=userUpdate.api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userUpdate.api.js","sourceRoot":"","sources":["../../../../src/example/api/user/userUpdate.api.ts"],"names":[],"mappings":";;AAGA,0BAKC;AAED,oBAMC;AAED,4BAGC;AArBD,gCAA2C;AAC3C,kDAA8C;AAEvC,KAAK,UAAU,OAAO,CAAC,OAAiB;IAC7C,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,IAAI,CAAC,GAAS;IAClC,mFAAmF;IACnF,0BAA0B;IAC1B,IAAI,aAAS,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IACjD,IAAI,aAAS,CAAC,KAAK,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IAClD,MAAM,gBAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;AACvC,CAAC;AAEM,KAAK,UAAU,QAAQ,CAAC,GAAS;IACtC,oDAAoD;IACpD,OAAO,GAAG,CAAC,GAAG,CAAC,IAAgB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/example/express.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const express_1 = __importDefault(require("express"));
|
|
7
|
+
const __1 = require("..");
|
|
8
|
+
const router_1 = require("./router");
|
|
9
|
+
const app = (0, express_1.default)();
|
|
10
|
+
function getHttpCode(ctx) {
|
|
11
|
+
if (ctx.res.code === "OK")
|
|
12
|
+
return 200;
|
|
13
|
+
if (ctx.res.code === "UNKNOWN_ERROR")
|
|
14
|
+
return 500;
|
|
15
|
+
return 400;
|
|
16
|
+
}
|
|
17
|
+
app.all("/{*any}", async (req, res) => {
|
|
18
|
+
const ctx = __1.toCtx.fromExpress(req);
|
|
19
|
+
await router_1.router.exec(ctx.req.method, ctx.req.path, ctx);
|
|
20
|
+
res.type("application/json").status(getHttpCode(ctx)).send(ctx.res);
|
|
21
|
+
});
|
|
22
|
+
app.listen(3000, () => {
|
|
23
|
+
console.log(`Express server listening on port 3000`);
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/example/express.ts"],"names":[],"mappings":";;;;;AAAA,sDAAqD;AACrD,0BAAiC;AACjC,qCAAkC;AAElC,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AAEtB,SAAS,WAAW,CAAC,GAAS;IAC5B,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;IACtC,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,GAAG,CAAC;IACjD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;IACvD,MAAM,GAAG,GAAS,SAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,eAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACrD,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/example/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAIrC,QAAA,MAAM,MAAM,iBAAwB,CAAC;AAarC,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.router = void 0;
|
|
37
|
+
const __1 = require("..");
|
|
38
|
+
const api = __importStar(require("./api/index"));
|
|
39
|
+
// Set your router
|
|
40
|
+
const router = new __1.CtxRouter();
|
|
41
|
+
exports.router = router;
|
|
42
|
+
router.handle("GET", "/health/ping", api.health.ping);
|
|
43
|
+
router.handle("POST", "/user/update", api.user.update);
|
|
44
|
+
router.handle("GET", "/user/detail", api.user.detail);
|
|
45
|
+
router.onError(async (ctx, error) => {
|
|
46
|
+
console.error("Route error:", error);
|
|
47
|
+
ctx.res.code = "ERROR";
|
|
48
|
+
ctx.res.msg = "Something went wrong";
|
|
49
|
+
return ctx;
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/example/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0BAAqC;AACrC,iDAAmC;AAEnC,kBAAkB;AAClB,MAAM,MAAM,GAAG,IAAI,aAAS,EAAQ,CAAC;AAa5B,wBAAM;AAXf,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEtD,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IAClC,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;IACvB,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,sBAAsB,CAAC;IACrC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TCtx, USER_ROLE, IBaseApi } from "./ctx/ctx.types";
|
|
2
|
+
import { expressTransformer } from "./transformer/express";
|
|
3
|
+
import { CtxRouter } from "./ctx/ctx.router";
|
|
4
|
+
export type { TCtx, IBaseApi };
|
|
5
|
+
export { USER_ROLE, CtxRouter };
|
|
6
|
+
export declare namespace toCtx {
|
|
7
|
+
const fromExpress: typeof expressTransformer;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAEhC,yBAAiB,KAAK,CAAC;IACd,MAAM,WAAW,2BAAqB,CAAC;CAC/C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCtx = exports.CtxRouter = exports.USER_ROLE = void 0;
|
|
4
|
+
const ctx_types_1 = require("./ctx/ctx.types");
|
|
5
|
+
Object.defineProperty(exports, "USER_ROLE", { enumerable: true, get: function () { return ctx_types_1.USER_ROLE; } });
|
|
6
|
+
const express_1 = require("./transformer/express");
|
|
7
|
+
const ctx_router_1 = require("./ctx/ctx.router");
|
|
8
|
+
Object.defineProperty(exports, "CtxRouter", { enumerable: true, get: function () { return ctx_router_1.CtxRouter; } });
|
|
9
|
+
var toCtx;
|
|
10
|
+
(function (toCtx) {
|
|
11
|
+
toCtx.fromExpress = express_1.expressTransformer;
|
|
12
|
+
})(toCtx || (exports.toCtx = toCtx = {}));
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAKnD,0FALM,qBAAS,OAKN;AAJlB,mDAA2D;AAC3D,iDAA6C;AAGzB,0FAHX,sBAAS,OAGW;AAE7B,IAAiB,KAAK,CAErB;AAFD,WAAiB,KAAK;IACP,iBAAW,GAAG,4BAAkB,CAAC;AAChD,CAAC,EAFgB,KAAK,qBAAL,KAAK,QAErB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/producer/express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AASpC,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAU9C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromExpress = fromExpress;
|
|
4
|
+
const transform_1 = require("../transform");
|
|
5
|
+
function getPath(url) {
|
|
6
|
+
const queryParamPos = url.indexOf("?");
|
|
7
|
+
if (queryParamPos === -1)
|
|
8
|
+
return url;
|
|
9
|
+
return url.substring(0, queryParamPos);
|
|
10
|
+
}
|
|
11
|
+
function fromExpress(req) {
|
|
12
|
+
const ctx = (0, transform_1.buildCtx)({
|
|
13
|
+
method: req.method,
|
|
14
|
+
path: getPath(req.url),
|
|
15
|
+
header: req.headers,
|
|
16
|
+
data: req.method === "POST" ? req.body || {} : req.query || {},
|
|
17
|
+
ip: req.ip || "",
|
|
18
|
+
ips: req.ips || [],
|
|
19
|
+
});
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/producer/express.ts"],"names":[],"mappings":";;AAUA,kCAUC;AAlBD,4CAAwC;AAExC,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,aAAa,KAAK,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACrC,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,WAAW,CAAC,GAAY;IACtC,MAAM,GAAG,GAAG,IAAA,oBAAQ,EAAC;QACnB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;QACtB,MAAM,EAAE,GAAG,CAAC,OAAO;QACnB,IAAI,EAAE,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;QAC9D,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE;QAChB,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE;KACnB,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CtxError } from "./ctxErr";
|
|
2
|
+
export declare class CtxRouter<TContext> {
|
|
3
|
+
private routeObj;
|
|
4
|
+
private onErrorHandler;
|
|
5
|
+
exec(method: string, path: string, ctx: TContext): Promise<TContext>;
|
|
6
|
+
handle(method: string, path: string, handler: (ctx: TContext) => Promise<TContext>): void;
|
|
7
|
+
onError(handler: (ctx: TContext, error: CtxError | Error | unknown) => Promise<TContext>): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,QAAQ,EAAE,MAAM,UAAU,CAAC;AAO5C,qBAAa,SAAS,CAAC,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,cAAc,CAGrB;IAEK,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAc1E,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,CAAC;IAKlF,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC;CAGzF"}
|
package/dist/router.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CtxRouter = void 0;
|
|
4
|
+
const ctxErr_1 = require("./ctxErr");
|
|
5
|
+
class CtxRouter {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.routeObj = {};
|
|
8
|
+
this.onErrorHandler = async (ctx, error) => {
|
|
9
|
+
console.log("CtxError:onErrorHandler", error);
|
|
10
|
+
return ctx;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async exec(method, path, ctx) {
|
|
14
|
+
const handler = this.routeObj[method]?.[path];
|
|
15
|
+
if (!handler) {
|
|
16
|
+
throw ctxErr_1.ctxErr.general.handlerNotFound({
|
|
17
|
+
data: { method, path },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return await handler(ctx);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return await this.onErrorHandler(ctx, error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
handle(method, path, handler) {
|
|
28
|
+
const methodRoute = this.routeObj[method] || (this.routeObj[method] = {});
|
|
29
|
+
methodRoute[path] = handler;
|
|
30
|
+
}
|
|
31
|
+
onError(handler) {
|
|
32
|
+
this.onErrorHandler = handler;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.CtxRouter = CtxRouter;
|
|
36
|
+
const ctxRouter = new CtxRouter();
|
|
37
|
+
async function handler(ctx) {
|
|
38
|
+
console.log(ctx);
|
|
39
|
+
return ctx;
|
|
40
|
+
}
|
|
41
|
+
ctxRouter.handle("GET", "/", handler);
|
|
42
|
+
ctxRouter.handle("GET", "/instance/ping", handler);
|
|
43
|
+
ctxRouter.handle("GET", "/instance/health", handler);
|
|
44
|
+
ctxRouter.handle("POST", "/route/test", handler);
|
|
45
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":";;;AACA,qCAA4C;AAO5C,MAAa,SAAS;IAAtB;QACU,aAAQ,GAAwB,EAAE,CAAC;QACnC,mBAAc,GAA4E,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YACrH,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC;QACb,CAAC,CAAA;IAwBH,CAAC;IAtBC,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,IAAY,EAAE,GAAa;QACpD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,eAAM,CAAC,OAAO,CAAC,eAAe,CAAC;gBACnC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;aACvB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,IAAY,EAAE,OAA6C;QAChF,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1E,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IAC9B,CAAC;IAED,OAAO,CAAC,OAAgF;QACtF,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;IAChC,CAAC;CACF;AA7BD,8BA6BC;AAED,MAAM,SAAS,GAAG,IAAI,SAAS,EAAQ,CAAC;AACxC,KAAK,UAAU,OAAO,CAAC,GAAS;IAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AACtC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACnD,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;AACrD,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { TCtx, USER_ROLE } from "./ctx/ctx.types";
|
|
2
|
+
type TCtxBuild = {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
header: Record<string, string | string[] | undefined>;
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
ip: string;
|
|
8
|
+
ips: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function buildCtx(ctxRaw: TCtxBuild): {
|
|
11
|
+
id: string;
|
|
12
|
+
meta: {
|
|
13
|
+
serviceName: string;
|
|
14
|
+
instance: {
|
|
15
|
+
id: string;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
seq: number;
|
|
18
|
+
inflight: number;
|
|
19
|
+
};
|
|
20
|
+
ts: {
|
|
21
|
+
in: Date;
|
|
22
|
+
clientIn: Date;
|
|
23
|
+
owd: number;
|
|
24
|
+
out?: Date;
|
|
25
|
+
execTime?: number;
|
|
26
|
+
};
|
|
27
|
+
monitor: {
|
|
28
|
+
traceId: string;
|
|
29
|
+
spanId: string;
|
|
30
|
+
stdout: string[];
|
|
31
|
+
dbLog: string[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
req: {
|
|
35
|
+
header: {
|
|
36
|
+
authorization?: string;
|
|
37
|
+
"x-ctx-device-name"?: string;
|
|
38
|
+
"x-ctx-device-id"?: string;
|
|
39
|
+
"x-ctx-os"?: string;
|
|
40
|
+
"x-ctx-app-version"?: string;
|
|
41
|
+
"x-ctx-api-version"?: string;
|
|
42
|
+
"x-ctx-session-id"?: string;
|
|
43
|
+
"x-ctx-seq"?: string;
|
|
44
|
+
"x-ctx-refresh-token"?: string;
|
|
45
|
+
[key: string]: string | string[] | undefined;
|
|
46
|
+
};
|
|
47
|
+
method: string;
|
|
48
|
+
path: string;
|
|
49
|
+
data: {
|
|
50
|
+
userId?: string;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
ip: string;
|
|
54
|
+
ips: string[];
|
|
55
|
+
};
|
|
56
|
+
user: {
|
|
57
|
+
id: string;
|
|
58
|
+
role: keyof typeof USER_ROLE;
|
|
59
|
+
deviceName: string;
|
|
60
|
+
deviceId: string;
|
|
61
|
+
os: string;
|
|
62
|
+
appVersion: string;
|
|
63
|
+
sessionId: string;
|
|
64
|
+
seq: number;
|
|
65
|
+
apiVersion: string;
|
|
66
|
+
auth: {
|
|
67
|
+
token: string;
|
|
68
|
+
refresh: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
res: {
|
|
72
|
+
code: string;
|
|
73
|
+
msg: string;
|
|
74
|
+
data: {
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
};
|
|
77
|
+
meta?: {
|
|
78
|
+
ctxId: string;
|
|
79
|
+
seq: number;
|
|
80
|
+
traceId: string;
|
|
81
|
+
spanId: string;
|
|
82
|
+
inTime: Date;
|
|
83
|
+
outTime: Date;
|
|
84
|
+
execTime: number;
|
|
85
|
+
owd: number;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export declare function doneCtx(ctx: TCtx): Promise<void>;
|
|
90
|
+
export {};
|
|
91
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAalD,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACtD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS;;;;;;;;;;;;;;eAgBN,CAAA;oBAAoB,CAAC;;;;;;;;;;;yBAlC/C,CAAC;+BAAiC,CAAC;6BAE3C,CAAF;sBAAwB,CAAC;+BAAiC,CAAC;+BAGvD,CAAC;8BACG,CAAA;uBAAyB,CAAC;iCAG3B,CAAC;;;;;;kBAIK,CAAC;;;;;;;;oBA4BH,gBAEP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAlBH;AAED,wBAAsB,OAAO,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAStD"}
|