CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
splitLink-B7Cuf2c_.mjs47 linesDownload Raw Back to dist
1import { observable } from "@trpc/server/observable";2 3//#region src/links/internals/createChain.ts4/** @internal */5function createChain(opts) {6	return observable((observer) => {7		function execute(index = 0, op = opts.op) {8			const next = opts.links[index];9			if (!next) throw new Error("No more links to execute - did you forget to add an ending link?");10			const subscription = next({11				op,12				next(nextOp) {13					const nextObserver = execute(index + 1, nextOp);14					return nextObserver;15				}16			});17			return subscription;18		}19		const obs$ = execute();20		return obs$.subscribe(observer);21	});22}23 24//#endregion25//#region src/links/splitLink.ts26function asArray(value) {27	return Array.isArray(value) ? value : [value];28}29function splitLink(opts) {30	return (runtime) => {31		const yes = asArray(opts.true).map((link) => link(runtime));32		const no = asArray(opts.false).map((link) => link(runtime));33		return (props) => {34			return observable((observer) => {35				const links = opts.condition(props.op) ? yes : no;36				return createChain({37					op: props.op,38					links39				}).subscribe(observer);40			});41		};42	};43}44 45//#endregion46export { createChain, splitLink };47//# sourceMappingURL=splitLink-B7Cuf2c_.mjs.map