onecore 0.2.0 → 0.3.1

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.
Files changed (3) hide show
  1. package/lib/index.js +65 -131
  2. package/package.json +1 -1
  3. package/src/index.ts +28 -48
package/lib/index.js CHANGED
@@ -13,181 +13,115 @@ var __extends = (this && this.__extends) || (function () {
13
13
  };
14
14
  })();
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- var ViewManager = (function () {
17
- function ViewManager(r) {
16
+ var ViewUseCase = (function () {
17
+ function ViewUseCase(r) {
18
18
  this.r = r;
19
19
  this.metadata = this.metadata.bind(this);
20
20
  this.keys = this.keys.bind(this);
21
21
  this.load = this.load.bind(this);
22
22
  }
23
- ViewManager.prototype.metadata = function () {
23
+ ViewUseCase.prototype.metadata = function () {
24
24
  return (this.r.metadata ? this.r.metadata() : undefined);
25
25
  };
26
- ViewManager.prototype.keys = function () {
26
+ ViewUseCase.prototype.keys = function () {
27
27
  return (this.r.keys ? this.r.keys() : []);
28
28
  };
29
- ViewManager.prototype.load = function (id, ctx) {
29
+ ViewUseCase.prototype.load = function (id, ctx) {
30
30
  return this.r.load(id, ctx);
31
31
  };
32
- return ViewManager;
33
- }());
34
- exports.ViewManager = ViewManager;
35
- var ViewUseCase = (function (_super) {
36
- __extends(ViewUseCase, _super);
37
- function ViewUseCase() {
38
- return _super !== null && _super.apply(this, arguments) || this;
39
- }
40
32
  return ViewUseCase;
41
- }(ViewManager));
33
+ }());
42
34
  exports.ViewUseCase = ViewUseCase;
43
- var DefaultViewService = (function (_super) {
44
- __extends(DefaultViewService, _super);
45
- function DefaultViewService() {
35
+ var ViewManager = (function (_super) {
36
+ __extends(ViewManager, _super);
37
+ function ViewManager() {
46
38
  return _super !== null && _super.apply(this, arguments) || this;
47
39
  }
48
- return DefaultViewService;
49
- }(ViewManager));
50
- exports.DefaultViewService = DefaultViewService;
51
- var ViewSearchManager = (function (_super) {
52
- __extends(ViewSearchManager, _super);
53
- function ViewSearchManager(find, repo) {
54
- var _this = _super.call(this, repo) || this;
55
- _this.find = find;
56
- _this.search = _this.search.bind(_this);
57
- return _this;
40
+ return ViewManager;
41
+ }(ViewUseCase));
42
+ exports.ViewManager = ViewManager;
43
+ var SearchUseCase = (function () {
44
+ function SearchUseCase(repo) {
45
+ this.repo = repo;
46
+ this.search = this.search.bind(this);
58
47
  }
59
- ViewSearchManager.prototype.search = function (s, limit, page, fields) {
60
- return this.find(s, limit, page, fields);
48
+ SearchUseCase.prototype.search = function (s, limit, page, fields) {
49
+ return this.repo.search(s, limit, page, fields);
61
50
  };
62
- return ViewSearchManager;
63
- }(ViewManager));
64
- exports.ViewSearchManager = ViewSearchManager;
51
+ return SearchUseCase;
52
+ }());
53
+ exports.SearchUseCase = SearchUseCase;
54
+ exports.SearchManager = SearchUseCase;
65
55
  var ViewSearchUseCase = (function (_super) {
66
56
  __extends(ViewSearchUseCase, _super);
67
- function ViewSearchUseCase() {
68
- return _super !== null && _super.apply(this, arguments) || this;
69
- }
70
- return ViewSearchUseCase;
71
- }(ViewSearchManager));
72
- exports.ViewSearchUseCase = ViewSearchUseCase;
73
- var SearchManager = (function (_super) {
74
- __extends(SearchManager, _super);
75
- function SearchManager(repository) {
76
- var _this = _super.call(this, repository) || this;
77
- _this.repository = repository;
57
+ function ViewSearchUseCase(repo) {
58
+ var _this = _super.call(this, repo) || this;
59
+ _this.repo = repo;
78
60
  _this.search = _this.search.bind(_this);
79
61
  return _this;
80
62
  }
81
- SearchManager.prototype.search = function (s, limit, page, fields) {
82
- return this.repository.search(s, limit, page, fields);
63
+ ViewSearchUseCase.prototype.search = function (s, limit, page, fields) {
64
+ return this.repo.search(s, limit, page, fields);
83
65
  };
84
- return SearchManager;
85
- }(ViewManager));
86
- exports.SearchManager = SearchManager;
87
- var SearchUseCase = (function (_super) {
88
- __extends(SearchUseCase, _super);
89
- function SearchUseCase() {
66
+ return ViewSearchUseCase;
67
+ }(ViewUseCase));
68
+ exports.ViewSearchUseCase = ViewSearchUseCase;
69
+ var ViewSearchManger = (function (_super) {
70
+ __extends(ViewSearchManger, _super);
71
+ function ViewSearchManger() {
90
72
  return _super !== null && _super.apply(this, arguments) || this;
91
73
  }
92
- return SearchUseCase;
93
- }(SearchManager));
94
- exports.SearchUseCase = SearchUseCase;
95
- var GenericManager = (function (_super) {
96
- __extends(GenericManager, _super);
97
- function GenericManager(repository) {
98
- var _this = _super.call(this, repository) || this;
99
- _this.repository = repository;
74
+ return ViewSearchManger;
75
+ }(ViewSearchUseCase));
76
+ exports.ViewSearchManger = ViewSearchManger;
77
+ var GenericUseCase = (function (_super) {
78
+ __extends(GenericUseCase, _super);
79
+ function GenericUseCase(repo) {
80
+ var _this = _super.call(this, repo) || this;
81
+ _this.repo = repo;
100
82
  _this.create = _this.create.bind(_this);
101
83
  _this.update = _this.update.bind(_this);
102
84
  _this.patch = _this.patch.bind(_this);
103
85
  _this.delete = _this.delete.bind(_this);
104
86
  return _this;
105
87
  }
106
- GenericManager.prototype.create = function (obj, ctx) {
107
- return this.repository.create(obj, ctx);
88
+ GenericUseCase.prototype.create = function (obj, ctx) {
89
+ return this.repo.create(obj, ctx);
108
90
  };
109
- GenericManager.prototype.update = function (obj, ctx) {
110
- return this.repository.update(obj, ctx);
91
+ GenericUseCase.prototype.update = function (obj, ctx) {
92
+ return this.repo.update(obj, ctx);
111
93
  };
112
- GenericManager.prototype.patch = function (obj, ctx) {
113
- return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
94
+ GenericUseCase.prototype.patch = function (obj, ctx) {
95
+ return (this.repo.patch ? this.repo.patch(obj, ctx) : Promise.resolve(-1));
114
96
  };
115
- GenericManager.prototype.delete = function (id, ctx) {
116
- return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
97
+ GenericUseCase.prototype.delete = function (id, ctx) {
98
+ return (this.repo.delete ? this.repo.delete(id, ctx) : Promise.resolve(-1));
117
99
  };
118
- return GenericManager;
119
- }(ViewManager));
120
- exports.GenericManager = GenericManager;
121
- var GenericUseCase = (function (_super) {
122
- __extends(GenericUseCase, _super);
123
- function GenericUseCase() {
124
- return _super !== null && _super.apply(this, arguments) || this;
125
- }
126
100
  return GenericUseCase;
127
- }(GenericManager));
101
+ }(ViewUseCase));
128
102
  exports.GenericUseCase = GenericUseCase;
129
- var DefaultGenericService = (function (_super) {
130
- __extends(DefaultGenericService, _super);
131
- function DefaultGenericService() {
132
- return _super !== null && _super.apply(this, arguments) || this;
133
- }
134
- return DefaultGenericService;
135
- }(GenericManager));
136
- exports.DefaultGenericService = DefaultGenericService;
137
- var DefaultService = (function (_super) {
138
- __extends(DefaultService, _super);
139
- function DefaultService() {
140
- return _super !== null && _super.apply(this, arguments) || this;
141
- }
142
- return DefaultService;
143
- }(GenericManager));
144
- exports.DefaultService = DefaultService;
145
- var DefaultGenericSearchService = (function (_super) {
146
- __extends(DefaultGenericSearchService, _super);
147
- function DefaultGenericSearchService() {
148
- return _super !== null && _super.apply(this, arguments) || this;
149
- }
150
- return DefaultGenericSearchService;
151
- }(GenericManager));
152
- exports.DefaultGenericSearchService = DefaultGenericSearchService;
153
- var Manager = (function (_super) {
154
- __extends(Manager, _super);
155
- function Manager(find, repo) {
156
- var _this = _super.call(this, repo) || this;
157
- _this.find = find;
158
- _this.search = _this.search.bind(_this);
159
- return _this;
160
- }
161
- Manager.prototype.search = function (s, limit, page, fields) {
162
- return this.find(s, limit, page, fields);
163
- };
164
- return Manager;
165
- }(GenericManager));
166
- exports.Manager = Manager;
103
+ exports.GenericManager = GenericUseCase;
167
104
  var UseCase = (function (_super) {
168
105
  __extends(UseCase, _super);
169
- function UseCase() {
170
- return _super !== null && _super.apply(this, arguments) || this;
106
+ function UseCase(repository) {
107
+ var _this = _super.call(this, repository) || this;
108
+ _this.repository = repository;
109
+ return _this;
171
110
  }
111
+ UseCase.prototype.search = function (s, limit, page, fields) {
112
+ return this.repository.search(s, limit, page, fields);
113
+ };
172
114
  return UseCase;
173
- }(Manager));
115
+ }(GenericUseCase));
174
116
  exports.UseCase = UseCase;
175
- var GenericSearchManager = (function (_super) {
176
- __extends(GenericSearchManager, _super);
177
- function GenericSearchManager() {
178
- return _super !== null && _super.apply(this, arguments) || this;
179
- }
180
- return GenericSearchManager;
181
- }(Manager));
182
- exports.GenericSearchManager = GenericSearchManager;
183
- var GenericSearchUseCase = (function (_super) {
184
- __extends(GenericSearchUseCase, _super);
185
- function GenericSearchUseCase() {
117
+ var Manager = (function (_super) {
118
+ __extends(Manager, _super);
119
+ function Manager() {
186
120
  return _super !== null && _super.apply(this, arguments) || this;
187
121
  }
188
- return GenericSearchUseCase;
189
- }(Manager));
190
- exports.GenericSearchUseCase = GenericSearchUseCase;
122
+ return Manager;
123
+ }(UseCase));
124
+ exports.Manager = Manager;
191
125
  var SavedService = (function () {
192
126
  function SavedService(savedRepository, max) {
193
127
  this.savedRepository = savedRepository;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -63,6 +63,9 @@ import { GenericSearchService } from './service/GenericSearchService';
63
63
  import { GenericService } from './service/GenericService';
64
64
  import { ViewSearchService } from './service/ViewSearchService';
65
65
  import { ViewService } from './service/ViewService';
66
+ import { SearchRepository } from './repository/SearchRepository';
67
+ import { ViewSearchRepository } from './repository/ViewSearchRepository';
68
+ import { GenericSearchRepository } from './repository/GenericSearchRepository';
66
69
 
67
70
  export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
68
71
  export type SearchFunc<T, F> = Search<T, F>;
@@ -126,7 +129,7 @@ export interface ExportService {
126
129
  export interface Exporter {
127
130
  export(ctx?: any): Promise<number>;
128
131
  }
129
- export class ViewManager<T, ID> implements ViewService<T, ID> {
132
+ export class ViewUseCase<T, ID> implements ViewService<T, ID> {
130
133
  constructor(private r: ViewRepository<T, ID>) {
131
134
  this.metadata = this.metadata.bind(this);
132
135
  this.keys = this.keys.bind(this);
@@ -142,91 +145,68 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
142
145
  return this.r.load(id, ctx);
143
146
  }
144
147
  }
148
+
145
149
  // tslint:disable-next-line:max-classes-per-file
146
- export class ViewUseCase<T, ID> extends ViewManager<T, ID> {
147
- }
148
- // tslint:disable-next-line:max-classes-per-file
149
- export class DefaultViewService<T, ID> extends ViewManager<T, ID> {
150
+ export class ViewManager<T, ID> extends ViewUseCase<T, ID> {
150
151
  }
151
152
 
152
153
  // tslint:disable-next-line:max-classes-per-file
153
- export class ViewSearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
154
- constructor(public find: Search<T, F>, repo: ViewRepository<T, ID>) {
155
- super(repo);
154
+ export class SearchUseCase<T, F extends Filter> {
155
+ constructor(protected repo: SearchRepository<T, F>) {
156
156
  this.search = this.search.bind(this);
157
157
  }
158
158
  search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
159
- return this.find(s, limit, page, fields);
159
+ return this.repo.search(s, limit, page, fields);
160
160
  }
161
161
  }
162
+ export const SearchManager = SearchUseCase
162
163
  // tslint:disable-next-line:max-classes-per-file
163
- export class ViewSearchUseCase<T, ID, F extends Filter> extends ViewSearchManager<T, ID, F> {
164
- }
165
- // tslint:disable-next-line:max-classes-per-file
166
- export class SearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
167
- constructor(protected repository: ViewSearchService<T, ID, F>) {
168
- super(repository);
164
+ export class ViewSearchUseCase<T, ID, F extends Filter> extends ViewUseCase<T, ID> implements ViewSearchService<T, ID, F> {
165
+ constructor(protected repo: ViewSearchRepository<T, ID, Filter>) {
166
+ super(repo);
169
167
  this.search = this.search.bind(this);
170
168
  }
171
169
  search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
172
- return this.repository.search(s, limit, page, fields);
170
+ return this.repo.search(s, limit, page, fields);
173
171
  }
174
172
  }
175
173
  // tslint:disable-next-line:max-classes-per-file
176
- export class SearchUseCase<T, ID, F extends Filter> extends SearchManager<T, ID, F> {
174
+ export class ViewSearchManger<T, ID, F extends Filter> extends ViewSearchUseCase<T, ID, F> {
177
175
  }
178
176
  // tslint:disable-next-line:max-classes-per-file
179
- export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
180
- constructor(protected repository: GenericRepository<T, ID>) {
181
- super(repository);
177
+ export class GenericUseCase<T, ID> extends ViewUseCase<T, ID> implements GenericService<T, ID, number> {
178
+ constructor(private repo: GenericRepository<T, ID>) {
179
+ super(repo);
182
180
  this.create = this.create.bind(this);
183
181
  this.update = this.update.bind(this);
184
182
  this.patch = this.patch.bind(this);
185
183
  this.delete = this.delete.bind(this);
186
184
  }
187
185
  create(obj: T, ctx?: any): Promise<number> {
188
- return this.repository.create(obj, ctx);
186
+ return this.repo.create(obj, ctx);
189
187
  }
190
188
  update(obj: T, ctx?: any): Promise<number> {
191
- return this.repository.update(obj, ctx);
189
+ return this.repo.update(obj, ctx);
192
190
  }
193
191
  patch(obj: Partial<T>, ctx?: any): Promise<number> {
194
- 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));
195
193
  }
196
194
  delete(id: ID, ctx?: any): Promise<number> {
197
- 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));
198
196
  }
199
197
  }
198
+ export const GenericManager = GenericUseCase
200
199
  // tslint:disable-next-line:max-classes-per-file
201
- export class GenericUseCase<T, ID> extends GenericManager<T, ID> {
202
- }
203
- // tslint:disable-next-line:max-classes-per-file
204
- export class DefaultGenericService<T, ID> extends GenericManager<T, ID> {
205
- }
206
- // tslint:disable-next-line:max-classes-per-file
207
- export class DefaultService<T, ID> extends GenericManager<T, ID> {
208
- }
209
- // tslint:disable-next-line:max-classes-per-file
210
- export class DefaultGenericSearchService<T, ID> extends GenericManager<T, ID> {
211
- }
212
- // tslint:disable-next-line:max-classes-per-file
213
- export class Manager<T, ID, F extends Filter> extends GenericManager<T, ID> implements GenericSearchService<T, ID, number, F> {
214
- constructor(public find: Search<T, F>, repo: GenericRepository<T, ID>) {
215
- super(repo);
216
- this.search = this.search.bind(this);
200
+ export class UseCase<T, ID, F extends Filter> extends GenericUseCase<T, ID> implements GenericSearchService<T, ID, number, F> {
201
+ constructor(protected repository: GenericSearchRepository<T, ID, F>) {
202
+ super(repository);
217
203
  }
218
204
  search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
219
- return this.find(s, limit, page, fields);
205
+ return this.repository.search(s, limit, page, fields);
220
206
  }
221
207
  }
222
208
  // tslint:disable-next-line:max-classes-per-file
223
- export class UseCase<T, ID, F extends Filter> extends Manager<T, ID, F> {
224
- }
225
- // tslint:disable-next-line:max-classes-per-file
226
- export class GenericSearchManager<T, ID, F extends Filter> extends Manager<T, ID, F> {
227
- }
228
- // tslint:disable-next-line:max-classes-per-file
229
- export class GenericSearchUseCase<T, ID, F extends Filter> extends Manager<T, ID, F> {
209
+ export class Manager<T, ID, F extends Filter> extends UseCase<T, ID, F> {
230
210
  }
231
211
  export interface SavedRepository<UID, ID> {
232
212
  isSaved(userId: UID, id: ID): Promise<boolean>