@domain.js/main 0.3.2 → 0.3.3
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/.vscode/settings.json +10 -2
- package/dist/http/router.d.ts +25 -12
- package/dist/http/router.js +6 -3
- package/package.json +1 -1
package/.vscode/settings.json
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"typescript.tsdk": "node_modules/typescript/lib"
|
|
3
|
-
|
|
2
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
3
|
+
"[markdown]": {
|
|
4
|
+
"editor.quickSuggestions": true
|
|
5
|
+
},
|
|
6
|
+
"editor.quickSuggestions": {
|
|
7
|
+
"other": true,
|
|
8
|
+
"comments": true,
|
|
9
|
+
"strings": true
|
|
10
|
+
}
|
|
11
|
+
}
|
package/dist/http/router.d.ts
CHANGED
|
@@ -25,21 +25,34 @@ export declare function Router(deps: Deps): {
|
|
|
25
25
|
resource: (res: string, routePath?: string) => void;
|
|
26
26
|
};
|
|
27
27
|
declare type TRouter = ReturnType<typeof Router>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
declare type
|
|
31
|
-
/**
|
|
32
|
-
declare type
|
|
33
|
-
/**
|
|
34
|
-
|
|
28
|
+
/** 普通路径动作类型集合 */
|
|
29
|
+
declare type normalVerb = "get" | "post" | "put" | "del";
|
|
30
|
+
declare type NoramVerbArguments = Parameters<TRouter["get"]>;
|
|
31
|
+
/** 从用点分隔的字符串中提取第一部分 */
|
|
32
|
+
declare type PickFirst<paths extends string> = paths extends string ? paths extends `${infer F}.${string}` ? F : never : never;
|
|
33
|
+
/**
|
|
34
|
+
* 从 services 路径中题可能的 model 名称的联合类型
|
|
35
|
+
*/
|
|
36
|
+
declare type PickModels<paths extends string, Keys extends string = PickFirst<paths>> = Keys extends any ? `${Keys}.detail` | `${Keys}.modify` | `${Keys}.remove` extends paths ? Keys : never : never;
|
|
37
|
+
/**
|
|
38
|
+
* 从 services 路径中题可能的 resource 名称的联合类型
|
|
39
|
+
*/
|
|
40
|
+
declare type PickResources<paths extends string, Keys extends string = PickFirst<paths>> = Keys extends any ? `${Keys}.add` | `${Keys}.list` | `${Keys}.detail` | `${Keys}.modify` | `${Keys}.remove` extends paths ? Keys : never : never;
|
|
41
|
+
/**
|
|
42
|
+
* 根据指定的 controller 尝试提取存在的 collectname
|
|
43
|
+
* type t2 = PickCollection<"user", "user.addFile" | "user.Files"> // File
|
|
44
|
+
*/
|
|
45
|
+
declare type PickCollect<Keys extends string, paths extends string> = paths extends `${Keys}.add${infer A}` ? A : never;
|
|
46
|
+
declare type PickCollection<Keys extends string, paths extends string, Collects extends string = PickCollect<Keys, paths>> = Collects extends any ? `${Keys}.add${Collects}` | `${Keys}.${Lowercase<Collects>}s` extends paths ? [Lowercase<Collects>, Keys] : never : never;
|
|
47
|
+
export declare type PickCollections<paths extends string, Keys extends string = PickFirst<paths>> = Keys extends any ? PickCollection<Keys, paths> : never;
|
|
35
48
|
/**
|
|
36
49
|
* 利用领域方法路径类型集合,收窄 methodPath, 同时可以自动提示
|
|
37
50
|
*/
|
|
38
|
-
export declare type NarrowDomainPaths<Paths extends string
|
|
39
|
-
[k in
|
|
51
|
+
export declare type NarrowDomainPaths<Paths extends string> = {
|
|
52
|
+
[k in normalVerb]: (routePath: NoramVerbArguments[0], ctlAct: Paths, code?: NoramVerbArguments[2], isList?: NoramVerbArguments[3], handler?: NoramVerbArguments[4], resHandler?: NoramVerbArguments[5]) => ReturnType<TRouter["get"]>;
|
|
40
53
|
} & {
|
|
41
|
-
model:
|
|
42
|
-
collection:
|
|
43
|
-
resource:
|
|
54
|
+
model: (res: PickModels<Paths>, routePath?: string) => ReturnType<TRouter["model"]>;
|
|
55
|
+
collection: PickCollections<Paths> extends [infer R, infer C] ? (res: R, _routePath?: string, controller?: C) => ReturnType<TRouter["collection"]> : never;
|
|
56
|
+
resource: (res: PickResources<Paths>, routePath?: string) => ReturnType<TRouter["resource"]>;
|
|
44
57
|
};
|
|
45
58
|
export {};
|
package/dist/http/router.js
CHANGED
|
@@ -18,9 +18,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
21
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
25
|
exports.Router = void 0;
|
|
23
|
-
const
|
|
26
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
24
27
|
const errors = __importStar(require("restify-errors"));
|
|
25
28
|
function Router(deps) {
|
|
26
29
|
const { domain, apisRoute, utils, server, httpCodes = {}, makeProfileHook } = deps;
|
|
@@ -84,7 +87,7 @@ function Router(deps) {
|
|
|
84
87
|
throw Error(`Missing domain method: ${methodPath}`);
|
|
85
88
|
const { method } = domain[methodPath];
|
|
86
89
|
/** 如果都没有则抛出异常 */
|
|
87
|
-
if (!method || !
|
|
90
|
+
if (!method || !lodash_1.default.isFunction(method)) {
|
|
88
91
|
throw Error(`Missing domain method: ${methodPath}`);
|
|
89
92
|
}
|
|
90
93
|
server[verb](route, async (req, res, next) => {
|
|
@@ -115,7 +118,7 @@ function Router(deps) {
|
|
|
115
118
|
if (!ok)
|
|
116
119
|
res.send(code, results.rows);
|
|
117
120
|
}
|
|
118
|
-
else if (!
|
|
121
|
+
else if (!lodash_1.default.isObject(results)) {
|
|
119
122
|
if (code === 204) {
|
|
120
123
|
res.send(code);
|
|
121
124
|
}
|