onecore 0.3.1 → 0.5.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 +74 -91
- package/package.json +1 -1
- package/src/index.ts +70 -55
- package/src/metadata.ts +2 -2
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() {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -57,14 +57,10 @@ export type LogFunc = Log;
|
|
|
57
57
|
import { Attributes } from './metadata';
|
|
58
58
|
import { Filter, SearchResult } from './model';
|
|
59
59
|
// import { GenericRepository } from './repository/GenericRepository';
|
|
60
|
-
import { ViewRepository } from './repository/ViewRepository';
|
|
61
60
|
import { GenericSearchService } from './service/GenericSearchService';
|
|
62
61
|
// import { GenericSearchService } from './service/GenericSearchService';
|
|
63
62
|
import { GenericService } from './service/GenericService';
|
|
64
|
-
import { ViewSearchService } from './service/ViewSearchService';
|
|
65
|
-
import { ViewService } from './service/ViewService';
|
|
66
63
|
import { SearchRepository } from './repository/SearchRepository';
|
|
67
|
-
import { ViewSearchRepository } from './repository/ViewSearchRepository';
|
|
68
64
|
import { GenericSearchRepository } from './repository/GenericSearchRepository';
|
|
69
65
|
|
|
70
66
|
export type Search<T, F> = (s: F, limit: number, page?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
@@ -129,85 +125,107 @@ export interface ExportService {
|
|
|
129
125
|
export interface Exporter {
|
|
130
126
|
export(ctx?: any): Promise<number>;
|
|
131
127
|
}
|
|
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
128
|
|
|
153
129
|
// tslint:disable-next-line:max-classes-per-file
|
|
154
130
|
export class SearchUseCase<T, F extends Filter> {
|
|
155
|
-
constructor(protected
|
|
131
|
+
constructor(protected repository: SearchRepository<T, F>) {
|
|
156
132
|
this.search = this.search.bind(this);
|
|
157
133
|
}
|
|
158
134
|
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
159
|
-
return this.
|
|
135
|
+
return this.repository.search(s, limit, page, fields);
|
|
160
136
|
}
|
|
161
137
|
}
|
|
162
138
|
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> {
|
|
139
|
+
|
|
140
|
+
interface WriterRepo<T> {
|
|
141
|
+
create(obj: T, ctx?: any): Promise<number>;
|
|
142
|
+
update(obj: T, ctx?: any): Promise<number>;
|
|
143
|
+
patch(obj: Partial<T>, ctx?: any): Promise<number>;
|
|
175
144
|
}
|
|
176
145
|
// tslint:disable-next-line:max-classes-per-file
|
|
177
|
-
export class
|
|
178
|
-
constructor(
|
|
179
|
-
super(repo);
|
|
146
|
+
export class Writer<T> {
|
|
147
|
+
constructor(protected repository: WriterRepo<T>) {
|
|
180
148
|
this.create = this.create.bind(this);
|
|
181
149
|
this.update = this.update.bind(this);
|
|
182
150
|
this.patch = this.patch.bind(this);
|
|
183
|
-
this.delete = this.delete.bind(this);
|
|
184
151
|
}
|
|
185
152
|
create(obj: T, ctx?: any): Promise<number> {
|
|
186
|
-
return this.
|
|
153
|
+
return this.repository.create(obj, ctx);
|
|
187
154
|
}
|
|
188
155
|
update(obj: T, ctx?: any): Promise<number> {
|
|
189
|
-
return this.
|
|
156
|
+
return this.repository.update(obj, ctx);
|
|
190
157
|
}
|
|
191
158
|
patch(obj: Partial<T>, ctx?: any): Promise<number> {
|
|
192
|
-
return (this.
|
|
159
|
+
return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
|
|
193
160
|
}
|
|
194
|
-
|
|
195
|
-
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface SearchWriterRepo<T, F extends Filter> {
|
|
164
|
+
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>>
|
|
165
|
+
create(obj: T, ctx?: any): Promise<number>;
|
|
166
|
+
update(obj: T, ctx?: any): Promise<number>;
|
|
167
|
+
patch(obj: Partial<T>, ctx?: any): Promise<number>;
|
|
168
|
+
}
|
|
169
|
+
// tslint:disable-next-line:max-classes-per-file
|
|
170
|
+
export class SearchWriter<T, F extends Filter> extends Writer<T> {
|
|
171
|
+
constructor(protected repository: SearchWriterRepo<T, F>) {
|
|
172
|
+
super(repository)
|
|
173
|
+
this.search = this.search.bind(this);
|
|
174
|
+
}
|
|
175
|
+
search(s: F, limit: number, page?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
176
|
+
return this.repository.search(s, limit, page, fields);
|
|
196
177
|
}
|
|
197
178
|
}
|
|
198
|
-
|
|
179
|
+
|
|
199
180
|
// tslint:disable-next-line:max-classes-per-file
|
|
200
|
-
export class UseCase<T, ID, F extends Filter> extends
|
|
181
|
+
export class UseCase<T, ID, F extends Filter> extends SearchWriter<T, F> implements GenericSearchService<T, ID, number, F> {
|
|
201
182
|
constructor(protected repository: GenericSearchRepository<T, ID, F>) {
|
|
202
183
|
super(repository);
|
|
184
|
+
this.metadata = this.metadata.bind(this);
|
|
185
|
+
this.keys = this.keys.bind(this);
|
|
186
|
+
this.load = this.load.bind(this);
|
|
187
|
+
this.delete = this.delete.bind(this);
|
|
203
188
|
}
|
|
204
|
-
|
|
205
|
-
return this.repository.
|
|
189
|
+
metadata(): Attributes|undefined {
|
|
190
|
+
return (this.repository.metadata ? this.repository.metadata() : undefined);
|
|
191
|
+
}
|
|
192
|
+
keys(): string[] {
|
|
193
|
+
return (this.repository.keys ? this.repository.keys() : []);
|
|
194
|
+
}
|
|
195
|
+
load(id: ID, ctx?: any): Promise<T | null> {
|
|
196
|
+
return this.repository.load(id, ctx);
|
|
197
|
+
}
|
|
198
|
+
delete(id: ID, ctx?: any): Promise<number> {
|
|
199
|
+
return this.repository.delete(id, ctx);
|
|
206
200
|
}
|
|
207
201
|
}
|
|
202
|
+
|
|
208
203
|
// tslint:disable-next-line:max-classes-per-file
|
|
209
|
-
export class
|
|
204
|
+
export class GenericUseCase<T, ID> extends Writer<T> implements GenericService<T, ID, number> {
|
|
205
|
+
constructor(protected repository: GenericRepository<T, ID>) {
|
|
206
|
+
super(repository);
|
|
207
|
+
this.metadata = this.metadata.bind(this);
|
|
208
|
+
this.keys = this.keys.bind(this);
|
|
209
|
+
this.load = this.load.bind(this);
|
|
210
|
+
this.delete = this.delete.bind(this);
|
|
211
|
+
}
|
|
212
|
+
metadata(): Attributes|undefined {
|
|
213
|
+
return (this.repository.metadata ? this.repository.metadata() : undefined);
|
|
214
|
+
}
|
|
215
|
+
keys(): string[] {
|
|
216
|
+
return (this.repository.keys ? this.repository.keys() : []);
|
|
217
|
+
}
|
|
218
|
+
load(id: ID, ctx?: any): Promise<T | null> {
|
|
219
|
+
return this.repository.load(id, ctx);
|
|
220
|
+
}
|
|
221
|
+
delete(id: ID, ctx?: any): Promise<number> {
|
|
222
|
+
return this.repository.delete(id, ctx);
|
|
223
|
+
}
|
|
210
224
|
}
|
|
225
|
+
export const CRUDUseCase = GenericUseCase
|
|
226
|
+
export const GenericManager = GenericUseCase
|
|
227
|
+
export const CRUDManager = GenericUseCase
|
|
228
|
+
|
|
211
229
|
export interface SavedRepository<UID, ID> {
|
|
212
230
|
isSaved(userId: UID, id: ID): Promise<boolean>
|
|
213
231
|
save(userId: UID, id: ID): Promise<number>
|
|
@@ -239,8 +257,5 @@ export class SavedService<UID, ID> {
|
|
|
239
257
|
}
|
|
240
258
|
}
|
|
241
259
|
// 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
260
|
export class SavedUseCase<ID, T> extends SavedService<ID, T> {
|
|
246
261
|
}
|
package/src/metadata.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type DataType = 'ObjectId' | 'date' | 'datetime' | 'time'
|
|
|
3
3
|
| 'object' | 'array' | 'binary'
|
|
4
4
|
| 'primitives' | 'booleans' | 'numbers' | 'integers' | 'strings' | 'dates' | 'datetimes' | 'times';
|
|
5
5
|
export type FormatType = 'currency' | 'percentage' | 'email' | 'url' | 'phone' | 'fax' | 'ipv4' | 'ipv6';
|
|
6
|
-
export type
|
|
6
|
+
export type Operator = "=" | "like" | "!=" | "<>" | ">" | ">=" | "<" | "<="
|
|
7
7
|
|
|
8
8
|
export interface Model {
|
|
9
9
|
name?: string;
|
|
@@ -24,7 +24,7 @@ export interface Attribute {
|
|
|
24
24
|
type?: DataType;
|
|
25
25
|
format?: FormatType;
|
|
26
26
|
required?: boolean;
|
|
27
|
-
|
|
27
|
+
operator?: Operator;
|
|
28
28
|
default?: string|number|Date|boolean;
|
|
29
29
|
key?: boolean;
|
|
30
30
|
unique?: boolean;
|