onecore 0.2.0 → 0.3.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 +56 -121
- package/package.json +1 -1
- package/src/index.ts +18 -38
package/lib/index.js
CHANGED
|
@@ -13,88 +13,70 @@ 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
|
|
74
|
+
return ViewSearchManger;
|
|
75
|
+
}(ViewSearchUseCase));
|
|
76
|
+
exports.ViewSearchManger = ViewSearchManger;
|
|
77
|
+
var GenericUseCase = (function (_super) {
|
|
78
|
+
__extends(GenericUseCase, _super);
|
|
79
|
+
function GenericUseCase(repository) {
|
|
98
80
|
var _this = _super.call(this, repository) || this;
|
|
99
81
|
_this.repository = repository;
|
|
100
82
|
_this.create = _this.create.bind(_this);
|
|
@@ -103,91 +85,44 @@ var GenericManager = (function (_super) {
|
|
|
103
85
|
_this.delete = _this.delete.bind(_this);
|
|
104
86
|
return _this;
|
|
105
87
|
}
|
|
106
|
-
|
|
88
|
+
GenericUseCase.prototype.create = function (obj, ctx) {
|
|
107
89
|
return this.repository.create(obj, ctx);
|
|
108
90
|
};
|
|
109
|
-
|
|
91
|
+
GenericUseCase.prototype.update = function (obj, ctx) {
|
|
110
92
|
return this.repository.update(obj, ctx);
|
|
111
93
|
};
|
|
112
|
-
|
|
94
|
+
GenericUseCase.prototype.patch = function (obj, ctx) {
|
|
113
95
|
return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
|
|
114
96
|
};
|
|
115
|
-
|
|
97
|
+
GenericUseCase.prototype.delete = function (id, ctx) {
|
|
116
98
|
return (this.repository.delete ? this.repository.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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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) {
|
|
103
|
+
exports.GenericManager = GenericUseCase;
|
|
104
|
+
var UseCase = (function (_super) {
|
|
105
|
+
__extends(UseCase, _super);
|
|
106
|
+
function UseCase(find, repo) {
|
|
156
107
|
var _this = _super.call(this, repo) || this;
|
|
157
108
|
_this.find = find;
|
|
158
109
|
_this.search = _this.search.bind(_this);
|
|
159
110
|
return _this;
|
|
160
111
|
}
|
|
161
|
-
|
|
112
|
+
UseCase.prototype.search = function (s, limit, page, fields) {
|
|
162
113
|
return this.find(s, limit, page, fields);
|
|
163
114
|
};
|
|
164
|
-
return Manager;
|
|
165
|
-
}(GenericManager));
|
|
166
|
-
exports.Manager = Manager;
|
|
167
|
-
var UseCase = (function (_super) {
|
|
168
|
-
__extends(UseCase, _super);
|
|
169
|
-
function UseCase() {
|
|
170
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
171
|
-
}
|
|
172
115
|
return UseCase;
|
|
173
|
-
}(
|
|
116
|
+
}(GenericUseCase));
|
|
174
117
|
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() {
|
|
118
|
+
var Manager = (function (_super) {
|
|
119
|
+
__extends(Manager, _super);
|
|
120
|
+
function Manager() {
|
|
186
121
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
187
122
|
}
|
|
188
|
-
return
|
|
189
|
-
}(
|
|
190
|
-
exports.
|
|
123
|
+
return Manager;
|
|
124
|
+
}(UseCase));
|
|
125
|
+
exports.Manager = Manager;
|
|
191
126
|
var SavedService = (function () {
|
|
192
127
|
function SavedService(savedRepository, max) {
|
|
193
128
|
this.savedRepository = savedRepository;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -63,6 +63,8 @@ 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';
|
|
66
68
|
|
|
67
69
|
export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
68
70
|
export type SearchFunc<T, F> = Search<T, F>;
|
|
@@ -126,7 +128,7 @@ export interface ExportService {
|
|
|
126
128
|
export interface Exporter {
|
|
127
129
|
export(ctx?: any): Promise<number>;
|
|
128
130
|
}
|
|
129
|
-
export class
|
|
131
|
+
export class ViewUseCase<T, ID> implements ViewService<T, ID> {
|
|
130
132
|
constructor(private r: ViewRepository<T, ID>) {
|
|
131
133
|
this.metadata = this.metadata.bind(this);
|
|
132
134
|
this.keys = this.keys.bind(this);
|
|
@@ -142,41 +144,36 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
|
|
|
142
144
|
return this.r.load(id, ctx);
|
|
143
145
|
}
|
|
144
146
|
}
|
|
147
|
+
|
|
145
148
|
// 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> {
|
|
149
|
+
export class ViewManager<T, ID> extends ViewUseCase<T, ID> {
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// tslint:disable-next-line:max-classes-per-file
|
|
153
|
-
export class
|
|
154
|
-
constructor(
|
|
155
|
-
super(repo);
|
|
153
|
+
export class SearchUseCase<T, F extends Filter> {
|
|
154
|
+
constructor(protected repo: SearchRepository<T, F>) {
|
|
156
155
|
this.search = this.search.bind(this);
|
|
157
156
|
}
|
|
158
157
|
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
159
|
-
return this.
|
|
158
|
+
return this.repo.search(s, limit, page, fields);
|
|
160
159
|
}
|
|
161
160
|
}
|
|
161
|
+
export const SearchManager = SearchUseCase
|
|
162
162
|
// 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);
|
|
163
|
+
export class ViewSearchUseCase<T, ID, F extends Filter> extends ViewUseCase<T, ID> implements ViewSearchService<T, ID, F> {
|
|
164
|
+
constructor(protected repo: ViewSearchRepository<T, ID, Filter>) {
|
|
165
|
+
super(repo);
|
|
169
166
|
this.search = this.search.bind(this);
|
|
170
167
|
}
|
|
171
168
|
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
172
|
-
return this.
|
|
169
|
+
return this.repo.search(s, limit, page, fields);
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
172
|
// tslint:disable-next-line:max-classes-per-file
|
|
176
|
-
export class
|
|
173
|
+
export class ViewSearchManger<T, ID, F extends Filter> extends ViewSearchUseCase<T, ID, F> {
|
|
177
174
|
}
|
|
178
175
|
// tslint:disable-next-line:max-classes-per-file
|
|
179
|
-
export class
|
|
176
|
+
export class GenericUseCase<T, ID> extends ViewUseCase<T, ID> implements GenericService<T, ID, number> {
|
|
180
177
|
constructor(protected repository: GenericRepository<T, ID>) {
|
|
181
178
|
super(repository);
|
|
182
179
|
this.create = this.create.bind(this);
|
|
@@ -197,20 +194,9 @@ export class GenericManager<T, ID> extends ViewManager<T, ID> implements Generic
|
|
|
197
194
|
return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
|
|
198
195
|
}
|
|
199
196
|
}
|
|
197
|
+
export const GenericManager = GenericUseCase
|
|
200
198
|
// tslint:disable-next-line:max-classes-per-file
|
|
201
|
-
export class
|
|
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> {
|
|
199
|
+
export class UseCase<T, ID, F extends Filter> extends GenericUseCase<T, ID> implements GenericSearchService<T, ID, number, F> {
|
|
214
200
|
constructor(public find: Search<T, F>, repo: GenericRepository<T, ID>) {
|
|
215
201
|
super(repo);
|
|
216
202
|
this.search = this.search.bind(this);
|
|
@@ -220,13 +206,7 @@ export class Manager<T, ID, F extends Filter> extends GenericManager<T, ID> impl
|
|
|
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>
|