onecore 0.1.2 → 0.1.3
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 +76 -65
- package/package.json +1 -1
- package/src/index.ts +5 -5
- package/src/repository/GenericRepository.ts +2 -2
- package/src/service/GenericService.ts +1 -1
package/lib/index.js
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
2
|
+
var __extends =
|
|
3
|
+
(this && this.__extends) ||
|
|
4
|
+
(function () {
|
|
5
|
+
var extendStatics = function (d, b) {
|
|
6
|
+
extendStatics =
|
|
7
|
+
Object.setPrototypeOf ||
|
|
8
|
+
({ __proto__: [] } instanceof Array &&
|
|
9
|
+
function (d, b) {
|
|
10
|
+
d.__proto__ = b;
|
|
11
|
+
}) ||
|
|
12
|
+
function (d, b) {
|
|
13
|
+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
14
|
+
};
|
|
15
|
+
return extendStatics(d, b);
|
|
16
|
+
};
|
|
17
|
+
return function (d, b) {
|
|
18
|
+
extendStatics(d, b);
|
|
19
|
+
function __() {
|
|
20
|
+
this.constructor = d;
|
|
21
|
+
}
|
|
22
|
+
d.prototype =
|
|
23
|
+
b === null
|
|
24
|
+
? Object.create(b)
|
|
25
|
+
: ((__.prototype = b.prototype), new __());
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
15
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
29
|
var ViewManager = (function () {
|
|
17
30
|
function ViewManager(r) {
|
|
@@ -21,32 +34,32 @@ var ViewManager = (function () {
|
|
|
21
34
|
this.load = this.load.bind(this);
|
|
22
35
|
}
|
|
23
36
|
ViewManager.prototype.metadata = function () {
|
|
24
|
-
return
|
|
37
|
+
return this.r.metadata ? this.r.metadata() : undefined;
|
|
25
38
|
};
|
|
26
39
|
ViewManager.prototype.keys = function () {
|
|
27
|
-
return
|
|
40
|
+
return this.r.keys ? this.r.keys() : [];
|
|
28
41
|
};
|
|
29
42
|
ViewManager.prototype.load = function (id, ctx) {
|
|
30
43
|
return this.r.load(id, ctx);
|
|
31
44
|
};
|
|
32
45
|
return ViewManager;
|
|
33
|
-
}()
|
|
46
|
+
})();
|
|
34
47
|
exports.ViewManager = ViewManager;
|
|
35
48
|
var ViewUseCase = (function (_super) {
|
|
36
49
|
__extends(ViewUseCase, _super);
|
|
37
50
|
function ViewUseCase() {
|
|
38
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
51
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
39
52
|
}
|
|
40
53
|
return ViewUseCase;
|
|
41
|
-
}(ViewManager)
|
|
54
|
+
})(ViewManager);
|
|
42
55
|
exports.ViewUseCase = ViewUseCase;
|
|
43
56
|
var DefaultViewService = (function (_super) {
|
|
44
57
|
__extends(DefaultViewService, _super);
|
|
45
58
|
function DefaultViewService() {
|
|
46
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
59
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
47
60
|
}
|
|
48
61
|
return DefaultViewService;
|
|
49
|
-
}(ViewManager)
|
|
62
|
+
})(ViewManager);
|
|
50
63
|
exports.DefaultViewService = DefaultViewService;
|
|
51
64
|
var ViewSearchManager = (function (_super) {
|
|
52
65
|
__extends(ViewSearchManager, _super);
|
|
@@ -60,15 +73,15 @@ var ViewSearchManager = (function (_super) {
|
|
|
60
73
|
return this.find(s, limit, offset, fields);
|
|
61
74
|
};
|
|
62
75
|
return ViewSearchManager;
|
|
63
|
-
}(ViewManager)
|
|
76
|
+
})(ViewManager);
|
|
64
77
|
exports.ViewSearchManager = ViewSearchManager;
|
|
65
78
|
var ViewSearchUseCase = (function (_super) {
|
|
66
79
|
__extends(ViewSearchUseCase, _super);
|
|
67
80
|
function ViewSearchUseCase() {
|
|
68
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
81
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
69
82
|
}
|
|
70
83
|
return ViewSearchUseCase;
|
|
71
|
-
}(ViewSearchManager)
|
|
84
|
+
})(ViewSearchManager);
|
|
72
85
|
exports.ViewSearchUseCase = ViewSearchUseCase;
|
|
73
86
|
var SearchManager = (function (_super) {
|
|
74
87
|
__extends(SearchManager, _super);
|
|
@@ -82,73 +95,77 @@ var SearchManager = (function (_super) {
|
|
|
82
95
|
return this.repository.search(s, limit, offset, fields);
|
|
83
96
|
};
|
|
84
97
|
return SearchManager;
|
|
85
|
-
}(ViewManager)
|
|
98
|
+
})(ViewManager);
|
|
86
99
|
exports.SearchManager = SearchManager;
|
|
87
100
|
var SearchUseCase = (function (_super) {
|
|
88
101
|
__extends(SearchUseCase, _super);
|
|
89
102
|
function SearchUseCase() {
|
|
90
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
103
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
91
104
|
}
|
|
92
105
|
return SearchUseCase;
|
|
93
|
-
}(SearchManager)
|
|
106
|
+
})(SearchManager);
|
|
94
107
|
exports.SearchUseCase = SearchUseCase;
|
|
95
108
|
var GenericManager = (function (_super) {
|
|
96
109
|
__extends(GenericManager, _super);
|
|
97
110
|
function GenericManager(repository) {
|
|
98
111
|
var _this = _super.call(this, repository) || this;
|
|
99
112
|
_this.repository = repository;
|
|
100
|
-
_this.
|
|
113
|
+
_this.create = _this.create.bind(_this);
|
|
101
114
|
_this.update = _this.update.bind(_this);
|
|
102
115
|
_this.patch = _this.patch.bind(_this);
|
|
103
116
|
_this.delete = _this.delete.bind(_this);
|
|
104
117
|
return _this;
|
|
105
118
|
}
|
|
106
|
-
GenericManager.prototype.
|
|
107
|
-
return this.repository.
|
|
119
|
+
GenericManager.prototype.create = function (obj, ctx) {
|
|
120
|
+
return this.repository.create(obj, ctx);
|
|
108
121
|
};
|
|
109
122
|
GenericManager.prototype.update = function (obj, ctx) {
|
|
110
123
|
return this.repository.update(obj, ctx);
|
|
111
124
|
};
|
|
112
125
|
GenericManager.prototype.patch = function (obj, ctx) {
|
|
113
|
-
return
|
|
126
|
+
return this.repository.patch
|
|
127
|
+
? this.repository.patch(obj, ctx)
|
|
128
|
+
: Promise.resolve(-1);
|
|
114
129
|
};
|
|
115
130
|
GenericManager.prototype.delete = function (id, ctx) {
|
|
116
|
-
return
|
|
131
|
+
return this.repository.delete
|
|
132
|
+
? this.repository.delete(id, ctx)
|
|
133
|
+
: Promise.resolve(-1);
|
|
117
134
|
};
|
|
118
135
|
return GenericManager;
|
|
119
|
-
}(ViewManager)
|
|
136
|
+
})(ViewManager);
|
|
120
137
|
exports.GenericManager = GenericManager;
|
|
121
138
|
var GenericUseCase = (function (_super) {
|
|
122
139
|
__extends(GenericUseCase, _super);
|
|
123
140
|
function GenericUseCase() {
|
|
124
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
141
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
125
142
|
}
|
|
126
143
|
return GenericUseCase;
|
|
127
|
-
}(GenericManager)
|
|
144
|
+
})(GenericManager);
|
|
128
145
|
exports.GenericUseCase = GenericUseCase;
|
|
129
146
|
var DefaultGenericService = (function (_super) {
|
|
130
147
|
__extends(DefaultGenericService, _super);
|
|
131
148
|
function DefaultGenericService() {
|
|
132
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
149
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
133
150
|
}
|
|
134
151
|
return DefaultGenericService;
|
|
135
|
-
}(GenericManager)
|
|
152
|
+
})(GenericManager);
|
|
136
153
|
exports.DefaultGenericService = DefaultGenericService;
|
|
137
154
|
var DefaultService = (function (_super) {
|
|
138
155
|
__extends(DefaultService, _super);
|
|
139
156
|
function DefaultService() {
|
|
140
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
157
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
141
158
|
}
|
|
142
159
|
return DefaultService;
|
|
143
|
-
}(GenericManager)
|
|
160
|
+
})(GenericManager);
|
|
144
161
|
exports.DefaultService = DefaultService;
|
|
145
162
|
var DefaultGenericSearchService = (function (_super) {
|
|
146
163
|
__extends(DefaultGenericSearchService, _super);
|
|
147
164
|
function DefaultGenericSearchService() {
|
|
148
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
165
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
149
166
|
}
|
|
150
167
|
return DefaultGenericSearchService;
|
|
151
|
-
}(GenericManager)
|
|
168
|
+
})(GenericManager);
|
|
152
169
|
exports.DefaultGenericSearchService = DefaultGenericSearchService;
|
|
153
170
|
var Manager = (function (_super) {
|
|
154
171
|
__extends(Manager, _super);
|
|
@@ -162,31 +179,31 @@ var Manager = (function (_super) {
|
|
|
162
179
|
return this.find(s, limit, offset, fields);
|
|
163
180
|
};
|
|
164
181
|
return Manager;
|
|
165
|
-
}(GenericManager)
|
|
182
|
+
})(GenericManager);
|
|
166
183
|
exports.Manager = Manager;
|
|
167
184
|
var UseCase = (function (_super) {
|
|
168
185
|
__extends(UseCase, _super);
|
|
169
186
|
function UseCase() {
|
|
170
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
187
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
171
188
|
}
|
|
172
189
|
return UseCase;
|
|
173
|
-
}(Manager)
|
|
190
|
+
})(Manager);
|
|
174
191
|
exports.UseCase = UseCase;
|
|
175
192
|
var GenericSearchManager = (function (_super) {
|
|
176
193
|
__extends(GenericSearchManager, _super);
|
|
177
194
|
function GenericSearchManager() {
|
|
178
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
195
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
179
196
|
}
|
|
180
197
|
return GenericSearchManager;
|
|
181
|
-
}(Manager)
|
|
198
|
+
})(Manager);
|
|
182
199
|
exports.GenericSearchManager = GenericSearchManager;
|
|
183
200
|
var GenericSearchUseCase = (function (_super) {
|
|
184
201
|
__extends(GenericSearchUseCase, _super);
|
|
185
202
|
function GenericSearchUseCase() {
|
|
186
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
203
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
187
204
|
}
|
|
188
205
|
return GenericSearchUseCase;
|
|
189
|
-
}(Manager)
|
|
206
|
+
})(Manager);
|
|
190
207
|
exports.GenericSearchUseCase = GenericSearchUseCase;
|
|
191
208
|
var SavedService = (function () {
|
|
192
209
|
function SavedService(repository, query, max, autoRemove) {
|
|
@@ -211,24 +228,20 @@ var SavedService = (function () {
|
|
|
211
228
|
var _this = this;
|
|
212
229
|
return this.repository.load(id).then(function (items) {
|
|
213
230
|
if (items == null) {
|
|
214
|
-
return _this.repository.
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
231
|
+
return _this.repository.create(id, [itemId]);
|
|
232
|
+
} else {
|
|
217
233
|
if (items.includes(itemId)) {
|
|
218
234
|
return Promise.resolve(0);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
235
|
+
} else {
|
|
221
236
|
items.push(itemId);
|
|
222
237
|
if (items.length > _this.max) {
|
|
223
238
|
if (_this.autoRemove) {
|
|
224
239
|
items.shift();
|
|
225
240
|
return _this.repository.update(id, items);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
241
|
+
} else {
|
|
228
242
|
return Promise.resolve(-1);
|
|
229
243
|
}
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
244
|
+
} else {
|
|
232
245
|
return _this.repository.update(id, items);
|
|
233
246
|
}
|
|
234
247
|
}
|
|
@@ -240,36 +253,34 @@ var SavedService = (function () {
|
|
|
240
253
|
return this.repository.load(id).then(function (items) {
|
|
241
254
|
if (items == null) {
|
|
242
255
|
return Promise.resolve(0);
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
256
|
+
} else {
|
|
245
257
|
if (items.includes(itemId)) {
|
|
246
258
|
items = items.filter(function (item) {
|
|
247
259
|
return item !== itemId;
|
|
248
260
|
});
|
|
249
261
|
return _this.repository.update(id, items);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
262
|
+
} else {
|
|
252
263
|
return Promise.resolve(0);
|
|
253
264
|
}
|
|
254
265
|
}
|
|
255
266
|
});
|
|
256
267
|
};
|
|
257
268
|
return SavedService;
|
|
258
|
-
}()
|
|
269
|
+
})();
|
|
259
270
|
exports.SavedService = SavedService;
|
|
260
271
|
var SavedManager = (function (_super) {
|
|
261
272
|
__extends(SavedManager, _super);
|
|
262
273
|
function SavedManager() {
|
|
263
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
274
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
264
275
|
}
|
|
265
276
|
return SavedManager;
|
|
266
|
-
}(SavedService)
|
|
277
|
+
})(SavedService);
|
|
267
278
|
exports.SavedManager = SavedManager;
|
|
268
279
|
var SavedUseCase = (function (_super) {
|
|
269
280
|
__extends(SavedUseCase, _super);
|
|
270
281
|
function SavedUseCase() {
|
|
271
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
282
|
+
return (_super !== null && _super.apply(this, arguments)) || this;
|
|
272
283
|
}
|
|
273
284
|
return SavedUseCase;
|
|
274
|
-
}(SavedService)
|
|
285
|
+
})(SavedService);
|
|
275
286
|
exports.SavedUseCase = SavedUseCase;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -179,13 +179,13 @@ export class SearchUseCase<T, ID, F extends Filter> extends SearchManager<T, ID,
|
|
|
179
179
|
export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
|
|
180
180
|
constructor(protected repository: GenericRepository<T, ID>) {
|
|
181
181
|
super(repository);
|
|
182
|
-
this.
|
|
182
|
+
this.create = this.create.bind(this);
|
|
183
183
|
this.update = this.update.bind(this);
|
|
184
184
|
this.patch = this.patch.bind(this);
|
|
185
185
|
this.delete = this.delete.bind(this);
|
|
186
186
|
}
|
|
187
|
-
|
|
188
|
-
return this.repository.
|
|
187
|
+
create(obj: T, ctx?: any): Promise<number> {
|
|
188
|
+
return this.repository.create(obj, ctx);
|
|
189
189
|
}
|
|
190
190
|
update(obj: T, ctx?: any): Promise<number> {
|
|
191
191
|
return this.repository.update(obj, ctx);
|
|
@@ -230,7 +230,7 @@ export class GenericSearchUseCase<T, ID, F extends Filter> extends Manager<T, ID
|
|
|
230
230
|
}
|
|
231
231
|
export interface SavedRepository<ID> {
|
|
232
232
|
load(id: ID): Promise<string[]|null>;
|
|
233
|
-
|
|
233
|
+
create(id: ID, arr: string[]): Promise<number>;
|
|
234
234
|
update(id: ID, arr: string[]): Promise<number>;
|
|
235
235
|
}
|
|
236
236
|
// tslint:disable-next-line:max-classes-per-file
|
|
@@ -251,7 +251,7 @@ export class SavedService<ID, T> {
|
|
|
251
251
|
save(id: ID, itemId: string): Promise<number> {
|
|
252
252
|
return this.repository.load(id).then(items => {
|
|
253
253
|
if (items == null) {
|
|
254
|
-
return this.repository.
|
|
254
|
+
return this.repository.create(id, [itemId]);
|
|
255
255
|
} else {
|
|
256
256
|
if (items.includes(itemId)) {
|
|
257
257
|
return Promise.resolve(0);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {ViewRepository} from './ViewRepository';
|
|
2
2
|
|
|
3
3
|
export interface GenericRepository<T, ID> extends ViewRepository<T, ID> {
|
|
4
|
-
|
|
4
|
+
create(obj: T, ctx?: any): Promise<number>;
|
|
5
5
|
update(obj: T, ctx?: any): Promise<number>;
|
|
6
6
|
patch(obj: Partial<T>, ctx?: any): Promise<number>;
|
|
7
7
|
delete(id: ID, ctx?: any): Promise<number>;
|
|
8
8
|
}
|
|
9
9
|
export interface Repository<T, ID> extends ViewRepository<T, ID> {
|
|
10
|
-
|
|
10
|
+
create(obj: T, ctx?: any): Promise<number>;
|
|
11
11
|
update(obj: T, ctx?: any): Promise<number>;
|
|
12
12
|
patch(obj: Partial<T>, ctx?: any): Promise<number>;
|
|
13
13
|
delete(id: ID, ctx?: any): Promise<number>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ViewService} from './ViewService';
|
|
2
2
|
|
|
3
3
|
export interface GenericService<T, ID, R> extends ViewService<T, ID> {
|
|
4
|
-
|
|
4
|
+
create(obj: T, ctx?: any): Promise<R>;
|
|
5
5
|
update(obj: T, ctx?: any): Promise<R>;
|
|
6
6
|
patch(obj: Partial<T>, ctx?: any): Promise<R>;
|
|
7
7
|
delete(id: ID, ctx?: any): Promise<number>;
|