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

baseSchemas.ts

49 lines2.2 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 return TrimmedNonEmptyString.pipe(Schema.brand(brand));
17};
18​
19export const ThreadId = makeEntityId("ThreadId");
20export type ThreadId = typeof ThreadId.Type;
21export const ProjectId = makeEntityId("ProjectId");
22export type ProjectId = typeof ProjectId.Type;
23export const EnvironmentId = makeEntityId("EnvironmentId");
24export type EnvironmentId = typeof EnvironmentId.Type;
25export const CommandId = makeEntityId("CommandId");
26export type CommandId = typeof CommandId.Type;
27export const EventId = makeEntityId("EventId");
28export type EventId = typeof EventId.Type;
29export const MessageId = makeEntityId("MessageId");
30export type MessageId = typeof MessageId.Type;
31export const TurnId = makeEntityId("TurnId");
32export type TurnId = typeof TurnId.Type;
33export const AuthSessionId = makeEntityId("AuthSessionId");
34export type AuthSessionId = typeof AuthSessionId.Type;
35​
36export const ProviderItemId = makeEntityId("ProviderItemId");
37export type ProviderItemId = typeof ProviderItemId.Type;
38export const RuntimeSessionId = makeEntityId("RuntimeSessionId");
39export type RuntimeSessionId = typeof RuntimeSessionId.Type;
40export const RuntimeItemId = makeEntityId("RuntimeItemId");
41export type RuntimeItemId = typeof RuntimeItemId.Type;
42export const RuntimeRequestId = makeEntityId("RuntimeRequestId");
43export type RuntimeRequestId = typeof RuntimeRequestId.Type;
44export const RuntimeTaskId = makeEntityId("RuntimeTaskId");
45export type RuntimeTaskId = typeof RuntimeTaskId.Type;
46export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
47export type ApprovalRequestId = typeof ApprovalRequestId.Type;
48export const CheckpointRef = makeEntityId("CheckpointRef");
49export type CheckpointRef = typeof CheckpointRef.Type;