@domain.js/main 0.3.3 → 0.3.4
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/dist/http/router.d.ts +4 -4
- package/dist/http/router.js +13 -9
- package/package.json +1 -1
package/dist/http/router.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function Router(deps: Deps): {
|
|
|
20
20
|
put: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
|
|
21
21
|
del: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
|
|
22
22
|
} & {
|
|
23
|
-
collection: (res: string, _routePath?: string | undefined
|
|
23
|
+
collection: (res: string, _routePath?: string | undefined) => void;
|
|
24
24
|
model: (res: string, routePath?: string) => void;
|
|
25
25
|
resource: (res: string, routePath?: string) => void;
|
|
26
26
|
};
|
|
@@ -43,8 +43,8 @@ declare type PickResources<paths extends string, Keys extends string = PickFirst
|
|
|
43
43
|
* type t2 = PickCollection<"user", "user.addFile" | "user.Files"> // File
|
|
44
44
|
*/
|
|
45
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 ?
|
|
47
|
-
export declare type PickCollections<paths extends string, Keys extends string = PickFirst<paths>> = Keys extends any ? PickCollection<Keys, paths> : 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 ? `${Keys}::${Lowercase<Collects>}` : never : never;
|
|
47
|
+
export declare type PickCollections<paths extends string, Keys extends string = PickFirst<paths>> = Keys extends any ? PickCollection<Keys, paths> | (`${Keys}.add` | `${Keys}.list` extends paths ? Keys : never) : never;
|
|
48
48
|
/**
|
|
49
49
|
* 利用领域方法路径类型集合,收窄 methodPath, 同时可以自动提示
|
|
50
50
|
*/
|
|
@@ -52,7 +52,7 @@ export declare type NarrowDomainPaths<Paths extends string> = {
|
|
|
52
52
|
[k in normalVerb]: (routePath: NoramVerbArguments[0], ctlAct: Paths, code?: NoramVerbArguments[2], isList?: NoramVerbArguments[3], handler?: NoramVerbArguments[4], resHandler?: NoramVerbArguments[5]) => ReturnType<TRouter["get"]>;
|
|
53
53
|
} & {
|
|
54
54
|
model: (res: PickModels<Paths>, routePath?: string) => ReturnType<TRouter["model"]>;
|
|
55
|
-
collection:
|
|
55
|
+
collection: (res: PickCollections<Paths>, routePath?: string) => ReturnType<TRouter["collection"]>;
|
|
56
56
|
resource: (res: PickResources<Paths>, routePath?: string) => ReturnType<TRouter["resource"]>;
|
|
57
57
|
};
|
|
58
58
|
export {};
|
package/dist/http/router.js
CHANGED
|
@@ -153,29 +153,33 @@ function Router(deps) {
|
|
|
153
153
|
del: RouterVerbFn("del"),
|
|
154
154
|
};
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
156
|
+
* 集合方法,集合方法包含了向集合添加元素,以及查看集合(列表)
|
|
157
|
+
* @param res 资源名称,如果有父级资源用双分号隔开 eg user, user::file
|
|
158
|
+
* @param _routePath 路径地址,可选,默认按照既定规则拼接
|
|
158
159
|
*/
|
|
159
|
-
const collection = (res, _routePath
|
|
160
|
+
const collection = (res, _routePath) => {
|
|
161
|
+
const arr = res.split("::");
|
|
162
|
+
const name = arr[1] ? arr[1] : arr[0];
|
|
163
|
+
const controller = arr[1] ? arr[0] : null;
|
|
160
164
|
let routePath;
|
|
161
165
|
if (typeof _routePath !== "string") {
|
|
162
166
|
if (controller) {
|
|
163
|
-
routePath = `/${controller}s/:${controller}Id/${
|
|
167
|
+
routePath = `/${controller}s/:${controller}Id/${name}s`;
|
|
164
168
|
}
|
|
165
169
|
else {
|
|
166
|
-
routePath = `/${
|
|
170
|
+
routePath = `/${name}s`;
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
else {
|
|
170
174
|
routePath = _routePath;
|
|
171
175
|
}
|
|
172
176
|
if (controller) {
|
|
173
|
-
register("get", routePath, `${controller}.${
|
|
174
|
-
register("post", routePath, `${controller}.add${ucwords(
|
|
177
|
+
register("get", routePath, `${controller}.${name}s`, 200, true);
|
|
178
|
+
register("post", routePath, `${controller}.add${ucwords(name)}`, 201);
|
|
175
179
|
}
|
|
176
180
|
else {
|
|
177
|
-
register("get", routePath, `${
|
|
178
|
-
register("post", routePath, `${
|
|
181
|
+
register("get", routePath, `${name}.list`, 200, true);
|
|
182
|
+
register("post", routePath, `${name}.add`, 201);
|
|
179
183
|
}
|
|
180
184
|
};
|
|
181
185
|
const model = (res, routePath = `/${res}s/:id`) => {
|