const require_namespace = require("../namespace.cjs");
const require_runtime = require("./runtime.cjs");
//#region src/stream/projections/extension.ts
function extensionProjection(name, namespace) {
	const ns = [...namespace];
	return {
		key: `extension|${name}|${require_namespace.namespaceKey(ns)}`,
		namespace: ns,
		initial: void 0,
		open({ thread, store }) {
			return require_runtime.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
exports.extensionProjection = extensionProjection;

//# sourceMappingURL=extension.cjs.map