@quatrain/core 0.5.6 → 1.0.0-beta2
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.d.ts +28 -0
- package/lib/Backend.js +0 -9
- package/lib/Core.d.ts +8 -8
- package/lib/Core.js +13 -3
- package/lib/backends/AbstractAdapter.d.ts +6 -42
- package/lib/backends/AbstractAdapter.js +0 -5
- package/lib/backends/BackendInterface.d.ts +13 -0
- package/lib/backends/BackendInterface.js +2 -0
- package/lib/backends/MockAdapter.d.ts +6 -4
- package/lib/backends/MockAdapter.js +15 -6
- package/lib/backends/Query.d.ts +20 -8
- package/lib/backends/Query.js +10 -6
- package/lib/backends/index.d.ts +4 -3
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +9 -0
- package/lib/backends/middlewares/InjectKeywordsMiddleware.js +47 -0
- package/lib/backends/middlewares/InjectMetaMiddleware copy.d.ts +12 -0
- package/lib/backends/middlewares/InjectMetaMiddleware copy.js +30 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +3 -4
- package/lib/backends/middlewares/InjectMetaMiddleware.js +3 -3
- package/lib/backends/types/BackendInterface.d.ts +13 -0
- package/lib/backends/types/BackendInterface.js +2 -0
- package/lib/common/statuses.d.ts +3 -0
- package/lib/common/statuses.js +4 -1
- package/lib/components/AbstractObject.d.ts +6 -0
- package/lib/components/AbstractObject.js +8 -0
- package/lib/components/BaseObject.d.ts +3 -3
- package/lib/components/BaseObject.js +2 -0
- package/lib/components/BaseObjectCore.d.ts +6 -2
- package/lib/components/BaseObjectCore.js +6 -2
- package/lib/components/BaseObjectProperties.d.ts +13 -0
- package/lib/components/BaseObjectProperties.js +87 -0
- package/lib/components/BaseRepository.d.ts +13 -13
- package/lib/components/BaseRepository.js +18 -20
- package/lib/components/DataObject.d.ts +8 -1
- package/lib/components/DataObject.js +32 -9
- package/lib/components/Entity.d.ts +2 -16
- package/lib/components/Entity.js +4 -2
- package/lib/components/EntityProperties.d.ts +1 -0
- package/lib/components/EntityProperties.js +54 -0
- package/lib/components/EntityRepository.d.ts +1 -1
- package/lib/components/ObjectUri.js +1 -1
- package/lib/components/User.d.ts +2 -3
- package/lib/components/User.js +4 -2
- package/lib/components/UserProperties.d.ts +1 -0
- package/lib/components/UserProperties.js +103 -0
- package/lib/components/UserRepository.d.ts +2 -2
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.js +6 -1
- package/lib/components/types/DataObjectClass.d.ts +3 -0
- package/lib/components/types/RepositoryClass.d.ts +2 -2
- package/lib/components/types/UserClass.d.ts +3 -0
- package/lib/components/types/UserClass.js +2 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +6 -2
- package/lib/properties/BaseProperty.js +1 -1
- package/lib/properties/CollectionProperty.d.ts +2 -2
- package/lib/properties/HashProperty.d.ts +6 -0
- package/lib/properties/HashProperty.js +8 -0
- 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/lib/properties/types/PropertyClassType.d.ts +1 -0
- package/package.json +4 -3
|
@@ -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
|
}
|
|
@@ -4,10 +4,10 @@ export interface BaseObject {
|
|
|
4
4
|
name: string;
|
|
5
5
|
status: string;
|
|
6
6
|
createdBy?: User | ObjectUri;
|
|
7
|
-
createdAt?: number;
|
|
7
|
+
createdAt?: number | string;
|
|
8
8
|
updatedBy?: User | ObjectUri;
|
|
9
|
-
updatedAt?: number;
|
|
9
|
+
updatedAt?: number | string;
|
|
10
10
|
deletedBy?: User | ObjectUri;
|
|
11
|
-
deletedAt?: number;
|
|
11
|
+
deletedAt?: number | string;
|
|
12
12
|
}
|
|
13
13
|
export declare const BaseObjectProperties: any;
|
|
@@ -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;
|
|
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) => {
|
|
@@ -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
|
+
];
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Query } from '../backends/Query';
|
|
1
|
+
import { Query, QueryResultType } from '../backends/Query';
|
|
3
2
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
4
3
|
import { DataObjectClass } from './types/DataObjectClass';
|
|
5
|
-
import Payload from './types/Payload';
|
|
6
|
-
import RepositoryClass from './types/RepositoryClass';
|
|
7
4
|
import { BaseObject } from './BaseObject';
|
|
8
|
-
import {
|
|
9
|
-
import { Proxy } from './types/ProxyConstructor';
|
|
5
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
10
6
|
/**
|
|
11
7
|
* CRUD methods for models/entities inheriting from BaseObject
|
|
12
8
|
* Extend this by passing the typeof of the desired class to the constructor
|
|
13
9
|
*/
|
|
14
|
-
export default class BaseRepository<T extends BaseObject>
|
|
15
|
-
protected
|
|
10
|
+
export default class BaseRepository<T extends BaseObject> {
|
|
11
|
+
protected _model: typeof BaseObjectCore;
|
|
16
12
|
backendAdapter: BackendInterface;
|
|
17
13
|
constructor(model: typeof BaseObjectCore, backendAdapter?: BackendInterface);
|
|
18
14
|
protected getDataObjectFromUid(uid: string): Promise<DataObjectClass<any>>;
|
|
19
|
-
create(obj:
|
|
20
|
-
read(
|
|
21
|
-
update(obj:
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
create<B extends BaseObjectCore>(obj: B, uid?: string): Promise<any>;
|
|
16
|
+
read(key: string): Promise<any>;
|
|
17
|
+
update(obj: BaseObjectCore): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* delete object in its backend
|
|
20
|
+
* @param uid string
|
|
21
|
+
*/
|
|
22
|
+
delete(uid: string): Promise<DataObjectClass<any>>;
|
|
23
|
+
query(query: Query<any>): Promise<QueryResultType<T>>;
|
|
24
24
|
}
|
|
@@ -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
|
}
|
|
@@ -89,27 +90,24 @@ class BaseRepository {
|
|
|
89
90
|
}
|
|
90
91
|
update(obj) {
|
|
91
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
const dataObject = obj.
|
|
93
|
+
const dataObject = obj.dataObject;
|
|
93
94
|
const savedObj = yield this.backendAdapter.update(dataObject);
|
|
94
|
-
return this.
|
|
95
|
+
return this._model.fromDataObject(savedObj);
|
|
95
96
|
});
|
|
96
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* delete object in its backend
|
|
100
|
+
* @param uid string
|
|
101
|
+
*/
|
|
97
102
|
delete(uid) {
|
|
98
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
104
|
const dataObject = yield this.getDataObjectFromUid(uid);
|
|
100
|
-
yield this.backendAdapter.delete(dataObject);
|
|
105
|
+
return yield this.backendAdapter.delete(dataObject);
|
|
101
106
|
});
|
|
102
107
|
}
|
|
103
108
|
query(query) {
|
|
104
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
|
|
106
|
-
const count = yield this.backendAdapter.count(query);
|
|
107
|
-
const meta = {
|
|
108
|
-
count,
|
|
109
|
-
updatedAt: new Date().getTime(),
|
|
110
|
-
};
|
|
111
|
-
const payload = { items, meta };
|
|
112
|
-
return payload;
|
|
110
|
+
return yield query.fetchAsInstances(this.backendAdapter);
|
|
113
111
|
});
|
|
114
112
|
}
|
|
115
113
|
}
|
|
@@ -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,7 +37,13 @@ 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;
|
|
46
|
+
addProperty(property: PropertyClassType): void;
|
|
40
47
|
/**
|
|
41
48
|
* Populate data object from instant data or backend query
|
|
42
49
|
* @param data
|
|
@@ -81,7 +88,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
81
88
|
* @param key string
|
|
82
89
|
* @returns any
|
|
83
90
|
*/
|
|
84
|
-
val(key: string): any;
|
|
91
|
+
val(key: string, transform?: string | undefined): any;
|
|
85
92
|
toJSON(objectsAsReferences?: boolean): {
|
|
86
93
|
[x: string]: any;
|
|
87
94
|
};
|
|
@@ -13,6 +13,7 @@ exports.DataObject = void 0;
|
|
|
13
13
|
const Core_1 = require("../Core");
|
|
14
14
|
const Property_1 = require("../properties/Property");
|
|
15
15
|
const ObjectUri_1 = require("./ObjectUri");
|
|
16
|
+
const ResourcesErrors_1 = require("../common/ResourcesErrors");
|
|
16
17
|
/**
|
|
17
18
|
* Data objects constitute the agnostic glue between objects and backends.
|
|
18
19
|
* They handle data and identifiers in a protected registry
|
|
@@ -52,10 +53,34 @@ class DataObject {
|
|
|
52
53
|
this._properties[prop.name] = Property_1.Property.factory(prop, this);
|
|
53
54
|
});
|
|
54
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Wrap instance into proxy to get access to properties
|
|
58
|
+
* @returns Proxy
|
|
59
|
+
*/
|
|
60
|
+
asProxy() {
|
|
61
|
+
return new Proxy(this, {
|
|
62
|
+
get: (target, prop) => {
|
|
63
|
+
return target.val(prop);
|
|
64
|
+
},
|
|
65
|
+
set(target, prop, newValue) {
|
|
66
|
+
if (prop === 'uid' || prop === 'core') {
|
|
67
|
+
throw new Error(`Property '${prop}' is readonly`);
|
|
68
|
+
}
|
|
69
|
+
target.set(prop, newValue);
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
55
74
|
setProperties(properties) {
|
|
56
75
|
// TODO check if doable
|
|
57
76
|
this._properties = properties;
|
|
58
77
|
}
|
|
78
|
+
addProperty(property) {
|
|
79
|
+
if (Object.keys(this._properties).includes(property.name)) {
|
|
80
|
+
throw new Error(`Property ${name} already exists`);
|
|
81
|
+
}
|
|
82
|
+
this._properties[property.name] = property;
|
|
83
|
+
}
|
|
59
84
|
/**
|
|
60
85
|
* Populate data object from instant data or backend query
|
|
61
86
|
* @param data
|
|
@@ -174,12 +199,10 @@ class DataObject {
|
|
|
174
199
|
* @returns BaseProperty
|
|
175
200
|
*/
|
|
176
201
|
get(key) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
throw new Error(err.message);
|
|
202
|
+
if (!Reflect.has(this._properties, key)) {
|
|
203
|
+
throw new ResourcesErrors_1.NotFoundError(`No property matching key ${key}`);
|
|
182
204
|
}
|
|
205
|
+
return Reflect.get(this._properties, key);
|
|
183
206
|
}
|
|
184
207
|
set(key, val) {
|
|
185
208
|
if (!this.has(key)) {
|
|
@@ -195,16 +218,16 @@ class DataObject {
|
|
|
195
218
|
* @param key string
|
|
196
219
|
* @returns any
|
|
197
220
|
*/
|
|
198
|
-
val(key) {
|
|
221
|
+
val(key, transform = undefined) {
|
|
199
222
|
if (this.has(key)) {
|
|
200
|
-
return Reflect.get(this._properties, key).val();
|
|
223
|
+
return Reflect.get(this._properties, key).val(transform);
|
|
201
224
|
}
|
|
202
225
|
else {
|
|
203
226
|
throw new Error(`Unknown property '${key}'`);
|
|
204
227
|
}
|
|
205
228
|
}
|
|
206
229
|
toJSON(objectsAsReferences = false) {
|
|
207
|
-
return Object.assign(Object.assign({}, (this.
|
|
230
|
+
return Object.assign(Object.assign({}, (this.uri && { uid: this.uri.uid, path: this.uri.path })), this._dataToJSON(objectsAsReferences));
|
|
208
231
|
}
|
|
209
232
|
toReference() {
|
|
210
233
|
return Object.assign(Object.assign({}, this._objectUri.toReference()), { label: this.val('name') || '' });
|
|
@@ -221,7 +244,7 @@ class DataObject {
|
|
|
221
244
|
const value = prop.val();
|
|
222
245
|
Reflect.set(data, key, value
|
|
223
246
|
? objectsAsReferences && !(value instanceof ObjectUri_1.ObjectUri)
|
|
224
|
-
? value.
|
|
247
|
+
? value.asReference()
|
|
225
248
|
: value.toJSON
|
|
226
249
|
? value.toJSON()
|
|
227
250
|
: value
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
import { User
|
|
3
|
+
import { User } from './User';
|
|
4
4
|
import { EntityClass } from './types/EntityClass';
|
|
5
5
|
export declare const EntityProperties: any;
|
|
6
6
|
export interface Entity extends BaseObject {
|
|
@@ -8,19 +8,5 @@ export interface Entity extends BaseObject {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class EntityCore extends BaseObjectCore implements EntityClass {
|
|
10
10
|
static COLLECTION: string;
|
|
11
|
-
static PROPS_DEFINITION:
|
|
12
|
-
name: string;
|
|
13
|
-
type: string;
|
|
14
|
-
mandatory: boolean;
|
|
15
|
-
minLength: number;
|
|
16
|
-
instanceOf?: undefined;
|
|
17
|
-
parentKey?: undefined;
|
|
18
|
-
} | {
|
|
19
|
-
name: string;
|
|
20
|
-
mandatory: boolean;
|
|
21
|
-
type: string;
|
|
22
|
-
instanceOf: typeof UserCore;
|
|
23
|
-
parentKey: string;
|
|
24
|
-
minLength?: undefined;
|
|
25
|
-
})[];
|
|
11
|
+
static PROPS_DEFINITION: any[];
|
|
26
12
|
}
|
package/lib/components/Entity.js
CHANGED
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.EntityCore = exports.EntityProperties = void 0;
|
|
27
27
|
const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
28
|
+
const BaseObject_1 = require("./BaseObject");
|
|
28
29
|
const User_1 = require("./User");
|
|
29
30
|
const CollectionProperty_1 = require("../properties/CollectionProperty");
|
|
30
31
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
@@ -49,15 +50,16 @@ exports.EntityProperties = [
|
|
|
49
50
|
class EntityCore extends BaseObjectCore_1.BaseObjectCore {
|
|
50
51
|
}
|
|
51
52
|
exports.EntityCore = EntityCore;
|
|
52
|
-
EntityCore.COLLECTION = '
|
|
53
|
+
EntityCore.COLLECTION = 'entities';
|
|
53
54
|
EntityCore.PROPS_DEFINITION = [
|
|
55
|
+
...BaseObject_1.BaseObjectProperties,
|
|
54
56
|
{
|
|
55
57
|
// surcharge property minLength and htmlType
|
|
56
58
|
name: 'name',
|
|
57
59
|
type: StringProperty_1.StringProperty.TYPE,
|
|
58
60
|
mandatory: true,
|
|
59
61
|
minLength: 1,
|
|
60
|
-
|
|
62
|
+
htmlType: htmlType.ORG,
|
|
61
63
|
},
|
|
62
64
|
{
|
|
63
65
|
name: 'users',
|
|
@@ -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
|
+
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
1
|
+
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
3
|
import { Entity } from './Entity';
|
|
4
4
|
export default class EntityRepository extends BaseRepository<Entity> {
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
import { Persisted } from './types/Persisted';
|
|
4
|
-
import { Proxy } from './types/ProxyConstructor';
|
|
5
3
|
export interface User extends BaseObject {
|
|
4
|
+
name: string;
|
|
6
5
|
firstname: string;
|
|
7
6
|
lastname: string;
|
|
8
7
|
gender?: 'male' | 'female' | 'nonbinary';
|
|
@@ -14,5 +13,5 @@ export declare const UserProperties: any;
|
|
|
14
13
|
export declare class UserCore extends BaseObjectCore {
|
|
15
14
|
static PROPS_DEFINITION: any;
|
|
16
15
|
static COLLECTION: string;
|
|
17
|
-
static factory(src?: any): Promise<
|
|
16
|
+
static factory(src?: any): Promise<UserCore>;
|
|
18
17
|
}
|
package/lib/components/User.js
CHANGED
|
@@ -39,6 +39,7 @@ const HashProperty_1 = require("../properties/HashProperty");
|
|
|
39
39
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
40
40
|
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
41
41
|
const BaseObject_1 = require("./BaseObject");
|
|
42
|
+
const Entity_1 = require("./Entity");
|
|
42
43
|
/**
|
|
43
44
|
* Callback function to populate the 'name' property
|
|
44
45
|
* @param dao DataObject
|
|
@@ -52,7 +53,6 @@ exports.UserProperties = [
|
|
|
52
53
|
name: 'name',
|
|
53
54
|
type: StringProperty_1.StringProperty.TYPE,
|
|
54
55
|
minLength: 0,
|
|
55
|
-
fullSearch: true,
|
|
56
56
|
htmlType: htmlType.NAME,
|
|
57
57
|
},
|
|
58
58
|
{
|
|
@@ -61,6 +61,7 @@ exports.UserProperties = [
|
|
|
61
61
|
type: StringProperty_1.StringProperty.TYPE,
|
|
62
62
|
minLength: 1,
|
|
63
63
|
maxLength: 100,
|
|
64
|
+
fullSearch: true,
|
|
64
65
|
htmlType: htmlType.GIVEN_NAME,
|
|
65
66
|
onChange,
|
|
66
67
|
},
|
|
@@ -70,6 +71,7 @@ exports.UserProperties = [
|
|
|
70
71
|
type: StringProperty_1.StringProperty.TYPE,
|
|
71
72
|
minLength: 1,
|
|
72
73
|
maxLength: 100,
|
|
74
|
+
fullSearch: true,
|
|
73
75
|
htmlType: htmlType.FAMILY_NAME,
|
|
74
76
|
onChange,
|
|
75
77
|
},
|
|
@@ -109,7 +111,7 @@ exports.UserProperties = [
|
|
|
109
111
|
name: 'entity',
|
|
110
112
|
mandatory: false,
|
|
111
113
|
type: properties_1.ObjectProperty.TYPE,
|
|
112
|
-
instanceOf:
|
|
114
|
+
instanceOf: Entity_1.EntityCore,
|
|
113
115
|
},
|
|
114
116
|
];
|
|
115
117
|
class UserCore extends BaseObjectCore_1.BaseObjectCore {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UserProperties: any;
|