@takeshape/util 11.76.0 → 11.76.2
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/dist/common/takeshape-id.d.ts +11 -5
- package/dist/common/takeshape-id.js +16 -15
- package/package.json +2 -2
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AKA TID. A unique ID that refers to an object in the TakeShape data index.
|
|
3
3
|
*/
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type TakeShapeId = `tid:${string}`;
|
|
5
|
+
/**
|
|
6
|
+
* Pattern to match a TakeShapeId. Note that colons are allowed in the ID part of the TID.
|
|
7
|
+
* For example, `tid:rick:Character:gid://foo` is valid and the ID part is `gid://foo`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TID_REGEX: RegExp;
|
|
10
|
+
export type ParsedTakeShapeId = {
|
|
11
|
+
shapeRef: string;
|
|
12
|
+
serviceId: string;
|
|
7
13
|
shapeName: string;
|
|
8
14
|
id: string;
|
|
9
15
|
};
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
16
|
+
export declare const parseTid: (tid: string) => ParsedTakeShapeId;
|
|
17
|
+
export declare const extractTids: (input: string) => TakeShapeId[];
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pattern to match a
|
|
2
|
+
* Pattern to match a TakeShapeId. Note that colons are allowed in the ID part of the TID.
|
|
3
3
|
* For example, `tid:rick:Character:gid://foo` is valid and the ID part is `gid://foo`.
|
|
4
4
|
*/
|
|
5
|
-
const TID_REGEX = /\btid:([^:\s]+):([^:\s]+):([
|
|
6
|
-
export const
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
throw new Error(`Invalid TID: ${tid}`);
|
|
5
|
+
export const TID_REGEX = /\btid:([^:\s]+):([^:\s]+):([\w\\/:-_~]+)/;
|
|
6
|
+
export const parseTid = (tid) => {
|
|
7
|
+
const match = TID_REGEX.exec(tid);
|
|
8
|
+
if (!match) {
|
|
9
|
+
throw new Error(`Invalid TID: "${tid}"`);
|
|
10
10
|
}
|
|
11
|
+
const [, serviceId, shapeName, id] = match;
|
|
11
12
|
return {
|
|
12
|
-
|
|
13
|
+
shapeRef: `${serviceId}:${shapeName}`,
|
|
14
|
+
serviceId: serviceId,
|
|
13
15
|
shapeName,
|
|
14
|
-
id
|
|
16
|
+
id
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
|
-
export const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
match = TID_REGEX.exec(input);
|
|
19
|
+
export const extractTids = (input) => {
|
|
20
|
+
const ids = [];
|
|
21
|
+
const matches = input.matchAll(new RegExp(TID_REGEX.source, 'g'));
|
|
22
|
+
for (const match of matches) {
|
|
23
|
+
ids.push(match[0]);
|
|
23
24
|
}
|
|
24
|
-
return
|
|
25
|
+
return ids;
|
|
25
26
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "11.76.
|
|
3
|
+
"version": "11.76.2",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"tiny-invariant": "^1.2.0",
|
|
47
47
|
"uint8array-extras": "^1.4.0",
|
|
48
48
|
"url-parse": "^1.5.3",
|
|
49
|
-
"@takeshape/routing": "11.76.
|
|
49
|
+
"@takeshape/routing": "11.76.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/classnames": "^2.2.9",
|