/** * Type that takes a value as an argument * and returns a specific value */ type ConstructorType

= (...args: P) => T; /** * The message type from which * values should be received */ interface MessageType { then(resolved: ConstructorType<[T]>, rejected?: ConstructorType<[unknown]>): MessageType; catch(rejected: ConstructorType<[unknown]>): this; } /** * Value type from message */ type MessageTypeValue = T extends MessageType ? U : never; /** * A type that accepts either a message or a raw value */ type MaybeMessage = MessageType | T; /** * A function that helps to ensure that * the message is indeed a message object * and not just a value * * @url https://silentium.pw/article/actual/view */ declare function Actual(message: MaybeMessage): MessageType; /** * Type of an object that can * be destroyed */ interface DestroyableType { destroy(): this; } /** * Represents an object that can provide an answer * whether it was destroyed */ interface DestroyedType { destroyed(): boolean; } /** * An object that allows collecting all disposable objects and * disposing them later all together */ declare function DestroyContainer(): DestroyContainerImpl; declare class DestroyContainerImpl implements DestroyableType { private destructors; private _destroyed; /** * Add one destroyable * @param e * @returns */ add(e: R): R; /** * Add many destroyable objects * @param destroyableList * @returns */ many(destroyableList: unknown[]): this; destroy(): this; destroyed(): boolean; destructor(): () => this; } /** * Handles rejections collection */ declare function Rejections(): RejectionsImpl; /** * Implementation of rejections collection */ declare class RejectionsImpl { private catchers; private lastRejectReason; static globalCatch?: ConstructorType<[unknown]>; reject: (reason: unknown) => void; constructor(); catch(rejected: ConstructorType<[unknown]>): this; destroy(): this; } type MessageExecutorType = (resolve: ConstructorType<[T]>, reject: ConstructorType<[unknown]>, name?: string) => MessageType | (() => void) | void; /** * A message created from an executor function. * The executor function can return a message destruction function. * * @url https://silentium.pw/article/message/view */ declare function Message(executor: MessageExecutorType): MessageImpl; /** * Reactive message implementation * * @url https://silentium.pw/article/message/view */ declare class MessageImpl implements MessageType, DestroyableType { private executor; private rejections; private dc; private myName; constructor(executor: MessageExecutorType, rejections?: RejectionsImpl, dc?: DestroyContainerImpl); then(resolve: ConstructorType<[T]>, rejected?: ConstructorType<[unknown]>): MessageImpl; catch(rejected: ConstructorType<[unknown]>): this; destroy(): this; destroyed(): boolean; name(newName: string): this; } /** * First message - is main * others will be destroyed when first * will be destroyed * * @url https://silentium.pw/article/connected/view */ declare function Connected(main: MessageType, ...m: MaybeMessage[]): MessageImpl; /** * Allows creating an object that definitely has a destructor, * useful to avoid creating unnecessary conditions */ declare function Destroyable(base: T): DestroyableImpl; declare class DestroyableImpl implements DestroyableType { private base; constructor(base: T); destroy(): this; } /** * Create local copy of source what can be destroyed */ declare function Local(_base: MaybeMessage): MessageImpl; declare function Props(...messages: MaybeMessage[]): MessageImpl[]; /** * A component that, on each access, returns a new instance * of a reference type based on the constructor function * * @url https://silentium.pw/article/new-component/view */ declare function New(construct: ConstructorType<[], T>): MessageImpl; /** * Helps convert a value into a message */ declare function Of(value: T): MessageImpl; declare const ResetSilenceCache: unique symbol; /** * Silence is null or undefined * Everything else is not silence * * @url https://silentium.pw/article/silence/view */ declare function Silence(resolve: ConstructorType<[T]>): (v: T | undefined) => void; /** * Silence rule when new value comes */ declare function SilenceUse(): { use(value: unknown, cb: (v: unknown) => unknown): void; }; /** * A type that can accept value */ interface SourceType { use(value: T): this; chain($m: MessageType): MessageType; } /** * Message and source at same time */ type MessageSourceType = MessageType & SourceType; /** * Base message source object, the message what can * accept new values * * @url https://silentium.pw/article/source/view */ declare function Source(messageExecutor: MessageExecutorType, sourceExecutor: ConstructorType<[T]>): SourceImpl; declare class SourceImpl implements MessageSourceType { private sourceExecutor; private message; private silenceUse; constructor(messageExecutor: MessageExecutorType, sourceExecutor: ConstructorType<[T]>); use(value: T): this; then(resolved: ConstructorType<[T]>): this; catch(rejected: ConstructorType<[unknown]>): this; destroy(): this; chain(m: MessageType): MessageType; } declare function SourceComputed(message: MessageType, source: SourceType): SourceImpl; /** * Resolver that does nothing with the passed value, * needed for silent message triggering */ declare function Void(): () => void; type ExtractTypeS = T extends MaybeMessage ? U : never; type ExtractTypesFromArrayS[]> = { [K in keyof T]: ExtractTypeS; }; /** * A message that represents values from * all provided messages as an array. * When all messages emit their values, * the combined value will be returned. * If at least one message later emits a new * value, the updated array with the new value * will be emitted by All. * * @url https://silentium.pw/article/all-component/view */ declare function All(...messages: T): MessageImpl>; /** * A message that emits values received from * any of its bound messages * * @url https://silentium.pw/article/any-component/view */ declare function Any(...messages: MaybeMessage[]): MessageImpl; /** * An message that applies a function * to the value of the base message * * @url https://silentium.pw/article/applied/view */ declare function Applied(base: MaybeMessage, applier: ConstructorType<[T], MaybeMessage>): MessageImpl; /** * Helps represent an message as a primitive type, which can be useful * for cases when you need to always have a reference to the current value * without updating the shared value when the current one changes. * For example, this could be used when passing an authorization token. * It can also be useful for testing or logging purposes. * * @url https://silentium.pw/article/primitive/view */ declare function Primitive($base: MessageType, theValue?: T | null): PrimitiveImpl; declare class PrimitiveImpl { private $base; private theValue; private touched; constructor($base: MessageType, theValue?: T | null); private ensureTouched; [Symbol.toPrimitive](): T | null; primitive(): T | null; primitiveWithException(): T & ({} | undefined); } /** * An information object that helps multiple owners access * a single another information object * * @url https://silentium.pw/article/shared/view */ declare function Shared($base: MessageType | MessageSourceType): SharedImpl; declare class SharedImpl implements MessageSourceType { private $base; private resolver; private lastV; private resolvers; private source?; private isDestroyed; private silenceUse; constructor($base: MessageType | MessageSourceType); then(resolved: ConstructorType<[T]>, rejected?: ConstructorType<[unknown]>): MessageImpl; use(value: T): this; catch(rejected: ConstructorType<[unknown]>): this; destroy(): this; destroyed(): boolean; value(): PrimitiveImpl; chain(m: MessageType): MessageType; } /** * Message with error caught * inside another message * * @url https://silentium.pw/article/catch/view */ declare function Catch($base: MessageType): SharedImpl; type Last$1 = T extends readonly [...infer _, infer L] ? L : never; /** * Chains messages together and triggers * the last message only when all previous messages * have emitted their values. The value of Chain will be the value * of the last message. If any messages * emit a value again after the overall Chain response was already returned, * then Chain emits again with the value of the last message. */ declare function Chain(...messages: T): MessageImpl>>; /** * Component what helps to compute * poor functions, and represent result * as message * * @url https://silentium.pw/article/computed/view */ declare function Computed[], R>(applier: ConstructorType, ...messages: T): MessageImpl; /** * Type for passing action requirements * to an external system */ interface ContextType extends Record { transport: any; params?: Record; result?: ConstructorType<[any]>; error?: ConstructorType<[any]>; value?: any; } /** * The ability to call an external system through * sending a message in a standardized format * ContextType, the list of transport should be defined via * the Context.transport map object * * @url https://silentium.pw/article/context/view */ declare function Context(name: MaybeMessage, params?: MaybeMessage): SourceImpl; declare namespace Context { var transport: Map>; } /** * Connects an external message to an Context message chain * * @url https://silentium.pw/article/context/view */ declare function ContextChain(base: MaybeMessage): (context: ContextType) => void; /** * Message for the arrival of a specific Context message * for specific transport * * @url https://silentium.pw/article/context/view */ declare function ContextOf(transport: string): MessageImpl; /** * If base returns error then * default will return default value * * @url https://silentium.pw/article/default/view */ declare function Default($base: MessageType, _default: MaybeMessage): MessageImpl; /** * Allows applying variables from an message that passes an array to a function, * where each element of the array will be passed as a separate argument * * @url https://silentium.pw/article/destructured/view */ declare function Destructured($base: MaybeMessage, applier: ConstructorType): MessageImpl; /** * When someone asks message for value * if there is no value in message return Error * if message exists return value * * @url https://silentium.pw/article/empty/view */ declare function Empty($base: MessageType, after?: MessageType): MessageImpl; type ExecutorApplier = (executor: (v: T) => void) => (v: T) => void; /** * Applies a value transfer function to the resolver * and returns the same value transfer function for the resolver * Useful for applying functions like debounced or throttle */ declare function ExecutorApplied($base: MessageType, applier: ExecutorApplier): MessageImpl; /** * Filters values from the source message based on a predicate function, * optionally providing a default value when the predicate fails. */ declare function Filtered(base: MaybeMessage, predicate: ConstructorType<[T], boolean>, defaultValue?: T): MessageType; /** * Reduces values of message data to one common value */ declare function Fold(data: MaybeMessage, reducer: (acc: TG, item: T[number], index: number) => TG, initial: MaybeMessage): MessageImpl; /** * Message what freezes first known value */ declare function Freeze($base: MessageType, $invalidate?: MessageType): MessageImpl; /** * A message derived from event with a different * method call interface, based on callbacks. * Allows attaching a custom handler to an existing event source * and presenting it as a silentium message */ declare function FromEvent(emitter: MaybeMessage, eventName: MaybeMessage, subscribeMethod: MaybeMessage, unsubscribeMethod?: MaybeMessage): MessageImpl; /** * A component that allows creating linked objects of information and its owner * in such a way that if a new value is assigned to the owner, this value * will become the value of the linked information source * * @url https://silentium.pw/article/late/view */ declare function Late(v?: T): SharedImpl; declare class LateImpl implements MessageSourceType { private v?; private rejections; private lateR; private notify; private silenceUse; constructor(v?: T | undefined); then(r: ConstructorType<[T]>): this; use(value: T): this; catch(rejected: ConstructorType<[unknown]>): this; chain(m: MessageType): MessageType; destroy(): this; } /** * Ability to create new messages when they will be needed * * @url https://silentium.pw/article/lazy/view */ declare function Lazy(constructor: () => MessageType): MessageImpl; /** * Component that applies an info object constructor to each data item, * producing an information source with new values * * @url https://silentium.pw/article/map/view */ declare function Map$1(base: MaybeMessage, target: ConstructorType<[any], MessageType>): MessageImpl; /** * Limits the number of values from the information source * to a single value - once the first value is emitted, no more * values are delivered from the source * * @url https://silentium.pw/article/once/view */ declare function Once($base: MessageType): MessageImpl; type Last = T extends readonly [...infer _, infer L] ? L extends (...args: any) => any ? L : never : never; /** * Helps to pipe actors or functions to one common actor * * @url https://silentium.pw/article/piped/view */ declare function Piped MaybeMessage)[]>($m: MaybeMessage, ...c: T): ReturnType>; declare function Process($base: MessageType, builder: ConstructorType<[T], MessageType>): MessageImpl; /** * Convert message to promise */ declare function Promisify($message: MessageType): Promise; /** * First responded message * * @url https://silentium.pw/article/race/view */ declare function Race(...messages: T): MessageImpl; /** * Creates a sequence that accumulates all values from the source into an array, * emitting the growing array with each new value. */ declare function Sequence($base: MessageType): MessageImpl; /** * Component that receives a data array and yields values one by one */ declare function Stream(base: MaybeMessage): MessageImpl; /** * Track creation and destruction of components * uses Context component to send messages * when created sends action=created * when destroyed sends action=destroyed * * @url https://silentium.pw/article/trackable/view */ declare function Trackable(name: string, target: T): T; interface PassiveType { value: T | null; } /** * Component what will return same proxied object * but with value property * * @url https://silentium.pw/article/value/view */ declare function Value(target: MessageType): MessageType & PassiveType; declare global { interface SilentiumDebug { value: ($message: MessageType) => unknown; print: (...messages: MessageType[]) => void; destroyable: (onDestroy: () => void) => MessageType & DestroyableType; } interface GlobalThis { silentiumDebug: SilentiumDebug; } const silentiumDebug: SilentiumDebug; } declare class MessageDestroyable implements MessageType, DestroyableType { private onDestroy; constructor(onDestroy: () => void); then(resolve: ConstructorType<[string]>): this; catch(): this; destroy(): this; } /** * global functions for debuging * silentium programs */ declare function DevTools(): void; declare function ensureFunction(v: unknown, label: string): void; declare function ensureMessage(v: unknown, label: string): void; /** * Checks that the value is neither undefined nor null */ declare const isFilled: (value?: T) => value is Exclude; /** * Checks that the object is an message */ declare function isMessage(o: unknown): o is MessageType; /** * Checks that the object is an message */ declare function isSource(o: unknown): o is SourceType; /** * Checks that the object is destroyable */ declare function isDestroyable(o: unknown): o is DestroyableType; /** * Checks that the object can indicate whether it has been destroyed or not */ declare function isDestroyed(o: unknown): o is DestroyedType; export { Actual, All, Any, Applied, Catch, Chain, Computed, Connected, Context, ContextChain, ContextOf, Default, DestroyContainer, DestroyContainerImpl, Destroyable, DestroyableImpl, Destructured, DevTools, Empty, ExecutorApplied, Filtered, Fold, Freeze, FromEvent, Late, LateImpl, Lazy, Local, Map$1 as Map, Message, MessageDestroyable, MessageImpl, New, Of, Once, Piped, Primitive, PrimitiveImpl, Process, Promisify, Props, Race, Rejections, RejectionsImpl, ResetSilenceCache, Sequence, Shared, SharedImpl, Silence, SilenceUse, Source, SourceComputed, SourceImpl, Stream, Trackable, Value, Void, ensureFunction, ensureMessage, isDestroyable, isDestroyed, isFilled, isMessage, isSource }; export type { ConstructorType, ContextType, DestroyableType, DestroyedType, MaybeMessage, MessageExecutorType, MessageSourceType, MessageType, MessageTypeValue, PassiveType, SourceType };