diff options
| author | Frank <[email protected]> | 2025-09-18 10:59:01 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-09-18 10:59:01 -0400 |
| commit | 4ceabdffa07b1af8d99eb73622a4d549d99ec6d2 (patch) | |
| tree | 72e2ae62084a9e24cc76caffbd1f30dafc69ea56 /packages/console/core/src/identifier.ts | |
| parent | c87480cf931a6f8f8b55552558ef521f1918b578 (diff) | |
| download | opencode-4ceabdffa07b1af8d99eb73622a4d549d99ec6d2.tar.gz opencode-4ceabdffa07b1af8d99eb73622a4d549d99ec6d2.zip | |
wip: zen
Diffstat (limited to 'packages/console/core/src/identifier.ts')
| -rw-r--r-- | packages/console/core/src/identifier.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/console/core/src/identifier.ts b/packages/console/core/src/identifier.ts new file mode 100644 index 000000000..f8e73852e --- /dev/null +++ b/packages/console/core/src/identifier.ts @@ -0,0 +1,26 @@ +import { ulid } from "ulid" +import { z } from "zod" + +export namespace Identifier { + const prefixes = { + account: "acc", + billing: "bil", + key: "key", + payment: "pay", + usage: "usg", + user: "usr", + workspace: "wrk", + } as const + + export function create(prefix: keyof typeof prefixes, given?: string): string { + if (given) { + if (given.startsWith(prefixes[prefix])) return given + throw new Error(`ID ${given} does not start with ${prefixes[prefix]}`) + } + return [prefixes[prefix], ulid()].join("_") + } + + export function schema(prefix: keyof typeof prefixes) { + return z.string().startsWith(prefixes[prefix]) + } +} |
