onecore 0.0.39 → 0.0.41

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/README.md CHANGED
@@ -1 +1 @@
1
- # core
1
+ # onecore
package/lib/index.js CHANGED
@@ -112,6 +112,7 @@ var SavedService = (function () {
112
112
  this.max = max;
113
113
  this.load = this.load.bind(this);
114
114
  this.save = this.save.bind(this);
115
+ this.remove = this.remove.bind(this);
115
116
  }
116
117
  SavedService.prototype.load = function (id) {
117
118
  var _this = this;
@@ -142,6 +143,25 @@ var SavedService = (function () {
142
143
  }
143
144
  });
144
145
  };
146
+ SavedService.prototype.remove = function (id, itemId) {
147
+ var _this = this;
148
+ return this.repository.load(id).then(function (items) {
149
+ if (items == null) {
150
+ return Promise.resolve(0);
151
+ }
152
+ else {
153
+ if (items.includes(itemId)) {
154
+ items = items.filter(function (item) {
155
+ return item !== itemId;
156
+ });
157
+ return _this.repository.update(id, items);
158
+ }
159
+ else {
160
+ return Promise.resolve(0);
161
+ }
162
+ }
163
+ });
164
+ };
145
165
  return SavedService;
146
166
  }());
147
167
  exports.SavedService = SavedService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -67,6 +67,19 @@ import { ViewService } from './service/ViewService';
67
67
  export type Search<T, F> = (s: F, limit?: number, offset?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
68
68
  export type SearchFunc<T, F> = Search<T, F>;
69
69
 
70
+ export interface ExceptionHandler {
71
+ handleException(rs: string, err: any, i?: number, filename?: string): void;
72
+ }
73
+ export interface ImportResult {
74
+ total: number;
75
+ success: number;
76
+ }
77
+ export interface ImportService {
78
+ import(): Promise<ImportResult>;
79
+ }
80
+ export interface Importer {
81
+ import(): Promise<ImportResult>;
82
+ }
70
83
  export class ViewManager<T, ID> implements ViewService<T, ID> {
71
84
  constructor(private r: ViewRepository<T, ID>) {
72
85
  this.metadata = this.metadata.bind(this);
@@ -150,6 +163,7 @@ export class SavedService<ID, T> {
150
163
  constructor(protected repository: SavedRepository<ID>, protected query: (ids: string[]) => Promise<T[]>, public max: number) {
151
164
  this.load = this.load.bind(this);
152
165
  this.save = this.save.bind(this);
166
+ this.remove = this.remove.bind(this);
153
167
  }
154
168
  load(id: ID): Promise<T[]> {
155
169
  return this.repository.load(id).then(items => {
@@ -176,4 +190,20 @@ export class SavedService<ID, T> {
176
190
  }
177
191
  });
178
192
  }
193
+ remove(id: ID, itemId: string): Promise<number> {
194
+ return this.repository.load(id).then(items => {
195
+ if (items == null) {
196
+ return Promise.resolve(0);
197
+ } else {
198
+ if (items.includes(itemId)) {
199
+ items = items.filter((item: any) => {
200
+ return item !== itemId;
201
+ });
202
+ return this.repository.update(id, items);
203
+ } else {
204
+ return Promise.resolve(0);
205
+ }
206
+ }
207
+ });
208
+ }
179
209
  }
package/src/model.ts CHANGED
@@ -115,6 +115,10 @@ export interface ErrorMessage {
115
115
  param?: string|number|Date;
116
116
  message?: string;
117
117
  }
118
+ export interface ErrorHandler<T> {
119
+ handleError(rs: T, errors: ErrorMessage[], i?: number, filename?: string): void;
120
+ }
121
+
118
122
  export interface ResultInfo<T> {
119
123
  status: number|string;
120
124
  errors?: ErrorMessage[];