Skip to content

Commit 3a4efeb

Browse files
authored
Merge pull request #58 from weaviate/feature/generate-uuid
UUIDv5 support
2 parents 6360573 + caccecd commit 3a4efeb

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

examples/typescript/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import weaviate, {
33
AuthUserPasswordCredentials,
44
ApiKey,
55
AuthAccessTokenCredentials,
6+
generateUuid5,
67
} from 'weaviate-ts-client';
78

89
const client = weaviate.client({
@@ -37,6 +38,7 @@ console.log(
3738
);
3839

3940
console.log(JSON.stringify(new ApiKey('abcd1234')));
41+
console.log(generateUuid5('55dfccce-0142-4807-a1ff-60be9b38f5cc', 'the-best-namespace'));
4042

4143
client.misc
4244
.metaGetter()

package-lock.json

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"homepage": "https://github.com/weaviate/typescript-client#readme",
4646
"dependencies": {
4747
"graphql-request": "^5.1.0",
48-
"isomorphic-fetch": "^3.0.0"
48+
"isomorphic-fetch": "^3.0.0",
49+
"uuid": "^9.0.0"
4950
},
5051
"devDependencies": {
5152
"@babel/core": "^7.20.12",
@@ -57,6 +58,7 @@
5758
"@types/isomorphic-fetch": "^0.0.36",
5859
"@types/jest": "^29.4.0",
5960
"@types/node": "^18.14.0",
61+
"@types/uuid": "^9.0.1",
6062
"@typescript-eslint/eslint-plugin": "^5.54.1",
6163
"@typescript-eslint/parser": "^5.54.1",
6264
"babel-jest": "^29.4.3",

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ export * from './c11y';
104104
export * from './backup';
105105
export * from './cluster';
106106
export * from './connection';
107+
export * from './utils/uuid';

src/utils/uuid.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { v5 as uuid5 } from 'uuid';
2+
3+
// Generates UUIDv5, used to consistently generate the same UUID for
4+
// a specific identifier and namespace
5+
export function generateUuid5(identifier: string | number, namespace: string | number = ''): string {
6+
const stringified = identifier.toString() + namespace.toString();
7+
return uuid5(stringified, uuid5.DNS).toString();
8+
}

0 commit comments

Comments
 (0)