@quatrain/core 0.5.6 → 1.0.0-beta1
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/Backend.js +0 -9
- package/lib/Core.d.ts +4 -0
- package/lib/Core.js +9 -0
- package/lib/backends/AbstractAdapter.d.ts +1 -1
- package/lib/backends/Query.d.ts +3 -2
- package/lib/backends/Query.js +2 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +3 -4
- package/lib/backends/middlewares/InjectMetaMiddleware.js +3 -3
- package/lib/common/statuses.d.ts +1 -0
- package/lib/common/statuses.js +2 -1
- package/lib/components/AbstractObject.d.ts +6 -0
- package/lib/components/AbstractObject.js +8 -0
- package/lib/components/BaseObject.js +2 -0
- package/lib/components/BaseObjectCore.d.ts +6 -2
- package/lib/components/BaseObjectCore.js +7 -2
- package/lib/components/BaseObjectProperties.d.ts +13 -0
- package/lib/components/BaseObjectProperties.js +87 -0
- package/lib/components/BaseRepository.d.ts +4 -5
- package/lib/components/BaseRepository.js +11 -10
- package/lib/components/DataObject.d.ts +7 -1
- package/lib/components/DataObject.js +21 -3
- package/lib/components/EntityProperties.d.ts +1 -0
- package/lib/components/EntityProperties.js +54 -0
- package/lib/components/ObjectUri.js +1 -1
- package/lib/components/UserProperties.d.ts +1 -0
- package/lib/components/UserProperties.js +103 -0
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.js +6 -1
- package/lib/components/types/DataObjectClass.d.ts +1 -0
- package/lib/components/types/RepositoryClass.d.ts +1 -1
- package/lib/components/types/UserClass.d.ts +3 -0
- package/lib/components/types/UserClass.js +2 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/properties/BaseProperty.js +1 -1
- package/lib/properties/ObjectProperty.d.ts +5 -5
- package/lib/properties/ObjectProperty.js +56 -3
- package/lib/properties/Property.d.ts +9 -2
- package/lib/properties/StringProperty.d.ts +1 -1
- package/package.json +4 -3
package/lib/Backend.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// export const CREATE = 'create'
|
|
3
|
-
// export const READ = 'read'
|
|
4
|
-
// export const UPDATE = 'update'
|
|
5
|
-
// export const DELETE = 'delete'
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.BackendAction = void 0;
|
|
8
|
-
// export type BackendActions =
|
|
9
|
-
// | typeof CREATE
|
|
10
|
-
// | typeof READ
|
|
11
|
-
// | typeof UPDATE
|
|
12
|
-
// | typeof DELETE
|
|
13
4
|
var BackendAction;
|
|
14
5
|
(function (BackendAction) {
|
|
15
6
|
BackendAction["CREATE"] = "create";
|
package/lib/Core.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class Core {
|
|
|
14
14
|
(...data: any[]): void;
|
|
15
15
|
(message?: any, ...optionalParams: any[]): void;
|
|
16
16
|
};
|
|
17
|
+
static timestamp: () => string;
|
|
17
18
|
protected static _backends: BackendRegistry<any>;
|
|
18
19
|
static definition(key: string): {
|
|
19
20
|
manifest: {
|
|
@@ -23,6 +24,8 @@ export declare class Core {
|
|
|
23
24
|
};
|
|
24
25
|
static addBackend(backend: AbstractAdapter, alias: string, setDefault?: boolean): void;
|
|
25
26
|
static getBackend<T extends AbstractAdapter>(alias?: string): T;
|
|
27
|
+
static addClass(name: string, obj: any): void;
|
|
28
|
+
static getClass(name: string): any;
|
|
26
29
|
/**
|
|
27
30
|
* Returns the class to use for a data object
|
|
28
31
|
* This is currently just a stub that will be implemented from config in the future
|
|
@@ -36,4 +39,5 @@ export declare class Core {
|
|
|
36
39
|
* @param level string
|
|
37
40
|
*/
|
|
38
41
|
static log(message: string, src?: string, level?: string): void;
|
|
42
|
+
static getObject(): void;
|
|
39
43
|
}
|
package/lib/Core.js
CHANGED
|
@@ -25,6 +25,12 @@ class Core {
|
|
|
25
25
|
throw new Error(`Unknown backend alias: '${alias}'`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
static addClass(name, obj) {
|
|
29
|
+
Core.classRegistry[name] = obj;
|
|
30
|
+
}
|
|
31
|
+
static getClass(name) {
|
|
32
|
+
return Core.classRegistry[name];
|
|
33
|
+
}
|
|
28
34
|
/**
|
|
29
35
|
* Returns the class to use for a data object
|
|
30
36
|
* This is currently just a stub that will be implemented from config in the future
|
|
@@ -42,9 +48,12 @@ class Core {
|
|
|
42
48
|
static log(message, src = 'Core', level = 'NOTICE') {
|
|
43
49
|
Core.logger(`${Date.now()} - [${src}] ${message}`);
|
|
44
50
|
}
|
|
51
|
+
static getObject() { }
|
|
45
52
|
}
|
|
46
53
|
exports.Core = Core;
|
|
47
54
|
Core.defaultBackend = '@default';
|
|
48
55
|
Core.classRegistry = {};
|
|
49
56
|
Core.logger = console.log;
|
|
57
|
+
// How timestamp are formatted
|
|
58
|
+
Core.timestamp = () => (new Date().toISOString());
|
|
50
59
|
Core._backends = {};
|
|
@@ -52,7 +52,7 @@ export declare abstract class AbstractAdapter implements BackendInterface {
|
|
|
52
52
|
set alias(alias: string);
|
|
53
53
|
get alias(): string;
|
|
54
54
|
getCollection(dao: DataObjectClass<any>): string | undefined;
|
|
55
|
-
abstract create(dataObject: DataObjectClass<any
|
|
55
|
+
abstract create(dataObject: DataObjectClass<any>, desiredUid?: string | undefined): Promise<DataObjectClass<any>>;
|
|
56
56
|
abstract read(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
57
57
|
abstract update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
|
58
58
|
abstract delete(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
|
package/lib/backends/Query.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare const AS_INSTANCES = "classInstances";
|
|
|
13
13
|
export declare enum returnAs {
|
|
14
14
|
AS_OBJECTURIS = "objectUris",
|
|
15
15
|
AS_DATAOBJECTS = "dataObjects",
|
|
16
|
-
AS_INSTANCES = "classInstances"
|
|
16
|
+
AS_INSTANCES = "classInstances",
|
|
17
|
+
AS_IS = "asIs"
|
|
17
18
|
}
|
|
18
19
|
export declare class Query<T extends typeof BaseObjectCore> {
|
|
19
20
|
protected _obj: T;
|
|
@@ -34,5 +35,5 @@ export declare class Query<T extends typeof BaseObjectCore> {
|
|
|
34
35
|
fetch(backend?: BackendInterface): Promise<DataObjectClass<any>[]>;
|
|
35
36
|
fetchAsUri(backend?: BackendInterface): Promise<ObjectUri[]>;
|
|
36
37
|
fetchAsInstances(backend?: BackendInterface): Promise<Persisted<BaseObject>[]>;
|
|
37
|
-
execute(as?: returnAs, backend?: BackendInterface): Promise<
|
|
38
|
+
execute(as?: returnAs, backend?: BackendInterface): Promise<any[]>;
|
|
38
39
|
}
|
package/lib/backends/Query.js
CHANGED
|
@@ -23,6 +23,7 @@ var returnAs;
|
|
|
23
23
|
returnAs["AS_OBJECTURIS"] = "objectUris";
|
|
24
24
|
returnAs["AS_DATAOBJECTS"] = "dataObjects";
|
|
25
25
|
returnAs["AS_INSTANCES"] = "classInstances";
|
|
26
|
+
returnAs["AS_IS"] = "asIs";
|
|
26
27
|
})(returnAs || (exports.returnAs = returnAs = {}));
|
|
27
28
|
class Query {
|
|
28
29
|
constructor(obj, params = {}) {
|
|
@@ -95,6 +96,7 @@ class Query {
|
|
|
95
96
|
}
|
|
96
97
|
execute(as = returnAs.AS_DATAOBJECTS, backend = Core_1.Core.getBackend()) {
|
|
97
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
//<DataObjectClass<any>[] | ObjectUri[] | Persisted<BaseObject>[]> {
|
|
98
100
|
//</any><Array<T2> | Array<DataObject> | Array<ObjectUri>> {
|
|
99
101
|
try {
|
|
100
102
|
switch (as) {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { DataObjectClass } from '../../components';
|
|
2
2
|
import { BackendAction } from '../../Backend';
|
|
3
|
-
import {
|
|
3
|
+
import { UserCore } from '../../components/User';
|
|
4
4
|
import Middleware from './Middleware';
|
|
5
|
-
import { Proxy } from '../../components/types/ProxyConstructor';
|
|
6
5
|
export interface InjectMetaMiddlewareParams {
|
|
7
|
-
user:
|
|
6
|
+
user: UserCore;
|
|
8
7
|
}
|
|
9
8
|
export declare class InjectMetaMiddleware implements Middleware {
|
|
10
|
-
protected _user:
|
|
9
|
+
protected _user: UserCore;
|
|
11
10
|
constructor(params: InjectMetaMiddlewareParams);
|
|
12
11
|
execute(dataObject: DataObjectClass<any>, action: BackendAction): void;
|
|
13
12
|
}
|
|
@@ -10,15 +10,15 @@ class InjectMetaMiddleware {
|
|
|
10
10
|
switch (action) {
|
|
11
11
|
// add properties existence validation
|
|
12
12
|
case Backend_1.BackendAction.CREATE:
|
|
13
|
-
dataObject.set('createdBy', this._user
|
|
13
|
+
dataObject.set('createdBy', this._user);
|
|
14
14
|
dataObject.set('createdAt', Date.now());
|
|
15
15
|
break;
|
|
16
16
|
case Backend_1.BackendAction.UPDATE:
|
|
17
|
-
dataObject.set('updatedBy', this._user
|
|
17
|
+
dataObject.set('updatedBy', this._user);
|
|
18
18
|
dataObject.set('updatedAt', Date.now());
|
|
19
19
|
break;
|
|
20
20
|
case Backend_1.BackendAction.DELETE:
|
|
21
|
-
dataObject.set('deletedBy', this._user
|
|
21
|
+
dataObject.set('deletedBy', this._user);
|
|
22
22
|
dataObject.set('deletedAt', Date.now());
|
|
23
23
|
break;
|
|
24
24
|
default:
|
package/lib/common/statuses.d.ts
CHANGED
package/lib/common/statuses.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UNKNOWN = exports.MAINTENANCE = exports.DONE = exports.DELETED = exports.DELETABLE = exports.SUSPENDED = exports.TEST = exports.ERROR = exports.ACTIVE = exports.PENDING = exports.CREATED = void 0;
|
|
3
|
+
exports.UNKNOWN = exports.MAINTENANCE = exports.DONE = exports.DELETED = exports.DELETABLE = exports.SUSPENDED = exports.TEST = exports.ERROR = exports.ACTIVE = exports.QUEUED = exports.PENDING = exports.CREATED = void 0;
|
|
4
4
|
exports.CREATED = 'created';
|
|
5
5
|
exports.PENDING = 'pending';
|
|
6
|
+
exports.QUEUED = 'queued';
|
|
6
7
|
exports.ACTIVE = 'active';
|
|
7
8
|
exports.ERROR = 'error';
|
|
8
9
|
exports.TEST = 'test';
|
|
@@ -6,6 +6,11 @@ export declare abstract class AbstractObject {
|
|
|
6
6
|
static LABEL_KEY: string;
|
|
7
7
|
protected _dataObject: DataObjectClass<any>;
|
|
8
8
|
constructor(dao: DataObjectClass<any>);
|
|
9
|
+
/**
|
|
10
|
+
* Return property object matching key
|
|
11
|
+
* @param key string
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
9
14
|
get(key: string): any;
|
|
10
15
|
set(key: string, val: any): any;
|
|
11
16
|
val(key: string): any;
|
|
@@ -13,6 +18,7 @@ export declare abstract class AbstractObject {
|
|
|
13
18
|
get path(): string;
|
|
14
19
|
get uid(): any;
|
|
15
20
|
get dataObject(): DataObjectClass<any>;
|
|
21
|
+
get _(): any;
|
|
16
22
|
get uri(): import("./ObjectUri").ObjectUri;
|
|
17
23
|
toJSON(): {
|
|
18
24
|
backend: string;
|
|
@@ -14,6 +14,11 @@ class AbstractObject {
|
|
|
14
14
|
constructor(dao) {
|
|
15
15
|
this._dataObject = dao;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Return property object matching key
|
|
19
|
+
* @param key string
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
17
22
|
get(key) {
|
|
18
23
|
return this._dataObject.get(key);
|
|
19
24
|
}
|
|
@@ -41,6 +46,9 @@ class AbstractObject {
|
|
|
41
46
|
get dataObject() {
|
|
42
47
|
return this._dataObject;
|
|
43
48
|
}
|
|
49
|
+
get _() {
|
|
50
|
+
return this._dataObject.asProxy();
|
|
51
|
+
}
|
|
44
52
|
get uri() {
|
|
45
53
|
return this._dataObject.uri;
|
|
46
54
|
}
|
|
@@ -39,7 +39,7 @@ export declare class BaseObjectCore extends AbstractObject implements BaseObject
|
|
|
39
39
|
* @param child
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
|
-
static fromObject<T extends BaseObject>(src: T, child?: any):
|
|
42
|
+
static fromObject<T extends BaseObject>(src: T, child?: any): any;
|
|
43
43
|
static factory(src?: string | ObjectUri | BaseObject | undefined, child?: any): Promise<any>;
|
|
44
44
|
/**
|
|
45
45
|
* Fetches an object from its backend path
|
|
@@ -52,7 +52,11 @@ export declare class BaseObjectCore extends AbstractObject implements BaseObject
|
|
|
52
52
|
* @param dao
|
|
53
53
|
* @returns
|
|
54
54
|
*/
|
|
55
|
-
static fromDataObject<T extends BaseObject>(dao: DataObjectClass<any>):
|
|
55
|
+
static fromDataObject<T extends BaseObject>(dao: DataObjectClass<any>): any;
|
|
56
|
+
/**
|
|
57
|
+
* Wrap instance into proxy to get access to properties
|
|
58
|
+
* @returns Proxy
|
|
59
|
+
*/
|
|
56
60
|
protected toProxy<T extends BaseObject>(): Proxy<Proxy<T>>;
|
|
57
61
|
asReference(): any;
|
|
58
62
|
query(): Query<any>;
|
|
@@ -63,7 +63,7 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
63
63
|
dao.uri.class = child;
|
|
64
64
|
dao.populateFromData(src);
|
|
65
65
|
const obj = new this(dao);
|
|
66
|
-
return obj
|
|
66
|
+
return obj; //.toProxy() as Proxy<T>
|
|
67
67
|
}
|
|
68
68
|
static factory(src = undefined, child = this) {
|
|
69
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -100,8 +100,12 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
100
100
|
*/
|
|
101
101
|
static fromDataObject(dao) {
|
|
102
102
|
const obj = new this(dao);
|
|
103
|
-
return obj
|
|
103
|
+
return obj; //.toProxy()
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Wrap instance into proxy to get access to properties
|
|
107
|
+
* @returns Proxy
|
|
108
|
+
*/
|
|
105
109
|
toProxy() {
|
|
106
110
|
return new ProxyConstructor_1.ProxyConstructor(this, {
|
|
107
111
|
get: (target, prop) => {
|
|
@@ -140,6 +144,7 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
140
144
|
});
|
|
141
145
|
}
|
|
142
146
|
asReference() {
|
|
147
|
+
console.log(this._dataObject.toReference());
|
|
143
148
|
return this._dataObject.toReference();
|
|
144
149
|
}
|
|
145
150
|
query() {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserClass } from './types/UserClass';
|
|
2
|
+
import { ObjectUri } from './ObjectUri';
|
|
3
|
+
export interface BaseObjectType {
|
|
4
|
+
name: string;
|
|
5
|
+
status: string;
|
|
6
|
+
createdBy?: UserClass | ObjectUri;
|
|
7
|
+
createdAt?: number;
|
|
8
|
+
updatedBy?: UserClass | ObjectUri;
|
|
9
|
+
updatedAt?: number;
|
|
10
|
+
deletedBy?: UserClass | ObjectUri;
|
|
11
|
+
deletedAt?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const BaseObjectProperties: any;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.BaseObjectProperties = void 0;
|
|
27
|
+
const statuses = __importStar(require("../statuses"));
|
|
28
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
+
const ObjectProperty_1 = require("../properties/ObjectProperty");
|
|
30
|
+
const EnumProperty_1 = require("../properties/EnumProperty");
|
|
31
|
+
const DateTimeProperty_1 = require("../properties/DateTimeProperty");
|
|
32
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
33
|
+
exports.BaseObjectProperties = [
|
|
34
|
+
{
|
|
35
|
+
name: 'name',
|
|
36
|
+
mandatory: true,
|
|
37
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
38
|
+
minLength: 1,
|
|
39
|
+
maxLength: 100,
|
|
40
|
+
htmlType: htmlType.NAME,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'status',
|
|
44
|
+
mandatory: true,
|
|
45
|
+
type: EnumProperty_1.EnumProperty.TYPE,
|
|
46
|
+
values: [
|
|
47
|
+
statuses.CREATED,
|
|
48
|
+
statuses.PENDING,
|
|
49
|
+
statuses.ACTIVE,
|
|
50
|
+
statuses.DELETED,
|
|
51
|
+
],
|
|
52
|
+
defaultValue: statuses.CREATED,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'createdBy',
|
|
56
|
+
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
57
|
+
instanceOf: 'User',
|
|
58
|
+
mandatory: true,
|
|
59
|
+
protected: true,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'createdAt',
|
|
63
|
+
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
64
|
+
mandatory: true,
|
|
65
|
+
protected: true,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'updatedBy',
|
|
69
|
+
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
70
|
+
instanceOf: 'User',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'updatedAt',
|
|
74
|
+
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'deletedBy',
|
|
78
|
+
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
79
|
+
instanceOf: 'User',
|
|
80
|
+
protected: true,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'deletedAt',
|
|
84
|
+
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
85
|
+
protected: true,
|
|
86
|
+
},
|
|
87
|
+
];
|
|
@@ -3,7 +3,6 @@ import { Query } from '../backends/Query';
|
|
|
3
3
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
4
4
|
import { DataObjectClass } from './types/DataObjectClass';
|
|
5
5
|
import Payload from './types/Payload';
|
|
6
|
-
import RepositoryClass from './types/RepositoryClass';
|
|
7
6
|
import { BaseObject } from './BaseObject';
|
|
8
7
|
import { Persisted } from './types/Persisted';
|
|
9
8
|
import { Proxy } from './types/ProxyConstructor';
|
|
@@ -11,13 +10,13 @@ import { Proxy } from './types/ProxyConstructor';
|
|
|
11
10
|
* CRUD methods for models/entities inheriting from BaseObject
|
|
12
11
|
* Extend this by passing the typeof of the desired class to the constructor
|
|
13
12
|
*/
|
|
14
|
-
export default class BaseRepository<T extends BaseObject>
|
|
15
|
-
protected
|
|
13
|
+
export default class BaseRepository<T extends BaseObject> {
|
|
14
|
+
protected _model: typeof BaseObjectCore;
|
|
16
15
|
backendAdapter: BackendInterface;
|
|
17
16
|
constructor(model: typeof BaseObjectCore, backendAdapter?: BackendInterface);
|
|
18
17
|
protected getDataObjectFromUid(uid: string): Promise<DataObjectClass<any>>;
|
|
19
|
-
create(obj:
|
|
20
|
-
read(
|
|
18
|
+
create<B extends BaseObjectCore>(obj: B, uid?: string): Promise<any>;
|
|
19
|
+
read(key: string): Promise<any>;
|
|
21
20
|
update(obj: Proxy<T>): Promise<Persisted<T>>;
|
|
22
21
|
delete(uid: string): Promise<void>;
|
|
23
22
|
query(query: Query<typeof BaseObjectCore>): Promise<Payload<Persisted<T>>>;
|
|
@@ -43,15 +43,15 @@ const RESOURCE_GONE_ERROR = `The resource you are trying to access has been dele
|
|
|
43
43
|
*/
|
|
44
44
|
class BaseRepository {
|
|
45
45
|
constructor(model, backendAdapter = Core_1.Core.getBackend()) {
|
|
46
|
-
this.
|
|
46
|
+
this._model = model;
|
|
47
47
|
this.backendAdapter = backendAdapter;
|
|
48
48
|
}
|
|
49
49
|
getDataObjectFromUid(uid) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const collection = this.
|
|
51
|
+
const collection = this._model.COLLECTION || this._model.name.toLowerCase();
|
|
52
52
|
const path = `${collection}/${uid}`;
|
|
53
|
-
const dataObject =
|
|
54
|
-
properties: this.
|
|
53
|
+
const dataObject = DataObject_1.DataObject.factory({
|
|
54
|
+
properties: this._model.PROPS_DEFINITION,
|
|
55
55
|
uri: path,
|
|
56
56
|
});
|
|
57
57
|
dataObject.uid = uid;
|
|
@@ -60,17 +60,18 @@ class BaseRepository {
|
|
|
60
60
|
}
|
|
61
61
|
create(obj, uid) {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
return this.model.fromDataObject(savedObj);
|
|
63
|
+
const savedObj = yield this.backendAdapter.create(obj.dataObject, uid);
|
|
64
|
+
return this._model.fromDataObject(savedObj); //as Persisted<T>
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
|
-
read(
|
|
67
|
+
read(key) {
|
|
69
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const uid = key.indexOf('/') !== -1 ? key.substring(key.lastIndexOf('/') + 1) : key;
|
|
70
70
|
try {
|
|
71
71
|
const dataObject = yield this.getDataObjectFromUid(uid);
|
|
72
72
|
const response = yield this.backendAdapter.read(dataObject);
|
|
73
|
-
const obj = this.
|
|
73
|
+
const obj = this._model.fromDataObject(response);
|
|
74
|
+
// TODO should be moved to the backend middleware
|
|
74
75
|
if (obj.status === statuses.DELETED) {
|
|
75
76
|
throw new ResourcesErrors_1.GoneError(RESOURCE_GONE_ERROR);
|
|
76
77
|
}
|
|
@@ -91,7 +92,7 @@ class BaseRepository {
|
|
|
91
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
93
|
const dataObject = obj.core.dataObject;
|
|
93
94
|
const savedObj = yield this.backendAdapter.update(dataObject);
|
|
94
|
-
return this.
|
|
95
|
+
return this._model.fromDataObject(savedObj);
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
delete(uid) {
|
|
@@ -26,6 +26,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
26
26
|
protected _properties: Properties;
|
|
27
27
|
protected _persisted: boolean;
|
|
28
28
|
protected _populated: boolean;
|
|
29
|
+
protected _proxied: any;
|
|
29
30
|
/**
|
|
30
31
|
* Has data been modified since last backend operation?
|
|
31
32
|
*/
|
|
@@ -36,6 +37,11 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
36
37
|
*/
|
|
37
38
|
protected constructor(params: DataObjectParams | undefined);
|
|
38
39
|
protected _init(properties: any[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Wrap instance into proxy to get access to properties
|
|
42
|
+
* @returns Proxy
|
|
43
|
+
*/
|
|
44
|
+
asProxy(): this;
|
|
39
45
|
setProperties(properties: Properties): void;
|
|
40
46
|
/**
|
|
41
47
|
* Populate data object from instant data or backend query
|
|
@@ -81,7 +87,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
81
87
|
* @param key string
|
|
82
88
|
* @returns any
|
|
83
89
|
*/
|
|
84
|
-
val(key: string): any;
|
|
90
|
+
val(key: string, transform?: string | undefined): any;
|
|
85
91
|
toJSON(objectsAsReferences?: boolean): {
|
|
86
92
|
[x: string]: any;
|
|
87
93
|
};
|
|
@@ -52,6 +52,24 @@ class DataObject {
|
|
|
52
52
|
this._properties[prop.name] = Property_1.Property.factory(prop, this);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Wrap instance into proxy to get access to properties
|
|
57
|
+
* @returns Proxy
|
|
58
|
+
*/
|
|
59
|
+
asProxy() {
|
|
60
|
+
return new Proxy(this, {
|
|
61
|
+
get: (target, prop) => {
|
|
62
|
+
return target.val(prop);
|
|
63
|
+
},
|
|
64
|
+
set(target, prop, newValue) {
|
|
65
|
+
if (prop === 'uid' || prop === 'core') {
|
|
66
|
+
throw new Error(`Property '${prop}' is readonly`);
|
|
67
|
+
}
|
|
68
|
+
target.set(prop, newValue);
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
55
73
|
setProperties(properties) {
|
|
56
74
|
// TODO check if doable
|
|
57
75
|
this._properties = properties;
|
|
@@ -195,9 +213,9 @@ class DataObject {
|
|
|
195
213
|
* @param key string
|
|
196
214
|
* @returns any
|
|
197
215
|
*/
|
|
198
|
-
val(key) {
|
|
216
|
+
val(key, transform = undefined) {
|
|
199
217
|
if (this.has(key)) {
|
|
200
|
-
return Reflect.get(this._properties, key).val();
|
|
218
|
+
return Reflect.get(this._properties, key).val(transform);
|
|
201
219
|
}
|
|
202
220
|
else {
|
|
203
221
|
throw new Error(`Unknown property '${key}'`);
|
|
@@ -221,7 +239,7 @@ class DataObject {
|
|
|
221
239
|
const value = prop.val();
|
|
222
240
|
Reflect.set(data, key, value
|
|
223
241
|
? objectsAsReferences && !(value instanceof ObjectUri_1.ObjectUri)
|
|
224
|
-
? value.
|
|
242
|
+
? value.asReference()
|
|
225
243
|
: value.toJSON
|
|
226
244
|
? value.toJSON()
|
|
227
245
|
: value
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EntityProperties: any;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.EntityProperties = void 0;
|
|
27
|
+
const CollectionProperty_1 = require("../properties/CollectionProperty");
|
|
28
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
30
|
+
const User_1 = require("./User");
|
|
31
|
+
exports.EntityProperties = [
|
|
32
|
+
{
|
|
33
|
+
// surcharge property minLength and htmlType
|
|
34
|
+
name: 'name',
|
|
35
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
36
|
+
mandatory: true,
|
|
37
|
+
minLength: 1,
|
|
38
|
+
htmlType: htmlType.ORG,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'bogus',
|
|
42
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
43
|
+
mandatory: true,
|
|
44
|
+
minLength: 1,
|
|
45
|
+
htmlType: htmlType.ORG,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'users',
|
|
49
|
+
mandatory: true,
|
|
50
|
+
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
51
|
+
instanceOf: User_1.User,
|
|
52
|
+
parentKey: 'entity',
|
|
53
|
+
},
|
|
54
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UserProperties: any;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.UserProperties = void 0;
|
|
27
|
+
const properties_1 = require("../properties");
|
|
28
|
+
const HashProperty_1 = require("../properties/HashProperty");
|
|
29
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
30
|
+
const Entity_1 = require("./Entity");
|
|
31
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
32
|
+
/**
|
|
33
|
+
* Callback function to populate the 'name' property
|
|
34
|
+
* @param dao DataObject
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
const onChange = (dao) => dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`);
|
|
38
|
+
exports.UserProperties = [
|
|
39
|
+
{
|
|
40
|
+
// change name property minLength
|
|
41
|
+
name: 'name',
|
|
42
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
43
|
+
minLength: 0,
|
|
44
|
+
fullSearch: true,
|
|
45
|
+
htmlType: htmlType.NAME,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'firstname',
|
|
49
|
+
mandatory: true,
|
|
50
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
51
|
+
minLength: 1,
|
|
52
|
+
maxLength: 100,
|
|
53
|
+
htmlType: htmlType.GIVEN_NAME,
|
|
54
|
+
onChange,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'lastname',
|
|
58
|
+
mandatory: true,
|
|
59
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
60
|
+
minLength: 1,
|
|
61
|
+
maxLength: 100,
|
|
62
|
+
htmlType: htmlType.FAMILY_NAME,
|
|
63
|
+
onChange,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'gender',
|
|
67
|
+
mandatory: false,
|
|
68
|
+
type: properties_1.EnumProperty.TYPE,
|
|
69
|
+
values: ['male', 'female', 'nonbinary'],
|
|
70
|
+
htmlType: htmlType.GENDER,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'birthday',
|
|
74
|
+
mandatory: false,
|
|
75
|
+
type: properties_1.DateTimeProperty.TYPE,
|
|
76
|
+
htmlType: htmlType.BIRTHDAY,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'email',
|
|
80
|
+
mandatory: true,
|
|
81
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
82
|
+
minLength: 1,
|
|
83
|
+
maxLength: 100,
|
|
84
|
+
fullSearch: true,
|
|
85
|
+
htmlType: htmlType.EMAIL,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'password',
|
|
89
|
+
mandatory: true,
|
|
90
|
+
type: HashProperty_1.HashProperty.TYPE,
|
|
91
|
+
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
92
|
+
salt: '',
|
|
93
|
+
minLength: 5,
|
|
94
|
+
maxLength: 20,
|
|
95
|
+
htmlType: htmlType.PASSWORD,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'entity',
|
|
99
|
+
mandatory: false,
|
|
100
|
+
type: properties_1.ObjectProperty.TYPE,
|
|
101
|
+
instanceof: Entity_1.Entity,
|
|
102
|
+
},
|
|
103
|
+
];
|
|
@@ -4,6 +4,7 @@ import { ObjectUri } from './ObjectUri';
|
|
|
4
4
|
import { AbstractObject } from './AbstractObject';
|
|
5
5
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
6
6
|
import { BaseObjectProperties } from './BaseObject';
|
|
7
|
+
import BaseRepository from './BaseRepository';
|
|
7
8
|
import { UserCore, UserProperties } from './User';
|
|
8
9
|
import { Entity } from './Entity';
|
|
9
|
-
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObjectCore, UserCore, Entity, BaseObjectProperties, UserProperties, };
|
|
10
|
+
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObjectCore, BaseRepository, UserCore, Entity, BaseObjectProperties, UserProperties, };
|
package/lib/components/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserProperties = exports.BaseObjectProperties = exports.UserCore = exports.BaseObjectCore = exports.AbstractObject = exports.ObjectUri = exports.DataObject = void 0;
|
|
6
|
+
exports.UserProperties = exports.BaseObjectProperties = exports.UserCore = exports.BaseRepository = exports.BaseObjectCore = exports.AbstractObject = exports.ObjectUri = exports.DataObject = void 0;
|
|
4
7
|
const DataObject_1 = require("./DataObject");
|
|
5
8
|
Object.defineProperty(exports, "DataObject", { enumerable: true, get: function () { return DataObject_1.DataObject; } });
|
|
6
9
|
const ObjectUri_1 = require("./ObjectUri");
|
|
@@ -11,6 +14,8 @@ const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
|
11
14
|
Object.defineProperty(exports, "BaseObjectCore", { enumerable: true, get: function () { return BaseObjectCore_1.BaseObjectCore; } });
|
|
12
15
|
const BaseObject_1 = require("./BaseObject");
|
|
13
16
|
Object.defineProperty(exports, "BaseObjectProperties", { enumerable: true, get: function () { return BaseObject_1.BaseObjectProperties; } });
|
|
17
|
+
const BaseRepository_1 = __importDefault(require("./BaseRepository"));
|
|
18
|
+
exports.BaseRepository = BaseRepository_1.default;
|
|
14
19
|
const User_1 = require("./User");
|
|
15
20
|
Object.defineProperty(exports, "UserCore", { enumerable: true, get: function () { return User_1.UserCore; } });
|
|
16
21
|
Object.defineProperty(exports, "UserProperties", { enumerable: true, get: function () { return User_1.UserProperties; } });
|
|
@@ -18,7 +18,7 @@ export default interface RepositoryClass<T extends BaseObject> {
|
|
|
18
18
|
* @param uid
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
|
-
read(uid: string): Promise<
|
|
21
|
+
read(uid: string): Promise<any>;
|
|
22
22
|
/**
|
|
23
23
|
* Updates a given object in the collction and returns it
|
|
24
24
|
* @param obj
|
package/lib/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { BaseObject, BaseObjectProperties } from './components/BaseObject';
|
|
|
18
18
|
import { Proxy } from './components/types/ProxyConstructor';
|
|
19
19
|
import { InjectMetaMiddleware } from './backends/middlewares/InjectMetaMiddleware';
|
|
20
20
|
import RepositoryClass from './components/types/RepositoryClass';
|
|
21
|
-
import
|
|
21
|
+
import BaseRepository from './components/BaseRepository';
|
|
22
22
|
import Middleware from './backends/middlewares/Middleware';
|
|
23
23
|
import { User } from './components/User';
|
|
24
24
|
import UserRepository from './components/UserRepository';
|
|
@@ -26,4 +26,4 @@ import { Entity } from './components/Entity';
|
|
|
26
26
|
import EntityRepository from './components/EntityRepository';
|
|
27
27
|
import { AbstractAdapter, MockAdapter, BackendError, BackendParameters, Query, Filter, Filters, Limits, Sorting, SortAndLimit } from './backends';
|
|
28
28
|
import { BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError } from './common/ResourcesErrors';
|
|
29
|
-
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass,
|
|
29
|
+
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass, MockAdapter, ObjectUri, DataObjectClass, DataObject, AbstractObject, BaseObject, BaseObjectCore, BaseObjectProperties, BackendParameters, BaseRepository, BackendError, Query, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, User, Proxy, UserRepository, Entity, EntityRepository, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError, };
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.GoneError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.EntityRepository = exports.UserRepository = exports.InjectMetaMiddleware = exports.SortAndLimit = exports.Sorting = exports.Limits = exports.Filters = exports.Filter = exports.Query = exports.BackendError = exports.BaseObjectProperties = exports.BaseObjectCore = exports.AbstractObject = exports.DataObject = exports.ObjectUri = exports.MockAdapter = exports.
|
|
29
|
+
exports.GoneError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.EntityRepository = exports.UserRepository = exports.InjectMetaMiddleware = exports.SortAndLimit = exports.Sorting = exports.Limits = exports.Filters = exports.Filter = exports.Query = exports.BackendError = exports.BaseRepository = exports.BaseObjectProperties = exports.BaseObjectCore = exports.AbstractObject = exports.DataObject = exports.ObjectUri = exports.MockAdapter = exports.AbstractAdapter = exports.StringProperty = exports.ObjectProperty = exports.HashProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.BaseProperty = exports.Property = exports.Core = exports.utils = exports.statuses = void 0;
|
|
30
30
|
const Core_1 = require("./Core");
|
|
31
31
|
Object.defineProperty(exports, "Core", { enumerable: true, get: function () { return Core_1.Core; } });
|
|
32
32
|
const statuses = __importStar(require("./common/statuses"));
|
|
@@ -62,7 +62,7 @@ Object.defineProperty(exports, "BaseObjectProperties", { enumerable: true, get:
|
|
|
62
62
|
const InjectMetaMiddleware_1 = require("./backends/middlewares/InjectMetaMiddleware");
|
|
63
63
|
Object.defineProperty(exports, "InjectMetaMiddleware", { enumerable: true, get: function () { return InjectMetaMiddleware_1.InjectMetaMiddleware; } });
|
|
64
64
|
const BaseRepository_1 = __importDefault(require("./components/BaseRepository"));
|
|
65
|
-
exports.
|
|
65
|
+
exports.BaseRepository = BaseRepository_1.default;
|
|
66
66
|
const UserRepository_1 = __importDefault(require("./components/UserRepository"));
|
|
67
67
|
exports.UserRepository = UserRepository_1.default;
|
|
68
68
|
const EntityRepository_1 = __importDefault(require("./components/EntityRepository"));
|
|
@@ -52,7 +52,7 @@ class BaseProperty {
|
|
|
52
52
|
return this;
|
|
53
53
|
}
|
|
54
54
|
val(transform = undefined) {
|
|
55
|
-
return transform ? transform(this._value) : this._value;
|
|
55
|
+
return transform ? transform(this._value) : this._value || this._defaultValue;
|
|
56
56
|
}
|
|
57
57
|
_enable(value) {
|
|
58
58
|
return value === undefined || value === true;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { BaseObject } from '../components/BaseObject';
|
|
2
1
|
import { ObjectUri } from '../components/ObjectUri';
|
|
3
2
|
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
4
|
-
import {
|
|
3
|
+
import { BaseObjectClass } from '../components/types/BaseObjectClass';
|
|
5
4
|
export interface ObjectPropertyType extends BasePropertyType {
|
|
6
|
-
instanceOf
|
|
5
|
+
instanceOf: any;
|
|
7
6
|
}
|
|
8
7
|
export declare class ObjectProperty extends BaseProperty {
|
|
9
8
|
static TYPE: string;
|
|
10
|
-
_value:
|
|
11
|
-
_instanceOf:
|
|
9
|
+
_value: BaseObjectClass | ObjectUri | undefined;
|
|
10
|
+
_instanceOf: any;
|
|
12
11
|
constructor(config: ObjectPropertyType);
|
|
12
|
+
val(transform?: string | undefined): any;
|
|
13
13
|
set(value: object): this;
|
|
14
14
|
toJSON(): any;
|
|
15
15
|
}
|
|
@@ -4,11 +4,64 @@ exports.ObjectProperty = void 0;
|
|
|
4
4
|
const DataObject_1 = require("../components/DataObject");
|
|
5
5
|
const ObjectUri_1 = require("../components/ObjectUri");
|
|
6
6
|
const BaseProperty_1 = require("./BaseProperty");
|
|
7
|
+
const Query_1 = require("../backends/Query");
|
|
8
|
+
const Core_1 = require("../Core");
|
|
7
9
|
class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
8
10
|
constructor(config) {
|
|
9
11
|
super(config);
|
|
10
12
|
this._value = undefined;
|
|
11
|
-
this._instanceOf = config.instanceOf
|
|
13
|
+
this._instanceOf = config.instanceOf;
|
|
14
|
+
}
|
|
15
|
+
val(transform = undefined) {
|
|
16
|
+
if (typeof this._instanceOf === 'string') {
|
|
17
|
+
console.log(`Getting instance from string ${this._instanceOf}`);
|
|
18
|
+
this._instanceOf = Core_1.Core.getClass(this._instanceOf);
|
|
19
|
+
//throw new Error(`Parameter 'instanceOf' was not properly setted`)
|
|
20
|
+
}
|
|
21
|
+
if (!this._value) {
|
|
22
|
+
return this._defaultValue;
|
|
23
|
+
}
|
|
24
|
+
switch (transform) {
|
|
25
|
+
case Query_1.returnAs.AS_DATAOBJECTS:
|
|
26
|
+
if (this._value instanceof DataObject_1.DataObject) {
|
|
27
|
+
console.log(`Returning already existing dataObject`);
|
|
28
|
+
return this._value;
|
|
29
|
+
}
|
|
30
|
+
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
31
|
+
console.log(`Converting objectUri -> dataObject`);
|
|
32
|
+
return DataObject_1.DataObject.factory({
|
|
33
|
+
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
34
|
+
uri: this._value,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.log(`Converting instance -> dataObject`);
|
|
39
|
+
return this._value.dataObject;
|
|
40
|
+
}
|
|
41
|
+
case Query_1.returnAs.AS_INSTANCES:
|
|
42
|
+
if (this._value instanceof DataObject_1.DataObject) {
|
|
43
|
+
console.log(`Converting dataObject -> instance`);
|
|
44
|
+
return Reflect.construct(this._instanceOf, [this._value]);
|
|
45
|
+
}
|
|
46
|
+
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
47
|
+
console.log('ObjectProperty', this);
|
|
48
|
+
console.log(`Converting objectUri -> dataObject -> instance`);
|
|
49
|
+
console.log(this._instanceOf);
|
|
50
|
+
const dao = DataObject_1.DataObject.factory({
|
|
51
|
+
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
52
|
+
uri: this._value,
|
|
53
|
+
});
|
|
54
|
+
return Reflect.construct(this._instanceOf, [dao]);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log(`Returning already existing instance`);
|
|
58
|
+
return this._value;
|
|
59
|
+
}
|
|
60
|
+
return this._value;
|
|
61
|
+
case Query_1.returnAs.AS_OBJECTURIS:
|
|
62
|
+
default:
|
|
63
|
+
return this._value;
|
|
64
|
+
}
|
|
12
65
|
}
|
|
13
66
|
set(value) {
|
|
14
67
|
if (value instanceof ObjectUri_1.ObjectUri &&
|
|
@@ -23,8 +76,8 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
23
76
|
return this._value.toJSON();
|
|
24
77
|
}
|
|
25
78
|
return this._value &&
|
|
26
|
-
(this._value.
|
|
27
|
-
? this._value.
|
|
79
|
+
(this._value.dataObject || this._value instanceof DataObject_1.DataObject)
|
|
80
|
+
? this._value.dataObject.toReference()
|
|
28
81
|
: null;
|
|
29
82
|
}
|
|
30
83
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
2
|
-
import { BaseProperty
|
|
2
|
+
import { BaseProperty } from './BaseProperty';
|
|
3
|
+
import { BooleanPropertyType } from './BooleanProperty';
|
|
4
|
+
import { DateTimePropertyType } from './DateTimeProperty';
|
|
5
|
+
import { EnumPropertyType } from './EnumProperty';
|
|
6
|
+
import { HashPropertyType } from './HashProperty';
|
|
7
|
+
import { StringPropertyType } from './StringProperty';
|
|
8
|
+
import { NumberPropertyType } from './NumberProperty';
|
|
9
|
+
import { ObjectPropertyType } from './ObjectProperty';
|
|
3
10
|
export declare class Property {
|
|
4
11
|
static TYPE_ANY: string;
|
|
5
12
|
static TYPE_NUMBER: string;
|
|
@@ -11,5 +18,5 @@ export declare class Property {
|
|
|
11
18
|
static TYPE_DATETIME: string;
|
|
12
19
|
static TYPE_ARRAY: string;
|
|
13
20
|
static TYPE_MAP: string;
|
|
14
|
-
static factory
|
|
21
|
+
static factory(params: ObjectPropertyType & StringPropertyType & NumberPropertyType & EnumPropertyType & BooleanPropertyType & HashPropertyType & DateTimePropertyType, parent: DataObjectClass<any>): BaseProperty;
|
|
15
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta1",
|
|
4
4
|
"description": "Core objects for business apps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "tsc && jest --verbose",
|
|
28
28
|
"build": "tsc --watch",
|
|
29
|
-
"
|
|
29
|
+
"patch": "yarn version --patch --no-git-tag-version",
|
|
30
|
+
"push": "yarn publish --access public",
|
|
30
31
|
"prepublish": "tsc"
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
}
|