onecore 0.3.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 +11 -12
- package/package.json +1 -1
- package/src/index.ts +10 -10
package/lib/index.js
CHANGED
|
@@ -76,9 +76,9 @@ var ViewSearchManger = (function (_super) {
|
|
|
76
76
|
exports.ViewSearchManger = ViewSearchManger;
|
|
77
77
|
var GenericUseCase = (function (_super) {
|
|
78
78
|
__extends(GenericUseCase, _super);
|
|
79
|
-
function GenericUseCase(
|
|
80
|
-
var _this = _super.call(this,
|
|
81
|
-
_this.
|
|
79
|
+
function GenericUseCase(repo) {
|
|
80
|
+
var _this = _super.call(this, repo) || this;
|
|
81
|
+
_this.repo = repo;
|
|
82
82
|
_this.create = _this.create.bind(_this);
|
|
83
83
|
_this.update = _this.update.bind(_this);
|
|
84
84
|
_this.patch = _this.patch.bind(_this);
|
|
@@ -86,16 +86,16 @@ var GenericUseCase = (function (_super) {
|
|
|
86
86
|
return _this;
|
|
87
87
|
}
|
|
88
88
|
GenericUseCase.prototype.create = function (obj, ctx) {
|
|
89
|
-
return this.
|
|
89
|
+
return this.repo.create(obj, ctx);
|
|
90
90
|
};
|
|
91
91
|
GenericUseCase.prototype.update = function (obj, ctx) {
|
|
92
|
-
return this.
|
|
92
|
+
return this.repo.update(obj, ctx);
|
|
93
93
|
};
|
|
94
94
|
GenericUseCase.prototype.patch = function (obj, ctx) {
|
|
95
|
-
return (this.
|
|
95
|
+
return (this.repo.patch ? this.repo.patch(obj, ctx) : Promise.resolve(-1));
|
|
96
96
|
};
|
|
97
97
|
GenericUseCase.prototype.delete = function (id, ctx) {
|
|
98
|
-
return (this.
|
|
98
|
+
return (this.repo.delete ? this.repo.delete(id, ctx) : Promise.resolve(-1));
|
|
99
99
|
};
|
|
100
100
|
return GenericUseCase;
|
|
101
101
|
}(ViewUseCase));
|
|
@@ -103,14 +103,13 @@ exports.GenericUseCase = GenericUseCase;
|
|
|
103
103
|
exports.GenericManager = GenericUseCase;
|
|
104
104
|
var UseCase = (function (_super) {
|
|
105
105
|
__extends(UseCase, _super);
|
|
106
|
-
function UseCase(
|
|
107
|
-
var _this = _super.call(this,
|
|
108
|
-
_this.
|
|
109
|
-
_this.search = _this.search.bind(_this);
|
|
106
|
+
function UseCase(repository) {
|
|
107
|
+
var _this = _super.call(this, repository) || this;
|
|
108
|
+
_this.repository = repository;
|
|
110
109
|
return _this;
|
|
111
110
|
}
|
|
112
111
|
UseCase.prototype.search = function (s, limit, page, fields) {
|
|
113
|
-
return this.
|
|
112
|
+
return this.repository.search(s, limit, page, fields);
|
|
114
113
|
};
|
|
115
114
|
return UseCase;
|
|
116
115
|
}(GenericUseCase));
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -65,6 +65,7 @@ import { ViewSearchService } from './service/ViewSearchService';
|
|
|
65
65
|
import { ViewService } from './service/ViewService';
|
|
66
66
|
import { SearchRepository } from './repository/SearchRepository';
|
|
67
67
|
import { ViewSearchRepository } from './repository/ViewSearchRepository';
|
|
68
|
+
import { GenericSearchRepository } from './repository/GenericSearchRepository';
|
|
68
69
|
|
|
69
70
|
export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
70
71
|
export type SearchFunc<T, F> = Search<T, F>;
|
|
@@ -174,35 +175,34 @@ export class ViewSearchManger<T, ID, F extends Filter> extends ViewSearchUseCase
|
|
|
174
175
|
}
|
|
175
176
|
// tslint:disable-next-line:max-classes-per-file
|
|
176
177
|
export class GenericUseCase<T, ID> extends ViewUseCase<T, ID> implements GenericService<T, ID, number> {
|
|
177
|
-
constructor(
|
|
178
|
-
super(
|
|
178
|
+
constructor(private repo: GenericRepository<T, ID>) {
|
|
179
|
+
super(repo);
|
|
179
180
|
this.create = this.create.bind(this);
|
|
180
181
|
this.update = this.update.bind(this);
|
|
181
182
|
this.patch = this.patch.bind(this);
|
|
182
183
|
this.delete = this.delete.bind(this);
|
|
183
184
|
}
|
|
184
185
|
create(obj: T, ctx?: any): Promise<number> {
|
|
185
|
-
return this.
|
|
186
|
+
return this.repo.create(obj, ctx);
|
|
186
187
|
}
|
|
187
188
|
update(obj: T, ctx?: any): Promise<number> {
|
|
188
|
-
return this.
|
|
189
|
+
return this.repo.update(obj, ctx);
|
|
189
190
|
}
|
|
190
191
|
patch(obj: Partial<T>, ctx?: any): Promise<number> {
|
|
191
|
-
return (this.
|
|
192
|
+
return (this.repo.patch ? this.repo.patch(obj, ctx) : Promise.resolve(-1));
|
|
192
193
|
}
|
|
193
194
|
delete(id: ID, ctx?: any): Promise<number> {
|
|
194
|
-
return (this.
|
|
195
|
+
return (this.repo.delete ? this.repo.delete(id, ctx) : Promise.resolve(-1));
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
export const GenericManager = GenericUseCase
|
|
198
199
|
// tslint:disable-next-line:max-classes-per-file
|
|
199
200
|
export class UseCase<T, ID, F extends Filter> extends GenericUseCase<T, ID> implements GenericSearchService<T, ID, number, F> {
|
|
200
|
-
constructor(
|
|
201
|
-
super(
|
|
202
|
-
this.search = this.search.bind(this);
|
|
201
|
+
constructor(protected repository: GenericSearchRepository<T, ID, F>) {
|
|
202
|
+
super(repository);
|
|
203
203
|
}
|
|
204
204
|
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
205
|
-
return this.
|
|
205
|
+
return this.repository.search(s, limit, page, fields);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
// tslint:disable-next-line:max-classes-per-file
|