Skip to content

Commit

Permalink
Merge pull request #103 from DevAndromeda/refactor/uuid
Browse files Browse the repository at this point in the history
refactor(impl/domain): use native uuid generator
  • Loading branch information
mesaugat committed Jan 18, 2022
2 parents da2b4e6 + 3835689 commit 0b51c52
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Value of bar: World
### Express Example

```js
const uuid = require('uuid');
const { randomUUID } = require('crypto');
const express = require('express');
const store = require('@leapfrogtechnology/async-store');

Expand All @@ -113,7 +113,7 @@ app.use(store.initializeMiddleware());

// Set request Id in store
app.use((req, res, next) => {
store.set({ reqId: uuid.v4() });
store.set({ reqId: randomUUID() });
next();
});

Expand All @@ -140,7 +140,7 @@ Request Id: 03d8bd27-9097-427a-9460-7d8d9576f156
### Fastify Example

```js
const uuid = require('uuid');
const { randomUUID } = require('crypto');
const fastifyPlugin = require('fastify-plugin');
const store = require('@leapfrogtechnology/async-store');

Expand All @@ -152,7 +152,7 @@ fastifyServer.register(fastifyPlugin(store.initializeFastifyPlugin()));

fastifyServer.register((fastifyInstance, opts, done) => {
fastifyInstance.addHook('preHandler', (req, reply, done) => {
store.set({ reqId: uuid.v4() });
store.set({ reqId: randomUUID() });
done();
});

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
],
"dependencies": {
"debug": "4.3.1",
"ramda": "0.27.1",
"uuid": "8.3.2"
"ramda": "0.27.1"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
Expand All @@ -67,8 +66,8 @@
"@types/debug": "^4.1.5",
"@types/express": "^4.17.9",
"@types/mocha": "^8.2.0",
"@types/node": "^14.17.0",
"@types/ramda": "^0.27.34",
"@types/uuid": "^8.3.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"codecov": "^3.8.1",
Expand Down
4 changes: 2 additions & 2 deletions src/impl/domain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as debug from 'debug';
import * as domain from 'domain';
import { v4 as uuidv4 } from 'uuid';
import { randomUUID } from 'crypto';
import { mergeDeepRight } from 'ramda'; // TODO: Import merge function only.

import { STORE_DOMAIN } from '../constants';
Expand All @@ -26,7 +26,7 @@ export function initialize(callback: (err?: any) => void, params?: AsyncStorePar
logDomain(`Adding ${STORE_KEY} and ${ID_KEY} in domain store`);
// Initialize the context in the domain.
d[STORE_KEY] = {};
d[ID_KEY] = uuidv4();
d[ID_KEY] = randomUUID();

d.run(callback);
}
Expand Down
15 changes: 5 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.17.tgz#29fab92f3986c0e379968ad3c2043683d8020dbb"
integrity sha512-G0lD1/7qD60TJ/mZmhog76k7NcpLWkPVGgzkRy3CTlnFu4LUQh5v2Wa661z6vnXmD8EQrnALUyf0VRtrACYztw==

"@types/node@^14.17.0":
version "14.18.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.5.tgz#0dd636fe7b2c6055cbed0d4ca3b7fb540f130a96"
integrity sha512-LMy+vDDcQR48EZdEx5wRX1q/sEl6NdGuHXPnfeL8ixkwCOSZ2qnIyIZmcCbdX0MeRqHhAcHmX+haCbrS8Run+A==

"@types/qs@*":
version "6.9.5"
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.5.tgz#434711bdd49eb5ee69d90c1d67c354a9a8ecb18b"
Expand All @@ -334,11 +339,6 @@
"@types/mime" "*"
"@types/node" "*"

"@types/uuid@^8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==

"@ungap/promise-all-settled@1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"
Expand Down Expand Up @@ -2275,11 +2275,6 @@ urlgrey@0.4.4:
resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f"
integrity sha1-iS/pWWCAXoVRnxzUOJ8stMu3ZS8=

uuid@8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^3.3.2, uuid@^3.3.3:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
Expand Down

0 comments on commit 0b51c52

Please sign in to comment.