import { namespaceKey } from "../namespace.js";
import { openProjectionSubscription } from "./runtime.js";
//#region src/stream/projections/extension.ts
function extensionProjection(name, namespace) {
	const ns = [...namespace];
	return {
		key: `extension|${name}|${namespaceKey(ns)}`,
		namespace: ns,
		initial: void 0,
		open({ thread, store }) {
			return openProjectionSubscription({
				thread,
				channels: [`custom:${name}`],
				namespace: ns,
				resumeOnPause: true,
				onEvent(event) {
					const data = event.params.data;
					const payload = data?.payload != null && typeof data.payload === "object" && "name" in data.payload ? data.payload : data;
					if (payload?.name !== name) return;
					store.setValue(payload.payload);
				}
			});
		}
	};
}
//#endregion
export { extensionProjection };

//# sourceMappingURL=extension.js.map