workspace.ts 617 B

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