@quatrain/core 1.0.0-beta10 → 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,33 +29,38 @@ class ObjectUri {
28
29
  this._path = str;
29
30
  }
30
31
  const parts = this._path.split(ObjectUri.DEFAULT);
31
- if (parts.length === 1) {
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 mean
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
- // General case is a path containing pairs of collection/uid
41
- let i = 0;
42
- while (i < parts.length) {
43
- this._collection = parts[i];
44
- this._uid = parts[i + 1];
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 {
53
+ else if (!isFilePath) {
54
+ // if the last part is not a filename with extension, throw error
51
55
  throw new Error(`Path parts number must be 1 or even, received: '${str}'`);
52
56
  }
53
57
  }
54
58
  set class(objClass) {
55
59
  this._objClass = objClass;
56
60
  if (objClass) {
57
- this._collection = objClass.COLLECTION || objClass.name && objClass.name.toLowerCase();
61
+ this._collection =
62
+ objClass.COLLECTION ||
63
+ (objClass.name && objClass.name.toLowerCase());
58
64
  }
59
65
  else {
60
66
  this._collection = undefined;
@@ -69,6 +75,9 @@ class ObjectUri {
69
75
  get path() {
70
76
  return this._path;
71
77
  }
78
+ get parent() {
79
+ return this._parent;
80
+ }
72
81
  set label(label) {
73
82
  this._label = label;
74
83
  }
@@ -76,7 +85,9 @@ class ObjectUri {
76
85
  return this._label;
77
86
  }
78
87
  get literal() {
79
- return `${this._backend}:${this._pairs.join(ObjectUri.DEFAULT)}`;
88
+ return this._str.includes(':')
89
+ ? this._str
90
+ : `${this._backend}:${this._str}`;
80
91
  }
81
92
  set path(path) {
82
93
  // if (this._path && this._path !== ObjectUri.DEFAULT) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/core",
3
- "version": "1.0.0-beta10",
3
+ "version": "1.0.0-beta12",
4
4
  "description": "Core objects for business apps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",