@quatrain/core 1.1.24 → 1.1.28
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/README.md +56 -8
- package/{lib → dist}/Core.d.ts +3 -17
- package/dist/Core.d.ts.map +1 -0
- package/dist/Core.js +105 -0
- package/dist/Core.js.map +1 -0
- package/dist/common/DataGenerator.d.ts +3 -0
- package/dist/common/DataGenerator.d.ts.map +1 -0
- package/dist/common/DataGenerator.js +86 -0
- package/dist/common/DataGenerator.js.map +1 -0
- package/{lib → dist}/common/ResourcesErrors.d.ts +1 -0
- package/dist/common/ResourcesErrors.d.ts.map +1 -0
- package/{lib → dist}/common/ResourcesErrors.js +1 -0
- package/dist/common/ResourcesErrors.js.map +1 -0
- package/{lib → dist}/common/statuses.d.ts +1 -0
- package/dist/common/statuses.d.ts.map +1 -0
- package/{lib → dist}/common/statuses.js +1 -0
- package/dist/common/statuses.js.map +1 -0
- package/{lib → dist}/components/AbstractObject.d.ts +1 -5
- package/dist/components/AbstractObject.d.ts.map +1 -0
- package/{lib → dist}/components/AbstractObject.js +7 -10
- package/dist/components/AbstractObject.js.map +1 -0
- package/{lib → dist}/components/BaseObject.d.ts +4 -17
- package/dist/components/BaseObject.d.ts.map +1 -0
- package/dist/components/BaseObject.js +71 -0
- package/dist/components/BaseObject.js.map +1 -0
- package/dist/components/BaseObjectProperties.d.ts +2 -0
- package/dist/components/BaseObjectProperties.d.ts.map +1 -0
- package/{lib → dist}/components/BaseObjectProperties.js +1 -2
- package/dist/components/BaseObjectProperties.js.map +1 -0
- package/{lib → dist}/components/DataObject.d.ts +2 -51
- package/dist/components/DataObject.d.ts.map +1 -0
- package/{lib → dist}/components/DataObject.js +38 -111
- package/dist/components/DataObject.js.map +1 -0
- package/{lib → dist}/components/Entity.d.ts +1 -0
- package/dist/components/Entity.d.ts.map +1 -0
- package/dist/components/Entity.js +48 -0
- package/dist/components/Entity.js.map +1 -0
- package/{lib → dist}/components/ObjectUri.d.ts +1 -26
- package/dist/components/ObjectUri.d.ts.map +1 -0
- package/{lib → dist}/components/ObjectUri.js +13 -41
- package/dist/components/ObjectUri.js.map +1 -0
- package/{lib → dist}/components/User.d.ts +1 -0
- package/dist/components/User.d.ts.map +1 -0
- package/{lib → dist}/components/User.js +7 -26
- package/dist/components/User.js.map +1 -0
- package/dist/components/__test__/fixtures/dao.d.ts +37 -0
- package/dist/components/__test__/fixtures/dao.d.ts.map +1 -0
- package/dist/components/__test__/fixtures/dao.js +100 -0
- package/dist/components/__test__/fixtures/dao.js.map +1 -0
- package/{lib → dist}/components/index.d.ts +5 -2
- package/dist/components/index.d.ts.map +1 -0
- package/{lib → dist}/components/index.js +1 -0
- package/dist/components/index.js.map +1 -0
- package/{lib → dist}/components/types/AbstractObjectClass.d.ts +1 -0
- package/dist/components/types/AbstractObjectClass.d.ts.map +1 -0
- package/dist/components/types/AbstractObjectClass.js +3 -0
- package/dist/components/types/AbstractObjectClass.js.map +1 -0
- package/{lib → dist}/components/types/BaseObjectClass.d.ts +1 -0
- package/dist/components/types/BaseObjectClass.d.ts.map +1 -0
- package/{lib → dist}/components/types/BaseObjectClass.js +1 -0
- package/dist/components/types/BaseObjectClass.js.map +1 -0
- package/{lib → dist}/components/types/BaseObjectType.d.ts +2 -1
- package/dist/components/types/BaseObjectType.d.ts.map +1 -0
- package/{lib → dist}/components/types/BaseObjectType.js +1 -0
- package/dist/components/types/BaseObjectType.js.map +1 -0
- package/{lib → dist}/components/types/DataObjectClass.d.ts +1 -0
- package/dist/components/types/DataObjectClass.d.ts.map +1 -0
- package/{lib → dist}/components/types/DataObjectClass.js +1 -0
- package/dist/components/types/DataObjectClass.js.map +1 -0
- package/dist/components/types/DataObjectParams.d.ts +8 -0
- package/dist/components/types/DataObjectParams.d.ts.map +1 -0
- package/dist/components/types/DataObjectParams.js +3 -0
- package/dist/components/types/DataObjectParams.js.map +1 -0
- package/{lib → dist}/components/types/DataObjectType.d.ts +1 -0
- package/dist/components/types/DataObjectType.d.ts.map +1 -0
- package/{lib → dist}/components/types/DataObjectType.js +1 -0
- package/dist/components/types/DataObjectType.js.map +1 -0
- package/{lib → dist}/components/types/EntityClass.d.ts +1 -0
- package/dist/components/types/EntityClass.d.ts.map +1 -0
- package/{lib → dist}/components/types/EntityClass.js +1 -0
- package/dist/components/types/EntityClass.js.map +1 -0
- package/{lib → dist}/components/types/Payload.d.ts +1 -0
- package/dist/components/types/Payload.d.ts.map +1 -0
- package/{lib → dist}/components/types/Payload.js +1 -0
- package/dist/components/types/Payload.js.map +1 -0
- package/{lib → dist}/components/types/Persisted.d.ts +1 -0
- package/dist/components/types/Persisted.d.ts.map +1 -0
- package/{lib → dist}/components/types/Persisted.js +1 -0
- package/dist/components/types/Persisted.js.map +1 -0
- package/dist/components/types/Properties.d.ts +2 -0
- package/dist/components/types/Properties.d.ts.map +1 -0
- package/{lib/components/types/AbstractObjectClass.js → dist/components/types/Properties.js} +1 -0
- package/dist/components/types/Properties.js.map +1 -0
- package/{lib → dist}/components/types/ProxyConstructor.d.ts +1 -0
- package/dist/components/types/ProxyConstructor.d.ts.map +1 -0
- package/{lib → dist}/components/types/ProxyConstructor.js +1 -0
- package/dist/components/types/ProxyConstructor.js.map +1 -0
- package/{lib → dist}/components/types/toJSONParams.d.ts +1 -0
- package/dist/components/types/toJSONParams.d.ts.map +1 -0
- package/{lib → dist}/components/types/toJSONParams.js +1 -0
- package/dist/components/types/toJSONParams.js.map +1 -0
- package/{lib → dist}/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -0
- package/{lib → dist}/index.js +4 -1
- package/dist/index.js.map +1 -0
- package/{lib → dist}/properties/ArrayProperty.d.ts +1 -0
- package/dist/properties/ArrayProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/ArrayProperty.js +5 -4
- package/dist/properties/ArrayProperty.js.map +1 -0
- package/{lib → dist}/properties/BaseProperty.d.ts +3 -2
- package/dist/properties/BaseProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/BaseProperty.js +18 -11
- package/dist/properties/BaseProperty.js.map +1 -0
- package/{lib → dist}/properties/BooleanProperty.d.ts +1 -0
- package/dist/properties/BooleanProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/BooleanProperty.js +2 -1
- package/dist/properties/BooleanProperty.js.map +1 -0
- package/{lib → dist}/properties/CollectionProperty.d.ts +1 -0
- package/dist/properties/CollectionProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/CollectionProperty.js +6 -4
- package/dist/properties/CollectionProperty.js.map +1 -0
- package/{lib → dist}/properties/DateTimeProperty.d.ts +1 -0
- package/dist/properties/DateTimeProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/DateTimeProperty.js +12 -5
- package/dist/properties/DateTimeProperty.js.map +1 -0
- package/{lib → dist}/properties/EnumProperty.d.ts +1 -0
- package/dist/properties/EnumProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/EnumProperty.js +4 -3
- package/dist/properties/EnumProperty.js.map +1 -0
- package/{lib → dist}/properties/FileProperty.d.ts +1 -0
- package/dist/properties/FileProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/FileProperty.js +3 -2
- package/dist/properties/FileProperty.js.map +1 -0
- package/{lib → dist}/properties/HashProperty.d.ts +2 -7
- package/dist/properties/HashProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/HashProperty.js +15 -23
- package/dist/properties/HashProperty.js.map +1 -0
- package/{lib → dist}/properties/MapProperty.d.ts +1 -0
- package/dist/properties/MapProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/MapProperty.js +2 -1
- package/dist/properties/MapProperty.js.map +1 -0
- package/{lib → dist}/properties/NumberProperty.d.ts +1 -0
- package/dist/properties/NumberProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/NumberProperty.js +15 -14
- package/dist/properties/NumberProperty.js.map +1 -0
- package/{lib → dist}/properties/ObjectProperty.d.ts +1 -0
- package/dist/properties/ObjectProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/ObjectProperty.js +4 -3
- package/dist/properties/ObjectProperty.js.map +1 -0
- package/{lib → dist}/properties/Property.d.ts +1 -0
- package/dist/properties/Property.d.ts.map +1 -0
- package/{lib → dist}/properties/Property.js +12 -11
- package/dist/properties/Property.js.map +1 -0
- package/{lib → dist}/properties/StringProperty.d.ts +3 -5
- package/dist/properties/StringProperty.d.ts.map +1 -0
- package/{lib → dist}/properties/StringProperty.js +20 -28
- package/dist/properties/StringProperty.js.map +1 -0
- package/{lib → dist}/properties/index.d.ts +4 -2
- package/dist/properties/index.d.ts.map +1 -0
- package/{lib → dist}/properties/index.js +1 -0
- package/dist/properties/index.js.map +1 -0
- package/{lib → dist}/properties/types/AbstractPropertyType.d.ts +1 -0
- package/dist/properties/types/AbstractPropertyType.d.ts.map +1 -0
- package/{lib → dist}/properties/types/AbstractPropertyType.js +1 -0
- package/dist/properties/types/AbstractPropertyType.js.map +1 -0
- package/{lib → dist}/properties/types/PropertyClassType.d.ts +1 -0
- package/dist/properties/types/PropertyClassType.d.ts.map +1 -0
- package/{lib → dist}/properties/types/PropertyClassType.js +1 -0
- package/dist/properties/types/PropertyClassType.js.map +1 -0
- package/{lib → dist}/properties/types/PropertyHTMLType.d.ts +1 -0
- package/dist/properties/types/PropertyHTMLType.d.ts.map +1 -0
- package/{lib → dist}/properties/types/PropertyHTMLType.js +1 -2
- package/dist/properties/types/PropertyHTMLType.js.map +1 -0
- package/{lib → dist}/properties/types/PropertyTypes.d.ts +1 -0
- package/dist/properties/types/PropertyTypes.d.ts.map +1 -0
- package/{lib → dist}/properties/types/PropertyTypes.js +1 -0
- package/dist/properties/types/PropertyTypes.js.map +1 -0
- package/package.json +47 -46
- package/src/Core.ts +145 -0
- package/src/common/DataGenerator.ts +81 -0
- package/src/common/ResourcesErrors.ts +17 -0
- package/src/common/statuses.ts +20 -0
- package/src/components/AbstractObject.ts +71 -0
- package/src/components/BaseObject.ts +123 -0
- package/src/components/BaseObjectProperties.ts +65 -0
- package/src/components/DataObject.ts +418 -0
- package/src/components/Entity.ts +38 -0
- package/src/components/ObjectUri.test.ts +74 -0
- package/src/components/ObjectUri.ts +174 -0
- package/src/components/User.ts +111 -0
- package/src/components/index.ts +19 -0
- package/src/components/types/AbstractObjectClass.ts +7 -0
- package/src/components/types/BaseObjectClass.ts +8 -0
- package/src/components/types/BaseObjectType.ts +10 -0
- package/src/components/types/DataObjectClass.ts +27 -0
- package/src/components/types/DataObjectParams.ts +8 -0
- package/src/components/types/DataObjectType.ts +27 -0
- package/src/components/types/EntityClass.ts +3 -0
- package/src/components/types/Payload.ts +11 -0
- package/src/components/types/Persisted.ts +7 -0
- package/src/components/types/Properties.ts +1 -0
- package/src/components/types/ProxyConstructor.ts +13 -0
- package/src/components/types/toJSONParams.ts +12 -0
- package/src/index.ts +97 -0
- package/src/properties/ArrayProperty.test.ts +46 -0
- package/src/properties/ArrayProperty.ts +87 -0
- package/src/properties/BaseProperty.test.ts +79 -0
- package/src/properties/BaseProperty.ts +140 -0
- package/src/properties/BooleanProperty.ts +11 -0
- package/src/properties/CollectionProperty.test.ts +22 -0
- package/src/properties/CollectionProperty.ts +43 -0
- package/src/properties/DateTimeProperty.ts +47 -0
- package/src/properties/EnumProperty.ts +36 -0
- package/src/properties/FileProperty.ts +14 -0
- package/src/properties/HashProperty.test.ts +108 -0
- package/src/properties/HashProperty.ts +70 -0
- package/src/properties/MapProperty.ts +19 -0
- package/src/properties/NumberProperty.test.ts +38 -0
- package/src/properties/NumberProperty.ts +110 -0
- package/src/properties/ObjectProperty.ts +118 -0
- package/src/properties/Property.ts +85 -0
- package/src/properties/StringProperty.test.ts +46 -0
- package/src/properties/StringProperty.ts +121 -0
- package/src/properties/index.ts +62 -0
- package/src/properties/types/AbstractPropertyType.ts +8 -0
- package/src/properties/types/PropertyClassType.ts +11 -0
- package/src/properties/types/PropertyHTMLType.ts +23 -0
- package/src/properties/types/PropertyTypes.ts +13 -0
- package/lib/Core.js +0 -133
- package/lib/components/BaseObject.js +0 -103
- package/lib/components/BaseObjectProperties.d.ts +0 -1
- package/lib/components/Entity.js +0 -71
- package/lib/components/types/Properties.d.ts +0 -3
- package/lib/components/types/Properties.js +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ObjectUri } from './ObjectUri'
|
|
2
|
+
|
|
3
|
+
describe('Object Uri', () => {
|
|
4
|
+
test('relative uri', () => {
|
|
5
|
+
const uri = new ObjectUri('collection/uid', 'a label')
|
|
6
|
+
//expect(uri.backend).toBe('@default')
|
|
7
|
+
expect(uri.path).toBe('collection/uid')
|
|
8
|
+
//expect(uri.literal).toBe('@default:collection/uid')
|
|
9
|
+
expect(uri.collection).toBe('collection')
|
|
10
|
+
expect(uri.uid).toBe('uid')
|
|
11
|
+
expect(uri.label).toBe('a label')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('relative uri with sub collection', () => {
|
|
15
|
+
const uri = new ObjectUri('collection/uid/subcollection/sid', 'a label')
|
|
16
|
+
//expect(uri.backend).toBe('@default')
|
|
17
|
+
// expect(uri.path).toBe('subcollection/sid')
|
|
18
|
+
// expect(uri.literal).toBe('@default:collection/uid/subcollection/sid')
|
|
19
|
+
expect(uri.collection).toBe('subcollection')
|
|
20
|
+
expect(uri.uid).toBe('sid')
|
|
21
|
+
expect(uri.label).toBe('a label')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('uri with backend', () => {
|
|
25
|
+
const uri = new ObjectUri('@backend:collection/uid', 'a label')
|
|
26
|
+
expect(uri.backend).toBe('@backend')
|
|
27
|
+
expect(uri.path).toBe('collection/uid')
|
|
28
|
+
expect(uri.literal).toBe('@backend:collection/uid')
|
|
29
|
+
expect(uri.collection).toBe('collection')
|
|
30
|
+
expect(uri.uid).toBe('uid')
|
|
31
|
+
expect(uri.label).toBe('a label')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('uri represents a subcollections-based path', () => {
|
|
35
|
+
const path = 'collection1/uid1/collection2/uid2/collection3/uid3'
|
|
36
|
+
const uri = new ObjectUri(path, 'a subcollections-based path')
|
|
37
|
+
//expect(uri.backend).toBe('@default')
|
|
38
|
+
// expect(uri.path).toBe('collection3/uid3')
|
|
39
|
+
// expect(uri.literal).toBe(`@default:${path}`)
|
|
40
|
+
expect(uri.collection).toBe('collection3')
|
|
41
|
+
expect(uri.uid).toBe('uid3')
|
|
42
|
+
expect(uri.parent).toBeInstanceOf(ObjectUri)
|
|
43
|
+
// expect(uri.parent?.literal).toBe('@default:collection1/uid1/collection2/uid2')
|
|
44
|
+
expect(uri.parent?.collection).toBe('collection2')
|
|
45
|
+
// expect(uri.parent?.path).toBe('collection2/uid2')
|
|
46
|
+
expect(uri.parent?.parent).toBeInstanceOf(ObjectUri)
|
|
47
|
+
// expect(uri.parent?.parent?.literal).toBe('@default:collection1/uid1')
|
|
48
|
+
expect(uri.parent?.parent?.collection).toBe('collection1')
|
|
49
|
+
expect(uri.parent?.parent?.path).toBe('collection1/uid1')
|
|
50
|
+
expect(uri.label).toBe('a subcollections-based path')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('uri points to file', () => {
|
|
54
|
+
const uri = new ObjectUri('@s3:path/to/file.ext', 'a file')
|
|
55
|
+
expect(uri.backend).toBe('@s3')
|
|
56
|
+
expect(uri.path).toBe('path/to/file.ext')
|
|
57
|
+
expect(uri.literal).toBe('@s3:path/to/file.ext')
|
|
58
|
+
expect(uri.collection).toBeUndefined()
|
|
59
|
+
expect(uri.uid).toBe('file.ext')
|
|
60
|
+
expect(uri.label).toBe('a file')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('uri without collection', () => {
|
|
64
|
+
const uri = new ObjectUri('uid')
|
|
65
|
+
// expect(uri.backend).toBe('@default')
|
|
66
|
+
expect(uri.path).toBe('uid')
|
|
67
|
+
//expect(uri.literal).toBe(`@default:${ObjectUri.MISSING_COLLECTION}/uid`)
|
|
68
|
+
expect(uri.collection).toBeUndefined()
|
|
69
|
+
expect(uri.uid).toBe('uid')
|
|
70
|
+
|
|
71
|
+
uri.collection = 'collection'
|
|
72
|
+
expect(uri.collection).toBe('collection')
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export class ObjectUri {
|
|
2
|
+
static DEFAULT = '/'
|
|
3
|
+
static MISSING_COLLECTION = '_?_'
|
|
4
|
+
|
|
5
|
+
protected _str: string
|
|
6
|
+
protected _pairs: Array<string> = []
|
|
7
|
+
protected _literal: string = ''
|
|
8
|
+
protected _backend: string | undefined
|
|
9
|
+
protected _path: string = ObjectUri.DEFAULT
|
|
10
|
+
protected _uid: string | undefined = undefined
|
|
11
|
+
protected _collection: string | undefined = undefined
|
|
12
|
+
protected _label: string | undefined = ''
|
|
13
|
+
protected _objClass: any
|
|
14
|
+
protected _parent: ObjectUri | undefined
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* create object uri from string:
|
|
18
|
+
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
19
|
+
* some backends will need a collection or table name, some may deduct it from object
|
|
20
|
+
* @param str partial or full resource path
|
|
21
|
+
* @param label optional label to describe path
|
|
22
|
+
*/
|
|
23
|
+
constructor(str: string = '', label: string | undefined = '') {
|
|
24
|
+
this._str = str
|
|
25
|
+
this._label = label
|
|
26
|
+
if (str.includes(':')) {
|
|
27
|
+
const [backend, path] = str.split(':')
|
|
28
|
+
this._backend = backend
|
|
29
|
+
this._path = path
|
|
30
|
+
} else {
|
|
31
|
+
this._path = str
|
|
32
|
+
}
|
|
33
|
+
const parts = this._path.split(ObjectUri.DEFAULT)
|
|
34
|
+
const isFilePath = parts[parts.length - 1].indexOf('.') !== -1
|
|
35
|
+
|
|
36
|
+
if (isFilePath) {
|
|
37
|
+
this._uid = parts[parts.length - 1]
|
|
38
|
+
} else if (parts.length === 1) {
|
|
39
|
+
// It is allowed to only give the uid part of the uri
|
|
40
|
+
// provided that collection will be injected by another means
|
|
41
|
+
this._uid = parts[0].length > 0 ? parts[0] : undefined
|
|
42
|
+
this._collection = ObjectUri.MISSING_COLLECTION
|
|
43
|
+
this._pairs.push(
|
|
44
|
+
`${ObjectUri.MISSING_COLLECTION}${ObjectUri.DEFAULT}${this._uid}`
|
|
45
|
+
)
|
|
46
|
+
this._label = label || this._uid
|
|
47
|
+
} else if (parts.length % 2 === 0) {
|
|
48
|
+
this._path = parts.slice(parts.length - 2).join(ObjectUri.DEFAULT)
|
|
49
|
+
this._uid = parts[parts.length - 1]
|
|
50
|
+
this._collection = parts[parts.length - 2]
|
|
51
|
+
if (parts.length > 2) {
|
|
52
|
+
this._parent = new ObjectUri(
|
|
53
|
+
parts.slice(0, parts.length - 2).join(ObjectUri.DEFAULT)
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
this._label = label || this._uid
|
|
57
|
+
} else if (!isFilePath) {
|
|
58
|
+
// if the last part is not a filename with extension, throw error
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Path parts number must be 1 or even, received: '${str}'`
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
set class(objClass: any) {
|
|
66
|
+
this._objClass = objClass
|
|
67
|
+
if (objClass) {
|
|
68
|
+
this._collection =
|
|
69
|
+
objClass.COLLECTION ||
|
|
70
|
+
(objClass.name && objClass.name.toLowerCase())
|
|
71
|
+
} else {
|
|
72
|
+
this._collection = undefined
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get class() {
|
|
77
|
+
return this._objClass
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get backend() {
|
|
81
|
+
return this._backend
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the full path of the resource
|
|
86
|
+
* including optional parents' path
|
|
87
|
+
* @returns string
|
|
88
|
+
*/
|
|
89
|
+
get path() {
|
|
90
|
+
return this._parent
|
|
91
|
+
? `${this._parent.path}${ObjectUri.DEFAULT}${this._path}`
|
|
92
|
+
: this._path
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Returns the own path of the resource
|
|
97
|
+
* without the optional parents' paths
|
|
98
|
+
* @returns string
|
|
99
|
+
*/
|
|
100
|
+
get ownPath() {
|
|
101
|
+
return this._path
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get parent() {
|
|
105
|
+
return this._parent
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
set label(label: string | undefined) {
|
|
109
|
+
this._label = label
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get label() {
|
|
113
|
+
return this._label
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Return the full path litteral
|
|
118
|
+
* including the backend alias
|
|
119
|
+
* @returns string
|
|
120
|
+
*/
|
|
121
|
+
get literal() {
|
|
122
|
+
return this._str.includes(':')
|
|
123
|
+
? this._str
|
|
124
|
+
: `${this._backend}:${this._str}`
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
set path(path: string) {
|
|
128
|
+
// if (this._path && this._path !== ObjectUri.DEFAULT) {
|
|
129
|
+
// throw new Error(`Path value already set with '${this._path}'`)
|
|
130
|
+
// }
|
|
131
|
+
this._path = path
|
|
132
|
+
// TODO manage paths to subcollection
|
|
133
|
+
this._collection = path.split('/')[0]
|
|
134
|
+
this._literal = `${this._backend}:${this._path}`
|
|
135
|
+
this._uid = path.split('/').pop()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get uid() {
|
|
139
|
+
return this._uid
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get collection(): string | undefined {
|
|
143
|
+
return this._collection === ObjectUri.MISSING_COLLECTION
|
|
144
|
+
? undefined
|
|
145
|
+
: this._collection
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
set collection(collection: string | undefined) {
|
|
149
|
+
if (this.collection !== undefined) {
|
|
150
|
+
throw new Error('Collection value already set')
|
|
151
|
+
}
|
|
152
|
+
this._collection = collection
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Return references to find object locally and remotely
|
|
157
|
+
* @returns object
|
|
158
|
+
*/
|
|
159
|
+
toReference() {
|
|
160
|
+
return {
|
|
161
|
+
ref: this.path,
|
|
162
|
+
uri: this._literal,
|
|
163
|
+
label: this._label,
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
toJSON() {
|
|
168
|
+
return {
|
|
169
|
+
backend: this._backend,
|
|
170
|
+
ref: this.path,
|
|
171
|
+
label: this._label || '',
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BaseObject } from './BaseObject'
|
|
2
|
+
import { DataObjectClass } from './types/DataObjectClass'
|
|
3
|
+
import { DateTimeProperty, EnumProperty, ObjectProperty } from '../properties'
|
|
4
|
+
import { HashProperty } from '../properties/HashProperty'
|
|
5
|
+
import { StringProperty } from '../properties/StringProperty'
|
|
6
|
+
import * as htmlType from '../properties/types/PropertyHTMLType'
|
|
7
|
+
import { BaseObjectProperties } from './BaseObjectProperties'
|
|
8
|
+
import { BaseObjectType } from './types/BaseObjectType'
|
|
9
|
+
|
|
10
|
+
export interface UserType extends BaseObjectType {
|
|
11
|
+
firstname: string
|
|
12
|
+
lastname: string
|
|
13
|
+
gender?: 'male' | 'female' | 'nonbinary'
|
|
14
|
+
birthday?: Date
|
|
15
|
+
password: string
|
|
16
|
+
email: string
|
|
17
|
+
[x: string]: any
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Callback function to populate the 'name' property
|
|
22
|
+
* @param dao DataObject
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
const onChange = (dao: DataObjectClass<any>) =>
|
|
26
|
+
dao.set('name', `${dao.val('firstname')} ${dao.val('lastname')}`)
|
|
27
|
+
|
|
28
|
+
export const UserProperties: any = [
|
|
29
|
+
...BaseObjectProperties,
|
|
30
|
+
{
|
|
31
|
+
// change name property minLength
|
|
32
|
+
name: 'name',
|
|
33
|
+
type: StringProperty.TYPE,
|
|
34
|
+
minLength: 0,
|
|
35
|
+
htmlType: htmlType.NAME,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'firstname',
|
|
39
|
+
mandatory: true,
|
|
40
|
+
type: StringProperty.TYPE,
|
|
41
|
+
minLength: 1,
|
|
42
|
+
maxLength: 100,
|
|
43
|
+
fullSearch: true,
|
|
44
|
+
htmlType: htmlType.GIVEN_NAME,
|
|
45
|
+
onChange,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'lastname',
|
|
49
|
+
mandatory: true,
|
|
50
|
+
type: StringProperty.TYPE,
|
|
51
|
+
minLength: 1,
|
|
52
|
+
maxLength: 100,
|
|
53
|
+
fullSearch: true,
|
|
54
|
+
htmlType: htmlType.FAMILY_NAME,
|
|
55
|
+
onChange,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'gender',
|
|
59
|
+
mandatory: false,
|
|
60
|
+
type: EnumProperty.TYPE,
|
|
61
|
+
values: ['male', 'female', 'nonbinary'],
|
|
62
|
+
htmlType: htmlType.GENDER,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'birthday',
|
|
66
|
+
mandatory: false,
|
|
67
|
+
type: DateTimeProperty.TYPE,
|
|
68
|
+
htmlType: htmlType.BIRTHDAY,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'email',
|
|
72
|
+
mandatory: true,
|
|
73
|
+
type: StringProperty.TYPE,
|
|
74
|
+
minLength: 1,
|
|
75
|
+
maxLength: 100,
|
|
76
|
+
fullSearch: true,
|
|
77
|
+
htmlType: htmlType.EMAIL,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'phone',
|
|
81
|
+
type: StringProperty.TYPE,
|
|
82
|
+
minLength: 1,
|
|
83
|
+
maxLength: 100,
|
|
84
|
+
htmlType: htmlType.OFF,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'password',
|
|
88
|
+
mandatory: true,
|
|
89
|
+
type: HashProperty.TYPE,
|
|
90
|
+
algorithm: HashProperty.ALGORITHM_SHA256,
|
|
91
|
+
salt: '', // you should override it in your code
|
|
92
|
+
minLength: 5,
|
|
93
|
+
maxLength: 20, // this is for the clear password
|
|
94
|
+
htmlType: htmlType.PASSWORD,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'entity',
|
|
98
|
+
mandatory: false,
|
|
99
|
+
type: ObjectProperty.TYPE,
|
|
100
|
+
instanceOf: 'Entity',
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
export class User extends BaseObject {
|
|
105
|
+
static PROPS_DEFINITION = UserProperties
|
|
106
|
+
static COLLECTION = 'user'
|
|
107
|
+
|
|
108
|
+
static async factory(src: any = undefined): Promise<User> {
|
|
109
|
+
return super.factory(src, User)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataObject } from './DataObject'
|
|
2
|
+
import { DataObjectClass } from './types/DataObjectClass'
|
|
3
|
+
import { DataObjectParams } from './types/DataObjectParams'
|
|
4
|
+
import { ObjectUri } from './ObjectUri'
|
|
5
|
+
import { AbstractObject } from './AbstractObject'
|
|
6
|
+
import { BaseObjectProperties } from './BaseObjectProperties'
|
|
7
|
+
import { User, UserProperties } from './User'
|
|
8
|
+
import { Entity } from './Entity'
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
DataObject,
|
|
12
|
+
ObjectUri,
|
|
13
|
+
AbstractObject,
|
|
14
|
+
User,
|
|
15
|
+
Entity,
|
|
16
|
+
BaseObjectProperties,
|
|
17
|
+
UserProperties,
|
|
18
|
+
}
|
|
19
|
+
export type { DataObjectParams, DataObjectClass }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PropertyClassType } from '../../properties/types/PropertyClassType'
|
|
2
|
+
import { ObjectUri } from '../ObjectUri'
|
|
3
|
+
import { toJSONParams } from './toJSONParams'
|
|
4
|
+
|
|
5
|
+
export interface DataObjectClass<T extends DataObjectClass<any>> {
|
|
6
|
+
uri: ObjectUri
|
|
7
|
+
uid: any
|
|
8
|
+
path: any
|
|
9
|
+
class: any
|
|
10
|
+
properties: any
|
|
11
|
+
parentProp: string | undefined
|
|
12
|
+
|
|
13
|
+
setProperties(properties: any): void
|
|
14
|
+
getProperties(type: any): any
|
|
15
|
+
addProperty(property: PropertyClassType): void
|
|
16
|
+
populate(data?: any): Promise<T>
|
|
17
|
+
isPopulated(): boolean
|
|
18
|
+
has(key: string): boolean
|
|
19
|
+
get(key: string): any
|
|
20
|
+
set(key: string, val: any): any
|
|
21
|
+
val(key: string): any
|
|
22
|
+
clone(data?: any): Promise<T>
|
|
23
|
+
toReference(): any
|
|
24
|
+
toJSON(params?: boolean | toJSONParams): any
|
|
25
|
+
populateFromData(data: { [x: string]: unknown }): this
|
|
26
|
+
asProxy(): any
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PropertyClassType } from '../../properties/types/PropertyClassType'
|
|
2
|
+
import { ObjectUri } from '../ObjectUri'
|
|
3
|
+
import { toJSONParams } from './toJSONParams'
|
|
4
|
+
|
|
5
|
+
export interface DataObjectType {
|
|
6
|
+
uri: ObjectUri
|
|
7
|
+
uid: any
|
|
8
|
+
path: any
|
|
9
|
+
class: any
|
|
10
|
+
properties: any
|
|
11
|
+
parentProp: string | undefined
|
|
12
|
+
|
|
13
|
+
setProperties(properties: any): void
|
|
14
|
+
getProperties(type: any): any
|
|
15
|
+
addProperty(property: PropertyClassType): void
|
|
16
|
+
populate(data?: any): Promise<any>
|
|
17
|
+
isPopulated(): boolean
|
|
18
|
+
has(key: string): boolean
|
|
19
|
+
get(key: string): any
|
|
20
|
+
set(key: string, val: any): any
|
|
21
|
+
val(key: string): any
|
|
22
|
+
clone(data?: any): Promise<any>
|
|
23
|
+
toReference(): any
|
|
24
|
+
toJSON(params?: boolean | toJSONParams): any
|
|
25
|
+
populateFromData(data: { [x: string]: unknown }): this
|
|
26
|
+
asProxy(): any
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type Properties<T> = { name: keyof T }[]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseObjectClass } from './BaseObjectClass'
|
|
2
|
+
|
|
3
|
+
interface ProxyConstructor {
|
|
4
|
+
new <T extends object, H>(target: T, handler: ProxyHandler<T>): Proxy<H>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const ProxyConstructor = Proxy as ProxyConstructor
|
|
8
|
+
|
|
9
|
+
export type Proxy<T> = T & {
|
|
10
|
+
readonly toJSON: () => object
|
|
11
|
+
readonly core: BaseObjectClass
|
|
12
|
+
//save: () => Promise<void>
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type toJSONParams = {
|
|
2
|
+
// Return objects as references
|
|
3
|
+
objectsAsReferences?: boolean
|
|
4
|
+
// Exclude URI data (uid, patch, etc.)
|
|
5
|
+
withoutURIData?: boolean
|
|
6
|
+
// Ignore property which value has not been changed
|
|
7
|
+
ignoreUnchanged?: boolean
|
|
8
|
+
// Ignore property which value is null
|
|
9
|
+
ignoreNulls?: boolean
|
|
10
|
+
// map of property values converters
|
|
11
|
+
converters?: { [propType: string]: Function }
|
|
12
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Core } from './Core'
|
|
2
|
+
import * as statuses from './common/statuses'
|
|
3
|
+
import { Property } from './properties/Property'
|
|
4
|
+
import { BaseProperty, BasePropertyType } from './properties/BaseProperty'
|
|
5
|
+
import { StringProperty, StringPropertyType } from './properties/StringProperty'
|
|
6
|
+
import { NumberProperty, NumberPropertyType } from './properties/NumberProperty'
|
|
7
|
+
import { EnumProperty, EnumPropertyType } from './properties/EnumProperty'
|
|
8
|
+
import {
|
|
9
|
+
BooleanProperty,
|
|
10
|
+
BooleanPropertyType,
|
|
11
|
+
} from './properties/BooleanProperty'
|
|
12
|
+
import {
|
|
13
|
+
ObjectProperty,
|
|
14
|
+
ObjectPropertyType,
|
|
15
|
+
returnAs,
|
|
16
|
+
} from './properties/ObjectProperty'
|
|
17
|
+
import {
|
|
18
|
+
DateTimeProperty,
|
|
19
|
+
DateTimePropertyType,
|
|
20
|
+
} from './properties/DateTimeProperty'
|
|
21
|
+
import { HashProperty, HashPropertyType } from './properties/HashProperty'
|
|
22
|
+
import {
|
|
23
|
+
CollectionProperty,
|
|
24
|
+
CollectionPropertyType,
|
|
25
|
+
} from './properties/CollectionProperty'
|
|
26
|
+
import { ArrayProperty, ArrayPropertyType } from './properties/ArrayProperty'
|
|
27
|
+
import { AbstractObject } from './components/AbstractObject'
|
|
28
|
+
import { ObjectUri } from './components/ObjectUri'
|
|
29
|
+
import { DataObjectClass } from './components/types/DataObjectClass'
|
|
30
|
+
import { DataObject } from './components/DataObject'
|
|
31
|
+
import { DataObjectProperties } from './properties'
|
|
32
|
+
import { BaseObject } from './components/BaseObject'
|
|
33
|
+
import { BaseObjectProperties } from './components/BaseObjectProperties'
|
|
34
|
+
import { BaseObjectType } from './components/types/BaseObjectType'
|
|
35
|
+
import { Proxy } from './components/types/ProxyConstructor'
|
|
36
|
+
|
|
37
|
+
import { UserType, User, UserProperties } from './components/User'
|
|
38
|
+
import { EntityType, Entity } from './components/Entity'
|
|
39
|
+
|
|
40
|
+
import {
|
|
41
|
+
BadRequestError,
|
|
42
|
+
UnauthorizedError,
|
|
43
|
+
ForbiddenError,
|
|
44
|
+
NotFoundError,
|
|
45
|
+
GoneError,
|
|
46
|
+
} from './common/ResourcesErrors'
|
|
47
|
+
import { DataObjectParams } from './components/types/DataObjectParams'
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
statuses,
|
|
51
|
+
Core,
|
|
52
|
+
Property,
|
|
53
|
+
BaseProperty,
|
|
54
|
+
BooleanProperty,
|
|
55
|
+
DateTimeProperty,
|
|
56
|
+
EnumProperty,
|
|
57
|
+
HashProperty,
|
|
58
|
+
CollectionProperty,
|
|
59
|
+
ArrayProperty,
|
|
60
|
+
ObjectProperty,
|
|
61
|
+
NumberProperty,
|
|
62
|
+
returnAs,
|
|
63
|
+
StringProperty,
|
|
64
|
+
ObjectUri,
|
|
65
|
+
DataObject,
|
|
66
|
+
AbstractObject,
|
|
67
|
+
BaseObject,
|
|
68
|
+
BaseObjectProperties,
|
|
69
|
+
User,
|
|
70
|
+
UserProperties,
|
|
71
|
+
Entity,
|
|
72
|
+
BadRequestError,
|
|
73
|
+
UnauthorizedError,
|
|
74
|
+
ForbiddenError,
|
|
75
|
+
NotFoundError,
|
|
76
|
+
GoneError,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type {
|
|
80
|
+
BasePropertyType,
|
|
81
|
+
BooleanPropertyType,
|
|
82
|
+
DataObjectParams,
|
|
83
|
+
DateTimePropertyType,
|
|
84
|
+
EnumPropertyType,
|
|
85
|
+
HashPropertyType,
|
|
86
|
+
CollectionPropertyType,
|
|
87
|
+
ArrayPropertyType,
|
|
88
|
+
ObjectPropertyType,
|
|
89
|
+
NumberPropertyType,
|
|
90
|
+
StringPropertyType,
|
|
91
|
+
DataObjectClass,
|
|
92
|
+
DataObjectProperties,
|
|
93
|
+
BaseObjectType,
|
|
94
|
+
UserType,
|
|
95
|
+
Proxy,
|
|
96
|
+
EntityType,
|
|
97
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ArrayProperty } from './ArrayProperty'
|
|
2
|
+
import { StringProperty } from './StringProperty'
|
|
3
|
+
|
|
4
|
+
const arrayValue = ['ab', 'cd', 'ef']
|
|
5
|
+
const transformer = (array: Array<string>) => array.join()
|
|
6
|
+
|
|
7
|
+
describe('Array Property without digits', () => {
|
|
8
|
+
const prop = new ArrayProperty({ name: 'toto', allowNumbers: false })
|
|
9
|
+
test('allow numbers is not set', () =>
|
|
10
|
+
expect(prop.allows).not.toContain(StringProperty.ALLOW_NUMBERS))
|
|
11
|
+
test('no numbers allowed', () => expect(() => prop.set([123])).toThrow())
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('Array Property without strings', () => {
|
|
15
|
+
const prop = new ArrayProperty({ name: 'toto', allowStrings: false })
|
|
16
|
+
test('allow strings is not set', () =>
|
|
17
|
+
expect(prop.allows).not.toContain(StringProperty.ALLOW_STRINGS))
|
|
18
|
+
test('no strings allowed', () => expect(() => prop.set(['value'])).toThrow())
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
describe('Array Property with minimal length', () => {
|
|
22
|
+
const prop = new ArrayProperty({ name: 'toto', minLength: 3 })
|
|
23
|
+
test('minlength is set', () => expect(prop.minLength).toBeGreaterThan(0))
|
|
24
|
+
test('minimum length of 3', () =>
|
|
25
|
+
expect(() => prop.set(['value', 123])).toThrow())
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('Array Property with maximal length', () => {
|
|
29
|
+
const prop = new ArrayProperty({ name: 'toto', maxLength: 2 })
|
|
30
|
+
test('maxlength is set', () => expect(prop.maxLength).toBeGreaterThan(0))
|
|
31
|
+
test('maximum length of 2', () =>
|
|
32
|
+
expect(() => prop.set(['value', 123, 'blue'])).toThrow())
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('Array Property returns array', () => {
|
|
36
|
+
const prop = new ArrayProperty({ name: 'toto' })
|
|
37
|
+
test('transform array to string', () =>
|
|
38
|
+
expect(prop.set(arrayValue).get()).toBe(arrayValue))
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// describe('Array Property supports registered transformer', () => {
|
|
42
|
+
// const prop = new ArrayProperty({ name: 'toto' })
|
|
43
|
+
// //prop.addTransformer(transformer)
|
|
44
|
+
// test('transform array to string', () =>
|
|
45
|
+
// expect(prop.set(arrayValue).get()).toBe('abcdef'))
|
|
46
|
+
// })
|