@quatrain/core 0.3.0 → 0.4.1
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 +5 -0
- package/lib/Backend.js +7 -0
- package/lib/Core.d.ts +20 -2
- package/lib/Core.js +24 -5
- package/lib/backends/AbstractAdapter.d.ts +27 -13
- package/lib/backends/AbstractAdapter.js +31 -3
- package/lib/backends/Filter.d.ts +5 -3
- package/lib/backends/Filter.js +1 -1
- package/lib/backends/MockAdapter.d.ts +8 -16
- package/lib/backends/MockAdapter.js +67 -41
- package/lib/backends/NotFoundError.d.ts +2 -0
- package/lib/backends/NotFoundError.js +6 -0
- package/lib/backends/Query.d.ts +3 -3
- package/lib/backends/middlewares/AbstractMiddleware.d.ts +0 -0
- package/lib/backends/middlewares/AbstractMiddleware.js +1 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +11 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.js +50 -0
- package/lib/components/AbstractObject.d.ts +9 -6
- package/lib/components/AbstractObject.js +12 -6
- package/lib/components/BaseObject.d.ts +2 -2
- package/lib/components/BaseObject.js +2 -2
- package/lib/components/BaseObjectProperties.d.ts +1 -2
- package/lib/components/BaseObjectProperties.js +2 -0
- package/lib/components/DataObject.d.ts +9 -7
- package/lib/components/DataObject.js +31 -18
- package/lib/components/EntityProperties.js +37 -2
- package/lib/components/ObjectUri.d.ts +1 -1
- package/lib/components/ObjectUri.js +16 -4
- package/lib/components/User.d.ts +1 -0
- package/lib/components/User.js +102 -3
- package/lib/components/UserProperties.js +45 -1
- package/lib/components/index.d.ts +2 -2
- package/lib/components/types/AbstractObjectClass.d.ts +2 -2
- package/lib/components/types/BaseObjectClass.d.ts +2 -2
- package/lib/components/types/DataObjectClass.d.ts +7 -5
- package/lib/index.d.ts +5 -1
- package/lib/index.js +7 -1
- package/lib/properties/BaseProperty.d.ts +8 -3
- package/lib/properties/BaseProperty.js +10 -1
- package/lib/properties/CollectionProperty.d.ts +11 -8
- package/lib/properties/CollectionProperty.js +10 -9
- package/lib/properties/EnumProperty.d.ts +1 -0
- package/lib/properties/EnumProperty.js +4 -1
- package/lib/properties/Property.d.ts +1 -1
- package/lib/properties/StringProperty.d.ts +4 -0
- package/lib/properties/StringProperty.js +32 -17
- package/lib/properties/types/PropertyClassType.d.ts +1 -1
- package/lib/properties/types/PropertyHTMLType.d.ts +10 -0
- package/lib/properties/types/PropertyHTMLType.js +14 -0
- package/lib/utils/DataGenerator.d.ts +9 -0
- package/lib/utils/DataGenerator.js +98 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +5 -0
- package/package.json +2 -2
|
@@ -8,8 +8,8 @@ export declare class BaseObject extends AbstractObject implements BaseObjectClas
|
|
|
8
8
|
static getProperty(key: string): any;
|
|
9
9
|
get status(): string;
|
|
10
10
|
set status(status: string);
|
|
11
|
-
static daoFactory(src?: string | ObjectUri | DataObjectClass | undefined, child?: any): Promise<DataObjectClass
|
|
12
|
-
static factory<T extends BaseObject>(src?: string | ObjectUri | DataObjectClass | undefined, child?: any): Promise<T | BaseObject>;
|
|
11
|
+
static daoFactory(src?: string | ObjectUri | DataObjectClass<any> | undefined, child?: any): Promise<DataObjectClass<any>>;
|
|
12
|
+
static factory<T extends BaseObject>(src?: string | ObjectUri | DataObjectClass<any> | undefined, child?: any): Promise<T | BaseObject>;
|
|
13
13
|
asReference(): any;
|
|
14
14
|
query(): Query<any>;
|
|
15
15
|
}
|
|
@@ -11,10 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.BaseObject = void 0;
|
|
13
13
|
const ObjectUri_1 = require("./ObjectUri");
|
|
14
|
-
const DataObject_1 = require("./DataObject");
|
|
15
14
|
const AbstractObject_1 = require("./AbstractObject");
|
|
16
15
|
const BaseObjectProperties_1 = require("./BaseObjectProperties");
|
|
17
16
|
const Query_1 = require("../backends/Query");
|
|
17
|
+
const DataObject_1 = require("./DataObject");
|
|
18
18
|
class BaseObject extends AbstractObject_1.AbstractObject {
|
|
19
19
|
static getProperty(key) {
|
|
20
20
|
return BaseObject.PROPS_DEFINITION.find((prop) => prop.name === key);
|
|
@@ -62,7 +62,7 @@ class BaseObject extends AbstractObject_1.AbstractObject {
|
|
|
62
62
|
static factory(src = undefined, child = this) {
|
|
63
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
try {
|
|
65
|
-
const dao = yield this.daoFactory(src);
|
|
65
|
+
const dao = yield this.daoFactory(src, child);
|
|
66
66
|
return Reflect.construct(this, [dao]);
|
|
67
67
|
}
|
|
68
68
|
catch (err) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as statuses from '../statuses';
|
|
2
1
|
import { UserClass } from './types/UserClass';
|
|
3
2
|
import { ObjectUri } from './ObjectUri';
|
|
4
3
|
export interface BaseObjectType {
|
|
5
4
|
name: string;
|
|
6
|
-
status:
|
|
5
|
+
status: string;
|
|
7
6
|
createdBy?: UserClass | ObjectUri;
|
|
8
7
|
createdAt?: number;
|
|
9
8
|
updatedBy?: UserClass | ObjectUri;
|
|
@@ -29,6 +29,7 @@ const StringProperty_1 = require("../properties/StringProperty");
|
|
|
29
29
|
const ObjectProperty_1 = require("../properties/ObjectProperty");
|
|
30
30
|
const EnumProperty_1 = require("../properties/EnumProperty");
|
|
31
31
|
const DateTimeProperty_1 = require("../properties/DateTimeProperty");
|
|
32
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
32
33
|
exports.BaseObjectProperties = [
|
|
33
34
|
{
|
|
34
35
|
name: 'name',
|
|
@@ -36,6 +37,7 @@ exports.BaseObjectProperties = [
|
|
|
36
37
|
type: StringProperty_1.StringProperty.TYPE,
|
|
37
38
|
minLength: 1,
|
|
38
39
|
maxLength: 100,
|
|
40
|
+
htmlType: htmlType.NAME,
|
|
39
41
|
},
|
|
40
42
|
{
|
|
41
43
|
name: 'status',
|
|
@@ -11,7 +11,7 @@ export interface DataObjectFactoryType {
|
|
|
11
11
|
path: string;
|
|
12
12
|
[x: string]: any;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface DataObjectParams {
|
|
15
15
|
uri?: string | ObjectUri;
|
|
16
16
|
properties: DataObjectProperties;
|
|
17
17
|
}
|
|
@@ -20,7 +20,7 @@ export interface DataObjectType {
|
|
|
20
20
|
* They handle data and identifiers in a protected registry
|
|
21
21
|
* This is what backends and objects manipulate, oblivious of the other.
|
|
22
22
|
*/
|
|
23
|
-
export declare class DataObject implements DataObjectClass {
|
|
23
|
+
export declare class DataObject implements DataObjectClass<any> {
|
|
24
24
|
protected _objectUri: ObjectUri;
|
|
25
25
|
protected _uid: string | undefined;
|
|
26
26
|
protected _properties: Properties;
|
|
@@ -34,7 +34,7 @@ export declare class DataObject implements DataObjectClass {
|
|
|
34
34
|
* Constructor is protected, use factory() instead
|
|
35
35
|
* @param params object of parameters
|
|
36
36
|
*/
|
|
37
|
-
protected constructor(params:
|
|
37
|
+
protected constructor(params: DataObjectParams | undefined);
|
|
38
38
|
protected _init(properties: any[]): void;
|
|
39
39
|
setProperties(properties: Properties): void;
|
|
40
40
|
/**
|
|
@@ -53,6 +53,7 @@ export declare class DataObject implements DataObjectClass {
|
|
|
53
53
|
set uri(uri: string | ObjectUri | undefined);
|
|
54
54
|
get uri(): ObjectUri;
|
|
55
55
|
get class(): any;
|
|
56
|
+
has(key: string): boolean;
|
|
56
57
|
/**
|
|
57
58
|
* Returns property matching key or throw
|
|
58
59
|
* @param key string
|
|
@@ -75,14 +76,15 @@ export declare class DataObject implements DataObjectClass {
|
|
|
75
76
|
uri: string;
|
|
76
77
|
};
|
|
77
78
|
protected _dataToJSON(): {};
|
|
78
|
-
read(): Promise<
|
|
79
|
-
save(
|
|
79
|
+
read(): Promise<DataObjectClass<any>>;
|
|
80
|
+
save(): Promise<DataObjectClass<any>>;
|
|
81
|
+
delete(): Promise<DataObjectClass<any>>;
|
|
80
82
|
/**
|
|
81
83
|
* Data object must be created from factory in order for async-loaded data to be available
|
|
82
84
|
* @param className
|
|
83
85
|
* @param param
|
|
84
86
|
* @returns DataObject
|
|
85
87
|
*/
|
|
86
|
-
static factory(param?:
|
|
87
|
-
clone(data?: any): Promise<
|
|
88
|
+
static factory(param?: DataObjectParams | undefined): Promise<DataObject>;
|
|
89
|
+
clone(data?: any): Promise<DataObject>;
|
|
88
90
|
}
|
|
@@ -33,9 +33,6 @@ class DataObject {
|
|
|
33
33
|
*/
|
|
34
34
|
this._modified = false;
|
|
35
35
|
if (params) {
|
|
36
|
-
if (Array.isArray(params.properties)) {
|
|
37
|
-
this._init(params.properties);
|
|
38
|
-
}
|
|
39
36
|
if (typeof params.uri !== 'object') {
|
|
40
37
|
this._objectUri = new ObjectUri_1.ObjectUri(params.uri);
|
|
41
38
|
}
|
|
@@ -46,6 +43,9 @@ class DataObject {
|
|
|
46
43
|
else {
|
|
47
44
|
this._objectUri = new ObjectUri_1.ObjectUri();
|
|
48
45
|
}
|
|
46
|
+
if (params && Array.isArray(params.properties)) {
|
|
47
|
+
this._init(params.properties);
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
50
|
_init(properties) {
|
|
51
51
|
properties.forEach((prop) => {
|
|
@@ -110,6 +110,9 @@ class DataObject {
|
|
|
110
110
|
}
|
|
111
111
|
set uri(uri) {
|
|
112
112
|
this._objectUri = uri instanceof ObjectUri_1.ObjectUri ? uri : new ObjectUri_1.ObjectUri(uri);
|
|
113
|
+
if (this._objectUri.collection !== ObjectUri_1.ObjectUri.MISSING_COLLECTION) {
|
|
114
|
+
this._persisted = true;
|
|
115
|
+
}
|
|
113
116
|
}
|
|
114
117
|
get uri() {
|
|
115
118
|
return this._objectUri;
|
|
@@ -118,6 +121,9 @@ class DataObject {
|
|
|
118
121
|
// TODO get class type
|
|
119
122
|
return this.uri.class;
|
|
120
123
|
}
|
|
124
|
+
has(key) {
|
|
125
|
+
return Reflect.has(this._properties, key);
|
|
126
|
+
}
|
|
121
127
|
/**
|
|
122
128
|
* Returns property matching key or throw
|
|
123
129
|
* @param key string
|
|
@@ -132,7 +138,7 @@ class DataObject {
|
|
|
132
138
|
}
|
|
133
139
|
}
|
|
134
140
|
set(key, val) {
|
|
135
|
-
if (!
|
|
141
|
+
if (!this.has(key)) {
|
|
136
142
|
throw new Error(`Unknown property in data object: ${key}`);
|
|
137
143
|
}
|
|
138
144
|
this._properties[key].set(val);
|
|
@@ -146,7 +152,7 @@ class DataObject {
|
|
|
146
152
|
* @returns any
|
|
147
153
|
*/
|
|
148
154
|
val(key) {
|
|
149
|
-
if (
|
|
155
|
+
if (this.has(key)) {
|
|
150
156
|
return Reflect.get(this._properties, key).val();
|
|
151
157
|
}
|
|
152
158
|
else {
|
|
@@ -157,19 +163,19 @@ class DataObject {
|
|
|
157
163
|
return Object.assign(Object.assign({}, (this._uid && { uid: this._uid })), this._dataToJSON());
|
|
158
164
|
}
|
|
159
165
|
toReference() {
|
|
160
|
-
|
|
161
|
-
return Object.assign(Object.assign({}, (_a = this._objectUri) === null || _a === void 0 ? void 0 : _a.toReference()), { label: this.val('name') });
|
|
166
|
+
return Object.assign(Object.assign({}, this._objectUri.toReference()), { label: this.val('name') || '' });
|
|
162
167
|
}
|
|
163
168
|
_dataToJSON() {
|
|
164
169
|
const data = {};
|
|
165
170
|
Object.keys(this._properties).forEach((key) => {
|
|
166
171
|
const prop = Reflect.get(this._properties, key);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
const value = prop.val();
|
|
173
|
+
switch (prop.constructor.name) {
|
|
174
|
+
case 'ObjectProperty':
|
|
175
|
+
Reflect.set(data, key, value ? value.toJSON() : null);
|
|
176
|
+
break;
|
|
177
|
+
default:
|
|
178
|
+
Reflect.set(data, key, value || null);
|
|
173
179
|
}
|
|
174
180
|
});
|
|
175
181
|
return data;
|
|
@@ -177,7 +183,7 @@ class DataObject {
|
|
|
177
183
|
read() {
|
|
178
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
185
|
try {
|
|
180
|
-
return this.populate(Core_1.Core.getBackend().read(this));
|
|
186
|
+
return this.populate(yield Core_1.Core.getBackend().read(this));
|
|
181
187
|
}
|
|
182
188
|
catch (err) {
|
|
183
189
|
console.log(err.message);
|
|
@@ -185,14 +191,20 @@ class DataObject {
|
|
|
185
191
|
}
|
|
186
192
|
});
|
|
187
193
|
}
|
|
188
|
-
save(
|
|
194
|
+
save() {
|
|
189
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
196
|
const backend = Core_1.Core.getBackend(this.backend || Core_1.Core.defaultBackend);
|
|
191
197
|
this._persisted = true;
|
|
192
198
|
this._modified = false;
|
|
193
|
-
return this.
|
|
194
|
-
|
|
195
|
-
|
|
199
|
+
return this.uid ? backend.update(this) : backend.create(this);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
delete() {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const backend = Core_1.Core.getBackend(this.backend || Core_1.Core.defaultBackend);
|
|
205
|
+
this._persisted = false;
|
|
206
|
+
this._modified = false;
|
|
207
|
+
return yield backend.delete(this);
|
|
196
208
|
});
|
|
197
209
|
}
|
|
198
210
|
/**
|
|
@@ -215,6 +227,7 @@ class DataObject {
|
|
|
215
227
|
clone(data = {}) {
|
|
216
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
229
|
const cloned = yield DataObject.factory();
|
|
230
|
+
cloned.uri.class = this.uri.class;
|
|
218
231
|
cloned.setProperties(this._properties);
|
|
219
232
|
if (data) {
|
|
220
233
|
yield cloned.populate(data);
|
|
@@ -1,12 +1,47 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.EntityProperties = void 0;
|
|
27
|
+
const properties_1 = require("../properties");
|
|
4
28
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
30
|
+
const User_1 = require("./User");
|
|
5
31
|
exports.EntityProperties = [
|
|
6
32
|
{
|
|
7
|
-
//
|
|
33
|
+
// surcharge property minLength and htmlType
|
|
8
34
|
name: 'name',
|
|
9
35
|
type: StringProperty_1.StringProperty.TYPE,
|
|
10
|
-
|
|
36
|
+
mandatory: true,
|
|
37
|
+
minLength: 1,
|
|
38
|
+
htmlType: htmlType.ORG,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'users',
|
|
42
|
+
mandatory: true,
|
|
43
|
+
type: properties_1.CollectionProperty.TYPE,
|
|
44
|
+
instanceOf: User_1.User,
|
|
45
|
+
parentKey: 'entity',
|
|
11
46
|
},
|
|
12
47
|
];
|
|
@@ -9,15 +9,16 @@ class ObjectUri {
|
|
|
9
9
|
* some backends will need a collection or table name, some may deduct it from object
|
|
10
10
|
* @param str
|
|
11
11
|
*/
|
|
12
|
-
constructor(str = '', label =
|
|
12
|
+
constructor(str = '', label = '') {
|
|
13
13
|
this._pairs = [];
|
|
14
14
|
this._literal = '';
|
|
15
15
|
this._backend = Core_1.Core.defaultBackend;
|
|
16
16
|
this._path = ObjectUri.DEFAULT;
|
|
17
17
|
this._uid = undefined;
|
|
18
18
|
this._collection = undefined;
|
|
19
|
+
this._label = '';
|
|
19
20
|
this._str = str;
|
|
20
|
-
this._label = label
|
|
21
|
+
this._label = label;
|
|
21
22
|
if (str.indexOf(':') !== -1) {
|
|
22
23
|
const [backend, path] = str.split(':');
|
|
23
24
|
this._backend = backend || Core_1.Core.defaultBackend;
|
|
@@ -33,6 +34,7 @@ class ObjectUri {
|
|
|
33
34
|
this._uid = parts[0].length > 0 ? parts[0] : undefined;
|
|
34
35
|
this._collection = ObjectUri.MISSING_COLLECTION;
|
|
35
36
|
this._pairs.push(`${ObjectUri.MISSING_COLLECTION}${ObjectUri.DEFAULT}${this._uid}`);
|
|
37
|
+
this._label = label || this._uid;
|
|
36
38
|
}
|
|
37
39
|
else if (parts.length % 2 === 0) {
|
|
38
40
|
// General case is a path containing pairs of collection/uid
|
|
@@ -43,13 +45,21 @@ class ObjectUri {
|
|
|
43
45
|
this._pairs.push(`${parts[i]}${ObjectUri.DEFAULT}${parts[i + 1]}`);
|
|
44
46
|
i += 2;
|
|
45
47
|
}
|
|
48
|
+
this._label = label || this._uid;
|
|
46
49
|
}
|
|
47
50
|
else {
|
|
48
51
|
throw new Error('Path parts number must be 1 or even');
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
set class(objClass) {
|
|
55
|
+
var _a;
|
|
52
56
|
this._objClass = objClass;
|
|
57
|
+
if (objClass) {
|
|
58
|
+
this._collection = objClass.COLLECTION || ((_a = objClass.name) === null || _a === void 0 ? void 0 : _a.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this._collection = undefined;
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
get class() {
|
|
55
65
|
return this._objClass;
|
|
@@ -74,8 +84,10 @@ class ObjectUri {
|
|
|
74
84
|
throw new Error(`Path value already set with '${this._path}'`);
|
|
75
85
|
}
|
|
76
86
|
this._path = path;
|
|
77
|
-
|
|
87
|
+
// TODO manage paths to subcollection
|
|
88
|
+
this._collection = path.split('/')[0];
|
|
78
89
|
this._literal = `${this._backend}:${this._path}`;
|
|
90
|
+
this._uid = path.split('/').pop();
|
|
79
91
|
}
|
|
80
92
|
get uid() {
|
|
81
93
|
return this._uid;
|
|
@@ -106,7 +118,7 @@ class ObjectUri {
|
|
|
106
118
|
return {
|
|
107
119
|
backend: this._backend,
|
|
108
120
|
ref: this._path,
|
|
109
|
-
label: this._label,
|
|
121
|
+
label: this._label || '',
|
|
110
122
|
};
|
|
111
123
|
}
|
|
112
124
|
}
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseObject } from './BaseObject';
|
|
2
2
|
import { UserClass } from './types/UserClass';
|
|
3
|
+
export declare const UserProperties: any;
|
|
3
4
|
export declare class User extends BaseObject implements UserClass {
|
|
4
5
|
static PROPS_DEFINITION: any;
|
|
5
6
|
static factory(src?: any): Promise<User>;
|
package/lib/components/User.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,9 +32,85 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
32
|
});
|
|
10
33
|
};
|
|
11
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.User = void 0;
|
|
35
|
+
exports.User = exports.UserProperties = void 0;
|
|
13
36
|
const BaseObject_1 = require("./BaseObject");
|
|
14
|
-
const
|
|
37
|
+
const properties_1 = require("../properties");
|
|
38
|
+
const HashProperty_1 = require("../properties/HashProperty");
|
|
39
|
+
const StringProperty_1 = require("../properties/StringProperty");
|
|
40
|
+
const Entity_1 = require("./Entity");
|
|
41
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
42
|
+
/**
|
|
43
|
+
* Callback function to populate the 'name' property
|
|
44
|
+
* @param dao DataObject
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
const onChange = (dao) => dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`);
|
|
48
|
+
exports.UserProperties = [
|
|
49
|
+
{
|
|
50
|
+
// change name property minLength
|
|
51
|
+
name: 'name',
|
|
52
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
53
|
+
minLength: 0,
|
|
54
|
+
fullSearch: true,
|
|
55
|
+
htmlType: htmlType.NAME,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'firstname',
|
|
59
|
+
mandatory: true,
|
|
60
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
61
|
+
minLength: 1,
|
|
62
|
+
maxLength: 100,
|
|
63
|
+
htmlType: htmlType.GIVEN_NAME,
|
|
64
|
+
onChange,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'lastname',
|
|
68
|
+
mandatory: true,
|
|
69
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
70
|
+
minLength: 1,
|
|
71
|
+
maxLength: 100,
|
|
72
|
+
htmlType: htmlType.FAMILY_NAME,
|
|
73
|
+
onChange,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'gender',
|
|
77
|
+
mandatory: false,
|
|
78
|
+
type: properties_1.EnumProperty.TYPE,
|
|
79
|
+
values: ['male', 'female', 'nonbinary'],
|
|
80
|
+
htmlType: htmlType.GENDER,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'birthday',
|
|
84
|
+
mandatory: false,
|
|
85
|
+
type: properties_1.DateTimeProperty.TYPE,
|
|
86
|
+
htmlType: htmlType.BIRTHDAY,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'email',
|
|
90
|
+
mandatory: true,
|
|
91
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
92
|
+
minLength: 1,
|
|
93
|
+
maxLength: 100,
|
|
94
|
+
fullSearch: true,
|
|
95
|
+
htmlType: htmlType.EMAIL,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'password',
|
|
99
|
+
mandatory: true,
|
|
100
|
+
type: HashProperty_1.HashProperty.TYPE,
|
|
101
|
+
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
102
|
+
salt: '',
|
|
103
|
+
minLength: 5,
|
|
104
|
+
maxLength: 20,
|
|
105
|
+
htmlType: htmlType.PASSWORD,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'entity',
|
|
109
|
+
mandatory: false,
|
|
110
|
+
type: properties_1.ObjectProperty.TYPE,
|
|
111
|
+
instanceof: Entity_1.Entity,
|
|
112
|
+
},
|
|
113
|
+
];
|
|
15
114
|
class User extends BaseObject_1.BaseObject {
|
|
16
115
|
static factory(src = undefined) {
|
|
17
116
|
const _super = Object.create(null, {
|
|
@@ -23,4 +122,4 @@ class User extends BaseObject_1.BaseObject {
|
|
|
23
122
|
}
|
|
24
123
|
}
|
|
25
124
|
exports.User = User;
|
|
26
|
-
User.PROPS_DEFINITION =
|
|
125
|
+
User.PROPS_DEFINITION = exports.UserProperties;
|
|
@@ -1,10 +1,34 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.UserProperties = void 0;
|
|
4
27
|
const properties_1 = require("../properties");
|
|
5
28
|
const HashProperty_1 = require("../properties/HashProperty");
|
|
6
29
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
7
30
|
const Entity_1 = require("./Entity");
|
|
31
|
+
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
8
32
|
/**
|
|
9
33
|
* Callback function to populate the 'name' property
|
|
10
34
|
* @param dao DataObject
|
|
@@ -17,6 +41,8 @@ exports.UserProperties = [
|
|
|
17
41
|
name: 'name',
|
|
18
42
|
type: StringProperty_1.StringProperty.TYPE,
|
|
19
43
|
minLength: 0,
|
|
44
|
+
fullSearch: true,
|
|
45
|
+
htmlType: htmlType.NAME,
|
|
20
46
|
},
|
|
21
47
|
{
|
|
22
48
|
name: 'firstname',
|
|
@@ -24,6 +50,7 @@ exports.UserProperties = [
|
|
|
24
50
|
type: StringProperty_1.StringProperty.TYPE,
|
|
25
51
|
minLength: 1,
|
|
26
52
|
maxLength: 100,
|
|
53
|
+
htmlType: htmlType.GIVEN_NAME,
|
|
27
54
|
onChange,
|
|
28
55
|
},
|
|
29
56
|
{
|
|
@@ -32,14 +59,30 @@ exports.UserProperties = [
|
|
|
32
59
|
type: StringProperty_1.StringProperty.TYPE,
|
|
33
60
|
minLength: 1,
|
|
34
61
|
maxLength: 100,
|
|
62
|
+
htmlType: htmlType.FAMILY_NAME,
|
|
35
63
|
onChange,
|
|
36
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
|
+
},
|
|
37
78
|
{
|
|
38
79
|
name: 'email',
|
|
39
80
|
mandatory: true,
|
|
40
81
|
type: StringProperty_1.StringProperty.TYPE,
|
|
41
82
|
minLength: 1,
|
|
42
83
|
maxLength: 100,
|
|
84
|
+
fullSearch: true,
|
|
85
|
+
htmlType: htmlType.EMAIL,
|
|
43
86
|
},
|
|
44
87
|
{
|
|
45
88
|
name: 'password',
|
|
@@ -48,7 +91,8 @@ exports.UserProperties = [
|
|
|
48
91
|
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
49
92
|
salt: '',
|
|
50
93
|
minLength: 5,
|
|
51
|
-
maxLength: 20,
|
|
94
|
+
maxLength: 20,
|
|
95
|
+
htmlType: htmlType.PASSWORD,
|
|
52
96
|
},
|
|
53
97
|
{
|
|
54
98
|
name: 'entity',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataObject,
|
|
1
|
+
import { DataObject, DataObjectParams } from './DataObject';
|
|
2
2
|
import { DataObjectClass } from './types/DataObjectClass';
|
|
3
3
|
import { ObjectUri } from './ObjectUri';
|
|
4
4
|
import { AbstractObject } from './AbstractObject';
|
|
@@ -7,4 +7,4 @@ import { BaseObjectProperties } from './BaseObjectProperties';
|
|
|
7
7
|
import { UserProperties } from './UserProperties';
|
|
8
8
|
import { User } from './User';
|
|
9
9
|
import { Entity } from './Entity';
|
|
10
|
-
export { DataObject,
|
|
10
|
+
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObject, User, Entity, BaseObjectProperties, UserProperties, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectUri } from '../ObjectUri';
|
|
2
|
-
export interface DataObjectClass {
|
|
2
|
+
export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
3
3
|
uri: ObjectUri;
|
|
4
4
|
uid: any;
|
|
5
5
|
backend: any;
|
|
@@ -7,15 +7,17 @@ export interface DataObjectClass {
|
|
|
7
7
|
class: any;
|
|
8
8
|
properties: any;
|
|
9
9
|
setProperties(properties: any): void;
|
|
10
|
-
populate(data
|
|
10
|
+
populate(data?: any): Promise<T>;
|
|
11
11
|
isPopulated(): boolean;
|
|
12
12
|
isPersisted(): boolean;
|
|
13
|
+
has(key: string): boolean;
|
|
13
14
|
get(key: string): any;
|
|
14
15
|
set(key: string, val: any): any;
|
|
15
16
|
val(key: string): any;
|
|
16
|
-
read(): Promise<
|
|
17
|
-
save(): Promise<
|
|
18
|
-
|
|
17
|
+
read(): Promise<T>;
|
|
18
|
+
save(): Promise<T>;
|
|
19
|
+
delete(): Promise<T>;
|
|
20
|
+
clone(data?: any): Promise<T>;
|
|
19
21
|
toReference(): any;
|
|
20
22
|
toJSON(): any;
|
|
21
23
|
}
|