@quatrain/core 1.0.0-beta11 → 1.0.0-beta12
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.
|
@@ -10,17 +10,20 @@ export declare class ObjectUri {
|
|
|
10
10
|
protected _collection: string | undefined;
|
|
11
11
|
protected _label: string | undefined;
|
|
12
12
|
protected _objClass: any;
|
|
13
|
+
protected _parent: ObjectUri | undefined;
|
|
13
14
|
/**
|
|
14
15
|
* create object uri from string:
|
|
15
16
|
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
16
17
|
* some backends will need a collection or table name, some may deduct it from object
|
|
17
|
-
* @param str
|
|
18
|
+
* @param str partial or full resource path
|
|
19
|
+
* @param label optional label to describe path
|
|
18
20
|
*/
|
|
19
21
|
constructor(str?: string, label?: string | undefined);
|
|
20
22
|
set class(objClass: any);
|
|
21
23
|
get class(): any;
|
|
22
24
|
get backend(): string;
|
|
23
25
|
get path(): string;
|
|
26
|
+
get parent(): ObjectUri | undefined;
|
|
24
27
|
set label(label: string | undefined);
|
|
25
28
|
get label(): string | undefined;
|
|
26
29
|
get literal(): string;
|
|
@@ -7,7 +7,8 @@ class ObjectUri {
|
|
|
7
7
|
* create object uri from string:
|
|
8
8
|
* ex: 'xyz', '@backend:xyz', 'collection/xyz', '@backend:collection/xyz'
|
|
9
9
|
* some backends will need a collection or table name, some may deduct it from object
|
|
10
|
-
* @param str
|
|
10
|
+
* @param str partial or full resource path
|
|
11
|
+
* @param label optional label to describe path
|
|
11
12
|
*/
|
|
12
13
|
constructor(str = '', label = '') {
|
|
13
14
|
this._pairs = [];
|
|
@@ -28,27 +29,29 @@ class ObjectUri {
|
|
|
28
29
|
this._path = str;
|
|
29
30
|
}
|
|
30
31
|
const parts = this._path.split(ObjectUri.DEFAULT);
|
|
31
|
-
|
|
32
|
+
const isFilePath = parts[parts.length - 1].indexOf('.') !== -1;
|
|
33
|
+
if (isFilePath) {
|
|
34
|
+
this._uid = parts[parts.length - 1];
|
|
35
|
+
}
|
|
36
|
+
else if (parts.length === 1) {
|
|
32
37
|
// It is allowed to only give the uid part of the uri
|
|
33
|
-
// provided that collection will be injected by another
|
|
38
|
+
// provided that collection will be injected by another means
|
|
34
39
|
this._uid = parts[0].length > 0 ? parts[0] : undefined;
|
|
35
40
|
this._collection = ObjectUri.MISSING_COLLECTION;
|
|
36
41
|
this._pairs.push(`${ObjectUri.MISSING_COLLECTION}${ObjectUri.DEFAULT}${this._uid}`);
|
|
37
42
|
this._label = label || this._uid;
|
|
38
43
|
}
|
|
39
44
|
else if (parts.length % 2 === 0) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
this._pairs.push(`${parts[i]}${ObjectUri.DEFAULT}${parts[i + 1]}`);
|
|
46
|
-
i += 2;
|
|
45
|
+
this._path = parts.slice(parts.length - 2).join(ObjectUri.DEFAULT);
|
|
46
|
+
this._uid = parts[parts.length - 1];
|
|
47
|
+
this._collection = parts[parts.length - 2];
|
|
48
|
+
if (parts.length > 2) {
|
|
49
|
+
this._parent = new ObjectUri(parts.slice(0, parts.length - 2).join(ObjectUri.DEFAULT));
|
|
47
50
|
}
|
|
48
51
|
this._label = label || this._uid;
|
|
49
52
|
}
|
|
50
|
-
else if (
|
|
51
|
-
// if the last part is not a
|
|
53
|
+
else if (!isFilePath) {
|
|
54
|
+
// if the last part is not a filename with extension, throw error
|
|
52
55
|
throw new Error(`Path parts number must be 1 or even, received: '${str}'`);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -72,6 +75,9 @@ class ObjectUri {
|
|
|
72
75
|
get path() {
|
|
73
76
|
return this._path;
|
|
74
77
|
}
|
|
78
|
+
get parent() {
|
|
79
|
+
return this._parent;
|
|
80
|
+
}
|
|
75
81
|
set label(label) {
|
|
76
82
|
this._label = label;
|
|
77
83
|
}
|
|
@@ -79,7 +85,9 @@ class ObjectUri {
|
|
|
79
85
|
return this._label;
|
|
80
86
|
}
|
|
81
87
|
get literal() {
|
|
82
|
-
return
|
|
88
|
+
return this._str.includes(':')
|
|
89
|
+
? this._str
|
|
90
|
+
: `${this._backend}:${this._str}`;
|
|
83
91
|
}
|
|
84
92
|
set path(path) {
|
|
85
93
|
// if (this._path && this._path !== ObjectUri.DEFAULT) {
|