onecore 0.0.31 → 0.0.34
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 +25 -21
- package/package.json +1 -1
- package/src/index.ts +13 -1
- package/src/model.ts +3 -0
package/lib/index.js
CHANGED
|
@@ -14,33 +14,38 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
})();
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
var ViewManager = (function () {
|
|
17
|
-
function ViewManager(
|
|
18
|
-
this.
|
|
17
|
+
function ViewManager(r) {
|
|
18
|
+
this.r = r;
|
|
19
19
|
this.metadata = this.metadata.bind(this);
|
|
20
20
|
this.keys = this.keys.bind(this);
|
|
21
|
-
this.all = this.all.bind(this);
|
|
22
21
|
this.load = this.load.bind(this);
|
|
23
|
-
this.exist = this.exist.bind(this);
|
|
24
22
|
}
|
|
25
23
|
ViewManager.prototype.metadata = function () {
|
|
26
|
-
return (this.
|
|
24
|
+
return (this.r.metadata ? this.r.metadata() : undefined);
|
|
27
25
|
};
|
|
28
26
|
ViewManager.prototype.keys = function () {
|
|
29
|
-
return (this.
|
|
30
|
-
};
|
|
31
|
-
ViewManager.prototype.all = function (ctx) {
|
|
32
|
-
return (this.repo.all ? this.repo.all() : Promise.resolve([]));
|
|
27
|
+
return (this.r.keys ? this.r.keys() : []);
|
|
33
28
|
};
|
|
34
29
|
ViewManager.prototype.load = function (id, ctx) {
|
|
35
|
-
return this.
|
|
36
|
-
;
|
|
37
|
-
};
|
|
38
|
-
ViewManager.prototype.exist = function (id, ctx) {
|
|
39
|
-
return (this.repo.exist ? this.repo.exist(id, ctx) : Promise.resolve(false));
|
|
30
|
+
return this.r.load(id, ctx);
|
|
40
31
|
};
|
|
41
32
|
return ViewManager;
|
|
42
33
|
}());
|
|
43
34
|
exports.ViewManager = ViewManager;
|
|
35
|
+
var ViewSearchManager = (function (_super) {
|
|
36
|
+
__extends(ViewSearchManager, _super);
|
|
37
|
+
function ViewSearchManager(find, repo) {
|
|
38
|
+
var _this = _super.call(this, repo) || this;
|
|
39
|
+
_this.find = find;
|
|
40
|
+
_this.search = _this.search.bind(_this);
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
ViewSearchManager.prototype.search = function (s, limit, offset, fields) {
|
|
44
|
+
return this.find(s, limit, offset, fields);
|
|
45
|
+
};
|
|
46
|
+
return ViewSearchManager;
|
|
47
|
+
}(ViewManager));
|
|
48
|
+
exports.ViewSearchManager = ViewSearchManager;
|
|
44
49
|
var GenericManager = (function (_super) {
|
|
45
50
|
__extends(GenericManager, _super);
|
|
46
51
|
function GenericManager(repository) {
|
|
@@ -49,24 +54,18 @@ var GenericManager = (function (_super) {
|
|
|
49
54
|
_this.insert = _this.insert.bind(_this);
|
|
50
55
|
_this.update = _this.update.bind(_this);
|
|
51
56
|
_this.patch = _this.patch.bind(_this);
|
|
52
|
-
_this.save = _this.save.bind(_this);
|
|
53
57
|
_this.delete = _this.delete.bind(_this);
|
|
54
58
|
return _this;
|
|
55
59
|
}
|
|
56
60
|
GenericManager.prototype.insert = function (obj, ctx) {
|
|
57
61
|
return this.repository.insert(obj, ctx);
|
|
58
|
-
;
|
|
59
62
|
};
|
|
60
63
|
GenericManager.prototype.update = function (obj, ctx) {
|
|
61
64
|
return this.repository.update(obj, ctx);
|
|
62
|
-
;
|
|
63
65
|
};
|
|
64
66
|
GenericManager.prototype.patch = function (obj, ctx) {
|
|
65
67
|
return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
|
|
66
68
|
};
|
|
67
|
-
GenericManager.prototype.save = function (obj, ctx) {
|
|
68
|
-
return (this.repository.save ? this.repository.save(obj, ctx) : Promise.resolve(-1));
|
|
69
|
-
};
|
|
70
69
|
GenericManager.prototype.delete = function (id, ctx) {
|
|
71
70
|
return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
|
|
72
71
|
};
|
|
@@ -86,4 +85,9 @@ var Manager = (function (_super) {
|
|
|
86
85
|
};
|
|
87
86
|
return Manager;
|
|
88
87
|
}(GenericManager));
|
|
89
|
-
exports.Manager = Manager;
|
|
88
|
+
exports.Manager = Manager;
|
|
89
|
+
exports.DefaultViewService = ViewManager;
|
|
90
|
+
exports.DefaultGenericService = GenericManager;
|
|
91
|
+
exports.GenericSearchManager = Manager;
|
|
92
|
+
exports.DefaultService = GenericManager;
|
|
93
|
+
exports.DefaultGenericSearchService = GenericManager;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -42,7 +42,8 @@ export * from './logger';
|
|
|
42
42
|
|
|
43
43
|
export type DeleteFile = (name: string, directory?: string) => Promise<boolean>;
|
|
44
44
|
export type Delete = (delFile: DeleteFile, url: string) => Promise<boolean>;
|
|
45
|
-
export type
|
|
45
|
+
export type BuildUrl = (name: string, directory?: string) => string;
|
|
46
|
+
export type Generate = () => string;
|
|
46
47
|
|
|
47
48
|
export type Log = (msg: string) => void;
|
|
48
49
|
export type LogFunc = Log;
|
|
@@ -54,6 +55,7 @@ import { ViewRepository } from './repository/ViewRepository';
|
|
|
54
55
|
import { GenericSearchService } from './service/GenericSearchService';
|
|
55
56
|
// import { GenericSearchService } from './service/GenericSearchService';
|
|
56
57
|
import { GenericService } from './service/GenericService';
|
|
58
|
+
import { ViewSearchService } from './service/ViewSearchService';
|
|
57
59
|
import { ViewService } from './service/ViewService';
|
|
58
60
|
|
|
59
61
|
export type Search<T, F> = (s: F, limit?: number, offset?: number | string, fields?: string[]) => Promise<SearchResult<T>>;
|
|
@@ -76,6 +78,16 @@ export class ViewManager<T, ID> implements ViewService<T, ID> {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
// tslint:disable-next-line:max-classes-per-file
|
|
81
|
+
export class ViewSearchManager<T, ID, F extends Filter> extends ViewManager<T, ID> implements ViewSearchService<T, ID, F> {
|
|
82
|
+
constructor(public find: Search<T, F>, repo: ViewRepository<T, ID>) {
|
|
83
|
+
super(repo);
|
|
84
|
+
this.search = this.search.bind(this);
|
|
85
|
+
}
|
|
86
|
+
search(s: F, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>> {
|
|
87
|
+
return this.find(s, limit, offset, fields);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// tslint:disable-next-line:max-classes-per-file
|
|
79
91
|
export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
|
|
80
92
|
constructor(protected repository: GenericRepository<T, ID>) {
|
|
81
93
|
super(repository);
|
package/src/model.ts
CHANGED
|
@@ -155,3 +155,6 @@ export interface RoleFilter extends Filter {
|
|
|
155
155
|
remark?: string;
|
|
156
156
|
description?: string;
|
|
157
157
|
}
|
|
158
|
+
export type Validate<T> = (obj: T, patch?: boolean) => Promise<ErrorMessage[]>;
|
|
159
|
+
export type Save<T> = (obj: T, ctx?: any) => Promise<number|ResultInfo<T>>;
|
|
160
|
+
export type Load<T, ID> = ((id: ID, ctx?: any) => Promise<T|null>);
|