onecore 0.5.0 → 0.5.2
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 +78 -91
- package/package.json +1 -1
- package/src/index.ts +74 -58
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(
|
|
45
|
-
this.
|
|
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.
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
return this.
|
|
65
|
-
};
|
|
66
|
-
return
|
|
67
|
-
}(
|
|
68
|
-
exports.
|
|
69
|
-
var
|
|
70
|
-
__extends(
|
|
71
|
-
function
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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(
|
|
80
|
-
var _this = _super.call(this,
|
|
81
|
-
_this.
|
|
82
|
-
_this.
|
|
83
|
-
_this.
|
|
84
|
-
_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.
|
|
89
|
-
return this.
|
|
98
|
+
GenericUseCase.prototype.metadata = function () {
|
|
99
|
+
return (this.repository.metadata ? this.repository.metadata() : undefined);
|
|
90
100
|
};
|
|
91
|
-
GenericUseCase.prototype.
|
|
92
|
-
return this.
|
|
101
|
+
GenericUseCase.prototype.keys = function () {
|
|
102
|
+
return (this.repository.keys ? this.repository.keys() : []);
|
|
93
103
|
};
|
|
94
|
-
GenericUseCase.prototype.
|
|
95
|
-
return
|
|
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
|
|
108
|
+
return this.repository.delete(id, ctx);
|
|
99
109
|
};
|
|
100
110
|
return GenericUseCase;
|
|
101
|
-
}(
|
|
111
|
+
}(Writer));
|
|
102
112
|
exports.GenericUseCase = GenericUseCase;
|
|
113
|
+
exports.CRUDUseCase = GenericUseCase;
|
|
103
114
|
exports.GenericManager = GenericUseCase;
|
|
104
|
-
|
|
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() {
|
|
@@ -166,3 +149,7 @@ var SavedUseCase = (function (_super) {
|
|
|
166
149
|
return SavedUseCase;
|
|
167
150
|
}(SavedService));
|
|
168
151
|
exports.SavedUseCase = SavedUseCase;
|
|
152
|
+
function isSuccessful(res) {
|
|
153
|
+
return (typeof res === "number" && res <= 0) || Array.isArray(res) ? false : true;
|
|
154
|
+
}
|
|
155
|
+
exports.isSuccessful = isSuccessful;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -55,16 +55,10 @@ export type Log = (msg: string) => void;
|
|
|
55
55
|
export type LogFunc = Log;
|
|
56
56
|
|
|
57
57
|
import { Attributes } from './metadata';
|
|
58
|
-
import { Filter, SearchResult } from './model';
|
|
59
|
-
// import { GenericRepository } from './repository/GenericRepository';
|
|
60
|
-
import { ViewRepository } from './repository/ViewRepository';
|
|
58
|
+
import { ErrorMessage, Filter, SearchResult } from './model';
|
|
61
59
|
import { GenericSearchService } from './service/GenericSearchService';
|
|
62
|
-
// import { GenericSearchService } from './service/GenericSearchService';
|
|
63
60
|
import { GenericService } from './service/GenericService';
|
|
64
|
-
import { ViewSearchService } from './service/ViewSearchService';
|
|
65
|
-
import { ViewService } from './service/ViewService';
|
|
66
61
|
import { SearchRepository } from './repository/SearchRepository';
|
|
67
|
-
import { ViewSearchRepository } from './repository/ViewSearchRepository';
|
|
68
62
|
import { GenericSearchRepository } from './repository/GenericSearchRepository';
|
|
69
63
|
|
|
70
64
|
export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
@@ -129,85 +123,107 @@ export interface ExportService {
|
|
|
129
123
|
export interface Exporter {
|
|
130
124
|
export(ctx?: any): Promise<number>;
|
|
131
125
|
}
|
|
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
126
|
|
|
153
127
|
// tslint:disable-next-line:max-classes-per-file
|
|
154
128
|
export class SearchUseCase<T, F extends Filter> {
|
|
155
|
-
constructor(protected
|
|
129
|
+
constructor(protected repository: SearchRepository<T, F>) {
|
|
156
130
|
this.search = this.search.bind(this);
|
|
157
131
|
}
|
|
158
132
|
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
159
|
-
return this.
|
|
133
|
+
return this.repository.search(s, limit, page, fields);
|
|
160
134
|
}
|
|
161
135
|
}
|
|
162
136
|
export const SearchManager = SearchUseCase
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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> {
|
|
137
|
+
|
|
138
|
+
interface WriterRepo<T> {
|
|
139
|
+
create(obj: T, ctx?: any): Promise<number>;
|
|
140
|
+
update(obj: T, ctx?: any): Promise<number>;
|
|
141
|
+
patch(obj: Partial<T>, ctx?: any): Promise<number>;
|
|
175
142
|
}
|
|
176
143
|
// tslint:disable-next-line:max-classes-per-file
|
|
177
|
-
export class
|
|
178
|
-
constructor(
|
|
179
|
-
super(repo);
|
|
144
|
+
export class Writer<T> {
|
|
145
|
+
constructor(protected repository: WriterRepo<T>) {
|
|
180
146
|
this.create = this.create.bind(this);
|
|
181
147
|
this.update = this.update.bind(this);
|
|
182
148
|
this.patch = this.patch.bind(this);
|
|
183
|
-
this.delete = this.delete.bind(this);
|
|
184
149
|
}
|
|
185
150
|
create(obj: T, ctx?: any): Promise<number> {
|
|
186
|
-
return this.
|
|
151
|
+
return this.repository.create(obj, ctx);
|
|
187
152
|
}
|
|
188
153
|
update(obj: T, ctx?: any): Promise<number> {
|
|
189
|
-
return this.
|
|
154
|
+
return this.repository.update(obj, ctx);
|
|
190
155
|
}
|
|
191
156
|
patch(obj: Partial<T>, ctx?: any): Promise<number> {
|
|
192
|
-
return (this.
|
|
157
|
+
return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
|
|
193
158
|
}
|
|
194
|
-
|
|
195
|
-
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface SearchWriterRepo<T, F extends Filter> {
|
|
162
|
+
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>>
|
|
163
|
+
create(obj: T, ctx?: any): Promise<number>;
|
|
164
|
+
update(obj: T, ctx?: any): Promise<number>;
|
|
165
|
+
patch(obj: Partial<T>, ctx?: any): Promise<number>;
|
|
166
|
+
}
|
|
167
|
+
// tslint:disable-next-line:max-classes-per-file
|
|
168
|
+
export class SearchWriter<T, F extends Filter> extends Writer<T> {
|
|
169
|
+
constructor(protected repository: SearchWriterRepo<T, F>) {
|
|
170
|
+
super(repository)
|
|
171
|
+
this.search = this.search.bind(this);
|
|
172
|
+
}
|
|
173
|
+
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
174
|
+
return this.repository.search(s, limit, page, fields);
|
|
196
175
|
}
|
|
197
176
|
}
|
|
198
|
-
|
|
177
|
+
|
|
199
178
|
// tslint:disable-next-line:max-classes-per-file
|
|
200
|
-
export class UseCase<T, ID, F extends Filter> extends
|
|
179
|
+
export class UseCase<T, ID, F extends Filter> extends SearchWriter<T, F> implements GenericSearchService<T, ID, number, F> {
|
|
201
180
|
constructor(protected repository: GenericSearchRepository<T, ID, F>) {
|
|
202
181
|
super(repository);
|
|
182
|
+
this.metadata = this.metadata.bind(this);
|
|
183
|
+
this.keys = this.keys.bind(this);
|
|
184
|
+
this.load = this.load.bind(this);
|
|
185
|
+
this.delete = this.delete.bind(this);
|
|
203
186
|
}
|
|
204
|
-
|
|
205
|
-
return this.repository.
|
|
187
|
+
metadata(): Attributes|undefined {
|
|
188
|
+
return (this.repository.metadata ? this.repository.metadata() : undefined);
|
|
189
|
+
}
|
|
190
|
+
keys(): string[] {
|
|
191
|
+
return (this.repository.keys ? this.repository.keys() : []);
|
|
192
|
+
}
|
|
193
|
+
load(id: ID, ctx?: any): Promise<T | null> {
|
|
194
|
+
return this.repository.load(id, ctx);
|
|
195
|
+
}
|
|
196
|
+
delete(id: ID, ctx?: any): Promise<number> {
|
|
197
|
+
return this.repository.delete(id, ctx);
|
|
206
198
|
}
|
|
207
199
|
}
|
|
200
|
+
|
|
208
201
|
// tslint:disable-next-line:max-classes-per-file
|
|
209
|
-
export class
|
|
202
|
+
export class GenericUseCase<T, ID> extends Writer<T> implements GenericService<T, ID, number> {
|
|
203
|
+
constructor(protected repository: GenericRepository<T, ID>) {
|
|
204
|
+
super(repository);
|
|
205
|
+
this.metadata = this.metadata.bind(this);
|
|
206
|
+
this.keys = this.keys.bind(this);
|
|
207
|
+
this.load = this.load.bind(this);
|
|
208
|
+
this.delete = this.delete.bind(this);
|
|
209
|
+
}
|
|
210
|
+
metadata(): Attributes|undefined {
|
|
211
|
+
return (this.repository.metadata ? this.repository.metadata() : undefined);
|
|
212
|
+
}
|
|
213
|
+
keys(): string[] {
|
|
214
|
+
return (this.repository.keys ? this.repository.keys() : []);
|
|
215
|
+
}
|
|
216
|
+
load(id: ID, ctx?: any): Promise<T | null> {
|
|
217
|
+
return this.repository.load(id, ctx);
|
|
218
|
+
}
|
|
219
|
+
delete(id: ID, ctx?: any): Promise<number> {
|
|
220
|
+
return this.repository.delete(id, ctx);
|
|
221
|
+
}
|
|
210
222
|
}
|
|
223
|
+
export const CRUDUseCase = GenericUseCase
|
|
224
|
+
export const GenericManager = GenericUseCase
|
|
225
|
+
export const CRUDManager = GenericUseCase
|
|
226
|
+
|
|
211
227
|
export interface SavedRepository<UID, ID> {
|
|
212
228
|
isSaved(userId: UID, id: ID): Promise<boolean>
|
|
213
229
|
save(userId: UID, id: ID): Promise<number>
|
|
@@ -239,8 +255,8 @@ export class SavedService<UID, ID> {
|
|
|
239
255
|
}
|
|
240
256
|
}
|
|
241
257
|
// 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
258
|
export class SavedUseCase<ID, T> extends SavedService<ID, T> {
|
|
246
259
|
}
|
|
260
|
+
export function isSuccessful<T>(res: number | T | ErrorMessage[]): boolean {
|
|
261
|
+
return (typeof res === "number" && res <= 0) || Array.isArray(res) ? false : true
|
|
262
|
+
}
|