@quatrain/core 1.0.0-beta11 → 1.0.0-beta13

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,19 +10,38 @@ 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;
25
+ /**
26
+ * Returns the full path of the resource
27
+ * including optional parents' path
28
+ * @returns string
29
+ */
23
30
  get path(): string;
31
+ /**
32
+ * Returns the own path of the resource
33
+ * without the optional parents' paths
34
+ * @returns string
35
+ */
36
+ get ownPath(): string;
37
+ get parent(): ObjectUri | undefined;
24
38
  set label(label: string | undefined);
25
39
  get label(): string | undefined;
40
+ /**
41
+ * Return the full path litteral
42
+ * including the backend alias
43
+ * @returns string
44
+ */
26
45
  get literal(): string;
27
46
  set path(path: string);
28
47
  get uid(): string | undefined;
@@ -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
- 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 if (parts[parts.length - 1].indexOf('.') === -1) {
51
- // if the last part is not a filenma with extension, throw error
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
  }
@@ -69,17 +72,42 @@ class ObjectUri {
69
72
  get backend() {
70
73
  return this._backend;
71
74
  }
75
+ /**
76
+ * Returns the full path of the resource
77
+ * including optional parents' path
78
+ * @returns string
79
+ */
72
80
  get path() {
81
+ return this._parent
82
+ ? `${this._parent.path}${ObjectUri.DEFAULT}${this._path}`
83
+ : this._path;
84
+ }
85
+ /**
86
+ * Returns the own path of the resource
87
+ * without the optional parents' paths
88
+ * @returns string
89
+ */
90
+ get ownPath() {
73
91
  return this._path;
74
92
  }
93
+ get parent() {
94
+ return this._parent;
95
+ }
75
96
  set label(label) {
76
97
  this._label = label;
77
98
  }
78
99
  get label() {
79
100
  return this._label;
80
101
  }
102
+ /**
103
+ * Return the full path litteral
104
+ * including the backend alias
105
+ * @returns string
106
+ */
81
107
  get literal() {
82
- return `${this._backend}:${this._pairs.join(ObjectUri.DEFAULT)}`;
108
+ return this._str.includes(':')
109
+ ? this._str
110
+ : `${this._backend}:${this._str}`;
83
111
  }
84
112
  set path(path) {
85
113
  // 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-beta11",
3
+ "version": "1.0.0-beta13",
4
4
  "description": "Core objects for business apps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",