session-id.ts 473 B

123456789101112131415
  1. import { Schema } from "effect"
  2. import { descending } from "./identifier"
  3. import { statics } from "./schema"
  4. export const SessionID = Schema.String.check(Schema.isStartsWith("ses")).pipe(
  5. Schema.brand("SessionID"),
  6. statics((schema) => {
  7. const create = () => schema.make("ses_" + descending())
  8. return {
  9. create,
  10. descending: (id?: string) => (id === undefined ? create() : schema.make(id)),
  11. }
  12. }),
  13. )
  14. export type SessionID = typeof SessionID.Type