perf
This commit is contained in:
parent
aeeb205e1e
commit
51dafe0f9a
@ -70,6 +70,18 @@ class Chain {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class QueryChain {
|
||||||
|
obj: SimpleObject = {};
|
||||||
|
constructor(value?: SimpleObject, opts?: SimpleObject) {
|
||||||
|
this.obj = value || {};
|
||||||
|
}
|
||||||
|
get(queryData?: Record<string, any>): Pick<RouteOpts, 'path' | 'key' | 'metadata' | 'description' | 'validator'> {
|
||||||
|
return {
|
||||||
|
...this.obj,
|
||||||
|
...queryData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
export const util = {
|
export const util = {
|
||||||
getChain: (obj: RouteOpts, opts?: ChainOptions) => {
|
getChain: (obj: RouteOpts, opts?: ChainOptions) => {
|
||||||
return new Chain(obj, opts);
|
return new Chain(obj, opts);
|
||||||
@ -77,10 +89,10 @@ export const util = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class QueryUtil<T extends RouteObject = RouteObject> {
|
export class QueryUtil<T extends RouteObject = RouteObject> {
|
||||||
routeObject: T;
|
obj: T;
|
||||||
app: QueryRouterServer;
|
app: QueryRouterServer;
|
||||||
constructor(object: T, opts?: ChainOptions) {
|
constructor(object: T, opts?: ChainOptions) {
|
||||||
this.routeObject = object;
|
this.obj = object;
|
||||||
this.app = opts?.app;
|
this.app = opts?.app;
|
||||||
}
|
}
|
||||||
static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions) {
|
static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions) {
|
||||||
@ -91,20 +103,18 @@ export class QueryUtil<T extends RouteObject = RouteObject> {
|
|||||||
return new QueryUtil<U>(obj, opts);
|
return new QueryUtil<U>(obj, opts);
|
||||||
}
|
}
|
||||||
get<K extends keyof T>(key: K): RouteOpts {
|
get<K extends keyof T>(key: K): RouteOpts {
|
||||||
return this.routeObject[key] as RouteOpts;
|
return this.obj[key] as RouteOpts;
|
||||||
}
|
}
|
||||||
chain<K extends keyof T>(key: K, opts?: ChainOptions) {
|
chain<K extends keyof T>(key: K, opts?: ChainOptions) {
|
||||||
const obj = this.routeObject[key];
|
const obj = this.obj[key];
|
||||||
let newOpts = { app: this.app, ...opts };
|
let newOpts = { app: this.app, ...opts };
|
||||||
return new Chain(obj, newOpts);
|
return new Chain(obj, newOpts);
|
||||||
}
|
}
|
||||||
queryChain<K extends keyof T>(key: K): (queryData?: Record<string, any>) => RouteOpts {
|
queryChain<K extends keyof T>(key: K) {
|
||||||
const value = this.routeObject[key];
|
const value = this.obj[key];
|
||||||
return (queryData?: Record<string, any>) => {
|
return new QueryChain(value);
|
||||||
return {
|
}
|
||||||
...value,
|
get routeObject() {
|
||||||
...queryData,
|
return this.obj;
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user