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.
- package/lib/index.js +65 -131
- package/package.json +1 -1
- 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
|
|
17
|
-
function
|
|
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
|
-
|
|
23
|
+
ViewUseCase.prototype.metadata = function () {
|
|
24
24
|
return (this.r.metadata ? this.r.metadata() : undefined);
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
ViewUseCase.prototype.keys = function () {
|
|
27
27
|
return (this.r.keys ? this.r.keys() : []);
|
|
28
28
|
};
|
|
29
|
-
|
|
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
|
-
}(
|
|
33
|
+
}());
|
|
42
34
|
exports.ViewUseCase = ViewUseCase;
|
|
43
|
-
var
|
|
44
|
-
__extends(
|
|
45
|
-
function
|
|
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
|
|
49
|
-
}(
|
|
50
|
-
exports.
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
60
|
-
return this.
|
|
48
|
+
SearchUseCase.prototype.search = function (s, limit, page, fields) {
|
|
49
|
+
return this.repo.search(s, limit, page, fields);
|
|
61
50
|
};
|
|
62
|
-
return
|
|
63
|
-
}(
|
|
64
|
-
exports.
|
|
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
|
-
|
|
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
|
-
|
|
82
|
-
return this.
|
|
63
|
+
ViewSearchUseCase.prototype.search = function (s, limit, page, fields) {
|
|
64
|
+
return this.repo.search(s, limit, page, fields);
|
|
83
65
|
};
|
|
84
|
-
return
|
|
85
|
-
}(
|
|
86
|
-
exports.
|
|
87
|
-
var
|
|
88
|
-
__extends(
|
|
89
|
-
function
|
|
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
|
|
93
|
-
}(
|
|
94
|
-
exports.
|
|
95
|
-
var
|
|
96
|
-
__extends(
|
|
97
|
-
function
|
|
98
|
-
var _this = _super.call(this,
|
|
99
|
-
_this.
|
|
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
|
-
|
|
107
|
-
return this.
|
|
88
|
+
GenericUseCase.prototype.create = function (obj, ctx) {
|
|
89
|
+
return this.repo.create(obj, ctx);
|
|
108
90
|
};
|
|
109
|
-
|
|
110
|
-
return this.
|
|
91
|
+
GenericUseCase.prototype.update = function (obj, ctx) {
|
|
92
|
+
return this.repo.update(obj, ctx);
|
|
111
93
|
};
|
|
112
|
-
|
|
113
|
-
return (this.
|
|
94
|
+
GenericUseCase.prototype.patch = function (obj, ctx) {
|
|
95
|
+
return (this.repo.patch ? this.repo.patch(obj, ctx) : Promise.resolve(-1));
|
|
114
96
|
};
|
|
115
|
-
|
|
116
|
-
return (this.
|
|
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
|
-
}(
|
|
101
|
+
}(ViewUseCase));
|
|
128
102
|
exports.GenericUseCase = GenericUseCase;
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
}(
|
|
115
|
+
}(GenericUseCase));
|
|
174
116
|
exports.UseCase = UseCase;
|
|
175
|
-
var
|
|
176
|
-
__extends(
|
|
177
|
-
function
|
|
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
|
|
189
|
-
}(
|
|
190
|
-
exports.
|
|
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
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
|
|
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
|
|
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
|
|
154
|
-
constructor(
|
|
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.
|
|
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
|
|
164
|
-
|
|
165
|
-
|
|
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.
|
|
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
|
|
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
|
|
180
|
-
constructor(
|
|
181
|
-
super(
|
|
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.
|
|
186
|
+
return this.repo.create(obj, ctx);
|
|
189
187
|
}
|
|
190
188
|
update(obj: T, ctx?: any): Promise<number> {
|
|
191
|
-
return this.
|
|
189
|
+
return this.repo.update(obj, ctx);
|
|
192
190
|
}
|
|
193
191
|
patch(obj: Partial<T>, ctx?: any): Promise<number> {
|
|
194
|
-
return (this.
|
|
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.
|
|
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
|
|
202
|
-
|
|
203
|
-
|
|
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.
|
|
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
|
|
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>
|