@quatrain/core 1.0.0-beta2 → 1.0.0-beta21
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/Auth.d.ts +25 -0
- package/lib/Auth.js +9 -0
- package/lib/Backend.d.ts +7 -2
- package/lib/Backend.js +1 -0
- package/lib/Core.d.ts +14 -2
- package/lib/Core.js +40 -1
- package/lib/authentication/AbstractAuthAdapter.d.ts +18 -0
- package/lib/authentication/AbstractAuthAdapter.js +23 -0
- package/lib/authentication/AuthenticationError.d.ts +2 -0
- package/lib/authentication/AuthenticationError.js +6 -0
- package/lib/authentication/index.d.ts +4 -0
- package/lib/authentication/index.js +7 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.d.ts +0 -0
- package/lib/authentication/middlewares/AbstractAuthMiddleware.js +1 -0
- package/lib/authentication/middlewares/AuthMiddleware.d.ts +5 -0
- package/lib/authentication/types/AuthInterface.d.ts +9 -0
- package/lib/backends/AbstractAdapter.d.ts +16 -5
- package/lib/backends/AbstractAdapter.js +27 -4
- package/lib/backends/Filters.d.ts +2 -1
- package/lib/backends/Query.d.ts +9 -5
- package/lib/backends/Query.js +13 -4
- package/lib/backends/index.d.ts +2 -1
- package/lib/backends/index.js +26 -1
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +2 -2
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +7 -6
- package/lib/backends/middlewares/InjectMetaMiddleware.js +7 -4
- package/lib/backends/middlewares/Middleware.d.ts +2 -2
- package/lib/backends/middlewares/types/MiddlewareParams.d.ts +3 -0
- package/lib/backends/middlewares/types/MiddlewareParams.js +2 -0
- package/lib/backends/types/BackendInterface.d.ts +1 -1
- package/lib/backends/types/CollectionHierarchy.d.ts +3 -0
- package/lib/backends/types/CollectionHierarchy.js +6 -0
- package/lib/components/AbstractObject.d.ts +3 -1
- package/lib/components/AbstractObject.js +1 -0
- package/lib/components/BaseObject.js +1 -0
- package/lib/components/BaseObjectCore.d.ts +10 -1
- package/lib/components/BaseObjectCore.js +15 -3
- package/lib/components/BaseRepository.d.ts +1 -0
- package/lib/components/BaseRepository.js +21 -3
- package/lib/components/DataObject.d.ts +12 -2
- package/lib/components/DataObject.js +44 -7
- package/lib/components/Entity.d.ts +3 -6
- package/lib/components/Entity.js +31 -31
- package/lib/components/EntityRepository.d.ts +2 -2
- package/lib/components/EntityRepository.js +1 -1
- package/lib/components/ObjectUri.d.ts +20 -1
- package/lib/components/ObjectUri.js +44 -14
- package/lib/components/User.d.ts +3 -3
- package/lib/components/User.js +16 -9
- package/lib/components/UserRepository.d.ts +3 -3
- package/lib/components/UserRepository.js +2 -2
- package/lib/components/index.d.ts +2 -2
- package/lib/components/index.js +4 -2
- package/lib/components/types/DataObjectClass.d.ts +4 -1
- package/lib/components/types/toJSONParams.d.ts +8 -0
- package/lib/components/types/toJSONParams.js +2 -0
- package/lib/index.d.ts +14 -3
- package/lib/index.js +14 -1
- package/lib/properties/ArrayProperty.d.ts +1 -1
- package/lib/properties/ArrayProperty.js +2 -2
- package/lib/properties/BaseProperty.d.ts +4 -1
- package/lib/properties/BaseProperty.js +15 -3
- package/lib/properties/BooleanProperty.d.ts +1 -1
- package/lib/properties/BooleanProperty.js +2 -2
- package/lib/properties/CollectionProperty.d.ts +1 -1
- package/lib/properties/CollectionProperty.js +4 -3
- package/lib/properties/DateTimeProperty.d.ts +1 -1
- package/lib/properties/DateTimeProperty.js +2 -2
- package/lib/properties/EnumProperty.d.ts +1 -1
- package/lib/properties/EnumProperty.js +2 -2
- package/lib/properties/HashProperty.d.ts +1 -1
- package/lib/properties/HashProperty.js +2 -2
- package/lib/properties/MapProperty.d.ts +1 -1
- package/lib/properties/MapProperty.js +2 -2
- package/lib/properties/NumberProperty.d.ts +1 -1
- package/lib/properties/NumberProperty.js +2 -2
- package/lib/properties/ObjectProperty.d.ts +1 -1
- package/lib/properties/ObjectProperty.js +5 -6
- package/lib/properties/StringProperty.d.ts +1 -1
- package/lib/properties/StringProperty.js +2 -2
- package/lib/properties/types/AbstractPropertyType.d.ts +1 -0
- package/lib/properties/types/PropertyClassType.d.ts +3 -1
- package/lib/storages/AbstractStorageAdapter.d.ts +17 -0
- package/lib/storages/AbstractStorageAdapter.js +7 -0
- package/lib/storages/StorageAdapterInterface.d.ts +19 -0
- package/lib/storages/StorageAdapterInterface.js +2 -0
- package/lib/storages/index.d.ts +8 -0
- package/lib/storages/index.js +5 -0
- package/lib/storages/types/BlobMediaType.d.ts +8 -0
- package/lib/storages/types/BlobMediaType.js +2 -0
- package/lib/storages/types/BlobType.d.ts +6 -0
- package/lib/storages/types/BlobType.js +2 -0
- package/lib/storages/types/FileResponseLink.d.ts +7 -0
- package/lib/storages/types/FileResponseLink.js +2 -0
- package/lib/storages/types/FileResponseUrl.d.ts +4 -0
- package/lib/storages/types/FileResponseUrl.js +2 -0
- package/lib/storages/types/FileType.d.ts +15 -0
- package/lib/storages/types/FileType.js +2 -0
- package/lib/storages/types.d.ts +5 -0
- package/lib/storages/types.js +2 -0
- package/lib/utils/DataGenerator.d.ts +2 -3
- package/lib/utils/DataGenerator.js +2 -1
- package/lib/wrappers/cloud/AbstractCloudWrapper.d.ts +4 -0
- package/lib/wrappers/cloud/AbstractCloudWrapper.js +9 -0
- package/lib/wrappers/cloud/types/DatabaseTriggerType.d.ts +8 -0
- package/lib/wrappers/cloud/types/DatabaseTriggerType.js +2 -0
- package/package.json +5 -3
- package/README.md +0 -124
- package/lib/backends/BackendInterface.d.ts +0 -13
- package/lib/backends/middlewares/InjectMetaMiddleware copy.d.ts +0 -12
- package/lib/backends/middlewares/InjectMetaMiddleware copy.js +0 -30
- package/lib/components/BaseObjectProperties.d.ts +0 -13
- package/lib/components/BaseObjectProperties.js +0 -87
- package/lib/components/EntityProperties.d.ts +0 -1
- package/lib/components/EntityProperties.js +0 -54
- package/lib/components/UserProperties.d.ts +0 -1
- package/lib/components/UserProperties.js +0 -103
- package/lib/components/types/UserClass.d.ts +0 -3
- /package/lib/{backends/BackendInterface.js → authentication/middlewares/AuthMiddleware.js} +0 -0
- /package/lib/{components/types/UserClass.js → authentication/types/AuthInterface.js} +0 -0
|
@@ -70,5 +70,6 @@ class AbstractObject {
|
|
|
70
70
|
}
|
|
71
71
|
exports.AbstractObject = AbstractObject;
|
|
72
72
|
AbstractObject.PROPS_DEFINITION = [];
|
|
73
|
+
AbstractObject.DEFAULT_BACKEND = 'default';
|
|
73
74
|
// Which property's value to use in backend as label for object reference
|
|
74
75
|
AbstractObject.LABEL_KEY = 'name';
|
|
@@ -59,6 +59,15 @@ export declare class BaseObjectCore extends AbstractObject implements BaseObject
|
|
|
59
59
|
*/
|
|
60
60
|
protected toProxy<T extends BaseObject>(): Proxy<Proxy<T>>;
|
|
61
61
|
asReference(): any;
|
|
62
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Create a query based on given class where parent is current instance
|
|
64
|
+
* @param obj
|
|
65
|
+
* @returns Query
|
|
66
|
+
*/
|
|
67
|
+
query(obj: any): Query<any>;
|
|
68
|
+
/**
|
|
69
|
+
* Create a query based on current class
|
|
70
|
+
* @returns Query
|
|
71
|
+
*/
|
|
63
72
|
static query(): Query<typeof BaseObjectCore>;
|
|
64
73
|
}
|
|
@@ -33,7 +33,10 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
33
33
|
base.push(property);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
const dao = DataObject_1.DataObject.factory({
|
|
36
|
+
const dao = DataObject_1.DataObject.factory({
|
|
37
|
+
properties: base,
|
|
38
|
+
parentProp: this.PARENT_PROP,
|
|
39
|
+
});
|
|
37
40
|
dao.uri.class = child;
|
|
38
41
|
return dao;
|
|
39
42
|
}
|
|
@@ -146,9 +149,18 @@ class BaseObjectCore extends AbstractObject_1.AbstractObject {
|
|
|
146
149
|
asReference() {
|
|
147
150
|
return this._dataObject.toReference();
|
|
148
151
|
}
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Create a query based on given class where parent is current instance
|
|
154
|
+
* @param obj
|
|
155
|
+
* @returns Query
|
|
156
|
+
*/
|
|
157
|
+
query(obj) {
|
|
158
|
+
return new Query_1.Query(obj, this);
|
|
151
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a query based on current class
|
|
162
|
+
* @returns Query
|
|
163
|
+
*/
|
|
152
164
|
static query() {
|
|
153
165
|
return new Query_1.Query(this);
|
|
154
166
|
}
|
|
@@ -12,6 +12,7 @@ export default class BaseRepository<T extends BaseObject> {
|
|
|
12
12
|
backendAdapter: BackendInterface;
|
|
13
13
|
constructor(model: typeof BaseObjectCore, backendAdapter?: BackendInterface);
|
|
14
14
|
protected getDataObjectFromUid(uid: string): Promise<DataObjectClass<any>>;
|
|
15
|
+
protected getDataObjectFromPath(path: string): Promise<DataObjectClass<any>>;
|
|
15
16
|
create<B extends BaseObjectCore>(obj: B, uid?: string): Promise<any>;
|
|
16
17
|
read(key: string): Promise<any>;
|
|
17
18
|
update(obj: BaseObjectCore): Promise<any>;
|
|
@@ -58,17 +58,35 @@ class BaseRepository {
|
|
|
58
58
|
return dataObject;
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
+
getDataObjectFromPath(path) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const dataObject = DataObject_1.DataObject.factory({
|
|
64
|
+
properties: this._model.PROPS_DEFINITION,
|
|
65
|
+
uri: path,
|
|
66
|
+
});
|
|
67
|
+
dataObject.uid = path.substring(path.lastIndexOf('/') + 1);
|
|
68
|
+
return dataObject;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
61
71
|
create(obj, uid) {
|
|
62
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
73
|
const savedObj = yield this.backendAdapter.create(obj.dataObject, uid);
|
|
64
|
-
return this._model.fromDataObject(savedObj);
|
|
74
|
+
return this._model.fromDataObject(savedObj);
|
|
65
75
|
});
|
|
66
76
|
}
|
|
67
77
|
read(key) {
|
|
68
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const uid = key.indexOf('/') !== -1 ? key.substring(key.lastIndexOf('/') + 1) : key;
|
|
70
79
|
try {
|
|
71
|
-
|
|
80
|
+
let dataObject;
|
|
81
|
+
if (key.split('/').length <= 2) {
|
|
82
|
+
const uid = key.indexOf('/') !== -1
|
|
83
|
+
? key.substring(key.lastIndexOf('/') + 1)
|
|
84
|
+
: key;
|
|
85
|
+
dataObject = yield this.getDataObjectFromUid(uid);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
dataObject = yield this.getDataObjectFromPath(key);
|
|
89
|
+
}
|
|
72
90
|
const response = yield this.backendAdapter.read(dataObject);
|
|
73
91
|
const obj = this._model.fromDataObject(response);
|
|
74
92
|
// TODO should be moved to the backend middleware
|
|
@@ -3,6 +3,7 @@ import { PropertyClassType } from '../properties/types/PropertyClassType';
|
|
|
3
3
|
import { AbstractObject } from './AbstractObject';
|
|
4
4
|
import { ObjectUri } from './ObjectUri';
|
|
5
5
|
import { DataObjectClass } from './types/DataObjectClass';
|
|
6
|
+
import { toJSONParams } from './types/toJSONParams';
|
|
6
7
|
export type CoreObject<T extends AbstractObject> = T;
|
|
7
8
|
export type Properties = {
|
|
8
9
|
[x: string]: PropertyClassType;
|
|
@@ -14,6 +15,7 @@ export interface DataObjectFactoryType {
|
|
|
14
15
|
export interface DataObjectParams {
|
|
15
16
|
uri?: string | ObjectUri;
|
|
16
17
|
properties: DataObjectProperties;
|
|
18
|
+
parentProp?: string;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Data objects constitute the agnostic glue between objects and backends.
|
|
@@ -26,6 +28,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
26
28
|
protected _properties: Properties;
|
|
27
29
|
protected _persisted: boolean;
|
|
28
30
|
protected _populated: boolean;
|
|
31
|
+
protected _parentProp: string | undefined;
|
|
29
32
|
protected _proxied: any;
|
|
30
33
|
/**
|
|
31
34
|
* Has data been modified since last backend operation?
|
|
@@ -43,6 +46,12 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
43
46
|
*/
|
|
44
47
|
asProxy(): this;
|
|
45
48
|
setProperties(properties: Properties): void;
|
|
49
|
+
/**
|
|
50
|
+
* Return a map of all propoerties or only those matching the provided type
|
|
51
|
+
* @param type
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
getProperties(type?: string): {};
|
|
46
55
|
addProperty(property: PropertyClassType): void;
|
|
47
56
|
/**
|
|
48
57
|
* Populate data object from instant data or backend query
|
|
@@ -75,6 +84,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
75
84
|
set uri(uri: ObjectUri);
|
|
76
85
|
get uri(): ObjectUri;
|
|
77
86
|
get class(): any;
|
|
87
|
+
get parentProp(): string | undefined;
|
|
78
88
|
has(key: string): boolean;
|
|
79
89
|
/**
|
|
80
90
|
* Returns property matching key or throw
|
|
@@ -89,7 +99,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
89
99
|
* @returns any
|
|
90
100
|
*/
|
|
91
101
|
val(key: string, transform?: string | undefined): any;
|
|
92
|
-
toJSON(
|
|
102
|
+
toJSON(params?: boolean | toJSONParams): {
|
|
93
103
|
[x: string]: any;
|
|
94
104
|
};
|
|
95
105
|
toReference(): {
|
|
@@ -97,7 +107,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
97
107
|
ref: string;
|
|
98
108
|
uri: string;
|
|
99
109
|
};
|
|
100
|
-
protected _dataToJSON(objectsAsReferences?: boolean): {};
|
|
110
|
+
protected _dataToJSON(objectsAsReferences?: boolean, ignoreUnchanged?: boolean, converters?: {}): {};
|
|
101
111
|
read(): Promise<DataObjectClass<any>>;
|
|
102
112
|
save(): Promise<DataObjectClass<any>>;
|
|
103
113
|
delete(): Promise<DataObjectClass<any>>;
|
|
@@ -40,6 +40,7 @@ class DataObject {
|
|
|
40
40
|
else {
|
|
41
41
|
this._objectUri = params.uri;
|
|
42
42
|
}
|
|
43
|
+
this._parentProp = params.parentProp;
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
46
|
this._objectUri = new ObjectUri_1.ObjectUri();
|
|
@@ -75,9 +76,26 @@ class DataObject {
|
|
|
75
76
|
// TODO check if doable
|
|
76
77
|
this._properties = properties;
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Return a map of all propoerties or only those matching the provided type
|
|
81
|
+
* @param type
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
getProperties(type) {
|
|
85
|
+
if (type) {
|
|
86
|
+
const matches = {};
|
|
87
|
+
for (let k of Object.keys(this._properties)) {
|
|
88
|
+
if (this._properties[k].constructor.name === type) {
|
|
89
|
+
Reflect.set(matches, k, this._properties[k]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return matches;
|
|
93
|
+
}
|
|
94
|
+
return this._properties;
|
|
95
|
+
}
|
|
78
96
|
addProperty(property) {
|
|
79
97
|
if (Object.keys(this._properties).includes(property.name)) {
|
|
80
|
-
throw new Error(`Property ${name} already exists`);
|
|
98
|
+
throw new Error(`Property ${property.name} already exists`);
|
|
81
99
|
}
|
|
82
100
|
this._properties[property.name] = property;
|
|
83
101
|
}
|
|
@@ -118,10 +136,10 @@ class DataObject {
|
|
|
118
136
|
'label' in val &&
|
|
119
137
|
typeof val.label == 'string') {
|
|
120
138
|
const { ref, label } = val;
|
|
121
|
-
Reflect.get(this._properties, key).set(new ObjectUri_1.ObjectUri(ref, label));
|
|
139
|
+
Reflect.get(this._properties, key).set(new ObjectUri_1.ObjectUri(ref, label), false);
|
|
122
140
|
}
|
|
123
141
|
else {
|
|
124
|
-
Reflect.get(this._properties, key).set(data[key]);
|
|
142
|
+
Reflect.get(this._properties, key).set(data[key], false);
|
|
125
143
|
}
|
|
126
144
|
}
|
|
127
145
|
}
|
|
@@ -190,6 +208,9 @@ class DataObject {
|
|
|
190
208
|
// TODO get class type
|
|
191
209
|
return this.uri.class;
|
|
192
210
|
}
|
|
211
|
+
get parentProp() {
|
|
212
|
+
return this._parentProp;
|
|
213
|
+
}
|
|
193
214
|
has(key) {
|
|
194
215
|
return Reflect.has(this._properties, key);
|
|
195
216
|
}
|
|
@@ -200,7 +221,7 @@ class DataObject {
|
|
|
200
221
|
*/
|
|
201
222
|
get(key) {
|
|
202
223
|
if (!Reflect.has(this._properties, key)) {
|
|
203
|
-
throw new ResourcesErrors_1.NotFoundError(`No property matching key ${key}`);
|
|
224
|
+
throw new ResourcesErrors_1.NotFoundError(`No property matching key '${key}'`);
|
|
204
225
|
}
|
|
205
226
|
return Reflect.get(this._properties, key);
|
|
206
227
|
}
|
|
@@ -226,16 +247,28 @@ class DataObject {
|
|
|
226
247
|
throw new Error(`Unknown property '${key}'`);
|
|
227
248
|
}
|
|
228
249
|
}
|
|
229
|
-
toJSON(
|
|
230
|
-
|
|
250
|
+
toJSON(params = false) {
|
|
251
|
+
let objectsAsReferences = false, withoutURIData = false, ignoreUnchanged = false, converters = {};
|
|
252
|
+
if (typeof params === 'object') {
|
|
253
|
+
// Any missing parameter should resolve to false
|
|
254
|
+
objectsAsReferences = Boolean(params.objectsAsReferences);
|
|
255
|
+
withoutURIData = Boolean(params.withoutURIData);
|
|
256
|
+
ignoreUnchanged = Boolean(params.ignoreUnchanged);
|
|
257
|
+
converters = params.converters;
|
|
258
|
+
}
|
|
259
|
+
return Object.assign(Object.assign({}, (!withoutURIData &&
|
|
260
|
+
this.uri && { uid: this.uri.uid, path: this.uri.path })), this._dataToJSON(objectsAsReferences, ignoreUnchanged, converters));
|
|
231
261
|
}
|
|
232
262
|
toReference() {
|
|
233
263
|
return Object.assign(Object.assign({}, this._objectUri.toReference()), { label: this.val('name') || '' });
|
|
234
264
|
}
|
|
235
|
-
_dataToJSON(objectsAsReferences = false) {
|
|
265
|
+
_dataToJSON(objectsAsReferences = false, ignoreUnchanged = false, converters = {}) {
|
|
236
266
|
const data = {};
|
|
237
267
|
Object.keys(this._properties).forEach((key) => {
|
|
238
268
|
const prop = Reflect.get(this._properties, key);
|
|
269
|
+
if (ignoreUnchanged && prop.hasChanged === false)
|
|
270
|
+
return;
|
|
271
|
+
// console.log(prop.constructor.name);
|
|
239
272
|
switch (prop.constructor.name) {
|
|
240
273
|
case 'CollectionProperty':
|
|
241
274
|
// ignore
|
|
@@ -256,8 +289,12 @@ class DataObject {
|
|
|
256
289
|
case 'ArrayProperty':
|
|
257
290
|
Reflect.set(data, key, prop.val() || []);
|
|
258
291
|
break;
|
|
292
|
+
case 'DateTimeProperty':
|
|
293
|
+
Reflect.set(data, key, prop.val(Reflect.get(converters, 'datetime')) || null);
|
|
294
|
+
break;
|
|
259
295
|
default:
|
|
260
296
|
Reflect.set(data, key, prop.val() || null);
|
|
297
|
+
break;
|
|
261
298
|
}
|
|
262
299
|
});
|
|
263
300
|
return data;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
|
|
4
|
-
import { EntityClass } from './types/EntityClass';
|
|
5
|
-
export declare const EntityProperties: any;
|
|
6
|
-
export interface Entity extends BaseObject {
|
|
7
|
-
users: User;
|
|
3
|
+
export interface EntityType extends BaseObject {
|
|
8
4
|
}
|
|
9
|
-
export declare class
|
|
5
|
+
export declare class Entity extends BaseObjectCore {
|
|
10
6
|
static COLLECTION: string;
|
|
11
7
|
static PROPS_DEFINITION: any[];
|
|
8
|
+
static factory(src?: any): Promise<Entity>;
|
|
12
9
|
}
|
package/lib/components/Entity.js
CHANGED
|
@@ -22,36 +22,36 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
35
|
+
exports.Entity = void 0;
|
|
27
36
|
const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
28
37
|
const BaseObject_1 = require("./BaseObject");
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
//import { User } from './User'
|
|
39
|
+
//import { CollectionProperty } from '../properties/CollectionProperty'
|
|
31
40
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
32
41
|
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
{
|
|
43
|
-
name: 'users',
|
|
44
|
-
mandatory: true,
|
|
45
|
-
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
46
|
-
instanceOf: 'User',
|
|
47
|
-
parentKey: 'entity',
|
|
48
|
-
},
|
|
49
|
-
];
|
|
50
|
-
class EntityCore extends BaseObjectCore_1.BaseObjectCore {
|
|
42
|
+
class Entity extends BaseObjectCore_1.BaseObjectCore {
|
|
43
|
+
static factory(src = undefined) {
|
|
44
|
+
const _super = Object.create(null, {
|
|
45
|
+
factory: { get: () => super.factory }
|
|
46
|
+
});
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return _super.factory.call(this, src, Entity);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
51
|
}
|
|
52
|
-
exports.
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
exports.Entity = Entity;
|
|
53
|
+
Entity.COLLECTION = 'entities';
|
|
54
|
+
Entity.PROPS_DEFINITION = [
|
|
55
55
|
...BaseObject_1.BaseObjectProperties,
|
|
56
56
|
{
|
|
57
57
|
// surcharge property minLength and htmlType
|
|
@@ -61,11 +61,11 @@ EntityCore.PROPS_DEFINITION = [
|
|
|
61
61
|
minLength: 1,
|
|
62
62
|
htmlType: htmlType.ORG,
|
|
63
63
|
},
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
64
|
+
// {
|
|
65
|
+
// name: 'users',
|
|
66
|
+
// mandatory: true,
|
|
67
|
+
// type: CollectionProperty.TYPE,
|
|
68
|
+
// instanceOf: User,
|
|
69
|
+
// parentKey: 'entity',
|
|
70
|
+
// },
|
|
71
71
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
|
-
import {
|
|
4
|
-
export default class EntityRepository extends BaseRepository<
|
|
3
|
+
import { EntityType } from './Entity';
|
|
4
|
+
export default class EntityRepository extends BaseRepository<EntityType> {
|
|
5
5
|
constructor(backendAdapter?: BackendInterface);
|
|
6
6
|
}
|
|
@@ -8,7 +8,7 @@ const BaseRepository_1 = __importDefault(require("./BaseRepository"));
|
|
|
8
8
|
const Entity_1 = require("./Entity");
|
|
9
9
|
class EntityRepository extends BaseRepository_1.default {
|
|
10
10
|
constructor(backendAdapter = Core_1.Core.getBackend()) {
|
|
11
|
-
super(Entity_1.
|
|
11
|
+
super(Entity_1.Entity, backendAdapter);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.default = EntityRepository;
|
|
@@ -10,19 +10,38 @@ export declare class ObjectUri {
|
|
|
10
10
|
protected _collection: string | undefined;
|
|
11
11
|
protected _label: string | undefined;
|
|
12
12
|
protected _objClass: any;
|
|
13
|
+
protected _parent: ObjectUri | undefined;
|
|
13
14
|
/**
|
|
14
15
|
* create object uri from string:
|
|
15
16
|
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
16
17
|
* some backends will need a collection or table name, some may deduct it from object
|
|
17
|
-
* @param str
|
|
18
|
+
* @param str partial or full resource path
|
|
19
|
+
* @param label optional label to describe path
|
|
18
20
|
*/
|
|
19
21
|
constructor(str?: string, label?: string | undefined);
|
|
20
22
|
set class(objClass: any);
|
|
21
23
|
get class(): any;
|
|
22
24
|
get backend(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the full path of the resource
|
|
27
|
+
* including optional parents' path
|
|
28
|
+
* @returns string
|
|
29
|
+
*/
|
|
23
30
|
get path(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the own path of the resource
|
|
33
|
+
* without the optional parents' paths
|
|
34
|
+
* @returns string
|
|
35
|
+
*/
|
|
36
|
+
get ownPath(): string;
|
|
37
|
+
get parent(): ObjectUri | undefined;
|
|
24
38
|
set label(label: string | undefined);
|
|
25
39
|
get label(): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Return the full path litteral
|
|
42
|
+
* including the backend alias
|
|
43
|
+
* @returns string
|
|
44
|
+
*/
|
|
26
45
|
get literal(): string;
|
|
27
46
|
set path(path: string);
|
|
28
47
|
get uid(): string | undefined;
|
|
@@ -7,7 +7,8 @@ class ObjectUri {
|
|
|
7
7
|
* create object uri from string:
|
|
8
8
|
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
9
9
|
* some backends will need a collection or table name, some may deduct it from object
|
|
10
|
-
* @param str
|
|
10
|
+
* @param str partial or full resource path
|
|
11
|
+
* @param label optional label to describe path
|
|
11
12
|
*/
|
|
12
13
|
constructor(str = '', label = '') {
|
|
13
14
|
this._pairs = [];
|
|
@@ -28,34 +29,38 @@ class ObjectUri {
|
|
|
28
29
|
this._path = str;
|
|
29
30
|
}
|
|
30
31
|
const parts = this._path.split(ObjectUri.DEFAULT);
|
|
31
|
-
|
|
32
|
+
const isFilePath = parts[parts.length - 1].indexOf('.') !== -1;
|
|
33
|
+
if (isFilePath) {
|
|
34
|
+
this._uid = parts[parts.length - 1];
|
|
35
|
+
}
|
|
36
|
+
else if (parts.length === 1) {
|
|
32
37
|
// It is allowed to only give the uid part of the uri
|
|
33
|
-
// provided that collection will be injected by another
|
|
38
|
+
// provided that collection will be injected by another means
|
|
34
39
|
this._uid = parts[0].length > 0 ? parts[0] : undefined;
|
|
35
40
|
this._collection = ObjectUri.MISSING_COLLECTION;
|
|
36
41
|
this._pairs.push(`${ObjectUri.MISSING_COLLECTION}${ObjectUri.DEFAULT}${this._uid}`);
|
|
37
42
|
this._label = label || this._uid;
|
|
38
43
|
}
|
|
39
44
|
else if (parts.length % 2 === 0) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
this._pairs.push(`${parts[i]}${ObjectUri.DEFAULT}${parts[i + 1]}`);
|
|
46
|
-
i += 2;
|
|
45
|
+
this._path = parts.slice(parts.length - 2).join(ObjectUri.DEFAULT);
|
|
46
|
+
this._uid = parts[parts.length - 1];
|
|
47
|
+
this._collection = parts[parts.length - 2];
|
|
48
|
+
if (parts.length > 2) {
|
|
49
|
+
this._parent = new ObjectUri(parts.slice(0, parts.length - 2).join(ObjectUri.DEFAULT));
|
|
47
50
|
}
|
|
48
51
|
this._label = label || this._uid;
|
|
49
52
|
}
|
|
50
|
-
else {
|
|
53
|
+
else if (!isFilePath) {
|
|
54
|
+
// if the last part is not a filename with extension, throw error
|
|
51
55
|
throw new Error(`Path parts number must be 1 or even, received: '${str}'`);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
set class(objClass) {
|
|
55
|
-
var _a;
|
|
56
59
|
this._objClass = objClass;
|
|
57
60
|
if (objClass) {
|
|
58
|
-
this._collection =
|
|
61
|
+
this._collection =
|
|
62
|
+
objClass.COLLECTION ||
|
|
63
|
+
(objClass.name && objClass.name.toLowerCase());
|
|
59
64
|
}
|
|
60
65
|
else {
|
|
61
66
|
this._collection = undefined;
|
|
@@ -67,17 +72,42 @@ class ObjectUri {
|
|
|
67
72
|
get backend() {
|
|
68
73
|
return this._backend;
|
|
69
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the full path of the resource
|
|
77
|
+
* including optional parents' path
|
|
78
|
+
* @returns string
|
|
79
|
+
*/
|
|
70
80
|
get path() {
|
|
81
|
+
return this._parent
|
|
82
|
+
? `${this._parent.path}${ObjectUri.DEFAULT}${this._path}`
|
|
83
|
+
: this._path;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the own path of the resource
|
|
87
|
+
* without the optional parents' paths
|
|
88
|
+
* @returns string
|
|
89
|
+
*/
|
|
90
|
+
get ownPath() {
|
|
71
91
|
return this._path;
|
|
72
92
|
}
|
|
93
|
+
get parent() {
|
|
94
|
+
return this._parent;
|
|
95
|
+
}
|
|
73
96
|
set label(label) {
|
|
74
97
|
this._label = label;
|
|
75
98
|
}
|
|
76
99
|
get label() {
|
|
77
100
|
return this._label;
|
|
78
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Return the full path litteral
|
|
104
|
+
* including the backend alias
|
|
105
|
+
* @returns string
|
|
106
|
+
*/
|
|
79
107
|
get literal() {
|
|
80
|
-
return
|
|
108
|
+
return this._str.includes(':')
|
|
109
|
+
? this._str
|
|
110
|
+
: `${this._backend}:${this._str}`;
|
|
81
111
|
}
|
|
82
112
|
set path(path) {
|
|
83
113
|
// if (this._path && this._path !== ObjectUri.DEFAULT) {
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
export interface
|
|
3
|
+
export interface UserType extends BaseObject {
|
|
4
4
|
name: string;
|
|
5
5
|
firstname: string;
|
|
6
6
|
lastname: string;
|
|
@@ -10,8 +10,8 @@ export interface User extends BaseObject {
|
|
|
10
10
|
email: string;
|
|
11
11
|
}
|
|
12
12
|
export declare const UserProperties: any;
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class User extends BaseObjectCore {
|
|
14
14
|
static PROPS_DEFINITION: any;
|
|
15
15
|
static COLLECTION: string;
|
|
16
|
-
static factory(src?: any): Promise<
|
|
16
|
+
static factory(src?: any): Promise<User>;
|
|
17
17
|
}
|
package/lib/components/User.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
35
|
+
exports.User = exports.UserProperties = void 0;
|
|
36
36
|
const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
37
37
|
const properties_1 = require("../properties");
|
|
38
38
|
const HashProperty_1 = require("../properties/HashProperty");
|
|
@@ -97,33 +97,40 @@ exports.UserProperties = [
|
|
|
97
97
|
fullSearch: true,
|
|
98
98
|
htmlType: htmlType.EMAIL,
|
|
99
99
|
},
|
|
100
|
+
{
|
|
101
|
+
name: 'phone',
|
|
102
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
103
|
+
minLength: 1,
|
|
104
|
+
maxLength: 100,
|
|
105
|
+
htmlType: htmlType.OFF,
|
|
106
|
+
},
|
|
100
107
|
{
|
|
101
108
|
name: 'password',
|
|
102
109
|
mandatory: true,
|
|
103
110
|
type: HashProperty_1.HashProperty.TYPE,
|
|
104
111
|
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
105
|
-
salt: '',
|
|
112
|
+
salt: '', // you should override it in your code
|
|
106
113
|
minLength: 5,
|
|
107
|
-
maxLength: 20,
|
|
114
|
+
maxLength: 20, // this is for the clear password
|
|
108
115
|
htmlType: htmlType.PASSWORD,
|
|
109
116
|
},
|
|
110
117
|
{
|
|
111
118
|
name: 'entity',
|
|
112
119
|
mandatory: false,
|
|
113
120
|
type: properties_1.ObjectProperty.TYPE,
|
|
114
|
-
instanceOf: Entity_1.
|
|
121
|
+
instanceOf: Entity_1.Entity,
|
|
115
122
|
},
|
|
116
123
|
];
|
|
117
|
-
class
|
|
124
|
+
class User extends BaseObjectCore_1.BaseObjectCore {
|
|
118
125
|
static factory(src = undefined) {
|
|
119
126
|
const _super = Object.create(null, {
|
|
120
127
|
factory: { get: () => super.factory }
|
|
121
128
|
});
|
|
122
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
return _super.factory.call(this, src,
|
|
130
|
+
return _super.factory.call(this, src, User);
|
|
124
131
|
});
|
|
125
132
|
}
|
|
126
133
|
}
|
|
127
|
-
exports.
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
exports.User = User;
|
|
135
|
+
User.PROPS_DEFINITION = exports.UserProperties;
|
|
136
|
+
User.COLLECTION = 'user';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BackendInterface } from '../backends/types/BackendInterface';
|
|
2
2
|
import BaseRepository from './BaseRepository';
|
|
3
|
-
import {
|
|
4
|
-
export default class UserRepository extends BaseRepository<
|
|
3
|
+
import { UserType } from './User';
|
|
4
|
+
export default class UserRepository extends BaseRepository<UserType> {
|
|
5
5
|
constructor(backendAdapter?: BackendInterface);
|
|
6
|
-
getFromEmail(email: string): Promise<
|
|
6
|
+
getFromEmail(email: string): Promise<UserType>;
|
|
7
7
|
}
|
|
@@ -19,11 +19,11 @@ const User_1 = require("./User");
|
|
|
19
19
|
const UNAUTHORIZED_ERROR = `Wrong password or email`;
|
|
20
20
|
class UserRepository extends BaseRepository_1.default {
|
|
21
21
|
constructor(backendAdapter) {
|
|
22
|
-
super(User_1.
|
|
22
|
+
super(User_1.User, backendAdapter);
|
|
23
23
|
}
|
|
24
24
|
getFromEmail(email) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const query = new backends_1.Query(User_1.
|
|
26
|
+
const query = new backends_1.Query(User_1.User);
|
|
27
27
|
query.where('email', email).batch(1);
|
|
28
28
|
const { items } = yield this.query(query);
|
|
29
29
|
if (items.length == 0) {
|