| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { AuthEnvironmentScopes } from "./auth.ts"; |
| 3 | import { ExecutionEnvironmentDescriptor } from "./environment.ts"; |
| 4 | |
| 5 | export 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 | ]); |
| 14 | export type OutboundSourceMessage = typeof OutboundSourceMessage.Type; |
| 15 | |
| 16 | export 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 | ]); |
| 25 | export type OutboundHubMessage = typeof OutboundHubMessage.Type; |
| 26 | |
| 27 | export 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 | }); |
| 32 | export type HostedSourceConnection = typeof HostedSourceConnection.Type; |