/** * Flattens an intersection type into a single type. */ type FlattenIntersection = T extends object ? { [K in keyof T]: T[K]; } : T; /** * The name of the Transporter protocol is the constant "transporter". */ export declare const protocol = "transporter"; /** * The current version of Transporter in semantic versioning. Different versions * of Transporter are considered compatible if they have the same major and * minor version. Therefore, a server and a client can use different patch * versions of transporter. * * If Transporter receives a message with an incompatible version a warning will * be logged to the console. This should hopefully surface any conflicts during * development. * * It is ok for multiple versions of Transporter to exist at runtime as long as * clients are using a version compatible with the server they are trying to * connect to. For example, a 3rd party dependency could use a different major * or minor version of Transporter as long as its servers and clients are using * a compatible version. */ export declare const version: Version; /** * Transporter may send messages with any of these types. */ export declare enum Type { Call = "Call", Error = "Error", GarbageCollect = "GarbageCollect", Set = "Set" } /** * A semantic version string. */ export type Version = `${number}.${number}.${number}`; /** * A discriminated union of the different types of messages. * * While the creation and interpretation of these messages should be * considered internal, it is ok to intercept these messages and perform your * own encoding on them. By doing so you can create your own protocol stack. */ export type Message = CallFunction | Error | GarbageCollect | SetValue; export type { Message as t }; /** * All messages sent by Transporter have this shape. * * Using a type instead of an interface is intentional as a type is a subtype of * a type with an index signature but an interface is not. This allows a message * to be passed to an encoder of a subprotocol type, with an index signature, * without type errors. */ type MessageBase = { readonly address: string; readonly id: string; readonly protocol: typeof protocol; readonly type: Type; readonly version: Version; }; export type CallFunction = FlattenIntersection; /** * Creates a message to call a remote function. */ export declare const CallFunction: ({ address, args, id, noReply, path }: { address: string; args: Args; id?: string | undefined; noReply?: boolean | undefined; path: string[]; }) => { readonly address: string; readonly id: string; readonly protocol: typeof protocol; readonly type: Type.Call; readonly version: Version; readonly args: Args; readonly path: string[]; readonly noReply: boolean; }; export type Error = FlattenIntersection; /** * The server may respond with an error when calling a function. */ export declare const Error: ({ address, error, id }: { address: string; error: T; id?: string | undefined; }) => { readonly address: string; readonly id: string; readonly protocol: typeof protocol; readonly type: Type.Error; readonly version: Version; readonly error: T; }; export type GarbageCollect = FlattenIntersection; /** * Sent by a client to a server when a proxy is disposed. */ export declare const GarbageCollect: ({ address, id }: { address: string; id?: string | undefined; }) => GarbageCollect; export type SetValue = FlattenIntersection; /** * The server responds with a Set message if calling a function is successful. */ export declare const SetValue: ({ address, id, value }: { address: string; id?: string | undefined; urn?: string | undefined; value: T; }) => { readonly address: string; readonly id: string; readonly protocol: typeof protocol; readonly type: Type.Set; readonly version: Version; readonly value: T; }; /** * Returns `true` if the message is a Transporter message. */ export declare function isMessage(message: T | Message): message is Message; /** * Checks if a message is compatible with the current version of Transporter. */ export declare function isCompatible(messageVersion: Version): boolean; /** * Returns the major, minor, and patch version of a semantic version string. */ export declare function parseVersion(version: Version): [major: string, minor: string, patch: string]; //# sourceMappingURL=Message.d.ts.map