@quatrain/core 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Backend.d.ts +5 -0
- package/lib/Backend.js +7 -0
- package/lib/Core.d.ts +23 -3
- package/lib/Core.js +24 -5
- package/lib/backends/AbstractAdapter.d.ts +29 -13
- package/lib/backends/AbstractAdapter.js +31 -3
- package/lib/backends/Filter.d.ts +5 -3
- package/lib/backends/Filter.js +1 -1
- package/lib/backends/MockAdapter.d.ts +11 -12
- package/lib/backends/MockAdapter.js +126 -35
- package/lib/backends/NotFoundError.d.ts +2 -0
- package/lib/backends/NotFoundError.js +6 -0
- package/lib/backends/Query.d.ts +11 -3
- package/lib/backends/Query.js +30 -4
- package/lib/backends/middlewares/AbstractMiddleware.d.ts +0 -0
- package/lib/backends/middlewares/AbstractMiddleware.js +1 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.d.ts +11 -0
- package/lib/backends/middlewares/InjectMetaMiddleware.js +50 -0
- package/lib/components/AbstractObject.d.ts +13 -10
- package/lib/components/AbstractObject.js +11 -2
- package/lib/components/BaseObject.d.ts +10 -11
- package/lib/components/BaseObject.js +42 -33
- package/lib/components/BaseObjectProperties.d.ts +6 -8
- package/lib/components/BaseObjectProperties.js +14 -9
- package/lib/components/DataObject.d.ts +25 -18
- package/lib/components/DataObject.js +63 -33
- package/lib/components/Entity.d.ts +6 -0
- package/lib/components/Entity.js +26 -0
- package/lib/components/EntityProperties.d.ts +1 -0
- package/lib/components/EntityProperties.js +47 -0
- package/lib/components/ObjectUri.d.ts +5 -2
- package/lib/components/ObjectUri.js +23 -8
- package/lib/components/User.d.ts +6 -4
- package/lib/components/User.js +78 -8
- package/lib/components/UserProperties.d.ts +1 -0
- package/lib/components/UserProperties.js +103 -0
- package/lib/components/index.d.ts +6 -3
- package/lib/components/index.js +5 -2
- package/lib/components/types/AbstractObjectClass.d.ts +6 -0
- package/lib/components/types/AbstractObjectClass.js +2 -0
- package/lib/components/types/BaseObjectClass.d.ts +6 -0
- package/lib/components/types/BaseObjectClass.js +2 -0
- package/lib/components/types/DataObjectClass.d.ts +23 -0
- package/lib/components/types/DataObjectClass.js +2 -0
- package/lib/components/types/EntityClass.d.ts +3 -0
- package/lib/components/types/EntityClass.js +2 -0
- package/lib/components/types/UserClass.d.ts +3 -0
- package/lib/components/types/UserClass.js +2 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +7 -1
- package/lib/properties/ArrayProperty.d.ts +1 -0
- package/lib/properties/ArrayProperty.js +6 -5
- package/lib/properties/BaseProperty.d.ts +10 -4
- package/lib/properties/BaseProperty.js +11 -1
- package/lib/properties/BooleanProperty.d.ts +2 -1
- package/lib/properties/BooleanProperty.js +3 -2
- package/lib/properties/CollectionProperty.d.ts +32 -0
- package/lib/properties/CollectionProperty.js +63 -0
- package/lib/properties/DateTimeProperty.d.ts +1 -0
- package/lib/properties/DateTimeProperty.js +1 -0
- package/lib/properties/EnumProperty.d.ts +2 -0
- package/lib/properties/EnumProperty.js +5 -1
- package/lib/properties/HashProperty.d.ts +1 -0
- package/lib/properties/HashProperty.js +1 -0
- package/lib/properties/MapProperty.d.ts +8 -0
- package/lib/properties/MapProperty.js +17 -0
- package/lib/properties/NumberProperty.d.ts +1 -0
- package/lib/properties/NumberProperty.js +1 -0
- package/lib/properties/ObjectProperty.d.ts +4 -7
- package/lib/properties/ObjectProperty.js +4 -1
- package/lib/properties/Property.d.ts +3 -7
- package/lib/properties/Property.js +13 -15
- package/lib/properties/StringProperty.d.ts +10 -0
- package/lib/properties/StringProperty.js +42 -21
- package/lib/properties/index.d.ts +4 -2
- package/lib/properties/index.js +5 -1
- package/lib/properties/types/PropertyClassType.d.ts +4 -2
- package/lib/properties/types/PropertyHTMLType.d.ts +10 -0
- package/lib/properties/types/PropertyHTMLType.js +14 -0
- package/lib/properties/types/PropertyTypes.d.ts +4 -1
- package/lib/utils/DataGenerator.d.ts +9 -0
- package/lib/utils/DataGenerator.js +98 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +5 -0
- package/package.json +3 -1
|
@@ -7,6 +7,7 @@ class BaseProperty {
|
|
|
7
7
|
this._mandatory = false;
|
|
8
8
|
this._protected = false;
|
|
9
9
|
this._allows = [];
|
|
10
|
+
this._htmlType = 'off';
|
|
10
11
|
this._events = {};
|
|
11
12
|
this._parent = config.parent;
|
|
12
13
|
this._name = config.name;
|
|
@@ -14,6 +15,7 @@ class BaseProperty {
|
|
|
14
15
|
this._mandatory = config.mandatory || false;
|
|
15
16
|
this._defaultValue = config.defaultValue;
|
|
16
17
|
this._value = config.defaultValue;
|
|
18
|
+
this._htmlType = config.htmlType || 'off';
|
|
17
19
|
if (typeof config.onChange === 'function') {
|
|
18
20
|
this._events.onChange = config.onChange;
|
|
19
21
|
}
|
|
@@ -30,8 +32,15 @@ class BaseProperty {
|
|
|
30
32
|
get allows() {
|
|
31
33
|
return this._allows;
|
|
32
34
|
}
|
|
35
|
+
set htmlType(type) {
|
|
36
|
+
this._htmlType = type;
|
|
37
|
+
}
|
|
38
|
+
get htmlType() {
|
|
39
|
+
return this._htmlType;
|
|
40
|
+
}
|
|
33
41
|
set(value) {
|
|
34
42
|
if (this._value !== undefined &&
|
|
43
|
+
this._value !== null &&
|
|
35
44
|
this._value !== this._defaultValue &&
|
|
36
45
|
this._protected === true) {
|
|
37
46
|
throw new Error(`Value already defined as '${this._value}' and protected from change`);
|
|
@@ -43,7 +52,7 @@ class BaseProperty {
|
|
|
43
52
|
return this;
|
|
44
53
|
}
|
|
45
54
|
val(transform = undefined) {
|
|
46
|
-
return this._value;
|
|
55
|
+
return transform ? transform(this._value) : this._value;
|
|
47
56
|
}
|
|
48
57
|
_enable(value) {
|
|
49
58
|
return value === undefined || value === true;
|
|
@@ -53,5 +62,6 @@ class BaseProperty {
|
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
exports.BaseProperty = BaseProperty;
|
|
65
|
+
BaseProperty.TYPE = 'any';
|
|
56
66
|
BaseProperty.EVENT_ONCHANGE = 'onChange';
|
|
57
67
|
BaseProperty.EVENT_ONDELETE = 'onDelete';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BaseProperty, BasePropertyType } from './';
|
|
1
|
+
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
2
2
|
export interface BooleanPropertyType extends BasePropertyType {
|
|
3
3
|
}
|
|
4
4
|
export declare class BooleanProperty extends BaseProperty {
|
|
5
|
+
static TYPE: string;
|
|
5
6
|
set(value: boolean): this;
|
|
6
7
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BooleanProperty = void 0;
|
|
4
|
-
const
|
|
5
|
-
class BooleanProperty extends
|
|
4
|
+
const BaseProperty_1 = require("./BaseProperty");
|
|
5
|
+
class BooleanProperty extends BaseProperty_1.BaseProperty {
|
|
6
6
|
set(value) {
|
|
7
7
|
return super.set(value);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.BooleanProperty = BooleanProperty;
|
|
11
|
+
BooleanProperty.TYPE = 'boolean';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
2
|
+
import { Query } from '../backends/Query';
|
|
3
|
+
import { Filter } from '../backends/Filter';
|
|
4
|
+
import { ObjectUri } from '../components/ObjectUri';
|
|
5
|
+
import { returnAs } from '../backends/Query';
|
|
6
|
+
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
7
|
+
export interface CollectionPropertyType extends BasePropertyType {
|
|
8
|
+
instanceOf?: Function | string | Object;
|
|
9
|
+
backend?: any;
|
|
10
|
+
parentKey?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class CollectionProperty extends BaseProperty {
|
|
13
|
+
static TYPE: string;
|
|
14
|
+
protected _value: Array<any> | Array<DataObjectClass<any>> | Array<ObjectUri> | undefined;
|
|
15
|
+
protected _instanceOf: any;
|
|
16
|
+
protected _backend: any;
|
|
17
|
+
protected _parentKey: string;
|
|
18
|
+
protected _query: Query<any>;
|
|
19
|
+
protected _filters: Filter[] | Filter | undefined;
|
|
20
|
+
constructor(config: CollectionPropertyType);
|
|
21
|
+
protected _setQuery(filters?: Filter[]): any;
|
|
22
|
+
set(value: Array<any>): this;
|
|
23
|
+
/**
|
|
24
|
+
* get objects matching collection class and filters
|
|
25
|
+
* in the requested format
|
|
26
|
+
* @param filters
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
get(filters?: Filter[] | undefined): Query<any>;
|
|
30
|
+
val(transform?: returnAs): Promise<Array<any> | Array<DataObjectClass<any>> | Array<ObjectUri>>;
|
|
31
|
+
toJSON(): any[] | DataObjectClass<any>[] | ObjectUri[] | undefined;
|
|
32
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CollectionProperty = void 0;
|
|
13
|
+
const BaseProperty_1 = require("./BaseProperty");
|
|
14
|
+
const Core_1 = require("../Core");
|
|
15
|
+
const Query_1 = require("../backends/Query");
|
|
16
|
+
class CollectionProperty extends BaseProperty_1.BaseProperty {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
super(config);
|
|
20
|
+
this._value = undefined;
|
|
21
|
+
this._filters = undefined;
|
|
22
|
+
this._instanceOf = config.instanceOf;
|
|
23
|
+
this._backend = config.backend
|
|
24
|
+
? Core_1.Core.getBackend(config.backend)
|
|
25
|
+
: undefined;
|
|
26
|
+
this._parentKey =
|
|
27
|
+
config.parentKey || ((_b = (_a = this._parent) === null || _a === void 0 ? void 0 : _a.uri) === null || _b === void 0 ? void 0 : _b.collection) || 'unknown';
|
|
28
|
+
this._query = this._setQuery();
|
|
29
|
+
}
|
|
30
|
+
_setQuery(filters) {
|
|
31
|
+
const query = this._instanceOf.query();
|
|
32
|
+
query.where(this._parentKey, this._parent ? this._parent.uri : 'unknown');
|
|
33
|
+
if (filters) {
|
|
34
|
+
query.filters = filters;
|
|
35
|
+
}
|
|
36
|
+
return query;
|
|
37
|
+
}
|
|
38
|
+
set(value) {
|
|
39
|
+
return super.set(value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* get objects matching collection class and filters
|
|
43
|
+
* in the requested format
|
|
44
|
+
* @param filters
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
get(filters = undefined) {
|
|
48
|
+
if (!this._query || this._filters !== filters) {
|
|
49
|
+
this._query = this._setQuery(filters);
|
|
50
|
+
}
|
|
51
|
+
return this._query;
|
|
52
|
+
}
|
|
53
|
+
val(transform = Query_1.returnAs.AS_DATAOBJECTS) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
return yield this.get().execute(transform, this._backend);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
toJSON() {
|
|
59
|
+
return this._value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.CollectionProperty = CollectionProperty;
|
|
63
|
+
CollectionProperty.TYPE = 'collection';
|
|
@@ -3,6 +3,7 @@ export interface DateTimePropertyType extends BasePropertyType {
|
|
|
3
3
|
timezone?: string;
|
|
4
4
|
}
|
|
5
5
|
export declare class DateTimeProperty extends BaseProperty {
|
|
6
|
+
static TYPE: string;
|
|
6
7
|
protected _timezone: string;
|
|
7
8
|
constructor(config: DateTimePropertyType);
|
|
8
9
|
set(value: string | Date): this;
|
|
@@ -3,7 +3,9 @@ export interface EnumPropertyType extends BasePropertyType {
|
|
|
3
3
|
values?: string[];
|
|
4
4
|
}
|
|
5
5
|
export declare class EnumProperty extends BaseProperty {
|
|
6
|
+
static TYPE: string;
|
|
6
7
|
protected _values: string[];
|
|
7
8
|
constructor(config: EnumPropertyType);
|
|
8
9
|
set(value: string): this;
|
|
10
|
+
get values(): string[];
|
|
9
11
|
}
|
|
@@ -9,10 +9,14 @@ class EnumProperty extends BaseProperty_1.BaseProperty {
|
|
|
9
9
|
this._values = config.values || [];
|
|
10
10
|
}
|
|
11
11
|
set(value) {
|
|
12
|
-
if (!this._values.includes(value)) {
|
|
12
|
+
if (value !== null && !this._values.includes(value)) {
|
|
13
13
|
throw new Error(`Value '${value}' is not acceptable`);
|
|
14
14
|
}
|
|
15
15
|
return super.set(value);
|
|
16
16
|
}
|
|
17
|
+
get values() {
|
|
18
|
+
return this._values;
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
exports.EnumProperty = EnumProperty;
|
|
22
|
+
EnumProperty.TYPE = 'enum';
|
|
@@ -6,6 +6,7 @@ export interface HashPropertyType extends StringPropertyType {
|
|
|
6
6
|
prefixed?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export declare class HashProperty extends StringProperty {
|
|
9
|
+
static TYPE: string;
|
|
9
10
|
static ALGORITHM_MD5: string;
|
|
10
11
|
static ALGORITHM_SHA1: string;
|
|
11
12
|
static ALGORITHM_SHA256: string;
|
|
@@ -42,6 +42,7 @@ class HashProperty extends StringProperty_1.StringProperty {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
exports.HashProperty = HashProperty;
|
|
45
|
+
HashProperty.TYPE = 'hash';
|
|
45
46
|
HashProperty.ALGORITHM_MD5 = 'md5';
|
|
46
47
|
HashProperty.ALGORITHM_SHA1 = 'sha1';
|
|
47
48
|
HashProperty.ALGORITHM_SHA256 = 'sha256';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapProperty = void 0;
|
|
4
|
+
const BaseProperty_1 = require("./BaseProperty");
|
|
5
|
+
class MapProperty extends BaseProperty_1.BaseProperty {
|
|
6
|
+
set(value) {
|
|
7
|
+
if (typeof value !== 'object') {
|
|
8
|
+
throw new Error(`value ${JSON.stringify(value)} is not an object`);
|
|
9
|
+
}
|
|
10
|
+
return super.set(value);
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return this._value ? JSON.stringify(this._value) : {};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.MapProperty = MapProperty;
|
|
17
|
+
MapProperty.TYPE = 'map';
|
|
@@ -11,6 +11,7 @@ export interface NumberPropertyType extends BasePropertyType {
|
|
|
11
11
|
precision?: number;
|
|
12
12
|
}
|
|
13
13
|
export declare class NumberProperty extends BaseProperty {
|
|
14
|
+
static TYPE: string;
|
|
14
15
|
static TYPE_SIGNED: string;
|
|
15
16
|
static TYPE_UNSIGNED: string;
|
|
16
17
|
static TYPE_INTEGER: string;
|
|
@@ -67,6 +67,7 @@ class NumberProperty extends BaseProperty_1.BaseProperty {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
exports.NumberProperty = NumberProperty;
|
|
70
|
+
NumberProperty.TYPE = 'number';
|
|
70
71
|
NumberProperty.TYPE_SIGNED = 'signed';
|
|
71
72
|
NumberProperty.TYPE_UNSIGNED = 'unsigned';
|
|
72
73
|
NumberProperty.TYPE_INTEGER = 'integer';
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseObjectClass } from '../components/types/BaseObjectClass';
|
|
2
2
|
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
3
3
|
export interface ObjectPropertyType extends BasePropertyType {
|
|
4
4
|
instanceOf?: Function | string | Object;
|
|
5
5
|
}
|
|
6
6
|
export declare class ObjectProperty extends BaseProperty {
|
|
7
|
-
|
|
7
|
+
static TYPE: string;
|
|
8
|
+
_value: BaseObjectClass | undefined;
|
|
8
9
|
_instanceOf: Function | string | Object;
|
|
9
10
|
constructor(config: ObjectPropertyType);
|
|
10
11
|
set(value: any): this;
|
|
11
|
-
toJSON():
|
|
12
|
-
label: any;
|
|
13
|
-
ref: string;
|
|
14
|
-
uri: string;
|
|
15
|
-
} | undefined;
|
|
12
|
+
toJSON(): any;
|
|
16
13
|
}
|
|
@@ -19,7 +19,10 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
19
19
|
return super.set(value);
|
|
20
20
|
}
|
|
21
21
|
toJSON() {
|
|
22
|
-
return this._value && this._value.dataObject
|
|
22
|
+
return this._value && this._value.dataObject
|
|
23
|
+
? this._value.dataObject.toReference()
|
|
24
|
+
: undefined;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
exports.ObjectProperty = ObjectProperty;
|
|
28
|
+
ObjectProperty.TYPE = 'object';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataObjectClass } from '../components/types/DataObjectClass';
|
|
2
2
|
import { BaseProperty, BasePropertyType } from './BaseProperty';
|
|
3
3
|
export declare class Property {
|
|
4
4
|
static TYPE_ANY: string;
|
|
@@ -9,10 +9,6 @@ export declare class Property {
|
|
|
9
9
|
static TYPE_BOOLEAN: string;
|
|
10
10
|
static TYPE_HASH: string;
|
|
11
11
|
static TYPE_DATETIME: string;
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static ALLOW_DIGITS: string;
|
|
15
|
-
static ALLOW_STRINGS: string;
|
|
16
|
-
static ALLOW_NUMBERS: string;
|
|
17
|
-
static factory<P extends BasePropertyType>(params: P, parent: DataObject): BaseProperty;
|
|
12
|
+
static TYPE_ARRAY: string;
|
|
13
|
+
static factory<P extends BasePropertyType>(params: P, parent: DataObjectClass<any>): BaseProperty;
|
|
18
14
|
}
|
|
@@ -6,30 +6,32 @@ const BooleanProperty_1 = require("./BooleanProperty");
|
|
|
6
6
|
const DateTimeProperty_1 = require("./DateTimeProperty");
|
|
7
7
|
const EnumProperty_1 = require("./EnumProperty");
|
|
8
8
|
const HashProperty_1 = require("./HashProperty");
|
|
9
|
-
const ObjectProperty_1 = require("./ObjectProperty");
|
|
10
9
|
const StringProperty_1 = require("./StringProperty");
|
|
11
10
|
const NumberProperty_1 = require("./NumberProperty");
|
|
11
|
+
const ObjectProperty_1 = require("./ObjectProperty");
|
|
12
|
+
const CollectionProperty_1 = require("./CollectionProperty");
|
|
12
13
|
class Property {
|
|
13
14
|
static factory(params, parent) {
|
|
14
15
|
params.parent = parent;
|
|
15
|
-
// console.log(`Creating ${params.type} property named ${params.name}`)
|
|
16
16
|
switch (params.type) {
|
|
17
|
-
case
|
|
17
|
+
case BaseProperty_1.BaseProperty.TYPE:
|
|
18
18
|
return new BaseProperty_1.BaseProperty(params);
|
|
19
|
-
case
|
|
19
|
+
case StringProperty_1.StringProperty.TYPE:
|
|
20
20
|
return new StringProperty_1.StringProperty(params);
|
|
21
|
-
case
|
|
21
|
+
case NumberProperty_1.NumberProperty.TYPE:
|
|
22
22
|
return new NumberProperty_1.NumberProperty(params);
|
|
23
|
-
case
|
|
23
|
+
case ObjectProperty_1.ObjectProperty.TYPE:
|
|
24
24
|
return new ObjectProperty_1.ObjectProperty(params);
|
|
25
|
-
case
|
|
25
|
+
case EnumProperty_1.EnumProperty.TYPE:
|
|
26
26
|
return new EnumProperty_1.EnumProperty(params);
|
|
27
|
-
case
|
|
27
|
+
case BooleanProperty_1.BooleanProperty.TYPE:
|
|
28
28
|
return new BooleanProperty_1.BooleanProperty(params);
|
|
29
|
-
case
|
|
29
|
+
case HashProperty_1.HashProperty.TYPE:
|
|
30
30
|
return new HashProperty_1.HashProperty(params);
|
|
31
|
-
case
|
|
31
|
+
case DateTimeProperty_1.DateTimeProperty.TYPE:
|
|
32
32
|
return new DateTimeProperty_1.DateTimeProperty(params);
|
|
33
|
+
case CollectionProperty_1.CollectionProperty.TYPE:
|
|
34
|
+
return new CollectionProperty_1.CollectionProperty(params);
|
|
33
35
|
default:
|
|
34
36
|
throw new Error(`Unknown property type ${params.type}`);
|
|
35
37
|
}
|
|
@@ -44,8 +46,4 @@ Property.TYPE_ENUM = 'enum';
|
|
|
44
46
|
Property.TYPE_BOOLEAN = 'boolean';
|
|
45
47
|
Property.TYPE_HASH = 'hash';
|
|
46
48
|
Property.TYPE_DATETIME = 'datetime';
|
|
47
|
-
Property.
|
|
48
|
-
Property.ALLOW_LETTERS = 'letters';
|
|
49
|
-
Property.ALLOW_DIGITS = 'digits';
|
|
50
|
-
Property.ALLOW_STRINGS = 'strings';
|
|
51
|
-
Property.ALLOW_NUMBERS = 'numbers';
|
|
49
|
+
Property.TYPE_ARRAY = 'array';
|
|
@@ -6,12 +6,20 @@ export interface StringPropertyType extends BasePropertyType {
|
|
|
6
6
|
allowDigits?: boolean;
|
|
7
7
|
allowLetters?: boolean;
|
|
8
8
|
allowPattern?: String;
|
|
9
|
+
fullSearch?: boolean;
|
|
9
10
|
}
|
|
10
11
|
export declare class StringProperty extends BaseProperty {
|
|
12
|
+
static TYPE: string;
|
|
11
13
|
static TRANSFORM_UCASE: string;
|
|
12
14
|
static TRANSFORM_LCASE: string;
|
|
15
|
+
static ALLOW_SPACES: string;
|
|
16
|
+
static ALLOW_LETTERS: string;
|
|
17
|
+
static ALLOW_DIGITS: string;
|
|
18
|
+
static ALLOW_STRINGS: string;
|
|
19
|
+
static ALLOW_NUMBERS: string;
|
|
13
20
|
protected _minLength: number;
|
|
14
21
|
protected _maxLength: number;
|
|
22
|
+
protected _fullSearch: boolean;
|
|
15
23
|
protected _value: string | undefined;
|
|
16
24
|
/**
|
|
17
25
|
* Set to false to bypass some rules
|
|
@@ -24,4 +32,6 @@ export declare class StringProperty extends BaseProperty {
|
|
|
24
32
|
get minLength(): number;
|
|
25
33
|
set maxLength(max: number);
|
|
26
34
|
get maxLength(): number;
|
|
35
|
+
set fullSearch(mode: boolean);
|
|
36
|
+
get fullSearch(): boolean;
|
|
27
37
|
}
|
|
@@ -1,47 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringProperty = void 0;
|
|
4
|
-
|
|
4
|
+
//import { Property } from './Property'
|
|
5
5
|
const BaseProperty_1 = require("./BaseProperty");
|
|
6
6
|
class StringProperty extends BaseProperty_1.BaseProperty {
|
|
7
7
|
constructor(config) {
|
|
8
8
|
super(config);
|
|
9
9
|
this._minLength = 0;
|
|
10
10
|
this._maxLength = 0;
|
|
11
|
+
this._fullSearch = false;
|
|
11
12
|
/**
|
|
12
13
|
* Set to false to bypass some rules
|
|
13
14
|
*/
|
|
14
15
|
this._rawValue = true;
|
|
15
16
|
this.minLength = config.minLength || 0;
|
|
16
17
|
this.maxLength = config.maxLength || 0;
|
|
18
|
+
this.fullSearch = config.fullSearch || false;
|
|
19
|
+
this._htmlType = config.htmlType || 'off';
|
|
17
20
|
if (this._enable(config.allowSpaces)) {
|
|
18
|
-
this._allows.push(
|
|
21
|
+
this._allows.push(StringProperty.ALLOW_SPACES);
|
|
19
22
|
}
|
|
20
23
|
if (this._enable(config.allowDigits)) {
|
|
21
|
-
this._allows.push(
|
|
24
|
+
this._allows.push(StringProperty.ALLOW_DIGITS);
|
|
22
25
|
}
|
|
23
26
|
if (this._enable(config.allowLetters)) {
|
|
24
|
-
this._allows.push(
|
|
27
|
+
this._allows.push(StringProperty.ALLOW_LETTERS);
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
set(value) {
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
if (value !== null && value !== undefined) {
|
|
32
|
+
if (this._allows.includes(StringProperty.ALLOW_DIGITS) === false &&
|
|
33
|
+
/\d/.test(value)) {
|
|
34
|
+
throw new Error(`Digits are not allowed in value`);
|
|
35
|
+
}
|
|
36
|
+
if (this._allows.includes(StringProperty.ALLOW_SPACES) === false &&
|
|
37
|
+
/\s/g.test(value)) {
|
|
38
|
+
throw new Error(`Spaces are not allowed in value`);
|
|
39
|
+
}
|
|
40
|
+
if (this._allows.includes(StringProperty.ALLOW_LETTERS) === false &&
|
|
41
|
+
/[a-zA-Z]/.test(value)) {
|
|
42
|
+
throw new Error(`Letters are not allowed in value`);
|
|
43
|
+
}
|
|
44
|
+
if (this._rawValue &&
|
|
45
|
+
this._minLength > 0 &&
|
|
46
|
+
value.length < this._minLength) {
|
|
47
|
+
throw new Error(`Value is too short`);
|
|
48
|
+
}
|
|
49
|
+
if (this._rawValue &&
|
|
50
|
+
this._maxLength > 0 &&
|
|
51
|
+
value.length > this._maxLength) {
|
|
52
|
+
throw new Error(`${this._name}: value '${value}' is too long`);
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
return super.set(value);
|
|
47
56
|
}
|
|
@@ -67,7 +76,19 @@ class StringProperty extends BaseProperty_1.BaseProperty {
|
|
|
67
76
|
get maxLength() {
|
|
68
77
|
return this._maxLength;
|
|
69
78
|
}
|
|
79
|
+
set fullSearch(mode) {
|
|
80
|
+
this._fullSearch = mode;
|
|
81
|
+
}
|
|
82
|
+
get fullSearch() {
|
|
83
|
+
return this._fullSearch;
|
|
84
|
+
}
|
|
70
85
|
}
|
|
71
86
|
exports.StringProperty = StringProperty;
|
|
87
|
+
StringProperty.TYPE = 'string';
|
|
72
88
|
StringProperty.TRANSFORM_UCASE = 'upper';
|
|
73
89
|
StringProperty.TRANSFORM_LCASE = 'lower';
|
|
90
|
+
StringProperty.ALLOW_SPACES = 'spaces';
|
|
91
|
+
StringProperty.ALLOW_LETTERS = 'letters';
|
|
92
|
+
StringProperty.ALLOW_DIGITS = 'digits';
|
|
93
|
+
StringProperty.ALLOW_STRINGS = 'strings';
|
|
94
|
+
StringProperty.ALLOW_NUMBERS = 'numbers';
|
|
@@ -8,9 +8,11 @@ import { EnumProperty, EnumPropertyType } from './EnumProperty';
|
|
|
8
8
|
import { BooleanProperty, BooleanPropertyType } from './BooleanProperty';
|
|
9
9
|
import { DateTimeProperty, DateTimePropertyType } from './DateTimeProperty';
|
|
10
10
|
import { ObjectProperty, ObjectPropertyType } from './ObjectProperty';
|
|
11
|
+
import { MapProperty, MapPropertyType } from './MapProperty';
|
|
12
|
+
import { CollectionProperty, CollectionPropertyType } from './CollectionProperty';
|
|
11
13
|
import { PropertyTypes } from './types/PropertyTypes';
|
|
12
|
-
export { Property, BaseProperty, BasePropertyType, ArrayProperty, ArrayPropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, };
|
|
14
|
+
export { Property, BaseProperty, BasePropertyType, ArrayProperty, ArrayPropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, MapProperty, MapPropertyType, CollectionProperty, CollectionPropertyType, };
|
|
13
15
|
declare type BaseType = {
|
|
14
16
|
type: PropertyTypes;
|
|
15
17
|
};
|
|
16
|
-
export declare type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimeProperty & BaseType))[];
|
|
18
|
+
export declare type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimeProperty & BaseType) | (ArrayPropertyType & BaseType) | (MapPropertyType & BaseType) | (CollectionPropertyType & BaseType))[];
|
package/lib/properties/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HashProperty = exports.StringProperty = exports.ObjectProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.NumberProperty = exports.ArrayProperty = exports.BaseProperty = exports.Property = void 0;
|
|
3
|
+
exports.CollectionProperty = exports.MapProperty = exports.HashProperty = exports.StringProperty = exports.ObjectProperty = exports.EnumProperty = exports.DateTimeProperty = exports.BooleanProperty = exports.NumberProperty = exports.ArrayProperty = exports.BaseProperty = exports.Property = void 0;
|
|
4
4
|
const Property_1 = require("./Property");
|
|
5
5
|
Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });
|
|
6
6
|
const BaseProperty_1 = require("./BaseProperty");
|
|
@@ -21,3 +21,7 @@ const DateTimeProperty_1 = require("./DateTimeProperty");
|
|
|
21
21
|
Object.defineProperty(exports, "DateTimeProperty", { enumerable: true, get: function () { return DateTimeProperty_1.DateTimeProperty; } });
|
|
22
22
|
const ObjectProperty_1 = require("./ObjectProperty");
|
|
23
23
|
Object.defineProperty(exports, "ObjectProperty", { enumerable: true, get: function () { return ObjectProperty_1.ObjectProperty; } });
|
|
24
|
+
const MapProperty_1 = require("./MapProperty");
|
|
25
|
+
Object.defineProperty(exports, "MapProperty", { enumerable: true, get: function () { return MapProperty_1.MapProperty; } });
|
|
26
|
+
const CollectionProperty_1 = require("./CollectionProperty");
|
|
27
|
+
Object.defineProperty(exports, "CollectionProperty", { enumerable: true, get: function () { return CollectionProperty_1.CollectionProperty; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const OFF = "off";
|
|
2
|
+
export declare const NAME = "name";
|
|
3
|
+
export declare const GIVEN_NAME = "given-name";
|
|
4
|
+
export declare const FAMILY_NAME = "family-name";
|
|
5
|
+
export declare const EMAIL = "email";
|
|
6
|
+
export declare const PASSWORD = "password";
|
|
7
|
+
export declare const BIRTHDAY = "bday";
|
|
8
|
+
export declare const GENDER = "sex";
|
|
9
|
+
export declare const ORG = "organization";
|
|
10
|
+
export declare type PropertyHTMLType = typeof OFF | typeof NAME | typeof GIVEN_NAME | typeof FAMILY_NAME | typeof EMAIL | typeof PASSWORD | typeof BIRTHDAY | typeof GENDER | typeof ORG;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
|
3
|
+
// @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ORG = exports.GENDER = exports.BIRTHDAY = exports.PASSWORD = exports.EMAIL = exports.FAMILY_NAME = exports.GIVEN_NAME = exports.NAME = exports.OFF = void 0;
|
|
6
|
+
exports.OFF = 'off';
|
|
7
|
+
exports.NAME = 'name';
|
|
8
|
+
exports.GIVEN_NAME = 'given-name';
|
|
9
|
+
exports.FAMILY_NAME = 'family-name';
|
|
10
|
+
exports.EMAIL = 'email';
|
|
11
|
+
exports.PASSWORD = 'password';
|
|
12
|
+
exports.BIRTHDAY = 'bday';
|
|
13
|
+
exports.GENDER = 'sex';
|
|
14
|
+
exports.ORG = 'organization';
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Property } from '..';
|
|
2
|
-
export declare type PropertyTypes = typeof Property.TYPE_STRING | typeof Property.TYPE_NUMBER | typeof Property.TYPE_ENUM | typeof Property.TYPE_BOOLEAN | typeof Property.TYPE_OBJECT | typeof Property.TYPE_DATETIME | typeof Property.TYPE_HASH;
|
|
2
|
+
export declare type PropertyTypes = typeof Property.TYPE_STRING | typeof Property.TYPE_NUMBER | typeof Property.TYPE_ENUM | typeof Property.TYPE_BOOLEAN | typeof Property.TYPE_OBJECT | typeof Property.TYPE_DATETIME | typeof Property.TYPE_HASH | typeof Property.TYPE_ARRAY;
|
|
3
|
+
export declare type BaseType = {
|
|
4
|
+
type: PropertyTypes;
|
|
5
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseObject } from '../components';
|
|
2
|
+
/**
|
|
3
|
+
* Generate data from model of object and save it in default backend
|
|
4
|
+
* @param model
|
|
5
|
+
* @param qty
|
|
6
|
+
* @param forcedValues
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const DataGenerator: <T extends BaseObject>(model: T, qty?: number, forcedValues?: any) => Promise<any>;
|