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