silentium 0.0.160 → 0.0.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/silentium.cjs +81 -48
- package/dist/silentium.cjs.map +1 -1
- package/dist/silentium.d.ts +9 -4
- package/dist/silentium.js +81 -49
- package/dist/silentium.js.map +1 -1
- package/dist/silentium.min.js +1 -1
- package/dist/silentium.min.mjs +1 -1
- package/dist/silentium.min.mjs.map +1 -1
- package/dist/silentium.mjs +81 -49
- package/dist/silentium.mjs.map +1 -1
- package/package.json +1 -1
- package/src/base/Message.ts +3 -9
- package/src/components/All.ts +4 -3
- package/src/components/Any.ts +3 -2
- package/src/components/Applied.ts +3 -2
- package/src/components/Chain.ts +28 -25
- package/src/components/ContextOf.ts +3 -2
- package/src/components/ExecutorApplied.ts +3 -2
- package/src/components/Filtered.ts +4 -3
- package/src/components/Freeze.test.ts +124 -0
- package/src/components/Freeze.ts +22 -0
- package/src/components/FromEvent.ts +6 -2
- package/src/components/Map.ts +3 -2
- package/src/components/Once.ts +3 -2
- package/src/components/Sequence.ts +3 -2
- package/src/components/Stream.ts +3 -2
- package/src/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"silentium.min.mjs","sources":["../src/helpers/guards.ts","../src/base/Destroyable.ts","../src/base/DestroyContainer.ts","../src/base/Rejections.ts","../src/helpers/ensures.ts","../src/base/Message.ts","../src/base/Of.ts","../src/base/ActualMessage.ts","../src/base/Chainable.ts","../src/base/Local.ts","../src/base/MessageSource.ts","../src/base/New.ts","../src/base/Void.ts","../src/components/All.ts","../src/components/Any.ts","../src/components/Applied.ts","../src/components/AppliedDestructured.ts","../src/components/Late.ts","../src/components/Catch.ts","../src/components/Chain.ts","../src/components/Context.ts","../src/components/ContextChain.ts","../src/components/Primitive.ts","../src/components/Shared.ts","../src/components/LateShared.ts","../src/components/ContextOf.ts","../src/components/Filtered.ts","../src/components/Empty.ts","../src/components/ExecutorApplied.ts","../src/components/FromEvent.ts","../src/components/Map.ts","../src/components/Once.ts","../src/components/Process.ts","../src/components/Sequence.ts","../src/components/Stream.ts"],"sourcesContent":["import { DestroyableType, DestroyedType } from \"types/DestroyableType\";\nimport { MessageType } from \"types/MessageType\";\nimport { SourceType } from \"types/SourceType\";\n\n/**\n * Checks that the value is neither undefined nor null\n */\nexport const isFilled = <T>(\n value?: T,\n): value is Exclude<T, null | undefined> => {\n return value !== undefined && value !== null;\n};\n\n/**\n * Checks that the object is an message\n */\nexport function isMessage(o: unknown): o is MessageType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"then\" in o &&\n typeof (o as any).then === \"function\"\n );\n}\n\n/**\n * Checks that the object is an message\n */\nexport function isSource(o: unknown): o is SourceType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"use\" in o &&\n typeof (o as any).use === \"function\"\n );\n}\n\n/**\n * Checks that the object is destroyable\n */\nexport function isDestroyable(o: unknown): o is DestroyableType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"destroy\" in o &&\n typeof (o as any).destroy === \"function\"\n );\n}\n\n/**\n * Checks that the object can indicate whether it has been destroyed or not\n */\nexport function isDestroyed(o: unknown): o is DestroyedType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"destroyed\" in o &&\n typeof (o as any).destroyed === \"function\"\n );\n}\n","import { isDestroyable } from \"helpers/guards\";\nimport { DestroyableType } from \"types/DestroyableType\";\n\n/**\n * Allows creating an object that definitely has a destructor,\n * useful to avoid creating unnecessary conditions\n */\nexport function Destroyable<T>(base: T) {\n return new DestroyableImpl(base);\n}\n\nexport class DestroyableImpl<T> implements DestroyableType {\n public constructor(private base: T) {}\n\n public destroy(): this {\n if (isDestroyable(this.base)) {\n this.base.destroy();\n }\n\n if (typeof this.base === \"function\") {\n this.base();\n }\n\n return this;\n }\n}\n","import { Destroyable } from \"base/Destroyable\";\nimport { DestroyableType } from \"types/DestroyableType\";\n\n/**\n * An object that allows collecting all disposable objects and\n * disposing them later all together\n */\nexport function DestroyContainer() {\n return new DestroyContainerImpl();\n}\n\nexport class DestroyContainerImpl implements DestroyableType {\n private destructors: DestroyableType[] = [];\n\n public add<R>(e: R): R {\n this.destructors.push(Destroyable(e));\n return e;\n }\n\n public destroy() {\n this.destructors.forEach((d) => d.destroy());\n this.destructors.length = 0;\n return this;\n }\n}\n","import { ConstructorType } from \"types/ConstructorType\";\n\n/**\n * Handles rejections collection\n */\nexport class Rejections {\n private catchers: ConstructorType<[unknown]>[] = [];\n private lastRejectReason: unknown = null;\n\n public reject = (reason: unknown) => {\n this.lastRejectReason = reason;\n this.catchers.forEach((catcher) => {\n catcher(reason);\n });\n };\n\n public catch(rejected: ConstructorType<[unknown]>) {\n if (this.lastRejectReason !== null) {\n rejected(this.lastRejectReason);\n }\n this.catchers.push(rejected);\n return this;\n }\n\n public destroy() {\n this.catchers.length = 0;\n return this;\n }\n}\n","import { isMessage } from \"helpers/guards\";\n\nexport function ensureFunction(v: unknown, label: string) {\n if (typeof v !== \"function\") {\n throw new Error(`${label}: is not function`);\n }\n}\n\nexport function ensureMessage(v: unknown, label: string) {\n if (!isMessage(v)) {\n throw new Error(`${label}: is not message`);\n }\n}\n","import { DestroyContainer } from \"base/DestroyContainer\";\nimport { Rejections } from \"base/Rejections\";\nimport { ensureFunction } from \"helpers/ensures\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { DestroyableType } from \"types/DestroyableType\";\nimport { MessageType } from \"types/MessageType\";\n\nexport type MessageExecutorType<T> = (\n resolve: ConstructorType<[T]>,\n reject: ConstructorType<[unknown]>,\n) => MessageType | (() => void) | void;\n\n/**\n * A message created from an executor function.\n * The executor function can return a message destruction function.\n */\nexport function Message<T>(\n executor: MessageExecutorType<T>,\n everyThenCallsExecutor: boolean = false,\n) {\n return new MessageRx<T>(executor, everyThenCallsExecutor);\n}\n\n/**\n * Reactive message implementation\n */\nexport class MessageRx<T> implements MessageType<T>, DestroyableType {\n private rejections = new Rejections();\n private dc = DestroyContainer();\n\n public constructor(\n private executor: MessageExecutorType<T>,\n private everyThenCallsExecutor: boolean = false,\n ) {\n ensureFunction(executor, \"Message: executor\");\n }\n\n public then(resolve: ConstructorType<[T]>) {\n try {\n this.dc.add(this.executor(resolve, this.rejections.reject));\n } catch (e: any) {\n this.rejections.reject(e);\n }\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>) {\n this.rejections.catch(rejected);\n return this;\n }\n\n public destroy() {\n this.dc.destroy();\n this.rejections.destroy();\n return this;\n }\n}\n","import { Message } from \"base/Message\";\n\n/**\n * Helps convert a value into a message\n */\nexport function Of<T>(value: T) {\n return Message<T>(function OfImpl(r) {\n r(value);\n });\n}\n","import { Of } from \"base/Of\";\nimport { isMessage } from \"helpers/guards\";\nimport { MaybeMessage, MessageType } from \"types/MessageType\";\n\n/**\n * A function that helps to ensure that\n * the message is indeed a message object\n * and not just a value\n */\nexport function ActualMessage<T>(message: MaybeMessage<T>): MessageType<T> {\n return isMessage(message) ? message : Of(message);\n}\n","import { ChainableType } from \"types/ChainableType\";\nimport { MessageType } from \"types/MessageType\";\nimport { SourceType } from \"types/SourceType\";\n\n/**\n * Helps to connect Different\n * message and source\n */\nexport function Chainable<T>(src: SourceType<T>) {\n return new ChainableImpl(src);\n}\n\nexport class ChainableImpl<T> implements ChainableType<T> {\n public constructor(private src: SourceType<T>) {}\n\n public chain($m: MessageType<T>) {\n $m.then(this.src.use.bind(this.src));\n return this;\n }\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * Create local copy of source what can be destroyed\n */\nexport function Local<T>(_base: MaybeMessage<T>) {\n const $base = ActualMessage(_base);\n return Message<T>(function LocalImpl(r) {\n let destroyed = false;\n $base.then((v) => {\n if (!destroyed) {\n r(v);\n }\n });\n return () => {\n destroyed = true;\n };\n });\n}\n","import { Message, MessageExecutorType, MessageRx } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MessageSourceType } from \"types/SourceType\";\n\n/**\n * Base message source object\n */\nexport function MessageSource<T>(\n messageExecutor: MessageExecutorType<T>,\n sourceExecutor: ConstructorType<[T]>,\n) {\n return new MessageSourceImpl(messageExecutor, sourceExecutor);\n}\n\nexport class MessageSourceImpl<T> implements MessageSourceType<T> {\n private message: MessageRx<T>;\n\n public constructor(\n messageExecutor: MessageExecutorType<T>,\n private sourceExecutor: ConstructorType<[T]>,\n ) {\n this.message = Message(messageExecutor);\n }\n\n public use(value: T): this {\n this.sourceExecutor(value);\n return this;\n }\n\n public then(resolved: ConstructorType<[T]>): this {\n this.message.then(resolved);\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>): this {\n this.message.catch(rejected);\n return this;\n }\n}\n","import { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\n\n/**\n * A component that, on each access, returns a new instance\n * of a reference type based on the constructor function\n */\nexport function New<T>(construct: ConstructorType<[], T>) {\n return Message<T>(function NewImpl(resolve) {\n resolve(construct());\n });\n}\n","/**\n * Resolver that does nothing with the passed value,\n * needed for silent message triggering\n */\nexport function Void() {\n return () => {};\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\ntype ExtractTypeS<T> = T extends MaybeMessage<infer U> ? U : never;\n\ntype ExtractTypesFromArrayS<T extends MaybeMessage<any>[]> = {\n [K in keyof T]: ExtractTypeS<T[K]>;\n};\n\nconst isAllFilled = (keysFilled: Set<string>, keysKnown: Set<string>) => {\n return keysFilled.size > 0 && keysFilled.size === keysKnown.size;\n};\n\n/**\n * A message that represents values from\n * all provided messages as an array.\n * When all messages emit their values,\n * the combined value will be returned.\n * If at least one message later emits a new\n * value, the updated array with the new value\n * will be emitted by All.\n */\nexport function All<const T extends MaybeMessage[]>(...messages: T) {\n const $messages = messages.map(ActualMessage);\n return Message<ExtractTypesFromArrayS<T>>(function AllImpl(r) {\n const known = new Set<string>(Object.keys(messages));\n const filled = new Set<string>();\n const result: unknown[] = [];\n if (known.size === 0) {\n r([] as ExtractTypesFromArrayS<T>);\n return;\n }\n $messages.map((m, key) => {\n m.then((v) => {\n filled.add(key.toString());\n result[key] = v;\n if (isAllFilled(filled, known)) {\n r(result as ExtractTypesFromArrayS<T>);\n }\n });\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * A message that emits values received from\n * any of its bound messages\n */\nexport function Any<const T>(...messages: MaybeMessage<T>[]) {\n const $messages = messages.map(ActualMessage);\n return Message<T>(function AnyImpl(r) {\n $messages.forEach((message) => {\n message.then(r);\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * An message that applies a function\n * to the value of the base message\n */\nexport function Applied<const T, R>(\n base: MaybeMessage<T>,\n applier: ConstructorType<[T], R>,\n) {\n const $base = ActualMessage(base);\n return Message<R>(function AppliedImpl(r) {\n $base.then((v) => {\n r(applier(v));\n });\n });\n}\n","import { Applied } from \"components/Applied\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * Allows applying variables from an message that passes an array to a function,\n * where each element of the array will be passed as a separate argument\n */\nexport function AppliedDestructured<const T extends any[], R>(\n $base: MaybeMessage<T>,\n applier: ConstructorType<T[number][], R>,\n) {\n return Applied($base, function AppliedDestructuredImpl(args) {\n return applier(...args);\n });\n}\n","import { Rejections } from \"base/Rejections\";\nimport { isFilled } from \"helpers/guards\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MessageSourceType } from \"types/SourceType\";\n\n/**\n * A component that allows creating linked objects of information and its owner\n * in such a way that if a new value is assigned to the owner, this value\n * will become the value of the linked information source\n * https://silentium-lab.github.io/silentium/#/en/information/of\n */\nexport function Late<T>(v?: T) {\n return new LateImpl<T>(v);\n}\n\nexport class LateImpl<T> implements MessageSourceType<T> {\n private rejections = new Rejections();\n private lateR: ConstructorType<[T]> | null = null;\n private notify = () => {\n if (isFilled(this.v) && this.lateR) {\n try {\n this.lateR(this.v);\n } catch (e: any) {\n this.rejections.reject(e);\n }\n }\n };\n\n public constructor(private v?: T) {}\n\n public then(r: ConstructorType<[T]>): this {\n if (this.lateR) {\n throw new Error(\n \"Late component gets new resolver, when another was already connected!\",\n );\n }\n this.lateR = r;\n this.notify();\n return this;\n }\n\n public use(value: T): this {\n this.v = value;\n this.notify();\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>) {\n this.rejections.catch(rejected);\n return this;\n }\n}\n","import { Rejections } from \"base/Rejections\";\nimport { Late } from \"components/Late\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Message with error catched\n * inside another message\n */\nexport function Catch<T>($base: MessageType) {\n const rejections = new Rejections();\n $base.catch(rejections.reject);\n const $error = Late<T>();\n rejections.catch((e) => {\n $error.use(e as T);\n });\n\n return $error;\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MessageType, MessageTypeValue } from \"types/MessageType\";\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype Last<T extends readonly any[]> = T extends readonly [...infer _, infer L]\n ? L\n : never;\n\n/**\n * Chains messages together and triggers\n * the last message only when all previous messages\n * have emitted their values. The value of Chain will be the value\n * of the last message. If any messages\n * emit a value again after the overall Chain response was already returned,\n * then Chain emits again with the value of the last message.\n */\nexport function Chain<T extends readonly MessageType[]>(...messages: T) {\n const $messages = messages.map(ActualMessage);\n return Message<MessageTypeValue<Last<T>>>(function ChainImpl(r) {\n let $latest: MessageTypeValue<Last<T>> | undefined;\n const handleMessage = (index: number) => {\n const message = $messages[index] as Last<T>;\n const next = $messages[index + 1] as Last<T> | undefined;\n message.then((v) => {\n oneMessage(v as MessageTypeValue<Last<T>>, next, index);\n });\n };\n function oneMessage(\n v: MessageTypeValue<Last<T>>,\n next: Last<T> | undefined,\n index: number,\n ) {\n if (!next) {\n $latest = v as MessageTypeValue<Last<T>>;\n }\n if ($latest) {\n r($latest);\n }\n if (next && !$latest) {\n handleMessage(index + 1);\n }\n }\n handleMessage(0);\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { ContextType } from \"types/ContextType\";\nimport { MaybeMessage } from \"types/MessageType\";\n\nContext.transport = new Map<any, ConstructorType<[ContextType]>>();\n\n/**\n * The ability to call an external system through\n * sending a message in a standardized format\n * ContextType, the list of transport should be defined via\n * the Context.transport map object\n */\nexport function Context<T>(msg: MaybeMessage<ContextType>) {\n const $msg = ActualMessage(msg);\n return Message<T>((resolve, reject) => {\n $msg.then((message) => {\n const transport = Context.transport.get(message.transport);\n if (transport === undefined) {\n throw new Error(`Context: unknown transport ${message.transport}`);\n }\n if (!message.result) {\n message.result = resolve;\n }\n if (!message.error) {\n message.error = reject;\n }\n try {\n transport(message);\n } catch (error) {\n reject(error);\n }\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { MaybeMessage } from \"types/MessageType\";\nimport { ContextType } from \"types/ContextType\";\n\n/**\n * Connects an external message to an RPC message chain\n */\nexport function ContextChain(base: MaybeMessage) {\n const $base = ActualMessage(base);\n return (context: ContextType) => {\n if (!context.result) {\n throw new Error(\"ContextChain did not find result in rpc message\");\n }\n $base.then(context.result);\n };\n}\n","import { MessageType } from \"types/MessageType\";\n\n/**\n * Helps represent an message as a primitive type, which can be useful\n * for cases when you need to always have a reference to the current value\n * without updating the shared value when the current one changes.\n * For example, this could be used when passing an authorization token.\n * It can also be useful for testing or logging purposes.\n */\nexport function Primitive<T>($base: MessageType<T>, theValue: T | null = null) {\n return new PrimitiveImpl<T>($base, theValue);\n}\n\nexport class PrimitiveImpl<T> {\n private touched = false;\n\n public constructor(\n private $base: MessageType<T>,\n private theValue: T | null = null,\n ) {}\n\n private ensureTouched() {\n if (!this.touched) {\n this.$base.then((v) => {\n this.theValue = v;\n });\n }\n this.touched = true;\n }\n\n public [Symbol.toPrimitive]() {\n this.ensureTouched();\n return this.theValue;\n }\n\n public primitive() {\n this.ensureTouched();\n return this.theValue;\n }\n\n public primitiveWithException() {\n this.ensureTouched();\n if (this.theValue === null) {\n throw new Error(\"Primitive value is null\");\n }\n return this.theValue;\n }\n}\n","import { MessageType } from \"types/MessageType\";\nimport { MessageSourceType, SourceType } from \"types/SourceType\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { isFilled, isSource } from \"helpers/guards\";\nimport { Primitive } from \"components/Primitive\";\nimport { ChainableType } from \"types/ChainableType\";\n\n/**\n * An information object that helps multiple owners access\n * a single another information object\n */\nexport function Shared<T>($base: MessageType<T> | MessageSourceType<T>) {\n return new SharedImpl<T>($base);\n}\n\nexport class SharedImpl<T> implements MessageSourceType<T>, ChainableType<T> {\n private resolver = (v: T) => {\n this.lastV = v;\n this.resolvers.forEach((r) => {\n r(v);\n });\n };\n private lastV: T | undefined;\n private resolvers = new Set<ConstructorType<[T]>>();\n private source?: SourceType<T>;\n\n public constructor(private $base: MessageType<T> | MessageSourceType<T>) {\n if (isSource($base)) {\n this.source = $base;\n }\n }\n\n public then(resolved: ConstructorType<[T]>) {\n this.resolvers.add(resolved);\n if (this.resolvers.size === 1) {\n this.$base.then(this.resolver);\n } else if (isFilled(this.lastV)) {\n resolved(this.lastV);\n }\n return this;\n }\n\n public use(value: T) {\n if (this.source) {\n this.source.use(value);\n } else {\n this.resolver(value);\n }\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>) {\n this.$base.catch(rejected);\n return this;\n }\n\n public destroy() {\n this.resolvers.clear();\n return this;\n }\n\n public value() {\n return Primitive(this);\n }\n\n public chain(m: MessageType<T>) {\n m.then(this.use.bind(this));\n return this;\n }\n}\n","import { Late } from \"components/Late\";\nimport { Shared } from \"components/Shared\";\n\n/**\n * An message with a value that will be set later,\n * capable of responding to many resolvers\n */\nexport function LateShared<T>(value?: T) {\n const l = Late(value);\n return Shared(l);\n}\n","import { Message } from \"base/Message\";\nimport { LateShared } from \"components/LateShared\";\nimport { Context } from \"components/Context\";\nimport { ContextType } from \"types/ContextType\";\n\n/**\n * Message for the arrival of a specific RPC message\n * for specific transport\n */\nexport function ContextOf(transport: string) {\n const $msg = LateShared<ContextType>();\n Context.transport.set(transport, $msg.use.bind($msg));\n return Message<ContextType>((t) => {\n $msg.then(t);\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MaybeMessage, MessageType } from \"types/MessageType\";\n\n/**\n * Filters values from the source message based on a predicate function,\n * optionally providing a default value when the predicate fails.\n */\nexport function Filtered<T>(\n base: MaybeMessage<T>,\n predicate: ConstructorType<[T], boolean>,\n defaultValue?: T,\n): MessageType<T> {\n const $base = ActualMessage(base);\n return Message<T>(function FilteredImpl(r) {\n $base.then((v) => {\n if (predicate(v)) {\n r(v);\n } else if (defaultValue !== undefined) {\n r(defaultValue);\n }\n });\n });\n}\n","import { Filtered } from \"components/Filtered\";\nimport { LateShared } from \"components/LateShared\";\nimport { Shared } from \"components/Shared\";\nimport { EmptyType } from \"types/EmptyType\";\nimport { MessageType } from \"types/MessageType\";\n\nexport const Nothing = Symbol(\"nothing\");\n\n/**\n * Helps to split message and empty\n * response\n */\nexport function Empty<T>($base: MessageType<T>) {\n return new EmptyImpl<T>($base);\n}\n\nexport class EmptyImpl<T> implements EmptyType {\n private $empty = LateShared<boolean>();\n\n public constructor(private $base: MessageType<T>) {}\n\n public message() {\n Shared(this.$base).then((v) => {\n if (v === Nothing) {\n this.$empty.use(true);\n }\n });\n return Filtered(this.$base, (v) => v !== Nothing);\n }\n\n public empty(): MessageType<boolean> {\n return this.$empty;\n }\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\ntype ExecutorApplier<T> = (executor: (v: T) => void) => (v: T) => void;\n\n/**\n * Applies a value transfer function to the resolver\n * and returns the same value transfer function for the resolver\n * Useful for applying functions like debounced or throttle\n */\nexport function ExecutorApplied<T>(\n $base: MessageType<T>,\n applier: ExecutorApplier<T>,\n) {\n return Message<T>(function ExecutorAppliedImpl(r) {\n $base.then(applier(r));\n });\n}\n","import { MaybeMessage } from \"types/MessageType\";\nimport { All } from \"components/All\";\nimport { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\n\n/**\n * A message derived from event with a different\n * method call interface, based on callbacks.\n * Allows attaching a custom handler to an existing event source\n * and presenting it as a silentium message\n */\nexport function FromEvent<T>(\n emitter: MaybeMessage<any>,\n eventName: MaybeMessage<string>,\n subscribeMethod: MaybeMessage<string>,\n unsubscribeMethod?: MaybeMessage<string>,\n) {\n const $emitter = ActualMessage(emitter);\n const $eventName = ActualMessage(eventName);\n const $subscribeMethod = ActualMessage(subscribeMethod);\n const $unsubscribeMethod = ActualMessage(unsubscribeMethod);\n return Message<T>((r) => {\n let lastR: ConstructorType<[T]> | null = null;\n const handler = (v: T) => {\n if (lastR) {\n lastR(v);\n }\n };\n All($emitter, $eventName, $subscribeMethod).then(\n ([emitter, eventName, subscribe]) => {\n lastR = r;\n if (!emitter?.[subscribe]) {\n return;\n }\n emitter[subscribe](eventName, handler);\n },\n );\n return () => {\n lastR = null;\n if (!$unsubscribeMethod) {\n return;\n }\n All($emitter, $eventName, $unsubscribeMethod).then(\n ([emitter, eventName, unsubscribe]) => {\n emitter?.[unsubscribe as string]?.(eventName, handler);\n },\n );\n };\n });\n}\n","import { MaybeMessage, MessageType } from \"types/MessageType\";\nimport { All } from \"components/All\";\nimport { isMessage } from \"helpers/guards\";\nimport { Of } from \"base/Of\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { Message } from \"base/Message\";\nimport { ActualMessage } from \"base/ActualMessage\";\nimport { DestroyContainer } from \"base/DestroyContainer\";\n\n/**\n * Component that applies an info object constructor to each data item,\n * producing an information source with new values\n */\nexport function Map<T, TG>(\n base: MaybeMessage<T[]>,\n target: ConstructorType<[any], MessageType<TG>>,\n) {\n const $base = ActualMessage(base);\n return Message<TG[]>((r) => {\n const infos: MessageType<TG>[] = [];\n const dc = DestroyContainer();\n $base.then((v) => {\n dc.destroy();\n v.forEach((val) => {\n let $val: MessageType<T> | T = val;\n if (!isMessage($val as object)) {\n $val = Of($val);\n }\n const info = target($val);\n dc.add(info);\n infos.push(info);\n });\n All(...infos).then(r);\n });\n });\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Limits the number of values from the information source\n * to a single value - once the first value is emitted, no more\n * values are delivered from the source\n */\nexport function Once<T>($base: MessageType<T>) {\n return Message<T>((r) => {\n let isFilled = false;\n $base.then((v) => {\n if (!isFilled) {\n isFilled = true;\n r(v);\n }\n });\n });\n}\n","import { DestroyContainer } from \"base/DestroyContainer\";\nimport { Message } from \"base/Message\";\nimport { LateShared } from \"components/LateShared\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MessageType } from \"types/MessageType\";\n\nexport function Process<T, R = unknown>(\n $base: MessageType<T>,\n builder: ConstructorType<[T], MessageType<R>>,\n) {\n return Message<R>((resolve, reject) => {\n const $res = LateShared<R>();\n const dc = DestroyContainer();\n\n $base.then((v) => {\n dc.destroy();\n const $msg = builder(v);\n dc.add($msg);\n $res.chain($msg);\n $msg.catch(reject);\n });\n $base.catch(reject);\n $res.then(resolve);\n\n return () => {\n dc.destroy();\n };\n });\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Creates a sequence that accumulates all values from the source into an array,\n * emitting the growing array with each new value.\n */\nexport function Sequence<T>($base: MessageType<T>) {\n return Message<T[]>((r) => {\n const result: T[] = [];\n $base.then((v) => {\n result.push(v);\n r(result);\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * Component that receives a data array and yields values one by one\n */\nexport function Stream<T>(base: MaybeMessage<T[]>) {\n const $base = ActualMessage(base);\n return Message<T>((r) => {\n $base.then((v) => {\n v.forEach((cv) => {\n r(cv);\n });\n });\n });\n}\n"],"names":["isFilled","value","isMessage","o","then","isSource","use","isDestroyable","destroy","isDestroyed","destroyed","Destroyable","base","DestroyableImpl","constructor","this","DestroyContainer","DestroyContainerImpl","__publicField","add","e","destructors","push","forEach","d","length","Rejections","reason","lastRejectReason","catchers","catcher","rejected","ensureFunction","v","label","Error","ensureMessage","Message","executor","everyThenCallsExecutor","MessageRx","resolve","dc","rejections","reject","catch","Of","r","ActualMessage","message","Chainable","src","ChainableImpl","chain","$m","bind","Local","_base","$base","MessageSource","messageExecutor","sourceExecutor","MessageSourceImpl","resolved","New","construct","Void","All","messages","$messages","map","known","Set","Object","keys","filled","result","size","m","key","keysFilled","keysKnown","toString","Any","Applied","applier","AppliedDestructured","args","Late","LateImpl","lateR","notify","Catch","$error","Chain","$latest","handleMessage","index","next","oneMessage","Context","msg","$msg","transport","get","error","ContextChain","context","Map","Primitive","theValue","PrimitiveImpl","ensureTouched","touched","Symbol","toPrimitive","primitive","primitiveWithException","Shared","SharedImpl","lastV","resolvers","source","resolver","clear","LateShared","ContextOf","set","t","Filtered","predicate","defaultValue","Nothing","Empty","EmptyImpl","$empty","empty","ExecutorApplied","FromEvent","emitter","eventName","subscribeMethod","unsubscribeMethod","$emitter","$eventName","$subscribeMethod","$unsubscribeMethod","lastR","handler","subscribe","unsubscribe","target","infos","val","$val","info","Once","Process","builder","$res","Sequence","Stream","cv"],"mappings":"AAOa,MAAAA,EACXC,GAEOA,QAMF,SAASC,EAAUC,GAEtB,OAAM,OAANA,GACa,iBAANA,GACP,SAAUA,GACiB,mBAAnBA,EAAUC,IAEtB,CAKO,SAASC,EAASF,GAErB,OAAM,OAANA,GACa,iBAANA,GACP,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AtD,MAAM6B,IACVS,EAAGlC,UACDyB,EAAAV,SAASkI,IACT,IAAIC,EAA2BD,EAC1BvJ,EAAUwJ,KACbA,EAAO5G,EAAG4G,IAEN,MAAAC,EAAOJ,EAAOG,GACpBhH,EAAGvB,IAAIwI,GACPH,EAAMlI,KAAKqI,EAAI,IAEjBxF,KAAOqF,GAAOpJ,KAAK2C,EAAC,GACrB,GAEL,CC3BO,SAAS6G,GAAQlG,GACf,OAAArB,GAAYU,IACjB,IAAI/C,GAAW,EACT0D,EAAAtD,MAAM6B,IACLjC,IACQA,GAAA,EACX+C,EAAEd,GAAC,GAEN,GAEL,CCZgB,SAAA4H,GACdnG,EACAoG,GAEO,OAAAzH,GAAW,CAACI,EAASG,KAC1B,MAAMmH,EAAOlC,IACPnF,EAAK1B,IAYX,OAVM0C,EAAAtD,MAAM6B,IACVS,EAAGlC,UACG,MAAA8F,EAAOwD,EAAQ7H,GACrBS,EAAGvB,IAAImF,GACPyD,EAAK1G,MAAMiD,GACXA,EAAKzD,MAAMD,EAAM,IAEnBc,EAAMb,MAAMD,GACZmH,EAAK3J,KAAKqC,GAEH,KACLC,EAAGlC,SAAQ,CACb,GAEJ,CCrBO,SAASwJ,GAAYtG,GACnB,OAAArB,GAAcU,IACnB,MAAM6B,EAAc,GACdlB,EAAAtD,MAAM6B,IACV2C,EAAOtD,KAAKW,GACZc,EAAE6B,EAAM,GACT,GAEL,CCRO,SAASqF,GAAUrJ,GAClB,MAAA8C,EAAQV,EAAcpC,GACrB,OAAAyB,GAAYU,IACXW,EAAAtD,MAAM6B,IACRA,EAAAV,SAAS2I,IACTnH,EAAEmH,EAAE,GACL,GACF,GAEL"}
|
|
1
|
+
{"version":3,"file":"silentium.min.mjs","sources":["../src/helpers/guards.ts","../src/base/Destroyable.ts","../src/base/DestroyContainer.ts","../src/base/Rejections.ts","../src/helpers/ensures.ts","../src/base/Message.ts","../src/base/Of.ts","../src/base/ActualMessage.ts","../src/base/Chainable.ts","../src/base/Local.ts","../src/base/MessageSource.ts","../src/base/New.ts","../src/base/Void.ts","../src/components/All.ts","../src/components/Any.ts","../src/components/Applied.ts","../src/components/AppliedDestructured.ts","../src/components/Late.ts","../src/components/Catch.ts","../src/components/Chain.ts","../src/components/Context.ts","../src/components/ContextChain.ts","../src/components/Primitive.ts","../src/components/Shared.ts","../src/components/LateShared.ts","../src/components/ContextOf.ts","../src/components/Filtered.ts","../src/components/Empty.ts","../src/components/ExecutorApplied.ts","../src/components/Freeze.ts","../src/components/FromEvent.ts","../src/components/Map.ts","../src/components/Once.ts","../src/components/Process.ts","../src/components/Sequence.ts","../src/components/Stream.ts"],"sourcesContent":["import { DestroyableType, DestroyedType } from \"types/DestroyableType\";\nimport { MessageType } from \"types/MessageType\";\nimport { SourceType } from \"types/SourceType\";\n\n/**\n * Checks that the value is neither undefined nor null\n */\nexport const isFilled = <T>(\n value?: T,\n): value is Exclude<T, null | undefined> => {\n return value !== undefined && value !== null;\n};\n\n/**\n * Checks that the object is an message\n */\nexport function isMessage(o: unknown): o is MessageType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"then\" in o &&\n typeof (o as any).then === \"function\"\n );\n}\n\n/**\n * Checks that the object is an message\n */\nexport function isSource(o: unknown): o is SourceType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"use\" in o &&\n typeof (o as any).use === \"function\"\n );\n}\n\n/**\n * Checks that the object is destroyable\n */\nexport function isDestroyable(o: unknown): o is DestroyableType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"destroy\" in o &&\n typeof (o as any).destroy === \"function\"\n );\n}\n\n/**\n * Checks that the object can indicate whether it has been destroyed or not\n */\nexport function isDestroyed(o: unknown): o is DestroyedType {\n return (\n o !== null &&\n typeof o === \"object\" &&\n \"destroyed\" in o &&\n typeof (o as any).destroyed === \"function\"\n );\n}\n","import { isDestroyable } from \"helpers/guards\";\nimport { DestroyableType } from \"types/DestroyableType\";\n\n/**\n * Allows creating an object that definitely has a destructor,\n * useful to avoid creating unnecessary conditions\n */\nexport function Destroyable<T>(base: T) {\n return new DestroyableImpl(base);\n}\n\nexport class DestroyableImpl<T> implements DestroyableType {\n public constructor(private base: T) {}\n\n public destroy(): this {\n if (isDestroyable(this.base)) {\n this.base.destroy();\n }\n\n if (typeof this.base === \"function\") {\n this.base();\n }\n\n return this;\n }\n}\n","import { Destroyable } from \"base/Destroyable\";\nimport { DestroyableType } from \"types/DestroyableType\";\n\n/**\n * An object that allows collecting all disposable objects and\n * disposing them later all together\n */\nexport function DestroyContainer() {\n return new DestroyContainerImpl();\n}\n\nexport class DestroyContainerImpl implements DestroyableType {\n private destructors: DestroyableType[] = [];\n\n public add<R>(e: R): R {\n this.destructors.push(Destroyable(e));\n return e;\n }\n\n public destroy() {\n this.destructors.forEach((d) => d.destroy());\n this.destructors.length = 0;\n return this;\n }\n}\n","import { ConstructorType } from \"types/ConstructorType\";\n\n/**\n * Handles rejections collection\n */\nexport class Rejections {\n private catchers: ConstructorType<[unknown]>[] = [];\n private lastRejectReason: unknown = null;\n\n public reject = (reason: unknown) => {\n this.lastRejectReason = reason;\n this.catchers.forEach((catcher) => {\n catcher(reason);\n });\n };\n\n public catch(rejected: ConstructorType<[unknown]>) {\n if (this.lastRejectReason !== null) {\n rejected(this.lastRejectReason);\n }\n this.catchers.push(rejected);\n return this;\n }\n\n public destroy() {\n this.catchers.length = 0;\n return this;\n }\n}\n","import { isMessage } from \"helpers/guards\";\n\nexport function ensureFunction(v: unknown, label: string) {\n if (typeof v !== \"function\") {\n throw new Error(`${label}: is not function`);\n }\n}\n\nexport function ensureMessage(v: unknown, label: string) {\n if (!isMessage(v)) {\n throw new Error(`${label}: is not message`);\n }\n}\n","import { DestroyContainer } from \"base/DestroyContainer\";\nimport { Rejections } from \"base/Rejections\";\nimport { ensureFunction } from \"helpers/ensures\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { DestroyableType } from \"types/DestroyableType\";\nimport { MessageType } from \"types/MessageType\";\n\nexport type MessageExecutorType<T> = (\n resolve: ConstructorType<[T]>,\n reject: ConstructorType<[unknown]>,\n) => MessageType | (() => void) | void;\n\n/**\n * A message created from an executor function.\n * The executor function can return a message destruction function.\n */\nexport function Message<T>(executor: MessageExecutorType<T>) {\n return new MessageRx<T>(executor);\n}\n\n/**\n * Reactive message implementation\n */\nexport class MessageRx<T> implements MessageType<T>, DestroyableType {\n private rejections = new Rejections();\n private dc = DestroyContainer();\n\n public constructor(private executor: MessageExecutorType<T>) {\n ensureFunction(executor, \"Message: executor\");\n }\n\n public then(resolve: ConstructorType<[T]>) {\n try {\n this.dc.add(this.executor(resolve, this.rejections.reject));\n } catch (e: any) {\n this.rejections.reject(e);\n }\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>) {\n this.rejections.catch(rejected);\n return this;\n }\n\n public destroy() {\n this.dc.destroy();\n this.rejections.destroy();\n return this;\n }\n}\n","import { Message } from \"base/Message\";\n\n/**\n * Helps convert a value into a message\n */\nexport function Of<T>(value: T) {\n return Message<T>(function OfImpl(r) {\n r(value);\n });\n}\n","import { Of } from \"base/Of\";\nimport { isMessage } from \"helpers/guards\";\nimport { MaybeMessage, MessageType } from \"types/MessageType\";\n\n/**\n * A function that helps to ensure that\n * the message is indeed a message object\n * and not just a value\n */\nexport function ActualMessage<T>(message: MaybeMessage<T>): MessageType<T> {\n return isMessage(message) ? message : Of(message);\n}\n","import { ChainableType } from \"types/ChainableType\";\nimport { MessageType } from \"types/MessageType\";\nimport { SourceType } from \"types/SourceType\";\n\n/**\n * Helps to connect Different\n * message and source\n */\nexport function Chainable<T>(src: SourceType<T>) {\n return new ChainableImpl(src);\n}\n\nexport class ChainableImpl<T> implements ChainableType<T> {\n public constructor(private src: SourceType<T>) {}\n\n public chain($m: MessageType<T>) {\n $m.then(this.src.use.bind(this.src));\n return this;\n }\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * Create local copy of source what can be destroyed\n */\nexport function Local<T>(_base: MaybeMessage<T>) {\n const $base = ActualMessage(_base);\n return Message<T>(function LocalImpl(r) {\n let destroyed = false;\n $base.then((v) => {\n if (!destroyed) {\n r(v);\n }\n });\n return () => {\n destroyed = true;\n };\n });\n}\n","import { Message, MessageExecutorType, MessageRx } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MessageSourceType } from \"types/SourceType\";\n\n/**\n * Base message source object\n */\nexport function MessageSource<T>(\n messageExecutor: MessageExecutorType<T>,\n sourceExecutor: ConstructorType<[T]>,\n) {\n return new MessageSourceImpl(messageExecutor, sourceExecutor);\n}\n\nexport class MessageSourceImpl<T> implements MessageSourceType<T> {\n private message: MessageRx<T>;\n\n public constructor(\n messageExecutor: MessageExecutorType<T>,\n private sourceExecutor: ConstructorType<[T]>,\n ) {\n this.message = Message(messageExecutor);\n }\n\n public use(value: T): this {\n this.sourceExecutor(value);\n return this;\n }\n\n public then(resolved: ConstructorType<[T]>): this {\n this.message.then(resolved);\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>): this {\n this.message.catch(rejected);\n return this;\n }\n}\n","import { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\n\n/**\n * A component that, on each access, returns a new instance\n * of a reference type based on the constructor function\n */\nexport function New<T>(construct: ConstructorType<[], T>) {\n return Message<T>(function NewImpl(resolve) {\n resolve(construct());\n });\n}\n","/**\n * Resolver that does nothing with the passed value,\n * needed for silent message triggering\n */\nexport function Void() {\n return () => {};\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\ntype ExtractTypeS<T> = T extends MaybeMessage<infer U> ? U : never;\n\ntype ExtractTypesFromArrayS<T extends MaybeMessage<any>[]> = {\n [K in keyof T]: ExtractTypeS<T[K]>;\n};\n\nconst isAllFilled = (keysFilled: Set<string>, keysKnown: Set<string>) => {\n return keysFilled.size > 0 && keysFilled.size === keysKnown.size;\n};\n\n/**\n * A message that represents values from\n * all provided messages as an array.\n * When all messages emit their values,\n * the combined value will be returned.\n * If at least one message later emits a new\n * value, the updated array with the new value\n * will be emitted by All.\n */\nexport function All<const T extends MaybeMessage[]>(...messages: T) {\n const $messages = messages.map(ActualMessage);\n return Message<ExtractTypesFromArrayS<T>>(function AllImpl(resolve, reject) {\n const known = new Set<string>(Object.keys(messages));\n const filled = new Set<string>();\n const result: unknown[] = [];\n if (known.size === 0) {\n resolve([] as ExtractTypesFromArrayS<T>);\n return;\n }\n $messages.map((m, key) => {\n m.catch(reject);\n m.then((v) => {\n filled.add(key.toString());\n result[key] = v;\n if (isAllFilled(filled, known)) {\n resolve(result as ExtractTypesFromArrayS<T>);\n }\n });\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * A message that emits values received from\n * any of its bound messages\n */\nexport function Any<const T>(...messages: MaybeMessage<T>[]) {\n const $messages = messages.map(ActualMessage);\n return Message<T>(function AnyImpl(resolve, reject) {\n $messages.forEach((message) => {\n message.catch(reject);\n message.then(resolve);\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * An message that applies a function\n * to the value of the base message\n */\nexport function Applied<const T, R>(\n base: MaybeMessage<T>,\n applier: ConstructorType<[T], R>,\n) {\n const $base = ActualMessage(base);\n return Message<R>(function AppliedImpl(resolve, reject) {\n $base.catch(reject);\n $base.then((v) => {\n resolve(applier(v));\n });\n });\n}\n","import { Applied } from \"components/Applied\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * Allows applying variables from an message that passes an array to a function,\n * where each element of the array will be passed as a separate argument\n */\nexport function AppliedDestructured<const T extends any[], R>(\n $base: MaybeMessage<T>,\n applier: ConstructorType<T[number][], R>,\n) {\n return Applied($base, function AppliedDestructuredImpl(args) {\n return applier(...args);\n });\n}\n","import { Rejections } from \"base/Rejections\";\nimport { isFilled } from \"helpers/guards\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MessageSourceType } from \"types/SourceType\";\n\n/**\n * A component that allows creating linked objects of information and its owner\n * in such a way that if a new value is assigned to the owner, this value\n * will become the value of the linked information source\n * https://silentium-lab.github.io/silentium/#/en/information/of\n */\nexport function Late<T>(v?: T) {\n return new LateImpl<T>(v);\n}\n\nexport class LateImpl<T> implements MessageSourceType<T> {\n private rejections = new Rejections();\n private lateR: ConstructorType<[T]> | null = null;\n private notify = () => {\n if (isFilled(this.v) && this.lateR) {\n try {\n this.lateR(this.v);\n } catch (e: any) {\n this.rejections.reject(e);\n }\n }\n };\n\n public constructor(private v?: T) {}\n\n public then(r: ConstructorType<[T]>): this {\n if (this.lateR) {\n throw new Error(\n \"Late component gets new resolver, when another was already connected!\",\n );\n }\n this.lateR = r;\n this.notify();\n return this;\n }\n\n public use(value: T): this {\n this.v = value;\n this.notify();\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>) {\n this.rejections.catch(rejected);\n return this;\n }\n}\n","import { Rejections } from \"base/Rejections\";\nimport { Late } from \"components/Late\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Message with error catched\n * inside another message\n */\nexport function Catch<T>($base: MessageType) {\n const rejections = new Rejections();\n $base.catch(rejections.reject);\n const $error = Late<T>();\n rejections.catch((e) => {\n $error.use(e as T);\n });\n\n return $error;\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MessageType, MessageTypeValue } from \"types/MessageType\";\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype Last<T extends readonly any[]> = T extends readonly [...infer _, infer L]\n ? L\n : never;\n\n/**\n * Chains messages together and triggers\n * the last message only when all previous messages\n * have emitted their values. The value of Chain will be the value\n * of the last message. If any messages\n * emit a value again after the overall Chain response was already returned,\n * then Chain emits again with the value of the last message.\n */\nexport function Chain<T extends readonly MessageType[]>(...messages: T) {\n const $messages = messages.map(ActualMessage);\n return Message<MessageTypeValue<Last<T>>>(\n function ChainImpl(resolve, reject) {\n let $latest: MessageTypeValue<Last<T>> | undefined;\n const handleMessage = (index: number) => {\n const message = $messages[index] as Last<T>;\n message.catch(reject);\n const next = $messages[index + 1] as Last<T> | undefined;\n message.then((v) => {\n oneMessage(v as MessageTypeValue<Last<T>>, next, index);\n });\n };\n function oneMessage(\n v: MessageTypeValue<Last<T>>,\n next: Last<T> | undefined,\n index: number,\n ) {\n if (!next) {\n $latest = v as MessageTypeValue<Last<T>>;\n }\n if ($latest) {\n resolve($latest);\n }\n if (next && !$latest) {\n handleMessage(index + 1);\n }\n }\n handleMessage(0);\n },\n );\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { ContextType } from \"types/ContextType\";\nimport { MaybeMessage } from \"types/MessageType\";\n\nContext.transport = new Map<any, ConstructorType<[ContextType]>>();\n\n/**\n * The ability to call an external system through\n * sending a message in a standardized format\n * ContextType, the list of transport should be defined via\n * the Context.transport map object\n */\nexport function Context<T>(msg: MaybeMessage<ContextType>) {\n const $msg = ActualMessage(msg);\n return Message<T>((resolve, reject) => {\n $msg.then((message) => {\n const transport = Context.transport.get(message.transport);\n if (transport === undefined) {\n throw new Error(`Context: unknown transport ${message.transport}`);\n }\n if (!message.result) {\n message.result = resolve;\n }\n if (!message.error) {\n message.error = reject;\n }\n try {\n transport(message);\n } catch (error) {\n reject(error);\n }\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { MaybeMessage } from \"types/MessageType\";\nimport { ContextType } from \"types/ContextType\";\n\n/**\n * Connects an external message to an RPC message chain\n */\nexport function ContextChain(base: MaybeMessage) {\n const $base = ActualMessage(base);\n return (context: ContextType) => {\n if (!context.result) {\n throw new Error(\"ContextChain did not find result in rpc message\");\n }\n $base.then(context.result);\n };\n}\n","import { MessageType } from \"types/MessageType\";\n\n/**\n * Helps represent an message as a primitive type, which can be useful\n * for cases when you need to always have a reference to the current value\n * without updating the shared value when the current one changes.\n * For example, this could be used when passing an authorization token.\n * It can also be useful for testing or logging purposes.\n */\nexport function Primitive<T>($base: MessageType<T>, theValue: T | null = null) {\n return new PrimitiveImpl<T>($base, theValue);\n}\n\nexport class PrimitiveImpl<T> {\n private touched = false;\n\n public constructor(\n private $base: MessageType<T>,\n private theValue: T | null = null,\n ) {}\n\n private ensureTouched() {\n if (!this.touched) {\n this.$base.then((v) => {\n this.theValue = v;\n });\n }\n this.touched = true;\n }\n\n public [Symbol.toPrimitive]() {\n this.ensureTouched();\n return this.theValue;\n }\n\n public primitive() {\n this.ensureTouched();\n return this.theValue;\n }\n\n public primitiveWithException() {\n this.ensureTouched();\n if (this.theValue === null) {\n throw new Error(\"Primitive value is null\");\n }\n return this.theValue;\n }\n}\n","import { MessageType } from \"types/MessageType\";\nimport { MessageSourceType, SourceType } from \"types/SourceType\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { isFilled, isSource } from \"helpers/guards\";\nimport { Primitive } from \"components/Primitive\";\nimport { ChainableType } from \"types/ChainableType\";\n\n/**\n * An information object that helps multiple owners access\n * a single another information object\n */\nexport function Shared<T>($base: MessageType<T> | MessageSourceType<T>) {\n return new SharedImpl<T>($base);\n}\n\nexport class SharedImpl<T> implements MessageSourceType<T>, ChainableType<T> {\n private resolver = (v: T) => {\n this.lastV = v;\n this.resolvers.forEach((r) => {\n r(v);\n });\n };\n private lastV: T | undefined;\n private resolvers = new Set<ConstructorType<[T]>>();\n private source?: SourceType<T>;\n\n public constructor(private $base: MessageType<T> | MessageSourceType<T>) {\n if (isSource($base)) {\n this.source = $base;\n }\n }\n\n public then(resolved: ConstructorType<[T]>) {\n this.resolvers.add(resolved);\n if (this.resolvers.size === 1) {\n this.$base.then(this.resolver);\n } else if (isFilled(this.lastV)) {\n resolved(this.lastV);\n }\n return this;\n }\n\n public use(value: T) {\n if (this.source) {\n this.source.use(value);\n } else {\n this.resolver(value);\n }\n return this;\n }\n\n public catch(rejected: ConstructorType<[unknown]>) {\n this.$base.catch(rejected);\n return this;\n }\n\n public destroy() {\n this.resolvers.clear();\n return this;\n }\n\n public value() {\n return Primitive(this);\n }\n\n public chain(m: MessageType<T>) {\n m.then(this.use.bind(this));\n return this;\n }\n}\n","import { Late } from \"components/Late\";\nimport { Shared } from \"components/Shared\";\n\n/**\n * An message with a value that will be set later,\n * capable of responding to many resolvers\n */\nexport function LateShared<T>(value?: T) {\n const l = Late(value);\n return Shared(l);\n}\n","import { Message } from \"base/Message\";\nimport { LateShared } from \"components/LateShared\";\nimport { Context } from \"components/Context\";\nimport { ContextType } from \"types/ContextType\";\n\n/**\n * Message for the arrival of a specific RPC message\n * for specific transport\n */\nexport function ContextOf(transport: string) {\n const $msg = LateShared<ContextType>();\n Context.transport.set(transport, $msg.use.bind($msg));\n return Message<ContextType>((resolve, reject) => {\n $msg.catch(reject);\n $msg.then(resolve);\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MaybeMessage, MessageType } from \"types/MessageType\";\n\n/**\n * Filters values from the source message based on a predicate function,\n * optionally providing a default value when the predicate fails.\n */\nexport function Filtered<T>(\n base: MaybeMessage<T>,\n predicate: ConstructorType<[T], boolean>,\n defaultValue?: T,\n): MessageType<T> {\n const $base = ActualMessage(base);\n return Message<T>(function FilteredImpl(resolve, reject) {\n $base.catch(reject);\n $base.then((v) => {\n if (predicate(v)) {\n resolve(v);\n } else if (defaultValue !== undefined) {\n resolve(defaultValue);\n }\n });\n });\n}\n","import { Filtered } from \"components/Filtered\";\nimport { LateShared } from \"components/LateShared\";\nimport { Shared } from \"components/Shared\";\nimport { EmptyType } from \"types/EmptyType\";\nimport { MessageType } from \"types/MessageType\";\n\nexport const Nothing = Symbol(\"nothing\");\n\n/**\n * Helps to split message and empty\n * response\n */\nexport function Empty<T>($base: MessageType<T>) {\n return new EmptyImpl<T>($base);\n}\n\nexport class EmptyImpl<T> implements EmptyType {\n private $empty = LateShared<boolean>();\n\n public constructor(private $base: MessageType<T>) {}\n\n public message() {\n Shared(this.$base).then((v) => {\n if (v === Nothing) {\n this.$empty.use(true);\n }\n });\n return Filtered(this.$base, (v) => v !== Nothing);\n }\n\n public empty(): MessageType<boolean> {\n return this.$empty;\n }\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\ntype ExecutorApplier<T> = (executor: (v: T) => void) => (v: T) => void;\n\n/**\n * Applies a value transfer function to the resolver\n * and returns the same value transfer function for the resolver\n * Useful for applying functions like debounced or throttle\n */\nexport function ExecutorApplied<T>(\n $base: MessageType<T>,\n applier: ExecutorApplier<T>,\n) {\n return Message<T>(function ExecutorAppliedImpl(resolve, reject) {\n $base.catch(reject);\n $base.then(applier(resolve));\n });\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Message what freezes first known value\n */\nexport function Freeze<T>($base: MessageType<T>, $invalidate?: MessageType<T>) {\n let freezedValue: T | null = null;\n return Message<T>(function FreezeImpl(resolve, reject) {\n $base.catch(reject);\n $base.then((v) => {\n if (freezedValue === null) {\n freezedValue = v;\n }\n resolve(freezedValue as T);\n });\n\n $invalidate?.then(() => {\n freezedValue = null;\n });\n });\n}\n","import { MaybeMessage } from \"types/MessageType\";\nimport { All } from \"components/All\";\nimport { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { ConstructorType } from \"types/ConstructorType\";\n\n/**\n * A message derived from event with a different\n * method call interface, based on callbacks.\n * Allows attaching a custom handler to an existing event source\n * and presenting it as a silentium message\n */\nexport function FromEvent<T>(\n emitter: MaybeMessage<any>,\n eventName: MaybeMessage<string>,\n subscribeMethod: MaybeMessage<string>,\n unsubscribeMethod?: MaybeMessage<string>,\n) {\n const $emitter = ActualMessage(emitter);\n const $eventName = ActualMessage(eventName);\n const $subscribeMethod = ActualMessage(subscribeMethod);\n const $unsubscribeMethod = ActualMessage(unsubscribeMethod);\n return Message<T>((resolve, reject) => {\n $emitter.catch(reject);\n $eventName.catch(reject);\n $subscribeMethod.catch(reject);\n $unsubscribeMethod.catch(reject);\n let lastR: ConstructorType<[T]> | null = null;\n const handler = (v: T) => {\n if (lastR) {\n lastR(v);\n }\n };\n All($emitter, $eventName, $subscribeMethod).then(\n ([emitter, eventName, subscribe]) => {\n lastR = resolve;\n if (!emitter?.[subscribe]) {\n return;\n }\n emitter[subscribe](eventName, handler);\n },\n );\n return () => {\n lastR = null;\n if (!$unsubscribeMethod) {\n return;\n }\n All($emitter, $eventName, $unsubscribeMethod).then(\n ([emitter, eventName, unsubscribe]) => {\n emitter?.[unsubscribe as string]?.(eventName, handler);\n },\n );\n };\n });\n}\n","import { MaybeMessage, MessageType } from \"types/MessageType\";\nimport { All } from \"components/All\";\nimport { isMessage } from \"helpers/guards\";\nimport { Of } from \"base/Of\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { Message } from \"base/Message\";\nimport { ActualMessage } from \"base/ActualMessage\";\nimport { DestroyContainer } from \"base/DestroyContainer\";\n\n/**\n * Component that applies an info object constructor to each data item,\n * producing an information source with new values\n */\nexport function Map<T, TG>(\n base: MaybeMessage<T[]>,\n target: ConstructorType<[any], MessageType<TG>>,\n) {\n const $base = ActualMessage(base);\n return Message<TG[]>((resolve, reject) => {\n $base.catch(reject);\n const infos: MessageType<TG>[] = [];\n const dc = DestroyContainer();\n $base.then((v) => {\n dc.destroy();\n v.forEach((val) => {\n let $val: MessageType<T> | T = val;\n if (!isMessage($val as object)) {\n $val = Of($val);\n }\n const info = target($val);\n dc.add(info);\n infos.push(info);\n });\n All(...infos).then(resolve);\n });\n });\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Limits the number of values from the information source\n * to a single value - once the first value is emitted, no more\n * values are delivered from the source\n */\nexport function Once<T>($base: MessageType<T>) {\n return Message<T>((resolve, reject) => {\n let isFilled = false;\n $base.catch(reject);\n $base.then((v) => {\n if (!isFilled) {\n isFilled = true;\n resolve(v);\n }\n });\n });\n}\n","import { DestroyContainer } from \"base/DestroyContainer\";\nimport { Message } from \"base/Message\";\nimport { LateShared } from \"components/LateShared\";\nimport { ConstructorType } from \"types/ConstructorType\";\nimport { MessageType } from \"types/MessageType\";\n\nexport function Process<T, R = unknown>(\n $base: MessageType<T>,\n builder: ConstructorType<[T], MessageType<R>>,\n) {\n return Message<R>((resolve, reject) => {\n const $res = LateShared<R>();\n const dc = DestroyContainer();\n\n $base.then((v) => {\n dc.destroy();\n const $msg = builder(v);\n dc.add($msg);\n $res.chain($msg);\n $msg.catch(reject);\n });\n $base.catch(reject);\n $res.then(resolve);\n\n return () => {\n dc.destroy();\n };\n });\n}\n","import { Message } from \"base/Message\";\nimport { MessageType } from \"types/MessageType\";\n\n/**\n * Creates a sequence that accumulates all values from the source into an array,\n * emitting the growing array with each new value.\n */\nexport function Sequence<T>($base: MessageType<T>) {\n return Message<T[]>((resolve, reject) => {\n const result: T[] = [];\n $base.catch(reject);\n $base.then((v) => {\n result.push(v);\n resolve(result);\n });\n });\n}\n","import { ActualMessage } from \"base/ActualMessage\";\nimport { Message } from \"base/Message\";\nimport { MaybeMessage } from \"types/MessageType\";\n\n/**\n * Component that receives a data array and yields values one by one\n */\nexport function Stream<T>(base: MaybeMessage<T[]>) {\n const $base = ActualMessage(base);\n return Message<T>((resolve, reject) => {\n $base.catch(reject);\n $base.then((v) => {\n v.forEach((cv) => {\n resolve(cv);\n });\n });\n });\n}\n"],"names":["isFilled","value","isMessage","o","then","isSource","use","isDestroyable","destroy","isDestroyed","destroyed","Destroyable","base","DestroyableImpl","constructor","this","DestroyContainer","DestroyContainerImpl","__publicField","add","e","destructors","push","forEach","d","length","Rejections","reason","lastRejectReason","catchers","catcher","rejected","ensureFunction","v","label","Error","ensureMessage","Message","executor","MessageRx","resolve","dc","rejections","reject","catch","Of","r","ActualMessage","message","Chainable","src","ChainableImpl","chain","$m","bind","Local","_base","$base","MessageSource","messageExecutor","sourceExecutor","MessageSourceImpl","resolved","New","construct","Void","All","messages","$messages","map","known","Set","Object","keys","filled","result","size","m","key","keysFilled","keysKnown","toString","Any","Applied","applier","AppliedDestructured","args","Late","LateImpl","lateR","notify","Catch","$error","Chain","$latest","handleMessage","index","next","oneMessage","Context","msg","$msg","transport","get","error","ContextChain","context","Map","Primitive","theValue","PrimitiveImpl","ensureTouched","touched","Symbol","toPrimitive","primitive","primitiveWithException","Shared","SharedImpl","lastV","resolvers","source","resolver","clear","LateShared","ContextOf","set","Filtered","predicate","defaultValue","Nothing","Empty","EmptyImpl","$empty","empty","ExecutorApplied","Freeze","$invalidate","freezedValue","FromEvent","emitter","eventName","subscribeMethod","unsubscribeMethod","$emitter","$eventName","$subscribeMethod","$unsubscribeMethod","lastR","handler","subscribe","unsubscribe","target","infos","val","$val","info","Once","Process","builder","$res","Sequence","Stream","cv"],"mappings":"AAOO,MAAMA,EACXC,GAEOA,QAMF,SAASC,EAAUC,GACxB,OACQ,OAANA,GACa,iBAANA,GACP,SAAUA,GACiB,mBAAnBA,EAAUC,IAEtB,CAKO,SAASC,EAASF,GACvB,OACQ,OAANA,GACa,iBAANA,GACP,QAASA,GACiB,mBAAlBA,EAAUG,GAEtB,CAKO,SAASC,EAAcJ,GAC5B,OACQ,OAANA,GACa,iBAANA,GACP,YAAaA,GACiB,mBAAtBA,EAAUK,OAEtB,CAKO,SAASC,EAAYN,GAC1B,OACQ,OAANA,GACa,iBAANA,GACP,cAAeA,GACiB,mBAAxBA,EAAUO,SAEtB,CCpDO,SAASC,EAAeC,GAC7B,OAAO,IAAIC,EAAgBD,EAC7B,CAEO,MAAMC,EACJ,WAAAC,CAAoBF,GAAAG,KAAAH,KAAAA,CAAU,CAE9B,OAAAJ,GASL,OARID,EAAcQ,KAAKH,OACrBG,KAAKH,KAAKJ,UAGa,m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AIC,EAA2BD,EAC1BxJ,EAAUyJ,KACbA,EAAO9G,EAAG8G,IAEZ,MAAMC,EAAOJ,EAAOG,GACpBlH,EAAGtB,IAAIyI,GACPH,EAAMnI,KAAKsI,KAEb1F,KAAOuF,GAAOrJ,KAAKoC,MAGzB,CC5BO,SAASqH,GAAQpG,GACtB,OAAOpB,EAAW,CAACG,EAASG,KAC1B,IAAI3C,GAAW,EACfyD,EAAMb,MAAMD,GACZc,EAAMrD,KAAM6B,IACLjC,IACHA,GAAW,EACXwC,EAAQP,OAIhB,CCbO,SAAS6H,GACdrG,EACAsG,GAEA,OAAO1H,EAAW,CAACG,EAASG,KAC1B,MAAMqH,EAAOpC,IACPnF,EAAKzB,IAYX,OAVAyC,EAAMrD,KAAM6B,IACVQ,EAAGjC,UACH,MAAM6F,EAAO0D,EAAQ9H,GACrBQ,EAAGtB,IAAIkF,GACP2D,EAAK5G,MAAMiD,GACXA,EAAKzD,MAAMD,KAEbc,EAAMb,MAAMD,GACZqH,EAAK5J,KAAKoC,GAEH,KACLC,EAAGjC,YAGT,CCrBO,SAASyJ,GAAYxG,GAC1B,OAAOpB,EAAa,CAACG,EAASG,KAC5B,MAAMgC,EAAc,GACpBlB,EAAMb,MAAMD,GACZc,EAAMrD,KAAM6B,IACV0C,EAAOrD,KAAKW,GACZO,EAAQmC,MAGd,CCTO,SAASuF,GAAUtJ,GACxB,MAAM6C,EAAQV,EAAcnC,GAC5B,OAAOyB,EAAW,CAACG,EAASG,KAC1Bc,EAAMb,MAAMD,GACZc,EAAMrD,KAAM6B,IACVA,EAAEV,QAAS4I,IACT3H,EAAQ2H,QAIhB"}
|
package/dist/silentium.mjs
CHANGED
|
@@ -94,13 +94,12 @@ function ensureMessage(v, label) {
|
|
|
94
94
|
var __defProp$5 = Object.defineProperty;
|
|
95
95
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
96
96
|
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
97
|
-
function Message(executor
|
|
98
|
-
return new MessageRx(executor
|
|
97
|
+
function Message(executor) {
|
|
98
|
+
return new MessageRx(executor);
|
|
99
99
|
}
|
|
100
100
|
class MessageRx {
|
|
101
|
-
constructor(executor
|
|
101
|
+
constructor(executor) {
|
|
102
102
|
this.executor = executor;
|
|
103
|
-
this.everyThenCallsExecutor = everyThenCallsExecutor;
|
|
104
103
|
__publicField$5(this, "rejections", new Rejections());
|
|
105
104
|
__publicField$5(this, "dc", DestroyContainer());
|
|
106
105
|
ensureFunction(executor, "Message: executor");
|
|
@@ -204,20 +203,21 @@ const isAllFilled = (keysFilled, keysKnown) => {
|
|
|
204
203
|
};
|
|
205
204
|
function All(...messages) {
|
|
206
205
|
const $messages = messages.map(ActualMessage);
|
|
207
|
-
return Message(function AllImpl(
|
|
206
|
+
return Message(function AllImpl(resolve, reject) {
|
|
208
207
|
const known = new Set(Object.keys(messages));
|
|
209
208
|
const filled = /* @__PURE__ */ new Set();
|
|
210
209
|
const result = [];
|
|
211
210
|
if (known.size === 0) {
|
|
212
|
-
|
|
211
|
+
resolve([]);
|
|
213
212
|
return;
|
|
214
213
|
}
|
|
215
214
|
$messages.map((m, key) => {
|
|
215
|
+
m.catch(reject);
|
|
216
216
|
m.then((v) => {
|
|
217
217
|
filled.add(key.toString());
|
|
218
218
|
result[key] = v;
|
|
219
219
|
if (isAllFilled(filled, known)) {
|
|
220
|
-
|
|
220
|
+
resolve(result);
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
223
|
});
|
|
@@ -226,18 +226,20 @@ function All(...messages) {
|
|
|
226
226
|
|
|
227
227
|
function Any(...messages) {
|
|
228
228
|
const $messages = messages.map(ActualMessage);
|
|
229
|
-
return Message(function AnyImpl(
|
|
229
|
+
return Message(function AnyImpl(resolve, reject) {
|
|
230
230
|
$messages.forEach((message) => {
|
|
231
|
-
message.
|
|
231
|
+
message.catch(reject);
|
|
232
|
+
message.then(resolve);
|
|
232
233
|
});
|
|
233
234
|
});
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
function Applied(base, applier) {
|
|
237
238
|
const $base = ActualMessage(base);
|
|
238
|
-
return Message(function AppliedImpl(
|
|
239
|
+
return Message(function AppliedImpl(resolve, reject) {
|
|
240
|
+
$base.catch(reject);
|
|
239
241
|
$base.then((v) => {
|
|
240
|
-
|
|
242
|
+
resolve(applier(v));
|
|
241
243
|
});
|
|
242
244
|
});
|
|
243
245
|
}
|
|
@@ -302,28 +304,31 @@ function Catch($base) {
|
|
|
302
304
|
|
|
303
305
|
function Chain(...messages) {
|
|
304
306
|
const $messages = messages.map(ActualMessage);
|
|
305
|
-
return Message(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
307
|
+
return Message(
|
|
308
|
+
function ChainImpl(resolve, reject) {
|
|
309
|
+
let $latest;
|
|
310
|
+
const handleMessage = (index) => {
|
|
311
|
+
const message = $messages[index];
|
|
312
|
+
message.catch(reject);
|
|
313
|
+
const next = $messages[index + 1];
|
|
314
|
+
message.then((v) => {
|
|
315
|
+
oneMessage(v, next, index);
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
function oneMessage(v, next, index) {
|
|
319
|
+
if (!next) {
|
|
320
|
+
$latest = v;
|
|
321
|
+
}
|
|
322
|
+
if ($latest) {
|
|
323
|
+
resolve($latest);
|
|
324
|
+
}
|
|
325
|
+
if (next && !$latest) {
|
|
326
|
+
handleMessage(index + 1);
|
|
327
|
+
}
|
|
323
328
|
}
|
|
329
|
+
handleMessage(0);
|
|
324
330
|
}
|
|
325
|
-
|
|
326
|
-
});
|
|
331
|
+
);
|
|
327
332
|
}
|
|
328
333
|
|
|
329
334
|
Context.transport = /* @__PURE__ */ new Map();
|
|
@@ -461,19 +466,21 @@ function LateShared(value) {
|
|
|
461
466
|
function ContextOf(transport) {
|
|
462
467
|
const $msg = LateShared();
|
|
463
468
|
Context.transport.set(transport, $msg.use.bind($msg));
|
|
464
|
-
return Message((
|
|
465
|
-
$msg.
|
|
469
|
+
return Message((resolve, reject) => {
|
|
470
|
+
$msg.catch(reject);
|
|
471
|
+
$msg.then(resolve);
|
|
466
472
|
});
|
|
467
473
|
}
|
|
468
474
|
|
|
469
475
|
function Filtered(base, predicate, defaultValue) {
|
|
470
476
|
const $base = ActualMessage(base);
|
|
471
|
-
return Message(function FilteredImpl(
|
|
477
|
+
return Message(function FilteredImpl(resolve, reject) {
|
|
478
|
+
$base.catch(reject);
|
|
472
479
|
$base.then((v) => {
|
|
473
480
|
if (predicate(v)) {
|
|
474
|
-
|
|
481
|
+
resolve(v);
|
|
475
482
|
} else if (defaultValue !== void 0) {
|
|
476
|
-
|
|
483
|
+
resolve(defaultValue);
|
|
477
484
|
}
|
|
478
485
|
});
|
|
479
486
|
});
|
|
@@ -505,8 +512,25 @@ class EmptyImpl {
|
|
|
505
512
|
}
|
|
506
513
|
|
|
507
514
|
function ExecutorApplied($base, applier) {
|
|
508
|
-
return Message(function ExecutorAppliedImpl(
|
|
509
|
-
$base.
|
|
515
|
+
return Message(function ExecutorAppliedImpl(resolve, reject) {
|
|
516
|
+
$base.catch(reject);
|
|
517
|
+
$base.then(applier(resolve));
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function Freeze($base, $invalidate) {
|
|
522
|
+
let freezedValue = null;
|
|
523
|
+
return Message(function FreezeImpl(resolve, reject) {
|
|
524
|
+
$base.catch(reject);
|
|
525
|
+
$base.then((v) => {
|
|
526
|
+
if (freezedValue === null) {
|
|
527
|
+
freezedValue = v;
|
|
528
|
+
}
|
|
529
|
+
resolve(freezedValue);
|
|
530
|
+
});
|
|
531
|
+
$invalidate?.then(() => {
|
|
532
|
+
freezedValue = null;
|
|
533
|
+
});
|
|
510
534
|
});
|
|
511
535
|
}
|
|
512
536
|
|
|
@@ -515,7 +539,11 @@ function FromEvent(emitter, eventName, subscribeMethod, unsubscribeMethod) {
|
|
|
515
539
|
const $eventName = ActualMessage(eventName);
|
|
516
540
|
const $subscribeMethod = ActualMessage(subscribeMethod);
|
|
517
541
|
const $unsubscribeMethod = ActualMessage(unsubscribeMethod);
|
|
518
|
-
return Message((
|
|
542
|
+
return Message((resolve, reject) => {
|
|
543
|
+
$emitter.catch(reject);
|
|
544
|
+
$eventName.catch(reject);
|
|
545
|
+
$subscribeMethod.catch(reject);
|
|
546
|
+
$unsubscribeMethod.catch(reject);
|
|
519
547
|
let lastR = null;
|
|
520
548
|
const handler = (v) => {
|
|
521
549
|
if (lastR) {
|
|
@@ -524,7 +552,7 @@ function FromEvent(emitter, eventName, subscribeMethod, unsubscribeMethod) {
|
|
|
524
552
|
};
|
|
525
553
|
All($emitter, $eventName, $subscribeMethod).then(
|
|
526
554
|
([emitter2, eventName2, subscribe]) => {
|
|
527
|
-
lastR =
|
|
555
|
+
lastR = resolve;
|
|
528
556
|
if (!emitter2?.[subscribe]) {
|
|
529
557
|
return;
|
|
530
558
|
}
|
|
@@ -547,7 +575,8 @@ function FromEvent(emitter, eventName, subscribeMethod, unsubscribeMethod) {
|
|
|
547
575
|
|
|
548
576
|
function Map$1(base, target) {
|
|
549
577
|
const $base = ActualMessage(base);
|
|
550
|
-
return Message((
|
|
578
|
+
return Message((resolve, reject) => {
|
|
579
|
+
$base.catch(reject);
|
|
551
580
|
const infos = [];
|
|
552
581
|
const dc = DestroyContainer();
|
|
553
582
|
$base.then((v) => {
|
|
@@ -561,18 +590,19 @@ function Map$1(base, target) {
|
|
|
561
590
|
dc.add(info);
|
|
562
591
|
infos.push(info);
|
|
563
592
|
});
|
|
564
|
-
All(...infos).then(
|
|
593
|
+
All(...infos).then(resolve);
|
|
565
594
|
});
|
|
566
595
|
});
|
|
567
596
|
}
|
|
568
597
|
|
|
569
598
|
function Once($base) {
|
|
570
|
-
return Message((
|
|
599
|
+
return Message((resolve, reject) => {
|
|
571
600
|
let isFilled = false;
|
|
601
|
+
$base.catch(reject);
|
|
572
602
|
$base.then((v) => {
|
|
573
603
|
if (!isFilled) {
|
|
574
604
|
isFilled = true;
|
|
575
|
-
|
|
605
|
+
resolve(v);
|
|
576
606
|
}
|
|
577
607
|
});
|
|
578
608
|
});
|
|
@@ -598,25 +628,27 @@ function Process($base, builder) {
|
|
|
598
628
|
}
|
|
599
629
|
|
|
600
630
|
function Sequence($base) {
|
|
601
|
-
return Message((
|
|
631
|
+
return Message((resolve, reject) => {
|
|
602
632
|
const result = [];
|
|
633
|
+
$base.catch(reject);
|
|
603
634
|
$base.then((v) => {
|
|
604
635
|
result.push(v);
|
|
605
|
-
|
|
636
|
+
resolve(result);
|
|
606
637
|
});
|
|
607
638
|
});
|
|
608
639
|
}
|
|
609
640
|
|
|
610
641
|
function Stream(base) {
|
|
611
642
|
const $base = ActualMessage(base);
|
|
612
|
-
return Message((
|
|
643
|
+
return Message((resolve, reject) => {
|
|
644
|
+
$base.catch(reject);
|
|
613
645
|
$base.then((v) => {
|
|
614
646
|
v.forEach((cv) => {
|
|
615
|
-
|
|
647
|
+
resolve(cv);
|
|
616
648
|
});
|
|
617
649
|
});
|
|
618
650
|
});
|
|
619
651
|
}
|
|
620
652
|
|
|
621
|
-
export { ActualMessage, All, Any, Applied, AppliedDestructured, Catch, Chain, Chainable, ChainableImpl, Context, ContextChain, ContextOf, DestroyContainer, DestroyContainerImpl, Destroyable, DestroyableImpl, Empty, EmptyImpl, ExecutorApplied, Filtered, FromEvent, Late, LateImpl, LateShared, Local, Map$1 as Map, Message, MessageRx, MessageSource, MessageSourceImpl, New, Nothing, Of, Once, Primitive, PrimitiveImpl, Process, Rejections, Sequence, Shared, SharedImpl, Stream, Void, ensureFunction, ensureMessage, isDestroyable, isDestroyed, isFilled, isMessage, isSource };
|
|
653
|
+
export { ActualMessage, All, Any, Applied, AppliedDestructured, Catch, Chain, Chainable, ChainableImpl, Context, ContextChain, ContextOf, DestroyContainer, DestroyContainerImpl, Destroyable, DestroyableImpl, Empty, EmptyImpl, ExecutorApplied, Filtered, Freeze, FromEvent, Late, LateImpl, LateShared, Local, Map$1 as Map, Message, MessageRx, MessageSource, MessageSourceImpl, New, Nothing, Of, Once, Primitive, PrimitiveImpl, Process, Rejections, Sequence, Shared, SharedImpl, Stream, Void, ensureFunction, ensureMessage, isDestroyable, isDestroyed, isFilled, isMessage, isSource };
|
|
622
654
|
//# sourceMappingURL=silentium.mjs.map
|