Skip to content

Commit 70cbe9d

Browse files
type-orm: Replace uuid package with default crypto module (#323)
This PR replaces use of the third-party [uuid](https://github.com/uuidjs/uuid) package with the `crypto` module built into Node. This is to work around an issue in #292 where the newer versions of this package require the consuming package to be ESM. We could figure out a workaround to import this most likely, but it's unnecessary since we can generate a UUID without that third-party package. By submitting this pull request, I confirm that my contribution is made under the terms of the MIT-0 license.
1 parent d4dc67d commit 70cbe9d

6 files changed

Lines changed: 11 additions & 13 deletions

File tree

typescript/type-orm/package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/type-orm/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"typeorm": "ts-node ./node_modules/typeorm/cli.js",
1515
"start": "node dist/index.js",
1616
"dev": "npm run clean && npm run build && npm run start",
17-
"test": "npm run clean && npm run build && jest dist/test"
17+
"test": "npm run clean && npm run build && node --experimental-vm-modules node_modules/jest/bin/jest.js dist/test"
1818
},
1919
"author": "",
2020
"license": "ISC",
@@ -31,8 +31,7 @@
3131
"npm-run-all": "^4.1.5",
3232
"pg": "^8.13.1",
3333
"ts-node": "^10.9.2",
34-
"typeorm": "^0.3.28",
35-
"uuid": "^11.0.3"
34+
"typeorm": "^0.3.28"
3635
},
3736
"engines": {
3837
"node": ">=18.0.0"

typescript/type-orm/src/entity/Owner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "reflect-metadata";
2+
import { randomUUID } from "crypto";
23
import { Column, Entity, PrimaryColumn, OneToMany } from "typeorm";
34
import { Pet } from "./Pet";
4-
import { v4 as uuidv4 } from "uuid";
55

66
@Entity("owner")
77
export class Owner {
@@ -38,7 +38,7 @@ export class Owner {
3838

3939
constructor() {
4040
if(!this.id) {
41-
this.id = uuidv4();
41+
this.id = randomUUID();
4242
}
4343
}
4444
}

typescript/type-orm/src/entity/Pet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "reflect-metadata";
2+
import { randomUUID } from "crypto";
23
import { Column, Entity, ManyToOne, PrimaryColumn, JoinColumn, RelationId } from "typeorm";
34
import { Owner } from "./Owner";
4-
import { v4 as uuidv4 } from "uuid";
55

66
@Entity("pet")
77
export class Pet {
@@ -36,7 +36,7 @@ export class Pet {
3636

3737
constructor() {
3838
if (!this.id) {
39-
this.id = uuidv4();
39+
this.id = randomUUID();
4040
}
4141
}
4242
}

typescript/type-orm/src/entity/Vet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "reflect-metadata";
2+
import { randomUUID } from "crypto";
23
import { Column, Entity, PrimaryColumn, ManyToMany, JoinTable } from "typeorm";
34
import { Specialty } from "./Specialty";
4-
import { v4 as uuidv4 } from "uuid";
55

66
@Entity("vet")
77
export class Vet {
@@ -37,7 +37,7 @@ export class Vet {
3737

3838
constructor() {
3939
if (!this.id) {
40-
this.id = uuidv4();
40+
this.id = randomUUID();
4141
}
4242
}
4343
}

typescript/type-orm/src/entity/VetSpecialty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "reflect-metadata";
2+
import { randomUUID } from "crypto";
23
import { Entity, Column, PrimaryColumn } from "typeorm";
3-
import { v4 as uuidv4 } from "uuid";
44

55
@Entity("vet_specialty")
66
export class VetSpecialty {
@@ -14,7 +14,7 @@ export class VetSpecialty {
1414

1515
constructor() {
1616
if(!this.id) {
17-
this.id = uuidv4();
17+
this.id = randomUUID();
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)