import { Observable, ObservableInput } from 'rxjs'; import { DomainConceptName } from './type'; export type SerializablePrimitives = void | undefined | number | string | boolean | null; export type ReadonlySerializableArray = readonly Serializable[]; export type SerializableArray = Serializable[] | ReadonlySerializableArray; export type SerializableObject = { [key: string]: Serializable; }; export type Serializable = SerializablePrimitives | SerializableArray | SerializableObject; export type ToType = T extends object | unknown[] ? { [key in keyof T]: ToType; } : T; export type Args = [] | [arg: T] | [arg?: T]; export type RemeshInjectedContext = { get, U>(input: RemeshQueryAction): U; get(input: RemeshStateItem): state; get(input: RemeshStateItem | RemeshQueryAction): unknown; fromEvent: (Event: RemeshEvent | RemeshSubscribeOnlyEvent) => Observable; fromQuery: , U>(Query: RemeshQueryAction) => Observable; }; export type RemeshEventContext = { get: RemeshInjectedContext['get']; }; export type RemeshEvent = { type: 'RemeshEvent'; eventId: number; eventName: DomainConceptName<'Event'>; impl?: (context: RemeshEventContext, arg: T[0]) => U; (...args: T): RemeshEventAction; emitted: (task: RemeshCommandTask) => void; owner: RemeshDomainAction; inspectable: boolean; toSubscribeOnlyEvent: () => RemeshSubscribeOnlyEvent; }; export type RemeshEventAction = { type: 'RemeshEventAction'; arg: T[0]; Event: RemeshEvent; }; export type RemeshEventOptions = { name: DomainConceptName<'Event'>; inspectable?: boolean; impl: (context: RemeshEventContext, ...args: T) => U; }; export declare function RemeshEvent(options: RemeshEventOptions): RemeshEvent; export declare function RemeshEvent(options: Omit, 'impl'>): RemeshEvent<[T], T>; export type RemeshSubscribeOnlyEvent<_T, _U> = { type: 'RemeshSubscribeOnlyEvent'; eventId: number; eventName: DomainConceptName<'Event'>; }; export type ToRemeshSubscribeOnlyEvent = T extends RemeshSubscribeOnlyEvent ? T : T extends RemeshEvent ? RemeshSubscribeOnlyEvent : never; export type ToRemeshSubscribeOnlyEventMap = { [K in keyof T]: ToRemeshSubscribeOnlyEvent; }; export declare const toRemeshSubscribeOnlyEvent: (event: RemeshEvent) => RemeshSubscribeOnlyEvent; export declare const internalToOriginalEvent: , U>(subscribeOnlyEvent: RemeshSubscribeOnlyEvent) => RemeshEvent; export type CompareFn = (prev: T, curr: T) => boolean; export declare const DefaultStateValue: unique symbol; export type DefaultStateValue = typeof DefaultStateValue; export type RemeshState = { type: 'RemeshState'; stateId: number; stateName: DomainConceptName<'State'>; (): RemeshStateItem; default: T | (() => T) | DefaultStateValue; owner: RemeshDomainAction; compare: CompareFn; inspectable: boolean; }; export type RemeshStateItem = { type: 'RemeshStateItem'; State: RemeshState; new: (state: T) => RemeshStateItemUpdatePayload; }; export type RemeshStateItemUpdatePayload = { type: 'RemeshStateItemUpdatePayload'; key?: string; value: T; stateItem: RemeshStateItem; }; export type RemeshStateOptions = { name: DomainConceptName<'State'>; inspectable?: boolean; compare?: CompareFn; } & ({ default: T | (() => T); } | { defer: true; }); export declare const defaultCompare: (prev: T, curr: T) => boolean; export declare const RemeshState: (options: RemeshStateOptions) => RemeshState; export type RemeshQueryContext = { get: RemeshInjectedContext['get']; }; export type RemeshQuery, U> = { type: 'RemeshQuery'; queryId: number; queryName: DomainConceptName<'Query'>; impl: (context: RemeshQueryContext, arg: T[0]) => U; (...args: T): RemeshQueryAction; owner: RemeshDomainAction; onError?: (error: Error, value: U) => U; compare: CompareFn; changed: (task: RemeshCommandTask<[{ current: U; previous: U; }]>) => void; inspectable: boolean; }; export type RemeshQueryAction, U> = { type: 'RemeshQueryAction'; Query: RemeshQuery; arg: T[0]; }; export type RemeshQueryOptions, U> = { name: DomainConceptName<'Query'>; inspectable?: boolean; impl: (context: RemeshQueryContext, ...args: T) => U; onError?: (error: Error, previous: U) => U; compare?: RemeshQuery['compare']; }; export declare const RemeshQuery: , U>(options: RemeshQueryOptions) => RemeshQuery; export type RemeshCommandContext = { get: RemeshInjectedContext['get']; }; export type RemeshCommandAction = { type: 'RemeshCommandAction'; arg: T[0]; Command: RemeshCommand; }; export type RemeshCommandOutput = RemeshCommandAction | RemeshEventAction | RemeshStateItemUpdatePayload | RemeshCommandOutput[] | null; export type RemeshCommand = { type: 'RemeshCommand'; commandId: number; commandName: DomainConceptName<'Command'>; impl: (context: RemeshCommandContext, arg: T[0]) => RemeshCommandOutput; (...args: T): RemeshCommandAction; owner: RemeshDomainAction; before: (task: RemeshCommandTask) => void; after: (task: RemeshCommandTask) => void; inspectable: boolean; }; type RemeshCommandTask = (context: RemeshCommandContext, ...args: T) => RemeshCommandOutput; export type RemeshCommandOptions = { name: DomainConceptName<'Command'>; inspectable?: boolean; impl: (context: RemeshCommandContext, ...args: T) => RemeshCommandOutput; }; declare const remeshCommandTaskStore: { before: WeakMap, Set>>; after: WeakMap, Set>>; changed: WeakMap, Set>>; emitted: WeakMap, Set>>; }; export declare const getCommandTaskSet: (key: unknown, type: keyof typeof remeshCommandTaskStore) => Set> | undefined; export declare const RemeshCommand: = []>(options: RemeshCommandOptions) => RemeshCommand; export type RemeshExternImpl = { type: 'RemeshExternImpl'; Extern: RemeshExtern; value: T; }; export type RemeshExtern = { type: 'RemeshExtern'; externId: number; default: T; impl(value: T): RemeshExternImpl; }; export type RemeshExternOptions = { default: RemeshExtern['default']; }; export declare const RemeshExtern: (options: RemeshExternOptions) => RemeshExtern; export type RemeshDomainPreloadQueryContext = { get: RemeshInjectedContext['get']; }; export type RemeshDomainPreloadCommandContext = { get: RemeshInjectedContext['get']; }; export type RemeshDomainPreloadCommandOutput = RemeshStateItemUpdatePayload | RemeshDomainPreloadCommandOutput[] | null; export type RemeshDomainPreloadOptions = { key: string; query: (context: RemeshDomainPreloadQueryContext) => Promise; command: (context: RemeshDomainPreloadCommandContext, data: T) => RemeshDomainPreloadCommandOutput; }; export type RemeshEffectContext = { get: RemeshInjectedContext['get']; fromEvent: RemeshInjectedContext['fromEvent']; fromQuery: RemeshInjectedContext['fromQuery']; }; export type RemeshAction = RemeshEventAction | RemeshCommandAction | null | RemeshAction[]; export type RemeshEffect = { name: DomainConceptName<'Effect'>; impl: (context: RemeshEffectContext) => ObservableInput | null; }; export type RemeshDomainContext = { state: typeof RemeshState; event: typeof RemeshEvent; query: typeof RemeshQuery; command: typeof RemeshCommand; effect: (effect: RemeshEffect) => void; preload: (options: RemeshDomainPreloadOptions) => void; getExtern: (Extern: RemeshExtern) => T; getDomain: >(domainAction: RemeshDomainAction) => { [key in keyof VerifiedRemeshDomainDefinition]: VerifiedRemeshDomainDefinition[key]; }; forgetDomain: >(domainAction: RemeshDomainAction) => void; }; export type DomainTypeOf> = T extends RemeshDomain ? VerifiedRemeshDomainDefinition : never; export type RemeshEvents = { [key: string]: RemeshEvent | RemeshSubscribeOnlyEvent; }; export type RemeshQueries = { [key: string]: RemeshQuery; }; export type RemeshCommands = { [key: string]: RemeshCommand; }; export type RemeshDomainOutput = { event: RemeshEvents; query: RemeshQueries; command: RemeshCommands; }; export type RemeshDomainDefinition = Partial; export type VerifiedRemeshDomainDefinition = Pick<{ event: { [key in keyof T['event']]: key extends DomainConceptName<'Event'> ? ToRemeshSubscribeOnlyEvent : `${key & string} is not a valid event name`; }; query: { [key in keyof T['query']]: key extends DomainConceptName<'Query'> ? T['query'][key] : `${key & string} is not a valid query name`; }; command: { [key in keyof T['command']]: key extends DomainConceptName<'Command'> ? T['command'][key] : `${key & string} is not a valid command name`; }; }, ('event' | 'query' | 'command') & keyof T>; export declare const toValidRemeshDomainDefinition: >(domainDefinition: T) => VerifiedRemeshDomainDefinition; export declare const RemeshModule: >(module: T) => VerifiedRemeshDomainDefinition extends infer T_1 ? { [key in keyof T_1]: VerifiedRemeshDomainDefinition[key]; } : never; export type RemeshDomain> = { type: 'RemeshDomain'; domainName: DomainConceptName<'Domain'>; domainId: number; impl: (context: RemeshDomainContext, arg: U[0]) => T; (...args: U): RemeshDomainAction; inspectable: boolean; }; export type RemeshDomainAction> = { type: 'RemeshDomainAction'; Domain: RemeshDomain; arg: U[0]; }; export type RemeshDomainOptions> = { name: DomainConceptName<'Domain'>; inspectable?: boolean; impl: (context: RemeshDomainContext, ...args: U) => T; }; export declare const RemeshDomain: , U extends Args>(options: RemeshDomainOptions) => RemeshDomain; export declare const DefaultDomain: RemeshDomain<{}, []>; export {};