workspace-id.ts 594 B

12345678910111213141516171819
  1. import { Schema } from "effect"
  2. import { ascending } from "./identifier"
  3. import { statics } from "./schema"
  4. export const WorkspaceID = Schema.String.check(Schema.isStartsWith("wrk")).pipe(
  5. Schema.brand("WorkspaceV2.ID"),
  6. statics((schema) => {
  7. const create = () => schema.make("wrk_" + ascending())
  8. return {
  9. ascending: (id?: string) => {
  10. if (!id) return create()
  11. if (!id.startsWith("wrk")) throw new Error(`ID ${id} does not start with wrk`)
  12. return schema.make(id)
  13. },
  14. create,
  15. }
  16. }),
  17. )
  18. export type WorkspaceID = typeof WorkspaceID.Type