@akanjs/service 0.0.28 → 0.0.30
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/package.json +50 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +3 -9
- package/src/serviceDecorators.d.ts +167 -0
- package/src/serviceDecorators.js +345 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/service",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,5 +10,54 @@
|
|
|
10
10
|
"url": "https://github.com/akan-team/akanjs.git",
|
|
11
11
|
"directory": "pkgs/@akanjs/service"
|
|
12
12
|
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@apollo/server": "^4.11.2",
|
|
15
|
+
"@inquirer/prompts": "^7.2.1",
|
|
16
|
+
"@nestjs/apollo": "^12.2.2",
|
|
17
|
+
"@nestjs/common": "^10.4.15",
|
|
18
|
+
"@nestjs/core": "^10.4.15",
|
|
19
|
+
"@nestjs/graphql": "^12.2.2",
|
|
20
|
+
"@nestjs/mongoose": "^10.1.0",
|
|
21
|
+
"@nestjs/passport": "^10.0.3",
|
|
22
|
+
"@nestjs/platform-express": "^10.4.15",
|
|
23
|
+
"@nestjs/platform-socket.io": "^10.4.15",
|
|
24
|
+
"@nestjs/schedule": "^4.1.2",
|
|
25
|
+
"@nestjs/websockets": "^10.4.15",
|
|
26
|
+
"@socket.io/redis-adapter": "^8.3.0",
|
|
27
|
+
"@urql/core": "^5.1.0",
|
|
28
|
+
"apple-signin": "^1.0.9",
|
|
29
|
+
"bull": "^4.16.5",
|
|
30
|
+
"class-transformer": "^0.5.1",
|
|
31
|
+
"class-validator": "^0.14.1",
|
|
32
|
+
"dataloader": "^2.2.3",
|
|
33
|
+
"dayjs": "^1.11.13",
|
|
34
|
+
"express": "^4.21.2",
|
|
35
|
+
"graphql": "^16.10.0",
|
|
36
|
+
"iap": "^1.1.1",
|
|
37
|
+
"immer": "^10.1.1",
|
|
38
|
+
"jsonwebtoken": "^9.0.2",
|
|
39
|
+
"lodash": "^4.17.21",
|
|
40
|
+
"meilisearch": "^0.47.0",
|
|
41
|
+
"mongoose": "^8.9.3",
|
|
42
|
+
"next": "^15.3.0",
|
|
43
|
+
"passport": "^0.7.0",
|
|
44
|
+
"passport-apple": "^2.0.2",
|
|
45
|
+
"passport-facebook": "^3.0.0",
|
|
46
|
+
"passport-github": "^1.1.0",
|
|
47
|
+
"passport-google-oauth20": "^2.0.0",
|
|
48
|
+
"passport-kakao": "^1.0.1",
|
|
49
|
+
"passport-naver": "^1.0.6",
|
|
50
|
+
"picocolors": "^1.1.1",
|
|
51
|
+
"pluralize": "^8.0.0",
|
|
52
|
+
"react": "^18.3.1",
|
|
53
|
+
"react-dom": "^18.3.1",
|
|
54
|
+
"redis": "^4.7.0",
|
|
55
|
+
"reflect-metadata": "^0.2.2",
|
|
56
|
+
"rxjs": "^7.8.1",
|
|
57
|
+
"socket.io": "^4.8.1",
|
|
58
|
+
"socket.io-client": "^4.8.1",
|
|
59
|
+
"tunnel-ssh": "^5.2.0",
|
|
60
|
+
"ua-parser-js": "^1.0.40"
|
|
61
|
+
},
|
|
13
62
|
"main": "./index.js"
|
|
14
63
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./serviceDecorators";
|
package/src/index.js
CHANGED
|
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
5
|
var __copyProps = (to, from, except, desc) => {
|
|
10
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,14 +10,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
10
|
}
|
|
15
11
|
return to;
|
|
16
12
|
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
15
|
var src_exports = {};
|
|
19
|
-
__export(src_exports, {
|
|
20
|
-
a: () => a
|
|
21
|
-
});
|
|
22
16
|
module.exports = __toCommonJS(src_exports);
|
|
23
|
-
|
|
17
|
+
__reExport(src_exports, require("./serviceDecorators"), module.exports);
|
|
24
18
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
19
|
0 && (module.exports = {
|
|
26
|
-
|
|
20
|
+
...require("./serviceDecorators")
|
|
27
21
|
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { BaseObject, Dayjs, Type } from "@akanjs/base";
|
|
3
|
+
import { Logger } from "@akanjs/common";
|
|
4
|
+
import { type DocumentModel, type FilterType, FindQueryOption, type GetActionObject, ListQueryOption, QueryOf, type SortOf } from "@akanjs/constant";
|
|
5
|
+
import type { BaseMiddleware, Database, DatabaseModel, DataInputOf } from "@akanjs/document";
|
|
6
|
+
import { FilterOutInternalArgs } from "@akanjs/signal";
|
|
7
|
+
import type { Job, Queue as BullQueue } from "bull";
|
|
8
|
+
import type { HydratedDocument } from "mongoose";
|
|
9
|
+
import type { Server } from "socket.io";
|
|
10
|
+
export type GetServices<AllSrvs extends {
|
|
11
|
+
[key: string]: Type | undefined;
|
|
12
|
+
}> = {
|
|
13
|
+
[key in keyof AllSrvs]: AllSrvs[key] extends Type<infer Srv> | undefined ? Srv : AllSrvs[key] extends Type<infer Srv> ? Srv : never;
|
|
14
|
+
};
|
|
15
|
+
export declare class ServiceStorage {
|
|
16
|
+
}
|
|
17
|
+
export interface ServiceInjectMeta {
|
|
18
|
+
type: "Db" | "Srv" | "Use" | "Queue" | "Websocket";
|
|
19
|
+
name: string;
|
|
20
|
+
key: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function Service(name: string): (target: Type) => Type;
|
|
23
|
+
export declare function Srv(name?: string): PropertyDecorator;
|
|
24
|
+
export declare function Use(name?: string): PropertyDecorator;
|
|
25
|
+
export declare function Queue(name?: string): PropertyDecorator;
|
|
26
|
+
export type Queue<Signal> = {
|
|
27
|
+
[K in keyof Signal as K extends string ? Signal[K] extends (...args: any) => Promise<{
|
|
28
|
+
__Returns__: "Done";
|
|
29
|
+
}> ? K : never : never]: Signal[K] extends (...args: infer Args) => Promise<infer R> ? (...args: FilterOutInternalArgs<Args>) => Promise<Job> : never;
|
|
30
|
+
} & BullQueue;
|
|
31
|
+
export declare function Websocket(name?: string): PropertyDecorator;
|
|
32
|
+
export type Websocket<Signal> = {
|
|
33
|
+
[K in keyof Signal as K extends string ? Signal[K] extends (...args: any) => Promise<{
|
|
34
|
+
__Returns__: "Subscribe";
|
|
35
|
+
}> ? K : Signal[K] extends (...args: any) => {
|
|
36
|
+
__Returns__: "Subscribe";
|
|
37
|
+
} ? K : never : never]: Signal[K] extends (...args: infer Args) => Promise<{
|
|
38
|
+
__Returns__: "Subscribe";
|
|
39
|
+
} & infer R> ? (...args: [...FilterOutInternalArgs<Args>, data: DocumentModel<R>]) => Promise<void> : Signal[K] extends (...args: infer Args) => {
|
|
40
|
+
__Returns__: "Subscribe";
|
|
41
|
+
} & infer R ? (...args: [...FilterOutInternalArgs<Args>, data: DocumentModel<R>]) => void : never;
|
|
42
|
+
} & {
|
|
43
|
+
server: Server;
|
|
44
|
+
};
|
|
45
|
+
export declare function Db(name: string): PropertyDecorator;
|
|
46
|
+
export declare const serviceOf: (srvRef: Type) => Type;
|
|
47
|
+
export declare function MixSrvs<T1 = unknown, T2 = unknown, T3 = unknown, T4 = unknown, T5 = unknown, T6 = unknown, T7 = unknown, T8 = unknown, T9 = unknown, T10 = unknown, T11 = unknown, T12 = unknown, T13 = unknown, T14 = unknown, T15 = unknown, T16 = unknown, T17 = unknown, T18 = unknown, T19 = unknown, T20 = unknown>(t1: Type<T1>, t2?: Type<T2>, t3?: Type<T3>, t4?: Type<T4>, t5?: Type<T5>, t6?: Type<T6>, t7?: Type<T7>, t8?: Type<T8>, t9?: Type<T9>, t10?: Type<T10>, t11?: Type<T11>, t12?: Type<T12>, t13?: Type<T13>, t14?: Type<T14>, t15?: Type<T15>, t16?: Type<T16>, t17?: Type<T17>, t18?: Type<T18>, t19?: Type<T19>, t20?: Type<T20>): Type<T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10 & T11 & T12 & T13 & T14 & T15 & T16 & T17 & T18 & T19 & T20>;
|
|
48
|
+
export declare const LogService: <T extends string>(name: T) => {
|
|
49
|
+
new (): {
|
|
50
|
+
logger: Logger;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
type QueueService<Signal> = {
|
|
54
|
+
[K in keyof Signal as K extends string ? Signal[K] extends (...args: any) => Promise<{
|
|
55
|
+
__Returns__: "Done";
|
|
56
|
+
}> ? K : never : never]: Signal[K] extends (...args: infer Args) => Promise<infer R> ? (...args: FilterOutInternalArgs<Args>) => Promise<Job> : never;
|
|
57
|
+
};
|
|
58
|
+
type DatabaseService<T extends string, Input, Doc, Obj, Model, Insight, Filter, Summary> = DatabaseServiceWithQuerySort<T, Input, Doc, Obj, Model, Insight, GetActionObject<Filter>, SortOf<Filter>>;
|
|
59
|
+
type DatabaseServiceWithQuerySort<T extends string, Input, Doc, Obj, Model, Insight, Query, Sort> = {
|
|
60
|
+
logger: Logger;
|
|
61
|
+
__databaseModel: Model;
|
|
62
|
+
__list(query?: QueryOf<Doc>, queryOption?: ListQueryOption<Sort, Obj>): Promise<Doc[]>;
|
|
63
|
+
__listIds(query?: QueryOf<Doc>, queryOption?: ListQueryOption<Sort, Obj>): Promise<string[]>;
|
|
64
|
+
__find(query?: QueryOf<Doc>, queryOption?: FindQueryOption<Sort, Obj>): Promise<Doc | null>;
|
|
65
|
+
__findId(query?: QueryOf<Doc>, queryOption?: FindQueryOption<Sort, Obj>): Promise<string | null>;
|
|
66
|
+
__pick(query?: QueryOf<Doc>, queryOption?: FindQueryOption<Sort, Obj>): Promise<Doc>;
|
|
67
|
+
__pickId(query?: QueryOf<Doc>, queryOption?: FindQueryOption<Sort, Obj>): Promise<string>;
|
|
68
|
+
__exists(query?: QueryOf<Doc>): Promise<string | null>;
|
|
69
|
+
__count(query?: QueryOf<Doc>): Promise<number>;
|
|
70
|
+
__insight(query?: QueryOf<Doc>): Promise<Insight>;
|
|
71
|
+
__search(query: QueryOf<Doc>, queryOption?: ListQueryOption<Sort, Obj>): Promise<{
|
|
72
|
+
docs: Doc[];
|
|
73
|
+
count: number;
|
|
74
|
+
}>;
|
|
75
|
+
__searchDocs(query: QueryOf<Doc>, queryOption?: ListQueryOption<Sort, Obj>): Promise<Doc[]>;
|
|
76
|
+
__searchCount(query: QueryOf<Doc>): Promise<number>;
|
|
77
|
+
_preCreate(data: DataInputOf<Input, Doc>): Promise<DataInputOf<Input, Doc>> | DataInputOf<Input, Doc>;
|
|
78
|
+
_postCreate(doc: Doc): Promise<Doc> | Doc;
|
|
79
|
+
_preUpdate(id: string, data: Partial<Doc>): Promise<Partial<Doc>> | Partial<Doc>;
|
|
80
|
+
_postUpdate(doc: Doc): Promise<Doc> | Doc;
|
|
81
|
+
_preRemove(id: string): Promise<void> | void;
|
|
82
|
+
_postRemove(doc: Doc): Promise<Doc> | Doc;
|
|
83
|
+
} & {
|
|
84
|
+
[key in `${T}Model`]: Model;
|
|
85
|
+
} & {
|
|
86
|
+
[K in `get${Capitalize<T>}`]: (id: string) => Promise<Doc>;
|
|
87
|
+
} & {
|
|
88
|
+
[K in `load${Capitalize<T>}`]: (id?: string) => Promise<Doc | null>;
|
|
89
|
+
} & {
|
|
90
|
+
[K in `load${Capitalize<T>}Many`]: (ids: string[]) => Promise<Doc[]>;
|
|
91
|
+
} & {
|
|
92
|
+
[K in `create${Capitalize<T>}`]: (data: DataInputOf<Input, Doc>) => Promise<Doc>;
|
|
93
|
+
} & {
|
|
94
|
+
[K in `update${Capitalize<T>}`]: (id: string, data: Partial<Doc>) => Promise<Doc>;
|
|
95
|
+
} & {
|
|
96
|
+
[K in `remove${Capitalize<T>}`]: (id: string) => Promise<Doc>;
|
|
97
|
+
} & {
|
|
98
|
+
[K in `search${Capitalize<T>}`]: (searchText: string, queryOption?: ListQueryOption<Sort, Obj>) => Promise<{
|
|
99
|
+
docs: Doc[];
|
|
100
|
+
count: number;
|
|
101
|
+
}>;
|
|
102
|
+
} & {
|
|
103
|
+
[K in `searchDocs${Capitalize<T>}`]: (searchText: string, queryOption?: ListQueryOption<Sort, Obj>) => Promise<Doc[]>;
|
|
104
|
+
} & {
|
|
105
|
+
[K in `searchCount${Capitalize<T>}`]: (searchText: string) => Promise<number>;
|
|
106
|
+
} & {
|
|
107
|
+
[K in keyof Query as K extends string ? `list${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args, queryOption?: ListQueryOption<Sort, Obj>]) => Promise<Doc[]> : never;
|
|
108
|
+
} & {
|
|
109
|
+
[K in keyof Query as K extends string ? `listIds${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args, queryOption?: ListQueryOption<Sort, Obj>]) => Promise<string[]> : never;
|
|
110
|
+
} & {
|
|
111
|
+
[K in keyof Query as K extends string ? `find${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args, queryOption?: FindQueryOption<Sort, Obj>]) => Promise<Doc | null> : never;
|
|
112
|
+
} & {
|
|
113
|
+
[K in keyof Query as K extends string ? `findId${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args, queryOption?: FindQueryOption<Sort, Obj>]) => Promise<string | null> : never;
|
|
114
|
+
} & {
|
|
115
|
+
[K in keyof Query as K extends string ? `pick${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args, queryOption?: FindQueryOption<Sort, Obj>]) => Promise<Doc> : never;
|
|
116
|
+
} & {
|
|
117
|
+
[K in keyof Query as K extends string ? `pickId${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args, queryOption?: FindQueryOption<Sort, Obj>]) => Promise<string> : never;
|
|
118
|
+
} & {
|
|
119
|
+
[K in keyof Query as K extends string ? `exists${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args]) => Promise<string | null> : never;
|
|
120
|
+
} & {
|
|
121
|
+
[K in keyof Query as K extends string ? `count${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args]) => Promise<number> : never;
|
|
122
|
+
} & {
|
|
123
|
+
[K in keyof Query as K extends string ? `insight${Capitalize<K>}` : never]: Query[K] extends (...args: infer Args) => any ? (...args: [...Args]) => Promise<Insight> : never;
|
|
124
|
+
};
|
|
125
|
+
export declare const DbService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, Summary>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, sigRef?: Type<Signal>) => Type<DatabaseService<T, Input, Doc, Obj, Model, Insight, Filter, Summary>>;
|
|
126
|
+
export declare const ExtendedUserService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, Summary>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Srv, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, srvRef: Type<Srv>, sigRef?: Type<Signal>) => Type<DatabaseService<T, Input, Doc, BaseObject & {
|
|
127
|
+
nickname: string;
|
|
128
|
+
}, Model, Insight, Filter, Summary> & {
|
|
129
|
+
queue: QueueService<Signal>;
|
|
130
|
+
} & { [K in keyof Srv]: Srv[K] extends (...args: infer Args) => Promise<BaseObject & {
|
|
131
|
+
nickname: string;
|
|
132
|
+
}> ? (...args: Args) => Promise<Doc> : Srv[K] extends (...args: infer Args) => Promise<(BaseObject & {
|
|
133
|
+
nickname: string;
|
|
134
|
+
})[]> ? (...args: Args) => Promise<Doc[]> : Srv[K] extends BaseObject & {
|
|
135
|
+
nickname: string;
|
|
136
|
+
} ? Doc : Srv[K] extends (BaseObject & {
|
|
137
|
+
nickname: string;
|
|
138
|
+
})[] ? Doc[] : Srv[K]; }>;
|
|
139
|
+
export declare const ExtendedSummaryService: <T extends string, Input, Doc extends HydratedDocument<any>, Model, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Srv, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, srvRef: Type<Srv>, sigRef?: Type<Signal>) => Type<Omit<DatabaseService<T, Input, Doc, Obj, Model, Insight, Filter, Summary> & {
|
|
140
|
+
queue: QueueService<Signal>;
|
|
141
|
+
} & { [K in keyof Srv]: Srv[K] extends (...args: infer Args) => Promise<BaseObject & {
|
|
142
|
+
type: string;
|
|
143
|
+
at: Dayjs;
|
|
144
|
+
}> ? (...args: Args) => Promise<Doc> : Srv[K] extends (...args: infer Args) => Promise<(BaseObject & {
|
|
145
|
+
type: string;
|
|
146
|
+
at: Dayjs;
|
|
147
|
+
})[]> ? (...args: Args) => Promise<Doc[]> : Srv[K] extends BaseObject & {
|
|
148
|
+
type: string;
|
|
149
|
+
at: Dayjs;
|
|
150
|
+
} ? Doc : Srv[K] extends (BaseObject & {
|
|
151
|
+
type: string;
|
|
152
|
+
at: Dayjs;
|
|
153
|
+
})[] ? Doc[] : Srv[K]; }, "userService">>;
|
|
154
|
+
export declare const ExtendedSettingService: <T extends string, Input, Doc extends HydratedDocument<any>, Model extends DatabaseModel<T, Input, Doc, Obj, Insight, Filter, Summary>, Middleware extends BaseMiddleware, Obj, Insight, Filter extends FilterType, Summary, Srv, Signal = unknown>(database: Database<T, Input, Doc, Model, Middleware, Obj, Insight, Filter, Summary>, srvRef: Type<Srv>, sigRef?: Type<Signal>) => Type<DatabaseService<T, Input, Doc, BaseObject & {
|
|
155
|
+
resignupDays: number;
|
|
156
|
+
}, Model, Insight, Filter, Summary> & {
|
|
157
|
+
queue: QueueService<Signal>;
|
|
158
|
+
} & { [K in keyof Srv]: Srv[K] extends (...args: infer Args) => Promise<BaseObject & {
|
|
159
|
+
resignupDays: number;
|
|
160
|
+
}> ? (...args: Args) => Promise<Doc> : Srv[K] extends (...args: infer Args) => Promise<(BaseObject & {
|
|
161
|
+
resignupDays: number;
|
|
162
|
+
})[]> ? (...args: Args) => Promise<Doc[]> : Srv[K] extends BaseObject & {
|
|
163
|
+
resignupDays: number;
|
|
164
|
+
} ? Doc : Srv[K] extends (BaseObject & {
|
|
165
|
+
resignupDays: number;
|
|
166
|
+
})[] ? Doc[] : Srv[K]; }>;
|
|
167
|
+
export {};
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
+
if (decorator = decorators[i])
|
|
22
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
+
if (kind && result)
|
|
24
|
+
__defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var serviceDecorators_exports = {};
|
|
28
|
+
__export(serviceDecorators_exports, {
|
|
29
|
+
Db: () => Db,
|
|
30
|
+
DbService: () => DbService,
|
|
31
|
+
ExtendedSettingService: () => ExtendedSettingService,
|
|
32
|
+
ExtendedSummaryService: () => ExtendedSummaryService,
|
|
33
|
+
ExtendedUserService: () => ExtendedUserService,
|
|
34
|
+
LogService: () => LogService,
|
|
35
|
+
MixSrvs: () => MixSrvs,
|
|
36
|
+
Queue: () => Queue,
|
|
37
|
+
Service: () => Service,
|
|
38
|
+
ServiceStorage: () => ServiceStorage,
|
|
39
|
+
Srv: () => Srv,
|
|
40
|
+
Use: () => Use,
|
|
41
|
+
Websocket: () => Websocket,
|
|
42
|
+
serviceOf: () => serviceOf
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(serviceDecorators_exports);
|
|
45
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
46
|
+
var import_common = require("@akanjs/common");
|
|
47
|
+
var import_constant = require("@akanjs/constant");
|
|
48
|
+
var import_common2 = require("@nestjs/common");
|
|
49
|
+
var import_mongoose = require("@nestjs/mongoose");
|
|
50
|
+
class ServiceStorage {
|
|
51
|
+
}
|
|
52
|
+
const getServiceRefs = (refName) => {
|
|
53
|
+
return Reflect.getMetadata(refName, ServiceStorage.prototype) ?? [];
|
|
54
|
+
};
|
|
55
|
+
const setServiceRefs = (refName, services) => {
|
|
56
|
+
Reflect.defineMetadata(refName, services, ServiceStorage.prototype);
|
|
57
|
+
};
|
|
58
|
+
const isServiceDefined = (srvRef) => {
|
|
59
|
+
return Reflect.getMetadata("service", srvRef.prototype) ?? false;
|
|
60
|
+
};
|
|
61
|
+
const setServiceDefined = (srvRef) => {
|
|
62
|
+
Reflect.defineMetadata("service", true, srvRef.prototype);
|
|
63
|
+
};
|
|
64
|
+
const getServiceInjectMetaMapOnPrototype = (prototype) => {
|
|
65
|
+
return Reflect.getMetadata("inject", prototype) ?? /* @__PURE__ */ new Map();
|
|
66
|
+
};
|
|
67
|
+
const setServiceInjectMetaMapOnPrototype = (prototype, injectMetaMap) => {
|
|
68
|
+
Reflect.defineMetadata("inject", injectMetaMap, prototype);
|
|
69
|
+
};
|
|
70
|
+
function Service(name) {
|
|
71
|
+
return function(target) {
|
|
72
|
+
const services = getServiceRefs(name);
|
|
73
|
+
setServiceRefs(name, [...services, target]);
|
|
74
|
+
Reflect.defineMetadata(name, [...services, target], ServiceStorage.prototype);
|
|
75
|
+
return target;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function Srv(name) {
|
|
79
|
+
return function(prototype, key) {
|
|
80
|
+
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
81
|
+
metadataMap.set(key, { type: "Srv", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
82
|
+
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function Use(name) {
|
|
86
|
+
return function(prototype, key) {
|
|
87
|
+
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
88
|
+
metadataMap.set(key, { type: "Use", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
89
|
+
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function Queue(name) {
|
|
93
|
+
return function(prototype, key) {
|
|
94
|
+
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
95
|
+
metadataMap.set(key, { type: "Queue", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
96
|
+
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function Websocket(name) {
|
|
100
|
+
return function(prototype, key) {
|
|
101
|
+
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
102
|
+
metadataMap.set(key, { type: "Websocket", key, name: name ?? (0, import_common.capitalize)(key) });
|
|
103
|
+
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function Db(name) {
|
|
107
|
+
return function(prototype, key) {
|
|
108
|
+
const metadataMap = getServiceInjectMetaMapOnPrototype(prototype);
|
|
109
|
+
metadataMap.set(key, { type: "Db", key, name });
|
|
110
|
+
setServiceInjectMetaMapOnPrototype(prototype, metadataMap);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const serviceOf = (srvRef) => {
|
|
114
|
+
if (isServiceDefined(srvRef))
|
|
115
|
+
return srvRef;
|
|
116
|
+
const injectMetaMap = getServiceInjectMetaMapOnPrototype(srvRef.prototype);
|
|
117
|
+
for (const injectMeta of [...injectMetaMap.values()]) {
|
|
118
|
+
if (injectMeta.type === "Db")
|
|
119
|
+
(0, import_mongoose.InjectModel)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
120
|
+
else if (injectMeta.type === "Use")
|
|
121
|
+
(0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
122
|
+
else if (injectMeta.type === "Srv") {
|
|
123
|
+
const services = getServiceRefs(injectMeta.name);
|
|
124
|
+
if (!services.length)
|
|
125
|
+
throw new Error(`Service ${injectMeta.name} not found`);
|
|
126
|
+
(0, import_common2.Inject)(services.at(-1))(srvRef.prototype, injectMeta.key);
|
|
127
|
+
} else if (injectMeta.type === "Queue")
|
|
128
|
+
(0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
129
|
+
else
|
|
130
|
+
(0, import_common2.Inject)(injectMeta.name)(srvRef.prototype, injectMeta.key);
|
|
131
|
+
}
|
|
132
|
+
(0, import_mongoose.InjectConnection)()(srvRef.prototype, "connection");
|
|
133
|
+
(0, import_common2.Injectable)()(srvRef);
|
|
134
|
+
setServiceDefined(srvRef);
|
|
135
|
+
return srvRef;
|
|
136
|
+
};
|
|
137
|
+
function MixSrvs(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20) {
|
|
138
|
+
class Mix extends t1 {
|
|
139
|
+
}
|
|
140
|
+
const injectMetadataMap = new Map(
|
|
141
|
+
[t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20].filter((t) => !!t).reduce((acc, srvRef) => {
|
|
142
|
+
const injectMetadataMap2 = getServiceInjectMetaMapOnPrototype(srvRef);
|
|
143
|
+
(0, import_common.applyMixins)(Mix, [srvRef]);
|
|
144
|
+
return [...acc, ...injectMetadataMap2];
|
|
145
|
+
}, [])
|
|
146
|
+
);
|
|
147
|
+
Reflect.defineMetadata("service", false, Mix.prototype);
|
|
148
|
+
Reflect.defineMetadata("inject", injectMetadataMap, Mix.prototype);
|
|
149
|
+
return Mix;
|
|
150
|
+
}
|
|
151
|
+
const LogService = (name) => {
|
|
152
|
+
class LogService2 {
|
|
153
|
+
logger = new import_common.Logger(name);
|
|
154
|
+
}
|
|
155
|
+
return LogService2;
|
|
156
|
+
};
|
|
157
|
+
const DbService = (database, sigRef) => {
|
|
158
|
+
const [modelName, className] = [database.refName, (0, import_common.capitalize)(database.refName)];
|
|
159
|
+
class DbService2 {
|
|
160
|
+
logger = new import_common.Logger(`${modelName}Service`);
|
|
161
|
+
__databaseModel;
|
|
162
|
+
async __list(query, queryOption) {
|
|
163
|
+
return await this.__databaseModel.__list(query, queryOption);
|
|
164
|
+
}
|
|
165
|
+
async __listIds(query, queryOption) {
|
|
166
|
+
return await this.__databaseModel.__listIds(query, queryOption);
|
|
167
|
+
}
|
|
168
|
+
async __find(query, queryOption) {
|
|
169
|
+
return await this.__databaseModel.__find(query, queryOption);
|
|
170
|
+
}
|
|
171
|
+
async __findId(query, queryOption) {
|
|
172
|
+
return await this.__databaseModel.__findId(query, queryOption);
|
|
173
|
+
}
|
|
174
|
+
async __pick(query, queryOption) {
|
|
175
|
+
return await this.__databaseModel.__pick(query, queryOption);
|
|
176
|
+
}
|
|
177
|
+
async __pickId(query, queryOption) {
|
|
178
|
+
return await this.__databaseModel.__pickId(query, queryOption);
|
|
179
|
+
}
|
|
180
|
+
async __exists(query) {
|
|
181
|
+
return await this.__databaseModel.__exists(query);
|
|
182
|
+
}
|
|
183
|
+
async __count(query) {
|
|
184
|
+
return await this.__databaseModel.__count(query);
|
|
185
|
+
}
|
|
186
|
+
async __insight(query) {
|
|
187
|
+
return await this.__databaseModel.__insight(query);
|
|
188
|
+
}
|
|
189
|
+
async __search(searchText, queryOption) {
|
|
190
|
+
return await this.__databaseModel[`search${className}`](searchText, queryOption);
|
|
191
|
+
}
|
|
192
|
+
async __searchDocs(searchText, queryOption) {
|
|
193
|
+
return await this.__databaseModel[`searchDocs${className}`](searchText, queryOption);
|
|
194
|
+
}
|
|
195
|
+
async __searchCount(searchText) {
|
|
196
|
+
return await this.__databaseModel[`searchCount${className}`](searchText);
|
|
197
|
+
}
|
|
198
|
+
async _preCreate(data) {
|
|
199
|
+
return data;
|
|
200
|
+
}
|
|
201
|
+
async _postCreate(doc) {
|
|
202
|
+
return doc;
|
|
203
|
+
}
|
|
204
|
+
async _preUpdate(id, data) {
|
|
205
|
+
return data;
|
|
206
|
+
}
|
|
207
|
+
async _postUpdate(doc) {
|
|
208
|
+
return doc;
|
|
209
|
+
}
|
|
210
|
+
async _preRemove(id) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
async _postRemove(doc) {
|
|
214
|
+
return doc;
|
|
215
|
+
}
|
|
216
|
+
async [`get${className}`](id) {
|
|
217
|
+
return await this.__databaseModel[`get${className}`](id);
|
|
218
|
+
}
|
|
219
|
+
async [`load${className}`](id) {
|
|
220
|
+
return await this.__databaseModel[`load${className}`](id);
|
|
221
|
+
}
|
|
222
|
+
async [`load${className}Many`](ids) {
|
|
223
|
+
return await this.__databaseModel[`load${className}Many`](ids);
|
|
224
|
+
}
|
|
225
|
+
async [`create${className}`](data) {
|
|
226
|
+
const input = await this._preCreate(data);
|
|
227
|
+
const doc = await this.__databaseModel[`create${className}`](input);
|
|
228
|
+
return await this._postCreate(doc);
|
|
229
|
+
}
|
|
230
|
+
async [`update${className}`](id, data) {
|
|
231
|
+
const input = await this._preUpdate(id, data);
|
|
232
|
+
const doc = await this.__databaseModel[`update${className}`](id, input);
|
|
233
|
+
return await this._postUpdate(doc);
|
|
234
|
+
}
|
|
235
|
+
async [`remove${className}`](id) {
|
|
236
|
+
await this._preRemove(id);
|
|
237
|
+
const doc = await this.__databaseModel[`remove${className}`](id);
|
|
238
|
+
return await this._postRemove(doc);
|
|
239
|
+
}
|
|
240
|
+
async [`search${className}`](query, queryOption) {
|
|
241
|
+
return await this.__databaseModel[`search${className}`](query, queryOption);
|
|
242
|
+
}
|
|
243
|
+
async [`searchDocs${className}`](query, queryOption) {
|
|
244
|
+
return await this.__databaseModel[`searchDocs${className}`](query, queryOption);
|
|
245
|
+
}
|
|
246
|
+
async [`searchCount${className}`](query) {
|
|
247
|
+
return await this.__databaseModel[`searchCount${className}`](query);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
__decorateClass([
|
|
251
|
+
Use(`${modelName}Model`)
|
|
252
|
+
], DbService2.prototype, "__databaseModel", 2);
|
|
253
|
+
const getQueryDataFromKey = (queryKey, args) => {
|
|
254
|
+
const lastArg = args.at(-1);
|
|
255
|
+
const hasQueryOption = lastArg && typeof lastArg === "object" && (typeof lastArg.select === "object" || typeof lastArg.skip === "number" || typeof lastArg.limit === "number" || typeof lastArg.sort === "string");
|
|
256
|
+
const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
|
|
257
|
+
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
258
|
+
const queryOption = hasQueryOption ? lastArg : {};
|
|
259
|
+
return { query, queryOption };
|
|
260
|
+
};
|
|
261
|
+
const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
|
|
262
|
+
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
263
|
+
queryKeys.forEach((queryKey) => {
|
|
264
|
+
const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
|
|
265
|
+
DbService2.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
266
|
+
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
267
|
+
return this.__list(query, queryOption);
|
|
268
|
+
};
|
|
269
|
+
DbService2.prototype[`listIds${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
270
|
+
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
271
|
+
return this.__listIds(query, queryOption);
|
|
272
|
+
};
|
|
273
|
+
DbService2.prototype[`find${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
274
|
+
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
275
|
+
return this.__find(query, queryOption);
|
|
276
|
+
};
|
|
277
|
+
DbService2.prototype[`findId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
278
|
+
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
279
|
+
return this.__findId(query, queryOption);
|
|
280
|
+
};
|
|
281
|
+
DbService2.prototype[`pick${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
282
|
+
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
283
|
+
return this.__pick(query, queryOption);
|
|
284
|
+
};
|
|
285
|
+
DbService2.prototype[`pickId${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
286
|
+
const { query, queryOption } = getQueryDataFromKey(queryKey, args);
|
|
287
|
+
return this.__pickId(query, queryOption);
|
|
288
|
+
};
|
|
289
|
+
DbService2.prototype[`exists${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
290
|
+
const query = queryFn(...args);
|
|
291
|
+
return this.__exists(query);
|
|
292
|
+
};
|
|
293
|
+
DbService2.prototype[`count${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
294
|
+
const query = queryFn(...args);
|
|
295
|
+
return this.__count(query);
|
|
296
|
+
};
|
|
297
|
+
DbService2.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
298
|
+
const query = queryFn(...args);
|
|
299
|
+
return this.__insight(query);
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
Use(`${modelName}Model`)(DbService2.prototype, `${modelName}Model`);
|
|
303
|
+
return DbService2;
|
|
304
|
+
};
|
|
305
|
+
const ExtendedUserService = (database, srvRef, sigRef) => {
|
|
306
|
+
const filterKeyMetaMap = (0, import_constant.getFilterKeyMetaMapOnPrototype)(database.Filter.prototype);
|
|
307
|
+
const queryKeys = [...filterKeyMetaMap.keys()];
|
|
308
|
+
queryKeys.forEach((queryKey) => {
|
|
309
|
+
const queryFn = (0, import_constant.getFilterQuery)(database.Filter, queryKey);
|
|
310
|
+
srvRef.prototype[`list${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
311
|
+
const queryOption = args.at(-1);
|
|
312
|
+
const hasQueryOption = typeof queryOption === "object" && (typeof queryOption.select === "object" || typeof queryOption.skip === "number" || typeof queryOption.limit === "number" || typeof queryOption.sort === "string");
|
|
313
|
+
const query = queryFn(...hasQueryOption ? args.slice(0, -1) : args);
|
|
314
|
+
return this.__list(query, queryOption);
|
|
315
|
+
};
|
|
316
|
+
srvRef.prototype[`insight${(0, import_common.capitalize)(queryKey)}`] = async function(...args) {
|
|
317
|
+
const query = queryFn(...args);
|
|
318
|
+
return this.__insight(query);
|
|
319
|
+
};
|
|
320
|
+
});
|
|
321
|
+
return srvRef;
|
|
322
|
+
};
|
|
323
|
+
const ExtendedSummaryService = (database, srvRef, sigRef) => {
|
|
324
|
+
return srvRef;
|
|
325
|
+
};
|
|
326
|
+
const ExtendedSettingService = (database, srvRef, sigRef) => {
|
|
327
|
+
return srvRef;
|
|
328
|
+
};
|
|
329
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
330
|
+
0 && (module.exports = {
|
|
331
|
+
Db,
|
|
332
|
+
DbService,
|
|
333
|
+
ExtendedSettingService,
|
|
334
|
+
ExtendedSummaryService,
|
|
335
|
+
ExtendedUserService,
|
|
336
|
+
LogService,
|
|
337
|
+
MixSrvs,
|
|
338
|
+
Queue,
|
|
339
|
+
Service,
|
|
340
|
+
ServiceStorage,
|
|
341
|
+
Srv,
|
|
342
|
+
Use,
|
|
343
|
+
Websocket,
|
|
344
|
+
serviceOf
|
|
345
|
+
});
|