onecore 0.6.0 → 0.6.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/formatter.ts CHANGED
@@ -24,8 +24,8 @@ export interface LocaleStringFormatter<T> {
24
24
  format(obj: T, locale: Locale): string;
25
25
  }
26
26
 
27
- export interface Formatter<T> {
28
- format(obj: T): T;
27
+ export interface Formatter<T, S> {
28
+ format(obj: T): S;
29
29
  }
30
30
  export interface LocaleFormatter<T> {
31
31
  format(obj: T, locale: Locale): T;
package/src/index.ts CHANGED
@@ -6,6 +6,10 @@ export * from './cache';
6
6
  export * from './validator';
7
7
  export * from './loader';
8
8
  export * from './model';
9
+ export * from './health';
10
+ export * from './logger';
11
+
12
+ export * from './io';
9
13
 
10
14
  import { GenericRepository, SearchRepository, GenericSearchRepository, Transaction } from './db';
11
15
  import { GenericSearchService, GenericService } from './service';
@@ -22,9 +26,8 @@ export * from './mail/model/ASMOptions';
22
26
  export * from './mail/config';
23
27
 
24
28
  export * from './location';
29
+ export * from './job';
25
30
  export * from './video';
26
- export * from './health';
27
- export * from './logger';
28
31
 
29
32
  export type DeleteFile = (name: string, directory?: string) => Promise<boolean>;
30
33
  export type Delete = (delFile: DeleteFile, url: string) => Promise<boolean>;
package/src/io.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { ErrorMessage } from "./model"
2
+
3
+ export interface Parser<T, S> {
4
+ parse: (data: S) => Promise<T>
5
+ }
6
+ export interface Transformer<T, S> {
7
+ transform: (data: S) => Promise<T>
8
+ }
9
+
10
+ export interface CSVFieldParser<T> {
11
+ name: string
12
+ toString(data: T, key: string, v: string): void
13
+ }
14
+ export interface FixedLengthFieldParser<T> {
15
+ name: string
16
+ length: number
17
+ parse(data: T, key: string, v: string): void
18
+ }
19
+
20
+ export interface Writer<T> {
21
+ write: (obj: T) => Promise<number>
22
+ flush?: () => Promise<number>
23
+ }
24
+ export interface ErrorHandler<T> {
25
+ handleError(rs: T, errors: ErrorMessage[], i?: number, filename?: string): void
26
+ }
27
+ export interface ExceptionHandler<S> {
28
+ handleException(res: S, err: any, i?: number, filename?: string): void
29
+ }
package/src/job.ts ADDED
@@ -0,0 +1,172 @@
1
+ import { DateRange, Filter, SearchResult, TimeRange } from "./model";
2
+
3
+ export interface Attachment {
4
+ originalFilename: string;
5
+ filename: string;
6
+ url: string;
7
+ size: number;
8
+ }
9
+
10
+ export interface Article {
11
+ id: string
12
+ slug: string
13
+ title: string
14
+ description?: string
15
+ publishedAt?: Date
16
+ tags?: string[]
17
+ thumbnail?: string
18
+ status?: string
19
+ createdAt?: Date
20
+ authorId?: string
21
+ savedAt?: Date
22
+ }
23
+ export interface ArticleFilter extends Filter {
24
+ id?: string
25
+ slug?: string
26
+ title?: string
27
+ description?: string
28
+ status?: string
29
+ publishedAt: TimeRange
30
+ tags?: string[]
31
+ authorId?: string
32
+ userId?: string
33
+ isSaved?: boolean
34
+ }
35
+ export interface ArticleRepository {
36
+ search(filter: ArticleFilter, limit: number, page?: number, fields?: string[]): Promise<SearchResult<Article>>
37
+ load(slug: string, userId?: string): Promise<Article | null>
38
+ getIdBySlug(slug: string): Promise<string>
39
+ }
40
+
41
+ export interface Achievement {
42
+ subject: string;
43
+ description: string;
44
+ }
45
+ export interface Skill {
46
+ skill: string;
47
+ hirable: boolean;
48
+ }
49
+ export interface UserFilter extends Filter {
50
+ userId?: string;
51
+ username?: string;
52
+ email?: string;
53
+ displayName?: string;
54
+ dateOfBirth?: DateRange;
55
+ status?: string[]|string;
56
+ interests?: string[];
57
+ skills?: Skill[];
58
+ achievements?: Achievement[];
59
+ }
60
+ export interface RoleFilter extends Filter {
61
+ roleId?: string;
62
+ roleName?: string;
63
+ status?: string[]|string;
64
+ remark?: string;
65
+ description?: string;
66
+ }
67
+
68
+ export interface ReviewComment {
69
+ commentId: string;
70
+ id: string;
71
+ author: string;
72
+ userId: string;
73
+ comment: string;
74
+ time: Date;
75
+ updatedAt?: Date;
76
+ histories?: ShortComment[];
77
+ userURL?: string;
78
+ authorURL?: string;
79
+ }
80
+ export interface ShortComment {
81
+ comment: string;
82
+ time: Date;
83
+ }
84
+
85
+ export interface ReviewCommentFilter extends Filter {
86
+ commentId?: string;
87
+ id?: string;
88
+ author?: string;
89
+ userId?: string;
90
+ comment?: string;
91
+ time?: DateRange;
92
+ updatedAt?: DateRange;
93
+ }
94
+ export interface Info {
95
+ id: string;
96
+ rate: number;
97
+ rate1: number;
98
+ rate2: number;
99
+ rate3: number;
100
+ rate4: number;
101
+ rate5: number;
102
+ count: number;
103
+ score: number;
104
+ }
105
+ export interface Info10 {
106
+ id: string;
107
+ rate: number;
108
+ rate1: number;
109
+ rate2: number;
110
+ rate3: number;
111
+ rate4: number;
112
+ rate5: number;
113
+ rate6: number;
114
+ rate7: number;
115
+ rate8: number;
116
+ rate9: number;
117
+ rate10: number;
118
+ count: number;
119
+ score: number;
120
+ }
121
+ export interface InfoRepository<ID> {
122
+ exist(id: ID, ctx?: any): Promise<boolean>;
123
+ }
124
+
125
+ export interface Company {
126
+ id: string
127
+ slug: string
128
+ name: string
129
+ overview: string
130
+ website?: string
131
+ industry?: string
132
+ size?: string
133
+ logo?: string
134
+ coverURL?: string
135
+ status: string
136
+
137
+ followerCount?: number
138
+ followingAt?: Date
139
+ followedAt?: Date
140
+ }
141
+
142
+ export interface Job {
143
+ id: string
144
+ slug: string
145
+ title: string
146
+ description: string
147
+ publishedAt?: Date
148
+ expiredAt?: Date
149
+ position?: string
150
+ quantity?: number
151
+ location?: string
152
+ applicantCount?: number
153
+ skills?: string[]
154
+ minSalary?: number
155
+ maxSalary?: number
156
+ companyId?: string
157
+ status: string
158
+ }
159
+ export interface JobFilter extends Filter {
160
+ id?: string
161
+ slug?: string
162
+ title?: string
163
+ description?: string
164
+ publishedAt?: TimeRange
165
+ expiredAt?: TimeRange
166
+ skills?: string[]
167
+ location?: string
168
+ quantity?: number
169
+ applicantCount?: number
170
+ companyId?: string
171
+ status?: string
172
+ }
package/src/location.ts CHANGED
@@ -1,27 +1,5 @@
1
1
  import {DateRange, Filter, NumberRange} from './model';
2
2
 
3
- export interface Article {
4
- id: string
5
- slug: string
6
- title: string
7
- description?: string
8
- content?: string
9
- publishedAt?: Date
10
- tags?: string[]
11
- thumbnail?: string
12
- status?: string
13
- createdAt?: Date
14
- authorId?: string
15
- savedAt?: Date
16
- }
17
- export interface ArticleFilter extends Filter {
18
- id?: string;
19
- title?: string;
20
- type?: string;
21
- tags?: string[];
22
- status?: string[]|string;
23
- }
24
-
25
3
  export interface Location {
26
4
  id?: string;
27
5
  name?: string;
package/src/model.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Transaction } from "./db";
2
+
1
3
  export interface Headers {
2
4
  [key: string]: any;
3
5
  }
@@ -125,9 +127,6 @@ export interface ErrorMessage {
125
127
  param?: string|number|Date;
126
128
  message?: string;
127
129
  }
128
- export interface ErrorHandler<T> {
129
- handleError(rs: T, errors: ErrorMessage[], i?: number, filename?: string): void;
130
- }
131
130
 
132
131
  export interface ResultInfo<T> {
133
132
  status: number|string;
@@ -149,143 +148,31 @@ export interface User {
149
148
  url?: string;
150
149
  }
151
150
  export interface History<T> {
152
- id: string;
153
- data: T;
154
- time: Date;
151
+ id: string
152
+ author: string
153
+ time: Date
154
+ action: string
155
+ data: T
155
156
  user: User;
156
157
  note?: string;
157
158
  }
158
- export interface Notification {
159
- id: string;
160
- time: Date;
161
- notifier?: User;
162
- message: string;
163
- url?: string;
164
- read: boolean;
165
- }
166
- export interface Attachment {
167
- originalFilename: string;
168
- filename: string;
169
- url: string;
170
- size: number;
171
- }
172
- export interface Achievement {
173
- subject: string;
174
- description: string;
175
- }
176
- export interface Skill {
177
- skill: string;
178
- hirable: boolean;
179
- }
180
- export interface UserFilter extends Filter {
181
- userId?: string;
182
- username?: string;
183
- email?: string;
184
- displayName?: string;
185
- dateOfBirth?: DateRange;
186
- status?: string[]|string;
187
- interests?: string[];
188
- skills?: Skill[];
189
- achievements?: Achievement[];
190
- }
191
- export interface RoleFilter extends Filter {
192
- roleId?: string;
193
- roleName?: string;
194
- status?: string[]|string;
195
- remark?: string;
196
- description?: string;
197
- }
159
+
198
160
  export type Validate<T> = (obj: T, patch?: boolean) => Promise<ErrorMessage[]>;
199
161
  export type Save<T> = (obj: T, ctx?: any) => Promise<number|ResultInfo<T>>;
200
162
  export type Load<T, ID> = ((id: ID, ctx?: any) => Promise<T|null>);
201
163
 
202
- export interface ReviewComment {
203
- commentId: string;
204
- id: string;
205
- author: string;
206
- userId: string;
207
- comment: string;
208
- time: Date;
209
- updatedAt?: Date;
210
- histories?: ShortComment[];
211
- userURL?: string;
212
- authorURL?: string;
213
- }
214
- export interface ShortComment {
215
- comment: string;
216
- time: Date;
217
- }
218
-
219
- export interface ReviewCommentFilter extends Filter {
220
- commentId?: string;
221
- id?: string;
222
- author?: string;
223
- userId?: string;
224
- comment?: string;
225
- time?: DateRange;
226
- updatedAt?: DateRange;
227
- }
228
- export interface Info {
229
- id: string;
230
- rate: number;
231
- rate1: number;
232
- rate2: number;
233
- rate3: number;
234
- rate4: number;
235
- rate5: number;
236
- count: number;
237
- score: number;
238
- }
239
- export interface Info10 {
240
- id: string;
241
- rate: number;
242
- rate1: number;
243
- rate2: number;
244
- rate3: number;
245
- rate4: number;
246
- rate5: number;
247
- rate6: number;
248
- rate7: number;
249
- rate8: number;
250
- rate9: number;
251
- rate10: number;
252
- count: number;
253
- score: number;
254
- }
255
- export interface InfoRepository<ID> {
256
- exist(id: ID, ctx?: any): Promise<boolean>;
257
- }
258
-
259
- export interface Company {
260
- id: string
261
- slug: string
262
- name: string
263
- overview: string
264
- website?: string
265
- industry?: string
266
- size?: string
267
- logo?: string
268
- coverURL?: string
269
- status: string
270
-
271
- followerCount?: number
272
- followingAt?: Date
273
- followedAt?: Date
274
- }
275
- export interface Job {
276
- id: string
277
- slug: string
278
- title: string
279
- description: string
280
- publishedAt?: Date
281
- expiredAt?: Date
282
- position?: string
283
- quantity?: number
284
- location?: string
285
- applicantCount?: number
286
- skills?: string[]
287
- minSalary?: number
288
- maxSalary?: number
289
- companyId?: string
290
- status: string
164
+ export interface Notification {
165
+ id?: string
166
+ sender: string
167
+ receiver: string
168
+ url?: string
169
+ message: string
170
+ }
171
+ export interface NotificationPort {
172
+ push(notification: Notification): Promise<number>
173
+ pushNotifications(notifications: Notification[]): Promise<number>
174
+ }
175
+ export interface NotificationRepository {
176
+ push(notification: Notification): Promise<number>
177
+ pushNotifications(notifications: Notification[]): Promise<number>
291
178
  }
package/src/mq.ts CHANGED
@@ -40,9 +40,6 @@ export interface Publisher<T, R, ID> {
40
40
  export interface Sender<T, R, ID> {
41
41
  send(data: T, attributes?: StringMap, id?: ID): Promise<R>;
42
42
  }
43
- export interface Writer<T, R, ID> {
44
- write(data: T, attributes?: StringMap, id?: ID): Promise<R>;
45
- }
46
43
 
47
44
  export interface Producer<T, R, ID> {
48
45
  produce(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
@@ -53,10 +50,11 @@ export interface Publisher<T, R, ID> {
53
50
  export interface Sender<T, R, ID> {
54
51
  send(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
55
52
  }
53
+ /*
56
54
  export interface Writer<T, R, ID> {
57
55
  write(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
58
56
  }
59
-
57
+ */
60
58
  export interface SimpleConsumer<T, R> {
61
59
  consume(handle: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
62
60
  }