@quatrain/core 0.2.0 → 0.3.0
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/Core.d.ts +3 -1
- package/lib/Core.js +2 -2
- package/lib/backends/AbstractAdapter.d.ts +11 -9
- package/lib/backends/MockAdapter.d.ts +16 -9
- package/lib/backends/MockAdapter.js +87 -22
- package/lib/backends/Query.d.ts +11 -3
- package/lib/backends/Query.js +30 -4
- package/lib/components/AbstractObject.d.ts +9 -9
- package/lib/components/AbstractObject.js +2 -2
- package/lib/components/BaseObject.d.ts +10 -11
- package/lib/components/BaseObject.js +42 -33
- package/lib/components/BaseObjectProperties.d.ts +5 -6
- package/lib/components/BaseObjectProperties.js +12 -9
- package/lib/components/DataObject.d.ts +21 -16
- package/lib/components/DataObject.js +35 -18
- package/lib/components/Entity.d.ts +6 -0
- package/lib/components/Entity.js +26 -0
- package/lib/components/EntityProperties.d.ts +1 -0
- package/lib/components/EntityProperties.js +12 -0
- package/lib/components/ObjectUri.d.ts +4 -1
- package/lib/components/ObjectUri.js +7 -4
- package/lib/components/User.d.ts +4 -4
- package/lib/components/User.js +20 -50
- package/lib/components/UserProperties.d.ts +1 -0
- package/lib/components/UserProperties.js +59 -0
- package/lib/components/index.d.ts +6 -3
- package/lib/components/index.js +5 -2
- package/lib/components/types/AbstractObjectClass.d.ts +6 -0
- package/lib/components/types/AbstractObjectClass.js +2 -0
- package/lib/components/types/BaseObjectClass.d.ts +6 -0
- package/lib/components/types/BaseObjectClass.js +2 -0
- package/lib/components/types/DataObjectClass.d.ts +21 -0
- package/lib/components/types/DataObjectClass.js +2 -0
- package/lib/components/types/EntityClass.d.ts +3 -0
- package/lib/components/types/EntityClass.js +2 -0
- package/lib/components/types/UserClass.d.ts +3 -0
- package/lib/components/types/UserClass.js +2 -0
- package/lib/properties/ArrayProperty.d.ts +1 -0
- package/lib/properties/ArrayProperty.js +6 -5
- package/lib/properties/BaseProperty.d.ts +5 -4
- package/lib/properties/BaseProperty.js +1 -0
- package/lib/properties/BooleanProperty.d.ts +2 -1
- package/lib/properties/BooleanProperty.js +3 -2
- package/lib/properties/CollectionProperty.d.ts +29 -0
- package/lib/properties/CollectionProperty.js +62 -0
- package/lib/properties/DateTimeProperty.d.ts +1 -0
- package/lib/properties/DateTimeProperty.js +1 -0
- package/lib/properties/EnumProperty.d.ts +1 -0
- package/lib/properties/EnumProperty.js +1 -0
- package/lib/properties/HashProperty.d.ts +1 -0
- package/lib/properties/HashProperty.js +1 -0
- package/lib/properties/MapProperty.d.ts +8 -0
- package/lib/properties/MapProperty.js +17 -0
- package/lib/properties/NumberProperty.d.ts +1 -0
- package/lib/properties/NumberProperty.js +1 -0
- package/lib/properties/ObjectProperty.d.ts +4 -7
- package/lib/properties/ObjectProperty.js +4 -1
- package/lib/properties/Property.d.ts +3 -7
- package/lib/properties/Property.js +13 -15
- package/lib/properties/StringProperty.d.ts +6 -0
- package/lib/properties/StringProperty.js +13 -7
- package/lib/properties/index.d.ts +4 -2
- package/lib/properties/index.js +5 -1
- package/lib/properties/types/PropertyClassType.d.ts +4 -2
- package/lib/properties/types/PropertyTypes.d.ts +4 -1
- package/package.json +3 -1
|
@@ -1,23 +1,29 @@
|
|
|
1
|
+
import { DataObjectProperties } from '../properties';
|
|
2
|
+
import { PropertyClassType } from '../properties/types/PropertyClassType';
|
|
1
3
|
import { AbstractObject } from './AbstractObject';
|
|
2
4
|
import { ObjectUri } from './ObjectUri';
|
|
5
|
+
import { DataObjectClass } from './types/DataObjectClass';
|
|
6
|
+
export declare type CoreObject<T extends AbstractObject> = T;
|
|
7
|
+
export declare type Properties = {
|
|
8
|
+
[x: string]: PropertyClassType;
|
|
9
|
+
};
|
|
3
10
|
export interface DataObjectFactoryType {
|
|
4
11
|
path: string;
|
|
5
12
|
[x: string]: any;
|
|
6
13
|
}
|
|
7
|
-
export
|
|
14
|
+
export interface DataObjectType {
|
|
15
|
+
uri?: string | ObjectUri;
|
|
16
|
+
properties: DataObjectProperties;
|
|
17
|
+
}
|
|
8
18
|
/**
|
|
9
19
|
* Data objects constitute the agnostic glue between objects and backends.
|
|
10
20
|
* They handle data and identifiers in a protected registry
|
|
11
21
|
* This is what backends and objects manipulate, oblivious of the other.
|
|
12
22
|
*/
|
|
13
|
-
export declare class DataObject {
|
|
14
|
-
protected _class: CoreObject<any>;
|
|
23
|
+
export declare class DataObject implements DataObjectClass {
|
|
15
24
|
protected _objectUri: ObjectUri;
|
|
16
|
-
protected _obj: any;
|
|
17
25
|
protected _uid: string | undefined;
|
|
18
|
-
protected _properties:
|
|
19
|
-
[x: string]: any;
|
|
20
|
-
};
|
|
26
|
+
protected _properties: Properties;
|
|
21
27
|
protected _persisted: boolean;
|
|
22
28
|
protected _populated: boolean;
|
|
23
29
|
/**
|
|
@@ -26,11 +32,11 @@ export declare class DataObject {
|
|
|
26
32
|
protected _modified: boolean;
|
|
27
33
|
/**
|
|
28
34
|
* Constructor is protected, use factory() instead
|
|
29
|
-
* @param
|
|
30
|
-
* @param properties array of properties instances
|
|
35
|
+
* @param params object of parameters
|
|
31
36
|
*/
|
|
32
|
-
protected constructor(
|
|
37
|
+
protected constructor(params: DataObjectType | undefined);
|
|
33
38
|
protected _init(properties: any[]): void;
|
|
39
|
+
setProperties(properties: Properties): void;
|
|
34
40
|
/**
|
|
35
41
|
* Populate data object from instant data or backend query
|
|
36
42
|
* @param data
|
|
@@ -38,23 +44,21 @@ export declare class DataObject {
|
|
|
38
44
|
populate(data?: any): Promise<DataObject>;
|
|
39
45
|
isPopulated(): boolean;
|
|
40
46
|
isPersisted(): boolean;
|
|
41
|
-
get properties():
|
|
42
|
-
[x: string]: any;
|
|
43
|
-
};
|
|
47
|
+
get properties(): Properties;
|
|
44
48
|
get backend(): string | undefined;
|
|
45
|
-
get class(): any;
|
|
46
49
|
get path(): string;
|
|
47
50
|
set uid(uid: string | undefined);
|
|
48
51
|
get uid(): string | undefined;
|
|
49
52
|
get data(): any;
|
|
50
53
|
set uri(uri: string | ObjectUri | undefined);
|
|
51
54
|
get uri(): ObjectUri;
|
|
55
|
+
get class(): any;
|
|
52
56
|
/**
|
|
53
57
|
* Returns property matching key or throw
|
|
54
58
|
* @param key string
|
|
55
59
|
* @returns BaseProperty
|
|
56
60
|
*/
|
|
57
|
-
get(key: string):
|
|
61
|
+
get(key: string): PropertyClassType;
|
|
58
62
|
set(key: string, val: any): this;
|
|
59
63
|
/**
|
|
60
64
|
* Get value of given property
|
|
@@ -79,5 +83,6 @@ export declare class DataObject {
|
|
|
79
83
|
* @param param
|
|
80
84
|
* @returns DataObject
|
|
81
85
|
*/
|
|
82
|
-
static factory(
|
|
86
|
+
static factory(param?: DataObjectType | undefined): Promise<DataObjectClass>;
|
|
87
|
+
clone(data?: any): Promise<DataObjectClass>;
|
|
83
88
|
}
|
|
@@ -21,10 +21,9 @@ const ObjectUri_1 = require("./ObjectUri");
|
|
|
21
21
|
class DataObject {
|
|
22
22
|
/**
|
|
23
23
|
* Constructor is protected, use factory() instead
|
|
24
|
-
* @param
|
|
25
|
-
* @param properties array of properties instances
|
|
24
|
+
* @param params object of parameters
|
|
26
25
|
*/
|
|
27
|
-
constructor(
|
|
26
|
+
constructor(params) {
|
|
28
27
|
this._uid = undefined;
|
|
29
28
|
this._properties = {};
|
|
30
29
|
this._persisted = false;
|
|
@@ -33,20 +32,30 @@ class DataObject {
|
|
|
33
32
|
* Has data been modified since last backend operation?
|
|
34
33
|
*/
|
|
35
34
|
this._modified = false;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
if (params) {
|
|
36
|
+
if (Array.isArray(params.properties)) {
|
|
37
|
+
this._init(params.properties);
|
|
38
|
+
}
|
|
39
|
+
if (typeof params.uri !== 'object') {
|
|
40
|
+
this._objectUri = new ObjectUri_1.ObjectUri(params.uri);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._objectUri = params.uri;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this._objectUri = new ObjectUri_1.ObjectUri();
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
_init(properties) {
|
|
43
|
-
// console.log(
|
|
44
|
-
// `Preparing properties for instance of ${this._class.constructor.name}`
|
|
45
|
-
// )
|
|
46
51
|
properties.forEach((prop) => {
|
|
47
52
|
this._properties[prop.name] = Property_1.Property.factory(prop, this);
|
|
48
53
|
});
|
|
49
54
|
}
|
|
55
|
+
setProperties(properties) {
|
|
56
|
+
// TODO check if doable
|
|
57
|
+
this._properties = properties;
|
|
58
|
+
}
|
|
50
59
|
/**
|
|
51
60
|
* Populate data object from instant data or backend query
|
|
52
61
|
* @param data
|
|
@@ -84,9 +93,6 @@ class DataObject {
|
|
|
84
93
|
get backend() {
|
|
85
94
|
return this._objectUri ? this._objectUri.backend : undefined;
|
|
86
95
|
}
|
|
87
|
-
get class() {
|
|
88
|
-
return this._class;
|
|
89
|
-
}
|
|
90
96
|
get path() {
|
|
91
97
|
return this._objectUri ? this._objectUri.path : '';
|
|
92
98
|
}
|
|
@@ -108,6 +114,10 @@ class DataObject {
|
|
|
108
114
|
get uri() {
|
|
109
115
|
return this._objectUri;
|
|
110
116
|
}
|
|
117
|
+
get class() {
|
|
118
|
+
// TODO get class type
|
|
119
|
+
return this.uri.class;
|
|
120
|
+
}
|
|
111
121
|
/**
|
|
112
122
|
* Returns property matching key or throw
|
|
113
123
|
* @param key string
|
|
@@ -191,13 +201,10 @@ class DataObject {
|
|
|
191
201
|
* @param param
|
|
192
202
|
* @returns DataObject
|
|
193
203
|
*/
|
|
194
|
-
static factory(
|
|
204
|
+
static factory(param = undefined) {
|
|
195
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
if (className === undefined) {
|
|
197
|
-
throw new Error(`className is a require value`);
|
|
198
|
-
}
|
|
199
206
|
try {
|
|
200
|
-
return new this(
|
|
207
|
+
return new this(param);
|
|
201
208
|
}
|
|
202
209
|
catch (err) {
|
|
203
210
|
console.log(err);
|
|
@@ -205,5 +212,15 @@ class DataObject {
|
|
|
205
212
|
}
|
|
206
213
|
});
|
|
207
214
|
}
|
|
215
|
+
clone(data = {}) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const cloned = yield DataObject.factory();
|
|
218
|
+
cloned.setProperties(this._properties);
|
|
219
|
+
if (data) {
|
|
220
|
+
yield cloned.populate(data);
|
|
221
|
+
}
|
|
222
|
+
return cloned;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
208
225
|
}
|
|
209
226
|
exports.DataObject = DataObject;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Entity = void 0;
|
|
13
|
+
const BaseObject_1 = require("./BaseObject");
|
|
14
|
+
const EntityProperties_1 = require("./EntityProperties");
|
|
15
|
+
class Entity extends BaseObject_1.BaseObject {
|
|
16
|
+
static factory(src = undefined) {
|
|
17
|
+
const _super = Object.create(null, {
|
|
18
|
+
factory: { get: () => super.factory }
|
|
19
|
+
});
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return _super.factory.call(this, src, Entity);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Entity = Entity;
|
|
26
|
+
Entity.PROPS_DEFINITION = EntityProperties_1.EntityProperties;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EntityProperties: any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityProperties = void 0;
|
|
4
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
5
|
+
exports.EntityProperties = [
|
|
6
|
+
{
|
|
7
|
+
// change name property minLength
|
|
8
|
+
name: 'name',
|
|
9
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
10
|
+
minLength: 0,
|
|
11
|
+
},
|
|
12
|
+
];
|
|
@@ -9,6 +9,7 @@ export declare class ObjectUri {
|
|
|
9
9
|
protected _uid: string | undefined;
|
|
10
10
|
protected _collection: string | undefined;
|
|
11
11
|
protected _label: string | undefined;
|
|
12
|
+
protected _objClass: any;
|
|
12
13
|
/**
|
|
13
14
|
* create object uri from string:
|
|
14
15
|
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
@@ -16,6 +17,8 @@ export declare class ObjectUri {
|
|
|
16
17
|
* @param str
|
|
17
18
|
*/
|
|
18
19
|
constructor(str?: string, label?: string | undefined);
|
|
20
|
+
set class(objClass: any);
|
|
21
|
+
get class(): any;
|
|
19
22
|
get backend(): string;
|
|
20
23
|
get path(): string;
|
|
21
24
|
set label(label: string | undefined);
|
|
@@ -35,7 +38,7 @@ export declare class ObjectUri {
|
|
|
35
38
|
label: string | undefined;
|
|
36
39
|
};
|
|
37
40
|
toJSON(): {
|
|
38
|
-
|
|
41
|
+
backend: string;
|
|
39
42
|
ref: string;
|
|
40
43
|
label: string | undefined;
|
|
41
44
|
};
|
|
@@ -48,6 +48,12 @@ class ObjectUri {
|
|
|
48
48
|
throw new Error('Path parts number must be 1 or even');
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
set class(objClass) {
|
|
52
|
+
this._objClass = objClass;
|
|
53
|
+
}
|
|
54
|
+
get class() {
|
|
55
|
+
return this._objClass;
|
|
56
|
+
}
|
|
51
57
|
get backend() {
|
|
52
58
|
return this._backend;
|
|
53
59
|
}
|
|
@@ -61,9 +67,6 @@ class ObjectUri {
|
|
|
61
67
|
return this._label;
|
|
62
68
|
}
|
|
63
69
|
get literal() {
|
|
64
|
-
// return `${this._backend}:${
|
|
65
|
-
// this._collection || ObjectUri.MISSING_COLLECTION
|
|
66
|
-
// }${ObjectUri.DEFAULT}${this._uid}`
|
|
67
70
|
return `${this._backend}:${this._pairs.join(ObjectUri.DEFAULT)}`;
|
|
68
71
|
}
|
|
69
72
|
set path(path) {
|
|
@@ -101,7 +104,7 @@ class ObjectUri {
|
|
|
101
104
|
}
|
|
102
105
|
toJSON() {
|
|
103
106
|
return {
|
|
104
|
-
|
|
107
|
+
backend: this._backend,
|
|
105
108
|
ref: this._path,
|
|
106
109
|
label: this._label,
|
|
107
110
|
};
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataObjectProperties } from '../properties';
|
|
2
1
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
|
|
4
|
-
export declare class User extends BaseObject {
|
|
5
|
-
static PROPS_DEFINITION:
|
|
2
|
+
import { UserClass } from './types/UserClass';
|
|
3
|
+
export declare class User extends BaseObject implements UserClass {
|
|
4
|
+
static PROPS_DEFINITION: any;
|
|
5
|
+
static factory(src?: any): Promise<User>;
|
|
6
6
|
}
|
package/lib/components/User.js
CHANGED
|
@@ -1,56 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.User =
|
|
4
|
-
const Property_1 = require("../properties/Property");
|
|
5
|
-
const HashProperty_1 = require("../properties/HashProperty");
|
|
12
|
+
exports.User = void 0;
|
|
6
13
|
const BaseObject_1 = require("./BaseObject");
|
|
7
|
-
|
|
8
|
-
* Callback function to populate the 'name' property
|
|
9
|
-
* @param dao DataObject
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
const onChange = (dao) => dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`);
|
|
13
|
-
exports.UserProperties = [
|
|
14
|
-
{
|
|
15
|
-
// change name property minLength
|
|
16
|
-
name: 'name',
|
|
17
|
-
type: Property_1.Property.TYPE_STRING,
|
|
18
|
-
minLength: 0,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: 'firstname',
|
|
22
|
-
mandatory: true,
|
|
23
|
-
type: Property_1.Property.TYPE_STRING,
|
|
24
|
-
minLength: 1,
|
|
25
|
-
maxLength: 100,
|
|
26
|
-
onChange,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'lastname',
|
|
30
|
-
mandatory: true,
|
|
31
|
-
type: Property_1.Property.TYPE_STRING,
|
|
32
|
-
minLength: 1,
|
|
33
|
-
maxLength: 100,
|
|
34
|
-
onChange,
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'email',
|
|
38
|
-
mandatory: true,
|
|
39
|
-
type: Property_1.Property.TYPE_STRING,
|
|
40
|
-
minLength: 1,
|
|
41
|
-
maxLength: 100,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'password',
|
|
45
|
-
mandatory: true,
|
|
46
|
-
type: Property_1.Property.TYPE_HASH,
|
|
47
|
-
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
48
|
-
salt: '',
|
|
49
|
-
minLength: 5,
|
|
50
|
-
maxLength: 20, // this is for the clear password
|
|
51
|
-
},
|
|
52
|
-
];
|
|
14
|
+
const UserProperties_1 = require("./UserProperties");
|
|
53
15
|
class User extends BaseObject_1.BaseObject {
|
|
16
|
+
static factory(src = undefined) {
|
|
17
|
+
const _super = Object.create(null, {
|
|
18
|
+
factory: { get: () => super.factory }
|
|
19
|
+
});
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return _super.factory.call(this, src, User);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
54
24
|
}
|
|
55
25
|
exports.User = User;
|
|
56
|
-
User.PROPS_DEFINITION =
|
|
26
|
+
User.PROPS_DEFINITION = UserProperties_1.UserProperties;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UserProperties: any;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserProperties = void 0;
|
|
4
|
+
const properties_1 = require("../properties");
|
|
5
|
+
const HashProperty_1 = require("../properties/HashProperty");
|
|
6
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
7
|
+
const Entity_1 = require("./Entity");
|
|
8
|
+
/**
|
|
9
|
+
* Callback function to populate the 'name' property
|
|
10
|
+
* @param dao DataObject
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
const onChange = (dao) => dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`);
|
|
14
|
+
exports.UserProperties = [
|
|
15
|
+
{
|
|
16
|
+
// change name property minLength
|
|
17
|
+
name: 'name',
|
|
18
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
19
|
+
minLength: 0,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'firstname',
|
|
23
|
+
mandatory: true,
|
|
24
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
25
|
+
minLength: 1,
|
|
26
|
+
maxLength: 100,
|
|
27
|
+
onChange,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'lastname',
|
|
31
|
+
mandatory: true,
|
|
32
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
33
|
+
minLength: 1,
|
|
34
|
+
maxLength: 100,
|
|
35
|
+
onChange,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'email',
|
|
39
|
+
mandatory: true,
|
|
40
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
41
|
+
minLength: 1,
|
|
42
|
+
maxLength: 100,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'password',
|
|
46
|
+
mandatory: true,
|
|
47
|
+
type: HashProperty_1.HashProperty.TYPE,
|
|
48
|
+
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
49
|
+
salt: '',
|
|
50
|
+
minLength: 5,
|
|
51
|
+
maxLength: 20, // this is for the clear password
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'entity',
|
|
55
|
+
mandatory: false,
|
|
56
|
+
type: properties_1.ObjectProperty.TYPE,
|
|
57
|
+
instanceof: Entity_1.Entity,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { DataObject } from './DataObject';
|
|
1
|
+
import { DataObject, DataObjectType } from './DataObject';
|
|
2
|
+
import { DataObjectClass } from './types/DataObjectClass';
|
|
2
3
|
import { ObjectUri } from './ObjectUri';
|
|
3
4
|
import { AbstractObject } from './AbstractObject';
|
|
4
5
|
import { BaseObject } from './BaseObject';
|
|
5
6
|
import { BaseObjectProperties } from './BaseObjectProperties';
|
|
6
|
-
import {
|
|
7
|
-
|
|
7
|
+
import { UserProperties } from './UserProperties';
|
|
8
|
+
import { User } from './User';
|
|
9
|
+
import { Entity } from './Entity';
|
|
10
|
+
export { DataObject, DataObjectType, DataObjectClass, ObjectUri, AbstractObject, BaseObject, User, Entity, BaseObjectProperties, UserProperties, };
|
package/lib/components/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserProperties = exports.BaseObjectProperties = exports.User = exports.BaseObject = exports.AbstractObject = exports.ObjectUri = exports.DataObject = void 0;
|
|
3
|
+
exports.UserProperties = exports.BaseObjectProperties = exports.Entity = exports.User = exports.BaseObject = exports.AbstractObject = exports.ObjectUri = exports.DataObject = void 0;
|
|
4
4
|
const DataObject_1 = require("./DataObject");
|
|
5
5
|
Object.defineProperty(exports, "DataObject", { enumerable: true, get: function () { return DataObject_1.DataObject; } });
|
|
6
6
|
const ObjectUri_1 = require("./ObjectUri");
|
|
@@ -11,6 +11,9 @@ const BaseObject_1 = require("./BaseObject");
|
|
|
11
11
|
Object.defineProperty(exports, "BaseObject", { enumerable: true, get: function () { return BaseObject_1.BaseObject; } });
|
|
12
12
|
const BaseObjectProperties_1 = require("./BaseObjectProperties");
|
|
13
13
|
Object.defineProperty(exports, "BaseObjectProperties", { enumerable: true, get: function () { return BaseObjectProperties_1.BaseObjectProperties; } });
|
|
14
|
+
const UserProperties_1 = require("./UserProperties");
|
|
15
|
+
Object.defineProperty(exports, "UserProperties", { enumerable: true, get: function () { return UserProperties_1.UserProperties; } });
|
|
14
16
|
const User_1 = require("./User");
|
|
15
17
|
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
|
|
16
|
-
|
|
18
|
+
const Entity_1 = require("./Entity");
|
|
19
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return Entity_1.Entity; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ObjectUri } from '../ObjectUri';
|
|
2
|
+
export interface DataObjectClass {
|
|
3
|
+
uri: ObjectUri;
|
|
4
|
+
uid: any;
|
|
5
|
+
backend: any;
|
|
6
|
+
path: any;
|
|
7
|
+
class: any;
|
|
8
|
+
properties: any;
|
|
9
|
+
setProperties(properties: any): void;
|
|
10
|
+
populate(data: any): Promise<DataObjectClass>;
|
|
11
|
+
isPopulated(): boolean;
|
|
12
|
+
isPersisted(): boolean;
|
|
13
|
+
get(key: string): any;
|
|
14
|
+
set(key: string, val: any): any;
|
|
15
|
+
val(key: string): any;
|
|
16
|
+
read(): Promise<DataObjectClass>;
|
|
17
|
+
save(): Promise<DataObjectClass>;
|
|
18
|
+
clone(data?: any): Promise<DataObjectClass>;
|
|
19
|
+
toReference(): any;
|
|
20
|
+
toJSON(): any;
|
|
21
|
+
}
|
|
@@ -6,6 +6,7 @@ export interface ArrayPropertyType extends BasePropertyType {
|
|
|
6
6
|
allowStrings?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export declare class ArrayProperty extends BaseProperty {
|
|
9
|
+
static TYPE: string;
|
|
9
10
|
protected _value: Array<any> | undefined;
|
|
10
11
|
protected _minLength: number;
|
|
11
12
|
protected _maxLength: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArrayProperty = void 0;
|
|
4
|
-
const Property_1 = require("./Property");
|
|
5
4
|
const BaseProperty_1 = require("./BaseProperty");
|
|
5
|
+
const StringProperty_1 = require("./StringProperty");
|
|
6
6
|
class ArrayProperty extends BaseProperty_1.BaseProperty {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
super(config);
|
|
@@ -12,10 +12,10 @@ class ArrayProperty extends BaseProperty_1.BaseProperty {
|
|
|
12
12
|
this.minLength = config.minLength || 0;
|
|
13
13
|
this.maxLength = config.maxLength || 0;
|
|
14
14
|
if (this._enable(config.allowNumbers)) {
|
|
15
|
-
this._allows.push(
|
|
15
|
+
this._allows.push(StringProperty_1.StringProperty.ALLOW_NUMBERS);
|
|
16
16
|
}
|
|
17
17
|
if (this._enable(config.allowStrings)) {
|
|
18
|
-
this._allows.push(
|
|
18
|
+
this._allows.push(StringProperty_1.StringProperty.ALLOW_STRINGS);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
set minLength(min) {
|
|
@@ -41,11 +41,11 @@ class ArrayProperty extends BaseProperty_1.BaseProperty {
|
|
|
41
41
|
throw new Error(`Array values are too many`);
|
|
42
42
|
}
|
|
43
43
|
const joined = value.join();
|
|
44
|
-
if (this._allows.includes(
|
|
44
|
+
if (this._allows.includes(StringProperty_1.StringProperty.ALLOW_STRINGS) === false &&
|
|
45
45
|
/[a-zA-Z]/.test(joined)) {
|
|
46
46
|
throw new Error(`Strings are not allowed in value`);
|
|
47
47
|
}
|
|
48
|
-
if (this._allows.includes(
|
|
48
|
+
if (this._allows.includes(StringProperty_1.StringProperty.ALLOW_NUMBERS) === false &&
|
|
49
49
|
/\d/.test(joined)) {
|
|
50
50
|
throw new Error(`Numbers are not allowed in value`);
|
|
51
51
|
}
|
|
@@ -59,3 +59,4 @@ class ArrayProperty extends BaseProperty_1.BaseProperty {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
exports.ArrayProperty = ArrayProperty;
|
|
62
|
+
ArrayProperty.TYPE = 'array';
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
2
2
|
import { AbstractPropertyType } from './types/AbstractPropertyType';
|
|
3
3
|
import { PropertyClassType } from './types/PropertyClassType';
|
|
4
4
|
export declare type EventTypes = typeof BaseProperty.EVENT_ONCHANGE | typeof BaseProperty.EVENT_ONDELETE;
|
|
5
5
|
export interface BasePropertyType extends AbstractPropertyType {
|
|
6
|
-
parent?:
|
|
6
|
+
parent?: DataObjectClass;
|
|
7
7
|
protected?: boolean;
|
|
8
8
|
mandatory?: boolean;
|
|
9
9
|
defaultValue?: any;
|
|
10
|
-
onChange?: (dao:
|
|
10
|
+
onChange?: (dao: DataObjectClass) => DataObjectClass;
|
|
11
11
|
}
|
|
12
12
|
export declare class BaseProperty implements PropertyClassType {
|
|
13
|
+
static TYPE: string;
|
|
13
14
|
static EVENT_ONCHANGE: string;
|
|
14
15
|
static EVENT_ONDELETE: string;
|
|
15
|
-
protected _parent:
|
|
16
|
+
protected _parent: DataObjectClass | undefined;
|
|
16
17
|
protected _name: string;
|
|
17
18
|
protected _value: any;
|
|
18
19
|
protected _mandatory: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BaseProperty, BasePropertyType } from './';
|
|
1
|
+
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
2
2
|
export interface BooleanPropertyType extends BasePropertyType {
|
|
3
3
|
}
|
|
4
4
|
export declare class BooleanProperty extends BaseProperty {
|
|
5
|
+
static TYPE: string;
|
|
5
6
|
set(value: boolean): this;
|
|
6
7
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BooleanProperty = void 0;
|
|
4
|
-
const
|
|
5
|
-
class BooleanProperty extends
|
|
4
|
+
const BaseProperty_1 = require("./BaseProperty");
|
|
5
|
+
class BooleanProperty extends BaseProperty_1.BaseProperty {
|
|
6
6
|
set(value) {
|
|
7
7
|
return super.set(value);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.BooleanProperty = BooleanProperty;
|
|
11
|
+
BooleanProperty.TYPE = 'boolean';
|