summaryrefslogtreecommitdiffhomepage
path: root/packages/util/src/identifier.ts
diff options
context:
space:
mode:
authorShoubhit Dash <[email protected]>2026-04-16 17:30:14 +0530
committerShoubhit Dash <[email protected]>2026-04-16 17:30:14 +0530
commit2e18a603f0ea24154908e748493fd4bfaa74fc00 (patch)
treeb723e00af2821b213573b16fa199b64babd5f1f5 /packages/util/src/identifier.ts
parent9819eb04614fd607cacb07d754052f1531a82331 (diff)
parent7341718f9234b0cf3a8758c87e91d2006b71bff6 (diff)
downloadopencode-2e18a603f0ea24154908e748493fd4bfaa74fc00.tar.gz
opencode-2e18a603f0ea24154908e748493fd4bfaa74fc00.zip
merge dev
Diffstat (limited to 'packages/util/src/identifier.ts')
-rw-r--r--packages/util/src/identifier.ts48
1 files changed, 0 insertions, 48 deletions
diff --git a/packages/util/src/identifier.ts b/packages/util/src/identifier.ts
deleted file mode 100644
index ba28a351b..000000000
--- a/packages/util/src/identifier.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { randomBytes } from "crypto"
-
-export namespace Identifier {
- const LENGTH = 26
-
- // State for monotonic ID generation
- let lastTimestamp = 0
- let counter = 0
-
- export function ascending() {
- return create(false)
- }
-
- export function descending() {
- return create(true)
- }
-
- function randomBase62(length: number): string {
- const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- let result = ""
- const bytes = randomBytes(length)
- for (let i = 0; i < length; i++) {
- result += chars[bytes[i] % 62]
- }
- return result
- }
-
- export function create(descending: boolean, timestamp?: number): string {
- const currentTimestamp = timestamp ?? Date.now()
-
- if (currentTimestamp !== lastTimestamp) {
- lastTimestamp = currentTimestamp
- counter = 0
- }
- counter++
-
- let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter)
-
- now = descending ? ~now : now
-
- const timeBytes = Buffer.alloc(6)
- for (let i = 0; i < 6; i++) {
- timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff))
- }
-
- return timeBytes.toString("hex") + randomBase62(LENGTH - 12)
- }
-}