onecore 0.0.20 → 0.0.24

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 CHANGED
@@ -1 +1,89 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var ViewManager = (function () {
17
+ function ViewManager(repo) {
18
+ this.repo = repo;
19
+ this.metadata = this.metadata.bind(this);
20
+ this.keys = this.keys.bind(this);
21
+ this.all = this.all.bind(this);
22
+ this.load = this.load.bind(this);
23
+ this.exist = this.exist.bind(this);
24
+ }
25
+ ViewManager.prototype.metadata = function () {
26
+ return (this.repo.metadata ? this.repo.metadata() : undefined);
27
+ };
28
+ ViewManager.prototype.keys = function () {
29
+ return (this.repo.keys ? this.repo.keys() : []);
30
+ };
31
+ ViewManager.prototype.all = function (ctx) {
32
+ return (this.repo.all ? this.repo.all() : Promise.resolve([]));
33
+ };
34
+ ViewManager.prototype.load = function (id, ctx) {
35
+ return this.repo.load(id, ctx);
36
+ ;
37
+ };
38
+ ViewManager.prototype.exist = function (id, ctx) {
39
+ return (this.repo.exist ? this.repo.exist(id, ctx) : Promise.resolve(false));
40
+ };
41
+ return ViewManager;
42
+ }());
43
+ exports.ViewManager = ViewManager;
44
+ var GenericManager = (function (_super) {
45
+ __extends(GenericManager, _super);
46
+ function GenericManager(repository) {
47
+ var _this = _super.call(this, repository) || this;
48
+ _this.repository = repository;
49
+ _this.insert = _this.insert.bind(_this);
50
+ _this.update = _this.update.bind(_this);
51
+ _this.patch = _this.patch.bind(_this);
52
+ _this.save = _this.save.bind(_this);
53
+ _this.delete = _this.delete.bind(_this);
54
+ return _this;
55
+ }
56
+ GenericManager.prototype.insert = function (obj, ctx) {
57
+ return this.repository.insert(obj, ctx);
58
+ ;
59
+ };
60
+ GenericManager.prototype.update = function (obj, ctx) {
61
+ return this.repository.update(obj, ctx);
62
+ ;
63
+ };
64
+ GenericManager.prototype.patch = function (obj, ctx) {
65
+ return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
66
+ };
67
+ GenericManager.prototype.save = function (obj, ctx) {
68
+ return (this.repository.save ? this.repository.save(obj, ctx) : Promise.resolve(-1));
69
+ };
70
+ GenericManager.prototype.delete = function (id, ctx) {
71
+ return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
72
+ };
73
+ return GenericManager;
74
+ }(ViewManager));
75
+ exports.GenericManager = GenericManager;
76
+ var Manager = (function (_super) {
77
+ __extends(Manager, _super);
78
+ function Manager(find, repo) {
79
+ var _this = _super.call(this, repo) || this;
80
+ _this.find = find;
81
+ _this.search = _this.search.bind(_this);
82
+ return _this;
83
+ }
84
+ Manager.prototype.search = function (s, limit, offset, fields) {
85
+ return this.find(s, limit, offset, fields);
86
+ };
87
+ return Manager;
88
+ }(GenericManager));
89
+ exports.Manager = Manager;exports.DefaultViewService = ViewManager;exports.DefaultGenericService = GenericManager;exports.GenericSearchManager = Manager;exports.DefaultService = GenericManager;exports.DefaultGenericSearchService = GenericManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onecore",
3
- "version": "0.0.20",
3
+ "version": "0.0.24",
4
4
  "description": "onecore",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git@github.com/core-ts/onecore"
20
+ "url": "git@github.com/core-ts/core"
21
21
  },
22
22
  "keywords": [
23
23
  "one",
package/src/db.ts ADDED
@@ -0,0 +1,19 @@
1
+ import {Attribute} from './metadata';
2
+ export interface Statement {
3
+ query: string;
4
+ params?: any[];
5
+ }
6
+ export interface SimpleDB {
7
+ driver: string;
8
+ query<T>(sql: string): Promise<T[]>;
9
+ }
10
+ interface StringMap {
11
+ [key: string]: string;
12
+ }
13
+ export interface DB {
14
+ driver: string;
15
+ param(i: number): string;
16
+ exec(sql: string, args?: any[], ctx?: any): Promise<number>;
17
+ execBatch(statements: Statement[], firstSuccess?: boolean, ctx?: any): Promise<number>;
18
+ query<T>(sql: string, args?: any[], m?: StringMap, bools?: Attribute[], ctx?: any): Promise<T[]>;
19
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export {Locale} from './formatter';
2
2
 
3
+ export * from './db';
4
+
3
5
  export {Mapper} from './formatter';
4
6
  export {LocaleMapper} from './formatter';
5
7
  export {Formatter} from './formatter';
@@ -26,8 +28,8 @@ export {DataLoader} from './loader';
26
28
 
27
29
  export * from './model';
28
30
 
29
- import {GenericSearchRepository} from './repository/GenericSearchRepository';
30
- export {GenericSearchRepository as Repository};
31
+ import {GenericRepository} from './repository/GenericRepository';
32
+ export {GenericRepository as Repository};
31
33
 
32
34
  export * from './repository/ViewRepository';
33
35
  export * from './repository/GenericRepository';
@@ -62,3 +64,76 @@ export * from './mail/config';
62
64
  export * from './location';
63
65
  export * from './video';
64
66
  export * from './health';
67
+ export * from './logger';
68
+
69
+ import { Attributes } from './metadata';
70
+ import { Filter, SearchResult } from './model';
71
+ // import { GenericRepository } from './repository/GenericRepository';
72
+ import { ViewRepository } from './repository/ViewRepository';
73
+ // import { GenericSearchService } from './service/GenericSearchService';
74
+ import { GenericService } from './service/GenericService';
75
+ import { ViewService } from './service/ViewService';
76
+
77
+ export class ViewManager<T, ID> implements ViewService<T, ID> {
78
+ constructor(private repo: ViewRepository<T, ID>) {
79
+ this.metadata = this.metadata.bind(this);
80
+ this.keys = this.keys.bind(this);
81
+ this.all = this.all.bind(this);
82
+ this.load = this.load.bind(this);
83
+ this.exist = this.exist.bind(this);
84
+ }
85
+ metadata(): Attributes|undefined {
86
+ return (this.repo.metadata ? this.repo.metadata() : undefined);
87
+ }
88
+ keys(): string[] {
89
+ return (this.repo.keys ? this.repo.keys() : []);
90
+ }
91
+ all(ctx?: any): Promise<T[]> {
92
+ return (this.repo.all ? this.repo.all() : Promise.resolve([]));
93
+ }
94
+ load(id: ID, ctx?: any): Promise<T | null> {
95
+ return this.repo.load(id, ctx);;
96
+ }
97
+ exist(id: ID, ctx?: any): Promise<boolean> {
98
+ return (this.repo.exist ? this.repo.exist(id, ctx) : Promise.resolve(false));
99
+ }
100
+ }
101
+ export class GenericManager<T, ID> extends ViewManager<T, ID> implements GenericService<T, ID, number> {
102
+ constructor(protected repository: GenericRepository<T, ID>) {
103
+ super(repository);
104
+ this.insert = this.insert.bind(this);
105
+ this.update = this.update.bind(this);
106
+ this.patch = this.patch.bind(this);
107
+ this.save = this.save.bind(this);
108
+ this.delete = this.delete.bind(this);
109
+ }
110
+ insert(obj: T, ctx?: any): Promise<number> {
111
+ return this.repository.insert(obj, ctx);;
112
+ }
113
+ update(obj: T, ctx?: any): Promise<number> {
114
+ return this.repository.update(obj, ctx);;
115
+ }
116
+ patch(obj: T, ctx?: any): Promise<number> {
117
+ return (this.repository.patch ? this.repository.patch(obj, ctx) : Promise.resolve(-1));
118
+ }
119
+ save(obj: T, ctx?: any): Promise<number> {
120
+ return (this.repository.save ? this.repository.save(obj, ctx) : Promise.resolve(-1));
121
+ }
122
+ delete(id: ID, ctx?: any): Promise<number> {
123
+ return (this.repository.delete ? this.repository.delete(id, ctx) : Promise.resolve(-1));
124
+ }
125
+ }
126
+ export class Manager<T, ID, S extends Filter> extends GenericManager<T, ID> implements GenericSearchService<T, ID, number, S> {
127
+ constructor(public find: (s: S, offset?: number, skip?: number|string, fields?: string[]) => Promise<SearchResult<T>>, repo: GenericRepository<T, ID>) {
128
+ super(repo);
129
+ this.search = this.search.bind(this);
130
+ }
131
+ search(s: S, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>> {
132
+ return this.find(s, limit, offset, fields);
133
+ }
134
+ }
135
+ export const DefaultViewService = ViewManager;
136
+ export const DefaultGenericService = GenericManager;
137
+ export const GenericSearchManager = Manager;
138
+ export const DefaultService = GenericManager;
139
+ export const DefaultGenericSearchService = GenericManager;
package/src/logger.ts ADDED
@@ -0,0 +1,31 @@
1
+ export interface SimpleMap {
2
+ [key: string]: string|number|boolean|Date;
3
+ }
4
+ export interface LogMap {
5
+ time: string;
6
+ level: string;
7
+ msg: string;
8
+ }
9
+ export interface LogMapConfig {
10
+ time?: string;
11
+ level?: string;
12
+ msg?: string;
13
+ }
14
+ export interface Logger {
15
+ level: number;
16
+ trace(msg: string, m?: SimpleMap, ctx?: any): void;
17
+ debug(msg: string, m?: SimpleMap, ctx?: any): void;
18
+ info(msg: string, m?: SimpleMap, ctx?: any): void;
19
+ warn(msg: string, m?: SimpleMap, ctx?: any): void;
20
+ error(msg: string, m?: SimpleMap, ctx?: any): void;
21
+ panic(msg: string, m?: SimpleMap, ctx?: any): void;
22
+ fatal(msg: string, m?: SimpleMap, ctx?: any): void;
23
+ isLevelEnabled(level: number): boolean;
24
+ isTraceEnabled(): boolean;
25
+ isDebugEnabled(): boolean;
26
+ isInfoEnabled(): boolean;
27
+ isWarnEnabled(): boolean;
28
+ isErrorEnabled(): boolean;
29
+ isPanicEnabled(): boolean;
30
+ isFatalEnabled(): boolean;
31
+ }
package/src/metadata.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type DataType = 'ObjectId' | 'date' | 'datetime' | 'time'
2
- | 'boolean' | 'number' | 'integer' | 'string' | 'text'
3
- | 'object' | 'array' | 'binary'
4
- | 'primitives' | 'booleans' | 'numbers' | 'integers' | 'strings' | 'dates' | 'datetimes' | 'times';
2
+ | 'boolean' | 'number' | 'integer' | 'string' | 'text'
3
+ | 'object' | 'array' | 'binary'
4
+ | 'primitives' | 'booleans' | 'numbers' | 'integers' | 'strings' | 'dates' | 'datetimes' | 'times';
5
5
  export type FormatType = 'currency' | 'percentage' | 'email' | 'url' | 'phone' | 'fax' | 'ipv4' | 'ipv6';
6
6
  export type MatchType = 'equal' | 'prefix' | 'contain' | 'max' | 'min'; // contain: default for string, min: default for Date, number
7
7
 
@@ -9,21 +9,26 @@ export interface Model {
9
9
  name?: string;
10
10
  attributes: Attributes;
11
11
  source?: string;
12
+ table?: string;
12
13
  collection?: string;
13
- model?: any;
14
- schema?: any;
14
+ // for mongo lowcode
15
+ sort?: string;
16
+ geo?: string;
17
+ latitude?: string;
18
+ longitude?: string;
15
19
  }
16
-
17
20
  export interface Attribute {
18
21
  name?: string;
19
22
  field?: string;
23
+ column?: string;
20
24
  type?: DataType;
21
25
  format?: FormatType;
22
26
  required?: boolean;
23
27
  match?: MatchType;
24
- defaultValue?: any;
28
+ default?: string|number|Date|boolean;
25
29
  key?: boolean;
26
30
  unique?: boolean;
31
+ enum?: string[] | number[];
27
32
  q?: boolean;
28
33
  noinsert?: boolean;
29
34
  noupdate?: boolean;
@@ -36,13 +41,15 @@ export interface Attribute {
36
41
  lt?: number;
37
42
  precision?: number;
38
43
  scale?: number;
39
- exp?: RegExp|string;
44
+ exp?: RegExp | string;
40
45
  code?: string;
41
46
  noformat?: boolean;
42
47
  ignored?: boolean;
43
48
  jsonField?: string;
44
49
  link?: string;
45
50
  typeof?: Attributes;
51
+ true?: string|number;
52
+ false?: string|number;
46
53
  }
47
54
  export interface Attributes {
48
55
  [key: string]: Attribute;
package/src/mq.ts CHANGED
@@ -21,41 +21,41 @@ export interface Writer<T, R, ID> {
21
21
  write(data: T, attributes?: StringMap, id?: ID): Promise<R>;
22
22
  }
23
23
 
24
- export interface SimpleProducer<T, R, ID> {
24
+ export interface Producer<T, R, ID> {
25
25
  produce(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
26
26
  }
27
- export interface SimplePublisher<T, R, ID> {
27
+ export interface Publisher<T, R, ID> {
28
28
  publish(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
29
29
  }
30
- export interface SimpleSender<T, R, ID> {
30
+ export interface Sender<T, R, ID> {
31
31
  send(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
32
32
  }
33
- export interface SimpleWriter<T, R, ID> {
33
+ export interface Writer<T, R, ID> {
34
34
  write(to: string, data: T, attributes?: StringMap, id?: ID): Promise<R>;
35
35
  }
36
36
 
37
- export interface SimpleConsumer<T> {
38
- consume(handle: (data: T, attributes?: StringMap) => Promise<number>): void;
37
+ export interface SimpleConsumer<T, R> {
38
+ consume(handle: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
39
39
  }
40
40
  export interface SimpleSubscriber<T, R> {
41
- subscribe(handle: (data: T, attributes?: StringMap) => Promise<number>): void;
41
+ subscribe(handle: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
42
42
  }
43
- export interface SimpleReceiver<T> {
44
- receive(handle: (data: T, attributes?: StringMap) => Promise<number>): void;
43
+ export interface SimpleReceiver<T, R> {
44
+ receive(handle: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
45
45
  }
46
- export interface SimpleReader<T> {
47
- read(handle: (data: T, attributes?: StringMap) => Promise<number>): void;
46
+ export interface SimpleReader<T, R> {
47
+ read(handle: (data: T, attributes?: StringMap, raw?: R) => Promise<number>): void;
48
48
  }
49
49
 
50
- export interface Consumer<T, ID, R> {
50
+ export interface MessageConsumer<T, ID, R> {
51
51
  consume(data: Message<T, ID, R>): void;
52
52
  }
53
- export interface Subscriber<T, ID, R> {
53
+ export interface MessageSubscriber<T, ID, R> {
54
54
  subscribe(handle: (data: Message<T, ID, R>) => Promise<number>): void;
55
55
  }
56
- export interface Receiver<T, ID, R> {
56
+ export interface MessageReceiver<T, ID, R> {
57
57
  receive(handle: (data: Message<T, ID, R>) => Promise<number>): void;
58
58
  }
59
- export interface Reader<T, ID, R> {
59
+ export interface MessageReader<T, ID, R> {
60
60
  read(handle: (data: Message<T, ID, R>) => Promise<number>): void;
61
61
  }
@@ -1,9 +1,9 @@
1
1
  import {ViewRepository} from './ViewRepository';
2
2
 
3
- export interface GenericRepository<T, ID, R> extends ViewRepository<T, ID> {
4
- insert(obj: T, ctx?: any): Promise<R>;
5
- update(obj: T, ctx?: any): Promise<R>;
6
- patch?(obj: T, ctx?: any): Promise<R>;
7
- save?(obj: T, ctx?: any): Promise<R>;
3
+ export interface GenericRepository<T, ID> extends ViewRepository<T, ID> {
4
+ insert(obj: T, ctx?: any): Promise<number>;
5
+ update(obj: T, ctx?: any): Promise<number>;
6
+ patch?(obj: T, ctx?: any): Promise<number>;
7
+ save?(obj: T, ctx?: any): Promise<number>;
8
8
  delete?(id: ID, ctx?: any): Promise<number>;
9
9
  }
@@ -2,6 +2,6 @@ import {Filter} from '../model';
2
2
  import {GenericRepository} from './GenericRepository';
3
3
  import {SearchRepository} from './SearchRepository';
4
4
 
5
- export interface GenericSearchRepository<T, ID, R, S extends Filter>
6
- extends GenericRepository<T, ID, R>, SearchRepository<T, S> {
5
+ export interface GenericSearchRepository<T, ID, S extends Filter>
6
+ extends GenericRepository<T, ID>, SearchRepository<T, S> {
7
7
  }