@quatrain/core 1.0.0-beta1 → 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 -0
- package/lib/Core.d.ts +8 -8
- package/lib/Core.js +6 -5
- 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/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 +19 -44
- 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 +27 -12
- package/lib/backends/Query.js +20 -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 +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 +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 +2 -0
- package/lib/common/statuses.js +3 -1
- package/lib/components/AbstractObject.d.ts +3 -1
- package/lib/components/AbstractObject.js +1 -0
- package/lib/components/BaseObject.d.ts +3 -3
- package/lib/components/BaseObject.js +1 -0
- package/lib/components/BaseObjectCore.d.ts +10 -1
- package/lib/components/BaseObjectCore.js +16 -5
- package/lib/components/BaseRepository.d.ts +10 -8
- package/lib/components/BaseRepository.js +28 -13
- package/lib/components/DataObject.d.ts +13 -2
- package/lib/components/DataObject.js +52 -10
- 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 +1 -2
- 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 +2 -2
- package/lib/components/index.js +4 -2
- package/lib/components/types/DataObjectClass.d.ts +6 -1
- package/lib/components/types/RepositoryClass.d.ts +1 -1
- package/lib/components/types/toJSONParams.d.ts +8 -0
- package/lib/components/types/toJSONParams.js +2 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +16 -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 +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 +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 +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 +2 -2
- package/README.md +0 -124
- 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/{components/types/UserClass.js → authentication/middlewares/AuthMiddleware.js} +0 -0
|
@@ -10,11 +10,13 @@ class BaseProperty {
|
|
|
10
10
|
this._htmlType = 'off';
|
|
11
11
|
this._events = {};
|
|
12
12
|
this._parent = config.parent;
|
|
13
|
+
this._id = config.id || config.name.toLowerCase();
|
|
13
14
|
this._name = config.name;
|
|
14
15
|
this._protected = config.protected || false;
|
|
15
16
|
this._mandatory = config.mandatory || false;
|
|
16
17
|
this._defaultValue = config.defaultValue;
|
|
17
18
|
this._value = config.defaultValue;
|
|
19
|
+
this._hasChanged = false;
|
|
18
20
|
this._htmlType = config.htmlType || 'off';
|
|
19
21
|
if (typeof config.onChange === 'function') {
|
|
20
22
|
this._events.onChange = config.onChange;
|
|
@@ -38,21 +40,31 @@ class BaseProperty {
|
|
|
38
40
|
get htmlType() {
|
|
39
41
|
return this._htmlType;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
get hasChanged() {
|
|
44
|
+
return this._hasChanged;
|
|
45
|
+
}
|
|
46
|
+
set(value, setChanged = true) {
|
|
42
47
|
if (this._value !== undefined &&
|
|
43
48
|
this._value !== null &&
|
|
44
49
|
this._value !== this._defaultValue &&
|
|
45
50
|
this._protected === true) {
|
|
46
51
|
throw new Error(`Value '${this._name}' already defined as '${this._value}' and protected from change`);
|
|
47
52
|
}
|
|
48
|
-
this._value
|
|
53
|
+
if (value !== this._value) {
|
|
54
|
+
// console.log(this.name, value, this._value)
|
|
55
|
+
this._value = value;
|
|
56
|
+
this._hasChanged = setChanged;
|
|
57
|
+
}
|
|
49
58
|
if (this._events[BaseProperty.EVENT_ONCHANGE]) {
|
|
50
59
|
this._events[BaseProperty.EVENT_ONCHANGE](this._parent);
|
|
51
60
|
}
|
|
52
61
|
return this;
|
|
53
62
|
}
|
|
54
63
|
val(transform = undefined) {
|
|
55
|
-
|
|
64
|
+
// console.log(transform && transform(this._value), typeof transform);
|
|
65
|
+
return typeof transform === 'function'
|
|
66
|
+
? transform(this._value)
|
|
67
|
+
: this._value || this._defaultValue;
|
|
56
68
|
}
|
|
57
69
|
_enable(value) {
|
|
58
70
|
return value === undefined || value === true;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BooleanProperty = void 0;
|
|
4
4
|
const BaseProperty_1 = require("./BaseProperty");
|
|
5
5
|
class BooleanProperty extends BaseProperty_1.BaseProperty {
|
|
6
|
-
set(value) {
|
|
7
|
-
return super.set(value);
|
|
6
|
+
set(value, setChanged = true) {
|
|
7
|
+
return super.set(value, setChanged);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.BooleanProperty = BooleanProperty;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
2
|
-
import { Query } from '../backends/Query';
|
|
2
|
+
import { Query, QueryResultType } from '../backends/Query';
|
|
3
3
|
import { Filter } from '../backends/Filter';
|
|
4
4
|
import { ObjectUri } from '../components/ObjectUri';
|
|
5
5
|
import { returnAs } from '../backends/Query';
|
|
@@ -20,7 +20,7 @@ export declare class CollectionProperty extends BaseProperty {
|
|
|
20
20
|
protected _filters: Filter[] | Filter | undefined;
|
|
21
21
|
constructor(config: CollectionPropertyType);
|
|
22
22
|
protected _setQuery(filters?: Filter[]): Query<typeof BaseObjectCore>;
|
|
23
|
-
set(value: Array<any
|
|
23
|
+
set(value: Array<any>, setChanged?: boolean): this;
|
|
24
24
|
/**
|
|
25
25
|
* get objects matching collection class and filters
|
|
26
26
|
* in the requested format
|
|
@@ -28,6 +28,6 @@ export declare class CollectionProperty extends BaseProperty {
|
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
30
|
get(filters?: Filter[] | undefined): Query<any>;
|
|
31
|
-
val(transform?: returnAs): Promise<
|
|
31
|
+
val(transform?: returnAs): Promise<QueryResultType<any>>;
|
|
32
32
|
toJSON(): any[] | DataObjectClass<any>[] | ObjectUri[] | undefined;
|
|
33
33
|
}
|
|
@@ -19,8 +19,9 @@ class CollectionProperty extends BaseProperty_1.BaseProperty {
|
|
|
19
19
|
super(config);
|
|
20
20
|
this._value = undefined;
|
|
21
21
|
this._filters = undefined;
|
|
22
|
+
// console.log(config)
|
|
22
23
|
if (!config.instanceOf) {
|
|
23
|
-
throw new Error(
|
|
24
|
+
throw new Error(`Parameter 'instanceOf' is mandatory`);
|
|
24
25
|
}
|
|
25
26
|
this._instanceOf =
|
|
26
27
|
typeof config.instanceOf === 'string'
|
|
@@ -41,8 +42,8 @@ class CollectionProperty extends BaseProperty_1.BaseProperty {
|
|
|
41
42
|
}
|
|
42
43
|
return query;
|
|
43
44
|
}
|
|
44
|
-
set(value) {
|
|
45
|
-
return super.set(value);
|
|
45
|
+
set(value, setChanged = true) {
|
|
46
|
+
return super.set(value, setChanged);
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* get objects matching collection class and filters
|
|
@@ -6,6 +6,6 @@ export declare class DateTimeProperty extends BaseProperty {
|
|
|
6
6
|
static TYPE: string;
|
|
7
7
|
protected _timezone: string;
|
|
8
8
|
constructor(config: DateTimePropertyType);
|
|
9
|
-
set(value: string | Date): this;
|
|
9
|
+
set(value: string | Date, setChanged?: boolean): this;
|
|
10
10
|
get timezone(): string;
|
|
11
11
|
}
|
|
@@ -7,8 +7,8 @@ class DateTimeProperty extends BaseProperty_1.BaseProperty {
|
|
|
7
7
|
super(config);
|
|
8
8
|
this._timezone = config.timezone || 'Z';
|
|
9
9
|
}
|
|
10
|
-
set(value) {
|
|
11
|
-
return super.set(value);
|
|
10
|
+
set(value, setChanged = true) {
|
|
11
|
+
return super.set(value, setChanged);
|
|
12
12
|
}
|
|
13
13
|
get timezone() {
|
|
14
14
|
return this._timezone;
|
|
@@ -8,11 +8,11 @@ class EnumProperty extends BaseProperty_1.BaseProperty {
|
|
|
8
8
|
this._values = [];
|
|
9
9
|
this._values = config.values || [];
|
|
10
10
|
}
|
|
11
|
-
set(value) {
|
|
11
|
+
set(value, setChanged = true) {
|
|
12
12
|
if (value !== null && !this._values.includes(value)) {
|
|
13
13
|
throw new Error(`Value '${value}' is not acceptable`);
|
|
14
14
|
}
|
|
15
|
-
return super.set(value);
|
|
15
|
+
return super.set(value, setChanged);
|
|
16
16
|
}
|
|
17
17
|
get values() {
|
|
18
18
|
return this._values;
|
|
@@ -16,6 +16,12 @@ export declare class HashProperty extends StringProperty {
|
|
|
16
16
|
protected _prefixed: boolean;
|
|
17
17
|
constructor(config: HashPropertyType);
|
|
18
18
|
_hash(value: string): string;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Never return the password which is hashed anyway
|
|
21
|
+
* @param transform
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
get(transform?: string | undefined): string | undefined;
|
|
25
|
+
set(value: string, setChanged?: boolean): this;
|
|
20
26
|
compare(value: string): boolean;
|
|
21
27
|
}
|
|
@@ -34,8 +34,16 @@ class HashProperty extends StringProperty_1.StringProperty {
|
|
|
34
34
|
this._rawValue = false; // don't test some constraints after hashing
|
|
35
35
|
return hash;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Never return the password which is hashed anyway
|
|
39
|
+
* @param transform
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
get(transform) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
set(value, setChanged = true) {
|
|
46
|
+
return super.set(this._hash(value), setChanged);
|
|
39
47
|
}
|
|
40
48
|
compare(value) {
|
|
41
49
|
return this._hash(value) === this._value;
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MapProperty = void 0;
|
|
4
4
|
const BaseProperty_1 = require("./BaseProperty");
|
|
5
5
|
class MapProperty extends BaseProperty_1.BaseProperty {
|
|
6
|
-
set(value) {
|
|
6
|
+
set(value, setChanged = true) {
|
|
7
7
|
if (typeof value !== 'object') {
|
|
8
8
|
throw new Error(`value ${JSON.stringify(value)} is not an object`);
|
|
9
9
|
}
|
|
10
|
-
return super.set(value);
|
|
10
|
+
return super.set(value, setChanged);
|
|
11
11
|
}
|
|
12
12
|
toJSON() {
|
|
13
13
|
return this._value ? JSON.stringify(this._value) : {};
|
|
@@ -27,7 +27,7 @@ export declare class NumberProperty extends BaseProperty {
|
|
|
27
27
|
protected _precision: number;
|
|
28
28
|
protected _value: number | undefined;
|
|
29
29
|
constructor(config: NumberPropertyType);
|
|
30
|
-
set(value: number): this;
|
|
30
|
+
set(value: number, setChanged?: boolean): this;
|
|
31
31
|
val(transform?: string | undefined): string | number | undefined;
|
|
32
32
|
set minVal(min: number | undefined);
|
|
33
33
|
get minVal(): number | undefined;
|
|
@@ -27,7 +27,7 @@ class NumberProperty extends BaseProperty_1.BaseProperty {
|
|
|
27
27
|
this._sign = config.sign;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
set(value) {
|
|
30
|
+
set(value, setChanged = true) {
|
|
31
31
|
if (this._sign === NumberProperty.TYPE_UNSIGNED && value < 0) {
|
|
32
32
|
throw new Error(`Value must be unsigned`);
|
|
33
33
|
}
|
|
@@ -40,7 +40,7 @@ class NumberProperty extends BaseProperty_1.BaseProperty {
|
|
|
40
40
|
if (this._type === NumberProperty.TYPE_INTEGER) {
|
|
41
41
|
value = Math.floor(value);
|
|
42
42
|
}
|
|
43
|
-
return super.set(value);
|
|
43
|
+
return super.set(value, setChanged);
|
|
44
44
|
}
|
|
45
45
|
val(transform = undefined) {
|
|
46
46
|
switch (transform) {
|
|
@@ -10,6 +10,6 @@ export declare class ObjectProperty extends BaseProperty {
|
|
|
10
10
|
_instanceOf: any;
|
|
11
11
|
constructor(config: ObjectPropertyType);
|
|
12
12
|
val(transform?: string | undefined): any;
|
|
13
|
-
set(value: object): this;
|
|
13
|
+
set(value: object, setChanged?: boolean): this;
|
|
14
14
|
toJSON(): any;
|
|
15
15
|
}
|
|
@@ -14,7 +14,7 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
14
14
|
}
|
|
15
15
|
val(transform = undefined) {
|
|
16
16
|
if (typeof this._instanceOf === 'string') {
|
|
17
|
-
console.log(`Getting instance from string ${this._instanceOf}`)
|
|
17
|
+
//console.log(`Getting instance from string ${this._instanceOf}`)
|
|
18
18
|
this._instanceOf = Core_1.Core.getClass(this._instanceOf);
|
|
19
19
|
//throw new Error(`Parameter 'instanceOf' was not properly setted`)
|
|
20
20
|
}
|
|
@@ -44,9 +44,9 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
44
44
|
return Reflect.construct(this._instanceOf, [this._value]);
|
|
45
45
|
}
|
|
46
46
|
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
47
|
-
console.log('ObjectProperty', this)
|
|
47
|
+
// console.log('ObjectProperty', this)
|
|
48
48
|
console.log(`Converting objectUri -> dataObject -> instance`);
|
|
49
|
-
console.log(this._instanceOf)
|
|
49
|
+
// console.log(this._instanceOf)
|
|
50
50
|
const dao = DataObject_1.DataObject.factory({
|
|
51
51
|
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
52
52
|
uri: this._value,
|
|
@@ -57,19 +57,18 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
57
57
|
console.log(`Returning already existing instance`);
|
|
58
58
|
return this._value;
|
|
59
59
|
}
|
|
60
|
-
return this._value;
|
|
61
60
|
case Query_1.returnAs.AS_OBJECTURIS:
|
|
62
61
|
default:
|
|
63
62
|
return this._value;
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
|
-
set(value) {
|
|
65
|
+
set(value, setChanged = true) {
|
|
67
66
|
if (value instanceof ObjectUri_1.ObjectUri &&
|
|
68
67
|
value instanceof DataObject_1.DataObject &&
|
|
69
68
|
value.constructor.name !== this._instanceOf.constructor.name) {
|
|
70
69
|
throw new Error(`value ${JSON.stringify(value)} is not an instance of ${this._instanceOf.constructor.name}`);
|
|
71
70
|
}
|
|
72
|
-
return super.set(value);
|
|
71
|
+
return super.set(value, setChanged);
|
|
73
72
|
}
|
|
74
73
|
toJSON() {
|
|
75
74
|
if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
@@ -26,7 +26,7 @@ export declare class StringProperty extends BaseProperty {
|
|
|
26
26
|
*/
|
|
27
27
|
protected _rawValue: boolean;
|
|
28
28
|
constructor(config: StringPropertyType);
|
|
29
|
-
set(value: any): this;
|
|
29
|
+
set(value: any, setChanged?: boolean): this;
|
|
30
30
|
get(transform?: string | undefined): string | undefined;
|
|
31
31
|
set minLength(min: number);
|
|
32
32
|
get minLength(): number;
|
|
@@ -27,7 +27,7 @@ class StringProperty extends BaseProperty_1.BaseProperty {
|
|
|
27
27
|
this._allows.push(StringProperty.ALLOW_LETTERS);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
set(value) {
|
|
30
|
+
set(value, setChanged = true) {
|
|
31
31
|
if (value !== null && value !== undefined) {
|
|
32
32
|
if (this._allows.includes(StringProperty.ALLOW_DIGITS) === false &&
|
|
33
33
|
/\d/.test(value)) {
|
|
@@ -52,7 +52,7 @@ class StringProperty extends BaseProperty_1.BaseProperty {
|
|
|
52
52
|
throw new Error(`${this._name}: value '${value}' is too long`);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
return super.set(value);
|
|
55
|
+
return super.set(value, setChanged);
|
|
56
56
|
}
|
|
57
57
|
get(transform = undefined) {
|
|
58
58
|
switch (transform) {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { AbstractPropertyType } from './AbstractPropertyType';
|
|
2
2
|
export interface PropertyClassType {
|
|
3
|
-
|
|
3
|
+
id?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
set(value: any, setCahnged?: boolean): AbstractPropertyType;
|
|
4
6
|
val(transform?: any): any;
|
|
5
7
|
toJSON(): any;
|
|
6
8
|
clone(): PropertyClassType;
|
|
9
|
+
hasChanged?: boolean;
|
|
7
10
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Proxy } from '../components/types/ProxyConstructor';
|
|
1
|
+
import { AbstractObject } from '../components';
|
|
3
2
|
/**
|
|
4
3
|
* Generate data from model of object and save it in default backend
|
|
5
4
|
* @param model
|
|
@@ -7,4 +6,4 @@ import { Proxy } from '../components/types/ProxyConstructor';
|
|
|
7
6
|
* @param forcedValues
|
|
8
7
|
* @returns
|
|
9
8
|
*/
|
|
10
|
-
export declare const DataGenerator: <T extends
|
|
9
|
+
export declare const DataGenerator: <T extends AbstractObject>(model: T, qty?: number, forcedValues?: any) => Promise<any>;
|
|
@@ -47,8 +47,9 @@ const DataGenerator = (model, qty = 5, forcedValues = {}) => __awaiter(void 0, v
|
|
|
47
47
|
const promises = [];
|
|
48
48
|
Core_1.Core.log(`Starting to create ${qty} ${model.constructor.name} records`);
|
|
49
49
|
for (let i = 0; i < qty; i++) {
|
|
50
|
-
const dao = yield model.
|
|
50
|
+
const dao = yield model.dataObject.clone();
|
|
51
51
|
Object.keys(dao.properties).forEach((key) => {
|
|
52
|
+
console.log(`Getting property for '${key}'`);
|
|
52
53
|
const property = dao.get(key);
|
|
53
54
|
if (forcedValues[key]) {
|
|
54
55
|
property.set(forcedValues[key]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/core",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta10",
|
|
4
4
|
"description": "Core objects for business apps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"push": "yarn publish --access public",
|
|
31
31
|
"prepublish": "tsc"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
package/README.md
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# Quatrain Core
|
|
2
|
-
|
|
3
|
-
## Why
|
|
4
|
-
|
|
5
|
-
Quatrain Core is an abstraction layer designed to accelerate and simplify the development
|
|
6
|
-
of applications using many models and various data stores, being database or APIs.
|
|
7
|
-
|
|
8
|
-
With Quatrain Core and peer packages, one may develop robust applications based on
|
|
9
|
-
Oriented Object Programming with a clear separation of concerns between logic, data
|
|
10
|
-
and storage.
|
|
11
|
-
|
|
12
|
-
## How to install
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
yarn install @quatrain/core
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Quatrain Core comes with a built-in Mock backend adapter. Other adapters are available in
|
|
19
|
-
different packages. For example, a Google Firestore adapter is available:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn install @quatrain/backend-firestore
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## How to use
|
|
26
|
-
|
|
27
|
-
### Setup
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import { Core } from '@quatrain/core'
|
|
31
|
-
|
|
32
|
-
Core.addBackend(myAdapter, 'myDB', true)
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Create a model
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { BaseObjectCore } from '@quatrain/core'
|
|
39
|
-
|
|
40
|
-
export type Cat = {
|
|
41
|
-
name: string
|
|
42
|
-
color: `#${string}`
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export class CatCore extends BaseObjectCore {
|
|
46
|
-
static COLLECTION = 'cats'
|
|
47
|
-
|
|
48
|
-
static PROPERTIES = [
|
|
49
|
-
{
|
|
50
|
-
name: 'name',
|
|
51
|
-
type: Property.STRING,
|
|
52
|
-
minLength: 1,
|
|
53
|
-
maxLength: 32,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'color',
|
|
57
|
-
type: Property.STRING,
|
|
58
|
-
minLength: 4,
|
|
59
|
-
maxLength: 7,
|
|
60
|
-
},
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Instantiate a model
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
const catData: Cat = {
|
|
69
|
-
name: 'Garfield',
|
|
70
|
-
color: '#ffa502',
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const garfield = CatCore.fromObject(catData)
|
|
74
|
-
|
|
75
|
-
console.log(garfield.name)
|
|
76
|
-
// > "Garfield"
|
|
77
|
-
console.log(garfield.color)
|
|
78
|
-
// > "#ffa502"
|
|
79
|
-
console.log(garfield.core)
|
|
80
|
-
// > CatCore { ... }
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Interact with backend
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
// Let's save Garfield in our database
|
|
87
|
-
garfield.core.save()
|
|
88
|
-
|
|
89
|
-
// Now, let's retrieve Garfield in the database
|
|
90
|
-
const persistedGarfield = await CatCore.fromBackend('garfield')
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Using repositories
|
|
94
|
-
|
|
95
|
-
You can use repositories as an alternative way to persist and retrieve models in your backend.
|
|
96
|
-
|
|
97
|
-
This module provides a BaseRepository class that you can extend and override to apply your business logic when doing backend operations.
|
|
98
|
-
|
|
99
|
-
Let's create a repository for our Cat model, that prevents us from deleting a cat.
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import { Core, BackendInterface, BaseRepository } from '@quatrain/core'
|
|
103
|
-
|
|
104
|
-
export default class CatRepository extends BaseRepository<Cat> {
|
|
105
|
-
constructor(backendAdapter: BackendInterface = Core.getBackend()) {
|
|
106
|
-
super(CatCore, backendAdapter)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async delete(uid: string) {
|
|
110
|
-
throw Error("Don't delete the cats!")
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Now, let's use our new CatRepository.
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
const repository = new CatRepository()
|
|
119
|
-
|
|
120
|
-
repository.create(garfield)
|
|
121
|
-
repository.read('garfield')
|
|
122
|
-
repository.update(persistedGarfield)
|
|
123
|
-
repository.delete('garfield') // Will throw "Don't delete the cats!"
|
|
124
|
-
```
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UserClass } from './types/UserClass';
|
|
2
|
-
import { ObjectUri } from './ObjectUri';
|
|
3
|
-
export interface BaseObjectType {
|
|
4
|
-
name: string;
|
|
5
|
-
status: string;
|
|
6
|
-
createdBy?: UserClass | ObjectUri;
|
|
7
|
-
createdAt?: number;
|
|
8
|
-
updatedBy?: UserClass | ObjectUri;
|
|
9
|
-
updatedAt?: number;
|
|
10
|
-
deletedBy?: UserClass | ObjectUri;
|
|
11
|
-
deletedAt?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare const BaseObjectProperties: any;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.BaseObjectProperties = void 0;
|
|
27
|
-
const statuses = __importStar(require("../statuses"));
|
|
28
|
-
const StringProperty_1 = require("../properties/StringProperty");
|
|
29
|
-
const ObjectProperty_1 = require("../properties/ObjectProperty");
|
|
30
|
-
const EnumProperty_1 = require("../properties/EnumProperty");
|
|
31
|
-
const DateTimeProperty_1 = require("../properties/DateTimeProperty");
|
|
32
|
-
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
33
|
-
exports.BaseObjectProperties = [
|
|
34
|
-
{
|
|
35
|
-
name: 'name',
|
|
36
|
-
mandatory: true,
|
|
37
|
-
type: StringProperty_1.StringProperty.TYPE,
|
|
38
|
-
minLength: 1,
|
|
39
|
-
maxLength: 100,
|
|
40
|
-
htmlType: htmlType.NAME,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'status',
|
|
44
|
-
mandatory: true,
|
|
45
|
-
type: EnumProperty_1.EnumProperty.TYPE,
|
|
46
|
-
values: [
|
|
47
|
-
statuses.CREATED,
|
|
48
|
-
statuses.PENDING,
|
|
49
|
-
statuses.ACTIVE,
|
|
50
|
-
statuses.DELETED,
|
|
51
|
-
],
|
|
52
|
-
defaultValue: statuses.CREATED,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: 'createdBy',
|
|
56
|
-
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
57
|
-
instanceOf: 'User',
|
|
58
|
-
mandatory: true,
|
|
59
|
-
protected: true,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'createdAt',
|
|
63
|
-
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
64
|
-
mandatory: true,
|
|
65
|
-
protected: true,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'updatedBy',
|
|
69
|
-
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
70
|
-
instanceOf: 'User',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: 'updatedAt',
|
|
74
|
-
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: 'deletedBy',
|
|
78
|
-
type: ObjectProperty_1.ObjectProperty.TYPE,
|
|
79
|
-
instanceOf: 'User',
|
|
80
|
-
protected: true,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: 'deletedAt',
|
|
84
|
-
type: DateTimeProperty_1.DateTimeProperty.TYPE,
|
|
85
|
-
protected: true,
|
|
86
|
-
},
|
|
87
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const EntityProperties: any;
|