@quatrain/core 1.2.5 → 1.2.7

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.
Files changed (67) hide show
  1. package/dist/Core.d.ts.map +1 -1
  2. package/dist/Core.js.map +1 -1
  3. package/dist/common/ResourcesErrors.d.ts.map +1 -1
  4. package/dist/common/ResourcesErrors.js.map +1 -1
  5. package/dist/components/AbstractObject.d.ts.map +1 -1
  6. package/dist/components/AbstractObject.js.map +1 -1
  7. package/dist/components/BaseObject.d.ts.map +1 -1
  8. package/dist/components/BaseObject.js.map +1 -1
  9. package/dist/components/DataObject.d.ts.map +1 -1
  10. package/dist/components/DataObject.js.map +1 -1
  11. package/dist/components/Entity.d.ts.map +1 -1
  12. package/dist/components/Entity.js.map +1 -1
  13. package/dist/components/ObjectUri.d.ts.map +1 -1
  14. package/dist/components/ObjectUri.js.map +1 -1
  15. package/dist/components/User.d.ts.map +1 -1
  16. package/dist/components/User.js.map +1 -1
  17. package/dist/properties/ArrayProperty.d.ts.map +1 -1
  18. package/dist/properties/ArrayProperty.js.map +1 -1
  19. package/dist/properties/BaseProperty.d.ts.map +1 -1
  20. package/dist/properties/BaseProperty.js +20 -2
  21. package/dist/properties/BaseProperty.js.map +1 -1
  22. package/dist/properties/BooleanProperty.d.ts.map +1 -1
  23. package/dist/properties/BooleanProperty.js.map +1 -1
  24. package/dist/properties/CollectionProperty.d.ts.map +1 -1
  25. package/dist/properties/CollectionProperty.js.map +1 -1
  26. package/dist/properties/DateTimeProperty.d.ts.map +1 -1
  27. package/dist/properties/DateTimeProperty.js.map +1 -1
  28. package/dist/properties/EnumProperty.d.ts.map +1 -1
  29. package/dist/properties/EnumProperty.js.map +1 -1
  30. package/dist/properties/FileProperty.d.ts.map +1 -1
  31. package/dist/properties/FileProperty.js.map +1 -1
  32. package/dist/properties/HashProperty.d.ts.map +1 -1
  33. package/dist/properties/HashProperty.js +3 -0
  34. package/dist/properties/HashProperty.js.map +1 -1
  35. package/dist/properties/MapProperty.d.ts.map +1 -1
  36. package/dist/properties/MapProperty.js.map +1 -1
  37. package/dist/properties/NumberProperty.d.ts.map +1 -1
  38. package/dist/properties/NumberProperty.js.map +1 -1
  39. package/dist/properties/ObjectProperty.d.ts.map +1 -1
  40. package/dist/properties/ObjectProperty.js.map +1 -1
  41. package/dist/properties/Property.d.ts.map +1 -1
  42. package/dist/properties/Property.js.map +1 -1
  43. package/dist/properties/StringProperty.d.ts.map +1 -1
  44. package/dist/properties/StringProperty.js.map +1 -1
  45. package/package.json +3 -3
  46. package/src/Core.ts +96 -0
  47. package/src/common/ResourcesErrors.ts +12 -0
  48. package/src/components/AbstractObject.ts +33 -3
  49. package/src/components/BaseObject.ts +37 -0
  50. package/src/components/DataObject.ts +45 -0
  51. package/src/components/Entity.ts +12 -0
  52. package/src/components/ObjectUri.ts +11 -0
  53. package/src/components/User.ts +12 -0
  54. package/src/properties/ArrayProperty.ts +48 -0
  55. package/src/properties/BaseProperty.test.ts +31 -0
  56. package/src/properties/BaseProperty.ts +81 -4
  57. package/src/properties/BooleanProperty.ts +26 -0
  58. package/src/properties/CollectionProperty.ts +35 -0
  59. package/src/properties/DateTimeProperty.ts +35 -0
  60. package/src/properties/EnumProperty.ts +34 -0
  61. package/src/properties/FileProperty.ts +17 -0
  62. package/src/properties/HashProperty.ts +63 -0
  63. package/src/properties/MapProperty.ts +31 -0
  64. package/src/properties/NumberProperty.ts +55 -0
  65. package/src/properties/ObjectProperty.ts +46 -0
  66. package/src/properties/Property.ts +24 -0
  67. package/src/properties/StringProperty.ts +54 -0
@@ -12,13 +12,39 @@ export enum returnAs {
12
12
  AS_IS = 'asIs',
13
13
  }
14
14
 
15
+ /**
16
+ * Configuration dictionary for instantiating an `ObjectProperty`.
17
+ * Defines the class type of the expected object.
18
+ *
19
+ * | Parameter | Type | Description | Default |
20
+ * | :--- | :--- | :--- | :--- |
21
+ * | `instanceOf` | any | The class constructor or class name string the object must match. | **Required** |
22
+ */
15
23
  export interface ObjectPropertyType extends BasePropertyType {
16
24
  instanceOf: any //Function | string | Object
17
25
  }
18
26
 
27
+ /**
28
+ * A relational property type designed to store references to other `BaseObjectClass` instances.
29
+ * Handles polymorphic resolution between raw `ObjectUri`, underlying `DataObject`, or the full class instance.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const owner = new ObjectProperty({
34
+ * name: 'owner',
35
+ * instanceOf: User
36
+ * });
37
+ *
38
+ * owner.set(userInstance);
39
+ * const uri = owner.val(returnAs.AS_OBJECTURIS); // Returns just the reference
40
+ * ```
41
+ */
19
42
  export class ObjectProperty extends BaseProperty {
43
+ /** The string literal type identifier for this property. */
20
44
  static TYPE = 'object'
45
+ /** The internal stored value, either a class instance or a URI. */
21
46
  _value: BaseObjectClass | ObjectUri | undefined = undefined
47
+ /** The class constructor or class name string the object must match. */
22
48
  _instanceOf: any //Function | string | Object
23
49
 
24
50
  constructor(config: ObjectPropertyType) {
@@ -30,6 +56,12 @@ export class ObjectProperty extends BaseProperty {
30
56
  return this._instanceOf
31
57
  }
32
58
 
59
+ /**
60
+ * Retrieves the object, optionally resolving it to a specific representation.
61
+ *
62
+ * @param transform - The desired format (`returnAs.AS_OBJECTURIS`, `AS_DATAOBJECTS`, `AS_INSTANCES`).
63
+ * @returns The resolved object, data object, or URI based on the requested transform.
64
+ */
33
65
  val(transform: string | undefined = undefined) {
34
66
  try {
35
67
  if (typeof this._instanceOf === 'string') {
@@ -89,6 +121,15 @@ export class ObjectProperty extends BaseProperty {
89
121
  }
90
122
  }
91
123
 
124
+ /**
125
+ * Assigns an object or an object reference to the property.
126
+ * Validates that the provided object matches the `instanceOf` class definition.
127
+ *
128
+ * @param value - The `BaseObjectClass`, `DataObject`, or `ObjectUri` to assign.
129
+ * @param setChanged - Whether to mark the property as modified.
130
+ * @returns The property instance for chaining.
131
+ * @throws {Error} If the assigned value is not an instance of the configured class.
132
+ */
92
133
  set(value: object, setChanged = true) {
93
134
  if (
94
135
  value! instanceof ObjectUri &&
@@ -105,6 +146,11 @@ export class ObjectProperty extends BaseProperty {
105
146
  return super.set(value, setChanged)
106
147
  }
107
148
 
149
+ /**
150
+ * Serializes the object property into a reference format suitable for storage.
151
+ *
152
+ * @returns The `ObjectUri` JSON representation, or a reference object.
153
+ */
108
154
  toJSON() {
109
155
  if (this._value instanceof ObjectUri) {
110
156
  return this._value.toJSON()
@@ -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: