onecore 0.0.30 → 0.0.33

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.30",
3
+ "version": "0.0.33",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -40,6 +40,10 @@ export * from './video';
40
40
  export * from './health';
41
41
  export * from './logger';
42
42
 
43
+ export type DeleteFile = (name: string, directory?: string) => Promise<boolean>;
44
+ export type Delete = (delFile: DeleteFile, url: string) => Promise<boolean>;
45
+ export type BuildUrl = (name: string, directory?: string) => string;
46
+
43
47
  export type Log = (msg: string) => void;
44
48
  export type LogFunc = Log;
45
49
 
@@ -50,6 +54,7 @@ import { ViewRepository } from './repository/ViewRepository';
50
54
  import { GenericSearchService } from './service/GenericSearchService';
51
55
  // import { GenericSearchService } from './service/GenericSearchService';
52
56
  import { GenericService } from './service/GenericService';
57
+ import { ViewSearchService } from './service/ViewSearchService';
53
58
  import { ViewService } from './service/ViewService';
54
59
 
55
60
  export type Search<T, F> = (s: F, limit?: number, offset?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
@@ -59,9 +64,7 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
59
64
  constructor(private r: ViewRepository<T, ID>) {
60
65
  this.metadata = this.metadata.bind(this);
61
66
  this.keys = this.keys.bind(this);
62
- this.all = this.all.bind(this);
63
67
  this.load = this.load.bind(this);
64
- this.exist = this.exist.bind(this);
65
68
  }
66
69
  metadata(): Attributes|undefined {
67
70
  return (this.r.metadata ? this.r.metadata() : undefined);
@@ -69,14 +72,18 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
69
72
  keys(): string[] {
70
73
  return (this.r.keys ? this.r.keys() : []);
71
74
  }
72
- all(ctx?: any): Promise<T[]> {
73
- return (this.r.all ? this.r.all() : Promise.resolve([]));
74
- }
75
75
  load(id: ID, ctx?: any): Promise<T | null> {
76
76
  return this.r.load(id, ctx);
77
77
  }
78
- exist(id: ID, ctx?: any): Promise<boolean> {
79
- return (this.r.exist ? this.r.exist(id, ctx) : Promise.resolve(false));
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);
80
87
  }
81
88
  }
82
89
  // tslint:disable-next-line:max-classes-per-file
@@ -86,7 +93,6 @@ export class GenericManager<T, ID> extends ViewManager<T, ID> implements Generic
86
93
  this.insert = this.insert.bind(this);
87
94
  this.update = this.update.bind(this);
88
95
  this.patch = this.patch.bind(this);
89
- this.save = this.save.bind(this);
90
96
  this.delete = this.delete.bind(this);
91
97
  }
92
98
  insert(obj: T, ctx?: any): Promise<number> {
@@ -95,12 +101,9 @@ export class GenericManager<T, ID> extends ViewManager<T, ID> implements Generic
95
101
  update(obj: T, ctx?: any): Promise<number> {
96
102
  return this.repository.update(obj, ctx);
97
103
  }
98
- patch(obj: T, ctx?: any): Promise<number> {
104
+ patch(obj: Partial<T>, ctx?: any): Promise<number> {
99
105
  return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
100
106
  }
101
- save(obj: T, ctx?: any): Promise<number> {
102
- return (this.repository.save ? this.repository.save(obj, ctx) : Promise.resolve(-1));
103
- }
104
107
  delete(id: ID, ctx?: any): Promise<number> {
105
108
  return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
106
109
  }
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>);
@@ -3,12 +3,12 @@ import {ViewRepository} from './ViewRepository';
3
3
  export interface GenericRepository<T, ID> extends ViewRepository<T, ID> {
4
4
  insert(obj: T, ctx?: any): Promise<number>;
5
5
  update(obj: T, ctx?: any): Promise<number>;
6
- patch(obj: T, ctx?: any): Promise<number>;
6
+ patch(obj: Partial<T>, ctx?: any): Promise<number>;
7
7
  delete(id: ID, ctx?: any): Promise<number>;
8
8
  }
9
9
  export interface Repository<T, ID> extends ViewRepository<T, ID> {
10
10
  insert(obj: T, ctx?: any): Promise<number>;
11
11
  update(obj: T, ctx?: any): Promise<number>;
12
- patch(obj: T, ctx?: any): Promise<number>;
12
+ patch(obj: Partial<T>, ctx?: any): Promise<number>;
13
13
  delete(id: ID, ctx?: any): Promise<number>;
14
14
  }
@@ -3,6 +3,6 @@ import {ViewService} from './ViewService';
3
3
  export interface GenericService<T, ID, R> extends ViewService<T, ID> {
4
4
  insert(obj: T, ctx?: any): Promise<R>;
5
5
  update(obj: T, ctx?: any): Promise<R>;
6
- patch(obj: T, ctx?: any): Promise<R>;
6
+ patch(obj: Partial<T>, ctx?: any): Promise<R>;
7
7
  delete(id: ID, ctx?: any): Promise<number>;
8
8
  }