Skip to content

Commit

Permalink
feat(ids): switch from shortid to nanoid
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 committed Sep 19, 2021
1 parent 3dbbfe7 commit 88d1eac
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 44 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Warthog is now on version 3.0! There were a few breaking changes that you should
<summary>Expand for Breaking change details</summary>
<p>

### Switch ID generation library from `shortid` (deprecated) to `nanoid`

Per `shortid` [README](https://github.com/dylang/shortid/blob/master/README.md) it is deprecated.

### Deprecated individual `WARTHOG_APP_*` variables in favor of `WARTHOG_API_BASE_URL`

It's a pain to have to manage 3 separate environment variables for setting the base API URL. We still support this, but prefer the new `WARTHOG_API_BASE_URL` and will use it first if it's present when spinning up a server.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
"@types/isomorphic-fetch": "^0.0.35",
"@types/lodash": "^4.14.148",
"@types/mkdirp": "^0.5.2",
"@types/nanoid": "^3.0.0",
"@types/node": "^12.12.8",
"@types/node-emoji": "^1.8.1",
"@types/open": "^6.2.1",
"@types/pg": "^7.14.11",
"@types/prettier": "^1.18.3",
"@types/shortid": "^0.0.29",
"@types/ws": "^6.0.3",
"apollo-link-error": "^1.1.12",
"apollo-link-http": "^1.5.16",
Expand All @@ -98,13 +98,13 @@
"graphql-type-json": "^0.3.0",
"lodash": "^4.17.15",
"mkdirp": "^0.5.1",
"nanoid": "^3",
"node-emoji": "^1.10.0",
"open": "^7.0.0",
"pg": "^8.6.0",
"pgtools": "^0.3.1",
"prettier": "^1.19.1",
"reflect-metadata": "^0.1.13",
"shortid": "^2.2.15",
"type-graphql": "^0.17.5",
"typedi": "^0.8.0",
"typeorm": "^0.2.32",
Expand Down
4 changes: 2 additions & 2 deletions src/core/BaseModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as shortid from 'shortid';
import { nanoid } from 'nanoid';
import { ObjectType } from 'type-graphql';
import { BeforeInsert } from 'typeorm';
import { IDType } from '../core';
Expand All @@ -22,7 +22,7 @@ export abstract class IdModel {

getId(): string {
// If settings allow ID to be specified on create, use the specified ID
return this.id || shortid.generate();
return this.id || nanoid();
}

@BeforeInsert()
Expand Down
4 changes: 2 additions & 2 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as shortid from 'shortid';
import { nanoid } from 'nanoid';

export class StringUtil {
// Ex: HelloWorld -> HELLO_WORLD
Expand All @@ -17,5 +17,5 @@ export class StringUtil {
}

export function generateId(): string {
return shortid.generate();
return nanoid();
}
50 changes: 12 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,13 @@
dependencies:
"@types/node" "*"

"@types/nanoid@^3.0.0":
version "3.0.0"
resolved "https://registry.npmjs.org/@types/nanoid/-/nanoid-3.0.0.tgz#c757b20f343f3a1dd76e80a9a431b6290fc20f35"
integrity sha512-UXitWSmXCwhDmAKe7D3hNQtQaHeHt5L8LO1CB8GF8jlYVzOv5cBWDNqiJ+oPEWrWei3i3dkZtHY/bUtd0R/uOQ==
dependencies:
nanoid "*"

"@types/node-emoji@^1.8.1":
version "1.8.1"
resolved "https://registry.yarnpkg.com/@types/node-emoji/-/node-emoji-1.8.1.tgz#689cb74fdf6e84309bcafce93a135dfecd01de3f"
Expand Down Expand Up @@ -1056,11 +1063,6 @@
"@types/express-serve-static-core" "*"
"@types/mime" "*"

"@types/shortid@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/shortid/-/shortid-0.0.29.tgz#8093ee0416a6e2bf2aa6338109114b3fbffa0e9b"
integrity sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand Down Expand Up @@ -6308,13 +6310,6 @@ makeerror@1.0.x:
dependencies:
tmpl "1.0.x"

map-age-cleaner@^0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a"
integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==
dependencies:
p-defer "^1.0.0"

map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
Expand Down Expand Up @@ -6420,10 +6415,6 @@ mem@^4.0.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/mem/-/mem-4.3.0.tgz#461af497bc4ae09608cdb2e60eefb69bff744178"
integrity sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==
dependencies:
map-age-cleaner "^0.1.1"
mimic-fn "^2.0.0"
p-is-promise "^2.0.0"

meow@5.0.0, meow@^5.0.0:
version "5.0.0"
Expand Down Expand Up @@ -6557,7 +6548,7 @@ mimic-fn@^1.0.0:
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==

mimic-fn@^2.0.0, mimic-fn@^2.1.0:
mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
Expand Down Expand Up @@ -6699,10 +6690,10 @@ nan@^2.12.1:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==

nanoid@^2.1.0:
version "2.1.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.7.tgz#d775e3e7c6470bbaaae3da9a647a80e228e0abf7"
integrity sha512-fmS3qwDldm4bE01HCIRqNk+f255CNjnAoeV3Zzzv0KemObHKqYgirVaZA9DtKcjogicWjYcHkJs4D5A8CjnuVQ==
nanoid@*, nanoid@^3:
version "3.1.25"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz#09ca32747c0e543f0e1814b7d3793477f9c8e152"
integrity sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q==

nanomatch@^1.2.9:
version "1.2.13"
Expand Down Expand Up @@ -7349,11 +7340,6 @@ osenv@^0.1.4, osenv@^0.1.5:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

p-defer@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c"
integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=

p-each-series@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-each-series/-/p-each-series-1.0.0.tgz#930f3d12dd1f50e7434457a22cd6f04ac6ad7f71"
Expand Down Expand Up @@ -7383,11 +7369,6 @@ p-finally@^2.0.0:
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-2.0.1.tgz#bd6fcaa9c559a096b680806f4d657b3f0f240561"
integrity sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw==

p-is-promise@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e"
integrity sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==

p-is-promise@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-3.0.0.tgz#58e78c7dfe2e163cf2a04ff869e7c1dba64a5971"
Expand Down Expand Up @@ -8828,13 +8809,6 @@ shellwords@^0.1.1:
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==

shortid@^2.2.15:
version "2.2.15"
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.15.tgz#2b902eaa93a69b11120373cd42a1f1fe4437c122"
integrity sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==
dependencies:
nanoid "^2.1.0"

signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
Expand Down

0 comments on commit 88d1eac

Please sign in to comment.