mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-06 14:16:41 +00:00
enh: uuid refactor
This commit is contained in:
parent
a0df601f96
commit
409b9b1e7d
@ -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",
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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> | void
|
||||
|
||||
@ -19,7 +18,7 @@ export type CleanupManagerApi = ReturnType<typeof createCleanupManager>
|
||||
// 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}`)
|
||||
|
||||
|
@ -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'
|
||||
|
@ -1,4 +0,0 @@
|
||||
import { customAlphabet } from 'nanoid'
|
||||
|
||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz')
|
||||
export const newId = (length = 15) => nanoid(length)
|
10
packages/pockethost/src/common/seqid.ts
Normal file
10
packages/pockethost/src/common/seqid.ts
Normal file
@ -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++}`
|
||||
}
|
@ -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, string>,
|
||||
): T => {
|
||||
const uuid = uniqueId()
|
||||
const uuid = seqid()
|
||||
const _lane = lane || (() => uuid)
|
||||
const wrapper = (...args: Parameters<T>) => {
|
||||
const { dbg } = LoggerService().create('serialAsyncExecutionGuard')
|
||||
@ -32,7 +32,7 @@ export const singletonAsyncExecutionGuard = <
|
||||
cb: T,
|
||||
key: SetReturnType<T, string>,
|
||||
): T => {
|
||||
const uuid = uniqueId()
|
||||
const uuid = seqid()
|
||||
const keyFactory = key || (() => uuid)
|
||||
const wrapper = (...args: Parameters<T>) => {
|
||||
const { dbg } = LoggerService().create(`singletonAsyncExecutionGuard`)
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
SingletonBaseConfig,
|
||||
asyncExitHook,
|
||||
mkSingleton,
|
||||
seqid,
|
||||
} from '../../core'
|
||||
|
||||
export type ProxyServiceApi = AsyncReturnType<typeof proxyService>
|
||||
@ -65,6 +66,7 @@ export const proxyService = mkSingleton(async (config: ProxyServiceConfig) => {
|
||||
const ip = (req.headers['x-forwarded-for'] as string) || '<ip>'
|
||||
const method = req.method || '<m>'
|
||||
const sig = [
|
||||
seqid(),
|
||||
method.padStart(10),
|
||||
country.padStart(5),
|
||||
ip.padEnd(45),
|
||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -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: {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user