onecore 0.0.31 → 0.0.32

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
@@ -14,33 +14,38 @@ var __extends = (this && this.__extends) || (function () {
14
14
  })();
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  var ViewManager = (function () {
17
- function ViewManager(repo) {
18
- this.repo = repo;
17
+ function ViewManager(r) {
18
+ this.r = r;
19
19
  this.metadata = this.metadata.bind(this);
20
20
  this.keys = this.keys.bind(this);
21
- this.all = this.all.bind(this);
22
21
  this.load = this.load.bind(this);
23
- this.exist = this.exist.bind(this);
24
22
  }
25
23
  ViewManager.prototype.metadata = function () {
26
- return (this.repo.metadata ? this.repo.metadata() : undefined);
24
+ return (this.r.metadata ? this.r.metadata() : undefined);
27
25
  };
28
26
  ViewManager.prototype.keys = function () {
29
- return (this.repo.keys ? this.repo.keys() : []);
30
- };
31
- ViewManager.prototype.all = function (ctx) {
32
- return (this.repo.all ? this.repo.all() : Promise.resolve([]));
27
+ return (this.r.keys ? this.r.keys() : []);
33
28
  };
34
29
  ViewManager.prototype.load = function (id, ctx) {
35
- return this.repo.load(id, ctx);
36
- ;
37
- };
38
- ViewManager.prototype.exist = function (id, ctx) {
39
- return (this.repo.exist ? this.repo.exist(id, ctx) : Promise.resolve(false));
30
+ return this.r.load(id, ctx);
40
31
  };
41
32
  return ViewManager;
42
33
  }());
43
34
  exports.ViewManager = ViewManager;
35
+ var ViewSearchManager = (function (_super) {
36
+ __extends(ViewSearchManager, _super);
37
+ function ViewSearchManager(find, repo) {
38
+ var _this = _super.call(this, repo) || this;
39
+ _this.find = find;
40
+ _this.search = _this.search.bind(_this);
41
+ return _this;
42
+ }
43
+ ViewSearchManager.prototype.search = function (s, limit, offset, fields) {
44
+ return this.find(s, limit, offset, fields);
45
+ };
46
+ return ViewSearchManager;
47
+ }(ViewManager));
48
+ exports.ViewSearchManager = ViewSearchManager;
44
49
  var GenericManager = (function (_super) {
45
50
  __extends(GenericManager, _super);
46
51
  function GenericManager(repository) {
@@ -49,24 +54,18 @@ var GenericManager = (function (_super) {
49
54
  _this.insert = _this.insert.bind(_this);
50
55
  _this.update = _this.update.bind(_this);
51
56
  _this.patch = _this.patch.bind(_this);
52
- _this.save = _this.save.bind(_this);
53
57
  _this.delete = _this.delete.bind(_this);
54
58
  return _this;
55
59
  }
56
60
  GenericManager.prototype.insert = function (obj, ctx) {
57
61
  return this.repository.insert(obj, ctx);
58
- ;
59
62
  };
60
63
  GenericManager.prototype.update = function (obj, ctx) {
61
64
  return this.repository.update(obj, ctx);
62
- ;
63
65
  };
64
66
  GenericManager.prototype.patch = function (obj, ctx) {
65
67
  return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
66
68
  };
67
- GenericManager.prototype.save = function (obj, ctx) {
68
- return (this.repository.save ? this.repository.save(obj, ctx) : Promise.resolve(-1));
69
- };
70
69
  GenericManager.prototype.delete = function (id, ctx) {
71
70
  return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
72
71
  };
@@ -86,4 +85,9 @@ var Manager = (function (_super) {
86
85
  };
87
86
  return Manager;
88
87
  }(GenericManager));
89
- exports.Manager = Manager;exports.DefaultViewService = ViewManager;exports.DefaultGenericService = GenericManager;exports.GenericSearchManager = Manager;exports.DefaultService = GenericManager;exports.DefaultGenericSearchService = GenericManager;
88
+ exports.Manager = Manager;
89
+ exports.DefaultViewService = ViewManager;
90
+ exports.DefaultGenericService = GenericManager;
91
+ exports.GenericSearchManager = Manager;
92
+ exports.DefaultService = GenericManager;
93
+ exports.DefaultGenericSearchService = GenericManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -55,6 +55,7 @@ import { GenericSearchService } from './service/GenericSearchService';
55
55
  // import { GenericSearchService } from './service/GenericSearchService';
56
56
  import { GenericService } from './service/GenericService';
57
57
  import { ViewService } from './service/ViewService';
58
+ import { ViewSearchService } from './service/ViewSearchService';
58
59
 
59
60
  export type Search<T, F> = (s: F, limit?: number, offset?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
60
61
  export type SearchFunc<T, F> = Search<T, F>;
@@ -76,6 +77,16 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
76
77
  }
77
78
  }
78
79
  // tslint:disable-next-line:max-classes-per-file
80
+ export class ViewSearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
81
+ constructor(public find: Search<T, F>, repo: ViewRepository<T, ID>) {
82
+ super(repo);
83
+ this.search = this.search.bind(this);
84
+ }
85
+ search(s: F, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>> {
86
+ return this.find(s, limit, offset, fields);
87
+ }
88
+ }
89
+ // tslint:disable-next-line:max-classes-per-file
79
90
  export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
80
91
  constructor(protected repository: GenericRepository<T, ID>) {
81
92
  super(repository);
package/src/model.ts CHANGED
@@ -155,3 +155,6 @@ export interface RoleFilter extends Filter {
155
155
  remark?: string;
156
156
  description?: string;
157
157
  }
158
+ export type Validate<T> = (obj: T, patch?: boolean) => Promise<ErrorMessage[]>;
159
+ export type Save<T> = (obj: T, ctx?: any) => Promise<number|ResultInfo<T>>;
160
+ export type Load<T, ID> = ((id: ID, ctx?: any) => Promise<T|null>);