@takeshape/util 11.55.0 → 11.58.0

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { extractTakeShapeIDs, parseTakeShapeID } from "../takeshape-id.js";
3
+ describe('parseTakeShapeID', () => {
4
+ test('simple example', () => {
5
+ expect(parseTakeShapeID('tid:rick:Character:1')).toEqual({
6
+ service: 'rick',
7
+ shapeName: 'Character',
8
+ id: '1'
9
+ });
10
+ });
11
+ test('colon in the id is allowed', () => {
12
+ expect(parseTakeShapeID('tid:shopify:Product:gid://shopify/Product/12345')).toEqual({
13
+ service: 'shopify',
14
+ shapeName: 'Product',
15
+ id: 'gid://shopify/Product/12345'
16
+ });
17
+ });
18
+ });
19
+ describe('extractTakeShapeIDs', () => {
20
+ test('simple example', () => {
21
+ expect(extractTakeShapeIDs('Here is a cool character:\n\ntid:rick:Character:1\n\nAnd another is tid:rick:Character:2')).toEqual(['tid:rick:Character:1', 'tid:rick:Character:2']);
22
+ });
23
+ test('colons in the id part are allowed', () => {
24
+ expect(extractTakeShapeIDs('Here is a nice product: tid:shopify:Product:gid://shopify/Product/12345\n\nHope you like it')).toEqual(['tid:shopify:Product:gid://shopify/Product/12345']);
25
+ });
26
+ });
@@ -33,3 +33,4 @@ export * from './validation.ts';
33
33
  export * from './value.ts';
34
34
  export * from './visit.ts';
35
35
  export * from './empty.ts';
36
+ export * from './takeshape-id.ts';
@@ -33,3 +33,4 @@ export * from "./validation.js";
33
33
  export * from "./value.js";
34
34
  export * from "./visit.js";
35
35
  export * from "./empty.js";
36
+ export * from "./takeshape-id.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * AKA TID. A unique ID that refers to an object in the TakeShape data index.
3
+ */
4
+ export type TakeShapeID = `tid:${string}`;
5
+ export type ParsedTakeshapeID = {
6
+ service: string;
7
+ shapeName: string;
8
+ id: string;
9
+ };
10
+ export declare const parseTakeShapeID: (tid: string) => ParsedTakeshapeID;
11
+ export declare const extractTakeShapeIDs: (input: string) => TakeShapeID[];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pattern to match a TakeShapeID. Note that colons are allowed in the ID part of the TID.
3
+ * For example, `tid:rick:Character:gid://foo` is valid and the ID part is `gid://foo`.
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}`);
10
+ }
11
+ return {
12
+ service,
13
+ shapeName,
14
+ id: rest.join(':')
15
+ };
16
+ };
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);
23
+ }
24
+ return matches;
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/util",
3
- "version": "11.55.0",
3
+ "version": "11.58.0",
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.55.0"
49
+ "@takeshape/routing": "11.58.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/classnames": "^2.2.9",
@@ -67,12 +67,11 @@
67
67
  "prebuild:ci": "pnpm clean",
68
68
  "build:ci": "pnpm build --noCheck",
69
69
  "clean": "del-cli dist coverage *.tsbuildinfo",
70
- "lint": "pnpm lint:biome && pnpm lint:eslint",
70
+ "lint": "trap 'RC=1' ERR; pnpm lint:biome; pnpm lint:eslint; exit $RC",
71
71
  "lint:biome": "biome check",
72
72
  "lint:eslint": "eslint src -c ../../eslint.config.mjs",
73
- "lint:ci": "pnpm lint:ci:biome; pnpm lint:ci:eslint",
74
73
  "lint:ci:biome": "mkdir -p \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}\" && biome check --diagnostic-level error --reporter=junit > \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/biome-results.xml\"",
75
- "lint:ci:eslint": "pnpm lint:eslint --quiet --format json -o \"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/eslint-results.json\"",
74
+ "lint:ci:eslint": "ESLINT_SUITE_NAME=${npm_package_name} ESLINT_JUNIT_OUTPUT=\"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/eslint-results.xml\" pnpm lint:eslint --quiet --format ../../node_modules/eslint-junit/index.js",
76
75
  "test": "TZ=UTC vitest run",
77
76
  "test:ci": "TZ=UTC vitest run --reporter=default --reporter=junit --outputFile=\"${GITHUB_WORKSPACE}/test-results/${npm_package_name#*\\/}/vitest-results.xml\" --coverage.enabled --coverage.reportsDirectory=\"${GITHUB_WORKSPACE}/coverage/${npm_package_name#*\\/}\"",
78
77
  "todo": "leasot 'src/**/*.{js,jsx,ts,tsx}'",