diff options
| author | Frank <[email protected]> | 2025-08-08 13:22:54 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-08-08 13:24:32 -0400 |
| commit | 183e0911b76025a1f2a82e979d9834fec2131d0e (patch) | |
| tree | 9987c1753bd64d1ce1d174ab397f1a8c681f642c /cloud/core/src/identifier.ts | |
| parent | c7bb19ad0712469063eab35589aa5d3602b0c5b1 (diff) | |
| download | opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.tar.gz opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.zip | |
wip: gateway
Diffstat (limited to 'cloud/core/src/identifier.ts')
| -rw-r--r-- | cloud/core/src/identifier.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cloud/core/src/identifier.ts b/cloud/core/src/identifier.ts new file mode 100644 index 000000000..f8e73852e --- /dev/null +++ b/cloud/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]) + } +} |
