@quatrain/core 1.2.5 → 1.2.6
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/dist/Core.d.ts.map +1 -1
- package/dist/Core.js.map +1 -1
- package/dist/common/ResourcesErrors.d.ts.map +1 -1
- package/dist/common/ResourcesErrors.js.map +1 -1
- package/dist/components/AbstractObject.d.ts.map +1 -1
- package/dist/components/AbstractObject.js.map +1 -1
- package/dist/components/BaseObject.d.ts.map +1 -1
- package/dist/components/BaseObject.js.map +1 -1
- package/dist/components/DataObject.d.ts.map +1 -1
- package/dist/components/DataObject.js.map +1 -1
- package/dist/components/Entity.d.ts.map +1 -1
- package/dist/components/Entity.js.map +1 -1
- package/dist/components/ObjectUri.d.ts.map +1 -1
- package/dist/components/ObjectUri.js.map +1 -1
- package/dist/components/User.d.ts.map +1 -1
- package/dist/components/User.js.map +1 -1
- package/dist/properties/ArrayProperty.d.ts.map +1 -1
- package/dist/properties/ArrayProperty.js.map +1 -1
- package/dist/properties/BaseProperty.d.ts.map +1 -1
- package/dist/properties/BaseProperty.js.map +1 -1
- package/dist/properties/BooleanProperty.d.ts.map +1 -1
- package/dist/properties/BooleanProperty.js.map +1 -1
- package/dist/properties/CollectionProperty.d.ts.map +1 -1
- package/dist/properties/CollectionProperty.js.map +1 -1
- package/dist/properties/DateTimeProperty.d.ts.map +1 -1
- package/dist/properties/DateTimeProperty.js.map +1 -1
- package/dist/properties/EnumProperty.d.ts.map +1 -1
- package/dist/properties/EnumProperty.js.map +1 -1
- package/dist/properties/FileProperty.d.ts.map +1 -1
- package/dist/properties/FileProperty.js.map +1 -1
- package/dist/properties/HashProperty.d.ts.map +1 -1
- package/dist/properties/HashProperty.js +3 -0
- package/dist/properties/HashProperty.js.map +1 -1
- package/dist/properties/MapProperty.d.ts.map +1 -1
- package/dist/properties/MapProperty.js.map +1 -1
- package/dist/properties/NumberProperty.d.ts.map +1 -1
- package/dist/properties/NumberProperty.js.map +1 -1
- package/dist/properties/ObjectProperty.d.ts.map +1 -1
- package/dist/properties/ObjectProperty.js.map +1 -1
- package/dist/properties/Property.d.ts.map +1 -1
- package/dist/properties/Property.js.map +1 -1
- package/dist/properties/StringProperty.d.ts.map +1 -1
- package/dist/properties/StringProperty.js.map +1 -1
- package/package.json +2 -2
- package/src/Core.ts +96 -0
- package/src/common/ResourcesErrors.ts +12 -0
- package/src/components/AbstractObject.ts +33 -3
- package/src/components/BaseObject.ts +37 -0
- package/src/components/DataObject.ts +45 -0
- package/src/components/Entity.ts +12 -0
- package/src/components/ObjectUri.ts +11 -0
- package/src/components/User.ts +12 -0
- package/src/properties/ArrayProperty.ts +48 -0
- package/src/properties/BaseProperty.ts +60 -0
- package/src/properties/BooleanProperty.ts +26 -0
- package/src/properties/CollectionProperty.ts +35 -0
- package/src/properties/DateTimeProperty.ts +35 -0
- package/src/properties/EnumProperty.ts +34 -0
- package/src/properties/FileProperty.ts +17 -0
- package/src/properties/HashProperty.ts +63 -0
- package/src/properties/MapProperty.ts +31 -0
- package/src/properties/NumberProperty.ts +55 -0
- package/src/properties/ObjectProperty.ts +46 -0
- package/src/properties/Property.ts +24 -0
- package/src/properties/StringProperty.ts +54 -0
|
@@ -12,19 +12,43 @@ import { ArrayProperty } from './ArrayProperty'
|
|
|
12
12
|
import { MapProperty } from './MapProperty'
|
|
13
13
|
import { FileProperty, FilePropertyType } from './FileProperty'
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* A central factory class for instantiating property objects dynamically based on a configuration payload.
|
|
17
|
+
* It routes property definitions to their respective concrete classes.
|
|
18
|
+
*/
|
|
15
19
|
export class Property {
|
|
20
|
+
/** Identifier for the `BaseProperty` class. */
|
|
16
21
|
static TYPE_ANY = 'any'
|
|
22
|
+
/** Identifier for the `NumberProperty` class. */
|
|
17
23
|
static TYPE_NUMBER = 'number'
|
|
24
|
+
/** Identifier for the `StringProperty` class. */
|
|
18
25
|
static TYPE_STRING = 'string'
|
|
26
|
+
/** Identifier for the `ObjectProperty` class. */
|
|
19
27
|
static TYPE_OBJECT = 'object'
|
|
28
|
+
/** Identifier for the `EnumProperty` class. */
|
|
20
29
|
static TYPE_ENUM = 'enum'
|
|
30
|
+
/** Identifier for the `BooleanProperty` class. */
|
|
21
31
|
static TYPE_BOOLEAN = 'boolean'
|
|
32
|
+
/** Identifier for the `HashProperty` class. */
|
|
22
33
|
static TYPE_HASH = 'hash'
|
|
34
|
+
/** Identifier for the `DateTimeProperty` class. */
|
|
23
35
|
static TYPE_DATETIME = 'datetime'
|
|
36
|
+
/** Identifier for the `ArrayProperty` class. */
|
|
24
37
|
static TYPE_ARRAY = 'array'
|
|
38
|
+
/** Identifier for the `MapProperty` class. */
|
|
25
39
|
static TYPE_MAP = 'map'
|
|
40
|
+
/** Identifier for the `FileProperty` class. */
|
|
26
41
|
static TYPE_FILE = 'file'
|
|
27
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Dynamically creates a concrete Property instance based on the provided configuration.
|
|
45
|
+
* Uses the `type` field to route to the correct subclass constructor.
|
|
46
|
+
*
|
|
47
|
+
* @param params - A comprehensive dictionary covering parameters for all possible property types. Must include `type`.
|
|
48
|
+
* @param parent - The parent `DataObjectClass` attaching this property.
|
|
49
|
+
* @returns The instantiated concrete property class (e.g. `StringProperty`, `NumberProperty`).
|
|
50
|
+
* @throws {Error} If the specified property type is unknown or missing required fields.
|
|
51
|
+
*/
|
|
28
52
|
static factory(
|
|
29
53
|
params: ObjectPropertyType &
|
|
30
54
|
StringPropertyType &
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
//import { Property } from './Property'
|
|
2
2
|
import { BaseProperty, BasePropertyType } from './BaseProperty'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Configuration dictionary for instantiating a `StringProperty`.
|
|
6
|
+
* Defines length constraints and character-level validation.
|
|
7
|
+
*
|
|
8
|
+
* | Parameter | Type | Description | Default |
|
|
9
|
+
* | :--- | :--- | :--- | :--- |
|
|
10
|
+
* | `minLength` | number | Minimum length of the string. | `0` |
|
|
11
|
+
* | `maxLength` | number | Maximum length of the string. | `0` (unlimited) |
|
|
12
|
+
* | `allowSpaces` | boolean | If false, throws an error if the string contains whitespace. | `true` |
|
|
13
|
+
* | `allowDigits` | boolean | If false, throws an error if the string contains digits (0-9). | `true` |
|
|
14
|
+
* | `allowLetters` | boolean | If false, throws an error if the string contains letters (a-z, A-Z). | `true` |
|
|
15
|
+
* | `allowPattern` | string | A regular expression pattern the string must match. | `undefined` |
|
|
16
|
+
* | `fullSearch` | boolean | Indicates to the backend if this field should be indexed for full-text search. | `false` |
|
|
17
|
+
*/
|
|
4
18
|
export interface StringPropertyType extends BasePropertyType {
|
|
5
19
|
minLength?: number
|
|
6
20
|
maxLength?: number
|
|
@@ -11,16 +25,42 @@ export interface StringPropertyType extends BasePropertyType {
|
|
|
11
25
|
fullSearch?: boolean
|
|
12
26
|
}
|
|
13
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A property type strictly validating and handling strings.
|
|
30
|
+
* It ensures that length constraints and specific character rules are respected before saving.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const username = new StringProperty({
|
|
35
|
+
* name: 'username',
|
|
36
|
+
* minLength: 3,
|
|
37
|
+
* maxLength: 15,
|
|
38
|
+
* allowSpaces: false
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* username.set('my user'); // Throws Error: Spaces are not allowed
|
|
42
|
+
* username.set('my_user'); // OK
|
|
43
|
+
* console.log(username.get(StringProperty.TRANSFORM_UCASE)); // "MY_USER"
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
14
46
|
export class StringProperty extends BaseProperty {
|
|
47
|
+
/** The string literal type identifier for this property. */
|
|
15
48
|
static TYPE = 'string'
|
|
16
49
|
|
|
50
|
+
/** Transformation identifier to convert string to uppercase. */
|
|
17
51
|
static TRANSFORM_UCASE = 'upper'
|
|
52
|
+
/** Transformation identifier to convert string to lowercase. */
|
|
18
53
|
static TRANSFORM_LCASE = 'lower'
|
|
19
54
|
|
|
55
|
+
/** Permission flag to allow whitespace characters. */
|
|
20
56
|
static ALLOW_SPACES = 'spaces'
|
|
57
|
+
/** Permission flag to allow alphabetic letters. */
|
|
21
58
|
static ALLOW_LETTERS = 'letters'
|
|
59
|
+
/** Permission flag to allow numeric digits. */
|
|
22
60
|
static ALLOW_DIGITS = 'digits'
|
|
61
|
+
/** Permission flag to allow string values. */
|
|
23
62
|
static ALLOW_STRINGS = 'strings'
|
|
63
|
+
/** Permission flag to allow number values. */
|
|
24
64
|
static ALLOW_NUMBERS = 'numbers'
|
|
25
65
|
|
|
26
66
|
protected _minLength: number = 0
|
|
@@ -50,6 +90,14 @@ export class StringProperty extends BaseProperty {
|
|
|
50
90
|
}
|
|
51
91
|
}
|
|
52
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Assigns a new string value while strictly enforcing length and character constraints.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The string to assign.
|
|
97
|
+
* @param setChanged - Whether to mark the property as modified.
|
|
98
|
+
* @returns The property instance for chaining.
|
|
99
|
+
* @throws {Error} If the string contains forbidden characters (spaces, letters, digits) or violates length limits.
|
|
100
|
+
*/
|
|
53
101
|
set(value: any, setChanged = true) {
|
|
54
102
|
if (this._rawValue && value !== null && value !== undefined) {
|
|
55
103
|
if (
|
|
@@ -84,6 +132,12 @@ export class StringProperty extends BaseProperty {
|
|
|
84
132
|
return super.set(value, setChanged)
|
|
85
133
|
}
|
|
86
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Retrieves the string value, optionally applying a casing transformation.
|
|
137
|
+
*
|
|
138
|
+
* @param transform - Use `TRANSFORM_LCASE` or `TRANSFORM_UCASE` to mutate output case.
|
|
139
|
+
* @returns The raw or transformed string, or undefined.
|
|
140
|
+
*/
|
|
87
141
|
get(transform: string | undefined = undefined) {
|
|
88
142
|
switch (transform) {
|
|
89
143
|
case StringProperty.TRANSFORM_LCASE:
|