1import * as Schema from "effect/Schema";
2import { AuthEnvironmentScopes } from "./auth.ts";
3import { ExecutionEnvironmentDescriptor } from "./environment.ts";
4
5export const OutboundSourceMessage = Schema.Union([
6 Schema.Struct({ type: Schema.Literal("register"), descriptor: ExecutionEnvironmentDescriptor }),
7 Schema.Struct({
8 type: Schema.Literal("grant"),
9 id: Schema.String.check(Schema.isUUID()),
10 token: Schema.NonEmptyString.check(Schema.isMaxLength(16_384)),
11 }),
12 Schema.Struct({ type: Schema.Literal("pong") }),
13]);
14export type OutboundSourceMessage = typeof OutboundSourceMessage.Type;
15
16export const OutboundHubMessage = Schema.Union([
17 Schema.Struct({ type: Schema.Literal("connect"), id: Schema.String.check(Schema.isUUID()) }),
18 Schema.Struct({
19 type: Schema.Literal("grant"),
20 id: Schema.String.check(Schema.isUUID()),
21 scopes: AuthEnvironmentScopes,
22 }),
23 Schema.Struct({ type: Schema.Literal("ping") }),
24]);
25export type OutboundHubMessage = typeof OutboundHubMessage.Type;
26
27export const HostedSourceConnection = Schema.Struct({
28 serverUrl: Schema.NonEmptyString.check(Schema.isMaxLength(2_048)),
29 authorization: Schema.NonEmptyString.check(Schema.isMaxLength(16_384)),
30 expiresAt: Schema.DateTimeUtc,
31});
32export type HostedSourceConnection = typeof HostedSourceConnection.Type;