Files
botpress--botpress/packages/cli/src/utils/id-utils.ts
T
2026-07-13 13:34:48 +08:00

28 lines
654 B
TypeScript

import { prefixToObjectMap } from '@bpinternal/const'
import * as uuid from 'uuid'
const ULID_LENGTH = 26 // Reference: https://github.com/ulid/spec#canonical-string-representation
export function isValidID(id: string) {
// Note: UUIDs were used first and then prefixed ULIDs were introduced.
return isPrefixedULID(id) || uuid.validate(id)
}
export function isPrefixedULID(id: string) {
const [prefix, identifier] = id.split('_')
if (!(prefix && identifier)) {
return false
}
if (!Object.keys(prefixToObjectMap).includes(prefix)) {
return false
}
if (identifier.length < ULID_LENGTH) {
return false
}
return true
}