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

baseSchemas.ts

44 lines2.0 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 ProviderItemId = makeEntityId("ProviderItemId");
32export type ProviderItemId = typeof ProviderItemId.Type;
33export const RuntimeSessionId = makeEntityId("RuntimeSessionId");
34export type RuntimeSessionId = typeof RuntimeSessionId.Type;
35export const RuntimeItemId = makeEntityId("RuntimeItemId");
36export type RuntimeItemId = typeof RuntimeItemId.Type;
37export const RuntimeRequestId = makeEntityId("RuntimeRequestId");
38export type RuntimeRequestId = typeof RuntimeRequestId.Type;
39export const RuntimeTaskId = makeEntityId("RuntimeTaskId");
40export type RuntimeTaskId = typeof RuntimeTaskId.Type;
41export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
42export type ApprovalRequestId = typeof ApprovalRequestId.Type;
43export const CheckpointRef = makeEntityId("CheckpointRef");
44export type CheckpointRef = typeof CheckpointRef.Type;