onecore 0.0.36 → 0.0.39

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/lib/index.js CHANGED
@@ -46,6 +46,20 @@ var ViewSearchManager = (function (_super) {
46
46
  return ViewSearchManager;
47
47
  }(ViewManager));
48
48
  exports.ViewSearchManager = ViewSearchManager;
49
+ var SearchManager = (function (_super) {
50
+ __extends(SearchManager, _super);
51
+ function SearchManager(repository) {
52
+ var _this = _super.call(this, repository) || this;
53
+ _this.repository = repository;
54
+ _this.search = _this.search.bind(_this);
55
+ return _this;
56
+ }
57
+ SearchManager.prototype.search = function (s, limit, offset, fields) {
58
+ return this.repository.search(s, limit, offset, fields);
59
+ };
60
+ return SearchManager;
61
+ }(ViewManager));
62
+ exports.SearchManager = SearchManager;
49
63
  var GenericManager = (function (_super) {
50
64
  __extends(GenericManager, _super);
51
65
  function GenericManager(repository) {
@@ -91,3 +105,43 @@ exports.DefaultGenericService = GenericManager;
91
105
  exports.GenericSearchManager = Manager;
92
106
  exports.DefaultService = GenericManager;
93
107
  exports.DefaultGenericSearchService = GenericManager;
108
+ var SavedService = (function () {
109
+ function SavedService(repository, query, max) {
110
+ this.repository = repository;
111
+ this.query = query;
112
+ this.max = max;
113
+ this.load = this.load.bind(this);
114
+ this.save = this.save.bind(this);
115
+ }
116
+ SavedService.prototype.load = function (id) {
117
+ var _this = this;
118
+ return this.repository.load(id).then(function (items) {
119
+ if (!items || items.length === 0) {
120
+ return [];
121
+ }
122
+ return _this.query(items);
123
+ });
124
+ };
125
+ SavedService.prototype.save = function (id, itemId) {
126
+ var _this = this;
127
+ return this.repository.load(id).then(function (items) {
128
+ if (items == null) {
129
+ return _this.repository.insert(id, [itemId]);
130
+ }
131
+ else {
132
+ if (items.includes(itemId)) {
133
+ return Promise.resolve(0);
134
+ }
135
+ else {
136
+ items.push(itemId);
137
+ if (items.length > _this.max) {
138
+ items.shift();
139
+ }
140
+ return _this.repository.update(id, items);
141
+ }
142
+ }
143
+ });
144
+ };
145
+ return SavedService;
146
+ }());
147
+ exports.SavedService = SavedService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.0.36",
3
+ "version": "0.0.39",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -44,10 +44,13 @@ export type DeleteFile = (name: string, directory?: string) => Promise<boolean>;
44
44
  export type Delete = (delFile: DeleteFile, url: string) => Promise<boolean>;
45
45
  export type BuildUrl = (name: string, directory?: string) => string;
46
46
  export type Generate = () => string;
47
+ export type SaveValues = (values: string[]) => Promise<number>;
48
+ export type SaveStrings = (values: string[]) => Promise<number>;
47
49
  export interface QueryService<T> {
48
- query(keyword: string, max?: number): Promise<T[]>
50
+ query(keyword: string, max?: number): Promise<T[]>;
49
51
  }
50
- export type Query<T> = (keyword: string, max?: number) => Promise<T[]>;
52
+ export type Get<T> = (keyword: string, max?: number) => Promise<T[]>;
53
+ export type Load<T> = (keyword: string, max?: number) => Promise<T[]>;
51
54
  export type Log = (msg: string) => void;
52
55
  export type LogFunc = Log;
53
56
 
@@ -91,6 +94,16 @@ export class ViewSearchManager<T, ID, F extends Filter> extends ViewManager<T, I
91
94
  }
92
95
  }
93
96
  // tslint:disable-next-line:max-classes-per-file
97
+ export class SearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
98
+ constructor(protected repository: ViewSearchService<T, ID, F>) {
99
+ super(repository);
100
+ this.search = this.search.bind(this);
101
+ }
102
+ search(s: F, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>> {
103
+ return this.repository.search(s, limit, offset, fields);
104
+ }
105
+ }
106
+ // tslint:disable-next-line:max-classes-per-file
94
107
  export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
95
108
  constructor(protected repository: GenericRepository<T, ID>) {
96
109
  super(repository);
@@ -127,3 +140,40 @@ export const DefaultGenericService = GenericManager;
127
140
  export const GenericSearchManager = Manager;
128
141
  export const DefaultService = GenericManager;
129
142
  export const DefaultGenericSearchService = GenericManager;
143
+ export interface SavedRepository<ID> {
144
+ load(id: ID): Promise<string[]|null>;
145
+ insert(id: ID, arr: string[]): Promise<number>;
146
+ update(id: ID, arr: string[]): Promise<number>;
147
+ }
148
+ // tslint:disable-next-line:max-classes-per-file
149
+ export class SavedService<ID, T> {
150
+ constructor(protected repository: SavedRepository<ID>, protected query: (ids: string[]) => Promise<T[]>, public max: number) {
151
+ this.load = this.load.bind(this);
152
+ this.save = this.save.bind(this);
153
+ }
154
+ load(id: ID): Promise<T[]> {
155
+ return this.repository.load(id).then(items => {
156
+ if (!items || items.length === 0) {
157
+ return [];
158
+ }
159
+ return this.query(items);
160
+ });
161
+ }
162
+ save(id: ID, itemId: string): Promise<number> {
163
+ return this.repository.load(id).then(items => {
164
+ if (items == null) {
165
+ return this.repository.insert(id, [itemId]);
166
+ } else {
167
+ if (items.includes(itemId)) {
168
+ return Promise.resolve(0);
169
+ } else {
170
+ items.push(itemId);
171
+ if (items.length > this.max) {
172
+ items.shift();
173
+ }
174
+ return this.repository.update(id, items);
175
+ }
176
+ }
177
+ });
178
+ }
179
+ }
package/src/model.ts CHANGED
@@ -158,3 +158,60 @@ export interface RoleFilter extends Filter {
158
158
  export type Validate<T> = (obj: T, patch?: boolean) => Promise<ErrorMessage[]>;
159
159
  export type Save<T> = (obj: T, ctx?: any) => Promise<number|ResultInfo<T>>;
160
160
  export type Load<T, ID> = ((id: ID, ctx?: any) => Promise<T|null>);
161
+
162
+ export interface ReviewComment {
163
+ commentId: string;
164
+ id: string;
165
+ author: string;
166
+ userId: string;
167
+ comment: string;
168
+ time: Date;
169
+ updatedAt?: Date;
170
+ histories?: ShortComment[];
171
+ userURL?: string;
172
+ authorURL?: string;
173
+ }
174
+ export interface ShortComment {
175
+ comment: string;
176
+ time: Date;
177
+ }
178
+
179
+ export interface ReviewCommentFilter extends Filter {
180
+ commentId?: string;
181
+ id?: string;
182
+ author?: string;
183
+ userId?: string;
184
+ comment?: string;
185
+ time?: DateRange;
186
+ updatedAt?: DateRange;
187
+ }
188
+ export interface Info {
189
+ id: string;
190
+ rate: number;
191
+ rate1: number;
192
+ rate2: number;
193
+ rate3: number;
194
+ rate4: number;
195
+ rate5: number;
196
+ count: number;
197
+ score: number;
198
+ }
199
+ export interface Info10 {
200
+ id: string;
201
+ rate: number;
202
+ rate1: number;
203
+ rate2: number;
204
+ rate3: number;
205
+ rate4: number;
206
+ rate5: number;
207
+ rate6: number;
208
+ rate7: number;
209
+ rate8: number;
210
+ rate9: number;
211
+ rate10: number;
212
+ count: number;
213
+ score: number;
214
+ }
215
+ export interface InfoRepository<ID> {
216
+ exist(id: ID, ctx?: any): Promise<boolean>;
217
+ }
@@ -7,6 +7,7 @@ export interface DiffService<T, ID> {
7
7
  }
8
8
  export interface DiffListService<T, ID> {
9
9
  keys?(): string[];
10
+ // tslint:disable-next-line:array-type
10
11
  diff(ids: ID[], ctx?: any): Promise<Array<DiffModel<T, ID>>>;
11
12
  }
12
13
 
@@ -16,5 +17,6 @@ export interface DiffRepository<T, ID> {
16
17
  }
17
18
  export interface DiffListRepository<T, ID> {
18
19
  keys?(): string[];
20
+ // tslint:disable-next-line:array-type
19
21
  diff(ids: ID[], ctx?: any): Promise<Array<DiffModel<T, ID>>>;
20
22
  }
@@ -1,7 +1,22 @@
1
- import {Filter} from '../model';
2
- import {SearchResult} from '../model';
1
+ import {Attributes} from '../metadata';
2
+ import {Filter, SearchResult} from '../model';
3
3
 
4
4
  export interface SearchService<T, F extends Filter> {
5
5
  keys?(): string[];
6
6
  search(s: F, limit?: number, offset?: number|string, fields?: string[], ctx?: any): Promise<SearchResult<T>>;
7
7
  }
8
+ export interface Query<T, ID, F extends Filter> extends SearchService<T, F> {
9
+ metadata?(): Attributes|undefined;
10
+ metadata?(): Attributes|undefined;
11
+ load(id: ID, ctx?: any): Promise<T|null>;
12
+ }
13
+ export interface QueryService<T, ID, F extends Filter> extends SearchService<T, F> {
14
+ metadata?(): Attributes|undefined;
15
+ metadata?(): Attributes|undefined;
16
+ load(id: ID, ctx?: any): Promise<T|null>;
17
+ }
18
+ export interface QueryRepository<T, ID, F extends Filter> extends SearchService<T, F> {
19
+ metadata?(): Attributes|undefined;
20
+ metadata?(): Attributes|undefined;
21
+ load(id: ID, ctx?: any): Promise<T|null>;
22
+ }
package/tsconfig.json CHANGED
@@ -14,7 +14,8 @@
14
14
  "removeComments": true,
15
15
  "lib": [
16
16
  "es5",
17
- "es6"
17
+ "es6",
18
+ "es7"
18
19
  ]
19
20
  },
20
21
  "include": [