Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

baseSchemas.ts

42 lines1.9 KB

1import { Schema } from "effect";
2​
3export const TrimmedString = Schema.Trim;
4export const TrimmedNonEmptyString = TrimmedString.check(Schema.isNonEmpty());
5​
6export const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
7export const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
8​
9export const IsoDateTime = Schema.String;
10export type IsoDateTime = typeof IsoDateTime.Type;
11​
12/**
13 * Construct a branded identifier. Enforces non-empty trimmed strings
14 */
15const makeEntityId = <Brand extends string>(brand: Brand) =>
16 TrimmedNonEmptyString.pipe(Schema.brand(brand));
17​
18export const ThreadId = makeEntityId("ThreadId");
19export type ThreadId = typeof ThreadId.Type;
20export const ProjectId = makeEntityId("ProjectId");
21export type ProjectId = typeof ProjectId.Type;
22export const CommandId = makeEntityId("CommandId");
23export type CommandId = typeof CommandId.Type;
24export const EventId = makeEntityId("EventId");
25export type EventId = typeof EventId.Type;
26export const MessageId = makeEntityId("MessageId");
27export type MessageId = typeof MessageId.Type;
28export const TurnId = makeEntityId("TurnId");
29export type TurnId = typeof TurnId.Type;
30​
31export const ProviderSessionId = makeEntityId("ProviderSessionId");
32export type ProviderSessionId = typeof ProviderSessionId.Type;
33export const ProviderThreadId = makeEntityId("ProviderThreadId");
34export type ProviderThreadId = typeof ProviderThreadId.Type;
35export const ProviderTurnId = makeEntityId("ProviderTurnId");
36export type ProviderTurnId = typeof ProviderTurnId.Type;
37export const ProviderItemId = makeEntityId("ProviderItemId");
38export type ProviderItemId = typeof ProviderItemId.Type;
39export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
40export type ApprovalRequestId = typeof ApprovalRequestId.Type;
41export const CheckpointRef = makeEntityId("CheckpointRef");
42export type CheckpointRef = typeof CheckpointRef.Type;