Skip to content

An open-source, self-hosted system for apps built with web technologies.

1.3 KB
Raw Blame
import type { EndpointMetadata, EndpointReference as CoreEndpointReference, ProcessSnapshot } from "@phreshos/core"
import { type Half } from "./process-traffic"
import Process from "./process"

export type ProcessReference = ProcessSnapshot

/**
 * An endpoint identity carried only between trusted boundaries and SDKs.
 *
 * The host derives both fields from its authoritative Process registry.
 * Program code can therefore receive a real Endpoint handle without being
 * able to forge the sender or destination attached to application traffic.
 */
export type EndpointReference = CoreEndpointReference

export function processReference(process: Process): ProcessReference {

    return { ...process.record(), program: process.program.record() }
}

export function endpointReference(process: Process, kind: Half): EndpointReference {

    return { kind, process: processReference(process) } satisfies CoreEndpointReference
}

/**
 * Who an Endpoint is, as every message to or from it carries it: public values, the same for every
 * receiver and observer. Reaching the Endpoint itself goes through its Process, under permissions.
 */
export function endpointMetadata(process: Process, kind: Half): EndpointMetadata {

    return { program: { identity: process.program.identity, name: process.program.name }, process: process.identity, endpoint: kind }
}