@quatrain/core 1.1.24 → 1.1.29

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 (234) hide show
  1. package/README.md +56 -8
  2. package/{lib → dist}/Core.d.ts +3 -17
  3. package/dist/Core.d.ts.map +1 -0
  4. package/dist/Core.js +105 -0
  5. package/dist/Core.js.map +1 -0
  6. package/dist/common/DataGenerator.d.ts +3 -0
  7. package/dist/common/DataGenerator.d.ts.map +1 -0
  8. package/dist/common/DataGenerator.js +86 -0
  9. package/dist/common/DataGenerator.js.map +1 -0
  10. package/{lib → dist}/common/ResourcesErrors.d.ts +1 -0
  11. package/dist/common/ResourcesErrors.d.ts.map +1 -0
  12. package/{lib → dist}/common/ResourcesErrors.js +1 -0
  13. package/dist/common/ResourcesErrors.js.map +1 -0
  14. package/{lib → dist}/common/statuses.d.ts +1 -0
  15. package/dist/common/statuses.d.ts.map +1 -0
  16. package/{lib → dist}/common/statuses.js +1 -0
  17. package/dist/common/statuses.js.map +1 -0
  18. package/{lib → dist}/components/AbstractObject.d.ts +1 -5
  19. package/dist/components/AbstractObject.d.ts.map +1 -0
  20. package/{lib → dist}/components/AbstractObject.js +7 -10
  21. package/dist/components/AbstractObject.js.map +1 -0
  22. package/{lib → dist}/components/BaseObject.d.ts +4 -17
  23. package/dist/components/BaseObject.d.ts.map +1 -0
  24. package/dist/components/BaseObject.js +71 -0
  25. package/dist/components/BaseObject.js.map +1 -0
  26. package/dist/components/BaseObjectProperties.d.ts +2 -0
  27. package/dist/components/BaseObjectProperties.d.ts.map +1 -0
  28. package/{lib → dist}/components/BaseObjectProperties.js +1 -2
  29. package/dist/components/BaseObjectProperties.js.map +1 -0
  30. package/{lib → dist}/components/DataObject.d.ts +2 -51
  31. package/dist/components/DataObject.d.ts.map +1 -0
  32. package/{lib → dist}/components/DataObject.js +38 -111
  33. package/dist/components/DataObject.js.map +1 -0
  34. package/{lib → dist}/components/Entity.d.ts +1 -0
  35. package/dist/components/Entity.d.ts.map +1 -0
  36. package/dist/components/Entity.js +48 -0
  37. package/dist/components/Entity.js.map +1 -0
  38. package/{lib → dist}/components/ObjectUri.d.ts +1 -26
  39. package/dist/components/ObjectUri.d.ts.map +1 -0
  40. package/{lib → dist}/components/ObjectUri.js +13 -41
  41. package/dist/components/ObjectUri.js.map +1 -0
  42. package/{lib → dist}/components/User.d.ts +1 -0
  43. package/dist/components/User.d.ts.map +1 -0
  44. package/{lib → dist}/components/User.js +7 -26
  45. package/dist/components/User.js.map +1 -0
  46. package/dist/components/__test__/fixtures/dao.d.ts +37 -0
  47. package/dist/components/__test__/fixtures/dao.d.ts.map +1 -0
  48. package/dist/components/__test__/fixtures/dao.js +100 -0
  49. package/dist/components/__test__/fixtures/dao.js.map +1 -0
  50. package/{lib → dist}/components/index.d.ts +5 -2
  51. package/dist/components/index.d.ts.map +1 -0
  52. package/{lib → dist}/components/index.js +1 -0
  53. package/dist/components/index.js.map +1 -0
  54. package/{lib → dist}/components/types/AbstractObjectClass.d.ts +1 -0
  55. package/dist/components/types/AbstractObjectClass.d.ts.map +1 -0
  56. package/dist/components/types/AbstractObjectClass.js +3 -0
  57. package/dist/components/types/AbstractObjectClass.js.map +1 -0
  58. package/{lib → dist}/components/types/BaseObjectClass.d.ts +1 -0
  59. package/dist/components/types/BaseObjectClass.d.ts.map +1 -0
  60. package/{lib → dist}/components/types/BaseObjectClass.js +1 -0
  61. package/dist/components/types/BaseObjectClass.js.map +1 -0
  62. package/{lib → dist}/components/types/BaseObjectType.d.ts +2 -1
  63. package/dist/components/types/BaseObjectType.d.ts.map +1 -0
  64. package/{lib → dist}/components/types/BaseObjectType.js +1 -0
  65. package/dist/components/types/BaseObjectType.js.map +1 -0
  66. package/{lib → dist}/components/types/DataObjectClass.d.ts +1 -0
  67. package/dist/components/types/DataObjectClass.d.ts.map +1 -0
  68. package/{lib → dist}/components/types/DataObjectClass.js +1 -0
  69. package/dist/components/types/DataObjectClass.js.map +1 -0
  70. package/dist/components/types/DataObjectParams.d.ts +8 -0
  71. package/dist/components/types/DataObjectParams.d.ts.map +1 -0
  72. package/dist/components/types/DataObjectParams.js +3 -0
  73. package/dist/components/types/DataObjectParams.js.map +1 -0
  74. package/{lib → dist}/components/types/DataObjectType.d.ts +1 -0
  75. package/dist/components/types/DataObjectType.d.ts.map +1 -0
  76. package/{lib → dist}/components/types/DataObjectType.js +1 -0
  77. package/dist/components/types/DataObjectType.js.map +1 -0
  78. package/{lib → dist}/components/types/EntityClass.d.ts +1 -0
  79. package/dist/components/types/EntityClass.d.ts.map +1 -0
  80. package/{lib → dist}/components/types/EntityClass.js +1 -0
  81. package/dist/components/types/EntityClass.js.map +1 -0
  82. package/{lib → dist}/components/types/Payload.d.ts +1 -0
  83. package/dist/components/types/Payload.d.ts.map +1 -0
  84. package/{lib → dist}/components/types/Payload.js +1 -0
  85. package/dist/components/types/Payload.js.map +1 -0
  86. package/{lib → dist}/components/types/Persisted.d.ts +1 -0
  87. package/dist/components/types/Persisted.d.ts.map +1 -0
  88. package/{lib → dist}/components/types/Persisted.js +1 -0
  89. package/dist/components/types/Persisted.js.map +1 -0
  90. package/dist/components/types/Properties.d.ts +2 -0
  91. package/dist/components/types/Properties.d.ts.map +1 -0
  92. package/{lib/components/types/AbstractObjectClass.js → dist/components/types/Properties.js} +1 -0
  93. package/dist/components/types/Properties.js.map +1 -0
  94. package/{lib → dist}/components/types/ProxyConstructor.d.ts +1 -0
  95. package/dist/components/types/ProxyConstructor.d.ts.map +1 -0
  96. package/{lib → dist}/components/types/ProxyConstructor.js +1 -0
  97. package/dist/components/types/ProxyConstructor.js.map +1 -0
  98. package/{lib → dist}/components/types/toJSONParams.d.ts +1 -0
  99. package/dist/components/types/toJSONParams.d.ts.map +1 -0
  100. package/{lib → dist}/components/types/toJSONParams.js +1 -0
  101. package/dist/components/types/toJSONParams.js.map +1 -0
  102. package/{lib → dist}/index.d.ts +5 -1
  103. package/dist/index.d.ts.map +1 -0
  104. package/{lib → dist}/index.js +4 -1
  105. package/dist/index.js.map +1 -0
  106. package/{lib → dist}/properties/ArrayProperty.d.ts +1 -0
  107. package/dist/properties/ArrayProperty.d.ts.map +1 -0
  108. package/{lib → dist}/properties/ArrayProperty.js +5 -4
  109. package/dist/properties/ArrayProperty.js.map +1 -0
  110. package/{lib → dist}/properties/BaseProperty.d.ts +3 -2
  111. package/dist/properties/BaseProperty.d.ts.map +1 -0
  112. package/{lib → dist}/properties/BaseProperty.js +18 -11
  113. package/dist/properties/BaseProperty.js.map +1 -0
  114. package/{lib → dist}/properties/BooleanProperty.d.ts +1 -0
  115. package/dist/properties/BooleanProperty.d.ts.map +1 -0
  116. package/{lib → dist}/properties/BooleanProperty.js +2 -1
  117. package/dist/properties/BooleanProperty.js.map +1 -0
  118. package/{lib → dist}/properties/CollectionProperty.d.ts +1 -0
  119. package/dist/properties/CollectionProperty.d.ts.map +1 -0
  120. package/{lib → dist}/properties/CollectionProperty.js +6 -4
  121. package/dist/properties/CollectionProperty.js.map +1 -0
  122. package/{lib → dist}/properties/DateTimeProperty.d.ts +1 -0
  123. package/dist/properties/DateTimeProperty.d.ts.map +1 -0
  124. package/{lib → dist}/properties/DateTimeProperty.js +12 -5
  125. package/dist/properties/DateTimeProperty.js.map +1 -0
  126. package/{lib → dist}/properties/EnumProperty.d.ts +1 -0
  127. package/dist/properties/EnumProperty.d.ts.map +1 -0
  128. package/{lib → dist}/properties/EnumProperty.js +4 -3
  129. package/dist/properties/EnumProperty.js.map +1 -0
  130. package/{lib → dist}/properties/FileProperty.d.ts +1 -0
  131. package/dist/properties/FileProperty.d.ts.map +1 -0
  132. package/{lib → dist}/properties/FileProperty.js +3 -2
  133. package/dist/properties/FileProperty.js.map +1 -0
  134. package/{lib → dist}/properties/HashProperty.d.ts +2 -7
  135. package/dist/properties/HashProperty.d.ts.map +1 -0
  136. package/{lib → dist}/properties/HashProperty.js +15 -23
  137. package/dist/properties/HashProperty.js.map +1 -0
  138. package/{lib → dist}/properties/MapProperty.d.ts +1 -0
  139. package/dist/properties/MapProperty.d.ts.map +1 -0
  140. package/{lib → dist}/properties/MapProperty.js +2 -1
  141. package/dist/properties/MapProperty.js.map +1 -0
  142. package/{lib → dist}/properties/NumberProperty.d.ts +1 -0
  143. package/dist/properties/NumberProperty.d.ts.map +1 -0
  144. package/{lib → dist}/properties/NumberProperty.js +15 -14
  145. package/dist/properties/NumberProperty.js.map +1 -0
  146. package/{lib → dist}/properties/ObjectProperty.d.ts +1 -0
  147. package/dist/properties/ObjectProperty.d.ts.map +1 -0
  148. package/{lib → dist}/properties/ObjectProperty.js +4 -3
  149. package/dist/properties/ObjectProperty.js.map +1 -0
  150. package/{lib → dist}/properties/Property.d.ts +1 -0
  151. package/dist/properties/Property.d.ts.map +1 -0
  152. package/{lib → dist}/properties/Property.js +12 -11
  153. package/dist/properties/Property.js.map +1 -0
  154. package/{lib → dist}/properties/StringProperty.d.ts +3 -5
  155. package/dist/properties/StringProperty.d.ts.map +1 -0
  156. package/{lib → dist}/properties/StringProperty.js +20 -28
  157. package/dist/properties/StringProperty.js.map +1 -0
  158. package/{lib → dist}/properties/index.d.ts +4 -2
  159. package/dist/properties/index.d.ts.map +1 -0
  160. package/{lib → dist}/properties/index.js +1 -0
  161. package/dist/properties/index.js.map +1 -0
  162. package/{lib → dist}/properties/types/AbstractPropertyType.d.ts +1 -0
  163. package/dist/properties/types/AbstractPropertyType.d.ts.map +1 -0
  164. package/{lib → dist}/properties/types/AbstractPropertyType.js +1 -0
  165. package/dist/properties/types/AbstractPropertyType.js.map +1 -0
  166. package/{lib → dist}/properties/types/PropertyClassType.d.ts +1 -0
  167. package/dist/properties/types/PropertyClassType.d.ts.map +1 -0
  168. package/{lib → dist}/properties/types/PropertyClassType.js +1 -0
  169. package/dist/properties/types/PropertyClassType.js.map +1 -0
  170. package/{lib → dist}/properties/types/PropertyHTMLType.d.ts +1 -0
  171. package/dist/properties/types/PropertyHTMLType.d.ts.map +1 -0
  172. package/{lib → dist}/properties/types/PropertyHTMLType.js +1 -2
  173. package/dist/properties/types/PropertyHTMLType.js.map +1 -0
  174. package/{lib → dist}/properties/types/PropertyTypes.d.ts +1 -0
  175. package/dist/properties/types/PropertyTypes.d.ts.map +1 -0
  176. package/{lib → dist}/properties/types/PropertyTypes.js +1 -0
  177. package/dist/properties/types/PropertyTypes.js.map +1 -0
  178. package/package.json +47 -46
  179. package/src/Core.ts +145 -0
  180. package/src/common/DataGenerator.ts +81 -0
  181. package/src/common/ResourcesErrors.ts +17 -0
  182. package/src/common/statuses.ts +20 -0
  183. package/src/components/AbstractObject.ts +71 -0
  184. package/src/components/BaseObject.ts +123 -0
  185. package/src/components/BaseObjectProperties.ts +65 -0
  186. package/src/components/DataObject.ts +418 -0
  187. package/src/components/Entity.ts +38 -0
  188. package/src/components/ObjectUri.test.ts +74 -0
  189. package/src/components/ObjectUri.ts +174 -0
  190. package/src/components/User.ts +111 -0
  191. package/src/components/index.ts +19 -0
  192. package/src/components/types/AbstractObjectClass.ts +7 -0
  193. package/src/components/types/BaseObjectClass.ts +8 -0
  194. package/src/components/types/BaseObjectType.ts +10 -0
  195. package/src/components/types/DataObjectClass.ts +27 -0
  196. package/src/components/types/DataObjectParams.ts +8 -0
  197. package/src/components/types/DataObjectType.ts +27 -0
  198. package/src/components/types/EntityClass.ts +3 -0
  199. package/src/components/types/Payload.ts +11 -0
  200. package/src/components/types/Persisted.ts +7 -0
  201. package/src/components/types/Properties.ts +1 -0
  202. package/src/components/types/ProxyConstructor.ts +13 -0
  203. package/src/components/types/toJSONParams.ts +12 -0
  204. package/src/index.ts +97 -0
  205. package/src/properties/ArrayProperty.test.ts +46 -0
  206. package/src/properties/ArrayProperty.ts +87 -0
  207. package/src/properties/BaseProperty.test.ts +79 -0
  208. package/src/properties/BaseProperty.ts +140 -0
  209. package/src/properties/BooleanProperty.ts +11 -0
  210. package/src/properties/CollectionProperty.test.ts +22 -0
  211. package/src/properties/CollectionProperty.ts +43 -0
  212. package/src/properties/DateTimeProperty.ts +47 -0
  213. package/src/properties/EnumProperty.ts +36 -0
  214. package/src/properties/FileProperty.ts +14 -0
  215. package/src/properties/HashProperty.test.ts +108 -0
  216. package/src/properties/HashProperty.ts +70 -0
  217. package/src/properties/MapProperty.ts +19 -0
  218. package/src/properties/NumberProperty.test.ts +38 -0
  219. package/src/properties/NumberProperty.ts +110 -0
  220. package/src/properties/ObjectProperty.ts +118 -0
  221. package/src/properties/Property.ts +85 -0
  222. package/src/properties/StringProperty.test.ts +46 -0
  223. package/src/properties/StringProperty.ts +121 -0
  224. package/src/properties/index.ts +62 -0
  225. package/src/properties/types/AbstractPropertyType.ts +8 -0
  226. package/src/properties/types/PropertyClassType.ts +11 -0
  227. package/src/properties/types/PropertyHTMLType.ts +23 -0
  228. package/src/properties/types/PropertyTypes.ts +13 -0
  229. package/lib/Core.js +0 -133
  230. package/lib/components/BaseObject.js +0 -103
  231. package/lib/components/BaseObjectProperties.d.ts +0 -1
  232. package/lib/components/Entity.js +0 -71
  233. package/lib/components/types/Properties.d.ts +0 -3
  234. package/lib/components/types/Properties.js +0 -1
@@ -1,22 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringProperty = void 0;
4
- //import { Property } from './Property'
5
4
  const BaseProperty_1 = require("./BaseProperty");
6
5
  class StringProperty extends BaseProperty_1.BaseProperty {
6
+ static TYPE = 'string';
7
+ static TRANSFORM_UCASE = 'upper';
8
+ static TRANSFORM_LCASE = 'lower';
9
+ static ALLOW_SPACES = 'spaces';
10
+ static ALLOW_LETTERS = 'letters';
11
+ static ALLOW_DIGITS = 'digits';
12
+ static ALLOW_STRINGS = 'strings';
13
+ static ALLOW_NUMBERS = 'numbers';
14
+ _minLength = 0;
15
+ _maxLength = 0;
16
+ _fullSearch = false;
17
+ _rawValue = true;
7
18
  constructor(config) {
8
19
  super(config);
9
- this._minLength = 0;
10
- this._maxLength = 0;
11
- this._fullSearch = false;
12
- /**
13
- * Set to false to bypass some rules
14
- */
15
- this._rawValue = true;
16
20
  this.minLength = config.minLength || 0;
17
21
  this.maxLength = config.maxLength || 0;
18
22
  this.fullSearch = config.fullSearch || false;
19
- this._htmlType = config.htmlType || 'off';
20
23
  if (this._enable(config.allowSpaces)) {
21
24
  this._allows.push(StringProperty.ALLOW_SPACES);
22
25
  }
@@ -28,27 +31,23 @@ class StringProperty extends BaseProperty_1.BaseProperty {
28
31
  }
29
32
  }
30
33
  set(value, setChanged = true) {
31
- if (value !== null && value !== undefined) {
32
- if (this._allows.includes(StringProperty.ALLOW_DIGITS) === false &&
34
+ if (this._rawValue && value !== null && value !== undefined) {
35
+ if (!this._allows.includes(StringProperty.ALLOW_DIGITS) &&
33
36
  /\d/.test(value)) {
34
37
  throw new Error(`Digits are not allowed in value`);
35
38
  }
36
- if (this._allows.includes(StringProperty.ALLOW_SPACES) === false &&
37
- /\s/g.test(value)) {
39
+ if (!this._allows.includes(StringProperty.ALLOW_SPACES) &&
40
+ /\s/.test(value)) {
38
41
  throw new Error(`Spaces are not allowed in value`);
39
42
  }
40
- if (this._allows.includes(StringProperty.ALLOW_LETTERS) === false &&
43
+ if (!this._allows.includes(StringProperty.ALLOW_LETTERS) &&
41
44
  /[a-zA-Z]/.test(value)) {
42
45
  throw new Error(`Letters are not allowed in value`);
43
46
  }
44
- if (this._rawValue &&
45
- this._minLength > 0 &&
46
- value.length < this._minLength) {
47
+ if (this._minLength > 0 && value.length < this._minLength) {
47
48
  throw new Error(`Value is too short`);
48
49
  }
49
- if (this._rawValue &&
50
- this._maxLength > 0 &&
51
- value.length > this._maxLength) {
50
+ if (this._maxLength > 0 && value.length > this._maxLength) {
52
51
  throw new Error(`${this._name}: value '${value}' is too long`);
53
52
  }
54
53
  }
@@ -84,11 +83,4 @@ class StringProperty extends BaseProperty_1.BaseProperty {
84
83
  }
85
84
  }
86
85
  exports.StringProperty = StringProperty;
87
- StringProperty.TYPE = 'string';
88
- StringProperty.TRANSFORM_UCASE = 'upper';
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';
86
+ //# sourceMappingURL=StringProperty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StringProperty.js","sourceRoot":"","sources":["../../src/properties/StringProperty.ts"],"names":[],"mappings":";;;AACA,iDAA+D;AAY/D,MAAa,cAAe,SAAQ,2BAAY;IAC7C,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAA;IAEtB,MAAM,CAAC,eAAe,GAAG,OAAO,CAAA;IAChC,MAAM,CAAC,eAAe,GAAG,OAAO,CAAA;IAEhC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;IAC9B,MAAM,CAAC,aAAa,GAAG,SAAS,CAAA;IAChC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;IAC9B,MAAM,CAAC,aAAa,GAAG,SAAS,CAAA;IAChC,MAAM,CAAC,aAAa,GAAG,SAAS,CAAA;IAEtB,UAAU,GAAW,CAAC,CAAA;IACtB,UAAU,GAAW,CAAC,CAAA;IACtB,WAAW,GAAY,KAAK,CAAA;IAO5B,SAAS,GAAG,IAAI,CAAA;IAE1B,YAAY,MAA0B;QACnC,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAA;QACtC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAA;QACtC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,KAAK,CAAA;QAC5C,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;QACjD,CAAC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PropertyType } from './MapProperty';
12
12
  import { FileProperty, FilePropertyType } from './FileProperty';
13
13
  import { CollectionProperty, CollectionPropertyType } from './CollectionProperty';
14
14
  import { PropertyTypes } from './types/PropertyTypes';
15
- export { Property, BaseProperty, BasePropertyType, ArrayProperty, ArrayPropertyType, NumberProperty, NumberPropertyType, BooleanProperty, BooleanPropertyType, DateTimeProperty, DateTimePropertyType, EnumProperty, EnumPropertyType, ObjectProperty, ObjectPropertyType, StringProperty, StringPropertyType, HashProperty, HashPropertyType, MapProperty, MapPropertyType, FileProperty, FilePropertyType, CollectionProperty, CollectionPropertyType, };
15
+ export { Property, BaseProperty, ArrayProperty, NumberProperty, BooleanProperty, DateTimeProperty, EnumProperty, ObjectProperty, StringProperty, HashProperty, MapProperty, FileProperty, CollectionProperty, };
16
+ export type { BasePropertyType, ArrayPropertyType, NumberPropertyType, BooleanPropertyType, DateTimePropertyType, EnumPropertyType, ObjectPropertyType, StringPropertyType, HashPropertyType, MapPropertyType, FilePropertyType, CollectionPropertyType, };
16
17
  type BaseType = {
17
18
  type: PropertyTypes;
18
19
  };
19
- export type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimeProperty & BaseType) | (ArrayPropertyType & BaseType) | (MapPropertyType & BaseType) | (CollectionPropertyType & BaseType))[];
20
+ export type DataObjectProperties = ((NumberPropertyType & BaseType) | (BooleanPropertyType & BaseType) | (EnumPropertyType & BaseType) | (ObjectPropertyType & BaseType) | (StringPropertyType & BaseType) | (HashPropertyType & BaseType) | (DateTimePropertyType & BaseType) | (ArrayPropertyType & BaseType) | (MapPropertyType & BaseType) | (CollectionPropertyType & BaseType))[];
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OA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AsB,GACxB,CAAA;AAED,KAAK,QAAQ,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAA;AAEvC,MAAM,MAAM,oBAAoB,GAAG,CAC9B,CAAC,kBAAkB,GAAG,QAAQ,CAAC,GAC/B,CAAC,mBAAmB,GAAG,QAAQ,CAAC,GAChC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,GAC7B,CAAC,kBAAkB,GAAG,QAAQ,CAAC,GAC/B,CAAC,kBAAkB,GAAG,QAAQ,CAAC,GAC/B,CAAC,gBAAgB,GAAG,QAAQ,CAAC,GAC7B,CAAC,oBAAoB,GAAG,QAAQ,CAAC,GACjC,CAAC,iBAAiB,GAAG,QAAQ,CAAC,GAC9B,CAAC,eAAe,GAAG,QAAQ,CAAC,GAC5B,CAAC,sBAAsB,GAAG,QAAQ,CAAC,CACvC,EAAE,CAAA"}
@@ -27,3 +27,4 @@ const FileProperty_1 = require("./FileProperty");
27
27
  Object.defineProperty(exports, "FileProperty", { enumerable: true, get: function () { return FileProperty_1.FileProperty; } });
28
28
  const CollectionProperty_1 = require("./CollectionProperty");
29
29
  Object.defineProperty(exports, "CollectionProperty", { enumerable: true, get: function () { return CollectionProperty_1.CollectionProperty; } });
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAmBlC,yFAnBM,mBAAQ,OAmBN;AAlBX,iDAA+D;AAmB5D,6FAnBM,2BAAY,OAmBN;AAlBf,mDAAkE;AAmB/D,8FAnBM,6BAAa,OAmBN;AAlBhB,qDAAqE;AAmBlE,+FAnBM,+BAAc,OAmBN;AAlBjB,qDAAqE;AAuBlE,+FAvBM,+BAAc,OAuBN;AAtBjB,iDAA+D;AAuB5D,6FAvBM,2BAAY,OAuBN;AAtBf,iDAA+D;AAmB5D,6FAnBM,2BAAY,OAmBN;AAlBf,uDAAwE;AAgBrE,gGAhBM,iCAAe,OAgBN;AAflB,yDAA2E;AAgBxE,iGAhBM,mCAAgB,OAgBN;AAfnB,qDAAqE;AAiBlE,+FAjBM,+BAAc,OAiBN;AAhBjB,+CAA4D;AAmBzD,4FAnBM,yBAAW,OAmBN;AAlBd,iDAA+D;AAmB5D,6FAnBM,2BAAY,OAmBN;AAlBf,6DAG6B;AAgB1B,mGAlBA,uCAAkB,OAkBA"}
@@ -5,3 +5,4 @@ export interface AbstractPropertyType {
5
5
  type?: PropertyTypes;
6
6
  defaultValue?: any;
7
7
  }
8
+ //# sourceMappingURL=AbstractPropertyType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractPropertyType.d.ts","sourceRoot":"","sources":["../../../src/properties/types/AbstractPropertyType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,WAAW,oBAAoB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,YAAY,CAAC,EAAE,GAAG,CAAA;CACpB"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AbstractPropertyType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractPropertyType.js","sourceRoot":"","sources":["../../../src/properties/types/AbstractPropertyType.ts"],"names":[],"mappings":""}
@@ -8,3 +8,4 @@ export interface PropertyClassType {
8
8
  clone(): PropertyClassType;
9
9
  hasChanged?: boolean;
10
10
  }
11
+ //# sourceMappingURL=PropertyClassType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyClassType.d.ts","sourceRoot":"","sources":["../../../src/properties/types/PropertyClassType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,MAAM,WAAW,iBAAiB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,oBAAoB,CAAA;IAC3D,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,CAAA;IACzB,MAAM,IAAI,GAAG,CAAA;IACb,KAAK,IAAI,iBAAiB,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;CACtB"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PropertyClassType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyClassType.js","sourceRoot":"","sources":["../../../src/properties/types/PropertyClassType.ts"],"names":[],"mappings":""}
@@ -8,3 +8,4 @@ export declare const BIRTHDAY = "bday";
8
8
  export declare const GENDER = "sex";
9
9
  export declare const ORG = "organization";
10
10
  export type PropertyHTMLType = typeof OFF | typeof NAME | typeof GIVEN_NAME | typeof FAMILY_NAME | typeof EMAIL | typeof PASSWORD | typeof BIRTHDAY | typeof GENDER | typeof ORG;
11
+ //# sourceMappingURL=PropertyHTMLType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyHTMLType.d.ts","sourceRoot":"","sources":["../../../src/properties/types/PropertyHTMLType.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG,QAAQ,CAAA;AACxB,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B,eAAO,MAAM,UAAU,eAAe,CAAA;AACtC,eAAO,MAAM,WAAW,gBAAgB,CAAA;AACxC,eAAO,MAAM,KAAK,UAAU,CAAA;AAC5B,eAAO,MAAM,QAAQ,aAAa,CAAA;AAClC,eAAO,MAAM,QAAQ,SAAS,CAAA;AAC9B,eAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,eAAO,MAAM,GAAG,iBAAiB,CAAA;AAEjC,MAAM,MAAM,gBAAgB,GACvB,OAAO,GAAG,GACV,OAAO,IAAI,GACX,OAAO,UAAU,GACjB,OAAO,WAAW,GAClB,OAAO,KAAK,GACZ,OAAO,QAAQ,GACf,OAAO,QAAQ,GACf,OAAO,MAAM,GACb,OAAO,GAAG,CAAA"}
@@ -1,6 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  exports.ORG = exports.GENDER = exports.BIRTHDAY = exports.PASSWORD = exports.EMAIL = exports.FAMILY_NAME = exports.GIVEN_NAME = exports.NAME = exports.OFF = void 0;
6
4
  exports.OFF = 'off';
@@ -12,3 +10,4 @@ exports.PASSWORD = 'password';
12
10
  exports.BIRTHDAY = 'bday';
13
11
  exports.GENDER = 'sex';
14
12
  exports.ORG = 'organization';
13
+ //# sourceMappingURL=PropertyHTMLType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyHTMLType.js","sourceRoot":"","sources":["../../../src/properties/types/PropertyHTMLType.ts"],"names":[],"mappings":";;;AAGa,QAAA,GAAG,GAAG,KAAK,CAAA;AACX,QAAA,IAAI,GAAG,MAAM,CAAA;AACb,QAAA,UAAU,GAAG,YAAY,CAAA;AACzB,QAAA,WAAW,GAAG,aAAa,CAAA;AAC3B,QAAA,KAAK,GAAG,OAAO,CAAA;AACf,QAAA,QAAQ,GAAG,UAAU,CAAA;AACrB,QAAA,QAAQ,GAAG,MAAM,CAAA;AACjB,QAAA,MAAM,GAAG,KAAK,CAAA;AACd,QAAA,GAAG,GAAG,cAAc,CAAA"}
@@ -3,3 +3,4 @@ export type PropertyTypes = typeof Property.TYPE_STRING | typeof Property.TYPE_N
3
3
  export type BaseType = {
4
4
  type: PropertyTypes;
5
5
  };
6
+ //# sourceMappingURL=PropertyTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyTypes.d.ts","sourceRoot":"","sources":["../../../src/properties/types/PropertyTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAE7B,MAAM,MAAM,aAAa,GACpB,OAAO,QAAQ,CAAC,WAAW,GAC3B,OAAO,QAAQ,CAAC,WAAW,GAC3B,OAAO,QAAQ,CAAC,SAAS,GACzB,OAAO,QAAQ,CAAC,YAAY,GAC5B,OAAO,QAAQ,CAAC,WAAW,GAC3B,OAAO,QAAQ,CAAC,aAAa,GAC7B,OAAO,QAAQ,CAAC,SAAS,GACzB,OAAO,QAAQ,CAAC,UAAU,CAAA;AAE/B,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAA"}
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PropertyTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyTypes.js","sourceRoot":"","sources":["../../../src/properties/types/PropertyTypes.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,47 +1,48 @@
1
1
  {
2
- "name": "@quatrain/core",
3
- "version": "1.1.24",
4
- "description": "Core objects for business apps",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "files": [
8
- "lib/",
9
- "README.md"
10
- ],
11
- "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
- "license": "MIT",
13
- "devDependencies": {
14
- "@tsconfig/recommended": "^1.0.1",
15
- "@types/jest": "^30.0.0",
16
- "@types/module-alias": "^2",
17
- "@types/node": "^22.10.1",
18
- "@types/node-persist": "^3.1.8",
19
- "@types/which": "^3.0.4",
20
- "jest": "^30.2.0",
21
- "trace-unhandled": "^2.0.1",
22
- "ts-jest": "^29.4.1",
23
- "ts-node": "^10.4.0",
24
- "typescript": "^5.1.5"
25
- },
26
- "dependencies": {
27
- "@faker-js/faker": "^7.6.0",
28
- "@quatrain/log": "^1.0.2",
29
- "module-alias": "^2.2.3",
30
- "node-persist": "^4.0.4",
31
- "which": "^5.0.0"
32
- },
33
- "scripts": {
34
- "test-ci": "jest --runInBand",
35
- "build": "tsc",
36
- "wbuild": "tsc --watch",
37
- "bump-to": "yarn version",
38
- "hash": "node ../../bin/hashFolder.js",
39
- "hash:persist": "yarn hash > .hash_latest.txt",
40
- "hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
41
- "publish": "yarn hash:compare || yarn publish:process",
42
- "publish:process": "yarn version patch && yarn build && yarn npm publish --access public && yarn hash:persist"
43
- },
44
- "_moduleAliases": {
45
- "@core": "."
46
- }
47
- }
2
+ "name": "@quatrain/core",
3
+ "version": "1.1.29",
4
+ "description": "Core objects for business apps",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/",
9
+ "src/",
10
+ "README.md"
11
+ ],
12
+ "author": "Quatrain Développement SAS <developers@quatrain.com>",
13
+ "license": "AGPL-3.0-only",
14
+ "devDependencies": {
15
+ "@tsconfig/recommended": "^1.0.1",
16
+ "@types/jest": "^30.0.0",
17
+ "@types/module-alias": "^2",
18
+ "@types/node": "^22.10.1",
19
+ "@types/node-persist": "^3.1.8",
20
+ "@types/which": "^3.0.4",
21
+ "jest": "^30.2.0",
22
+ "trace-unhandled": "^2.0.1",
23
+ "ts-jest": "^29.4.1",
24
+ "ts-node": "^10.9.1",
25
+ "typescript": "^5.2.2"
26
+ },
27
+ "dependencies": {
28
+ "@faker-js/faker": "^7.6.0",
29
+ "@quatrain/log": "workspace:^",
30
+ "module-alias": "^2.2.3",
31
+ "node-persist": "^4.0.4",
32
+ "which": "^5.0.0"
33
+ },
34
+ "scripts": {
35
+ "test-ci": "jest --runInBand",
36
+ "build": "tsc",
37
+ "wbuild": "tsc --watch",
38
+ "bump-to": "yarn version",
39
+ "hash": "node ../../bin/hashFolder.js",
40
+ "hash:persist": "yarn hash > .hash_latest.txt",
41
+ "hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
42
+ "publish": "yarn hash:compare || yarn publish:process",
43
+ "publish:process": "yarn version patch && yarn build && npm publish --access public && yarn hash:persist"
44
+ },
45
+ "_moduleAliases": {
46
+ "@core": "."
47
+ }
48
+ }
package/src/Core.ts ADDED
@@ -0,0 +1,145 @@
1
+ import {
2
+ AbstractLoggerAdapter,
3
+ DefaultLoggerAdapter,
4
+ Log,
5
+ LogLevel,
6
+ } from '@quatrain/log'
7
+ import { spawn } from 'child_process'
8
+ import which from 'which'
9
+
10
+ export class Core {
11
+ static readonly me = this.name
12
+ static readonly storage = require('node-persist')
13
+ static readonly storagePrefix = 'core'
14
+ static readonly classRegistry: { [key: string]: any } = {}
15
+ static readonly logLevel = LogLevel.DEBUG
16
+ static readonly logger: AbstractLoggerAdapter = this.addLogger()
17
+
18
+ static addLogger(alias: string = this.name) {
19
+ return Log.addLogger(
20
+ '@' + alias,
21
+ new DefaultLoggerAdapter(alias, this.logLevel),
22
+ true
23
+ )
24
+ }
25
+
26
+ static setLogLevel(level: LogLevel) {
27
+ this.logger.logLevel(level)
28
+ }
29
+
30
+ // How timestamp are formatted
31
+ static readonly timestamp = () => new Date().toISOString()
32
+
33
+ static definition(key: string) {
34
+ return {
35
+ manifest: {
36
+ type: String,
37
+ mandatory: true,
38
+ },
39
+ }
40
+ }
41
+
42
+ static async addConfig(key: string, value: any) {
43
+ if (!this.storage.set) {
44
+ await this.storage.init()
45
+ }
46
+ await this.storage.set(`${this.storagePrefix}_${key}`, value)
47
+ }
48
+
49
+ static async getConfig(key: string) {
50
+ if (!this.storage.get) {
51
+ await this.storage.init()
52
+ }
53
+ return await this.storage.get(`${this.storagePrefix}_${key}`)
54
+ }
55
+
56
+ static addClass(name: string, obj: any) {
57
+ Core.classRegistry[name] = obj
58
+ }
59
+
60
+ static getClass(name: string) {
61
+ return Core.classRegistry[name]
62
+ }
63
+
64
+ /**
65
+ * Execute an external command in a promise
66
+ * @see https://stackoverflow.com/questions/46289682/how-to-wait-for-child-process-spawn-execution-with-async-await
67
+ * @see https://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node
68
+ * @param string command
69
+ * @param array args
70
+ * @return Promise
71
+ */
72
+ static readonly execPromise = (
73
+ command: string,
74
+ args: any[] = [],
75
+ cwd = process.cwd()
76
+ ): Promise<any> => {
77
+ try {
78
+ Core.info(`Executing command ${command} in ${cwd} with arguments:`)
79
+ args.forEach((arg) => console.log(`\t${arg}`))
80
+ return new Promise((resolve, reject) => {
81
+ const child = spawn(command, args, { cwd })
82
+
83
+ child.stdout.on('data', (data: Buffer) =>
84
+ Core.debug(data.toString())
85
+ )
86
+
87
+ child.stderr.on('data', (data: Buffer) =>
88
+ Core.debug(data.toString())
89
+ )
90
+
91
+ child.on('close', (code) => {
92
+ if (code !== 0) {
93
+ Core.error(`Command execution failed with code: ${code}`)
94
+ reject(new Error(`Process failed and returned code: ${code}`))
95
+ } else {
96
+ Core.info(`Command execution completed with code: ${code}`)
97
+ resolve(undefined)
98
+ }
99
+ })
100
+ })
101
+ } catch (err) {
102
+ Core.error((err as Error).message)
103
+ throw err
104
+ }
105
+ }
106
+
107
+ static readonly getSystemCommandPath = (command: string): Promise<string> =>
108
+ which(command)
109
+
110
+ static sleep(seconds: number = 1) {
111
+ return new Promise((resolve) => setTimeout(resolve, seconds * 1000))
112
+ }
113
+
114
+ static get userClass() {
115
+ return this.getClass('User')
116
+ }
117
+
118
+ static set userClass(cls: any) {
119
+ this.addClass('User', cls)
120
+ }
121
+
122
+ static log(...message: any): void {
123
+ return this.logger.log(message)
124
+ }
125
+
126
+ static debug(...message: any): void {
127
+ return this.logger.debug(message)
128
+ }
129
+
130
+ static warn(...message: any): void {
131
+ return this.logger.warn(message)
132
+ }
133
+
134
+ static info(...message: any): void {
135
+ return this.logger.info(message)
136
+ }
137
+
138
+ static error(...message: any): void {
139
+ return this.logger.error(message)
140
+ }
141
+
142
+ static trace(...message: any): void {
143
+ return this.logger.trace(message)
144
+ }
145
+ }
@@ -0,0 +1,81 @@
1
+ import { AbstractObject } from '../components/AbstractObject'
2
+ import * as htmlType from '../properties/types/PropertyHTMLType'
3
+ import { faker } from '@faker-js/faker'
4
+ import { Core } from '..'
5
+
6
+ /**
7
+ * Generate data from model of object and save it in default backend
8
+ * @param model
9
+ * @param qty
10
+ * @param forcedValues
11
+ * @returns
12
+ */
13
+ export const DataGenerator = async <T extends AbstractObject>(
14
+ model: T,
15
+ qty: number = 5,
16
+ forcedValues: any = {}
17
+ ): Promise<any> => {
18
+ const promises: any = []
19
+ Core.info(`Starting to create ${qty} ${model.constructor.name} records`)
20
+ for (let i = 0; i < qty; i++) {
21
+ const dao = await model.dataObject.clone()
22
+
23
+ Object.keys(dao.properties).forEach((key) => {
24
+ Core.debug(`Getting property for '${key}'`)
25
+ const property = dao.get(key)
26
+
27
+ if (forcedValues[key]) {
28
+ property.set(forcedValues[key])
29
+ return
30
+ }
31
+
32
+ switch (property.constructor.name) {
33
+ case 'StringProperty':
34
+ switch (property.htmlType) {
35
+ case htmlType.GIVEN_NAME:
36
+ property.set(faker.name.firstName())
37
+ break
38
+ case htmlType.FAMILY_NAME:
39
+ property.set(faker.name.lastName())
40
+ break
41
+ case htmlType.EMAIL:
42
+ property.set(faker.helpers.unique(faker.internet.email))
43
+ break
44
+ case htmlType.ORG:
45
+ property.set(faker.company.name())
46
+ break
47
+ default:
48
+ property.set(faker.word.noun())
49
+ break
50
+ }
51
+ break
52
+
53
+ case 'EnumProperty':
54
+ property.set(faker.helpers.arrayElement(property.values))
55
+ break
56
+
57
+ case 'HashProperty':
58
+ property.set(faker.random.alphaNumeric(16))
59
+ break
60
+
61
+ case 'DateTimeProperty':
62
+ switch (property.htmlType) {
63
+ case htmlType.BIRTHDAY:
64
+ property.set(faker.date.birthdate())
65
+ break
66
+ default:
67
+ //property.set(faker.date.future())
68
+ break
69
+ }
70
+ break
71
+
72
+ default:
73
+ break
74
+ }
75
+ })
76
+
77
+ promises.push(dao)
78
+ }
79
+
80
+ return promises
81
+ }
@@ -0,0 +1,17 @@
1
+ export class ResourceError extends Error {
2
+ constructor(message: string) {
3
+ super(message)
4
+
5
+ this.name = this.constructor.name
6
+ }
7
+ }
8
+
9
+ export class BadRequestError extends ResourceError {}
10
+
11
+ export class UnauthorizedError extends ResourceError {}
12
+
13
+ export class ForbiddenError extends ResourceError {}
14
+
15
+ export class NotFoundError extends ResourceError {}
16
+
17
+ export class GoneError extends ResourceError {}
@@ -0,0 +1,20 @@
1
+ export const ACTIVE = 'active'
2
+ export const COMPLETED = 'completed'
3
+ export const CREATED = 'created'
4
+ export const DELETABLE = 'deletable'
5
+ export const DELETED = 'deleted'
6
+ export const DISABLED = 'disabled'
7
+ export const DONE = 'done'
8
+ export const DOWNLOADING = 'downloading'
9
+ export const DOWNLOADED = 'downloaded'
10
+ export const DOWNLOAD_KO = 'download_ko'
11
+ export const ERROR = 'error'
12
+ export const KO = 'ko'
13
+ export const PENDING = 'pending'
14
+ export const PREPARING = 'preparing'
15
+ export const PROCESSING = 'processing'
16
+ export const QUEUED = 'queued'
17
+ export const UNKNOWN = 'unknown'
18
+ export const UPLOADING = 'uploading'
19
+ export const UPLOADED = 'uploaded'
20
+ export const UPLOAD_KO = 'upload_ko'
@@ -0,0 +1,71 @@
1
+ import { DataObjectClass } from './types/DataObjectClass'
2
+ import { DataObjectProperties } from '../properties'
3
+
4
+ export abstract class AbstractObject {
5
+ static PROPS_DEFINITION: DataObjectProperties = []
6
+
7
+ // Which name to use in backend as table/collection identifer
8
+ static COLLECTION: string | undefined
9
+
10
+ // which property handles relation to parent
11
+ static PARENT_PROP: string | undefined
12
+
13
+ // Which property's value to use in backend as label for object reference
14
+ static LABEL_KEY = 'name'
15
+
16
+ protected _dataObject: DataObjectClass<any>
17
+
18
+ constructor(dao: DataObjectClass<any>) {
19
+ this._dataObject = dao
20
+ }
21
+
22
+ /**
23
+ * Return property object matching key
24
+ * @param key string
25
+ * @returns
26
+ */
27
+ get(key: string) {
28
+ return this._dataObject.get(key)
29
+ }
30
+
31
+ set(key: string, val: any) {
32
+ return this._dataObject.set(key, val)
33
+ }
34
+
35
+ val(key: string): any {
36
+ const prop = this.get(key)
37
+ if (prop) {
38
+ return prop.val()
39
+ } else {
40
+ return null
41
+ }
42
+ }
43
+
44
+ has(key: string) {
45
+ return Reflect.has(this._dataObject.properties, key)
46
+ }
47
+
48
+ get path(): string {
49
+ return this._dataObject.path
50
+ }
51
+
52
+ get uid() {
53
+ return this._dataObject.uid
54
+ }
55
+
56
+ get dataObject() {
57
+ return this._dataObject
58
+ }
59
+
60
+ get _() {
61
+ return this._dataObject.asProxy()
62
+ }
63
+
64
+ get uri() {
65
+ return this._dataObject.uri
66
+ }
67
+
68
+ toJSON() {
69
+ return typeof this.uri === 'string' ? this.uri : this.uri?.toJSON()
70
+ }
71
+ }