@dxos/keys 0.8.4-main.bbf232bc24 → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +32 -1
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +31 -1
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/parse-id.d.ts +10 -0
- package/dist/types/src/parse-id.d.ts.map +1 -0
- package/dist/types/src/parse-id.test.d.ts +2 -0
- package/dist/types/src/parse-id.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -0
- package/src/parse-id.test.ts +32 -0
- package/src/parse-id.ts +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/keys",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.bc2380dfbc",
|
|
4
4
|
"description": "Key utils and definitions.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"ulidx": "^2.3.0",
|
|
30
|
-
"@dxos/debug": "0.8.4-main.
|
|
31
|
-
"@dxos/invariant": "0.8.4-main.
|
|
32
|
-
"@dxos/node-std": "0.8.4-main.
|
|
30
|
+
"@dxos/debug": "0.8.4-main.bc2380dfbc",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.bc2380dfbc",
|
|
32
|
+
"@dxos/node-std": "0.8.4-main.bc2380dfbc"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"base32-decode": "^1.0.0",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { parseId } from './parse-id';
|
|
8
|
+
|
|
9
|
+
describe('parseId', () => {
|
|
10
|
+
test('space id', () => {
|
|
11
|
+
const id = '123456789012345678901234567890123';
|
|
12
|
+
expect(parseId(id)).toEqual({ spaceId: id });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('object id', () => {
|
|
16
|
+
const id = '12345678901234567890123456';
|
|
17
|
+
expect(parseId(id)).toEqual({ objectId: id });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('fully qualified id', () => {
|
|
21
|
+
const id = '123456789012345678901234567890123:12345678901234567890123456';
|
|
22
|
+
expect(parseId(id)).toEqual({
|
|
23
|
+
spaceId: '123456789012345678901234567890123',
|
|
24
|
+
objectId: '12345678901234567890123456',
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('invalid id', () => {
|
|
29
|
+
const id = '123456789012345678901234561234567890123456';
|
|
30
|
+
expect(parseId(id)).toEqual({});
|
|
31
|
+
});
|
|
32
|
+
});
|
package/src/parse-id.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ObjectId } from './object-id';
|
|
6
|
+
import { type SpaceId } from './space-id';
|
|
7
|
+
|
|
8
|
+
export const SPACE_ID_LENGTH = 33;
|
|
9
|
+
export const OBJECT_ID_LENGTH = 26;
|
|
10
|
+
export const FQ_ID_LENGTH = SPACE_ID_LENGTH + OBJECT_ID_LENGTH + 1;
|
|
11
|
+
|
|
12
|
+
export const parseId = (id?: string): { spaceId?: SpaceId; objectId?: ObjectId } => {
|
|
13
|
+
if (!id) {
|
|
14
|
+
return {};
|
|
15
|
+
} else if (id.length === SPACE_ID_LENGTH) {
|
|
16
|
+
return {
|
|
17
|
+
spaceId: id as SpaceId,
|
|
18
|
+
};
|
|
19
|
+
} else if (id.length === OBJECT_ID_LENGTH) {
|
|
20
|
+
return {
|
|
21
|
+
objectId: id as ObjectId,
|
|
22
|
+
};
|
|
23
|
+
} else if (id.length === FQ_ID_LENGTH && id.indexOf(':') === SPACE_ID_LENGTH) {
|
|
24
|
+
const [spaceId, objectId] = id.split(':');
|
|
25
|
+
return {
|
|
26
|
+
spaceId: spaceId as SpaceId,
|
|
27
|
+
objectId: objectId as ObjectId,
|
|
28
|
+
};
|
|
29
|
+
} else {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
};
|