UNPKG

@casual-simulation/aux-common

Version:
561 lines 16.7 kB
import type { Action } from './Action'; import type { ConnectionInfo } from './ConnectionInfo'; import { z } from 'zod'; /** * An event that is used to indicate an event that was sent from a remote device. */ export interface DeviceAction extends Action { type: 'device'; /** * The connection which sent the event. */ connection: ConnectionInfo; /** * The event. */ event: Action; /** * The ID of the task that this action was sent with. */ taskId?: number | string; } export declare const deviceActionSchema: z.ZodObject<{ type: z.ZodLiteral<"device">; connection: z.ZodObject<{ connectionId: z.ZodString; sessionId: z.ZodString; userId: z.ZodString; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; }, { connectionId?: string; sessionId?: string; userId?: string; }>; event: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { type?: "device"; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; event?: any; taskId?: string | number; }, { type?: "device"; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; event?: any; taskId?: string | number; }>; /** * An interface that is used to determine which device to send a remote event to. */ export interface DeviceSelector { /** * The ID of the connection that the event should be sent to. */ connectionId?: string; /** * The ID of the session that the event should be sent to. */ sessionId?: string; /** * The ID of the user that the event should be sent to. */ userId?: string; /** * Whether the event should be broadcast to all users. */ broadcast?: boolean; } export declare const deviceSelectorSchema: z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; }>; export type RemoteActions = RemoteAction | RemoteActionResult | RemoteActionError; /** * An event that is used to send events from this device to a remote device. * * @dochash types/os/event * @docname RemoteAction */ export interface RemoteAction extends Action, DeviceSelector { type: 'remote'; /** * The event that should be sent to the device. */ event: Action; /** * Whether this action is allowed to be batched with other remote actions. * Batching will preserve ordering between remote actions but may * break ordering with respect to bot actions. Defaults to true. */ allowBatching?: boolean; /** * The ID of the task. */ taskId?: number | string; } export declare const remoteActionSchema: z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; type: z.ZodLiteral<"remote">; event: z.ZodAny; allowBatching: z.ZodOptional<z.ZodBoolean>; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote"; event?: any; allowBatching?: boolean; taskId?: string | number; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote"; event?: any; allowBatching?: boolean; taskId?: string | number; }>; /** * An event that is used to respond to remote actions with some arbitrary data. */ export interface RemoteActionResult extends Action, DeviceSelector { type: 'remote_result'; /** * The data that is included in the result. */ result?: any; /** * The ID of the task that this is a result for. */ taskId: number | string; } export declare const remoteActionResultSchema: z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; type: z.ZodLiteral<"remote_result">; result: z.ZodOptional<z.ZodAny>; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_result"; result?: any; taskId?: string | number; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_result"; result?: any; taskId?: string | number; }>; /** * An event that is used to response to remote actions with an error. */ export interface RemoteActionError extends Action, DeviceSelector { type: 'remote_error'; /** * The error that occurred. */ error: any; /** * The ID of the task that this is a result for. */ taskId: number | string; } export declare const remoteActionErrorSchema: z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; type: z.ZodLiteral<"remote_error">; error: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_error"; error?: any; taskId?: string | number; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_error"; error?: any; taskId?: string | number; }>; export declare const remoteActionsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; type: z.ZodLiteral<"remote">; event: z.ZodAny; allowBatching: z.ZodOptional<z.ZodBoolean>; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote"; event?: any; allowBatching?: boolean; taskId?: string | number; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote"; event?: any; allowBatching?: boolean; taskId?: string | number; }>, z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; type: z.ZodLiteral<"remote_result">; result: z.ZodOptional<z.ZodAny>; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_result"; result?: any; taskId?: string | number; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_result"; result?: any; taskId?: string | number; }>, z.ZodObject<{ connectionId: z.ZodOptional<z.ZodString>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; broadcast: z.ZodOptional<z.ZodBoolean>; type: z.ZodLiteral<"remote_error">; error: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_error"; error?: any; taskId?: string | number; }, { connectionId?: string; sessionId?: string; userId?: string; broadcast?: boolean; type?: "remote_error"; error?: any; taskId?: string | number; }>]>; /** * An event that is used to respond to remote actions with some arbitrary data. */ export interface DeviceActionResult extends Action { type: 'device_result'; /** * The data that is included in the result. */ result: any; /** * The ID of the task that this is a result for. */ taskId: number | string; /** * The connection which sent the event. */ connection: ConnectionInfo; } export declare const deviceActionResultSchema: z.ZodObject<{ type: z.ZodLiteral<"device_result">; result: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; connection: z.ZodObject<{ connectionId: z.ZodString; sessionId: z.ZodString; userId: z.ZodString; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; }, { connectionId?: string; sessionId?: string; userId?: string; }>; }, "strip", z.ZodTypeAny, { type?: "device_result"; result?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }, { type?: "device_result"; result?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }>; /** * An event that is used to respond to remote actions with an error. */ export interface DeviceActionError extends Action { type: 'device_error'; /** * The error that is included in the result. */ error: any; /** * The ID of the task that this is a result for. */ taskId: number | string; /** * The connection which sent the event. */ connection: ConnectionInfo; } export declare const deviceActionErrorSchema: z.ZodObject<{ type: z.ZodLiteral<"device_error">; error: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; connection: z.ZodObject<{ connectionId: z.ZodString; sessionId: z.ZodString; userId: z.ZodString; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; }, { connectionId?: string; sessionId?: string; userId?: string; }>; }, "strip", z.ZodTypeAny, { type?: "device_error"; error?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }, { type?: "device_error"; error?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }>; export type DeviceActions = DeviceAction | DeviceActionResult | DeviceActionError; export declare const deviceActionsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{ type: z.ZodLiteral<"device">; connection: z.ZodObject<{ connectionId: z.ZodString; sessionId: z.ZodString; userId: z.ZodString; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; }, { connectionId?: string; sessionId?: string; userId?: string; }>; event: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; }, "strip", z.ZodTypeAny, { type?: "device"; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; event?: any; taskId?: string | number; }, { type?: "device"; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; event?: any; taskId?: string | number; }>, z.ZodObject<{ type: z.ZodLiteral<"device_result">; result: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; connection: z.ZodObject<{ connectionId: z.ZodString; sessionId: z.ZodString; userId: z.ZodString; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; }, { connectionId?: string; sessionId?: string; userId?: string; }>; }, "strip", z.ZodTypeAny, { type?: "device_result"; result?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }, { type?: "device_result"; result?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }>, z.ZodObject<{ type: z.ZodLiteral<"device_error">; error: z.ZodAny; taskId: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>; connection: z.ZodObject<{ connectionId: z.ZodString; sessionId: z.ZodString; userId: z.ZodString; }, "strip", z.ZodTypeAny, { connectionId?: string; sessionId?: string; userId?: string; }, { connectionId?: string; sessionId?: string; userId?: string; }>; }, "strip", z.ZodTypeAny, { type?: "device_error"; error?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }, { type?: "device_error"; error?: any; taskId?: string | number; connection?: { connectionId?: string; sessionId?: string; userId?: string; }; }>]>; /** * Creates a new remote event. * @param event The event. * @param selector The selector that should be used to determine which devices this event should be sent to. * @param allowBatching Whether this action is allowed to be batched with other remote actions. * Batching will preserve ordering between remote actions but may * break ordering with respect to bot actions. Defaults to true. * @param taskId The ID of the task that this remote action represents. */ export declare function remote(event: Action, selector?: DeviceSelector, allowBatching?: boolean, taskId?: number | string): RemoteAction; /** * Creates a new remote event that represents a result to an async task. * @param result The result data. * @param selector The selector that should be used to determine which devices this event should be sent to. * @param taskId The ID of the task that this remote action represents. */ export declare function remoteResult(result: any, selector?: DeviceSelector, taskId?: number | string): RemoteActionResult; /** * Creates a new remote event that represents an error result to an async task. * @param result The result data. * @param selector The selector that should be used to determine which devices this event should be sent to. * @param taskId The ID of the task that this remote action represents. */ export declare function remoteError(error: any, selector?: DeviceSelector, taskId?: number | string): RemoteActionError; /** * Creates a new device event. * @param info The info about the device that is sending the event. * @param data The data included in the result. * @param taskId The ID of the task that this device action represents. */ export declare function device(info: ConnectionInfo, event: Action, taskId?: number | string): DeviceAction; /** * Creates a new device event that represents the result of an async task. * @param info The info about the device that is sending the event. * @param result The result data included in the result. * @param taskId The ID of the task that this device action represents. */ export declare function deviceResult(info: ConnectionInfo, result: any, taskId?: number | string): DeviceActionResult; /** * Creates a new device event that represents an error of an async task. * @param info The info about the device that is sending the event. * @param error The error data included in the result. * @param taskId The ID of the task that this device action represents. */ export declare function deviceError(info: ConnectionInfo, error: any, taskId?: number | string): DeviceActionError; //# sourceMappingURL=RemoteActions.d.ts.map