Skip to content

Commit

Permalink
refactor: remove create unique id util function
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jan 9, 2024
1 parent fef5777 commit 4fbb9bf
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/events/http/lambda-events/LambdaProxyIntegrationEvent.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from 'node:buffer'
import { randomUUID } from 'node:crypto'
import { env } from 'node:process'
import { log } from '@serverless/utils/log.js'
import { decodeJwt } from 'jose'
import {
createUniqueId,
formatToClfTime,
nullIfEmpty,
parseHeaders,
Expand Down Expand Up @@ -181,7 +181,7 @@ export default class LambdaProxyIntegrationEvent {
}),
domainName: 'offlineContext_domainName',
domainPrefix: 'offlineContext_domainPrefix',
extendedRequestId: createUniqueId(),
extendedRequestId: randomUUID(),
httpMethod,
identity: {
accessKey: null,
Expand Down Expand Up @@ -212,7 +212,7 @@ export default class LambdaProxyIntegrationEvent {
operationName: this.#additionalRequestContext.operationName,
path: this.#path,
protocol: 'HTTP/1.1',
requestId: createUniqueId(),
requestId: randomUUID(),
requestTime,
requestTimeEpoch,
resourceId: 'offlineContext_resourceId',
Expand Down
10 changes: 3 additions & 7 deletions src/events/http/lambda-events/VelocityContext.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Buffer } from 'node:buffer'
import { randomUUID } from 'node:crypto'
import { env } from 'node:process'
import jsEscapeString from 'js-string-escape'
import { decodeJwt } from 'jose'
import {
createUniqueId,
isPlainObject,
jsonPath,
parseHeaders,
} from '../../../utils/index.js'
import { isPlainObject, jsonPath, parseHeaders } from '../../../utils/index.js'

const { parse, stringify } = JSON
const { assign, entries, fromEntries } = Object
Expand Down Expand Up @@ -107,7 +103,7 @@ export default class VelocityContext {
userAgent: this.#request.headers['user-agent'] || '',
userArn: 'offlineContext_userArn',
},
requestId: createUniqueId(),
requestId: randomUUID(),
resourceId: 'offlineContext_resourceId',
resourcePath: this.#path,
stage: this.#stage,
Expand Down
6 changes: 3 additions & 3 deletions src/events/schedule/ScheduleEvent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createUniqueId } from '../../utils/index.js'
import { randomUUID } from 'node:crypto'

export default class ScheduleEvent {
account = createUniqueId()
account = randomUUID()

detail = {};

['detail-type'] = 'Scheduled Event'

id = createUniqueId()
id = randomUUID()

region = null

Expand Down
4 changes: 2 additions & 2 deletions src/events/websocket/WebSocketServer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomUUID } from 'node:crypto'
import { log } from '@serverless/utils/log.js'
import { WebSocketServer as WsWebSocketServer } from 'ws'
import { createUniqueId } from '../../utils/index.js'

export default class WebSocketServer {
#connectionIds = new Map()
Expand All @@ -21,7 +21,7 @@ export default class WebSocketServer {
const server = new WsWebSocketServer({
server: this.#sharedServer,
verifyClient: async ({ req }, cb) => {
const connectionId = createUniqueId()
const connectionId = randomUUID()
const key = req.headers['sec-websocket-key']

log.debug(`verifyClient:${key} ${connectionId}`)
Expand Down
5 changes: 3 additions & 2 deletions src/events/websocket/lambda-events/WebSocketConnectEvent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// import { randomUUID } from 'node:crypto'
import WebSocketRequestContext from './WebSocketRequestContext.js'
import {
parseHeaders,
Expand Down Expand Up @@ -32,9 +33,9 @@ export default class WebSocketConnectEvent {
// const headers = {
// Host: 'localhost',
// 'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
// 'Sec-WebSocket-Key': createUniqueId(),
// 'Sec-WebSocket-Key': randomUUID(),
// 'Sec-WebSocket-Version': '13',
// 'X-Amzn-Trace-Id': `Root=${createUniqueId()}`,
// 'X-Amzn-Trace-Id': `Root=${randomUUID()}`,
// 'X-Forwarded-For': '127.0.0.1',
// 'X-Forwarded-Port': String(this.#websocketPort),
// 'X-Forwarded-Proto': ${httpsProtocol ? 'https' : 'http'},
Expand Down
9 changes: 5 additions & 4 deletions src/events/websocket/lambda-events/WebSocketRequestContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createUniqueId, formatToClfTime } from '../../../utils/index.js'
import { randomUUID } from 'node:crypto'
import { formatToClfTime } from '../../../utils/index.js'

const { now } = Date

Expand Down Expand Up @@ -38,7 +39,7 @@ export default class WebSocketRequestContext {
connectionId: this.#connectionId,
domainName: 'localhost',
eventType: this.#eventType,
extendedRequestId: createUniqueId(),
extendedRequestId: randomUUID(),
identity: {
accessKey: null,
accountId: null,
Expand All @@ -54,8 +55,8 @@ export default class WebSocketRequestContext {
userArn: null,
},
messageDirection: 'IN',
messageId: createUniqueId(),
requestId: createUniqueId(),
messageId: randomUUID(),
requestId: randomUUID(),
requestTime: formatToClfTime(timeEpoch),
requestTimeEpoch: timeEpoch,
routeKey: this.#route,
Expand Down
6 changes: 3 additions & 3 deletions src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { randomUUID } from 'node:crypto'
import { readFile, writeFile } from 'node:fs/promises'
import { dirname, join, resolve } from 'node:path'
import process from 'node:process'
Expand All @@ -15,7 +16,6 @@ import {
supportedRuntimes,
} from '../config/index.js'
import { LambdaTimeoutError } from '../errors/index.js'
import { createUniqueId } from '../utils/index.js'

const { ceil } = Math
const { entries, fromEntries } = Object
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class LambdaFunction {
'services',
service.service,
functionKey,
createUniqueId(),
randomUUID(),
)
}

Expand Down Expand Up @@ -286,7 +286,7 @@ export default class LambdaFunction {
await this.#initialize()
}

const requestId = createUniqueId()
const requestId = randomUUID()

this.#lambdaContext.setRequestId(requestId)
this.#lambdaContext.setClientContext(this.#clientContext)
Expand Down
18 changes: 0 additions & 18 deletions src/utils/__tests__/createUniqueId.test.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/utils/createUniqueId.js

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { default as checkDockerDaemon } from './checkDockerDaemon.js'
export { default as checkGoVersion } from './checkGoVersion.js'
export { default as createApiKey } from './createApiKey.js'
export { default as createUniqueId } from './createUniqueId.js'
export { default as detectExecutable } from './detectExecutable.js'
export { default as formatToClfTime } from './formatToClfTime.js'
export { default as generateHapiPath } from './generateHapiPath.js'
Expand Down

0 comments on commit 4fbb9bf

Please sign in to comment.