narrative-studio-sdk
Version:
Narrative SDK for building apps on the Narrative Studio
55 lines (54 loc) • 2.36 kB
TypeScript
import { CommandBase } from './Commands';
import { EventBase } from './Events';
import { Scheme } from "./scheme";
export interface IParams {
}
export type CommandConstructor<T extends CommandBase<IParams>> = new (params: IParams) => T;
export type EventConstructor<T extends EventBase> = {
new (...args: any[]): T;
readonly type: string;
};
interface MessageHandler {
postMessage: (message: any) => void;
addMessageListener: (listener: (event: MessageEvent) => void) => void;
}
export declare class Narrative {
private static messageHandler;
/** @internal */
static _setMessageHandler(handler: MessageHandler): void;
/**
* Creates a new scheme.
* @param scheme - The scheme to create.
* @returns Promise<void | Error> - Resolves on successful scheme creation, returns the error on failure.
*/
static createScheme(scheme: Scheme): Promise<void | Error>;
/**
* Serializes all function references in a scheme (e.g., file transform rules)
* so they can be postMessage-safe and later looked up by ID.
*/
private static serializeSchemeFunctions;
/**
* Replaces function fields with ID references and registers them.
*/
private static serializeFileTransformRules;
/**
* Sends a command to be processed, specifying the command class and its parameters.
* Resolves or rejects based on the command’s result.
* @param CommandClass - The constructor of the command to be sent.
* @param params - Parameters required by the command.
* @returns Promise<void | Error> - Resolves on successful command execution, returns the error on failure.
*/
static sendCommand<T extends IParams>(CommandClass: CommandConstructor<CommandBase<T>>, params: T): Promise<void | Error>;
/**
* Subscribes to specified events and executes a handler function when the event is received.
* @param eventClasses - An array of event constructors to subscribe to.
* @param handler - A function to handle the incoming events.
*/
static subscribeToEvents<T extends EventBase>(eventClasses: EventConstructor<T>[], handler: (event: T) => void): void;
/**
* Updates the ReadModel with the provided data.
* @param data - The data to update the ReadModel with.
*/
static updateReadModel<T>(data: T): void;
}
export {};