onecore 0.0.21 → 0.0.25

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.21",
3
+ "version": "0.0.25",
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/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
 
@@ -11,10 +11,12 @@ export interface Model {
11
11
  source?: string;
12
12
  table?: string;
13
13
  collection?: string;
14
- model?: any;
15
- schema?: any;
14
+ // for mongo lowcode
15
+ sort?: string;
16
+ geo?: string;
17
+ latitude?: string;
18
+ longitude?: string;
16
19
  }
17
-
18
20
  export interface Attribute {
19
21
  name?: string;
20
22
  field?: string;
@@ -23,10 +25,10 @@ export interface Attribute {
23
25
  format?: FormatType;
24
26
  required?: boolean;
25
27
  match?: MatchType;
26
- defaultValue?: any;
28
+ default?: string|number|Date|boolean;
27
29
  key?: boolean;
28
30
  unique?: boolean;
29
- enum?: string[]|number[];
31
+ enum?: string[] | number[];
30
32
  q?: boolean;
31
33
  noinsert?: boolean;
32
34
  noupdate?: boolean;
@@ -39,13 +41,15 @@ export interface Attribute {
39
41
  lt?: number;
40
42
  precision?: number;
41
43
  scale?: number;
42
- exp?: RegExp|string;
44
+ exp?: RegExp | string;
43
45
  code?: string;
44
46
  noformat?: boolean;
45
47
  ignored?: boolean;
46
48
  jsonField?: string;
47
49
  link?: string;
48
50
  typeof?: Attributes;
51
+ true?: string|number;
52
+ false?: string|number;
49
53
  }
50
54
  export interface Attributes {
51
55
  [key: string]: Attribute;
@@ -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
  }