@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.
@@ -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 TakeShapeID = `tid:${string}`;
5
- export type ParsedTakeshapeID = {
6
- service: string;
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 parseTakeShapeID: (tid: string) => ParsedTakeshapeID;
11
- export declare const extractTakeShapeIDs: (input: string) => TakeShapeID[];
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 TakeShapeID. Note that colons are allowed in the ID part of the TID.
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]+):([^\s]+)/g;
6
- export const parseTakeShapeID = (tid) => {
7
- const [prefix, service, shapeName, ...rest] = tid.split(':');
8
- if (prefix !== 'tid') {
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
- service,
13
+ shapeRef: `${serviceId}:${shapeName}`,
14
+ serviceId: serviceId,
13
15
  shapeName,
14
- id: rest.join(':')
16
+ id
15
17
  };
16
18
  };
17
- export const extractTakeShapeIDs = (input) => {
18
- const matches = [];
19
- let match = TID_REGEX.exec(input);
20
- while (match !== null) {
21
- matches.push(match[0]);
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 matches;
25
+ return ids;
25
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/util",
3
- "version": "11.76.0",
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.0"
49
+ "@takeshape/routing": "11.76.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/classnames": "^2.2.9",