@quatrain/core 0.5.6 → 1.0.0-beta10
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 +34 -1
- package/lib/Backend.js +1 -9
- package/lib/Core.d.ts +11 -7
- package/lib/Core.js +13 -3
- 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/middlewares/AuthMiddleware.js +2 -0
- package/lib/authentication/middlewares/Middleware.d.ts +5 -0
- package/lib/authentication/middlewares/Middleware.js +2 -0
- package/lib/authentication/types/AuthInterface.d.ts +9 -0
- package/lib/authentication/types/AuthInterface.js +2 -0
- package/lib/backends/AbstractAdapter.d.ts +20 -45
- package/lib/backends/AbstractAdapter.js +27 -9
- package/lib/backends/Filters.d.ts +2 -1
- package/lib/backends/MockAdapter.d.ts +6 -4
- package/lib/backends/MockAdapter.js +15 -6
- package/lib/backends/Query.d.ts +29 -13
- package/lib/backends/Query.js +22 -9
- package/lib/backends/index.d.ts +5 -3
- package/lib/backends/index.js +26 -1
- package/lib/backends/middlewares/InjectKeywordsMiddleware.d.ts +9 -0
- package/lib/backends/middlewares/InjectKeywordsMiddleware.js +47 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +6 -6
- package/lib/backends/middlewares/InjectMetaMiddleware.js +10 -7
- 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 +13 -0
- package/lib/backends/types/BackendInterface.js +2 -0
- package/lib/backends/types/CollectionHierarchy.d.ts +3 -0
- package/lib/backends/types/CollectionHierarchy.js +6 -0
- package/lib/common/statuses.d.ts +3 -0
- package/lib/common/statuses.js +4 -1
- package/lib/components/AbstractObject.d.ts +9 -1
- package/lib/components/AbstractObject.js +9 -0
- package/lib/components/BaseObject.d.ts +3 -3
- package/lib/components/BaseObject.js +3 -0
- package/lib/components/BaseObjectCore.d.ts +16 -3
- package/lib/components/BaseObjectCore.js +21 -5
- package/lib/components/BaseRepository.d.ts +14 -13
- package/lib/components/BaseRepository.js +37 -21
- package/lib/components/DataObject.d.ts +20 -3
- package/lib/components/DataObject.js +73 -13
- package/lib/components/Entity.d.ts +4 -21
- package/lib/components/Entity.js +34 -32
- package/lib/components/EntityRepository.d.ts +3 -3
- package/lib/components/EntityRepository.js +1 -1
- package/lib/components/ObjectUri.js +2 -3
- package/lib/components/User.d.ts +4 -5
- package/lib/components/User.js +19 -10
- package/lib/components/UserRepository.d.ts +4 -4
- package/lib/components/UserRepository.js +2 -2
- package/lib/components/index.d.ts +3 -2
- package/lib/components/index.js +9 -2
- package/lib/components/types/DataObjectClass.d.ts +7 -1
- package/lib/components/types/RepositoryClass.d.ts +2 -2
- package/lib/components/types/toJSONParams.d.ts +8 -0
- package/lib/components/types/toJSONParams.js +2 -0
- package/lib/index.d.ts +10 -5
- package/lib/index.js +17 -2
- 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 +3 -3
- 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 +7 -1
- package/lib/properties/HashProperty.js +10 -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 +6 -6
- package/lib/properties/ObjectProperty.js +57 -5
- package/lib/properties/Property.d.ts +9 -2
- package/lib/properties/StringProperty.d.ts +2 -2
- package/lib/properties/StringProperty.js +2 -2
- package/lib/properties/types/AbstractPropertyType.d.ts +1 -0
- package/lib/properties/types/PropertyClassType.d.ts +4 -1
- 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/package.json +3 -2
- package/README.md +0 -124
|
@@ -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,8 @@ 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;
|
|
32
|
+
protected _proxied: any;
|
|
29
33
|
/**
|
|
30
34
|
* Has data been modified since last backend operation?
|
|
31
35
|
*/
|
|
@@ -36,7 +40,19 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
36
40
|
*/
|
|
37
41
|
protected constructor(params: DataObjectParams | undefined);
|
|
38
42
|
protected _init(properties: any[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Wrap instance into proxy to get access to properties
|
|
45
|
+
* @returns Proxy
|
|
46
|
+
*/
|
|
47
|
+
asProxy(): this;
|
|
39
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): {};
|
|
55
|
+
addProperty(property: PropertyClassType): void;
|
|
40
56
|
/**
|
|
41
57
|
* Populate data object from instant data or backend query
|
|
42
58
|
* @param data
|
|
@@ -68,6 +84,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
68
84
|
set uri(uri: ObjectUri);
|
|
69
85
|
get uri(): ObjectUri;
|
|
70
86
|
get class(): any;
|
|
87
|
+
get parentProp(): string | undefined;
|
|
71
88
|
has(key: string): boolean;
|
|
72
89
|
/**
|
|
73
90
|
* Returns property matching key or throw
|
|
@@ -81,8 +98,8 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
81
98
|
* @param key string
|
|
82
99
|
* @returns any
|
|
83
100
|
*/
|
|
84
|
-
val(key: string): any;
|
|
85
|
-
toJSON(
|
|
101
|
+
val(key: string, transform?: string | undefined): any;
|
|
102
|
+
toJSON(params?: boolean | toJSONParams): {
|
|
86
103
|
[x: string]: any;
|
|
87
104
|
};
|
|
88
105
|
toReference(): {
|
|
@@ -90,7 +107,7 @@ export declare class DataObject implements DataObjectClass<any> {
|
|
|
90
107
|
ref: string;
|
|
91
108
|
uri: string;
|
|
92
109
|
};
|
|
93
|
-
protected _dataToJSON(objectsAsReferences?: boolean): {};
|
|
110
|
+
protected _dataToJSON(objectsAsReferences?: boolean, ignoreUnchanged?: boolean, converters?: {}): {};
|
|
94
111
|
read(): Promise<DataObjectClass<any>>;
|
|
95
112
|
save(): Promise<DataObjectClass<any>>;
|
|
96
113
|
delete(): Promise<DataObjectClass<any>>;
|
|
@@ -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
|
|
@@ -39,6 +40,7 @@ class DataObject {
|
|
|
39
40
|
else {
|
|
40
41
|
this._objectUri = params.uri;
|
|
41
42
|
}
|
|
43
|
+
this._parentProp = params.parentProp;
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
this._objectUri = new ObjectUri_1.ObjectUri();
|
|
@@ -52,10 +54,51 @@ class DataObject {
|
|
|
52
54
|
this._properties[prop.name] = Property_1.Property.factory(prop, this);
|
|
53
55
|
});
|
|
54
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Wrap instance into proxy to get access to properties
|
|
59
|
+
* @returns Proxy
|
|
60
|
+
*/
|
|
61
|
+
asProxy() {
|
|
62
|
+
return new Proxy(this, {
|
|
63
|
+
get: (target, prop) => {
|
|
64
|
+
return target.val(prop);
|
|
65
|
+
},
|
|
66
|
+
set(target, prop, newValue) {
|
|
67
|
+
if (prop === 'uid' || prop === 'core') {
|
|
68
|
+
throw new Error(`Property '${prop}' is readonly`);
|
|
69
|
+
}
|
|
70
|
+
target.set(prop, newValue);
|
|
71
|
+
return true;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
55
75
|
setProperties(properties) {
|
|
56
76
|
// TODO check if doable
|
|
57
77
|
this._properties = properties;
|
|
58
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
|
+
}
|
|
96
|
+
addProperty(property) {
|
|
97
|
+
if (Object.keys(this._properties).includes(property.name)) {
|
|
98
|
+
throw new Error(`Property ${property.name} already exists`);
|
|
99
|
+
}
|
|
100
|
+
this._properties[property.name] = property;
|
|
101
|
+
}
|
|
59
102
|
/**
|
|
60
103
|
* Populate data object from instant data or backend query
|
|
61
104
|
* @param data
|
|
@@ -93,10 +136,10 @@ class DataObject {
|
|
|
93
136
|
'label' in val &&
|
|
94
137
|
typeof val.label == 'string') {
|
|
95
138
|
const { ref, label } = val;
|
|
96
|
-
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);
|
|
97
140
|
}
|
|
98
141
|
else {
|
|
99
|
-
Reflect.get(this._properties, key).set(data[key]);
|
|
142
|
+
Reflect.get(this._properties, key).set(data[key], false);
|
|
100
143
|
}
|
|
101
144
|
}
|
|
102
145
|
}
|
|
@@ -165,6 +208,9 @@ class DataObject {
|
|
|
165
208
|
// TODO get class type
|
|
166
209
|
return this.uri.class;
|
|
167
210
|
}
|
|
211
|
+
get parentProp() {
|
|
212
|
+
return this._parentProp;
|
|
213
|
+
}
|
|
168
214
|
has(key) {
|
|
169
215
|
return Reflect.has(this._properties, key);
|
|
170
216
|
}
|
|
@@ -174,12 +220,10 @@ class DataObject {
|
|
|
174
220
|
* @returns BaseProperty
|
|
175
221
|
*/
|
|
176
222
|
get(key) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
throw new Error(err.message);
|
|
223
|
+
if (!Reflect.has(this._properties, key)) {
|
|
224
|
+
throw new ResourcesErrors_1.NotFoundError(`No property matching key '${key}'`);
|
|
182
225
|
}
|
|
226
|
+
return Reflect.get(this._properties, key);
|
|
183
227
|
}
|
|
184
228
|
set(key, val) {
|
|
185
229
|
if (!this.has(key)) {
|
|
@@ -195,24 +239,36 @@ class DataObject {
|
|
|
195
239
|
* @param key string
|
|
196
240
|
* @returns any
|
|
197
241
|
*/
|
|
198
|
-
val(key) {
|
|
242
|
+
val(key, transform = undefined) {
|
|
199
243
|
if (this.has(key)) {
|
|
200
|
-
return Reflect.get(this._properties, key).val();
|
|
244
|
+
return Reflect.get(this._properties, key).val(transform);
|
|
201
245
|
}
|
|
202
246
|
else {
|
|
203
247
|
throw new Error(`Unknown property '${key}'`);
|
|
204
248
|
}
|
|
205
249
|
}
|
|
206
|
-
toJSON(
|
|
207
|
-
|
|
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));
|
|
208
261
|
}
|
|
209
262
|
toReference() {
|
|
210
263
|
return Object.assign(Object.assign({}, this._objectUri.toReference()), { label: this.val('name') || '' });
|
|
211
264
|
}
|
|
212
|
-
_dataToJSON(objectsAsReferences = false) {
|
|
265
|
+
_dataToJSON(objectsAsReferences = false, ignoreUnchanged = false, converters = {}) {
|
|
213
266
|
const data = {};
|
|
214
267
|
Object.keys(this._properties).forEach((key) => {
|
|
215
268
|
const prop = Reflect.get(this._properties, key);
|
|
269
|
+
if (ignoreUnchanged && prop.hasChanged === false)
|
|
270
|
+
return;
|
|
271
|
+
// console.log(prop.constructor.name);
|
|
216
272
|
switch (prop.constructor.name) {
|
|
217
273
|
case 'CollectionProperty':
|
|
218
274
|
// ignore
|
|
@@ -221,7 +277,7 @@ class DataObject {
|
|
|
221
277
|
const value = prop.val();
|
|
222
278
|
Reflect.set(data, key, value
|
|
223
279
|
? objectsAsReferences && !(value instanceof ObjectUri_1.ObjectUri)
|
|
224
|
-
? value.
|
|
280
|
+
? value.asReference()
|
|
225
281
|
: value.toJSON
|
|
226
282
|
? value.toJSON()
|
|
227
283
|
: value
|
|
@@ -233,8 +289,12 @@ class DataObject {
|
|
|
233
289
|
case 'ArrayProperty':
|
|
234
290
|
Reflect.set(data, key, prop.val() || []);
|
|
235
291
|
break;
|
|
292
|
+
case 'DateTimeProperty':
|
|
293
|
+
Reflect.set(data, key, prop.val(Reflect.get(converters, 'datetime')) || null);
|
|
294
|
+
break;
|
|
236
295
|
default:
|
|
237
296
|
Reflect.set(data, key, prop.val() || null);
|
|
297
|
+
break;
|
|
238
298
|
}
|
|
239
299
|
});
|
|
240
300
|
return data;
|
|
@@ -1,26 +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
|
-
static PROPS_DEFINITION:
|
|
12
|
-
|
|
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
|
-
})[];
|
|
7
|
+
static PROPS_DEFINITION: any[];
|
|
8
|
+
static factory(src?: any): Promise<Entity>;
|
|
26
9
|
}
|
package/lib/components/Entity.js
CHANGED
|
@@ -22,48 +22,50 @@ 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
|
-
const
|
|
29
|
-
|
|
37
|
+
const BaseObject_1 = require("./BaseObject");
|
|
38
|
+
//import { User } from './User'
|
|
39
|
+
//import { CollectionProperty } from '../properties/CollectionProperty'
|
|
30
40
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
31
41
|
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
{
|
|
42
|
-
name: 'users',
|
|
43
|
-
mandatory: true,
|
|
44
|
-
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
45
|
-
instanceOf: 'User',
|
|
46
|
-
parentKey: 'entity',
|
|
47
|
-
},
|
|
48
|
-
];
|
|
49
|
-
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
|
+
}
|
|
50
51
|
}
|
|
51
|
-
exports.
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
exports.Entity = Entity;
|
|
53
|
+
Entity.COLLECTION = 'entities';
|
|
54
|
+
Entity.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
|
-
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: 'users',
|
|
64
|
-
mandatory: true,
|
|
65
|
-
type: CollectionProperty_1.CollectionProperty.TYPE,
|
|
66
|
-
instanceOf: User_1.UserCore,
|
|
67
|
-
parentKey: 'entity',
|
|
62
|
+
htmlType: htmlType.ORG,
|
|
68
63
|
},
|
|
64
|
+
// {
|
|
65
|
+
// name: 'users',
|
|
66
|
+
// mandatory: true,
|
|
67
|
+
// type: CollectionProperty.TYPE,
|
|
68
|
+
// instanceOf: User,
|
|
69
|
+
// parentKey: 'entity',
|
|
70
|
+
// },
|
|
69
71
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
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;
|
|
@@ -48,14 +48,13 @@ class ObjectUri {
|
|
|
48
48
|
this._label = label || this._uid;
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
throw new Error(
|
|
51
|
+
throw new Error(`Path parts number must be 1 or even, received: '${str}'`);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
set class(objClass) {
|
|
55
|
-
var _a;
|
|
56
55
|
this._objClass = objClass;
|
|
57
56
|
if (objClass) {
|
|
58
|
-
this._collection = objClass.COLLECTION ||
|
|
57
|
+
this._collection = objClass.COLLECTION || objClass.name && objClass.name.toLowerCase();
|
|
59
58
|
}
|
|
60
59
|
else {
|
|
61
60
|
this._collection = undefined;
|
package/lib/components/User.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
2
2
|
import { BaseObject } from './BaseObject';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface User extends BaseObject {
|
|
3
|
+
export interface UserType extends BaseObject {
|
|
4
|
+
name: string;
|
|
6
5
|
firstname: string;
|
|
7
6
|
lastname: string;
|
|
8
7
|
gender?: 'male' | 'female' | 'nonbinary';
|
|
@@ -11,8 +10,8 @@ export interface User extends BaseObject {
|
|
|
11
10
|
email: string;
|
|
12
11
|
}
|
|
13
12
|
export declare const UserProperties: any;
|
|
14
|
-
export declare class
|
|
13
|
+
export declare class User 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<User>;
|
|
18
17
|
}
|
package/lib/components/User.js
CHANGED
|
@@ -32,13 +32,14 @@ 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");
|
|
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
|
},
|
|
@@ -95,33 +97,40 @@ exports.UserProperties = [
|
|
|
95
97
|
fullSearch: true,
|
|
96
98
|
htmlType: htmlType.EMAIL,
|
|
97
99
|
},
|
|
100
|
+
{
|
|
101
|
+
name: 'phone',
|
|
102
|
+
type: StringProperty_1.StringProperty.TYPE,
|
|
103
|
+
minLength: 1,
|
|
104
|
+
maxLength: 100,
|
|
105
|
+
htmlType: htmlType.OFF,
|
|
106
|
+
},
|
|
98
107
|
{
|
|
99
108
|
name: 'password',
|
|
100
109
|
mandatory: true,
|
|
101
110
|
type: HashProperty_1.HashProperty.TYPE,
|
|
102
111
|
algorithm: HashProperty_1.HashProperty.ALGORITHM_SHA256,
|
|
103
|
-
salt: '',
|
|
112
|
+
salt: '', // you should override it in your code
|
|
104
113
|
minLength: 5,
|
|
105
|
-
maxLength: 20,
|
|
114
|
+
maxLength: 20, // this is for the clear password
|
|
106
115
|
htmlType: htmlType.PASSWORD,
|
|
107
116
|
},
|
|
108
117
|
{
|
|
109
118
|
name: 'entity',
|
|
110
119
|
mandatory: false,
|
|
111
120
|
type: properties_1.ObjectProperty.TYPE,
|
|
112
|
-
instanceOf:
|
|
121
|
+
instanceOf: Entity_1.Entity,
|
|
113
122
|
},
|
|
114
123
|
];
|
|
115
|
-
class
|
|
124
|
+
class User extends BaseObjectCore_1.BaseObjectCore {
|
|
116
125
|
static factory(src = undefined) {
|
|
117
126
|
const _super = Object.create(null, {
|
|
118
127
|
factory: { get: () => super.factory }
|
|
119
128
|
});
|
|
120
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
return _super.factory.call(this, src,
|
|
130
|
+
return _super.factory.call(this, src, User);
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
133
|
}
|
|
125
|
-
exports.
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
exports.User = User;
|
|
135
|
+
User.PROPS_DEFINITION = exports.UserProperties;
|
|
136
|
+
User.COLLECTION = 'user';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BackendInterface } from '../backends';
|
|
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) {
|
|
@@ -4,6 +4,7 @@ import { ObjectUri } from './ObjectUri';
|
|
|
4
4
|
import { AbstractObject } from './AbstractObject';
|
|
5
5
|
import { BaseObjectCore } from './BaseObjectCore';
|
|
6
6
|
import { BaseObjectProperties } from './BaseObject';
|
|
7
|
-
import
|
|
7
|
+
import BaseRepository from './BaseRepository';
|
|
8
|
+
import { User, UserProperties } from './User';
|
|
8
9
|
import { Entity } from './Entity';
|
|
9
|
-
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObjectCore,
|
|
10
|
+
export { DataObject, DataObjectParams, DataObjectClass, ObjectUri, AbstractObject, BaseObjectCore, BaseRepository, User, Entity, BaseObjectProperties, UserProperties, };
|
package/lib/components/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserProperties = exports.BaseObjectProperties = exports.
|
|
6
|
+
exports.UserProperties = exports.BaseObjectProperties = exports.Entity = exports.User = exports.BaseRepository = exports.BaseObjectCore = exports.AbstractObject = exports.ObjectUri = exports.DataObject = void 0;
|
|
4
7
|
const DataObject_1 = require("./DataObject");
|
|
5
8
|
Object.defineProperty(exports, "DataObject", { enumerable: true, get: function () { return DataObject_1.DataObject; } });
|
|
6
9
|
const ObjectUri_1 = require("./ObjectUri");
|
|
@@ -11,6 +14,10 @@ const BaseObjectCore_1 = require("./BaseObjectCore");
|
|
|
11
14
|
Object.defineProperty(exports, "BaseObjectCore", { enumerable: true, get: function () { return BaseObjectCore_1.BaseObjectCore; } });
|
|
12
15
|
const BaseObject_1 = require("./BaseObject");
|
|
13
16
|
Object.defineProperty(exports, "BaseObjectProperties", { enumerable: true, get: function () { return BaseObject_1.BaseObjectProperties; } });
|
|
17
|
+
const BaseRepository_1 = __importDefault(require("./BaseRepository"));
|
|
18
|
+
exports.BaseRepository = BaseRepository_1.default;
|
|
14
19
|
const User_1 = require("./User");
|
|
15
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
|
|
16
21
|
Object.defineProperty(exports, "UserProperties", { enumerable: true, get: function () { return User_1.UserProperties; } });
|
|
22
|
+
const Entity_1 = require("./Entity");
|
|
23
|
+
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return Entity_1.Entity; } });
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { PropertyClassType } from '../../properties/types/PropertyClassType';
|
|
1
2
|
import { ObjectUri } from '../ObjectUri';
|
|
3
|
+
import { toJSONParams } from './toJSONParams';
|
|
2
4
|
export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
3
5
|
uri: ObjectUri;
|
|
4
6
|
uid: any;
|
|
@@ -6,7 +8,10 @@ export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
|
6
8
|
path: any;
|
|
7
9
|
class: any;
|
|
8
10
|
properties: any;
|
|
11
|
+
parentProp: string | undefined;
|
|
9
12
|
setProperties(properties: any): void;
|
|
13
|
+
getProperties(type: any): any;
|
|
14
|
+
addProperty(property: PropertyClassType): void;
|
|
10
15
|
populate(data?: any): Promise<T>;
|
|
11
16
|
isPopulated(): boolean;
|
|
12
17
|
isPersisted(): boolean;
|
|
@@ -19,8 +24,9 @@ export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
|
19
24
|
delete(): Promise<T>;
|
|
20
25
|
clone(data?: any): Promise<T>;
|
|
21
26
|
toReference(): any;
|
|
22
|
-
toJSON(
|
|
27
|
+
toJSON(params?: boolean | toJSONParams): any;
|
|
23
28
|
populateFromData(data: {
|
|
24
29
|
[x: string]: unknown;
|
|
25
30
|
}): this;
|
|
31
|
+
asProxy(): any;
|
|
26
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackendInterface } from '../../backends/
|
|
1
|
+
import { BackendInterface } from '../../backends/types/BackendInterface';
|
|
2
2
|
import { Query } from '../../backends/Query';
|
|
3
3
|
import { BaseObjectCore } from '../BaseObjectCore';
|
|
4
4
|
import { BaseObject } from '../BaseObject';
|
|
@@ -18,7 +18,7 @@ export default interface RepositoryClass<T extends BaseObject> {
|
|
|
18
18
|
* @param uid
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
|
-
read(uid: string): Promise<
|
|
21
|
+
read(uid: string): Promise<any>;
|
|
22
22
|
/**
|
|
23
23
|
* Updates a given object in the collction and returns it
|
|
24
24
|
* @param obj
|
package/lib/index.d.ts
CHANGED
|
@@ -17,13 +17,18 @@ import { BaseObjectCore } from './components/BaseObjectCore';
|
|
|
17
17
|
import { BaseObject, BaseObjectProperties } from './components/BaseObject';
|
|
18
18
|
import { Proxy } from './components/types/ProxyConstructor';
|
|
19
19
|
import { InjectMetaMiddleware } from './backends/middlewares/InjectMetaMiddleware';
|
|
20
|
+
import { InjectKeywordsMiddleware } from './backends/middlewares/InjectKeywordsMiddleware';
|
|
20
21
|
import RepositoryClass from './components/types/RepositoryClass';
|
|
21
|
-
import
|
|
22
|
+
import BaseRepository from './components/BaseRepository';
|
|
23
|
+
import { BackendAction, BackendParameters, BackendParametersKeys, BackendRecordType } from './Backend';
|
|
22
24
|
import Middleware from './backends/middlewares/Middleware';
|
|
23
|
-
import { User } from './components/User';
|
|
25
|
+
import { UserType, User } from './components/User';
|
|
24
26
|
import UserRepository from './components/UserRepository';
|
|
25
|
-
import { Entity } from './components/Entity';
|
|
27
|
+
import { EntityType, Entity } from './components/Entity';
|
|
26
28
|
import EntityRepository from './components/EntityRepository';
|
|
27
|
-
import {
|
|
29
|
+
import { AuthAction, AuthParameters, AuthParametersKeys } from './Auth';
|
|
30
|
+
import { AuthInterface, AbstractAuthAdapter, AuthenticationError } from './authentication';
|
|
31
|
+
import { AbstractAdapter, MockAdapter, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit } from './backends';
|
|
28
32
|
import { BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError } from './common/ResourcesErrors';
|
|
29
|
-
|
|
33
|
+
import { AbstractCloudWrapper } from './wrappers/cloud/AbstractCloudWrapper';
|
|
34
|
+
export { statuses, utils, Core, Property, BaseProperty, BasePropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, HashProperty, HashPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, AbstractAdapter, RepositoryClass, MockAdapter, ObjectUri, DataObjectClass, DataObject, AbstractObject, BaseObject, BaseObjectCore, BaseObjectProperties, AuthAction, AuthParameters, AuthParametersKeys, AuthInterface, AbstractAuthAdapter, AuthenticationError, BackendParameters, BackendParametersKeys, BackendRecordType, BackendAction, BaseRepository, BackendError, Query, QueryMetaType, QueryResultType, Filter, Filters, Limits, Sorting, SortAndLimit, Middleware, InjectMetaMiddleware, InjectKeywordsMiddleware, User, UserType, Proxy, UserRepository, Entity, EntityType, EntityRepository, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, GoneError, AbstractCloudWrapper, };
|