import { O as OPERATIONS$1 } from './paths-2M_UxD_H.js';
import './dist4-CiQ5cizO.js';
import 'crypto';
import 'path';

//#region ../runtime/dist/chunk-L5BLVQDA.js
var OPERATIONS = OPERATIONS$1;
function getCounts() {
	return {
		query: OPERATIONS.filter((o) => o.gateway === "query").length,
		mutate: OPERATIONS.filter((o) => o.gateway === "mutate").length,
		total: OPERATIONS.length
	};
}
var counts = getCounts();
if (counts.total !== OPERATIONS.length) console.warn(`[Registry] Operation count mismatch: total=${counts.total}, registry=${OPERATIONS.length}`);
//#endregion
//#region ../runtime/dist/chunk-U2ESNIJ5.js
var LF = "\n";
var RECORD_END = "\n\n";
function encodeSseFrame(frame) {
	let out = "";
	if (frame.event !== void 0) out += `event: ${frame.event}${LF}`;
	if (frame.id !== void 0) out += `id: ${frame.id}${LF}`;
	out += `data: ${JSON.stringify(frame.data)}${RECORD_END}`;
	return out;
}
function encodeStreamEvent(frame) {
	return encodeSseFrame({
		id: String(frame.seq),
		data: frame
	});
}
var SSE_HEADERS = Object.freeze({
	"Content-Type": "text/event-stream",
	"Cache-Control": "no-cache",
	Connection: "keep-alive",
	"X-Accel-Buffering": "no"
});
function createSseStream(source, signal) {
	const encoder = new TextEncoder();
	return new ReadableStream({ start(controller) {
		let closed = false;
		let teardown;
		let teardownDone = false;
		let sourceRunning = false;
		const onAbort = () => emitter.close();
		const runTeardown = () => {
			if (teardownDone) return;
			teardownDone = true;
			if (typeof teardown === "function") teardown();
		};
		const emitter = {
			get closed() {
				return closed;
			},
			send(frame) {
				if (closed) return;
				try {
					controller.enqueue(encoder.encode(encodeSseFrame(frame)));
				} catch {
					emitter.close();
				}
			},
			sendStreamEvent(frame) {
				if (closed) return;
				try {
					controller.enqueue(encoder.encode(encodeStreamEvent(frame)));
				} catch {
					emitter.close();
				}
			},
			sendRaw(record) {
				if (closed) return;
				try {
					controller.enqueue(encoder.encode(record));
				} catch {
					emitter.close();
				}
			},
			close() {
				if (closed) return;
				closed = true;
				if (signal) signal.removeEventListener("abort", onAbort);
				if (!sourceRunning) runTeardown();
				try {
					controller.close();
				} catch {}
			}
		};
		if (signal) {
			if (signal.aborted) {
				closed = true;
				teardownDone = true;
				try {
					controller.close();
				} catch {}
				return;
			}
			signal.addEventListener("abort", onAbort);
		}
		sourceRunning = true;
		const returned = source(emitter);
		teardown = typeof returned === "function" ? returned : void 0;
		sourceRunning = false;
		if (closed) runTeardown();
	} });
}

export { SSE_HEADERS as S, encodeStreamEvent as a, createSseStream as c, encodeSseFrame as e };
//# sourceMappingURL=http-CoxxIFTY.js.map
