onecore 0.3.0 → 0.5.0

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
@@ -76,9 +76,9 @@ var ViewSearchManger = (function (_super) {
76
76
  exports.ViewSearchManger = ViewSearchManger;
77
77
  var GenericUseCase = (function (_super) {
78
78
  __extends(GenericUseCase, _super);
79
- function GenericUseCase(repository) {
80
- var _this = _super.call(this, repository) || this;
81
- _this.repository = repository;
79
+ function GenericUseCase(repo) {
80
+ var _this = _super.call(this, repo) || this;
81
+ _this.repo = repo;
82
82
  _this.create = _this.create.bind(_this);
83
83
  _this.update = _this.update.bind(_this);
84
84
  _this.patch = _this.patch.bind(_this);
@@ -86,16 +86,16 @@ var GenericUseCase = (function (_super) {
86
86
  return _this;
87
87
  }
88
88
  GenericUseCase.prototype.create = function (obj, ctx) {
89
- return this.repository.create(obj, ctx);
89
+ return this.repo.create(obj, ctx);
90
90
  };
91
91
  GenericUseCase.prototype.update = function (obj, ctx) {
92
- return this.repository.update(obj, ctx);
92
+ return this.repo.update(obj, ctx);
93
93
  };
94
94
  GenericUseCase.prototype.patch = function (obj, ctx) {
95
- return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
95
+ return (this.repo.patch ? this.repo.patch(obj, ctx) : Promise.resolve(-1));
96
96
  };
97
97
  GenericUseCase.prototype.delete = function (id, ctx) {
98
- return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
98
+ return (this.repo.delete ? this.repo.delete(id, ctx) : Promise.resolve(-1));
99
99
  };
100
100
  return GenericUseCase;
101
101
  }(ViewUseCase));
@@ -103,14 +103,13 @@ exports.GenericUseCase = GenericUseCase;
103
103
  exports.GenericManager = GenericUseCase;
104
104
  var UseCase = (function (_super) {
105
105
  __extends(UseCase, _super);
106
- function UseCase(find, repo) {
107
- var _this = _super.call(this, repo) || this;
108
- _this.find = find;
109
- _this.search = _this.search.bind(_this);
106
+ function UseCase(repository) {
107
+ var _this = _super.call(this, repository) || this;
108
+ _this.repository = repository;
110
109
  return _this;
111
110
  }
112
111
  UseCase.prototype.search = function (s, limit, page, fields) {
113
- return this.find(s, limit, page, fields);
112
+ return this.repository.search(s, limit, page, fields);
114
113
  };
115
114
  return UseCase;
116
115
  }(GenericUseCase));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -65,6 +65,7 @@ import { ViewSearchService } from './service/ViewSearchService';
65
65
  import { ViewService } from './service/ViewService';
66
66
  import { SearchRepository } from './repository/SearchRepository';
67
67
  import { ViewSearchRepository } from './repository/ViewSearchRepository';
68
+ import { GenericSearchRepository } from './repository/GenericSearchRepository';
68
69
 
69
70
  export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
70
71
  export type SearchFunc<T, F> = Search<T, F>;
@@ -174,35 +175,34 @@ export class ViewSearchManger<T, ID, F extends Filter> extends ViewSearchUseCase
174
175
  }
175
176
  // tslint:disable-next-line:max-classes-per-file
176
177
  export class GenericUseCase<T, ID> extends ViewUseCase<T, ID> implements GenericService<T, ID, number> {
177
- constructor(protected repository: GenericRepository<T, ID>) {
178
- super(repository);
178
+ constructor(private repo: GenericRepository<T, ID>) {
179
+ super(repo);
179
180
  this.create = this.create.bind(this);
180
181
  this.update = this.update.bind(this);
181
182
  this.patch = this.patch.bind(this);
182
183
  this.delete = this.delete.bind(this);
183
184
  }
184
185
  create(obj: T, ctx?: any): Promise<number> {
185
- return this.repository.create(obj, ctx);
186
+ return this.repo.create(obj, ctx);
186
187
  }
187
188
  update(obj: T, ctx?: any): Promise<number> {
188
- return this.repository.update(obj, ctx);
189
+ return this.repo.update(obj, ctx);
189
190
  }
190
191
  patch(obj: Partial<T>, ctx?: any): Promise<number> {
191
- return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
192
+ return (this.repo.patch ? this.repo.patch(obj, ctx) : Promise.resolve(-1));
192
193
  }
193
194
  delete(id: ID, ctx?: any): Promise<number> {
194
- return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
195
+ return (this.repo.delete ? this.repo.delete(id, ctx) : Promise.resolve(-1));
195
196
  }
196
197
  }
197
198
  export const GenericManager = GenericUseCase
198
199
  // tslint:disable-next-line:max-classes-per-file
199
200
  export class UseCase<T, ID, F extends Filter> extends GenericUseCase<T, ID> implements GenericSearchService<T, ID, number, F> {
200
- constructor(public find: Search<T, F>, repo: GenericRepository<T, ID>) {
201
- super(repo);
202
- this.search = this.search.bind(this);
201
+ constructor(protected repository: GenericSearchRepository<T, ID, F>) {
202
+ super(repository);
203
203
  }
204
204
  search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
205
- return this.find(s, limit, page, fields);
205
+ return this.repository.search(s, limit, page, fields);
206
206
  }
207
207
  }
208
208
  // tslint:disable-next-line:max-classes-per-file
package/src/metadata.ts CHANGED
@@ -3,7 +3,7 @@ export type DataType = 'ObjectId' | 'date' | 'datetime' | 'time'
3
3
  | 'object' | 'array' | 'binary'
4
4
  | 'primitives' | 'booleans' | 'numbers' | 'integers' | 'strings' | 'dates' | 'datetimes' | 'times';
5
5
  export type FormatType = 'currency' | 'percentage' | 'email' | 'url' | 'phone' | 'fax' | 'ipv4' | 'ipv6';
6
- export type MatchType = 'equal' | 'prefix' | 'contain' | 'max' | 'min'; // contain: default for string, min: default for Date, number
6
+ export type Operator = "=" | "like" | "!=" | "<>" | ">" | ">=" | "<" | "<="
7
7
 
8
8
  export interface Model {
9
9
  name?: string;
@@ -24,7 +24,7 @@ export interface Attribute {
24
24
  type?: DataType;
25
25
  format?: FormatType;
26
26
  required?: boolean;
27
- match?: MatchType;
27
+ operator?: Operator;
28
28
  default?: string|number|Date|boolean;
29
29
  key?: boolean;
30
30
  unique?: boolean;