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AChH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE/D,QAAA,MAAM,iBAAiB;;;;EAIrB,CAAC;AACH,QAAA,MAAM,sBAAsB;;;;;;EAG1B,CAAC;AACH,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;IAa1B,CAAC;AACH,QAAA,MAAM,0BAA0B;;;;EAI9B,CAAC;AACH,wEAAwE;AACxE,QAAA,MAAM,wBAAwB;;;;;;;EAG5B,CAAC;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAM9B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC3D,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACrE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACrE,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAC7E,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AACzE,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC","sourcesContent":["import type { JsonValue } from \"@earendil-works/chord\";\nimport Type, { type Static } from \"typebox\";\nimport { Check } from \"typebox/value\";\n\nexport const PROTOCOL_VERSION = 8 as const;\n\nconst IdSchema = Type.String({ minLength: 1 });\nconst OpaqueJsonValueSchema = Type.Unsafe<JsonValue>(Type.Unknown());\nconst StrictObject = <const T extends Parameters<typeof Type.Object>[0]>(properties: T) =>\n\tType.Object(properties, { additionalProperties: false });\n\nconst ServerIdSchema = Type.String({\n\tpattern: \"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$\",\n});\nexport type ServerId = Static<typeof ServerIdSchema>;\n\nexport function isServerId(value: unknown): value is ServerId {\n\treturn Check(ServerIdSchema, value);\n}\n\nconst ProtocolErrorSchema = StrictObject({\n\tcode: IdSchema,\n\tmessage: Type.String(),\n});\nexport type ProtocolErrorCode = string;\nexport type ProtocolError = Static<typeof ProtocolErrorSchema>;\n\n/** Must be the first frame sent by a client. */\nconst ClientHelloSchema = StrictObject({\n\ttype: Type.Literal(\"hello\"),\n\tversion: Type.Integer({ minimum: 0 }),\n});\nexport type ClientHello = Static<typeof ClientHelloSchema>;\n\n/** A server-wide call, fenced to one logical server. */\nconst ServerTargetSchema = StrictObject({\n\tserverId: ServerIdSchema,\n});\n/** A session call, fenced to one logical server, durable session, and live attachment. */\nconst SessionTargetSchema = StrictObject({\n\tserverId: ServerIdSchema,\n\tsessionId: IdSchema,\n\tattachmentId: IdSchema,\n});\nexport type SessionTarget = Static<typeof SessionTargetSchema>;\nconst RpcTargetSchema = Type.Union([ServerTargetSchema, SessionTargetSchema]);\nexport type RpcTarget = Static<typeof RpcTargetSchema>;\n\nconst RequestEnvelopeSchema = StrictObject({\n\ttype: Type.Literal(\"request\"),\n\tid: IdSchema,\n\ttarget: RpcTargetSchema,\n\tcall: OpaqueJsonValueSchema,\n});\nconst CancelEnvelopeSchema = StrictObject({\n\ttype: Type.Literal(\"cancel\"),\n\tid: IdSchema,\n\ttarget: RpcTargetSchema,\n});\nexport type RequestEnvelope = Static<typeof RequestEnvelopeSchema>;\nexport type CancelEnvelope = Static<typeof CancelEnvelopeSchema>;\nexport const ClientMessageSchema = Type.Union([ClientHelloSchema, RequestEnvelopeSchema, CancelEnvelopeSchema]);\nexport type ClientMessage = Static<typeof ClientMessageSchema>;\n\nconst ServerHelloSchema = StrictObject({\n\ttype: Type.Literal(\"hello\"),\n\tversion: Type.Literal(PROTOCOL_VERSION),\n\tserverId: ServerIdSchema,\n});\nconst ServerHelloErrorSchema = StrictObject({\n\ttype: Type.Literal(\"hello_error\"),\n\terror: ProtocolErrorSchema,\n});\nconst ResponseEnvelopeSchema = Type.Union([\n\tStrictObject({\n\t\ttype: Type.Literal(\"response\"),\n\t\tid: IdSchema,\n\t\tok: Type.Literal(true),\n\t\tresult: Type.Optional(OpaqueJsonValueSchema),\n\t}),\n\tStrictObject({\n\t\ttype: Type.Literal(\"response\"),\n\t\tid: IdSchema,\n\t\tok: Type.Literal(false),\n\t\terror: ProtocolErrorSchema,\n\t}),\n]);\nconst ServiceEventEnvelopeSchema = StrictObject({\n\ttype: Type.Literal(\"service_update\"),\n\tsubscriptionId: IdSchema,\n\tupdate: OpaqueJsonValueSchema,\n});\n/** Out-of-band update to this presentation's selected Session route. */\nconst AttachmentEnvelopeSchema = StrictObject({\n\ttype: Type.Literal(\"attachment\"),\n\tattachment: Type.Union([SessionTargetSchema, Type.Null()]),\n});\nexport const ServerMessageSchema = Type.Union([\n\tServerHelloSchema,\n\tServerHelloErrorSchema,\n\tResponseEnvelopeSchema,\n\tServiceEventEnvelopeSchema,\n\tAttachmentEnvelopeSchema,\n]);\nexport type ServerHello = Static<typeof ServerHelloSchema>;\nexport type ServerHelloError = Static<typeof ServerHelloErrorSchema>;\nexport type ResponseEnvelope = Static<typeof ResponseEnvelopeSchema>;\nexport type ServiceEventEnvelope = Static<typeof ServiceEventEnvelopeSchema>;\nexport type AttachmentEnvelope = Static<typeof AttachmentEnvelopeSchema>;\nexport type ServerMessage = Static<typeof ServerMessageSchema>;\n"]}