diff --git a/packages/pockethost/package.json b/packages/pockethost/package.json index 0dcbb0ef..450257cb 100644 --- a/packages/pockethost/package.json +++ b/packages/pockethost/package.json @@ -51,7 +51,6 @@ "json-stringify-safe": "^5.0.1", "knex": "^2.5.1", "memorystream": "^0.3.1", - "nanoid": "^5.0.2", "node-fetch": "^3.3.2", "node-os-utils": "^1.3.7", "pocketbase": "^0.21.3", diff --git a/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/PhFs.ts b/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/PhFs.ts index 6128dc95..0e099d0d 100644 --- a/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/PhFs.ts +++ b/packages/pockethost/src/cli/commands/EdgeCommand/FtpCommand/FtpService/PhFs.ts @@ -9,7 +9,7 @@ import { Logger, PocketBase, assert, - newId, + seqid, } from '../../../../../common' import { DATA_ROOT } from '../../../../../core' import { InstanceLogger, InstanceLoggerApi } from '../../../../../services' @@ -434,6 +434,6 @@ export class PhFs implements FileSystem { } getUniqueName() { - return newId(30) + return seqid() } } diff --git a/packages/pockethost/src/common/CleanupManager.ts b/packages/pockethost/src/common/CleanupManager.ts index e7b3a5f7..5d122f09 100644 --- a/packages/pockethost/src/common/CleanupManager.ts +++ b/packages/pockethost/src/common/CleanupManager.ts @@ -1,6 +1,5 @@ import { reduce, values } from '@s-libs/micro-dash' -import { nanoid } from 'nanoid' -import { LoggerService } from '.' +import { LoggerService, seqid } from '.' export type CleanupFunc = () => Promise | void @@ -19,7 +18,7 @@ export type CleanupManagerApi = ReturnType // TODO: Document this // This is currently only used in the Logging.svelte file for unsubscribing from real-time events from PocketBase export const createCleanupManager = (slug?: string) => { - const _slug = slug || nanoid() + const _slug = slug || seqid() const { error, warn, dbg } = LoggerService().create(`cleanupManager:${_slug}`) diff --git a/packages/pockethost/src/common/index.ts b/packages/pockethost/src/common/index.ts index c867931f..fea620a9 100644 --- a/packages/pockethost/src/common/index.ts +++ b/packages/pockethost/src/common/index.ts @@ -1,16 +1,16 @@ +export * from './assert' export * from './CleanupManager' export * from './ConsoleLogger' -export * from './Logger' -export * from './ResourceAllocator' -export * from './TimerManager' -export * from './assert' export * from './events' export * from './ioc' +export * from './Logger' export * from './mergeConfig' export * from './mkSingleton' -export * from './newId' export * from './now' export * from './pocketbase' export * from './pocketbase-client-helpers' +export * from './ResourceAllocator' export * from './schema' +export * from './seqid' export * from './stringify' +export * from './TimerManager' diff --git a/packages/pockethost/src/common/newId.ts b/packages/pockethost/src/common/newId.ts deleted file mode 100644 index ecb0ecc4..00000000 --- a/packages/pockethost/src/common/newId.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { customAlphabet } from 'nanoid' - -const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz') -export const newId = (length = 15) => nanoid(length) diff --git a/packages/pockethost/src/common/seqid.ts b/packages/pockethost/src/common/seqid.ts new file mode 100644 index 00000000..636d3e3d --- /dev/null +++ b/packages/pockethost/src/common/seqid.ts @@ -0,0 +1,10 @@ +let base = Date.now() +let modifier = 0 +export const seqid = () => { + const now = Date.now() + if (now !== base) { + base = now + modifier = 0 + } + return `${base}-${modifier++}` +} diff --git a/packages/pockethost/src/core/asyncExecutionGuard.ts b/packages/pockethost/src/core/asyncExecutionGuard.ts index d6c61a1b..fe3b732b 100644 --- a/packages/pockethost/src/core/asyncExecutionGuard.ts +++ b/packages/pockethost/src/core/asyncExecutionGuard.ts @@ -1,6 +1,6 @@ -import { uniqueId } from '@s-libs/micro-dash' import Bottleneck from 'bottleneck' import { SetReturnType } from 'type-fest' +import { seqid } from '../common' import { LoggerService } from '../common/Logger' const limiters: { [lane: string]: Bottleneck } = {} @@ -10,7 +10,7 @@ export const serialAsyncExecutionGuard = < cb: T, lane?: SetReturnType, ): T => { - const uuid = uniqueId() + const uuid = seqid() const _lane = lane || (() => uuid) const wrapper = (...args: Parameters) => { const { dbg } = LoggerService().create('serialAsyncExecutionGuard') @@ -32,7 +32,7 @@ export const singletonAsyncExecutionGuard = < cb: T, key: SetReturnType, ): T => { - const uuid = uniqueId() + const uuid = seqid() const keyFactory = key || (() => uuid) const wrapper = (...args: Parameters) => { const { dbg } = LoggerService().create(`singletonAsyncExecutionGuard`) diff --git a/packages/pockethost/src/services/ProxyService.ts b/packages/pockethost/src/services/ProxyService.ts index 10035132..f163a8ee 100644 --- a/packages/pockethost/src/services/ProxyService.ts +++ b/packages/pockethost/src/services/ProxyService.ts @@ -11,6 +11,7 @@ import { SingletonBaseConfig, asyncExitHook, mkSingleton, + seqid, } from '../../core' export type ProxyServiceApi = AsyncReturnType @@ -65,6 +66,7 @@ export const proxyService = mkSingleton(async (config: ProxyServiceConfig) => { const ip = (req.headers['x-forwarded-for'] as string) || '' const method = req.method || '' const sig = [ + seqid(), method.padStart(10), country.padStart(5), ip.padEnd(45), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 668666f4..a5056e95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -397,9 +397,6 @@ importers: memorystream: specifier: ^0.3.1 version: 0.3.1 - nanoid: - specifier: ^5.0.2 - version: 5.0.7 node-fetch: specifier: ^3.3.2 version: 3.3.2 @@ -3848,11 +3845,6 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - nanoid@5.0.7: - resolution: {integrity: sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==} - engines: {node: ^18 || >=20} - hasBin: true - napi-build-utils@1.0.2: resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==} @@ -8784,8 +8776,6 @@ snapshots: nanoid@3.3.7: {} - nanoid@5.0.7: {} - napi-build-utils@1.0.2: {} ncp@2.0.0: {}