@kontur.candy/tools 2.219.0 → 2.221.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ChainableValueProducer.js","names":["_lodash","_interopRequireDefault","require","_pLimit","_IterableUtils","_TypingUtils","_GetCpuLimits","_AggregatedError","noop","ChainableValueProducer","constructor","errorListeners","onNext","_listener","Error","onError","listener","push","index","indexOf","splice","currentValue","transform","transformFunction","TransformValueProducer","do","action","ExecuteOnValueProducer","chainWith","nextItemFactory","attach","attachFactory","joinValues","evaluateAttachKey","AttachValueProducer","skipUpdatesUntilNextCompleted","SkipUpdatesUntilNextCompletedProducer","splitToChains","splitFunction","getKey","factory","SplitToChainsValueProducer","splitToParallelChains","ParallelSplitToChainsValueProducer","observe","beginObserve","detachListener","endObserve","emitError","error","errorObject","errorListener","exports","ObservableValueProducerBase","args","listeners","getCurrentValue","beginListening","stopListening","emitUpdate","value","notifyAllListenersAndWaitForComplete","nextValue","parent","lastAttachKey","attachedProducer","detachParentListener","detachAttachedListener","lastAttachedValue","lastParentValue","awaitingLastAttachedValue","isInObserveState","handleChangeAttachedValue","attachedValue","undefined","emitNextValue","handleChangeParentValue","parentValue","attachKey","delay","x","length","e","console","log","chains","handleChangeParentChain","key","chainValue","lastValue","emitValue","Object","values","map","filter","isNotNullOrUndefined","handleChangeParent","input","nextValuesMap","toMap","newKeys","_","difference","keys","removedKeys","newKey","_nextValuesMap$newKey","newChain","reject","newChainValue","valueProducer","removedKey","removedChain","result","errors","childValueProducer","childValue","AggregatedError","iterateValues","_nextValuesMap$newKey2","cpuLimit","getCpuLimits","concurrencyLimit","pLimit","Promise","all","_this$chains$key","detachFromParent","nextEmitToProcess","currentlyProcessingEmit","once","timeout","resolve","setTimeout"],"sources":["../../../../../src/Commons/TasksCore/ChainableValueProducer.ts"],"sourcesContent":["import _ from \"lodash\";\nimport pLimit from \"p-limit\";\n\nimport { ReasonOrError } from \"../ErrorUntyped\";\nimport { iterateValues } from \"../../../../Common/IterableUtils\";\nimport { reject } from \"../../../../Common/TypingUtils\";\nimport { getCpuLimits } from \"../GetCpuLimits\";\n\nimport { AggregatedError } from \"./AggregatedError\";\nimport { DetachListener, IValueProducer, ValueListener } from \"./BuildTask\";\n\nasync function noop(): Promise<void> {\n // empty function\n}\n\nexport class ChainableValueProducer<T> implements IValueProducer<T> {\n private readonly errorListeners: Array<ValueListener<Error>> = [];\n\n public onNext(_listener: (nextValue: T) => Promise<void>): DetachListener {\n throw new Error(\"AbstractError\");\n }\n\n public onError(listener: (error: Error) => Promise<void>): DetachListener {\n this.errorListeners.push(listener);\n return () => {\n const index = this.errorListeners.indexOf(listener);\n if (index >= 0) {\n this.errorListeners.splice(index, 1);\n }\n };\n }\n\n public get currentValue(): Promise<T> {\n throw new Error(\"AbstractError\");\n }\n\n public transform<TO>(transformFunction: (input: T) => Promise<TO>): TransformValueProducer<T, TO> {\n return new TransformValueProducer(this, transformFunction);\n }\n\n public do(action: (input: T) => Promise<void>): ExecuteOnValueProducer<T> {\n return new ExecuteOnValueProducer(this, action);\n }\n\n public chainWith<TO, TVP extends IValueProducer<TO>>(nextItemFactory: (prevItem: IValueProducer<T>) => TVP): TVP {\n return nextItemFactory(this);\n }\n\n public attach<TA, TO = T>(\n attachFactory: (value: T) => Promise<IValueProducer<TA>>,\n joinValues?: (original: T, attached: TA) => Promise<TO>,\n evaluateAttachKey?: (value: T) => Promise<string>\n ): AttachValueProducer<T, TA, TO> {\n return new AttachValueProducer(this, attachFactory, joinValues, evaluateAttachKey);\n }\n\n public skipUpdatesUntilNextCompleted(): SkipUpdatesUntilNextCompletedProducer<T> {\n return new SkipUpdatesUntilNextCompletedProducer(this);\n }\n\n public splitToChains<TI, TO>(\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO>\n ): SplitToChainsValueProducer<T, TI, TO> {\n return new SplitToChainsValueProducer(this, splitFunction, getKey, factory);\n }\n\n public splitToParallelChains<TI, TO>(\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO> | Promise<IValueProducer<TO>>\n ): ParallelSplitToChainsValueProducer<T, TI, TO> {\n return new ParallelSplitToChainsValueProducer(this, splitFunction, getKey, factory);\n }\n\n public async observe(listener: ValueListener<T> = noop): Promise<() => Promise<void>> {\n await this.beginObserve();\n await listener(await this.currentValue);\n const detachListener = this.onNext(listener);\n return async () => {\n detachListener();\n await this.endObserve();\n };\n }\n\n public async beginObserve(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n public async endObserve(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async emitError(error: any): Promise<void> {\n const errorObject = error instanceof Error ? error : new Error(`${error}`);\n for (const errorListener of this.errorListeners) {\n await errorListener(errorObject);\n }\n }\n}\n\nexport class ObservableValueProducerBase<T> extends ChainableValueProducer<T> {\n public get currentValue(): Promise<T> {\n return this.getCurrentValue();\n }\n\n private readonly listeners: Array<ValueListener<T>> = [];\n\n protected async getCurrentValue(): Promise<T> {\n throw new Error(\"AbstractError\");\n }\n\n public async beginObserve(): Promise<void> {\n await this.beginListening();\n }\n\n public async endObserve(): Promise<void> {\n await this.stopListening();\n }\n\n protected async beginListening(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n protected async stopListening(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n protected async emitUpdate(value: T): Promise<void> {\n await this.notifyAllListenersAndWaitForComplete(value);\n }\n\n public onNext(listener: (nextValue: T) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n };\n }\n\n private async notifyAllListenersAndWaitForComplete(nextValue: T): Promise<void> {\n for (const listener of this.listeners) {\n await listener(nextValue);\n }\n }\n}\n\nexport class AttachValueProducer<TI, TA, TO> extends ChainableValueProducer<TO> {\n private readonly parent: IValueProducer<TI>;\n private readonly attachFactory: (value: TI) => Promise<IValueProducer<TA>>;\n private readonly joinValues: (original: TI, attached: TA) => Promise<TO>;\n private lastAttachKey?: string;\n private attachedProducer?: IValueProducer<TA>;\n private readonly evaluateAttachKey: (value: TI) => Promise<string>;\n private readonly listeners: Array<ValueListener<TO>> = [];\n private detachParentListener?: DetachListener;\n private detachAttachedListener?: DetachListener;\n private lastAttachedValue?: TA;\n private lastParentValue?: TI;\n private awaitingLastAttachedValue = false;\n private isInObserveState = false;\n\n public constructor(\n parent: IValueProducer<TI>,\n attachFactory: (value: TI) => Promise<IValueProducer<TA>>,\n joinValues?: (original: TI, attached: TA) => Promise<TO>,\n evaluateAttachKey?: (value: TI) => Promise<string>\n ) {\n super();\n this.parent = parent;\n this.attachFactory = attachFactory;\n // Я не могу победить типизацию в этом месте, слишком много у меня кода получается\n // @ts-ignore\n this.joinValues = joinValues || (async x => x);\n this.evaluateAttachKey = evaluateAttachKey || (async () => \"STATIC-ATTACH-KEY\");\n }\n\n public async beginObserve(): Promise<void> {\n this.isInObserveState = true;\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n if (this.attachedProducer != undefined) {\n await this.attachedProducer.endObserve();\n }\n this.isInObserveState = false;\n }\n\n public get currentValue(): Promise<TO> {\n const getCurrentValue = async (): Promise<TO> => {\n const parentValue = await this.parent.currentValue;\n this.lastParentValue = parentValue;\n const attachKey = await this.evaluateAttachKey(parentValue);\n if (this.attachedProducer != undefined && this.detachAttachedListener == undefined) {\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.lastAttachKey == undefined || this.lastAttachKey !== attachKey) {\n this.lastAttachKey = attachKey;\n if (this.detachAttachedListener != undefined) {\n this.detachAttachedListener();\n }\n if (this.attachedProducer != undefined && this.isInObserveState) {\n await this.attachedProducer.endObserve();\n }\n this.attachedProducer = await this.attachFactory(parentValue);\n if (this.isInObserveState) {\n await this.attachedProducer.beginObserve();\n }\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.attachedProducer == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n const attachedValue = await this.attachedProducer.currentValue;\n this.lastAttachedValue = attachedValue;\n return this.joinValues(parentValue, attachedValue);\n };\n return getCurrentValue();\n }\n\n public async emitNextValue(value: TO): Promise<void> {\n for (const listener of this.listeners) {\n await listener(value);\n }\n }\n\n public onNext(listener: (nextValue: TO) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n if (this.listeners.length === 1) {\n if (this.detachParentListener == undefined) {\n this.detachParentListener = this.parent.onNext(this.handleChangeParentValue);\n }\n if (this.attachedProducer != undefined && this.detachParentListener == undefined) {\n this.detachParentListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n }\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n if (this.listeners.length === 0) {\n if (this.detachParentListener != undefined) {\n this.detachParentListener();\n }\n if (this.detachAttachedListener != undefined) {\n this.detachAttachedListener();\n }\n }\n };\n }\n\n private readonly handleChangeAttachedValue = async (attachedValue: TA): Promise<void> => {\n this.lastAttachedValue = attachedValue;\n if (!this.awaitingLastAttachedValue) {\n if (this.lastParentValue == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n await this.emitNextValue(await this.joinValues(this.lastParentValue, attachedValue));\n }\n };\n\n private readonly handleChangeParentValue = async (parentValue: TI): Promise<void> => {\n this.lastParentValue = parentValue;\n const attachKey = await this.evaluateAttachKey(parentValue);\n if (this.attachedProducer != undefined && this.detachAttachedListener == undefined) {\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.lastAttachKey == undefined || this.lastAttachKey !== attachKey) {\n this.lastAttachKey = attachKey;\n if (this.detachAttachedListener != undefined) {\n this.detachAttachedListener();\n }\n if (this.attachedProducer != undefined && this.isInObserveState) {\n await this.attachedProducer.endObserve();\n }\n this.attachedProducer = await this.attachFactory(parentValue);\n if (this.isInObserveState) {\n await this.attachedProducer.beginObserve();\n }\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.attachedProducer == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n // Просто немного обождем, вдруг придёт другое attachedValue\n this.awaitingLastAttachedValue = true;\n await delay(700);\n this.awaitingLastAttachedValue = false;\n let attachedValue = this.lastAttachedValue;\n if (attachedValue == undefined) {\n attachedValue = await this.attachedProducer.currentValue;\n }\n await this.emitNextValue(await this.joinValues(parentValue, attachedValue));\n };\n}\n\nexport class ExecuteOnValueProducer<T> extends ChainableValueProducer<T> {\n private readonly parent: IValueProducer<T>;\n private readonly action: (value: T) => Promise<void>;\n\n public constructor(parent: IValueProducer<T>, action: (value: T) => Promise<void>) {\n super();\n this.parent = parent;\n this.action = action;\n }\n\n public async beginObserve(): Promise<void> {\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n }\n\n public get currentValue(): Promise<T> {\n const getCurrentValue = async (): Promise<T> => {\n const value = await this.parent.currentValue;\n await this.action(value);\n return value;\n };\n return getCurrentValue();\n }\n\n public onNext(listener: (nextValue: T) => Promise<void>): DetachListener {\n return this.parent.onNext(async parentValue => {\n try {\n const value = parentValue;\n await this.action(value);\n await listener(value);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n await this.emitError(e);\n }\n });\n }\n}\n\nexport class TransformValueProducer<TI, TO> extends ChainableValueProducer<TO> {\n private readonly parent: IValueProducer<TI>;\n private readonly transformFunction: (value: TI) => Promise<TO>;\n\n public constructor(parent: IValueProducer<TI>, transformFunction: (value: TI) => Promise<TO>) {\n super();\n this.parent = parent;\n this.transformFunction = transformFunction;\n }\n\n public async beginObserve(): Promise<void> {\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n }\n\n public get currentValue(): Promise<TO> {\n const getCurrentValue = async (): Promise<TO> => this.transformFunction(await this.parent.currentValue);\n return getCurrentValue();\n }\n\n public onNext(listener: (nextValue: TO) => Promise<void>): DetachListener {\n return this.parent.onNext(async parentValue => {\n await listener(await this.transformFunction(parentValue));\n });\n }\n}\n\nexport class SplitToChainsValueProducer<T, TI, TO> extends ChainableValueProducer<TO[]> {\n private readonly parent: IValueProducer<T>;\n private readonly splitFunction: (input: T) => TI[];\n private readonly getKey: (input: TI) => string;\n private readonly factory: (input: TI) => IValueProducer<TO>;\n private readonly listeners: Array<ValueListener<TO[]>> = [];\n private readonly chains: {\n [key: string]: {\n valueProducer: IValueProducer<TO>;\n lastValue: undefined | TO;\n detachListener: DetachListener;\n };\n } = {};\n private isInObserveState = false;\n\n public constructor(\n parent: IValueProducer<T>,\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO>\n ) {\n super();\n this.parent = parent;\n this.splitFunction = splitFunction;\n this.getKey = getKey;\n this.factory = factory;\n this.parent.onNext(this.handleChangeParent);\n }\n\n public get currentValue(): Promise<TO[]> {\n const getCurrentValue = async (): Promise<TO[]> => {\n const values = this.splitFunction(await this.parent.currentValue);\n const result: TO[] = [];\n const errors: ReasonOrError[] = [];\n for (const value of values) {\n const childValueProducer = this.factory(value);\n if (this.isInObserveState) {\n await childValueProducer.beginObserve();\n }\n try {\n const childValue = await childValueProducer.currentValue;\n result.push(childValue);\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: childValue,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n } catch (e) {\n if (this.isInObserveState) {\n // eslint-disable-next-line no-console\n console.log(e);\n } else {\n errors.push(e);\n }\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: undefined,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n }\n }\n if (errors.length === 1) {\n throw errors[0];\n } else if (errors.length > 1) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n throw new AggregatedError(\"There are errors\", ...errors);\n }\n return result;\n };\n return getCurrentValue();\n }\n\n public async beginObserve(): Promise<void> {\n this.isInObserveState = true;\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n for (const value of iterateValues(this.chains)) {\n await value.valueProducer.endObserve();\n }\n this.isInObserveState = false;\n }\n\n public onNext(listener: (nextValue: TO[]) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n };\n }\n\n private async emitValue(value: TO[]): Promise<void> {\n for (const listener of this.listeners) {\n await listener(value);\n }\n }\n\n private toMap(values: TI[]): { [key: string]: TI } {\n const result: { [key: string]: TI } = {};\n for (const value of values) {\n result[this.getKey(value)] = value;\n }\n return result;\n }\n\n private readonly handleChangeParentChain = async (nextValue: TO, key: string): Promise<void> => {\n const chainValue = this.chains[key];\n if (chainValue != undefined) {\n chainValue.lastValue = nextValue;\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n\n private readonly handleChangeParent = async (input: T): Promise<void> => {\n const values = this.splitFunction(input);\n const nextValuesMap = this.toMap(values);\n\n const newKeys = _.difference(Object.keys(nextValuesMap), Object.keys(this.chains));\n const removedKeys = _.difference(Object.keys(this.chains), Object.keys(nextValuesMap));\n for (const newKey of newKeys) {\n const newChain = this.factory(nextValuesMap[newKey] ?? reject());\n if (this.isInObserveState) {\n await newChain.beginObserve();\n }\n try {\n const newChainValue = await newChain.currentValue;\n this.chains[newKey] = {\n lastValue: newChainValue,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n this.chains[newKey] = {\n lastValue: undefined,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n }\n }\n for (const removedKey of removedKeys) {\n const removedChain = this.chains[removedKey];\n removedChain?.detachListener();\n if (this.isInObserveState) {\n await removedChain?.valueProducer.endObserve();\n }\n // Я не знаю, как тут правильно\n delete this.chains[removedKey];\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n}\n\nexport class ParallelSplitToChainsValueProducer<T, TI, TO> extends ChainableValueProducer<TO[]> {\n private readonly parent: IValueProducer<T>;\n private readonly splitFunction: (input: T) => TI[];\n private readonly getKey: (input: TI) => string;\n private readonly factory: (input: TI) => IValueProducer<TO> | Promise<IValueProducer<TO>>;\n private readonly listeners: Array<ValueListener<TO[]>> = [];\n private readonly chains: {\n [key: string]: {\n valueProducer: IValueProducer<TO>;\n lastValue: undefined | TO;\n detachListener: DetachListener;\n };\n } = {};\n private isInObserveState = false;\n\n public constructor(\n parent: IValueProducer<T>,\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO> | Promise<IValueProducer<TO>>\n ) {\n super();\n this.parent = parent;\n this.splitFunction = splitFunction;\n this.getKey = getKey;\n this.factory = factory;\n this.parent.onNext(this.handleChangeParent);\n }\n\n public get currentValue(): Promise<TO[]> {\n const getCurrentValue = async (): Promise<TO[]> => {\n const values = this.splitFunction(await this.parent.currentValue);\n const result: TO[] = [];\n const errors: ReasonOrError[] = [];\n const cpuLimit = getCpuLimits();\n // eslint-disable-next-line no-console\n console.log(`Use limit: ${cpuLimit}`);\n const concurrencyLimit = pLimit(cpuLimit);\n await Promise.all(\n values.map((value, index) =>\n concurrencyLimit(async () => {\n const childValueProducer = await this.factory(value);\n if (this.isInObserveState) {\n await childValueProducer.beginObserve();\n }\n try {\n const childValue = await childValueProducer.currentValue;\n result[index] = childValue;\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: childValue,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n } catch (e) {\n if (this.isInObserveState) {\n // eslint-disable-next-line no-console\n console.log(e);\n } else {\n errors.push(e);\n }\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: undefined,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n }\n })\n )\n );\n if (errors.length === 1) {\n throw errors[0];\n } else if (errors.length > 1) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n throw new AggregatedError(\"There are errors\", ...errors);\n }\n return result;\n };\n return getCurrentValue();\n }\n\n public async beginObserve(): Promise<void> {\n this.isInObserveState = true;\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n for (const key of Object.keys(this.chains)) {\n await this.chains[key]?.valueProducer.endObserve();\n }\n this.isInObserveState = false;\n }\n\n public onNext(listener: (nextValue: TO[]) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n };\n }\n\n private async emitValue(value: TO[]): Promise<void> {\n for (const listener of this.listeners) {\n await listener(value);\n }\n }\n\n private toMap(values: TI[]): { [key: string]: TI } {\n const result: { [key: string]: TI } = {};\n for (const value of values) {\n result[this.getKey(value)] = value;\n }\n return result;\n }\n\n private readonly handleChangeParentChain = async (nextValue: TO, key: string): Promise<void> => {\n const chainValue = this.chains[key];\n if (chainValue != undefined) {\n chainValue.lastValue = nextValue;\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n\n private readonly handleChangeParent = async (input: T): Promise<void> => {\n const values = this.splitFunction(input);\n const nextValuesMap = this.toMap(values);\n\n const newKeys = _.difference(Object.keys(nextValuesMap), Object.keys(this.chains));\n const removedKeys = _.difference(Object.keys(this.chains), Object.keys(nextValuesMap));\n for (const newKey of newKeys) {\n const newChain = await this.factory(nextValuesMap[newKey] ?? reject());\n if (this.isInObserveState) {\n await newChain.beginObserve();\n }\n try {\n const newChainValue = await newChain.currentValue;\n this.chains[newKey] = {\n lastValue: newChainValue,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n this.chains[newKey] = {\n lastValue: undefined,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n }\n }\n for (const removedKey of removedKeys) {\n const removedChain = this.chains[removedKey];\n removedChain?.detachListener();\n if (this.isInObserveState) {\n await removedChain?.valueProducer.endObserve();\n }\n // Я не знаю, как тут правильно\n delete this.chains[removedKey];\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n}\n\nexport class SkipUpdatesUntilNextCompletedProducer<T> extends ObservableValueProducerBase<T> {\n private readonly parent: IValueProducer<T>;\n private detachFromParent?: DetachListener;\n private lastParentValue?: T;\n\n private nextEmitToProcess?: () => Promise<void>;\n private currentlyProcessingEmit?: Promise<void>;\n\n public constructor(parent: IValueProducer<T>) {\n super();\n this.parent = parent;\n }\n\n protected async getCurrentValue(): Promise<T> {\n if (this.lastParentValue == undefined) {\n this.currentlyProcessingEmit = (async () => {\n this.lastParentValue = await this.parent.currentValue;\n })();\n await this.currentlyProcessingEmit;\n }\n if (this.lastParentValue == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n return this.lastParentValue;\n }\n\n protected async beginListening(): Promise<void> {\n await this.parent.beginObserve();\n if (this.detachFromParent == undefined) {\n this.detachFromParent = this.parent.onNext(nextValue => this.handleChangeParentValue(nextValue));\n }\n }\n\n protected async stopListening(): Promise<void> {\n if (this.detachFromParent != undefined) {\n this.detachFromParent();\n }\n await this.parent.endObserve();\n }\n\n private async handleChangeParentValue(nextValue: T): Promise<void> {\n this.lastParentValue = nextValue;\n this.nextEmitToProcess = _.once(() => this.emitUpdate(nextValue));\n if (this.currentlyProcessingEmit != undefined) {\n await this.currentlyProcessingEmit;\n }\n this.currentlyProcessingEmit = this.nextEmitToProcess();\n await this.currentlyProcessingEmit;\n this.currentlyProcessingEmit = undefined;\n }\n}\n\nfunction delay(timeout: number): Promise<void> {\n return new Promise<void>(resolve => {\n setTimeout(() => {\n resolve();\n }, timeout);\n });\n}\n\nfunction isNotNullOrUndefined<T>(input: T | undefined | null): input is T {\n return input != undefined;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAGA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,gBAAA,GAAAL,OAAA;AAGA,eAAeM,IAAIA,CAAA,EAAkB;EACjC;AAAA;AAGG,MAAMC,sBAAsB,CAAiC;EAAAC,YAAA;IAAA,KAC/CC,cAAc,GAAgC,EAAE;EAAA;EAE1DC,MAAMA,CAACC,SAA0C,EAAkB;IACtE,MAAM,IAAIC,KAAK,CAAC,eAAe,CAAC;EACpC;EAEOC,OAAOA,CAACC,QAAyC,EAAkB;IACtE,IAAI,CAACL,cAAc,CAACM,IAAI,CAACD,QAAQ,CAAC;IAClC,OAAO,MAAM;MACT,MAAME,KAAK,GAAG,IAAI,CAACP,cAAc,CAACQ,OAAO,CAACH,QAAQ,CAAC;MACnD,IAAIE,KAAK,IAAI,CAAC,EAAE;QACZ,IAAI,CAACP,cAAc,CAACS,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;MACxC;IACJ,CAAC;EACL;EAEA,IAAWG,YAAYA,CAAA,EAAe;IAClC,MAAM,IAAIP,KAAK,CAAC,eAAe,CAAC;EACpC;EAEOQ,SAASA,CAAKC,iBAA4C,EAAiC;IAC9F,OAAO,IAAIC,sBAAsB,CAAC,I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AACqD,gBAAgB,GAAG,IAAI,CAAChE,MAAM,CAACnD,MAAM,CAACkD,SAAS,IAAI,IAAI,CAACc,uBAAuB,CAACd,SAAS,CAAC,CAAC;IACpG;EACJ;EAEA,MAAgBJ,aAAaA,CAAA,EAAkB;IAC3C,IAAI,IAAI,CAACqE,gBAAgB,IAAIrD,SAAS,EAAE;MACpC,IAAI,CAACqD,gBAAgB,CAAC,CAAC;IAC3B;IACA,MAAM,IAAI,CAAChE,MAAM,CAAChB,UAAU,CAAC,CAAC;EAClC;EAEA,MAAc6B,uBAAuBA,CAACd,SAAY,EAAiB;IAC/D,IAAI,CAACO,eAAe,GAAGP,SAAS;IAChC,IAAI,CAACkE,iBAAiB,GAAG3B,eAAC,CAAC6B,IAAI,CAAC,MAAM,IAAI,CAACvE,UAAU,CAACG,SAAS,CAAC,CAAC;IACjE,IAAI,IAAI,CAACmE,uBAAuB,IAAIvD,SAAS,EAAE;MAC3C,MAAM,IAAI,CAACuD,uBAAuB;IACtC;IACA,IAAI,CAACA,uBAAuB,GAAG,IAAI,CAACD,iBAAiB,CAAC,CAAC;IACvD,MAAM,IAAI,CAACC,uBAAuB;IAClC,IAAI,CAACA,uBAAuB,GAAGvD,SAAS;EAC5C;AACJ;AAACtB,OAAA,CAAAhB,qCAAA,GAAAA,qCAAA;AAED,SAAS2C,KAAKA,CAACoD,OAAe,EAAiB;EAC3C,OAAO,IAAIP,OAAO,CAAOQ,OAAO,IAAI;IAChCC,UAAU,CAAC,MAAM;MACbD,OAAO,CAAC,CAAC;IACb,CAAC,EAAED,OAAO,CAAC;EACf,CAAC,CAAC;AACN;AAEA,SAASpC,oBAAoBA,CAAIE,KAA2B,EAAc;EACtE,OAAOA,KAAK,IAAIvB,SAAS;AAC7B","ignoreList":[]}
1
+ {"version":3,"file":"ChainableValueProducer.js","names":["_lodash","_interopRequireDefault","require","_pLimit","_IterableUtils","_TypingUtils","_GetCpuLimits","_AggregatedError","noop","ChainableValueProducer","constructor","errorListeners","onNext","_listener","Error","onError","listener","push","index","indexOf","splice","currentValue","transform","transformFunction","TransformValueProducer","do","action","ExecuteOnValueProducer","chainWith","nextItemFactory","attach","attachFactory","joinValues","evaluateAttachKey","AttachValueProducer","skipUpdatesUntilNextCompleted","SkipUpdatesUntilNextCompletedProducer","splitToChains","splitFunction","getKey","factory","SplitToChainsValueProducer","splitToParallelChains","ParallelSplitToChainsValueProducer","observe","beginObserve","detachListener","endObserve","emitError","error","errorObject","errorListener","exports","ObservableValueProducerBase","args","listeners","getCurrentValue","beginListening","stopListening","emitUpdate","value","notifyAllListenersAndWaitForComplete","nextValue","parent","lastAttachKey","attachedProducer","detachParentListener","detachAttachedListener","lastAttachedValue","lastParentValue","awaitingLastAttachedValue","isInObserveState","handleChangeAttachedValue","attachedValue","undefined","emitNextValue","handleChangeParentValue","parentValue","attachKey","delay","x","length","e","console","log","chains","handleChangeParentChain","key","chainValue","lastValue","emitValue","Object","values","map","filter","isNotNullOrUndefined","handleChangeParent","input","nextValuesMap","toMap","newKeys","_","difference","keys","removedKeys","newKey","_nextValuesMap$newKey","newChain","reject","newChainValue","valueProducer","removedKey","removedChain","result","errors","childValueProducer","childValue","AggregatedError","iterateValues","_nextValuesMap$newKey2","cpuLimit","getCpuLimits","concurrencyLimit","pLimit","Promise","all","_this$chains$key","detachFromParent","nextEmitToProcess","currentlyProcessingEmit","once","timeout","resolve","setTimeout"],"sources":["../../../../../src/Commons/TasksCore/ChainableValueProducer.ts"],"sourcesContent":["import _ from \"lodash\";\nimport pLimit from \"p-limit\";\n\nimport { ReasonOrError } from \"../ErrorUntyped\";\nimport { iterateValues } from \"../../../../Common/IterableUtils\";\nimport { reject } from \"../../../../Common/TypingUtils\";\nimport { getCpuLimits } from \"../GetCpuLimits\";\n\nimport { AggregatedError } from \"./AggregatedError\";\nimport { DetachListener, IValueProducer, ValueListener } from \"./BuildTask\";\n\nasync function noop(): Promise<void> {\n // empty function\n}\n\nexport class ChainableValueProducer<T> implements IValueProducer<T> {\n private readonly errorListeners: Array<ValueListener<Error>> = [];\n\n public onNext(_listener: (nextValue: T) => Promise<void>): DetachListener {\n throw new Error(\"AbstractError\");\n }\n\n public onError(listener: (error: Error) => Promise<void>): DetachListener {\n this.errorListeners.push(listener);\n return () => {\n const index = this.errorListeners.indexOf(listener);\n if (index >= 0) {\n this.errorListeners.splice(index, 1);\n }\n };\n }\n\n public get currentValue(): Promise<T> {\n throw new Error(\"AbstractError\");\n }\n\n public transform<TO>(transformFunction: (input: T) => Promise<TO>): TransformValueProducer<T, TO> {\n return new TransformValueProducer(this, transformFunction);\n }\n\n public do(action: (input: T) => Promise<void>): ExecuteOnValueProducer<T> {\n return new ExecuteOnValueProducer(this, action);\n }\n\n public chainWith<TO, TVP extends IValueProducer<TO>>(nextItemFactory: (prevItem: IValueProducer<T>) => TVP): TVP {\n return nextItemFactory(this);\n }\n\n public attach<TA, TO = T>(\n attachFactory: (value: T) => Promise<IValueProducer<TA>>,\n joinValues?: (original: T, attached: TA) => Promise<TO>,\n evaluateAttachKey?: (value: T) => Promise<string>\n ): AttachValueProducer<T, TA, TO> {\n return new AttachValueProducer(this, attachFactory, joinValues, evaluateAttachKey);\n }\n\n public skipUpdatesUntilNextCompleted(): SkipUpdatesUntilNextCompletedProducer<T> {\n return new SkipUpdatesUntilNextCompletedProducer(this);\n }\n\n public splitToChains<TI, TO>(\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO>\n ): SplitToChainsValueProducer<T, TI, TO> {\n return new SplitToChainsValueProducer(this, splitFunction, getKey, factory);\n }\n\n public splitToParallelChains<TI, TO>(\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO> | Promise<IValueProducer<TO>>\n ): ParallelSplitToChainsValueProducer<T, TI, TO> {\n return new ParallelSplitToChainsValueProducer(this, splitFunction, getKey, factory);\n }\n\n public async observe(listener: ValueListener<T> = noop): Promise<() => Promise<void>> {\n await this.beginObserve();\n await listener(await this.currentValue);\n const detachListener = this.onNext(listener);\n return async () => {\n detachListener();\n await this.endObserve();\n };\n }\n\n public async beginObserve(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n public async endObserve(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async emitError(error: any): Promise<void> {\n const errorObject = error instanceof Error ? error : new Error(`${error}`);\n for (const errorListener of this.errorListeners) {\n await errorListener(errorObject);\n }\n }\n}\n\nexport class ObservableValueProducerBase<T> extends ChainableValueProducer<T> {\n public get currentValue(): Promise<T> {\n return this.getCurrentValue();\n }\n\n private readonly listeners: Array<ValueListener<T>> = [];\n\n protected async getCurrentValue(): Promise<T> {\n throw new Error(\"AbstractError\");\n }\n\n public async beginObserve(): Promise<void> {\n await this.beginListening();\n }\n\n public async endObserve(): Promise<void> {\n await this.stopListening();\n }\n\n protected async beginListening(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n protected async stopListening(): Promise<void> {\n throw new Error(\"AbstractError\");\n }\n\n protected async emitUpdate(value: T): Promise<void> {\n await this.notifyAllListenersAndWaitForComplete(value);\n }\n\n public onNext(listener: (nextValue: T) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n };\n }\n\n private async notifyAllListenersAndWaitForComplete(nextValue: T): Promise<void> {\n for (const listener of this.listeners) {\n await listener(nextValue);\n }\n }\n}\n\nexport class AttachValueProducer<TI, TA, TO> extends ChainableValueProducer<TO> {\n private readonly parent: IValueProducer<TI>;\n private readonly attachFactory: (value: TI) => Promise<IValueProducer<TA>>;\n private readonly joinValues: (original: TI, attached: TA) => Promise<TO>;\n private lastAttachKey?: string;\n private attachedProducer?: IValueProducer<TA>;\n private readonly evaluateAttachKey: (value: TI) => Promise<string>;\n private readonly listeners: Array<ValueListener<TO>> = [];\n private detachParentListener?: DetachListener;\n private detachAttachedListener?: DetachListener;\n private lastAttachedValue?: TA;\n private lastParentValue?: TI;\n private awaitingLastAttachedValue = false;\n private isInObserveState = false;\n\n public constructor(\n parent: IValueProducer<TI>,\n attachFactory: (value: TI) => Promise<IValueProducer<TA>>,\n joinValues?: (original: TI, attached: TA) => Promise<TO>,\n evaluateAttachKey?: (value: TI) => Promise<string>\n ) {\n super();\n this.parent = parent;\n this.attachFactory = attachFactory;\n // Я не могу победить типизацию в этом месте, слишком много у меня кода получается\n // @ts-ignore\n this.joinValues = joinValues || (async x => x);\n this.evaluateAttachKey = evaluateAttachKey || (async () => \"STATIC-ATTACH-KEY\");\n }\n\n public async beginObserve(): Promise<void> {\n this.isInObserveState = true;\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n if (this.attachedProducer != undefined) {\n await this.attachedProducer.endObserve();\n }\n this.isInObserveState = false;\n }\n\n public get currentValue(): Promise<TO> {\n const getCurrentValue = async (): Promise<TO> => {\n const parentValue = await this.parent.currentValue;\n this.lastParentValue = parentValue;\n const attachKey = await this.evaluateAttachKey(parentValue);\n if (this.attachedProducer != undefined && this.detachAttachedListener == undefined) {\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.lastAttachKey == undefined || this.lastAttachKey !== attachKey) {\n this.lastAttachKey = attachKey;\n if (this.detachAttachedListener != undefined) {\n this.detachAttachedListener();\n }\n if (this.attachedProducer != undefined && this.isInObserveState) {\n await this.attachedProducer.endObserve();\n }\n this.attachedProducer = await this.attachFactory(parentValue);\n if (this.isInObserveState) {\n await this.attachedProducer.beginObserve();\n }\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.attachedProducer == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n const attachedValue = await this.attachedProducer.currentValue;\n this.lastAttachedValue = attachedValue;\n return this.joinValues(parentValue, attachedValue);\n };\n return getCurrentValue();\n }\n\n public async emitNextValue(value: TO): Promise<void> {\n for (const listener of this.listeners) {\n await listener(value);\n }\n }\n\n public onNext(listener: (nextValue: TO) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n if (this.listeners.length === 1) {\n if (this.detachParentListener == undefined) {\n this.detachParentListener = this.parent.onNext(this.handleChangeParentValue);\n }\n if (this.attachedProducer != undefined && this.detachParentListener == undefined) {\n this.detachParentListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n }\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n if (this.listeners.length === 0) {\n if (this.detachParentListener != undefined) {\n this.detachParentListener();\n }\n if (this.detachAttachedListener != undefined) {\n this.detachAttachedListener();\n }\n }\n };\n }\n\n private readonly handleChangeAttachedValue = async (attachedValue: TA): Promise<void> => {\n this.lastAttachedValue = attachedValue;\n if (!this.awaitingLastAttachedValue) {\n if (this.lastParentValue == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n await this.emitNextValue(await this.joinValues(this.lastParentValue, attachedValue));\n }\n };\n\n private readonly handleChangeParentValue = async (parentValue: TI): Promise<void> => {\n this.lastParentValue = parentValue;\n const attachKey = await this.evaluateAttachKey(parentValue);\n if (this.attachedProducer != undefined && this.detachAttachedListener == undefined) {\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.lastAttachKey == undefined || this.lastAttachKey !== attachKey) {\n this.lastAttachKey = attachKey;\n if (this.detachAttachedListener != undefined) {\n this.detachAttachedListener();\n }\n if (this.attachedProducer != undefined && this.isInObserveState) {\n await this.attachedProducer.endObserve();\n }\n this.attachedProducer = await this.attachFactory(parentValue);\n if (this.isInObserveState) {\n await this.attachedProducer.beginObserve();\n }\n this.detachAttachedListener = this.attachedProducer.onNext(this.handleChangeAttachedValue);\n }\n if (this.attachedProducer == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n // Просто немного обождем, вдруг придёт другое attachedValue\n this.awaitingLastAttachedValue = true;\n await delay(700);\n this.awaitingLastAttachedValue = false;\n let attachedValue = this.lastAttachedValue;\n if (attachedValue == undefined) {\n attachedValue = await this.attachedProducer.currentValue;\n }\n await this.emitNextValue(await this.joinValues(parentValue, attachedValue));\n };\n}\n\nexport class ExecuteOnValueProducer<T> extends ChainableValueProducer<T> {\n private readonly parent: IValueProducer<T>;\n private readonly action: (value: T) => Promise<void>;\n\n public constructor(parent: IValueProducer<T>, action: (value: T) => Promise<void>) {\n super();\n this.parent = parent;\n this.action = action;\n }\n\n public async beginObserve(): Promise<void> {\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n }\n\n public get currentValue(): Promise<T> {\n const getCurrentValue = async (): Promise<T> => {\n const value = await this.parent.currentValue;\n await this.action(value);\n return value;\n };\n return getCurrentValue();\n }\n\n public onNext(listener: (nextValue: T) => Promise<void>): DetachListener {\n return this.parent.onNext(async parentValue => {\n try {\n const value = parentValue;\n await this.action(value);\n await listener(value);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n await this.emitError(e);\n }\n });\n }\n}\n\nexport class TransformValueProducer<TI, TO> extends ChainableValueProducer<TO> {\n private readonly parent: IValueProducer<TI>;\n private readonly transformFunction: (value: TI) => Promise<TO>;\n\n public constructor(parent: IValueProducer<TI>, transformFunction: (value: TI) => Promise<TO>) {\n super();\n this.parent = parent;\n this.transformFunction = transformFunction;\n }\n\n public async beginObserve(): Promise<void> {\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n }\n\n public get currentValue(): Promise<TO> {\n const getCurrentValue = async (): Promise<TO> => this.transformFunction(await this.parent.currentValue);\n return getCurrentValue();\n }\n\n public onNext(listener: (nextValue: TO) => Promise<void>): DetachListener {\n return this.parent.onNext(async parentValue => {\n try {\n await listener(await this.transformFunction(parentValue));\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e);\n await this.emitError(e);\n }\n });\n }\n}\n\nexport class SplitToChainsValueProducer<T, TI, TO> extends ChainableValueProducer<TO[]> {\n private readonly parent: IValueProducer<T>;\n private readonly splitFunction: (input: T) => TI[];\n private readonly getKey: (input: TI) => string;\n private readonly factory: (input: TI) => IValueProducer<TO>;\n private readonly listeners: Array<ValueListener<TO[]>> = [];\n private readonly chains: {\n [key: string]: {\n valueProducer: IValueProducer<TO>;\n lastValue: undefined | TO;\n detachListener: DetachListener;\n };\n } = {};\n private isInObserveState = false;\n\n public constructor(\n parent: IValueProducer<T>,\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO>\n ) {\n super();\n this.parent = parent;\n this.splitFunction = splitFunction;\n this.getKey = getKey;\n this.factory = factory;\n this.parent.onNext(this.handleChangeParent);\n }\n\n public get currentValue(): Promise<TO[]> {\n const getCurrentValue = async (): Promise<TO[]> => {\n const values = this.splitFunction(await this.parent.currentValue);\n const result: TO[] = [];\n const errors: ReasonOrError[] = [];\n for (const value of values) {\n const childValueProducer = this.factory(value);\n if (this.isInObserveState) {\n await childValueProducer.beginObserve();\n }\n try {\n const childValue = await childValueProducer.currentValue;\n result.push(childValue);\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: childValue,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n } catch (e) {\n if (this.isInObserveState) {\n // eslint-disable-next-line no-console\n console.log(e);\n } else {\n errors.push(e);\n }\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: undefined,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n }\n }\n if (errors.length === 1) {\n throw errors[0];\n } else if (errors.length > 1) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n throw new AggregatedError(\"There are errors\", ...errors);\n }\n return result;\n };\n return getCurrentValue();\n }\n\n public async beginObserve(): Promise<void> {\n this.isInObserveState = true;\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n for (const value of iterateValues(this.chains)) {\n await value.valueProducer.endObserve();\n }\n this.isInObserveState = false;\n }\n\n public onNext(listener: (nextValue: TO[]) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n };\n }\n\n private async emitValue(value: TO[]): Promise<void> {\n for (const listener of this.listeners) {\n await listener(value);\n }\n }\n\n private toMap(values: TI[]): { [key: string]: TI } {\n const result: { [key: string]: TI } = {};\n for (const value of values) {\n result[this.getKey(value)] = value;\n }\n return result;\n }\n\n private readonly handleChangeParentChain = async (nextValue: TO, key: string): Promise<void> => {\n const chainValue = this.chains[key];\n if (chainValue != undefined) {\n chainValue.lastValue = nextValue;\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n\n private readonly handleChangeParent = async (input: T): Promise<void> => {\n const values = this.splitFunction(input);\n const nextValuesMap = this.toMap(values);\n\n const newKeys = _.difference(Object.keys(nextValuesMap), Object.keys(this.chains));\n const removedKeys = _.difference(Object.keys(this.chains), Object.keys(nextValuesMap));\n for (const newKey of newKeys) {\n const newChain = this.factory(nextValuesMap[newKey] ?? reject());\n if (this.isInObserveState) {\n await newChain.beginObserve();\n }\n try {\n const newChainValue = await newChain.currentValue;\n this.chains[newKey] = {\n lastValue: newChainValue,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n this.chains[newKey] = {\n lastValue: undefined,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n }\n }\n for (const removedKey of removedKeys) {\n const removedChain = this.chains[removedKey];\n removedChain?.detachListener();\n if (this.isInObserveState) {\n await removedChain?.valueProducer.endObserve();\n }\n // Я не знаю, как тут правильно\n delete this.chains[removedKey];\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n}\n\nexport class ParallelSplitToChainsValueProducer<T, TI, TO> extends ChainableValueProducer<TO[]> {\n private readonly parent: IValueProducer<T>;\n private readonly splitFunction: (input: T) => TI[];\n private readonly getKey: (input: TI) => string;\n private readonly factory: (input: TI) => IValueProducer<TO> | Promise<IValueProducer<TO>>;\n private readonly listeners: Array<ValueListener<TO[]>> = [];\n private readonly chains: {\n [key: string]: {\n valueProducer: IValueProducer<TO>;\n lastValue: undefined | TO;\n detachListener: DetachListener;\n };\n } = {};\n private isInObserveState = false;\n\n public constructor(\n parent: IValueProducer<T>,\n splitFunction: (input: T) => TI[],\n getKey: (input: TI) => string,\n factory: (input: TI) => IValueProducer<TO> | Promise<IValueProducer<TO>>\n ) {\n super();\n this.parent = parent;\n this.splitFunction = splitFunction;\n this.getKey = getKey;\n this.factory = factory;\n this.parent.onNext(this.handleChangeParent);\n }\n\n public get currentValue(): Promise<TO[]> {\n const getCurrentValue = async (): Promise<TO[]> => {\n const values = this.splitFunction(await this.parent.currentValue);\n const result: TO[] = [];\n const errors: ReasonOrError[] = [];\n const cpuLimit = getCpuLimits();\n // eslint-disable-next-line no-console\n console.log(`Use limit: ${cpuLimit}`);\n const concurrencyLimit = pLimit(cpuLimit);\n await Promise.all(\n values.map((value, index) =>\n concurrencyLimit(async () => {\n const childValueProducer = await this.factory(value);\n if (this.isInObserveState) {\n await childValueProducer.beginObserve();\n }\n try {\n const childValue = await childValueProducer.currentValue;\n result[index] = childValue;\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: childValue,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n } catch (e) {\n if (this.isInObserveState) {\n // eslint-disable-next-line no-console\n console.log(e);\n } else {\n errors.push(e);\n }\n const key = this.getKey(value);\n this.chains[key] = {\n lastValue: undefined,\n valueProducer: childValueProducer,\n detachListener: childValueProducer.onNext(x => this.handleChangeParentChain(x, key)),\n };\n }\n })\n )\n );\n if (errors.length === 1) {\n throw errors[0];\n } else if (errors.length > 1) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n throw new AggregatedError(\"There are errors\", ...errors);\n }\n return result;\n };\n return getCurrentValue();\n }\n\n public async beginObserve(): Promise<void> {\n this.isInObserveState = true;\n await this.parent.beginObserve();\n }\n\n public async endObserve(): Promise<void> {\n await this.parent.endObserve();\n for (const key of Object.keys(this.chains)) {\n await this.chains[key]?.valueProducer.endObserve();\n }\n this.isInObserveState = false;\n }\n\n public onNext(listener: (nextValue: TO[]) => Promise<void>): DetachListener {\n this.listeners.push(listener);\n return () => {\n const index = this.listeners.indexOf(listener);\n if (index >= 0) {\n this.listeners.splice(index, 1);\n }\n };\n }\n\n private async emitValue(value: TO[]): Promise<void> {\n for (const listener of this.listeners) {\n await listener(value);\n }\n }\n\n private toMap(values: TI[]): { [key: string]: TI } {\n const result: { [key: string]: TI } = {};\n for (const value of values) {\n result[this.getKey(value)] = value;\n }\n return result;\n }\n\n private readonly handleChangeParentChain = async (nextValue: TO, key: string): Promise<void> => {\n const chainValue = this.chains[key];\n if (chainValue != undefined) {\n chainValue.lastValue = nextValue;\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n\n private readonly handleChangeParent = async (input: T): Promise<void> => {\n const values = this.splitFunction(input);\n const nextValuesMap = this.toMap(values);\n\n const newKeys = _.difference(Object.keys(nextValuesMap), Object.keys(this.chains));\n const removedKeys = _.difference(Object.keys(this.chains), Object.keys(nextValuesMap));\n for (const newKey of newKeys) {\n const newChain = await this.factory(nextValuesMap[newKey] ?? reject());\n if (this.isInObserveState) {\n await newChain.beginObserve();\n }\n try {\n const newChainValue = await newChain.currentValue;\n this.chains[newKey] = {\n lastValue: newChainValue,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n this.chains[newKey] = {\n lastValue: undefined,\n valueProducer: newChain,\n detachListener: newChain.onNext(nextValue => this.handleChangeParentChain(nextValue, newKey)),\n };\n }\n }\n for (const removedKey of removedKeys) {\n const removedChain = this.chains[removedKey];\n removedChain?.detachListener();\n if (this.isInObserveState) {\n await removedChain?.valueProducer.endObserve();\n }\n // Я не знаю, как тут правильно\n delete this.chains[removedKey];\n }\n await this.emitValue(\n Object.values(this.chains)\n .map(x => x.lastValue)\n .filter(isNotNullOrUndefined)\n );\n };\n}\n\nexport class SkipUpdatesUntilNextCompletedProducer<T> extends ObservableValueProducerBase<T> {\n private readonly parent: IValueProducer<T>;\n private detachFromParent?: DetachListener;\n private lastParentValue?: T;\n\n private nextEmitToProcess?: () => Promise<void>;\n private currentlyProcessingEmit?: Promise<void>;\n\n public constructor(parent: IValueProducer<T>) {\n super();\n this.parent = parent;\n }\n\n protected async getCurrentValue(): Promise<T> {\n if (this.lastParentValue == undefined) {\n this.currentlyProcessingEmit = (async () => {\n this.lastParentValue = await this.parent.currentValue;\n })();\n await this.currentlyProcessingEmit;\n }\n if (this.lastParentValue == undefined) {\n throw new Error(\"InvalidProgramState\");\n }\n return this.lastParentValue;\n }\n\n protected async beginListening(): Promise<void> {\n await this.parent.beginObserve();\n if (this.detachFromParent == undefined) {\n this.detachFromParent = this.parent.onNext(nextValue => this.handleChangeParentValue(nextValue));\n }\n }\n\n protected async stopListening(): Promise<void> {\n if (this.detachFromParent != undefined) {\n this.detachFromParent();\n }\n await this.parent.endObserve();\n }\n\n private async handleChangeParentValue(nextValue: T): Promise<void> {\n this.lastParentValue = nextValue;\n this.nextEmitToProcess = _.once(() => this.emitUpdate(nextValue));\n if (this.currentlyProcessingEmit != undefined) {\n await this.currentlyProcessingEmit;\n }\n this.currentlyProcessingEmit = this.nextEmitToProcess();\n await this.currentlyProcessingEmit;\n this.currentlyProcessingEmit = undefined;\n }\n}\n\nfunction delay(timeout: number): Promise<void> {\n return new Promise<void>(resolve => {\n setTimeout(() => {\n resolve();\n }, timeout);\n });\n}\n\nfunction isNotNullOrUndefined<T>(input: T | undefined | null): input is T {\n return input != undefined;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAGA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAEA,IAAAK,gBAAA,GAAAL,OAAA;AAGA,eAAeM,IAAIA,CAAA,EAAkB;EACjC;AAAA;AAGG,MAAMC,sBAAsB,CAAiC;EAAAC,YAAA;IAAA,KAC/CC,cAAc,GAAgC,EAAE;EAAA;EAE1DC,MAAMA,CAACC,SAA0C,EAAkB;IACtE,MAAM,IAAIC,KAAK,CAAC,eAAe,CAAC;EACpC;EAEOC,OAAOA,CAACC,QAAyC,EAAkB;IACtE,IAAI,CAACL,cAAc,CAACM,IAAI,CAACD,QAAQ,CAAC;IAClC,OAAO,MAAM;MACT,MAAME,KAAK,GAAG,IAAI,CAACP,cAAc,CAACQ,OAAO,CAACH,QAAQ,CAAC;MACnD,IAAIE,KAAK,IAAI,CAAC,EAAE;QACZ,IAAI,CAACP,cAAc,CAACS,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;MACxC;IACJ,CAAC;EACL;EAEA,IAAWG,YAAYA,CAAA,EAAe;IAClC,MAAM,IAAIP,KAAK,CAAC,eAAe,CAAC;EACpC;EAEOQ,SAASA,CAAKC,iBAA4C,EAAiC;IAC9F,OAAO,IAAIC,sBAAsB,CAAC,IAAI,EAAED,iBAAiB,CAAC;EAC9D;EAEOE,EAAEA,CAACC,MAAmC,EAA6B;IACtE,OAAO,IAAIC,sBAAsB,CAAC,IAAI,EAAED,MAAM,CAAC;EACnD;EAEOE,SAASA,CAAqCC,eAAqD,EAAO;IAC7G,OAAOA,eAAe,CAAC,IAAI,CAA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,MAAM,CAACkD,SAAS,IAAI,IAAI,CAACc,uBAAuB,CAACd,SAAS,CAAC,CAAC;IACpG;EACJ;EAEA,MAAgBJ,aAAaA,CAAA,EAAkB;IAC3C,IAAI,IAAI,CAACqE,gBAAgB,IAAIrD,SAAS,EAAE;MACpC,IAAI,CAACqD,gBAAgB,CAAC,CAAC;IAC3B;IACA,MAAM,IAAI,CAAChE,MAAM,CAAChB,UAAU,CAAC,CAAC;EAClC;EAEA,MAAc6B,uBAAuBA,CAACd,SAAY,EAAiB;IAC/D,IAAI,CAACO,eAAe,GAAGP,SAAS;IAChC,IAAI,CAACkE,iBAAiB,GAAG3B,eAAC,CAAC6B,IAAI,CAAC,MAAM,IAAI,CAACvE,UAAU,CAACG,SAAS,CAAC,CAAC;IACjE,IAAI,IAAI,CAACmE,uBAAuB,IAAIvD,SAAS,EAAE;MAC3C,MAAM,IAAI,CAACuD,uBAAuB;IACtC;IACA,IAAI,CAACA,uBAAuB,GAAG,IAAI,CAACD,iBAAiB,CAAC,CAAC;IACvD,MAAM,IAAI,CAACC,uBAAuB;IAClC,IAAI,CAACA,uBAAuB,GAAGvD,SAAS;EAC5C;AACJ;AAACtB,OAAA,CAAAhB,qCAAA,GAAAA,qCAAA;AAED,SAAS2C,KAAKA,CAACoD,OAAe,EAAiB;EAC3C,OAAO,IAAIP,OAAO,CAAOQ,OAAO,IAAI;IAChCC,UAAU,CAAC,MAAM;MACbD,OAAO,CAAC,CAAC;IACb,CAAC,EAAED,OAAO,CAAC;EACf,CAAC,CAAC;AACN;AAEA,SAASpC,oBAAoBA,CAAIE,KAA2B,EAAc;EACtE,OAAOA,KAAK,IAAIvB,SAAS;AAC7B","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.eventBus = exports.FORM_REMOVE_EVENT = void 0;
8
+ var _jsEventBus = _interopRequireDefault(require("js-event-bus"));
9
+ const FORM_REMOVE_EVENT = exports.FORM_REMOVE_EVENT = "FORM_REMOVE_EVENT";
10
+ const eventBus = exports.eventBus = new _jsEventBus.default();
11
+ //# sourceMappingURL=EventBus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventBus.js","names":["_jsEventBus","_interopRequireDefault","require","FORM_REMOVE_EVENT","exports","eventBus","EventBus"],"sources":["../../../../../src/Commons/TasksCore/EventBus.ts"],"sourcesContent":["import EventBus from \"js-event-bus\";\n\nexport const FORM_REMOVE_EVENT = \"FORM_REMOVE_EVENT\";\n\nexport const eventBus = new EventBus();\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,MAAMC,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,mBAAmB;AAE7C,MAAME,QAAQ,GAAAD,OAAA,CAAAC,QAAA,GAAG,IAAIC,mBAAQ,CAAC,CAAC","ignoreList":[]}
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.FileValueProducer = void 0;
8
8
  var _chokidar = require("chokidar");
9
9
  var _lodash = _interopRequireDefault(require("lodash"));
10
+ var _WellKnownDirectories = require("../../../../Common/WellKnownDirectories");
10
11
  var _ChainableValueProducer = require("./ChainableValueProducer");
12
+ var _EventBus = require("./EventBus");
11
13
  class FileValueProducer extends _ChainableValueProducer.ObservableValueProducerBase {
12
14
  constructor(pathToFile) {
13
15
  super();
@@ -24,7 +26,7 @@ class FileValueProducer extends _ChainableValueProducer.ObservableValueProducerB
24
26
  ignorePermissionErrors: false,
25
27
  usePolling: true
26
28
  });
27
- const handleAnyFsEventDebounced = _lodash.default.debounce(() => this.handleAnyFsEvent(), 1000);
29
+ const handleAnyFsEventDebounced = _lodash.default.debounce(event => this.handleAnyFsEvent(event), 1000);
28
30
  this.watcher.on("all", handleAnyFsEventDebounced);
29
31
  this.watcher.on("error", handleAnyFsEventDebounced);
30
32
  }
@@ -37,7 +39,10 @@ class FileValueProducer extends _ChainableValueProducer.ObservableValueProducerB
37
39
  async getCurrentValue() {
38
40
  return this.pathToFile;
39
41
  }
40
- async handleAnyFsEvent() {
42
+ async handleAnyFsEvent(event) {
43
+ if (event === "unlink" && this.pathToFile.includes(_WellKnownDirectories.WellKnownDirectories.FormJsonFileName)) {
44
+ _EventBus.eventBus.emit(_EventBus.FORM_REMOVE_EVENT);
45
+ }
41
46
  await this.emitUpdate(this.pathToFile);
42
47
  }
43
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FileValueProducer.js","names":["_chokidar","require","_lodash","_interopRequireDefault","_ChainableValueProducer","FileValueProducer","ObservableValueProducerBase","constructor","pathToFile","watcher","beginListening","undefined","watch","ignoreInitial","ignorePermissionErrors","usePolling","handleAnyFsEventDebounced","_","debounce","handleAnyFsEvent","on","stopListening","close","getCurrentValue","emitUpdate","exports"],"sources":["../../../../../src/Commons/TasksCore/FileValueProducer.ts"],"sourcesContent":["import { FSWatcher, watch } from \"chokidar\";\nimport _ from \"lodash\";\n\nimport { ObservableValueProducerBase } from \"./ChainableValueProducer\";\n\nexport class FileValueProducer extends ObservableValueProducerBase<string> {\n private readonly pathToFile: string;\n private watcher?: FSWatcher;\n\n public constructor(pathToFile: string) {\n super();\n this.pathToFile = pathToFile;\n }\n\n protected async beginListening(): Promise<void> {\n if (this.watcher != undefined) {\n return;\n }\n this.watcher = watch(this.pathToFile, {\n ignoreInitial: true,\n ignorePermissionErrors: false,\n usePolling: true,\n });\n const handleAnyFsEventDebounced = _.debounce(() => this.handleAnyFsEvent(), 1000);\n this.watcher.on(\"all\", handleAnyFsEventDebounced);\n this.watcher.on(\"error\", handleAnyFsEventDebounced);\n }\n\n protected async stopListening(): Promise<void> {\n if (this.watcher != undefined) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.watcher.close();\n }\n }\n\n protected async getCurrentValue(): Promise<string> {\n return this.pathToFile;\n }\n\n private async handleAnyFsEvent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ApB,iBAAA,GAAAA,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"FileValueProducer.js","names":["_chokidar","require","_lodash","_interopRequireDefault","_WellKnownDirectories","_ChainableValueProducer","_EventBus","FileValueProducer","ObservableValueProducerBase","constructor","pathToFile","watcher","beginListening","undefined","watch","ignoreInitial","ignorePermissionErrors","usePolling","handleAnyFsEventDebounced","_","debounce","event","handleAnyFsEvent","on","stopListening","close","getCurrentValue","includes","WellKnownDirectories","FormJsonFileName","eventBus","emit","FORM_REMOVE_EVENT","emitUpdate","exports"],"sources":["../../../../../src/Commons/TasksCore/FileValueProducer.ts"],"sourcesContent":["import { FSWatcher, watch } from \"chokidar\";\nimport _ from \"lodash\";\n\nimport { WellKnownDirectories } from \"../../../../Common/WellKnownDirectories\";\n\nimport { ObservableValueProducerBase } from \"./ChainableValueProducer\";\nimport { eventBus, FORM_REMOVE_EVENT } from \"./EventBus\";\n\ntype FsEvent = \"add\" | \"addDir\" | \"change\" | \"unlink\" | \"unlinkDir\";\n\nexport class FileValueProducer extends ObservableValueProducerBase<string> {\n private readonly pathToFile: string;\n private watcher?: FSWatcher;\n\n public constructor(pathToFile: string) {\n super();\n this.pathToFile = pathToFile;\n }\n\n protected async beginListening(): Promise<void> {\n if (this.watcher != undefined) {\n return;\n }\n this.watcher = watch(this.pathToFile, {\n ignoreInitial: true,\n ignorePermissionErrors: false,\n usePolling: true,\n });\n const handleAnyFsEventDebounced = _.debounce((event: FsEvent) => this.handleAnyFsEvent(event), 1000);\n this.watcher.on(\"all\", handleAnyFsEventDebounced);\n this.watcher.on(\"error\", handleAnyFsEventDebounced);\n }\n\n protected async stopListening(): Promise<void> {\n if (this.watcher != undefined) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.watcher.close();\n }\n }\n\n protected async getCurrentValue(): Promise<string> {\n return this.pathToFile;\n }\n\n private async handleAnyFsEvent(event: FsEvent): Promise<void> {\n if (event === \"unlink\" && this.pathToFile.includes(WellKnownDirectories.FormJsonF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