globalThis.process ??= {};
globalThis.process.env ??= {};
import { $ as PgDateString, A as inArray, At as getTableUniqueName, B as uuid, C as asc, Ct as View, Dt as Schema, E as eq, Et as Columns, F as or, Ft as PgColumn, G as text, H as PgTimestampString, I as primaryKey, J as PgJsonb, K as PgNumeric, L as PgTable, Lt as Column, Mt as tracer, Nt as Subquery, Ot as Table, P as ne, Pt as WithSubquery, Q as PgDate, R as pgTable, Rt as entityKind, S as normalizeRelation, St as SQL, T as and, Tt as sql, U as timestamp, V as PgTimestamp, W as PgTime, X as PgJson, Y as jsonb, Z as integer, _ as createTableRelationsHelpers, _t as aliasedTable, a as TypedQueryBuilder, at as getTableLikeName, b as getOrderByOperators, bt as mapColumnsInSQLToAlias, c as uniqueIndex, ct as mapResultRow, dt as QueryPromise, et as boolean, f as getTransactionIdentity, ft as DefaultLogger, g as One, gt as TransactionRollbackError, h as Many, ht as DrizzleQueryError, i as hashQuery, it as getTableColumns, jt as ViewBaseConfig, kt as getTableName, l as SelectionProxyHandler, lt as mapUpdateSet, mt as DrizzleError, o as CasingCache, ot as haveSameKeys, pt as NoopLogger, r as NoopCache, rt as applyMixins, s as index, st as isConfig, tt as bigserial, u as check, ut as orderSelectedFields, v as extractTablesRelationalConfig, vt as aliasedTableColumn, w as desc, wt as fillPlaceholders, x as mapRelationalRow, xt as Param, y as getOperators, yt as mapColumnsInAliasedSQLToAlias, z as PgUUID, zt as is$1 } from "./d1_DTqC4o_t.mjs";
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/sql/functions/aggregate.js
function count(expression) {
	return sql`count(${expression || sql.raw("*")})`.mapWith(Number);
}
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/view-base.js
var PgViewBase = class extends View {
	static [entityKind] = "PgViewBase";
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/dialect.js
var PgDialect = class {
	static [entityKind] = "PgDialect";
	/** @internal */
	casing;
	constructor(config) {
		this.casing = new CasingCache(config?.casing);
	}
	async migrate(migrations, session, config) {
		const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
		const migrationsSchema = typeof config === "string" ? "drizzle" : config.migrationsSchema ?? "drizzle";
		const migrationTableCreate = sql`
			CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} (
				id SERIAL PRIMARY KEY,
				hash text NOT NULL,
				created_at bigint
			)
		`;
		await session.execute(sql`CREATE SCHEMA IF NOT EXISTS ${sql.identifier(migrationsSchema)}`);
		await session.execute(migrationTableCreate);
		const lastDbMigration = (await session.all(sql`select id, hash, created_at from ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} order by created_at desc limit 1`))[0];
		await session.transaction(async (tx) => {
			for await (const migration of migrations) if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
				for (const stmt of migration.sql) await tx.execute(sql.raw(stmt));
				await tx.execute(sql`insert into ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`);
			}
		});
	}
	escapeName(name) {
		return `"${name.replace(/"/g, "\"\"")}"`;
	}
	escapeParam(num) {
		return `$${num + 1}`;
	}
	escapeString(str) {
		return `'${str.replace(/'/g, "''")}'`;
	}
	buildWithCTE(queries) {
		if (!queries?.length) return void 0;
		const withSqlChunks = [sql`with `];
		for (const [i, w] of queries.entries()) {
			withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
			if (i < queries.length - 1) withSqlChunks.push(sql`, `);
		}
		withSqlChunks.push(sql` `);
		return sql.join(withSqlChunks);
	}
	buildDeleteQuery({ table, where, returning, withList }) {
		const withSql = this.buildWithCTE(withList);
		const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
		const whereSql = where ? sql` where ${where}` : void 0;
		return sql`${withSql}delete from ${table}${whereSql}${returningSql}`;
	}
	buildUpdateSet(table, set) {
		const tableColumns = table[Table.Symbol.Columns];
		const columnNames = Object.keys(tableColumns).filter((colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0);
		const setSize = columnNames.length;
		return sql.join(columnNames.flatMap((colName, i) => {
			const col = tableColumns[colName];
			const onUpdateFnResult = col.onUpdateFn?.();
			const value = set[colName] ?? (is$1(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
			const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
			if (i < setSize - 1) return [res, sql.raw(", ")];
			return [res];
		}));
	}
	buildUpdateQuery({ table, set, where, returning, withList, from, joins }) {
		const withSql = this.buildWithCTE(withList);
		const tableName = table[PgTable.Symbol.Name];
		const tableSchema = table[PgTable.Symbol.Schema];
		const origTableName = table[PgTable.Symbol.OriginalName];
		const alias = tableName === origTableName ? void 0 : tableName;
		const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
		const setSql = this.buildUpdateSet(table, set);
		const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
		const joinsSql = this.buildJoins(joins);
		const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
		const whereSql = where ? sql` where ${where}` : void 0;
		return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
	}
	/**
	* Builds selection SQL with provided fields/expressions
	*
	* Examples:
	*
	* `select <selection> from`
	*
	* `insert ... returning <selection>`
	*
	* If `isSingleTable` is true, then columns won't be prefixed with table name
	*/
	buildSelection(fields, { isSingleTable = false } = {}) {
		const columnsLen = fields.length;
		const chunks = fields.flatMap(({ field }, i) => {
			const chunk = [];
			if (is$1(field, SQL.Aliased) && field.isSelectionField) chunk.push(sql.identifier(field.fieldAlias));
			else if (is$1(field, SQL.Aliased) || is$1(field, SQL)) {
				const query = is$1(field, SQL.Aliased) ? field.sql : field;
				if (isSingleTable) chunk.push(new SQL(query.queryChunks.map((c) => {
					if (is$1(c, PgColumn)) return sql.identifier(this.casing.getColumnCasing(c));
					return c;
				})));
				else chunk.push(query);
				if (is$1(field, SQL.Aliased)) chunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);
			} else if (is$1(field, Column)) {
				if (isSingleTable) chunk.push(sql.identifier(this.casing.getColumnCasing(field)));
				else chunk.push(field);
			} else if (is$1(field, Subquery)) {
				const entries = Object.entries(field._.selectedFields);
				if (entries.length === 1) {
					const entry = entries[0][1];
					const fieldDecoder = is$1(entry, SQL) ? entry.decoder : is$1(entry, Column) ? { mapFromDriverValue: (v) => entry.mapFromDriverValue(v) } : entry.sql.decoder;
					if (fieldDecoder) field._.sql.decoder = fieldDecoder;
				}
				chunk.push(field);
			}
			if (i < columnsLen - 1) chunk.push(sql`, `);
			return chunk;
		});
		return sql.join(chunks);
	}
	buildJoins(joins) {
		if (!joins || joins.length === 0) return;
		const joinsArray = [];
		for (const [index, joinMeta] of joins.entries()) {
			if (index === 0) joinsArray.push(sql` `);
			const table = joinMeta.table;
			const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
			const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
			if (is$1(table, PgTable)) {
				const tableName = table[PgTable.Symbol.Name];
				const tableSchema = table[PgTable.Symbol.Schema];
				const origTableName = table[PgTable.Symbol.OriginalName];
				const alias = tableName === origTableName ? void 0 : joinMeta.alias;
				joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
			} else if (is$1(table, View)) {
				const viewName = table[ViewBaseConfig].name;
				const viewSchema = table[ViewBaseConfig].schema;
				const origViewName = table[ViewBaseConfig].originalName;
				const alias = viewName === origViewName ? void 0 : joinMeta.alias;
				joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : void 0}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
			} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`);
			if (index < joins.length - 1) joinsArray.push(sql` `);
		}
		return sql.join(joinsArray);
	}
	buildFromTable(table) {
		if (is$1(table, Table) && table[Table.Symbol.IsAlias]) {
			let fullName = sql`${sql.identifier(table[Table.Symbol.OriginalName])}`;
			if (table[Table.Symbol.Schema]) fullName = sql`${sql.identifier(table[Table.Symbol.Schema])}.${fullName}`;
			return sql`${fullName} ${sql.identifier(table[Table.Symbol.Name])}`;
		}
		return table;
	}
	buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, lockingClause, distinct, setOperators }) {
		const fieldsList = fieldsFlat ?? orderSelectedFields(fields);
		for (const f of fieldsList) if (is$1(f.field, Column) && getTableName(f.field.table) !== (is$1(table, Subquery) ? table._.alias : is$1(table, PgViewBase) ? table[ViewBaseConfig].name : is$1(table, SQL) ? void 0 : getTableName(table)) && !((table2) => joins?.some(({ alias }) => alias === (table2[Table.Symbol.IsAlias] ? getTableName(table2) : table2[Table.Symbol.BaseName])))(f.field.table)) {
			const tableName = getTableName(f.field.table);
			throw new Error(`Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`);
		}
		const isSingleTable = !joins || joins.length === 0;
		const withSql = this.buildWithCTE(withList);
		let distinctSql;
		if (distinct) distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
		const selection = this.buildSelection(fieldsList, { isSingleTable });
		const tableSql = this.buildFromTable(table);
		const joinsSql = this.buildJoins(joins);
		const whereSql = where ? sql` where ${where}` : void 0;
		const havingSql = having ? sql` having ${having}` : void 0;
		let orderBySql;
		if (orderBy && orderBy.length > 0) orderBySql = sql` order by ${sql.join(orderBy, sql`, `)}`;
		let groupBySql;
		if (groupBy && groupBy.length > 0) groupBySql = sql` group by ${sql.join(groupBy, sql`, `)}`;
		const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
		const offsetSql = offset ? sql` offset ${offset}` : void 0;
		const lockingClauseSql = sql.empty();
		if (lockingClause) {
			const clauseSql = sql` for ${sql.raw(lockingClause.strength)}`;
			if (lockingClause.config.of) clauseSql.append(sql` of ${sql.join(Array.isArray(lockingClause.config.of) ? lockingClause.config.of : [lockingClause.config.of], sql`, `)}`);
			if (lockingClause.config.noWait) clauseSql.append(sql` nowait`);
			else if (lockingClause.config.skipLocked) clauseSql.append(sql` skip locked`);
			lockingClauseSql.append(clauseSql);
		}
		const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClauseSql}`;
		if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
		return finalQuery;
	}
	buildSetOperations(leftSelect, setOperators) {
		const [setOperator, ...rest] = setOperators;
		if (!setOperator) throw new Error("Cannot pass undefined values to any set operator");
		if (rest.length === 0) return this.buildSetOperationQuery({
			leftSelect,
			setOperator
		});
		return this.buildSetOperations(this.buildSetOperationQuery({
			leftSelect,
			setOperator
		}), rest);
	}
	buildSetOperationQuery({ leftSelect, setOperator: { type, isAll, rightSelect, limit, orderBy, offset } }) {
		const leftChunk = sql`(${leftSelect.getSQL()}) `;
		const rightChunk = sql`(${rightSelect.getSQL()})`;
		let orderBySql;
		if (orderBy && orderBy.length > 0) {
			const orderByValues = [];
			for (const singleOrderBy of orderBy) if (is$1(singleOrderBy, PgColumn)) orderByValues.push(sql.identifier(singleOrderBy.name));
			else if (is$1(singleOrderBy, SQL)) {
				for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
					const chunk = singleOrderBy.queryChunks[i];
					if (is$1(chunk, PgColumn)) singleOrderBy.queryChunks[i] = sql.identifier(chunk.name);
				}
				orderByValues.push(sql`${singleOrderBy}`);
			} else orderByValues.push(sql`${singleOrderBy}`);
			orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;
		}
		const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
		const operatorChunk = sql.raw(`${type} ${isAll ? "all " : ""}`);
		const offsetSql = offset ? sql` offset ${offset}` : void 0;
		return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
	}
	buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
		const valuesSqlList = [];
		const columns = table[Table.Symbol.Columns];
		const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
		const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
		if (select) {
			const select2 = valuesOrSelect;
			if (is$1(select2, SQL)) valuesSqlList.push(select2);
			else valuesSqlList.push(select2.getSQL());
		} else {
			const values = valuesOrSelect;
			valuesSqlList.push(sql.raw("values "));
			for (const [valueIndex, value] of values.entries()) {
				const valueList = [];
				for (const [fieldName, col] of colEntries) {
					const colValue = value[fieldName];
					if (colValue === void 0 || is$1(colValue, Param) && colValue.value === void 0) {
						if (col.defaultFn !== void 0) {
							const defaultFnResult = col.defaultFn();
							const defaultValue = is$1(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
							valueList.push(defaultValue);
						} else if (!col.default && col.onUpdateFn !== void 0) {
							const onUpdateFnResult = col.onUpdateFn();
							const newValue = is$1(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
							valueList.push(newValue);
						} else valueList.push(sql`default`);
					} else valueList.push(colValue);
				}
				valuesSqlList.push(valueList);
				if (valueIndex < values.length - 1) valuesSqlList.push(sql`, `);
			}
		}
		const withSql = this.buildWithCTE(withList);
		const valuesSql = sql.join(valuesSqlList);
		const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
		const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
		const overridingSql = overridingSystemValue_ === true ? sql`overriding system value ` : void 0;
		return sql`${withSql}insert into ${table} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
	}
	buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
		const concurrentlySql = concurrently ? sql` concurrently` : void 0;
		const withNoDataSql = withNoData ? sql` with no data` : void 0;
		return sql`refresh materialized view${concurrentlySql} ${view}${withNoDataSql}`;
	}
	prepareTyping(encoder) {
		if (is$1(encoder, PgJsonb) || is$1(encoder, PgJson)) return "json";
		else if (is$1(encoder, PgNumeric)) return "decimal";
		else if (is$1(encoder, PgTime)) return "time";
		else if (is$1(encoder, PgTimestamp) || is$1(encoder, PgTimestampString)) return "timestamp";
		else if (is$1(encoder, PgDate) || is$1(encoder, PgDateString)) return "date";
		else if (is$1(encoder, PgUUID)) return "uuid";
		else return "none";
	}
	sqlToQuery(sql2, invokeSource) {
		return sql2.toQuery({
			casing: this.casing,
			escapeName: this.escapeName,
			escapeParam: this.escapeParam,
			escapeString: this.escapeString,
			prepareTyping: this.prepareTyping,
			invokeSource
		});
	}
	buildRelationalQueryWithoutPK({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn }) {
		let selection = [];
		let limit, offset, orderBy = [], where;
		const joins = [];
		if (config === true) selection = Object.entries(tableConfig.columns).map(([key, value]) => ({
			dbKey: value.name,
			tsKey: key,
			field: aliasedTableColumn(value, tableAlias),
			relationTableTsKey: void 0,
			isJson: false,
			selection: []
		}));
		else {
			const aliasedColumns = Object.fromEntries(Object.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]));
			if (config.where) {
				const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, getOperators()) : config.where;
				where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
			}
			const fieldsSelection = [];
			let selectedColumns = [];
			if (config.columns) {
				let isIncludeMode = false;
				for (const [field, value] of Object.entries(config.columns)) {
					if (value === void 0) continue;
					if (field in tableConfig.columns) {
						if (!isIncludeMode && value === true) isIncludeMode = true;
						selectedColumns.push(field);
					}
				}
				if (selectedColumns.length > 0) selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
			} else selectedColumns = Object.keys(tableConfig.columns);
			for (const field of selectedColumns) {
				const column = tableConfig.columns[field];
				fieldsSelection.push({
					tsKey: field,
					value: column
				});
			}
			let selectedRelations = [];
			if (config.with) selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({
				tsKey,
				queryConfig,
				relation: tableConfig.relations[tsKey]
			}));
			let extras;
			if (config.extras) {
				extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql }) : config.extras;
				for (const [tsKey, value] of Object.entries(extras)) fieldsSelection.push({
					tsKey,
					value: mapColumnsInAliasedSQLToAlias(value, tableAlias)
				});
			}
			for (const { tsKey, value } of fieldsSelection) selection.push({
				dbKey: is$1(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name,
				tsKey,
				field: is$1(value, Column) ? aliasedTableColumn(value, tableAlias) : value,
				relationTableTsKey: void 0,
				isJson: false,
				selection: []
			});
			let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, getOrderByOperators()) : config.orderBy ?? [];
			if (!Array.isArray(orderByOrig)) orderByOrig = [orderByOrig];
			orderBy = orderByOrig.map((orderByValue) => {
				if (is$1(orderByValue, Column)) return aliasedTableColumn(orderByValue, tableAlias);
				return mapColumnsInSQLToAlias(orderByValue, tableAlias);
			});
			limit = config.limit;
			offset = config.offset;
			for (const { tsKey: selectedRelationTsKey, queryConfig: selectedRelationConfigValue, relation } of selectedRelations) {
				const normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);
				const relationTableTsName = tableNamesMap[getTableUniqueName(relation.referencedTable)];
				const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;
				const joinOn2 = and(...normalizedRelation.fields.map((field2, i) => eq(aliasedTableColumn(normalizedRelation.references[i], relationTableAlias), aliasedTableColumn(field2, tableAlias))));
				const builtRelation = this.buildRelationalQueryWithoutPK({
					fullSchema,
					schema,
					tableNamesMap,
					table: fullSchema[relationTableTsName],
					tableConfig: schema[relationTableTsName],
					queryConfig: is$1(relation, One) ? selectedRelationConfigValue === true ? { limit: 1 } : {
						...selectedRelationConfigValue,
						limit: 1
					} : selectedRelationConfigValue,
					tableAlias: relationTableAlias,
					joinOn: joinOn2,
					nestedQueryRelation: relation
				});
				const field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier("data")}`.as(selectedRelationTsKey);
				joins.push({
					on: sql`true`,
					table: new Subquery(builtRelation.sql, {}, relationTableAlias),
					alias: relationTableAlias,
					joinType: "left",
					lateral: true
				});
				selection.push({
					dbKey: selectedRelationTsKey,
					tsKey: selectedRelationTsKey,
					field,
					relationTableTsKey: relationTableTsName,
					isJson: true,
					selection: builtRelation.selection
				});
			}
		}
		if (selection.length === 0) throw new DrizzleError({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}")` });
		let result;
		where = and(joinOn, where);
		if (nestedQueryRelation) {
			let field = sql`json_build_array(${sql.join(selection.map(({ field: field2, tsKey, isJson }) => isJson ? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier("data")}` : is$1(field2, SQL.Aliased) ? field2.sql : field2), sql`, `)})`;
			if (is$1(nestedQueryRelation, Many)) field = sql`coalesce(json_agg(${field}${orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0}), '[]'::json)`;
			const nestedSelection = [{
				dbKey: "data",
				tsKey: "data",
				field: field.as("data"),
				isJson: true,
				relationTableTsKey: tableConfig.tsName,
				selection
			}];
			if (limit !== void 0 || offset !== void 0 || orderBy.length > 0) {
				result = this.buildSelectQuery({
					table: aliasedTable(table, tableAlias),
					fields: {},
					fieldsFlat: [{
						path: [],
						field: sql.raw("*")
					}],
					where,
					limit,
					offset,
					orderBy,
					setOperators: []
				});
				where = void 0;
				limit = void 0;
				offset = void 0;
				orderBy = [];
			} else result = aliasedTable(table, tableAlias);
			result = this.buildSelectQuery({
				table: is$1(result, PgTable) ? result : new Subquery(result, {}, tableAlias),
				fields: {},
				fieldsFlat: nestedSelection.map(({ field: field2 }) => ({
					path: [],
					field: is$1(field2, Column) ? aliasedTableColumn(field2, tableAlias) : field2
				})),
				joins,
				where,
				limit,
				offset,
				orderBy,
				setOperators: []
			});
		} else result = this.buildSelectQuery({
			table: aliasedTable(table, tableAlias),
			fields: {},
			fieldsFlat: selection.map(({ field }) => ({
				path: [],
				field: is$1(field, Column) ? aliasedTableColumn(field, tableAlias) : field
			})),
			joins,
			where,
			limit,
			offset,
			orderBy,
			setOperators: []
		});
		return {
			tableTsKey: tableConfig.tsName,
			sql: result,
			selection
		};
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/select.js
var PgSelectBuilder = class {
	static [entityKind] = "PgSelectBuilder";
	fields;
	session;
	dialect;
	withList = [];
	distinct;
	constructor(config) {
		this.fields = config.fields;
		this.session = config.session;
		this.dialect = config.dialect;
		if (config.withList) this.withList = config.withList;
		this.distinct = config.distinct;
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	/**
	* Specify the table, subquery, or other target that you're
	* building a select query against.
	*
	* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM | Postgres from documentation}
	*/
	from(source) {
		const isPartialSelect = !!this.fields;
		const src = source;
		let fields;
		if (this.fields) fields = this.fields;
		else if (is$1(src, Subquery)) fields = Object.fromEntries(Object.keys(src._.selectedFields).map((key) => [key, src[key]]));
		else if (is$1(src, PgViewBase)) fields = src[ViewBaseConfig].selectedFields;
		else if (is$1(src, SQL)) fields = {};
		else fields = getTableColumns(src);
		return new PgSelectBase({
			table: src,
			fields,
			isPartialSelect,
			session: this.session,
			dialect: this.dialect,
			withList: this.withList,
			distinct: this.distinct
		}).setToken(this.authToken);
	}
};
var PgSelectQueryBuilderBase = class extends TypedQueryBuilder {
	static [entityKind] = "PgSelectQueryBuilder";
	_;
	config;
	joinsNotNullableMap;
	tableName;
	isPartialSelect;
	session;
	dialect;
	cacheConfig = void 0;
	usedTables = /* @__PURE__ */ new Set();
	constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) {
		super();
		this.config = {
			withList,
			table,
			fields: { ...fields },
			distinct,
			setOperators: []
		};
		this.isPartialSelect = isPartialSelect;
		this.session = session;
		this.dialect = dialect;
		this._ = {
			selectedFields: fields,
			config: this.config
		};
		this.tableName = getTableLikeName(table);
		this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
		for (const item of extractUsedTable(table)) this.usedTables.add(item);
	}
	/** @internal */
	getUsedTables() {
		return [...this.usedTables];
	}
	createJoin(joinType, lateral) {
		return (table, on) => {
			const baseTableName = this.tableName;
			const tableName = getTableLikeName(table);
			for (const item of extractUsedTable(table)) this.usedTables.add(item);
			if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
			if (!this.isPartialSelect) {
				if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
				if (typeof tableName === "string" && !is$1(table, SQL)) {
					const selection = is$1(table, Subquery) ? table._.selectedFields : is$1(table, View) ? table[ViewBaseConfig].selectedFields : table[Table.Symbol.Columns];
					this.config.fields[tableName] = selection;
				}
			}
			if (typeof on === "function") on = on(new Proxy(this.config.fields, new SelectionProxyHandler({
				sqlAliasedBehavior: "sql",
				sqlBehavior: "sql"
			})));
			if (!this.config.joins) this.config.joins = [];
			this.config.joins.push({
				on,
				table,
				joinType,
				alias: tableName,
				lateral
			});
			if (typeof tableName === "string") switch (joinType) {
				case "left":
					this.joinsNotNullableMap[tableName] = false;
					break;
				case "right":
					this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
					this.joinsNotNullableMap[tableName] = true;
					break;
				case "cross":
				case "inner":
					this.joinsNotNullableMap[tableName] = true;
					break;
				case "full":
					this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
					this.joinsNotNullableMap[tableName] = false;
			}
			return this;
		};
	}
	/**
	* Executes a `left join` operation by adding another table to the current query.
	*
	* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
	*
	* @param table the table to join.
	* @param on the `on` clause.
	*
	* @example
	*
	* ```ts
	* // Select all users and their pets
	* const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
	*   .from(users)
	*   .leftJoin(pets, eq(users.id, pets.ownerId))
	*
	* // Select userId and petId
	* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
	*   userId: users.id,
	*   petId: pets.id,
	* })
	*   .from(users)
	*   .leftJoin(pets, eq(users.id, pets.ownerId))
	* ```
	*/
	leftJoin = this.createJoin("left", false);
	/**
	* Executes a `left join lateral` operation by adding subquery to the current query.
	*
	* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
	*
	* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}
	*
	* @param table the subquery to join.
	* @param on the `on` clause.
	*/
	leftJoinLateral = this.createJoin("left", true);
	/**
	* Executes a `right join` operation by adding another table to the current query.
	*
	* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
	*
	* @param table the table to join.
	* @param on the `on` clause.
	*
	* @example
	*
	* ```ts
	* // Select all users and their pets
	* const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
	*   .from(users)
	*   .rightJoin(pets, eq(users.id, pets.ownerId))
	*
	* // Select userId and petId
	* const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
	*   userId: users.id,
	*   petId: pets.id,
	* })
	*   .from(users)
	*   .rightJoin(pets, eq(users.id, pets.ownerId))
	* ```
	*/
	rightJoin = this.createJoin("right", false);
	/**
	* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
	*
	* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
	*
	* @param table the table to join.
	* @param on the `on` clause.
	*
	* @example
	*
	* ```ts
	* // Select all users and their pets
	* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
	*   .from(users)
	*   .innerJoin(pets, eq(users.id, pets.ownerId))
	*
	* // Select userId and petId
	* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
	*   userId: users.id,
	*   petId: pets.id,
	* })
	*   .from(users)
	*   .innerJoin(pets, eq(users.id, pets.ownerId))
	* ```
	*/
	innerJoin = this.createJoin("inner", false);
	/**
	* Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.
	*
	* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
	*
	* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}
	*
	* @param table the subquery to join.
	* @param on the `on` clause.
	*/
	innerJoinLateral = this.createJoin("inner", true);
	/**
	* Executes a `full join` operation by combining rows from two tables into a new table.
	*
	* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
	*
	* @param table the table to join.
	* @param on the `on` clause.
	*
	* @example
	*
	* ```ts
	* // Select all users and their pets
	* const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
	*   .from(users)
	*   .fullJoin(pets, eq(users.id, pets.ownerId))
	*
	* // Select userId and petId
	* const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
	*   userId: users.id,
	*   petId: pets.id,
	* })
	*   .from(users)
	*   .fullJoin(pets, eq(users.id, pets.ownerId))
	* ```
	*/
	fullJoin = this.createJoin("full", false);
	/**
	* Executes a `cross join` operation by combining rows from two tables into a new table.
	*
	* Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
	*
	* @param table the table to join.
	*
	* @example
	*
	* ```ts
	* // Select all users, each user with every pet
	* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
	*   .from(users)
	*   .crossJoin(pets)
	*
	* // Select userId and petId
	* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
	*   userId: users.id,
	*   petId: pets.id,
	* })
	*   .from(users)
	*   .crossJoin(pets)
	* ```
	*/
	crossJoin = this.createJoin("cross", false);
	/**
	* Executes a `cross join lateral` operation by combining rows from two queries into a new table.
	*
	* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
	*
	* Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.
	*
	* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}
	*
	* @param table the query to join.
	*/
	crossJoinLateral = this.createJoin("cross", true);
	createSetOperator(type, isAll) {
		return (rightSelection) => {
			const rightSelect = typeof rightSelection === "function" ? rightSelection(getPgSetOperators()) : rightSelection;
			if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
			this.config.setOperators.push({
				type,
				isAll,
				rightSelect
			});
			return this;
		};
	}
	/**
	* Adds `union` set operator to the query.
	*
	* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
	*
	* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
	*
	* @example
	*
	* ```ts
	* // Select all unique names from customers and users tables
	* await db.select({ name: users.name })
	*   .from(users)
	*   .union(
	*     db.select({ name: customers.name }).from(customers)
	*   );
	* // or
	* import { union } from 'drizzle-orm/pg-core'
	*
	* await union(
	*   db.select({ name: users.name }).from(users),
	*   db.select({ name: customers.name }).from(customers)
	* );
	* ```
	*/
	union = this.createSetOperator("union", false);
	/**
	* Adds `union all` set operator to the query.
	*
	* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
	*
	* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
	*
	* @example
	*
	* ```ts
	* // Select all transaction ids from both online and in-store sales
	* await db.select({ transaction: onlineSales.transactionId })
	*   .from(onlineSales)
	*   .unionAll(
	*     db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
	*   );
	* // or
	* import { unionAll } from 'drizzle-orm/pg-core'
	*
	* await unionAll(
	*   db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
	*   db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
	* );
	* ```
	*/
	unionAll = this.createSetOperator("union", true);
	/**
	* Adds `intersect` set operator to the query.
	*
	* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
	*
	* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
	*
	* @example
	*
	* ```ts
	* // Select course names that are offered in both departments A and B
	* await db.select({ courseName: depA.courseName })
	*   .from(depA)
	*   .intersect(
	*     db.select({ courseName: depB.courseName }).from(depB)
	*   );
	* // or
	* import { intersect } from 'drizzle-orm/pg-core'
	*
	* await intersect(
	*   db.select({ courseName: depA.courseName }).from(depA),
	*   db.select({ courseName: depB.courseName }).from(depB)
	* );
	* ```
	*/
	intersect = this.createSetOperator("intersect", false);
	/**
	* Adds `intersect all` set operator to the query.
	*
	* Calling this method will retain only the rows that are present in both result sets including all duplicates.
	*
	* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
	*
	* @example
	*
	* ```ts
	* // Select all products and quantities that are ordered by both regular and VIP customers
	* await db.select({
	*   productId: regularCustomerOrders.productId,
	*   quantityOrdered: regularCustomerOrders.quantityOrdered
	* })
	* .from(regularCustomerOrders)
	* .intersectAll(
	*   db.select({
	*     productId: vipCustomerOrders.productId,
	*     quantityOrdered: vipCustomerOrders.quantityOrdered
	*   })
	*   .from(vipCustomerOrders)
	* );
	* // or
	* import { intersectAll } from 'drizzle-orm/pg-core'
	*
	* await intersectAll(
	*   db.select({
	*     productId: regularCustomerOrders.productId,
	*     quantityOrdered: regularCustomerOrders.quantityOrdered
	*   })
	*   .from(regularCustomerOrders),
	*   db.select({
	*     productId: vipCustomerOrders.productId,
	*     quantityOrdered: vipCustomerOrders.quantityOrdered
	*   })
	*   .from(vipCustomerOrders)
	* );
	* ```
	*/
	intersectAll = this.createSetOperator("intersect", true);
	/**
	* Adds `except` set operator to the query.
	*
	* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
	*
	* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
	*
	* @example
	*
	* ```ts
	* // Select all courses offered in department A but not in department B
	* await db.select({ courseName: depA.courseName })
	*   .from(depA)
	*   .except(
	*     db.select({ courseName: depB.courseName }).from(depB)
	*   );
	* // or
	* import { except } from 'drizzle-orm/pg-core'
	*
	* await except(
	*   db.select({ courseName: depA.courseName }).from(depA),
	*   db.select({ courseName: depB.courseName }).from(depB)
	* );
	* ```
	*/
	except = this.createSetOperator("except", false);
	/**
	* Adds `except all` set operator to the query.
	*
	* Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.
	*
	* See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
	*
	* @example
	*
	* ```ts
	* // Select all products that are ordered by regular customers but not by VIP customers
	* await db.select({
	*   productId: regularCustomerOrders.productId,
	*   quantityOrdered: regularCustomerOrders.quantityOrdered,
	* })
	* .from(regularCustomerOrders)
	* .exceptAll(
	*   db.select({
	*     productId: vipCustomerOrders.productId,
	*     quantityOrdered: vipCustomerOrders.quantityOrdered,
	*   })
	*   .from(vipCustomerOrders)
	* );
	* // or
	* import { exceptAll } from 'drizzle-orm/pg-core'
	*
	* await exceptAll(
	*   db.select({
	*     productId: regularCustomerOrders.productId,
	*     quantityOrdered: regularCustomerOrders.quantityOrdered
	*   })
	*   .from(regularCustomerOrders),
	*   db.select({
	*     productId: vipCustomerOrders.productId,
	*     quantityOrdered: vipCustomerOrders.quantityOrdered
	*   })
	*   .from(vipCustomerOrders)
	* );
	* ```
	*/
	exceptAll = this.createSetOperator("except", true);
	/** @internal */
	addSetOperators(setOperators) {
		this.config.setOperators.push(...setOperators);
		return this;
	}
	/**
	* Adds a `where` clause to the query.
	*
	* Calling this method will select only those rows that fulfill a specified condition.
	*
	* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
	*
	* @param where the `where` clause.
	*
	* @example
	* You can use conditional operators and `sql function` to filter the rows to be selected.
	*
	* ```ts
	* // Select all cars with green color
	* await db.select().from(cars).where(eq(cars.color, 'green'));
	* // or
	* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
	* ```
	*
	* You can logically combine conditional operators with `and()` and `or()` operators:
	*
	* ```ts
	* // Select all BMW cars with a green color
	* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
	*
	* // Select all cars with the green or blue color
	* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
	* ```
	*/
	where(where) {
		if (typeof where === "function") where = where(new Proxy(this.config.fields, new SelectionProxyHandler({
			sqlAliasedBehavior: "sql",
			sqlBehavior: "sql"
		})));
		this.config.where = where;
		return this;
	}
	/**
	* Adds a `having` clause to the query.
	*
	* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
	*
	* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
	*
	* @param having the `having` clause.
	*
	* @example
	*
	* ```ts
	* // Select all brands with more than one car
	* await db.select({
	* 	brand: cars.brand,
	* 	count: sql<number>`cast(count(${cars.id}) as int)`,
	* })
	*   .from(cars)
	*   .groupBy(cars.brand)
	*   .having(({ count }) => gt(count, 1));
	* ```
	*/
	having(having) {
		if (typeof having === "function") having = having(new Proxy(this.config.fields, new SelectionProxyHandler({
			sqlAliasedBehavior: "sql",
			sqlBehavior: "sql"
		})));
		this.config.having = having;
		return this;
	}
	groupBy(...columns) {
		if (typeof columns[0] === "function") {
			const groupBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({
				sqlAliasedBehavior: "alias",
				sqlBehavior: "sql"
			})));
			this.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];
		} else this.config.groupBy = columns;
		return this;
	}
	orderBy(...columns) {
		if (typeof columns[0] === "function") {
			const orderBy = columns[0](new Proxy(this.config.fields, new SelectionProxyHandler({
				sqlAliasedBehavior: "alias",
				sqlBehavior: "sql"
			})));
			const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
			if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).orderBy = orderByArray;
			else this.config.orderBy = orderByArray;
		} else {
			const orderByArray = columns;
			if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).orderBy = orderByArray;
			else this.config.orderBy = orderByArray;
		}
		return this;
	}
	/**
	* Adds a `limit` clause to the query.
	*
	* Calling this method will set the maximum number of rows that will be returned by this query.
	*
	* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
	*
	* @param limit the `limit` clause.
	*
	* @example
	*
	* ```ts
	* // Get the first 10 people from this query.
	* await db.select().from(people).limit(10);
	* ```
	*/
	limit(limit) {
		if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).limit = limit;
		else this.config.limit = limit;
		return this;
	}
	/**
	* Adds an `offset` clause to the query.
	*
	* Calling this method will skip a number of rows when returning results from this query.
	*
	* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
	*
	* @param offset the `offset` clause.
	*
	* @example
	*
	* ```ts
	* // Get the 10th-20th people from this query.
	* await db.select().from(people).offset(10).limit(10);
	* ```
	*/
	offset(offset) {
		if (this.config.setOperators.length > 0) this.config.setOperators.at(-1).offset = offset;
		else this.config.offset = offset;
		return this;
	}
	/**
	* Adds a `for` clause to the query.
	*
	* Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.
	*
	* See docs: {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE}
	*
	* @param strength the lock strength.
	* @param config the lock configuration.
	*/
	for(strength, config = {}) {
		this.config.lockingClause = {
			strength,
			config
		};
		return this;
	}
	/** @internal */
	getSQL() {
		return this.dialect.buildSelectQuery(this.config);
	}
	toSQL() {
		const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
		return rest;
	}
	as(alias) {
		const usedTables = [];
		usedTables.push(...extractUsedTable(this.config.table));
		if (this.config.joins) for (const it of this.config.joins) usedTables.push(...extractUsedTable(it.table));
		return new Proxy(new Subquery(this.getSQL(), this.config.fields, alias, false, [...new Set(usedTables)]), new SelectionProxyHandler({
			alias,
			sqlAliasedBehavior: "alias",
			sqlBehavior: "error"
		}));
	}
	/** @internal */
	getSelectedFields() {
		return new Proxy(this.config.fields, new SelectionProxyHandler({
			alias: this.tableName,
			sqlAliasedBehavior: "alias",
			sqlBehavior: "error"
		}));
	}
	$dynamic() {
		return this;
	}
	$withCache(config) {
		this.cacheConfig = config === void 0 ? {
			config: {},
			enable: true,
			autoInvalidate: true
		} : config === false ? { enable: false } : {
			enable: true,
			autoInvalidate: true,
			...config
		};
		return this;
	}
};
var PgSelectBase = class extends PgSelectQueryBuilderBase {
	static [entityKind] = "PgSelect";
	/** @internal */
	_prepare(name) {
		const { session, config, dialect, joinsNotNullableMap, authToken, cacheConfig, usedTables } = this;
		if (!session) throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
		const { fields } = config;
		return tracer.startActiveSpan("drizzle.prepareQuery", () => {
			const fieldsList = orderSelectedFields(fields);
			const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true, void 0, {
				type: "select",
				tables: [...usedTables]
			}, cacheConfig);
			query.joinsNotNullableMap = joinsNotNullableMap;
			return query.setToken(authToken);
		});
	}
	/**
	* Create a prepared statement for this query. This allows
	* the database to remember this query for the given session
	* and call it by name, rather than specifying the full query.
	*
	* {@link https://www.postgresql.org/docs/current/sql-prepare.html | Postgres prepare documentation}
	*/
	prepare(name) {
		return this._prepare(name);
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	execute = (placeholderValues) => {
		return tracer.startActiveSpan("drizzle.operation", () => {
			return this._prepare().execute(placeholderValues, this.authToken);
		});
	};
};
applyMixins(PgSelectBase, [QueryPromise]);
function createSetOperator(type, isAll) {
	return (leftSelect, rightSelect, ...restSelects) => {
		const setOperators = [rightSelect, ...restSelects].map((select) => ({
			type,
			isAll,
			rightSelect: select
		}));
		for (const setOperator of setOperators) if (!haveSameKeys(leftSelect.getSelectedFields(), setOperator.rightSelect.getSelectedFields())) throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");
		return leftSelect.addSetOperators(setOperators);
	};
}
var getPgSetOperators = () => ({
	union,
	unionAll,
	intersect,
	intersectAll,
	except,
	exceptAll
});
var union = createSetOperator("union", false);
var unionAll = createSetOperator("union", true);
var intersect = createSetOperator("intersect", false);
var intersectAll = createSetOperator("intersect", true);
var except = createSetOperator("except", false);
var exceptAll = createSetOperator("except", true);
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/query-builder.js
var QueryBuilder = class {
	static [entityKind] = "PgQueryBuilder";
	dialect;
	dialectConfig;
	constructor(dialect) {
		this.dialect = is$1(dialect, PgDialect) ? dialect : void 0;
		this.dialectConfig = is$1(dialect, PgDialect) ? void 0 : dialect;
	}
	$with = (alias, selection) => {
		const queryBuilder = this;
		const as = (qb) => {
			if (typeof qb === "function") qb = qb(queryBuilder);
			return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
				alias,
				sqlAliasedBehavior: "alias",
				sqlBehavior: "error"
			}));
		};
		return { as };
	};
	with(...queries) {
		const self = this;
		function select(fields) {
			return new PgSelectBuilder({
				fields: fields ?? void 0,
				session: void 0,
				dialect: self.getDialect(),
				withList: queries
			});
		}
		function selectDistinct(fields) {
			return new PgSelectBuilder({
				fields: fields ?? void 0,
				session: void 0,
				dialect: self.getDialect(),
				distinct: true
			});
		}
		function selectDistinctOn(on, fields) {
			return new PgSelectBuilder({
				fields: fields ?? void 0,
				session: void 0,
				dialect: self.getDialect(),
				distinct: { on }
			});
		}
		return {
			select,
			selectDistinct,
			selectDistinctOn
		};
	}
	select(fields) {
		return new PgSelectBuilder({
			fields: fields ?? void 0,
			session: void 0,
			dialect: this.getDialect()
		});
	}
	selectDistinct(fields) {
		return new PgSelectBuilder({
			fields: fields ?? void 0,
			session: void 0,
			dialect: this.getDialect(),
			distinct: true
		});
	}
	selectDistinctOn(on, fields) {
		return new PgSelectBuilder({
			fields: fields ?? void 0,
			session: void 0,
			dialect: this.getDialect(),
			distinct: { on }
		});
	}
	getDialect() {
		if (!this.dialect) this.dialect = new PgDialect(this.dialectConfig);
		return this.dialect;
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/utils.js
function extractUsedTable(table) {
	if (is$1(table, PgTable)) return [table[Schema] ? `${table[Schema]}.${table[Table.Symbol.BaseName]}` : table[Table.Symbol.BaseName]];
	if (is$1(table, Subquery)) return table._.usedTables ?? [];
	if (is$1(table, SQL)) return table.usedTables ?? [];
	return [];
}
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/delete.js
var PgDeleteBase = class extends QueryPromise {
	constructor(table, session, dialect, withList) {
		super();
		this.session = session;
		this.dialect = dialect;
		this.config = {
			table,
			withList
		};
	}
	static [entityKind] = "PgDelete";
	config;
	cacheConfig;
	/**
	* Adds a `where` clause to the query.
	*
	* Calling this method will delete only those rows that fulfill a specified condition.
	*
	* See docs: {@link https://orm.drizzle.team/docs/delete}
	*
	* @param where the `where` clause.
	*
	* @example
	* You can use conditional operators and `sql function` to filter the rows to be deleted.
	*
	* ```ts
	* // Delete all cars with green color
	* await db.delete(cars).where(eq(cars.color, 'green'));
	* // or
	* await db.delete(cars).where(sql`${cars.color} = 'green'`)
	* ```
	*
	* You can logically combine conditional operators with `and()` and `or()` operators:
	*
	* ```ts
	* // Delete all BMW cars with a green color
	* await db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
	*
	* // Delete all cars with the green or blue color
	* await db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
	* ```
	*/
	where(where) {
		this.config.where = where;
		return this;
	}
	returning(fields = this.config.table[Table.Symbol.Columns]) {
		this.config.returningFields = fields;
		this.config.returning = orderSelectedFields(fields);
		return this;
	}
	/** @internal */
	getSQL() {
		return this.dialect.buildDeleteQuery(this.config);
	}
	toSQL() {
		const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
		return rest;
	}
	/** @internal */
	_prepare(name) {
		return tracer.startActiveSpan("drizzle.prepareQuery", () => {
			return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true, void 0, {
				type: "delete",
				tables: extractUsedTable(this.config.table)
			}, this.cacheConfig);
		});
	}
	prepare(name) {
		return this._prepare(name);
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	execute = (placeholderValues) => {
		return tracer.startActiveSpan("drizzle.operation", () => {
			return this._prepare().execute(placeholderValues, this.authToken);
		});
	};
	/** @internal */
	getSelectedFields() {
		return this.config.returningFields ? new Proxy(this.config.returningFields, new SelectionProxyHandler({
			alias: getTableName(this.config.table),
			sqlAliasedBehavior: "alias",
			sqlBehavior: "error"
		})) : void 0;
	}
	$dynamic() {
		return this;
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/insert.js
var PgInsertBuilder = class {
	constructor(table, session, dialect, withList, overridingSystemValue_) {
		this.table = table;
		this.session = session;
		this.dialect = dialect;
		this.withList = withList;
		this.overridingSystemValue_ = overridingSystemValue_;
	}
	static [entityKind] = "PgInsertBuilder";
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	overridingSystemValue() {
		this.overridingSystemValue_ = true;
		return this;
	}
	values(values) {
		values = Array.isArray(values) ? values : [values];
		if (values.length === 0) throw new Error("values() must be called with at least one value");
		const mappedValues = values.map((entry) => {
			const result = {};
			const cols = this.table[Table.Symbol.Columns];
			for (const colKey of Object.keys(entry)) {
				const colValue = entry[colKey];
				result[colKey] = is$1(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
			}
			return result;
		});
		return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList, false, this.overridingSystemValue_).setToken(this.authToken);
	}
	select(selectQuery) {
		const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
		if (!is$1(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) throw new Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");
		return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
	}
};
var PgInsertBase = class extends QueryPromise {
	constructor(table, values, session, dialect, withList, select, overridingSystemValue_) {
		super();
		this.session = session;
		this.dialect = dialect;
		this.config = {
			table,
			values,
			withList,
			select,
			overridingSystemValue_
		};
	}
	static [entityKind] = "PgInsert";
	config;
	cacheConfig;
	returning(fields = this.config.table[Table.Symbol.Columns]) {
		this.config.returningFields = fields;
		this.config.returning = orderSelectedFields(fields);
		return this;
	}
	/**
	* Adds an `on conflict do nothing` clause to the query.
	*
	* Calling this method simply avoids inserting a row as its alternative action.
	*
	* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
	*
	* @param config The `target` and `where` clauses.
	*
	* @example
	* ```ts
	* // Insert one row and cancel the insert if there's a conflict
	* await db.insert(cars)
	*   .values({ id: 1, brand: 'BMW' })
	*   .onConflictDoNothing();
	*
	* // Explicitly specify conflict target
	* await db.insert(cars)
	*   .values({ id: 1, brand: 'BMW' })
	*   .onConflictDoNothing({ target: cars.id });
	* ```
	*/
	onConflictDoNothing(config = {}) {
		if (config.target === void 0) this.config.onConflict = sql`do nothing`;
		else {
			let targetColumn = "";
			targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
			const whereSql = config.where ? sql` where ${config.where}` : void 0;
			this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
		}
		return this;
	}
	/**
	* Adds an `on conflict do update` clause to the query.
	*
	* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
	*
	* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
	*
	* @param config The `target`, `set` and `where` clauses.
	*
	* @example
	* ```ts
	* // Update the row if there's a conflict
	* await db.insert(cars)
	*   .values({ id: 1, brand: 'BMW' })
	*   .onConflictDoUpdate({
	*     target: cars.id,
	*     set: { brand: 'Porsche' }
	*   });
	*
	* // Upsert with 'where' clause
	* await db.insert(cars)
	*   .values({ id: 1, brand: 'BMW' })
	*   .onConflictDoUpdate({
	*     target: cars.id,
	*     set: { brand: 'newBMW' },
	*     targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
	*   });
	* ```
	*/
	onConflictDoUpdate(config) {
		if (config.where && (config.targetWhere || config.setWhere)) throw new Error("You cannot use both \"where\" and \"targetWhere\"/\"setWhere\" at the same time - \"where\" is deprecated, use \"targetWhere\" or \"setWhere\" instead.");
		const whereSql = config.where ? sql` where ${config.where}` : void 0;
		const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
		const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
		const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
		let targetColumn = "";
		targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
		this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
		return this;
	}
	/** @internal */
	getSQL() {
		return this.dialect.buildInsertQuery(this.config);
	}
	toSQL() {
		const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
		return rest;
	}
	/** @internal */
	_prepare(name) {
		return tracer.startActiveSpan("drizzle.prepareQuery", () => {
			return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true, void 0, {
				type: "insert",
				tables: extractUsedTable(this.config.table)
			}, this.cacheConfig);
		});
	}
	prepare(name) {
		return this._prepare(name);
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	execute = (placeholderValues) => {
		return tracer.startActiveSpan("drizzle.operation", () => {
			return this._prepare().execute(placeholderValues, this.authToken);
		});
	};
	/** @internal */
	getSelectedFields() {
		return this.config.returningFields ? new Proxy(this.config.returningFields, new SelectionProxyHandler({
			alias: getTableName(this.config.table),
			sqlAliasedBehavior: "alias",
			sqlBehavior: "error"
		})) : void 0;
	}
	$dynamic() {
		return this;
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.js
var PgRefreshMaterializedView = class extends QueryPromise {
	constructor(view, session, dialect) {
		super();
		this.session = session;
		this.dialect = dialect;
		this.config = { view };
	}
	static [entityKind] = "PgRefreshMaterializedView";
	config;
	concurrently() {
		if (this.config.withNoData !== void 0) throw new Error("Cannot use concurrently and withNoData together");
		this.config.concurrently = true;
		return this;
	}
	withNoData() {
		if (this.config.concurrently !== void 0) throw new Error("Cannot use concurrently and withNoData together");
		this.config.withNoData = true;
		return this;
	}
	/** @internal */
	getSQL() {
		return this.dialect.buildRefreshMaterializedViewQuery(this.config);
	}
	toSQL() {
		const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
		return rest;
	}
	/** @internal */
	_prepare(name) {
		return tracer.startActiveSpan("drizzle.prepareQuery", () => {
			return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, name, true);
		});
	}
	prepare(name) {
		return this._prepare(name);
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	execute = (placeholderValues) => {
		return tracer.startActiveSpan("drizzle.operation", () => {
			return this._prepare().execute(placeholderValues, this.authToken);
		});
	};
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/update.js
var PgUpdateBuilder = class {
	constructor(table, session, dialect, withList) {
		this.table = table;
		this.session = session;
		this.dialect = dialect;
		this.withList = withList;
	}
	static [entityKind] = "PgUpdateBuilder";
	authToken;
	setToken(token) {
		this.authToken = token;
		return this;
	}
	set(values) {
		return new PgUpdateBase(this.table, mapUpdateSet(this.table, values), this.session, this.dialect, this.withList).setToken(this.authToken);
	}
};
var PgUpdateBase = class extends QueryPromise {
	constructor(table, set, session, dialect, withList) {
		super();
		this.session = session;
		this.dialect = dialect;
		this.config = {
			set,
			table,
			withList,
			joins: []
		};
		this.tableName = getTableLikeName(table);
		this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
	}
	static [entityKind] = "PgUpdate";
	config;
	tableName;
	joinsNotNullableMap;
	cacheConfig;
	from(source) {
		const src = source;
		const tableName = getTableLikeName(src);
		if (typeof tableName === "string") this.joinsNotNullableMap[tableName] = true;
		this.config.from = src;
		return this;
	}
	getTableLikeFields(table) {
		if (is$1(table, PgTable)) return table[Table.Symbol.Columns];
		else if (is$1(table, Subquery)) return table._.selectedFields;
		return table[ViewBaseConfig].selectedFields;
	}
	createJoin(joinType) {
		return (table, on) => {
			const tableName = getTableLikeName(table);
			if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
			if (typeof on === "function") {
				const from = this.config.from && !is$1(this.config.from, SQL) ? this.getTableLikeFields(this.config.from) : void 0;
				on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
					sqlAliasedBehavior: "sql",
					sqlBehavior: "sql"
				})), from && new Proxy(from, new SelectionProxyHandler({
					sqlAliasedBehavior: "sql",
					sqlBehavior: "sql"
				})));
			}
			this.config.joins.push({
				on,
				table,
				joinType,
				alias: tableName
			});
			if (typeof tableName === "string") switch (joinType) {
				case "left":
					this.joinsNotNullableMap[tableName] = false;
					break;
				case "right":
					this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
					this.joinsNotNullableMap[tableName] = true;
					break;
				case "inner":
					this.joinsNotNullableMap[tableName] = true;
					break;
				case "full":
					this.joinsNotNullableMap = Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]));
					this.joinsNotNullableMap[tableName] = false;
			}
			return this;
		};
	}
	leftJoin = this.createJoin("left");
	rightJoin = this.createJoin("right");
	innerJoin = this.createJoin("inner");
	fullJoin = this.createJoin("full");
	/**
	* Adds a 'where' clause to the query.
	*
	* Calling this method will update only those rows that fulfill a specified condition.
	*
	* See docs: {@link https://orm.drizzle.team/docs/update}
	*
	* @param where the 'where' clause.
	*
	* @example
	* You can use conditional operators and `sql function` to filter the rows to be updated.
	*
	* ```ts
	* // Update all cars with green color
	* await db.update(cars).set({ color: 'red' })
	*   .where(eq(cars.color, 'green'));
	* // or
	* await db.update(cars).set({ color: 'red' })
	*   .where(sql`${cars.color} = 'green'`)
	* ```
	*
	* You can logically combine conditional operators with `and()` and `or()` operators:
	*
	* ```ts
	* // Update all BMW cars with a green color
	* await db.update(cars).set({ color: 'red' })
	*   .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
	*
	* // Update all cars with the green or blue color
	* await db.update(cars).set({ color: 'red' })
	*   .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
	* ```
	*/
	where(where) {
		this.config.where = where;
		return this;
	}
	returning(fields) {
		if (!fields) {
			fields = Object.assign({}, this.config.table[Table.Symbol.Columns]);
			if (this.config.from) {
				const tableName = getTableLikeName(this.config.from);
				if (typeof tableName === "string" && this.config.from && !is$1(this.config.from, SQL)) {
					const fromFields = this.getTableLikeFields(this.config.from);
					fields[tableName] = fromFields;
				}
				for (const join of this.config.joins) {
					const tableName2 = getTableLikeName(join.table);
					if (typeof tableName2 === "string" && !is$1(join.table, SQL)) {
						const fromFields = this.getTableLikeFields(join.table);
						fields[tableName2] = fromFields;
					}
				}
			}
		}
		this.config.returningFields = fields;
		this.config.returning = orderSelectedFields(fields);
		return this;
	}
	/** @internal */
	getSQL() {
		return this.dialect.buildUpdateQuery(this.config);
	}
	toSQL() {
		const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
		return rest;
	}
	/** @internal */
	_prepare(name) {
		const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true, void 0, {
			type: "insert",
			tables: extractUsedTable(this.config.table)
		}, this.cacheConfig);
		query.joinsNotNullableMap = this.joinsNotNullableMap;
		return query;
	}
	prepare(name) {
		return this._prepare(name);
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	execute = (placeholderValues) => {
		return this._prepare().execute(placeholderValues, this.authToken);
	};
	/** @internal */
	getSelectedFields() {
		return this.config.returningFields ? new Proxy(this.config.returningFields, new SelectionProxyHandler({
			alias: getTableName(this.config.table),
			sqlAliasedBehavior: "alias",
			sqlBehavior: "error"
		})) : void 0;
	}
	$dynamic() {
		return this;
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/count.js
var PgCountBuilder = class PgCountBuilder extends SQL {
	constructor(params) {
		super(PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
		this.params = params;
		this.mapWith(Number);
		this.session = params.session;
		this.sql = PgCountBuilder.buildCount(params.source, params.filters);
	}
	sql;
	token;
	static [entityKind] = "PgCountBuilder";
	[Symbol.toStringTag] = "PgCountBuilder";
	session;
	static buildEmbeddedCount(source, filters) {
		return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
	}
	static buildCount(source, filters) {
		return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters};`;
	}
	/** @intrnal */
	setToken(token) {
		this.token = token;
		return this;
	}
	then(onfulfilled, onrejected) {
		return Promise.resolve(this.session.count(this.sql, this.token)).then(onfulfilled, onrejected);
	}
	catch(onRejected) {
		return this.then(void 0, onRejected);
	}
	finally(onFinally) {
		return this.then((value) => {
			onFinally?.();
			return value;
		}, (reason) => {
			onFinally?.();
			throw reason;
		});
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/query.js
var RelationalQueryBuilder = class {
	constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session) {
		this.fullSchema = fullSchema;
		this.schema = schema;
		this.tableNamesMap = tableNamesMap;
		this.table = table;
		this.tableConfig = tableConfig;
		this.dialect = dialect;
		this.session = session;
	}
	static [entityKind] = "PgRelationalQueryBuilder";
	findMany(config) {
		return new PgRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? config : {}, "many");
	}
	findFirst(config) {
		return new PgRelationalQuery(this.fullSchema, this.schema, this.tableNamesMap, this.table, this.tableConfig, this.dialect, this.session, config ? {
			...config,
			limit: 1
		} : { limit: 1 }, "first");
	}
};
var PgRelationalQuery = class extends QueryPromise {
	constructor(fullSchema, schema, tableNamesMap, table, tableConfig, dialect, session, config, mode) {
		super();
		this.fullSchema = fullSchema;
		this.schema = schema;
		this.tableNamesMap = tableNamesMap;
		this.table = table;
		this.tableConfig = tableConfig;
		this.dialect = dialect;
		this.session = session;
		this.config = config;
		this.mode = mode;
	}
	static [entityKind] = "PgRelationalQuery";
	/** @internal */
	_prepare(name) {
		return tracer.startActiveSpan("drizzle.prepareQuery", () => {
			const { query, builtQuery } = this._toSQL();
			return this.session.prepareQuery(builtQuery, void 0, name, true, (rawRows, mapColumnValue) => {
				const rows = rawRows.map((row) => mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue));
				if (this.mode === "first") return rows[0];
				return rows;
			});
		});
	}
	prepare(name) {
		return this._prepare(name);
	}
	_getQuery() {
		return this.dialect.buildRelationalQueryWithoutPK({
			fullSchema: this.fullSchema,
			schema: this.schema,
			tableNamesMap: this.tableNamesMap,
			table: this.table,
			tableConfig: this.tableConfig,
			queryConfig: this.config,
			tableAlias: this.tableConfig.tsName
		});
	}
	/** @internal */
	getSQL() {
		return this._getQuery().sql;
	}
	_toSQL() {
		const query = this._getQuery();
		return {
			query,
			builtQuery: this.dialect.sqlToQuery(query.sql)
		};
	}
	toSQL() {
		return this._toSQL().builtQuery;
	}
	authToken;
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	execute() {
		return tracer.startActiveSpan("drizzle.operation", () => {
			return this._prepare().execute(void 0, this.authToken);
		});
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/query-builders/raw.js
var PgRaw = class extends QueryPromise {
	constructor(execute, sql, query, mapBatchResult) {
		super();
		this.execute = execute;
		this.sql = sql;
		this.query = query;
		this.mapBatchResult = mapBatchResult;
	}
	static [entityKind] = "PgRaw";
	/** @internal */
	getSQL() {
		return this.sql;
	}
	getQuery() {
		return this.query;
	}
	mapResult(result, isFromBatch) {
		return isFromBatch ? this.mapBatchResult(result) : result;
	}
	_prepare() {
		return this;
	}
	/** @internal */
	isResponseInArrayMode() {
		return false;
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/db.js
var PgDatabase = class {
	constructor(dialect, session, schema) {
		this.dialect = dialect;
		this.session = session;
		this._ = schema ? {
			schema: schema.schema,
			fullSchema: schema.fullSchema,
			tableNamesMap: schema.tableNamesMap,
			session
		} : {
			schema: void 0,
			fullSchema: {},
			tableNamesMap: {},
			session
		};
		this.query = {};
		if (this._.schema) for (const [tableName, columns] of Object.entries(this._.schema)) this.query[tableName] = new RelationalQueryBuilder(schema.fullSchema, this._.schema, this._.tableNamesMap, schema.fullSchema[tableName], columns, dialect, session);
		this.$cache = { invalidate: async (_params) => {} };
	}
	static [entityKind] = "PgDatabase";
	query;
	/**
	* Creates a subquery that defines a temporary named result set as a CTE.
	*
	* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
	*
	* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
	*
	* @param alias The alias for the subquery.
	*
	* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
	*
	* @example
	*
	* ```ts
	* // Create a subquery with alias 'sq' and use it in the select query
	* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
	*
	* const result = await db.with(sq).select().from(sq);
	* ```
	*
	* To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
	*
	* ```ts
	* // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
	* const sq = db.$with('sq').as(db.select({
	*   name: sql<string>`upper(${users.name})`.as('name'),
	* })
	* .from(users));
	*
	* const result = await db.with(sq).select({ name: sq.name }).from(sq);
	* ```
	*/
	$with = (alias, selection) => {
		const self = this;
		const as = (qb) => {
			if (typeof qb === "function") qb = qb(new QueryBuilder(self.dialect));
			return new Proxy(new WithSubquery(qb.getSQL(), selection ?? ("getSelectedFields" in qb ? qb.getSelectedFields() ?? {} : {}), alias, true), new SelectionProxyHandler({
				alias,
				sqlAliasedBehavior: "alias",
				sqlBehavior: "error"
			}));
		};
		return { as };
	};
	$count(source, filters) {
		return new PgCountBuilder({
			source,
			filters,
			session: this.session
		});
	}
	$cache;
	/**
	* Incorporates a previously defined CTE (using `$with`) into the main query.
	*
	* This method allows the main query to reference a temporary named result set.
	*
	* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
	*
	* @param queries The CTEs to incorporate into the main query.
	*
	* @example
	*
	* ```ts
	* // Define a subquery 'sq' as a CTE using $with
	* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
	*
	* // Incorporate the CTE 'sq' into the main query and select from it
	* const result = await db.with(sq).select().from(sq);
	* ```
	*/
	with(...queries) {
		const self = this;
		function select(fields) {
			return new PgSelectBuilder({
				fields: fields ?? void 0,
				session: self.session,
				dialect: self.dialect,
				withList: queries
			});
		}
		function selectDistinct(fields) {
			return new PgSelectBuilder({
				fields: fields ?? void 0,
				session: self.session,
				dialect: self.dialect,
				withList: queries,
				distinct: true
			});
		}
		function selectDistinctOn(on, fields) {
			return new PgSelectBuilder({
				fields: fields ?? void 0,
				session: self.session,
				dialect: self.dialect,
				withList: queries,
				distinct: { on }
			});
		}
		function update(table) {
			return new PgUpdateBuilder(table, self.session, self.dialect, queries);
		}
		function insert(table) {
			return new PgInsertBuilder(table, self.session, self.dialect, queries);
		}
		function delete_(table) {
			return new PgDeleteBase(table, self.session, self.dialect, queries);
		}
		return {
			select,
			selectDistinct,
			selectDistinctOn,
			update,
			insert,
			delete: delete_
		};
	}
	select(fields) {
		return new PgSelectBuilder({
			fields: fields ?? void 0,
			session: this.session,
			dialect: this.dialect
		});
	}
	selectDistinct(fields) {
		return new PgSelectBuilder({
			fields: fields ?? void 0,
			session: this.session,
			dialect: this.dialect,
			distinct: true
		});
	}
	selectDistinctOn(on, fields) {
		return new PgSelectBuilder({
			fields: fields ?? void 0,
			session: this.session,
			dialect: this.dialect,
			distinct: { on }
		});
	}
	/**
	* Creates an update query.
	*
	* Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
	*
	* Use `.set()` method to specify which values to update.
	*
	* See docs: {@link https://orm.drizzle.team/docs/update}
	*
	* @param table The table to update.
	*
	* @example
	*
	* ```ts
	* // Update all rows in the 'cars' table
	* await db.update(cars).set({ color: 'red' });
	*
	* // Update rows with filters and conditions
	* await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
	*
	* // Update with returning clause
	* const updatedCar: Car[] = await db.update(cars)
	*   .set({ color: 'red' })
	*   .where(eq(cars.id, 1))
	*   .returning();
	* ```
	*/
	update(table) {
		return new PgUpdateBuilder(table, this.session, this.dialect);
	}
	/**
	* Creates an insert query.
	*
	* Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
	*
	* See docs: {@link https://orm.drizzle.team/docs/insert}
	*
	* @param table The table to insert into.
	*
	* @example
	*
	* ```ts
	* // Insert one row
	* await db.insert(cars).values({ brand: 'BMW' });
	*
	* // Insert multiple rows
	* await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
	*
	* // Insert with returning clause
	* const insertedCar: Car[] = await db.insert(cars)
	*   .values({ brand: 'BMW' })
	*   .returning();
	* ```
	*/
	insert(table) {
		return new PgInsertBuilder(table, this.session, this.dialect);
	}
	/**
	* Creates a delete query.
	*
	* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
	*
	* See docs: {@link https://orm.drizzle.team/docs/delete}
	*
	* @param table The table to delete from.
	*
	* @example
	*
	* ```ts
	* // Delete all rows in the 'cars' table
	* await db.delete(cars);
	*
	* // Delete rows with filters and conditions
	* await db.delete(cars).where(eq(cars.color, 'green'));
	*
	* // Delete with returning clause
	* const deletedCar: Car[] = await db.delete(cars)
	*   .where(eq(cars.id, 1))
	*   .returning();
	* ```
	*/
	delete(table) {
		return new PgDeleteBase(table, this.session, this.dialect);
	}
	refreshMaterializedView(view) {
		return new PgRefreshMaterializedView(view, this.session, this.dialect);
	}
	authToken;
	execute(query) {
		const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
		const builtQuery = this.dialect.sqlToQuery(sequel);
		const prepared = this.session.prepareQuery(builtQuery, void 0, void 0, false);
		return new PgRaw(() => prepared.execute(void 0, this.authToken), sequel, builtQuery, (result) => prepared.mapResult(result, true));
	}
	transaction(transaction, config) {
		return this.session.transaction(transaction, config);
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/pg-core/session.js
var PgPreparedQuery = class {
	constructor(query, cache, queryMetadata, cacheConfig) {
		this.query = query;
		this.cache = cache;
		this.queryMetadata = queryMetadata;
		this.cacheConfig = cacheConfig;
		if (cache && cache.strategy() === "all" && cacheConfig === void 0) this.cacheConfig = {
			enable: true,
			autoInvalidate: true
		};
		if (!this.cacheConfig?.enable) this.cacheConfig = void 0;
	}
	authToken;
	getQuery() {
		return this.query;
	}
	mapResult(response, _isFromBatch) {
		return response;
	}
	/** @internal */
	setToken(token) {
		this.authToken = token;
		return this;
	}
	static [entityKind] = "PgPreparedQuery";
	/** @internal */
	joinsNotNullableMap;
	/** @internal */
	async queryWithCache(queryString, params, query) {
		if (this.cache === void 0 || is$1(this.cache, NoopCache) || this.queryMetadata === void 0) try {
			return await query();
		} catch (e) {
			throw new DrizzleQueryError(queryString, params, e);
		}
		if (this.cacheConfig && !this.cacheConfig.enable) try {
			return await query();
		} catch (e) {
			throw new DrizzleQueryError(queryString, params, e);
		}
		if ((this.queryMetadata.type === "insert" || this.queryMetadata.type === "update" || this.queryMetadata.type === "delete") && this.queryMetadata.tables.length > 0) try {
			const [res] = await Promise.all([query(), this.cache.onMutate({ tables: this.queryMetadata.tables })]);
			return res;
		} catch (e) {
			throw new DrizzleQueryError(queryString, params, e);
		}
		if (!this.cacheConfig) try {
			return await query();
		} catch (e) {
			throw new DrizzleQueryError(queryString, params, e);
		}
		if (this.queryMetadata.type === "select") {
			const fromCache = await this.cache.get(this.cacheConfig.tag ?? await hashQuery(queryString, params), this.queryMetadata.tables, this.cacheConfig.tag !== void 0, this.cacheConfig.autoInvalidate);
			if (fromCache === void 0) {
				let result;
				try {
					result = await query();
				} catch (e) {
					throw new DrizzleQueryError(queryString, params, e);
				}
				await this.cache.put(this.cacheConfig.tag ?? await hashQuery(queryString, params), result, this.cacheConfig.autoInvalidate ? this.queryMetadata.tables : [], this.cacheConfig.tag !== void 0, this.cacheConfig.config);
				return result;
			}
			return fromCache;
		}
		try {
			return await query();
		} catch (e) {
			throw new DrizzleQueryError(queryString, params, e);
		}
	}
};
var PgSession = class {
	constructor(dialect) {
		this.dialect = dialect;
	}
	static [entityKind] = "PgSession";
	/** @internal */
	execute(query, token) {
		return tracer.startActiveSpan("drizzle.operation", () => {
			return tracer.startActiveSpan("drizzle.prepareQuery", () => {
				return this.prepareQuery(this.dialect.sqlToQuery(query), void 0, void 0, false);
			}).setToken(token).execute(void 0, token);
		});
	}
	all(query) {
		return this.prepareQuery(this.dialect.sqlToQuery(query), void 0, void 0, false).all();
	}
	/** @internal */
	async count(sql2, token) {
		const res = await this.execute(sql2, token);
		return Number(res[0]["count"]);
	}
};
var PgTransaction = class extends PgDatabase {
	constructor(dialect, session, schema, nestedIndex = 0) {
		super(dialect, session, schema);
		this.schema = schema;
		this.nestedIndex = nestedIndex;
	}
	static [entityKind] = "PgTransaction";
	rollback() {
		throw new TransactionRollbackError();
	}
	/** @internal */
	getTransactionConfigSQL(config) {
		const chunks = [];
		if (config.isolationLevel) chunks.push(`isolation level ${config.isolationLevel}`);
		if (config.accessMode) chunks.push(config.accessMode);
		if (typeof config.deferrable === "boolean") chunks.push(config.deferrable ? "deferrable" : "not deferrable");
		return sql.raw(chunks.join(" "));
	}
	setTransaction(config) {
		return this.session.execute(sql`set transaction ${this.getTransactionConfigSQL(config)}`);
	}
};
//#endregion
//#region ../../packages/content/dist/taxonomy-CmOYaoVZ.js
var definitionColumns = () => ({
	key: text("key").primaryKey(),
	origin: text("origin").$type().notNull(),
	version: integer("version").notNull().default(1),
	active: boolean("active").notNull().default(true),
	currentRevision: integer("current_revision").notNull().default(1),
	canonicalHash: text("canonical_hash").notNull(),
	definition: jsonb("definition").$type().notNull(),
	shadowedDbVersion: integer("shadowed_db_version"),
	hostSessionId: text("host_session_id"),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
});
var contentTypeDefinitions = pgTable("content_type_definitions", definitionColumns(), (t) => [
	check("content_type_definitions_version_positive", sql`${t.version} > 0`),
	check("content_type_definitions_revision_positive", sql`${t.currentRevision} > 0`),
	index("content_type_definitions_active_idx").on(t.active, t.key)
]);
var contentStatusDefinitions = pgTable("content_status_definitions", definitionColumns(), (t) => [
	check("content_status_definitions_version_positive", sql`${t.version} > 0`),
	check("content_status_definitions_revision_positive", sql`${t.currentRevision} > 0`),
	index("content_status_definitions_active_idx").on(t.active, t.key)
]);
var contentDefinitionVersions = pgTable("content_definition_versions", {
	definitionKind: text("definition_kind").$type().notNull(),
	definitionKey: text("definition_key").notNull(),
	revision: integer("revision").notNull(),
	canonicalHash: text("canonical_hash").notNull(),
	definition: jsonb("definition").$type().notNull(),
	origin: text("origin").$type().notNull(),
	hostSessionId: text("host_session_id"),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [
	primaryKey({ columns: [
		t.definitionKind,
		t.definitionKey,
		t.revision
	] }),
	check("content_definition_versions_revision_positive", sql`${t.revision} > 0`),
	index("content_definition_versions_hash_idx").on(t.canonicalHash)
]);
/** Private credential bytes never join the public entry projection. */
var contentPasswordCredentials = pgTable("content_password_credentials", {
	entryId: uuid("entry_id").primaryKey(),
	credentialVersion: text("credential_version").notNull(),
	credential: text("credential").notNull(),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [index("content_password_credentials_version_idx").on(t.credentialVersion)]);
var contentLifecycleJournal = pgTable("content_lifecycle_journal", {
	id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
	operationId: text("operation_id").notNull(),
	kind: text("kind").notNull(),
	entryId: uuid("entry_id"),
	definitionKind: text("definition_kind").$type(),
	definitionKey: text("definition_key"),
	definitionRevision: integer("definition_revision"),
	state: text("state").notNull(),
	payload: jsonb("payload").$type(),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [uniqueIndex("content_lifecycle_journal_operation_uq").on(t.operationId), index("content_lifecycle_journal_entry_idx").on(t.entryId, t.createdAt)]);
var contentImportJournal = pgTable("content_import_journal", {
	importId: uuid("import_id").primaryKey().$defaultFn(() => crypto.randomUUID()),
	hostSessionId: text("host_session_id").notNull(),
	manifestHash: text("manifest_hash").notNull(),
	planHash: text("plan_hash").notNull(),
	state: text("state").notNull(),
	version: integer("version").notNull().default(0),
	nextSection: text("next_section"),
	nextOffset: integer("next_offset"),
	highWaterMark: text("high_water_mark"),
	payload: jsonb("payload").$type(),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [uniqueIndex("content_import_journal_session_uq").on(t.hostSessionId), check("content_import_journal_version_nonnegative", sql`${t.version} >= 0`)]);
var contentTombstones = pgTable("content_tombstones", {
	id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
	entryId: uuid("entry_id").notNull(),
	operationId: text("operation_id").notNull(),
	typeKey: text("type_key").notNull(),
	typeDefinitionRevision: integer("type_definition_revision").notNull(),
	statusKey: text("status_key").notNull(),
	statusDefinitionRevision: integer("status_definition_revision").notNull(),
	snapshot: jsonb("snapshot").$type().notNull(),
	deletedAt: timestamp("deleted_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [uniqueIndex("content_tombstones_operation_entry_uq").on(t.operationId, t.entryId), index("content_tombstones_entry_idx").on(t.entryId, t.deletedAt)]);
var contentMigrationCheckpoints = pgTable("content_migration_checkpoints", {
	migrationId: text("migration_id").notNull(),
	adapter: text("adapter").$type().notNull(),
	phase: text("phase").$type().notNull(),
	batchOrdinal: integer("batch_ordinal").notNull().default(0),
	version: integer("version").notNull().default(0),
	lastKey: text("last_key"),
	sourceCount: integer("source_count").notNull(),
	targetCount: integer("target_count"),
	sourceHash: text("source_hash").notNull(),
	targetHash: text("target_hash"),
	highWaterMark: text("high_water_mark"),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [
	primaryKey({ columns: [
		t.migrationId,
		t.adapter,
		t.phase,
		t.batchOrdinal
	] }),
	check("content_migration_checkpoint_batch_nonnegative", sql`${t.batchOrdinal} >= 0`),
	check("content_migration_checkpoint_version_nonnegative", sql`${t.version} >= 0`)
]);
var contentMigrationWriteJournal = pgTable("content_migration_write_journal", {
	seq: bigserial("seq", { mode: "number" }).primaryKey(),
	migrationId: text("migration_id").notNull(),
	operation: text("operation").$type().notNull(),
	entryId: text("entry_id").notNull(),
	beforeValue: jsonb("before_value").$type(),
	afterValue: jsonb("after_value").$type(),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [index("content_migration_write_journal_migration_seq_idx").on(t.migrationId, t.seq)]);
var contentEntries = pgTable("content_entries", {
	id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
	slug: text("slug").notNull(),
	type: text("type").notNull(),
	title: text("title").notNull(),
	body: text("body").notNull().default(""),
	status: text("status").$type().notNull().default("draft"),
	visibility: text("visibility").$type().notNull().default("public"),
	publishedAt: timestamp("published_at", {
		withTimezone: true,
		precision: 3
	}),
	author: text("author").notNull(),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
	parentId: uuid("parent_id"),
	menuOrder: integer("menu_order").notNull().default(0),
	templateKey: text("template_key"),
	excerpt: text("excerpt").notNull().default(""),
	featuredMedia: jsonb("featured_media").$type(),
	commentStatus: text("comment_status").$type().notNull().default("open"),
	pingStatus: text("ping_status").$type().notNull().default("open"),
	sticky: boolean("sticky").notNull().default(false),
	format: text("format"),
	deletedAt: timestamp("deleted_at", {
		withTimezone: true,
		precision: 3
	}),
	lastEditedBy: text("last_edited_by").notNull(),
	typeDefinitionRevision: integer("type_definition_revision").notNull().default(1),
	statusDefinitionRevision: integer("status_definition_revision").notNull().default(1)
}, (t) => [
	uniqueIndex("content_entries_type_slug_uq").on(t.type, t.slug),
	index("content_entries_type_status_pub_idx").on(t.type, t.status, desc(t.publishedAt)),
	index("content_entries_type_status_vis_pub_idx").on(t.type, t.status, t.visibility, desc(t.publishedAt)),
	index("content_entries_parent_order_idx").on(t.type, t.parentId, t.menuOrder, t.id),
	index("content_entries_deleted_idx").on(t.deletedAt),
	index("content_entries_type_definition_idx").on(t.type, t.typeDefinitionRevision),
	index("content_entries_status_definition_idx").on(t.status, t.statusDefinitionRevision)
]);
var contentTerms = pgTable("content_terms", {
	id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
	taxonomy: text("taxonomy").notNull(),
	slug: text("slug").notNull(),
	name: text("name").notNull(),
	parentId: uuid("parent_id").references(() => contentTerms.id, { onDelete: "restrict" }),
	depth: integer("depth").notNull().default(0),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
}, (t) => [uniqueIndex("content_terms_sibling_slug_uq").on(t.taxonomy, sql`COALESCE(${t.parentId}, '00000000-0000-0000-0000-000000000000'::uuid)`, t.slug), index("content_terms_taxonomy_parent_idx").on(t.taxonomy, t.parentId)]);
var contentEntryTerms = pgTable("content_entry_terms", {
	entryId: uuid("entry_id").notNull().references(() => contentEntries.id, { onDelete: "cascade" }),
	termId: uuid("term_id").notNull().references(() => contentTerms.id, { onDelete: "cascade" })
}, (t) => [primaryKey({ columns: [t.entryId, t.termId] }), index("content_entry_terms_term_idx").on(t.termId)]);
var contentSchema = {
	contentEntries,
	contentTerms,
	contentEntryTerms,
	contentRevisions: pgTable("content_revisions", {
		id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
		entryId: uuid("entry_id").notNull().references(() => contentEntries.id, { onDelete: "cascade" }),
		seq: bigserial("seq", { mode: "number" }).notNull(),
		title: text("title").notNull(),
		body: text("body").notNull(),
		slug: text("slug").notNull(),
		type: text("type").notNull(),
		termIds: jsonb("term_ids").$type().notNull().$defaultFn(() => []),
		snapshot: jsonb("snapshot").$type(),
		editor: text("editor").notNull(),
		createdAt: timestamp("created_at", {
			withTimezone: true,
			precision: 3
		}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
	}, (t) => [index("content_revisions_entry_seq_idx").on(t.entryId, desc(t.seq))]),
	contentTypeDefinitions,
	contentStatusDefinitions,
	contentDefinitionVersions,
	contentPasswordCredentials,
	contentLifecycleJournal,
	contentImportJournal,
	contentTombstones,
	contentMigrationCheckpoints,
	contentMigrationWriteJournal
};
/** Runtime guard: only an active callback-minted database transaction may enter T4 lifecycle seams. */
function assertActiveContentTransaction(tx) {
	getTransactionIdentity(tx);
}
var ContentAuthorizationError = class extends Error {
	operation;
	principalId;
	detail;
	name = "ContentAuthorizationError";
	constructor(operation, principalId, detail) {
		super(`content authorization denied: ${operation} by ${principalId} — ${detail}`);
		this.operation = operation;
		this.principalId = principalId;
		this.detail = detail;
	}
};
function requireEntryStatus(input) {
	if (!input.entry) return input.status;
	if (!input.status || input.status.key !== input.entry.status) throw new ContentAuthorizationError(input.operation, input.principal.id, "entry status metadata is missing or mismatched");
	return input.status;
}
/**
* Normative capability-key resolution from the complete content-type contract.
* Returned keys are conjunctive; callers must never select their own ownership/status branches.
*/
function resolveRequiredContentCapabilities(input) {
	const status = requireEntryStatus(input);
	const capabilities = [];
	const own = input.entry?.author === input.principal.id;
	switch (input.operation) {
		case "manageType":
			capabilities.push("manageType");
			break;
		case "migrateTypeDefinition":
			capabilities.push("manageType", "migrateAll");
			break;
		case "manageTerms":
			capabilities.push("manageTerms");
			if (input.entry) capabilities.push(own ? "editOwn" : "editOthers");
			break;
		case "create":
			capabilities.push("create");
			break;
		case "read":
			capabilities.push("read");
			if (input.entry?.visibility === "private") capabilities.push("readPrivate");
			break;
		case "readProtected":
			capabilities.push("read");
			if (input.entry?.visibility === "private") capabilities.push("readPrivate");
			capabilities.push("readProtected");
			break;
		case "edit":
			if (!input.entry) throw new ContentAuthorizationError(input.operation, input.principal.id, "edit requires exact entry metadata");
			capabilities.push(own ? "editOwn" : "editOthers");
			if (input.entry.visibility === "private") capabilities.push("editPrivate");
			if (status?.published) capabilities.push("editPublished");
			break;
		case "publish":
			if (!input.entry) throw new ContentAuthorizationError(input.operation, input.principal.id, "publish requires exact entry metadata");
			capabilities.push(own ? "editOwn" : "editOthers");
			if (input.entry.visibility === "private") capabilities.push("editPrivate");
			if (status?.published) capabilities.push("editPublished");
			capabilities.push("publish");
			break;
		case "delete":
			if (!input.entry) throw new ContentAuthorizationError(input.operation, input.principal.id, "delete requires exact entry metadata");
			capabilities.push(own ? "deleteOwn" : "deleteOthers");
			if (input.entry.visibility === "private") capabilities.push("deletePrivate");
			if (status?.published) capabilities.push("deletePublished");
	}
	return Object.freeze([...new Set(capabilities)]);
}
function authorizeContentAction(input) {
	const required = resolveRequiredContentCapabilities(input);
	for (const capabilityKey of required) {
		const mapped = input.type.capabilities[capabilityKey];
		if (typeof mapped !== "string" || mapped.length === 0 || !input.principal.capabilities.has(mapped)) throw new ContentAuthorizationError(input.operation, input.principal.id, `missing required capability ${capabilityKey}`);
	}
}
var ContentAuthzError = class extends Error {
	action;
	actorId;
	detail;
	entryId;
	name = "ContentAuthzError";
	constructor(action, actorId, detail, entryId) {
		super(`content authz denied: ${action} by ${actorId} — ${detail}`);
		this.action = action;
		this.actorId = actorId;
		this.detail = detail;
		this.entryId = entryId;
	}
};
function assertCanModify(actor, action, ownerAuthor, entryId) {
	if (actor.canEditAny || ownerAuthor === actor.id) return;
	throw new ContentAuthzError(action, actor.id, "actor is not the author and lacks canEditAny", entryId);
}
function assertCanPublish(actor, action, entryId) {
	if (!actor.canPublish) throw new ContentAuthzError(action, actor.id, "actor lacks canPublish", entryId);
}
/** Typed, contextful boundary error — carries the offending field + why (coding-standard §4). */
var ContentValidationError = class extends Error {
	field;
	detail;
	name = "ContentValidationError";
	constructor(field, detail) {
		super(`content input invalid: ${field} — ${detail}`);
		this.field = field;
		this.detail = detail;
	}
};
/** Thrown when a write reaches the store without a usable `sanitize` function (fail-closed). */
var ContentSanitizationError = class extends Error {
	name = "ContentSanitizationError";
	constructor(message) {
		super(message);
	}
};
var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
var MAX_SLUG = 200;
var MAX_TYPE = 64;
var MAX_TITLE = 300;
var VISIBILITY_LITERALS$1 = [
	"public",
	"private",
	"members"
];
var UUID_RE$1 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
function normTermIds(raw) {
	if (raw === void 0) return void 0;
	if (!Array.isArray(raw)) throw new ContentValidationError("termIds", "must be an array of UUID strings");
	const out = [];
	for (const id of raw) {
		if (typeof id !== "string" || !UUID_RE$1.test(id)) throw new ContentValidationError("termIds", "must contain only well-formed UUID strings");
		out.push(id);
	}
	return [...new Set(out)];
}
function normVisibility(raw, isUpdate) {
	if (raw === void 0 || raw === null) return isUpdate ? null : "public";
	if (typeof raw !== "string" || !VISIBILITY_LITERALS$1.includes(raw)) throw new ContentValidationError("visibility", "must be public|private|members");
	return raw;
}
/**
* Validator-agnostic boundary normalization (north-star: never bundle a validator).
* Hand-rolled required-field + format checks; the adopter's own validator runs at the route.
*/
function normalizeContentInput(raw) {
	if (typeof raw !== "object" || raw === null) throw new ContentValidationError("input", "must be an object");
	const slug = String(raw.slug ?? "").trim();
	if (!SLUG_RE.test(slug)) throw new ContentValidationError("slug", "must be lowercase kebab-case [a-z0-9-]");
	if (slug.length > MAX_SLUG) throw new ContentValidationError("slug", `exceeds ${MAX_SLUG} chars`);
	const type = String(raw.type ?? "").trim();
	if (!type) throw new ContentValidationError("type", "required");
	if (type.length > MAX_TYPE) throw new ContentValidationError("type", `exceeds ${MAX_TYPE} chars`);
	const title = String(raw.title ?? "").trim();
	if (!title) throw new ContentValidationError("title", "required");
	if (title.length > MAX_TITLE) throw new ContentValidationError("title", `exceeds ${MAX_TITLE} chars`);
	const body = typeof raw.body === "string" ? raw.body : "";
	const id = raw.id !== void 0 && raw.id !== null ? String(raw.id).trim() : null;
	if (id !== null && id.length === 0) throw new ContentValidationError("id", "must be non-empty when present");
	return {
		id,
		slug,
		type,
		title,
		body,
		visibility: normVisibility(raw.visibility, id !== null),
		termIds: normTermIds(raw.termIds)
	};
}
var TermNotFoundError = class extends Error {
	selector;
	name = "TermNotFoundError";
	constructor(selector) {
		super(`term not found: ${selector}`);
		this.selector = selector;
	}
};
var TermValidationError = class extends Error {
	field;
	detail;
	name = "TermValidationError";
	constructor(field, detail) {
		super(`term invalid: ${field} — ${detail}`);
		this.field = field;
		this.detail = detail;
	}
};
function toTermRef(row) {
	return {
		id: row.id,
		taxonomy: row.taxonomy,
		slug: row.slug,
		name: row.name,
		parentId: row.parentId ?? null,
		depth: row.depth
	};
}
async function listTerms(db, taxonomy) {
	return (await db.select().from(contentTerms).where(eq(contentTerms.taxonomy, taxonomy)).orderBy(asc(contentTerms.depth), asc(contentTerms.name))).map(toTermRef);
}
async function validateTermIdsExist(db, termIds) {
	if (termIds.length === 0) return;
	for (const id of termIds) if (typeof id !== "string" || !UUID_RE$1.test(id)) throw new TermValidationError("termIds", "must contain only well-formed UUID strings");
	const found = await db.select({ id: contentTerms.id }).from(contentTerms).where(inArray(contentTerms.id, termIds));
	if (found.length !== termIds.length) {
		const foundSet = new Set(found.map((r) => r.id));
		throw new TermNotFoundError(`id=${termIds.find((id) => !foundSet.has(id))}`);
	}
}
async function replaceEntryTerms(db, entryId, termIds) {
	await db.delete(contentEntryTerms).where(eq(contentEntryTerms.entryId, entryId));
	for (const termId of termIds) await db.insert(contentEntryTerms).values({
		entryId,
		termId
	});
}
async function termsForEntry(db, entryId) {
	return (await db.select({ term: contentTerms }).from(contentEntryTerms).innerJoin(contentTerms, eq(contentEntryTerms.termId, contentTerms.id)).where(eq(contentEntryTerms.entryId, entryId)).orderBy(asc(contentTerms.depth), asc(contentTerms.name))).map((r) => toTermRef(r.term));
}
//#endregion
//#region ../../packages/content/dist/store-D_2h-weW.js
/** Typed structural error for the final-store boundary. */
var ContentStoreContractError = class extends Error {
	code;
	detail;
	field;
	name = "ContentStoreContractError";
	constructor(code, detail, field) {
		super(`content store ${code}: ${detail}`);
		this.code = code;
		this.detail = detail;
		this.field = field;
	}
};
function trustedFlatRow(row) {
	if (typeof row !== "object" || row === null || Array.isArray(row) || Object.getPrototypeOf(row) !== Object.prototype || Object.getOwnPropertySymbols(row).length !== 0) throw new ContentStoreContractError("invalid-flat-row", "must be a plain data row", "row");
	for (const key of Object.getOwnPropertyNames(row)) {
		const descriptor = Object.getOwnPropertyDescriptor(row, key);
		if (!descriptor.enumerable || !("value" in descriptor)) throw new ContentStoreContractError("invalid-flat-row", "must not contain non-enumerable properties or accessors", "row");
	}
	return row;
}
function requiredString(row, field) {
	const value = row[field];
	if (typeof value !== "string") throw new ContentStoreContractError("invalid-flat-row", "must be a string", field);
	return value;
}
function requiredDate(row, field, nullable = false) {
	const value = row[field];
	if (nullable && value === null) return null;
	const date = value instanceof Date ? new Date(Date.prototype.getTime.call(value)) : typeof value === "string" ? new Date(value) : null;
	if (date === null || Number.isNaN(date.getTime())) throw new ContentStoreContractError("invalid-flat-row", "must be an ISO timestamp or Date", field);
	return date;
}
/**
* Reads the legacy flat corpus losslessly enough for cross-adapter comparison.
* It validates only transport shape; arbitrary legacy type/status strings are
* deliberately preserved until the registry-materialization migration.
*/
async function readFlatContentEntries(reader) {
	if (reader.adapter !== "d1" && reader.adapter !== "postgres") throw new ContentStoreContractError("unsupported-adapter", `unknown adapter ${String(reader.adapter)}`);
	const rows = await reader.execute(sql`
    SELECT id, slug, type, title, body, status, visibility,
      published_at AS "publishedAt", author,
      created_at AS "createdAt", updated_at AS "updatedAt"
    FROM content_entries
    ORDER BY id ASC
  `);
	return Object.freeze(rows.map((candidate) => {
		const row = trustedFlatRow(candidate);
		return Object.freeze({
			id: requiredString(row, "id"),
			slug: requiredString(row, "slug"),
			type: requiredString(row, "type"),
			title: requiredString(row, "title"),
			body: requiredString(row, "body"),
			status: requiredString(row, "status"),
			visibility: requiredString(row, "visibility"),
			publishedAt: requiredDate(row, "publishedAt", true),
			author: requiredString(row, "author"),
			createdAt: requiredDate(row, "createdAt"),
			updatedAt: requiredDate(row, "updatedAt")
		});
	}));
}
var ContentNotFoundError = class extends Error {
	selector;
	name = "ContentNotFoundError";
	constructor(selector) {
		super(`content entry not found: ${selector}`);
		this.selector = selector;
	}
};
/**
* A duplicate (type, slug) hits content_entries_type_slug_uq. Surface it as a TYPED, contextful
* boundary error (coding-standard §4) instead of leaking the raw Postgres error out of the seam.
* DB-index-enforced + caught = race-safe (no pre-check TOCTOU).
*/
var ContentConflictError = class extends Error {
	type;
	slug;
	name = "ContentConflictError";
	constructor(type, slug) {
		super(`content entry already exists: type=${type} slug=${slug}`);
		this.type = type;
		this.slug = slug;
	}
};
var VISIBILITY_LITERALS = [
	"public",
	"private",
	"members"
];
function assertVisibilityLiteral(visibility) {
	if (!VISIBILITY_LITERALS.includes(visibility)) throw new ContentValidationError("visibility", "must be public|private|members");
}
/** SQL read-authz floor — never post-filter in JS (spec §3). Shared by list/getBySlug/search. */
function visibilityPredicate(viewer) {
	if (viewer?.canEditAny) return void 0;
	if (!viewer) return and(eq(contentEntries.status, "published"), eq(contentEntries.visibility, "public"));
	const clauses = [eq(contentEntries.author, viewer.id), and(eq(contentEntries.status, "published"), eq(contentEntries.visibility, "public"))];
	if (viewer.canViewMembers) clauses.push(and(eq(contentEntries.status, "published"), eq(contentEntries.visibility, "members")));
	return or(...clauses);
}
/** Detect a unique-constraint violation without coupling to one driver's error shape. */
function isUniqueViolation$1(e) {
	let cur = e;
	while (cur) {
		const code = cur?.code;
		const msg = cur instanceof Error ? cur.message : String(cur);
		if (code === "23505" || /content_entries_type_slug_uq|duplicate key|unique constraint/i.test(msg)) return true;
		cur = cur instanceof Error ? cur.cause : void 0;
	}
	return false;
}
async function catchConflict(type, slug, fn) {
	try {
		return await fn();
	} catch (e) {
		if (isUniqueViolation$1(e)) throw new ContentConflictError(type, slug);
		throw e;
	}
}
var DEFAULT_LIMIT = 20;
var MAX_LIMIT = 100;
function toEntry$1(row, terms) {
	return {
		id: row.id,
		slug: row.slug,
		type: row.type,
		title: row.title,
		body: row.body,
		status: row.status,
		visibility: row.visibility,
		publishedAt: row.publishedAt ?? null,
		author: row.author,
		terms,
		createdAt: row.createdAt,
		updatedAt: row.updatedAt,
		parentId: row.parentId ?? null,
		menuOrder: row.menuOrder,
		templateKey: row.templateKey ?? null,
		excerpt: row.excerpt,
		featuredMedia: row.featuredMedia ?? null,
		commentStatus: row.commentStatus,
		pingStatus: row.pingStatus,
		passwordProtected: false,
		sticky: row.sticky,
		format: row.format ?? null,
		deletedAt: row.deletedAt ?? null,
		lastEditedBy: row.lastEditedBy,
		typeDefinitionRevision: row.typeDefinitionRevision,
		statusDefinitionRevision: row.statusDefinitionRevision
	};
}
async function entryWithTerms(db, row) {
	return toEntry$1(row, await termsForEntry(db, row.id));
}
var REF_COLS = {
	id: contentEntries.id,
	slug: contentEntries.slug,
	type: contentEntries.type
};
async function getRow(db, id) {
	const [row] = await db.select().from(contentEntries).where(eq(contentEntries.id, id)).limit(1);
	if (!row) throw new ContentNotFoundError(`id=${id}`);
	return row;
}
async function list(db, query = {}, viewer, _opts = {}) {
	const limit = Math.min(Math.max(query.limit ?? DEFAULT_LIMIT, 1), MAX_LIMIT);
	const offset = Math.max(query.offset ?? 0, 0);
	const filters = [];
	const vis = visibilityPredicate(viewer);
	if (vis) filters.push(vis);
	if (query.type) filters.push(eq(contentEntries.type, query.type));
	if (query.status) filters.push(eq(contentEntries.status, query.status));
	else filters.push(ne(contentEntries.status, "trashed"));
	if (query.term) {
		if (!UUID_RE$1.test(query.term)) throw new ContentValidationError("term", "must be a well-formed UUID string");
		if (query.includeDescendants) filters.push(sql`EXISTS (
        SELECT 1 FROM content_entry_terms cet
        WHERE cet.entry_id = ${contentEntries.id}
        AND cet.term_id IN (
          WITH RECURSIVE subtree AS (
            SELECT id, 1 AS lvl FROM content_terms WHERE id = ${query.term}::uuid
            UNION ALL
            SELECT t.id, s.lvl + 1 FROM content_terms t INNER JOIN subtree s ON t.parent_id = s.id
            WHERE s.lvl < 64
          )
          SELECT id FROM subtree
        )
      )`);
		else filters.push(sql`EXISTS (
        SELECT 1 FROM content_entry_terms cet
        WHERE cet.entry_id = ${contentEntries.id} AND cet.term_id = ${query.term}::uuid
      )`);
	}
	const defined = filters.filter((f) => f !== void 0);
	const rows = await db.select().from(contentEntries).where(defined.length ? and(...defined) : void 0).orderBy(desc(contentEntries.publishedAt), desc(contentEntries.createdAt)).limit(limit).offset(offset);
	return Promise.all(rows.map((row) => entryWithTerms(db, row)));
}
async function getBySlug(db, type, slug, viewer, _opts = {}) {
	const filters = [eq(contentEntries.type, type), eq(contentEntries.slug, slug)];
	const vis = visibilityPredicate(viewer);
	if (vis) filters.push(vis);
	const [row] = await db.select().from(contentEntries).where(and(...filters)).limit(1);
	return row ? await entryWithTerms(db, row) : null;
}
/**
* Read a single entry by its stable primary-key id (peer of `getBySlug`; admin edit URLs key on id,
* not the mutable slug). Applies the IDENTICAL viewer visibility predicate in SQL — an admin
* (`canEditAny`) loads any status/visibility; a non-permitted viewer gets `null` with no
* existence oracle (indistinguishable from absent). Read-authz floor enforced in-store, never delegated.
*/
async function getById(db, id, viewer, _opts = {}) {
	const filters = [eq(contentEntries.id, id)];
	const vis = visibilityPredicate(viewer);
	if (vis) filters.push(vis);
	const [row] = await db.select().from(contentEntries).where(and(...filters)).limit(1);
	return row ? await entryWithTerms(db, row) : null;
}
/**
* Fail-closed guard for the host-injected sanitizer (mirrors comments). A missing/non-function
* `sanitize` throws BEFORE any DB access — a forgotten sanitizer never silently stores raw HTML.
*/
function assertSanitize$1(sanitize, verb) {
	if (typeof sanitize !== "function") throw new ContentSanitizationError(`${verb}: sanitize must be a function, got ${typeof sanitize}`);
}
/**
* Create or update a content entry. The HTML `body` is sanitized on store (XSS hard floor):
* `sanitize` is REQUIRED and applied to `body` on both the insert and update paths; the SANITIZED
* value is persisted (no raw HTML retained). `title` is plain text and is NOT sanitized — the host
* render-escapes it. The sanitizer ENGINE is host-owned (an allowlist sanitizer appropriate to the
* host runtime — the adopter picks one that actually strips on their runtime); this module owns the
* contract + enforcement, never the engine.
*/
async function put(db, raw, actor, sanitize, _opts = {}) {
	assertSanitize$1(sanitize, "put");
	const input = normalizeContentInput(raw);
	const safeBody = sanitize(input.body);
	if (input.termIds !== void 0) await validateTermIdsExist(db, input.termIds);
	if (input.id) {
		const id = input.id;
		const existing = await getRow(db, id);
		assertCanModify(actor, "update", existing.author, existing.id);
		const patch = {
			slug: input.slug,
			type: input.type,
			title: input.title,
			body: safeBody,
			updatedAt: /* @__PURE__ */ new Date(),
			lastEditedBy: actor.id
		};
		if (input.visibility !== null) patch.visibility = input.visibility;
		const [updated] = await catchConflict(input.type, input.slug, () => db.update(contentEntries).set(patch).where(eq(contentEntries.id, id)).returning());
		if (input.termIds !== void 0) await replaceEntryTerms(db, id, input.termIds);
		return entryWithTerms(db, updated);
	}
	const [created] = await catchConflict(input.type, input.slug, () => db.insert(contentEntries).values({
		slug: input.slug,
		type: input.type,
		title: input.title,
		body: safeBody,
		author: actor.id,
		lastEditedBy: actor.id,
		status: "draft",
		visibility: input.visibility ?? "public"
	}).returning());
	if (input.termIds !== void 0) await replaceEntryTerms(db, created.id, input.termIds);
	return entryWithTerms(db, created);
}
async function setVisibility(db, id, visibility, actor, _opts = {}) {
	assertVisibilityLiteral(visibility);
	assertCanModify(actor, "update", (await getRow(db, id)).author, id);
	const now = /* @__PURE__ */ new Date();
	const [row] = await db.update(contentEntries).set({
		visibility,
		updatedAt: now
	}).where(eq(contentEntries.id, id)).returning(REF_COLS);
	return row;
}
async function publish(db, id, actor, _opts = {}) {
	await getRow(db, id);
	assertCanPublish(actor, "publish", id);
	const now = /* @__PURE__ */ new Date();
	const [row] = await db.update(contentEntries).set({
		status: "published",
		publishedAt: now,
		updatedAt: now
	}).where(eq(contentEntries.id, id)).returning(REF_COLS);
	return row;
}
async function schedule(db, id, at, actor, _opts = {}) {
	if (!(at instanceof Date) || Number.isNaN(at.getTime())) throw new ContentValidationError("at", "must be a valid Date");
	const now = /* @__PURE__ */ new Date();
	if (at <= now) throw new ContentValidationError("at", "must be in the future; use publish() to go live now");
	await getRow(db, id);
	assertCanPublish(actor, "schedule", id);
	const [row] = await db.update(contentEntries).set({
		status: "scheduled",
		publishedAt: at,
		updatedAt: now
	}).where(eq(contentEntries.id, id)).returning(REF_COLS);
	return row;
}
async function unpublish(db, id, actor, _opts = {}) {
	await getRow(db, id);
	assertCanPublish(actor, "unpublish", id);
	const now = /* @__PURE__ */ new Date();
	const [row] = await db.update(contentEntries).set({
		status: "draft",
		publishedAt: null,
		updatedAt: now
	}).where(eq(contentEntries.id, id)).returning(REF_COLS);
	return row;
}
/**
* Take-offline floor (U1b): trashing a live (published|scheduled) entry is a publication-status transition —
* also requires `canPublish`. Non-live (draft|trashed) → `canModify` only.
*/
async function trash(db, id, actor, _opts = {}) {
	const existing = await getRow(db, id);
	assertCanModify(actor, "trash", existing.author, id);
	if (existing.status === "published" || existing.status === "scheduled") assertCanPublish(actor, "trash", id);
	const now = /* @__PURE__ */ new Date();
	const [row] = await db.update(contentEntries).set({
		status: "trashed",
		updatedAt: now
	}).where(eq(contentEntries.id, id)).returning(REF_COLS);
	return row;
}
/**
* Restores a TRASHED entry to draft (the inverse of `trash`). Prior status is intentionally not
* persisted (no column) — restored content re-enters review and must be re-published by the admin.
*
* Scoped to `status='trashed'` ONLY: on a non-trashed entry this is a no-op that returns the entry's
* ref unchanged. This keeps restore from being a publish-state bypass — `restore` must NOT be a path
* for a `canModify`-but-not-`canPublish` actor to move a LIVE (published/scheduled) entry to draft
* (that liveness transition is gated by `unpublish`/`assertCanPublish`). Idempotent: a second restore
* sees `draft`, matches no row, and no-ops.
*/
async function restore(db, id, actor, _opts = {}) {
	const existing = await getRow(db, id);
	assertCanModify(actor, "restore", existing.author, id);
	const now = /* @__PURE__ */ new Date();
	const [row] = await db.update(contentEntries).set({
		status: "draft",
		updatedAt: now
	}).where(and(eq(contentEntries.id, id), eq(contentEntries.status, "trashed"))).returning(REF_COLS);
	return row ?? {
		id: existing.id,
		slug: existing.slug,
		type: existing.type
	};
}
/**
* Take-offline floor (U1b): removing a live (published|scheduled) entry is a publication-status transition —
* also requires `canPublish`. Non-live (draft|trashed) → `canModify` only.
*/
async function remove(db, id, actor, _opts = {}) {
	const existing = await getRow(db, id);
	assertCanModify(actor, "remove", existing.author, id);
	if (existing.status === "published" || existing.status === "scheduled") assertCanPublish(actor, "remove", id);
	const [row] = await db.delete(contentEntries).where(eq(contentEntries.id, id)).returning(REF_COLS);
	return row;
}
//#endregion
//#region ../../packages/content/dist/migrate.js
var ContentMigrateError = class extends Error {
	detail;
	name = "ContentMigrateError";
	constructor(detail) {
		super(`content migrate: ${detail}`);
		this.detail = detail;
	}
};
var STATUS_LITERALS = [
	"draft",
	"pending",
	"scheduled",
	"published",
	"trashed"
];
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
var MAX_BODY_LENGTH = 1e6;
var MAX_ENTRIES = 1e5;
async function toEntry(db, row) {
	return {
		id: row.id,
		slug: row.slug,
		type: row.type,
		title: row.title,
		body: row.body,
		status: row.status,
		visibility: row.visibility,
		publishedAt: row.publishedAt ?? null,
		author: row.author,
		terms: await termsForEntry(db, row.id),
		createdAt: row.createdAt,
		updatedAt: row.updatedAt,
		parentId: row.parentId ?? null,
		menuOrder: row.menuOrder,
		templateKey: row.templateKey ?? null,
		excerpt: row.excerpt,
		featuredMedia: row.featuredMedia ?? null,
		commentStatus: row.commentStatus,
		pingStatus: row.pingStatus,
		passwordProtected: false,
		sticky: row.sticky,
		format: row.format ?? null,
		deletedAt: row.deletedAt ?? null,
		lastEditedBy: row.lastEditedBy,
		typeDefinitionRevision: row.typeDefinitionRevision,
		statusDefinitionRevision: row.statusDefinitionRevision
	};
}
function assertSanitize(sanitize) {
	if (typeof sanitize !== "function") throw new ContentMigrateError("sanitize required");
}
function assertCanImport(actor) {
	if (actor?.canEditAny !== true || actor?.canPublish !== true) throw new ContentAuthzError("update", actor?.id ?? "<anonymous>", "import requires canEditAny and canPublish");
}
function assertCanExport(actor) {
	if (actor?.canEditAny !== true) throw new ContentAuthzError("read", actor?.id ?? "<anonymous>", "export requires canEditAny");
}
function assertTransactional(db) {
	if (typeof db.transaction !== "function") throw new ContentMigrateError("replace mode requires a TransactionalDatabase");
}
function isUniqueViolation(e) {
	let cur = e;
	while (cur) {
		const code = cur?.code;
		const msg = cur instanceof Error ? cur.message : String(cur);
		if (code === "23505" || /content_entries_type_slug_uq|duplicate key|unique constraint/i.test(msg)) return true;
		cur = cur instanceof Error ? cur.cause : void 0;
	}
	return false;
}
function toContentInput(entry) {
	return {
		id: entry.id,
		slug: entry.slug,
		type: entry.type,
		title: entry.title,
		body: entry.body,
		visibility: entry.visibility,
		termIds: entry.terms.map((t) => t.id)
	};
}
function prepareEntries(archive, sanitize) {
	const prepared = [];
	const conflicts = [];
	let skipped = 0;
	for (const entry of archive.entries) {
		const ref = `${entry?.type ?? "?"}/${entry?.slug ?? "?"}`;
		try {
			if (entry.id !== void 0 && entry.id !== null && (typeof entry.id !== "string" || !UUID_RE.test(entry.id))) {
				conflicts.push(`${ref}: id — must be a valid UUID`);
				skipped++;
				continue;
			}
			if (!STATUS_LITERALS.includes(entry.status)) {
				conflicts.push(`${ref}: status — must be draft|pending|scheduled|published|trashed`);
				skipped++;
				continue;
			}
			if (typeof entry.body === "string" && entry.body.length > MAX_BODY_LENGTH) {
				conflicts.push(`${ref}: body — exceeds ${MAX_BODY_LENGTH} chars`);
				skipped++;
				continue;
			}
			const normalized = normalizeContentInput(toContentInput(entry));
			const safeBody = sanitize(normalized.body);
			const safeVisibility = normalized.visibility ?? "private";
			prepared.push({
				source: entry,
				normalized,
				safeBody,
				safeStatus: entry.status,
				safeVisibility
			});
		} catch (e) {
			if (e instanceof ContentValidationError) {
				conflicts.push(`${ref}: ${e.field} — ${e.detail}`);
				skipped++;
				continue;
			}
			throw new ContentMigrateError("validation failed");
		}
	}
	return {
		prepared,
		skipped,
		conflicts
	};
}
function insertValues(p) {
	const { source, normalized, safeBody, safeStatus, safeVisibility } = p;
	return {
		id: source.id,
		slug: normalized.slug,
		type: normalized.type,
		title: normalized.title,
		body: safeBody,
		status: safeStatus,
		visibility: safeVisibility,
		publishedAt: source.publishedAt,
		author: source.author,
		createdAt: source.createdAt,
		updatedAt: source.updatedAt,
		parentId: source.parentId ?? null,
		menuOrder: source.menuOrder ?? 0,
		templateKey: source.templateKey ?? null,
		excerpt: source.excerpt ?? "",
		featuredMedia: source.featuredMedia ?? null,
		commentStatus: source.commentStatus ?? "open",
		pingStatus: source.pingStatus ?? "open",
		sticky: source.sticky ?? false,
		format: source.format ?? null,
		deletedAt: source.deletedAt ?? null,
		lastEditedBy: source.lastEditedBy ?? source.author,
		typeDefinitionRevision: source.typeDefinitionRevision ?? 1,
		statusDefinitionRevision: source.statusDefinitionRevision ?? 1
	};
}
async function exportContent(db, opts) {
	assertCanExport(opts?.actor);
	const rows = opts?.types?.length ? await db.select().from(contentEntries).where(inArray(contentEntries.type, opts.types)) : await db.select().from(contentEntries);
	const archive = {
		version: 1,
		exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
		entries: await Promise.all(rows.map((row) => toEntry(db, row)))
	};
	if (opts?.includeSettings) archive.settings = {};
	return archive;
}
async function writePrepared(db, prepared, mode) {
	let imported = 0;
	let skipped = 0;
	for (const p of prepared) {
		if (mode === "merge") {
			const [existing] = await db.select().from(contentEntries).where(and(eq(contentEntries.type, p.normalized.type), eq(contentEntries.slug, p.normalized.slug))).limit(1);
			if (existing && p.source.updatedAt <= existing.updatedAt) {
				skipped++;
				continue;
			}
		}
		try {
			await db.insert(contentEntries).values(insertValues(p)).onConflictDoUpdate({
				target: [contentEntries.type, contentEntries.slug],
				set: {
					title: p.normalized.title,
					body: p.safeBody,
					status: p.safeStatus,
					visibility: p.safeVisibility,
					publishedAt: p.source.publishedAt,
					author: p.source.author,
					updatedAt: p.source.updatedAt
				},
				where: sql`${contentEntries.updatedAt} < excluded.updated_at`
			});
			imported++;
		} catch (e) {
			if (isUniqueViolation(e)) {
				skipped++;
				continue;
			}
			throw new ContentMigrateError("write failed");
		}
	}
	return {
		imported,
		skipped
	};
}
async function importContent(db, archive, opts) {
	assertCanImport(opts?.actor);
	assertSanitize(opts.sanitize);
	if (!archive || !Array.isArray(archive.entries)) throw new ContentMigrateError("archive.entries must be an array");
	if (archive.entries.length > MAX_ENTRIES) throw new ContentMigrateError(`archive exceeds ${MAX_ENTRIES} entries`);
	const { prepared, skipped: invalidSkipped, conflicts } = prepareEntries(archive, opts.sanitize);
	if (opts.mode === "replace") {
		assertTransactional(db);
		if (conflicts.length > 0) throw new ContentMigrateError(`replace aborted: ${conflicts.length} invalid entries`);
		let imported = 0;
		await db.transaction(async (tx) => {
			await tx.delete(contentEntries);
			imported = (await writePrepared(tx, prepared, "replace")).imported;
		});
		return {
			imported,
			skipped: invalidSkipped,
			conflicts
		};
	}
	const result = await writePrepared(db, prepared, "merge");
	return {
		imported: result.imported,
		skipped: invalidSkipped + result.skipped,
		conflicts
	};
}
//#endregion
//#region src/lib/settings.ts
var SettingsValidationError = class extends Error {
	field;
	detail;
	name = "SettingsValidationError";
	constructor(field, detail) {
		super(`settings validation failed: ${field} — ${detail}`);
		this.field = field;
		this.detail = detail;
	}
};
var siteSettings = pgTable("site_settings", {
	key: text("key").primaryKey(),
	value: jsonb("value").notNull(),
	updatedAt: timestamp("updated_at", {
		withTimezone: true,
		precision: 3
	}).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
});
var settingsSchema = { siteSettings };
async function getAllSettings(db) {
	const rows = await db.select().from(siteSettings);
	return Object.fromEntries(rows.map((row) => [row.key, row.value]));
}
async function getSetting(db, key) {
	const [row] = await db.select().from(siteSettings).where(eq(siteSettings.key, key)).limit(1);
	return row?.value ?? null;
}
async function setSetting(db, key, value) {
	if (typeof key !== "string" || !key.trim()) throw new SettingsValidationError("key", "must be a non-empty string");
	if (value === void 0) throw new SettingsValidationError("value", "must be defined");
	const now = /* @__PURE__ */ new Date();
	await db.insert(siteSettings).values({
		key,
		value,
		updatedAt: now
	}).onConflictDoUpdate({
		target: siteSettings.key,
		set: {
			value,
			updatedAt: now
		}
	});
}
var SETTINGS_KEYS = {
	theme: "theme",
	homepage: "homepage",
	maintenance: "maintenance",
	siteName: "site_name",
	siteConfigured: "site_configured",
	siteLogoUrl: "site_logo_url",
	consent: "consent",
	privacyInput: "privacy_input",
	hideModeToggle: "hide_mode_toggle",
	setupMethod: "setup_method",
	discussion: "discussion"
};
var SLUG_MAX = 200;
/**
* Parse the stored `homepage` setting into a typed config. ALWAYS resolves to a valid config —
* any malformed/absent value falls back to `{ mode: 'feed' }` so `/` never breaks on bad settings.
*/
function parseHomepage(value) {
	if (value && typeof value === "object") {
		const v = value;
		if (v.mode === "page" && typeof v.slug === "string") {
			const slug = v.slug.trim();
			if (slug.length > 0 && slug.length <= SLUG_MAX) return {
				mode: "page",
				slug
			};
		}
	}
	return { mode: "feed" };
}
/**
* Parse the stored `hide_mode_toggle` setting. ALWAYS resolves to a boolean; **fail-closed to `false`
* (toggle SHOWN)** so visitors keep light/dark control unless the admin EXPLICITLY hides it. Requires
* a STRICT boolean `true` — truthy junk ('true', 1, {}) never hides the control.
*/
function parseHideModeToggle(value) {
	return value === true;
}
var DEFAULT_SITE_NAME = "mod-cms";
var SITE_NAME_MAX = 100;
var LOGO_URL_MAX = 2048;
/**
* True iff `value` is an absolute https:// URL within the length cap. The single source of truth for
* logo-URL acceptance — used both client-side (inline UX validation) and at render (fail-closed parse).
* https-only: blocks javascript:/data: scheme-confusion and mixed-content; relative/host-relative
* rejected (the logo renders cross-origin in an <img src>, so it must be a fully-qualified https URL).
*/
function isValidLogoUrl(value) {
	if (typeof value !== "string") return false;
	const trimmed = value.trim();
	if (trimmed.length === 0 || trimmed.length > LOGO_URL_MAX) return false;
	try {
		const url = new URL(trimmed);
		return url.protocol === "https:" && url.username === "" && url.password === "";
	} catch {
		return false;
	}
}
/**
* Parse the stored `site_name` + `site_logo_url` settings into a render-safe identity. ALWAYS resolves:
* name falls back to DEFAULT_SITE_NAME (absent/blank/non-string) and is length-capped; logoUrl is the
* stored value only when it passes `isValidLogoUrl`, else null. Never throws — the header never breaks
* on a malformed/tampered setting (matches parseHomepage's fail-closed contract).
*/
function parseSiteIdentity(rawName, rawLogoUrl) {
	let name = DEFAULT_SITE_NAME;
	if (typeof rawName === "string") {
		const trimmed = rawName.trim();
		if (trimmed.length > 0) name = trimmed.slice(0, SITE_NAME_MAX);
	}
	const logoUrl = isValidLogoUrl(rawLogoUrl) ? rawLogoUrl.trim() : null;
	return {
		name,
		logoUrl
	};
}
var MAINTENANCE_MSG_MAX = 2e3;
var MAINTENANCE_ROLES_MAX = 20;
var RETRY_AFTER_MIN = 1;
var RETRY_AFTER_MAX = 86400;
/**
* Parse the stored `maintenance` setting into a `MaintenanceConfig`. ALWAYS resolves — any
* malformed/absent value falls back to `{ enabled: false }`. A throw here would defeat the
* operator escape hatch (a crashing per-request guard locks EVERYONE out), so every field is
* coerced fail-closed. `enabled` requires a STRICT boolean true (truthy junk never enables).
*/
function parseMaintenance(value) {
	if (!value || typeof value !== "object") return { enabled: false };
	const v = value;
	if (v.enabled !== true) return { enabled: false };
	const cfg = { enabled: true };
	if (typeof v.message === "string") {
		const msg = v.message.trim().slice(0, MAINTENANCE_MSG_MAX);
		if (msg.length > 0) cfg.message = msg;
	}
	if (Array.isArray(v.allowRoles)) {
		const roles = v.allowRoles.filter((r) => typeof r === "string" && r.trim().length > 0).map((r) => r.trim()).slice(0, MAINTENANCE_ROLES_MAX);
		if (roles.length > 0) cfg.allowRoles = roles;
	}
	if (typeof v.retryAfterSec === "number" && Number.isFinite(v.retryAfterSec)) {
		const n = Math.floor(v.retryAfterSec);
		if (n >= RETRY_AFTER_MIN) cfg.retryAfterSec = Math.min(n, RETRY_AFTER_MAX);
	}
	return cfg;
}
var CONSENT_POLICY_HREF_MAX = 2048;
var CONSENT_VERSION_MAX = 64;
var DEFAULT_POLICY_HREF = "/privacy";
var NON_NECESSARY_CATEGORIES = [
	"analytics",
	"marketing",
	"preferences"
];
/**
* Accept a relative href (no scheme) or an http(s)/mailto absolute href; anything else → DEFAULT_POLICY_HREF.
* Tests on a control-char-stripped copy (browsers drop ASCII whitespace/control chars before parsing the
* scheme, so `java\tscript:` cannot bypass). Defense-in-depth — ConsentBanner ALSO guards the href at render.
*/
function safeConsentHref(value) {
	if (typeof value !== "string") return DEFAULT_POLICY_HREF;
	const trimmed = value.trim();
	if (trimmed.length === 0 || trimmed.length > CONSENT_POLICY_HREF_MAX) return DEFAULT_POLICY_HREF;
	const cleaned = trimmed.replace(/[\u0000-\u0020]+/g, "");
	const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(cleaned);
	if (!scheme) return trimmed;
	const s = scheme[1].toLowerCase();
	return s === "http" || s === "https" || s === "mailto" ? trimmed : DEFAULT_POLICY_HREF;
}
/**
* Parse the stored `consent` setting into a typed config. ALWAYS resolves — any malformed/absent value
* (or `enabled !== true`) falls back to `{ enabled: false }` (no banner). When enabled, fills `version`
* (default '0'), `policyHref` (default /privacy, scheme-guarded), and `categories` (filtered to the
* non-necessary allowlist). Never throws — the public shell must never break on a tampered setting
* (matches parseMaintenance/parseHomepage fail-closed contract).
*/
function parseConsentConfig(value) {
	if (!value || typeof value !== "object") return { enabled: false };
	const v = value;
	if (v.enabled !== true) return { enabled: false };
	return {
		enabled: true,
		version: typeof v.version === "string" && v.version.trim().length > 0 ? v.version.trim().slice(0, CONSENT_VERSION_MAX) : "0",
		policyHref: safeConsentHref(v.policyHref),
		categories: Array.isArray(v.categories) ? v.categories.filter((c) => typeof c === "string" && NON_NECESSARY_CATEGORIES.includes(c)) : [...NON_NECESSARY_CATEGORIES]
	};
}
var DISCUSSION_NESTING_MAX = 10;
var DISCUSSION_BLOCKLIST_MAX = 200;
var DISCUSSION_BLOCKLIST_TERM_MAX = 100;
var DISCUSSION_DEFAULTS = {
	enabled: false,
	whoCanComment: "everyone",
	nestingDepth: 3,
	blocklist: []
};
/**
* Parse the stored `discussion` setting into a typed config. ALWAYS resolves — any malformed/absent
* value falls back to DISCUSSION_DEFAULTS. Never throws (matches parseMaintenance fail-closed contract).
*/
function parseDiscussionConfig(value) {
	if (!value || typeof value !== "object") return { ...DISCUSSION_DEFAULTS };
	const v = value;
	const enabled = v.enabled === true;
	const whoCanComment = v.whoCanComment === "registered" ? "registered" : "everyone";
	let nestingDepth = 3;
	if (typeof v.nestingDepth === "number" && Number.isFinite(v.nestingDepth)) nestingDepth = Math.min(DISCUSSION_NESTING_MAX, Math.max(0, Math.round(v.nestingDepth)));
	let blocklist = [];
	if (Array.isArray(v.blocklist)) {
		const seen = /* @__PURE__ */ new Set();
		for (const item of v.blocklist) {
			if (typeof item !== "string") continue;
			const term = item.trim().toLowerCase().slice(0, DISCUSSION_BLOCKLIST_TERM_MAX);
			if (term.length === 0 || seen.has(term)) continue;
			seen.add(term);
			blocklist.push(term);
			if (blocklist.length >= DISCUSSION_BLOCKLIST_MAX) break;
		}
	}
	return {
		enabled,
		whoCanComment,
		nestingDepth,
		blocklist
	};
}
/**
* Parse newline-separated blocklist input from the admin form into a normalized string array.
* Trims, lowercases, deduplicates (preserving order), and caps at DISCUSSION_BLOCKLIST_MAX.
*/
function parseBlocklistInput(raw) {
	const seen = /* @__PURE__ */ new Set();
	const result = [];
	for (const segment of raw.split("\n")) {
		const term = segment.trim().toLowerCase();
		if (term.length === 0 || seen.has(term)) continue;
		seen.add(term);
		result.push(term);
		if (result.length >= DISCUSSION_BLOCKLIST_MAX) break;
	}
	return result;
}
//#endregion
//#region src/lib/http.ts
var ENTITY_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
function isEntityId(value) {
	return typeof value === "string" && ENTITY_ID_RE.test(value);
}
function parseIdBody(data) {
	if (typeof data !== "object" || data === null) throw new ContentValidationError("input", "must be an object");
	const id = data.id;
	if (!isEntityId(id)) throw new ContentValidationError("id", "must be a valid UUID");
	return id;
}
function jsonError(status, code, message) {
	return new Response(JSON.stringify({ error: {
		code,
		message
	} }), {
		status,
		headers: { "Content-Type": "application/json" }
	});
}
function jsonOk(data, status = 200) {
	return new Response(JSON.stringify(data), {
		status,
		headers: { "Content-Type": "application/json" }
	});
}
function mapContentError(error) {
	const name = error?.name;
	if (name === "CsrfError") return jsonError(403, "forbidden", error.message);
	if (name === "RateLimitedError") return jsonError(429, "rate_limited", error.message);
	if (name === "RoleDeniedError") return jsonError(403, "forbidden", error.message);
	if (name === "InvalidSessionError") return jsonError(401, "unauthorized", error.message);
	if (error instanceof ContentAuthzError) return jsonError(403, "forbidden", error.message);
	if (error instanceof ContentNotFoundError) return jsonError(404, "not_found", error.message);
	if (error instanceof ContentConflictError) return jsonError(409, "conflict", error.message);
	if (error instanceof ContentValidationError) return jsonError(400, "validation_error", error.message);
	if (error instanceof ContentMigrateError) return jsonError(400, "validation_error", error.message);
	if (error instanceof SettingsValidationError) return jsonError(400, "validation_error", error.message);
	if (name === "UserNotFoundError") return jsonError(404, "not_found", error.message);
	if (name === "UnknownLocaleError") return jsonError(400, "validation_error", error instanceof Error ? error.message : "invalid locale");
	if (name === "SourceUnavailableError") return jsonError(404, "not_found", error instanceof Error ? error.message : "source unavailable");
	if (name === "LastAdminError") return jsonError(409, "conflict", error.message);
	if (name === "InboxValidationError" || name === "InvalidCursorError") return jsonError(400, "validation_error", error.message);
	return jsonError(500, "internal_error", "internal error");
}
//#endregion
//#region ../../node_modules/.pnpm/@neondatabase+serverless@1.1.0/node_modules/@neondatabase/serverless/index.mjs
var So = Object.create;
var Ie = Object.defineProperty;
var Eo = Object.getOwnPropertyDescriptor;
var Ao = Object.getOwnPropertyNames;
var Co = Object.getPrototypeOf;
var _o = Object.prototype.hasOwnProperty;
var Io = (r, e, t) => e in r ? Ie(r, e, {
	enumerable: !0,
	configurable: !0,
	writable: !0,
	value: t
}) : r[e] = t;
var a = (r, e) => Ie(r, "name", {
	value: e,
	configurable: !0
});
var G = (r, e) => () => (r && (e = r(r = 0)), e);
var T = (r, e) => () => (e || r((e = { exports: {} }).exports, e), e.exports);
var ie = (r, e) => {
	for (var t in e) Ie(r, t, {
		get: e[t],
		enumerable: !0
	});
};
var Dn = (r, e, t, n) => {
	if (e && typeof e == "object" || typeof e == "function") for (let i of Ao(e)) !_o.call(r, i) && i !== t && Ie(r, i, {
		get: () => e[i],
		enumerable: !(n = Eo(e, i)) || n.enumerable
	});
	return r;
};
var Se = (r, e, t) => (t = r != null ? So(Co(r)) : {}, Dn(e || !r || !r.__esModule ? Ie(t, "default", {
	value: r,
	enumerable: !0
}) : t, r));
var O = (r) => Dn(Ie({}, "__esModule", { value: !0 }), r);
var E = (r, e, t) => Io(r, typeof e != "symbol" ? e + "" : e, t);
var Qn = T((lt) => {
	"use strict";
	p();
	lt.byteLength = Po;
	lt.toByteArray = Bo;
	lt.fromByteArray = ko;
	var ae = [], te = [], To = typeof Uint8Array < "u" ? Uint8Array : Array, qt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	for (Ee = 0, On = qt.length; Ee < On; ++Ee) ae[Ee] = qt[Ee], te[qt.charCodeAt(Ee)] = Ee;
	var Ee, On;
	te[45] = 62;
	te[95] = 63;
	function qn(r) {
		var e = r.length;
		if (e % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4");
		var t = r.indexOf("=");
		t === -1 && (t = e);
		var n = t === e ? 0 : 4 - t % 4;
		return [t, n];
	}
	a(qn, "getLens");
	function Po(r) {
		var e = qn(r), t = e[0], n = e[1];
		return (t + n) * 3 / 4 - n;
	}
	a(Po, "byteLength");
	function Ro(r, e, t) {
		return (e + t) * 3 / 4 - t;
	}
	a(Ro, "_byteLength");
	function Bo(r) {
		var e, t = qn(r), n = t[0], i = t[1], s = new To(Ro(r, n, i)), o = 0, u = i > 0 ? n - 4 : n, c;
		for (c = 0; c < u; c += 4) e = te[r.charCodeAt(c)] << 18 | te[r.charCodeAt(c + 1)] << 12 | te[r.charCodeAt(c + 2)] << 6 | te[r.charCodeAt(c + 3)], s[o++] = e >> 16 & 255, s[o++] = e >> 8 & 255, s[o++] = e & 255;
		return i === 2 && (e = te[r.charCodeAt(c)] << 2 | te[r.charCodeAt(c + 1)] >> 4, s[o++] = e & 255), i === 1 && (e = te[r.charCodeAt(c)] << 10 | te[r.charCodeAt(c + 1)] << 4 | te[r.charCodeAt(c + 2)] >> 2, s[o++] = e >> 8 & 255, s[o++] = e & 255), s;
	}
	a(Bo, "toByteArray");
	function Lo(r) {
		return ae[r >> 18 & 63] + ae[r >> 12 & 63] + ae[r >> 6 & 63] + ae[r & 63];
	}
	a(Lo, "tripletToBase64");
	function Fo(r, e, t) {
		for (var n, i = [], s = e; s < t; s += 3) n = (r[s] << 16 & 16711680) + (r[s + 1] << 8 & 65280) + (r[s + 2] & 255), i.push(Lo(n));
		return i.join("");
	}
	a(Fo, "encodeChunk");
	function ko(r) {
		for (var e, t = r.length, n = t % 3, i = [], s = 16383, o = 0, u = t - n; o < u; o += s) i.push(Fo(r, o, o + s > u ? u : o + s));
		return n === 1 ? (e = r[t - 1], i.push(ae[e >> 2] + ae[e << 4 & 63] + "==")) : n === 2 && (e = (r[t - 2] << 8) + r[t - 1], i.push(ae[e >> 10] + ae[e >> 4 & 63] + ae[e << 2 & 63] + "=")), i.join("");
	}
	a(ko, "fromByteArray");
});
var Nn = T((Qt) => {
	p();
	Qt.read = function(r, e, t, n, i) {
		var s, o, u = i * 8 - n - 1, c = (1 << u) - 1, l = c >> 1, f = -7, y = t ? i - 1 : 0, g = t ? -1 : 1, A = r[e + y];
		for (y += g, s = A & (1 << -f) - 1, A >>= -f, f += u; f > 0; s = s * 256 + r[e + y], y += g, f -= 8);
		for (o = s & (1 << -f) - 1, s >>= -f, f += n; f > 0; o = o * 256 + r[e + y], y += g, f -= 8);
		if (s === 0) s = 1 - l;
		else {
			if (s === c) return o ? NaN : (A ? -1 : 1) * (1 / 0);
			o = o + Math.pow(2, n), s = s - l;
		}
		return (A ? -1 : 1) * o * Math.pow(2, s - n);
	};
	Qt.write = function(r, e, t, n, i, s) {
		var o, u, c, l = s * 8 - i - 1, f = (1 << l) - 1, y = f >> 1, g = i === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, A = n ? 0 : s - 1, C = n ? 1 : -1, D = e < 0 || e === 0 && 1 / e < 0 ? 1 : 0;
		for (e = Math.abs(e), isNaN(e) || e === 1 / 0 ? (u = isNaN(e) ? 1 : 0, o = f) : (o = Math.floor(Math.log(e) / Math.LN2), e * (c = Math.pow(2, -o)) < 1 && (o--, c *= 2), o + y >= 1 ? e += g / c : e += g * Math.pow(2, 1 - y), e * c >= 2 && (o++, c /= 2), o + y >= f ? (u = 0, o = f) : o + y >= 1 ? (u = (e * c - 1) * Math.pow(2, i), o = o + y) : (u = e * Math.pow(2, y - 1) * Math.pow(2, i), o = 0)); i >= 8; r[t + A] = u & 255, A += C, u /= 256, i -= 8);
		for (o = o << i | u, l += i; l > 0; r[t + A] = o & 255, A += C, o /= 256, l -= 8);
		r[t + A - C] |= D * 128;
	};
});
var ii = T((Be) => {
	"use strict";
	p();
	var Nt = Qn(), Pe = Nn(), Wn = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
	Be.Buffer = h;
	Be.SlowBuffer = Qo;
	Be.INSPECT_MAX_BYTES = 50;
	var ft = 2147483647;
	Be.kMaxLength = ft;
	h.TYPED_ARRAY_SUPPORT = Mo();
	!h.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");
	function Mo() {
		try {
			let r = /* @__PURE__ */ new Uint8Array(1), e = { foo: a(function() {
				return 42;
			}, "foo") };
			return Object.setPrototypeOf(e, Uint8Array.prototype), Object.setPrototypeOf(r, e), r.foo() === 42;
		} catch {
			return !1;
		}
	}
	a(Mo, "typedArraySupport");
	Object.defineProperty(h.prototype, "parent", {
		enumerable: !0,
		get: a(function() {
			if (h.isBuffer(this)) return this.buffer;
		}, "get")
	});
	Object.defineProperty(h.prototype, "offset", {
		enumerable: !0,
		get: a(function() {
			if (h.isBuffer(this)) return this.byteOffset;
		}, "get")
	});
	function he(r) {
		if (r > ft) throw new RangeError("The value \"" + r + "\" is invalid for option \"size\"");
		let e = new Uint8Array(r);
		return Object.setPrototypeOf(e, h.prototype), e;
	}
	a(he, "createBuffer");
	function h(r, e, t) {
		if (typeof r == "number") {
			if (typeof e == "string") throw new TypeError("The \"string\" argument must be of type string. Received type number");
			return $t(r);
		}
		return Gn(r, e, t);
	}
	a(h, "Buffer");
	h.poolSize = 8192;
	function Gn(r, e, t) {
		if (typeof r == "string") return Do(r, e);
		if (ArrayBuffer.isView(r)) return Oo(r);
		if (r == null) throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof r);
		if (ue(r, ArrayBuffer) || r && ue(r.buffer, ArrayBuffer) || typeof SharedArrayBuffer < "u" && (ue(r, SharedArrayBuffer) || r && ue(r.buffer, SharedArrayBuffer))) return jt(r, e, t);
		if (typeof r == "number") throw new TypeError("The \"value\" argument must not be of type number. Received type number");
		let n = r.valueOf && r.valueOf();
		if (n != null && n !== r) return h.from(n, e, t);
		let i = qo(r);
		if (i) return i;
		if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof r[Symbol.toPrimitive] == "function") return h.from(r[Symbol.toPrimitive]("string"), e, t);
		throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof r);
	}
	a(Gn, "from");
	h.from = function(r, e, t) {
		return Gn(r, e, t);
	};
	Object.setPrototypeOf(h.prototype, Uint8Array.prototype);
	Object.setPrototypeOf(h, Uint8Array);
	function Vn(r) {
		if (typeof r != "number") throw new TypeError("\"size\" argument must be of type number");
		if (r < 0) throw new RangeError("The value \"" + r + "\" is invalid for option \"size\"");
	}
	a(Vn, "assertSize");
	function Uo(r, e, t) {
		return Vn(r), r <= 0 ? he(r) : e !== void 0 ? typeof t == "string" ? he(r).fill(e, t) : he(r).fill(e) : he(r);
	}
	a(Uo, "alloc");
	h.alloc = function(r, e, t) {
		return Uo(r, e, t);
	};
	function $t(r) {
		return Vn(r), he(r < 0 ? 0 : Gt(r) | 0);
	}
	a($t, "allocUnsafe");
	h.allocUnsafe = function(r) {
		return $t(r);
	};
	h.allocUnsafeSlow = function(r) {
		return $t(r);
	};
	function Do(r, e) {
		if ((typeof e != "string" || e === "") && (e = "utf8"), !h.isEncoding(e)) throw new TypeError("Unknown encoding: " + e);
		let t = zn(r, e) | 0, n = he(t), i = n.write(r, e);
		return i !== t && (n = n.slice(0, i)), n;
	}
	a(Do, "fromString");
	function Wt(r) {
		let e = r.length < 0 ? 0 : Gt(r.length) | 0, t = he(e);
		for (let n = 0; n < e; n += 1) t[n] = r[n] & 255;
		return t;
	}
	a(Wt, "fromArrayLike");
	function Oo(r) {
		if (ue(r, Uint8Array)) {
			let e = new Uint8Array(r);
			return jt(e.buffer, e.byteOffset, e.byteLength);
		}
		return Wt(r);
	}
	a(Oo, "fromArrayView");
	function jt(r, e, t) {
		if (e < 0 || r.byteLength < e) throw new RangeError("\"offset\" is outside of buffer bounds");
		if (r.byteLength < e + (t || 0)) throw new RangeError("\"length\" is outside of buffer bounds");
		let n;
		return e === void 0 && t === void 0 ? n = new Uint8Array(r) : t === void 0 ? n = new Uint8Array(r, e) : n = new Uint8Array(r, e, t), Object.setPrototypeOf(n, h.prototype), n;
	}
	a(jt, "fromArrayBuffer");
	function qo(r) {
		if (h.isBuffer(r)) {
			let e = Gt(r.length) | 0, t = he(e);
			return t.length === 0 || r.copy(t, 0, 0, e), t;
		}
		if (r.length !== void 0) return typeof r.length != "number" || zt(r.length) ? he(0) : Wt(r);
		if (r.type === "Buffer" && Array.isArray(r.data)) return Wt(r.data);
	}
	a(qo, "fromObject");
	function Gt(r) {
		if (r >= ft) throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + ft.toString(16) + " bytes");
		return r | 0;
	}
	a(Gt, "checked");
	function Qo(r) {
		return +r != r && (r = 0), h.alloc(+r);
	}
	a(Qo, "SlowBuffer");
	h.isBuffer = a(function(e) {
		return e != null && e._isBuffer === !0 && e !== h.prototype;
	}, "isBuffer");
	h.compare = a(function(e, t) {
		if (ue(e, Uint8Array) && (e = h.from(e, e.offset, e.byteLength)), ue(t, Uint8Array) && (t = h.from(t, t.offset, t.byteLength)), !h.isBuffer(e) || !h.isBuffer(t)) throw new TypeError("The \"buf1\", \"buf2\" arguments must be one of type Buffer or Uint8Array");
		if (e === t) return 0;
		let n = e.length, i = t.length;
		for (let s = 0, o = Math.min(n, i); s < o; ++s) if (e[s] !== t[s]) {
			n = e[s], i = t[s];
			break;
		}
		return n < i ? -1 : i < n ? 1 : 0;
	}, "compare");
	h.isEncoding = a(function(e) {
		switch (String(e).toLowerCase()) {
			case "hex":
			case "utf8":
			case "utf-8":
			case "ascii":
			case "latin1":
			case "binary":
			case "base64":
			case "ucs2":
			case "ucs-2":
			case "utf16le":
			case "utf-16le": return !0;
			default: return !1;
		}
	}, "isEncoding");
	h.concat = a(function(e, t) {
		if (!Array.isArray(e)) throw new TypeError("\"list\" argument must be an Array of Buffers");
		if (e.length === 0) return h.alloc(0);
		let n;
		if (t === void 0) for (t = 0, n = 0; n < e.length; ++n) t += e[n].length;
		let i = h.allocUnsafe(t), s = 0;
		for (n = 0; n < e.length; ++n) {
			let o = e[n];
			if (ue(o, Uint8Array)) s + o.length > i.length ? (h.isBuffer(o) || (o = h.from(o)), o.copy(i, s)) : Uint8Array.prototype.set.call(i, o, s);
			else if (h.isBuffer(o)) o.copy(i, s);
			else throw new TypeError("\"list\" argument must be an Array of Buffers");
			s += o.length;
		}
		return i;
	}, "concat");
	function zn(r, e) {
		if (h.isBuffer(r)) return r.length;
		if (ArrayBuffer.isView(r) || ue(r, ArrayBuffer)) return r.byteLength;
		if (typeof r != "string") throw new TypeError("The \"string\" argument must be one of type string, Buffer, or ArrayBuffer. Received type " + typeof r);
		let t = r.length, n = arguments.length > 2 && arguments[2] === !0;
		if (!n && t === 0) return 0;
		let i = !1;
		for (;;) switch (e) {
			case "ascii":
			case "latin1":
			case "binary": return t;
			case "utf8":
			case "utf-8": return Ht(r).length;
			case "ucs2":
			case "ucs-2":
			case "utf16le":
			case "utf-16le": return t * 2;
			case "hex": return t >>> 1;
			case "base64": return ni(r).length;
			default:
				if (i) return n ? -1 : Ht(r).length;
				e = ("" + e).toLowerCase(), i = !0;
		}
	}
	a(zn, "byteLength");
	h.byteLength = zn;
	function No(r, e, t) {
		let n = !1;
		if ((e === void 0 || e < 0) && (e = 0), e > this.length || ((t === void 0 || t > this.length) && (t = this.length), t <= 0) || (t >>>= 0, e >>>= 0, t <= e)) return "";
		for (r || (r = "utf8");;) switch (r) {
			case "hex": return Zo(this, e, t);
			case "utf8":
			case "utf-8": return Yn(this, e, t);
			case "ascii": return Ko(this, e, t);
			case "latin1":
			case "binary": return Yo(this, e, t);
			case "base64": return Vo(this, e, t);
			case "ucs2":
			case "ucs-2":
			case "utf16le":
			case "utf-16le": return Jo(this, e, t);
			default:
				if (n) throw new TypeError("Unknown encoding: " + r);
				r = (r + "").toLowerCase(), n = !0;
		}
	}
	a(No, "slowToString");
	h.prototype._isBuffer = !0;
	function Ae(r, e, t) {
		let n = r[e];
		r[e] = r[t], r[t] = n;
	}
	a(Ae, "swap");
	h.prototype.swap16 = a(function() {
		let e = this.length;
		if (e % 2 !== 0) throw new RangeError("Buffer size must be a multiple of 16-bits");
		for (let t = 0; t < e; t += 2) Ae(this, t, t + 1);
		return this;
	}, "swap16");
	h.prototype.swap32 = a(function() {
		let e = this.length;
		if (e % 4 !== 0) throw new RangeError("Buffer size must be a multiple of 32-bits");
		for (let t = 0; t < e; t += 4) Ae(this, t, t + 3), Ae(this, t + 1, t + 2);
		return this;
	}, "swap32");
	h.prototype.swap64 = a(function() {
		let e = this.length;
		if (e % 8 !== 0) throw new RangeError("Buffer size must be a multiple of 64-bits");
		for (let t = 0; t < e; t += 8) Ae(this, t, t + 7), Ae(this, t + 1, t + 6), Ae(this, t + 2, t + 5), Ae(this, t + 3, t + 4);
		return this;
	}, "swap64");
	h.prototype.toString = a(function() {
		let e = this.length;
		return e === 0 ? "" : arguments.length === 0 ? Yn(this, 0, e) : No.apply(this, arguments);
	}, "toString");
	h.prototype.toLocaleString = h.prototype.toString;
	h.prototype.equals = a(function(e) {
		if (!h.isBuffer(e)) throw new TypeError("Argument must be a Buffer");
		return this === e ? !0 : h.compare(this, e) === 0;
	}, "equals");
	h.prototype.inspect = a(function() {
		let e = "", t = Be.INSPECT_MAX_BYTES;
		return e = this.toString("hex", 0, t).replace(/(.{2})/g, "$1 ").trim(), this.length > t && (e += " ... "), "<Buffer " + e + ">";
	}, "inspect");
	Wn && (h.prototype[Wn] = h.prototype.inspect);
	h.prototype.compare = a(function(e, t, n, i, s) {
		if (ue(e, Uint8Array) && (e = h.from(e, e.offset, e.byteLength)), !h.isBuffer(e)) throw new TypeError("The \"target\" argument must be one of type Buffer or Uint8Array. Received type " + typeof e);
		if (t === void 0 && (t = 0), n === void 0 && (n = e ? e.length : 0), i === void 0 && (i = 0), s === void 0 && (s = this.length), t < 0 || n > e.length || i < 0 || s > this.length) throw new RangeError("out of range index");
		if (i >= s && t >= n) return 0;
		if (i >= s) return -1;
		if (t >= n) return 1;
		if (t >>>= 0, n >>>= 0, i >>>= 0, s >>>= 0, this === e) return 0;
		let o = s - i, u = n - t, c = Math.min(o, u), l = this.slice(i, s), f = e.slice(t, n);
		for (let y = 0; y < c; ++y) if (l[y] !== f[y]) {
			o = l[y], u = f[y];
			break;
		}
		return o < u ? -1 : u < o ? 1 : 0;
	}, "compare");
	function Kn(r, e, t, n, i) {
		if (r.length === 0) return -1;
		if (typeof t == "string" ? (n = t, t = 0) : t > 2147483647 ? t = 2147483647 : t < -2147483648 && (t = -2147483648), t = +t, zt(t) && (t = i ? 0 : r.length - 1), t < 0 && (t = r.length + t), t >= r.length) {
			if (i) return -1;
			t = r.length - 1;
		} else if (t < 0) if (i) t = 0;
		else return -1;
		if (typeof e == "string" && (e = h.from(e, n)), h.isBuffer(e)) return e.length === 0 ? -1 : jn(r, e, t, n, i);
		if (typeof e == "number") return e = e & 255, typeof Uint8Array.prototype.indexOf == "function" ? i ? Uint8Array.prototype.indexOf.call(r, e, t) : Uint8Array.prototype.lastIndexOf.call(r, e, t) : jn(r, [e], t, n, i);
		throw new TypeError("val must be string, number or Buffer");
	}
	a(Kn, "bidirectionalIndexOf");
	function jn(r, e, t, n, i) {
		let s = 1, o = r.length, u = e.length;
		if (n !== void 0 && (n = String(n).toLowerCase(), n === "ucs2" || n === "ucs-2" || n === "utf16le" || n === "utf-16le")) {
			if (r.length < 2 || e.length < 2) return -1;
			s = 2, o /= 2, u /= 2, t /= 2;
		}
		function c(f, y) {
			return s === 1 ? f[y] : f.readUInt16BE(y * s);
		}
		a(c, "read");
		let l;
		if (i) {
			let f = -1;
			for (l = t; l < o; l++) if (c(r, l) === c(e, f === -1 ? 0 : l - f)) {
				if (f === -1 && (f = l), l - f + 1 === u) return f * s;
			} else f !== -1 && (l -= l - f), f = -1;
		} else for (t + u > o && (t = o - u), l = t; l >= 0; l--) {
			let f = !0;
			for (let y = 0; y < u; y++) if (c(r, l + y) !== c(e, y)) {
				f = !1;
				break;
			}
			if (f) return l;
		}
		return -1;
	}
	a(jn, "arrayIndexOf");
	h.prototype.includes = a(function(e, t, n) {
		return this.indexOf(e, t, n) !== -1;
	}, "includes");
	h.prototype.indexOf = a(function(e, t, n) {
		return Kn(this, e, t, n, !0);
	}, "indexOf");
	h.prototype.lastIndexOf = a(function(e, t, n) {
		return Kn(this, e, t, n, !1);
	}, "lastIndexOf");
	function Wo(r, e, t, n) {
		t = Number(t) || 0;
		let i = r.length - t;
		n ? (n = Number(n), n > i && (n = i)) : n = i;
		let s = e.length;
		n > s / 2 && (n = s / 2);
		let o;
		for (o = 0; o < n; ++o) {
			let u = parseInt(e.substr(o * 2, 2), 16);
			if (zt(u)) return o;
			r[t + o] = u;
		}
		return o;
	}
	a(Wo, "hexWrite");
	function jo(r, e, t, n) {
		return ht(Ht(e, r.length - t), r, t, n);
	}
	a(jo, "utf8Write");
	function Ho(r, e, t, n) {
		return ht(ra(e), r, t, n);
	}
	a(Ho, "asciiWrite");
	function $o(r, e, t, n) {
		return ht(ni(e), r, t, n);
	}
	a($o, "base64Write");
	function Go(r, e, t, n) {
		return ht(na(e, r.length - t), r, t, n);
	}
	a(Go, "ucs2Write");
	h.prototype.write = a(function(e, t, n, i) {
		if (t === void 0) i = "utf8", n = this.length, t = 0;
		else if (n === void 0 && typeof t == "string") i = t, n = this.length, t = 0;
		else if (isFinite(t)) t = t >>> 0, isFinite(n) ? (n = n >>> 0, i === void 0 && (i = "utf8")) : (i = n, n = void 0);
		else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
		let s = this.length - t;
		if ((n === void 0 || n > s) && (n = s), e.length > 0 && (n < 0 || t < 0) || t > this.length) throw new RangeError("Attempt to write outside buffer bounds");
		i || (i = "utf8");
		let o = !1;
		for (;;) switch (i) {
			case "hex": return Wo(this, e, t, n);
			case "utf8":
			case "utf-8": return jo(this, e, t, n);
			case "ascii":
			case "latin1":
			case "binary": return Ho(this, e, t, n);
			case "base64": return $o(this, e, t, n);
			case "ucs2":
			case "ucs-2":
			case "utf16le":
			case "utf-16le": return Go(this, e, t, n);
			default:
				if (o) throw new TypeError("Unknown encoding: " + i);
				i = ("" + i).toLowerCase(), o = !0;
		}
	}, "write");
	h.prototype.toJSON = a(function() {
		return {
			type: "Buffer",
			data: Array.prototype.slice.call(this._arr || this, 0)
		};
	}, "toJSON");
	function Vo(r, e, t) {
		return e === 0 && t === r.length ? Nt.fromByteArray(r) : Nt.fromByteArray(r.slice(e, t));
	}
	a(Vo, "base64Slice");
	function Yn(r, e, t) {
		t = Math.min(r.length, t);
		let n = [], i = e;
		for (; i < t;) {
			let s = r[i], o = null, u = s > 239 ? 4 : s > 223 ? 3 : s > 191 ? 2 : 1;
			if (i + u <= t) {
				let c, l, f, y;
				switch (u) {
					case 1:
						s < 128 && (o = s);
						break;
					case 2:
						c = r[i + 1], (c & 192) === 128 && (y = (s & 31) << 6 | c & 63, y > 127 && (o = y));
						break;
					case 3:
						c = r[i + 1], l = r[i + 2], (c & 192) === 128 && (l & 192) === 128 && (y = (s & 15) << 12 | (c & 63) << 6 | l & 63, y > 2047 && (y < 55296 || y > 57343) && (o = y));
						break;
					case 4: c = r[i + 1], l = r[i + 2], f = r[i + 3], (c & 192) === 128 && (l & 192) === 128 && (f & 192) === 128 && (y = (s & 15) << 18 | (c & 63) << 12 | (l & 63) << 6 | f & 63, y > 65535 && y < 1114112 && (o = y));
				}
			}
			o === null ? (o = 65533, u = 1) : o > 65535 && (o -= 65536, n.push(o >>> 10 & 1023 | 55296), o = 56320 | o & 1023), n.push(o), i += u;
		}
		return zo(n);
	}
	a(Yn, "utf8Slice");
	var Hn = 4096;
	function zo(r) {
		let e = r.length;
		if (e <= Hn) return String.fromCharCode.apply(String, r);
		let t = "", n = 0;
		for (; n < e;) t += String.fromCharCode.apply(String, r.slice(n, n += Hn));
		return t;
	}
	a(zo, "decodeCodePointsArray");
	function Ko(r, e, t) {
		let n = "";
		t = Math.min(r.length, t);
		for (let i = e; i < t; ++i) n += String.fromCharCode(r[i] & 127);
		return n;
	}
	a(Ko, "asciiSlice");
	function Yo(r, e, t) {
		let n = "";
		t = Math.min(r.length, t);
		for (let i = e; i < t; ++i) n += String.fromCharCode(r[i]);
		return n;
	}
	a(Yo, "latin1Slice");
	function Zo(r, e, t) {
		let n = r.length;
		(!e || e < 0) && (e = 0), (!t || t < 0 || t > n) && (t = n);
		let i = "";
		for (let s = e; s < t; ++s) i += ia[r[s]];
		return i;
	}
	a(Zo, "hexSlice");
	function Jo(r, e, t) {
		let n = r.slice(e, t), i = "";
		for (let s = 0; s < n.length - 1; s += 2) i += String.fromCharCode(n[s] + n[s + 1] * 256);
		return i;
	}
	a(Jo, "utf16leSlice");
	h.prototype.slice = a(function(e, t) {
		let n = this.length;
		e = ~~e, t = t === void 0 ? n : ~~t, e < 0 ? (e += n, e < 0 && (e = 0)) : e > n && (e = n), t < 0 ? (t += n, t < 0 && (t = 0)) : t > n && (t = n), t < e && (t = e);
		let i = this.subarray(e, t);
		return Object.setPrototypeOf(i, h.prototype), i;
	}, "slice");
	function q(r, e, t) {
		if (r % 1 !== 0 || r < 0) throw new RangeError("offset is not uint");
		if (r + e > t) throw new RangeError("Trying to access beyond buffer length");
	}
	a(q, "checkOffset");
	h.prototype.readUintLE = h.prototype.readUIntLE = a(function(e, t, n) {
		e = e >>> 0, t = t >>> 0, n || q(e, t, this.length);
		let i = this[e], s = 1, o = 0;
		for (; ++o < t && (s *= 256);) i += this[e + o] * s;
		return i;
	}, "readUIntLE");
	h.prototype.readUintBE = h.prototype.readUIntBE = a(function(e, t, n) {
		e = e >>> 0, t = t >>> 0, n || q(e, t, this.length);
		let i = this[e + --t], s = 1;
		for (; t > 0 && (s *= 256);) i += this[e + --t] * s;
		return i;
	}, "readUIntBE");
	h.prototype.readUint8 = h.prototype.readUInt8 = a(function(e, t) {
		return e = e >>> 0, t || q(e, 1, this.length), this[e];
	}, "readUInt8");
	h.prototype.readUint16LE = h.prototype.readUInt16LE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 2, this.length), this[e] | this[e + 1] << 8;
	}, "readUInt16LE");
	h.prototype.readUint16BE = h.prototype.readUInt16BE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 2, this.length), this[e] << 8 | this[e + 1];
	}, "readUInt16BE");
	h.prototype.readUint32LE = h.prototype.readUInt32LE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 4, this.length), (this[e] | this[e + 1] << 8 | this[e + 2] << 16) + this[e + 3] * 16777216;
	}, "readUInt32LE");
	h.prototype.readUint32BE = h.prototype.readUInt32BE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 4, this.length), this[e] * 16777216 + (this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3]);
	}, "readUInt32BE");
	h.prototype.readBigUInt64LE = we(a(function(e) {
		e = e >>> 0, Re(e, "offset");
		let t = this[e], n = this[e + 7];
		(t === void 0 || n === void 0) && je(e, this.length - 8);
		let i = t + this[++e] * 256 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24, s = this[++e] + this[++e] * 256 + this[++e] * 2 ** 16 + n * 2 ** 24;
		return BigInt(i) + (BigInt(s) << BigInt(32));
	}, "readBigUInt64LE"));
	h.prototype.readBigUInt64BE = we(a(function(e) {
		e = e >>> 0, Re(e, "offset");
		let t = this[e], n = this[e + 7];
		(t === void 0 || n === void 0) && je(e, this.length - 8);
		let i = t * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 256 + this[++e], s = this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 256 + n;
		return (BigInt(i) << BigInt(32)) + BigInt(s);
	}, "readBigUInt64BE"));
	h.prototype.readIntLE = a(function(e, t, n) {
		e = e >>> 0, t = t >>> 0, n || q(e, t, this.length);
		let i = this[e], s = 1, o = 0;
		for (; ++o < t && (s *= 256);) i += this[e + o] * s;
		return s *= 128, i >= s && (i -= Math.pow(2, 8 * t)), i;
	}, "readIntLE");
	h.prototype.readIntBE = a(function(e, t, n) {
		e = e >>> 0, t = t >>> 0, n || q(e, t, this.length);
		let i = t, s = 1, o = this[e + --i];
		for (; i > 0 && (s *= 256);) o += this[e + --i] * s;
		return s *= 128, o >= s && (o -= Math.pow(2, 8 * t)), o;
	}, "readIntBE");
	h.prototype.readInt8 = a(function(e, t) {
		return e = e >>> 0, t || q(e, 1, this.length), this[e] & 128 ? (255 - this[e] + 1) * -1 : this[e];
	}, "readInt8");
	h.prototype.readInt16LE = a(function(e, t) {
		e = e >>> 0, t || q(e, 2, this.length);
		let n = this[e] | this[e + 1] << 8;
		return n & 32768 ? n | 4294901760 : n;
	}, "readInt16LE");
	h.prototype.readInt16BE = a(function(e, t) {
		e = e >>> 0, t || q(e, 2, this.length);
		let n = this[e + 1] | this[e] << 8;
		return n & 32768 ? n | 4294901760 : n;
	}, "readInt16BE");
	h.prototype.readInt32LE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 4, this.length), this[e] | this[e + 1] << 8 | this[e + 2] << 16 | this[e + 3] << 24;
	}, "readInt32LE");
	h.prototype.readInt32BE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 4, this.length), this[e] << 24 | this[e + 1] << 16 | this[e + 2] << 8 | this[e + 3];
	}, "readInt32BE");
	h.prototype.readBigInt64LE = we(a(function(e) {
		e = e >>> 0, Re(e, "offset");
		let t = this[e], n = this[e + 7];
		(t === void 0 || n === void 0) && je(e, this.length - 8);
		let i = this[e + 4] + this[e + 5] * 256 + this[e + 6] * 2 ** 16 + (n << 24);
		return (BigInt(i) << BigInt(32)) + BigInt(t + this[++e] * 256 + this[++e] * 2 ** 16 + this[++e] * 2 ** 24);
	}, "readBigInt64LE"));
	h.prototype.readBigInt64BE = we(a(function(e) {
		e = e >>> 0, Re(e, "offset");
		let t = this[e], n = this[e + 7];
		(t === void 0 || n === void 0) && je(e, this.length - 8);
		let i = (t << 24) + this[++e] * 2 ** 16 + this[++e] * 256 + this[++e];
		return (BigInt(i) << BigInt(32)) + BigInt(this[++e] * 2 ** 24 + this[++e] * 2 ** 16 + this[++e] * 256 + n);
	}, "readBigInt64BE"));
	h.prototype.readFloatLE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 4, this.length), Pe.read(this, e, !0, 23, 4);
	}, "readFloatLE");
	h.prototype.readFloatBE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 4, this.length), Pe.read(this, e, !1, 23, 4);
	}, "readFloatBE");
	h.prototype.readDoubleLE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 8, this.length), Pe.read(this, e, !0, 52, 8);
	}, "readDoubleLE");
	h.prototype.readDoubleBE = a(function(e, t) {
		return e = e >>> 0, t || q(e, 8, this.length), Pe.read(this, e, !1, 52, 8);
	}, "readDoubleBE");
	function V(r, e, t, n, i, s) {
		if (!h.isBuffer(r)) throw new TypeError("\"buffer\" argument must be a Buffer instance");
		if (e > i || e < s) throw new RangeError("\"value\" argument is out of bounds");
		if (t + n > r.length) throw new RangeError("Index out of range");
	}
	a(V, "checkInt");
	h.prototype.writeUintLE = h.prototype.writeUIntLE = a(function(e, t, n, i) {
		if (e = +e, t = t >>> 0, n = n >>> 0, !i) {
			let u = Math.pow(2, 8 * n) - 1;
			V(this, e, t, n, u, 0);
		}
		let s = 1, o = 0;
		for (this[t] = e & 255; ++o < n && (s *= 256);) this[t + o] = e / s & 255;
		return t + n;
	}, "writeUIntLE");
	h.prototype.writeUintBE = h.prototype.writeUIntBE = a(function(e, t, n, i) {
		if (e = +e, t = t >>> 0, n = n >>> 0, !i) {
			let u = Math.pow(2, 8 * n) - 1;
			V(this, e, t, n, u, 0);
		}
		let s = n - 1, o = 1;
		for (this[t + s] = e & 255; --s >= 0 && (o *= 256);) this[t + s] = e / o & 255;
		return t + n;
	}, "writeUIntBE");
	h.prototype.writeUint8 = h.prototype.writeUInt8 = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 1, 255, 0), this[t] = e & 255, t + 1;
	}, "writeUInt8");
	h.prototype.writeUint16LE = h.prototype.writeUInt16LE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 2, 65535, 0), this[t] = e & 255, this[t + 1] = e >>> 8, t + 2;
	}, "writeUInt16LE");
	h.prototype.writeUint16BE = h.prototype.writeUInt16BE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 2, 65535, 0), this[t] = e >>> 8, this[t + 1] = e & 255, t + 2;
	}, "writeUInt16BE");
	h.prototype.writeUint32LE = h.prototype.writeUInt32LE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 4, 4294967295, 0), this[t + 3] = e >>> 24, this[t + 2] = e >>> 16, this[t + 1] = e >>> 8, this[t] = e & 255, t + 4;
	}, "writeUInt32LE");
	h.prototype.writeUint32BE = h.prototype.writeUInt32BE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 4, 4294967295, 0), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
	}, "writeUInt32BE");
	function Zn(r, e, t, n, i) {
		ri(e, n, i, r, t, 7);
		let s = Number(e & BigInt(4294967295));
		r[t++] = s, s = s >> 8, r[t++] = s, s = s >> 8, r[t++] = s, s = s >> 8, r[t++] = s;
		let o = Number(e >> BigInt(32) & BigInt(4294967295));
		return r[t++] = o, o = o >> 8, r[t++] = o, o = o >> 8, r[t++] = o, o = o >> 8, r[t++] = o, t;
	}
	a(Zn, "wrtBigUInt64LE");
	function Jn(r, e, t, n, i) {
		ri(e, n, i, r, t, 7);
		let s = Number(e & BigInt(4294967295));
		r[t + 7] = s, s = s >> 8, r[t + 6] = s, s = s >> 8, r[t + 5] = s, s = s >> 8, r[t + 4] = s;
		let o = Number(e >> BigInt(32) & BigInt(4294967295));
		return r[t + 3] = o, o = o >> 8, r[t + 2] = o, o = o >> 8, r[t + 1] = o, o = o >> 8, r[t] = o, t + 8;
	}
	a(Jn, "wrtBigUInt64BE");
	h.prototype.writeBigUInt64LE = we(a(function(e, t = 0) {
		return Zn(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
	}, "writeBigUInt64LE"));
	h.prototype.writeBigUInt64BE = we(a(function(e, t = 0) {
		return Jn(this, e, t, BigInt(0), BigInt("0xffffffffffffffff"));
	}, "writeBigUInt64BE"));
	h.prototype.writeIntLE = a(function(e, t, n, i) {
		if (e = +e, t = t >>> 0, !i) {
			let c = Math.pow(2, 8 * n - 1);
			V(this, e, t, n, c - 1, -c);
		}
		let s = 0, o = 1, u = 0;
		for (this[t] = e & 255; ++s < n && (o *= 256);) e < 0 && u === 0 && this[t + s - 1] !== 0 && (u = 1), this[t + s] = (e / o >> 0) - u & 255;
		return t + n;
	}, "writeIntLE");
	h.prototype.writeIntBE = a(function(e, t, n, i) {
		if (e = +e, t = t >>> 0, !i) {
			let c = Math.pow(2, 8 * n - 1);
			V(this, e, t, n, c - 1, -c);
		}
		let s = n - 1, o = 1, u = 0;
		for (this[t + s] = e & 255; --s >= 0 && (o *= 256);) e < 0 && u === 0 && this[t + s + 1] !== 0 && (u = 1), this[t + s] = (e / o >> 0) - u & 255;
		return t + n;
	}, "writeIntBE");
	h.prototype.writeInt8 = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 1, 127, -128), e < 0 && (e = 255 + e + 1), this[t] = e & 255, t + 1;
	}, "writeInt8");
	h.prototype.writeInt16LE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 2, 32767, -32768), this[t] = e & 255, this[t + 1] = e >>> 8, t + 2;
	}, "writeInt16LE");
	h.prototype.writeInt16BE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 2, 32767, -32768), this[t] = e >>> 8, this[t + 1] = e & 255, t + 2;
	}, "writeInt16BE");
	h.prototype.writeInt32LE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 4, 2147483647, -2147483648), this[t] = e & 255, this[t + 1] = e >>> 8, this[t + 2] = e >>> 16, this[t + 3] = e >>> 24, t + 4;
	}, "writeInt32LE");
	h.prototype.writeInt32BE = a(function(e, t, n) {
		return e = +e, t = t >>> 0, n || V(this, e, t, 4, 2147483647, -2147483648), e < 0 && (e = 4294967295 + e + 1), this[t] = e >>> 24, this[t + 1] = e >>> 16, this[t + 2] = e >>> 8, this[t + 3] = e & 255, t + 4;
	}, "writeInt32BE");
	h.prototype.writeBigInt64LE = we(a(function(e, t = 0) {
		return Zn(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
	}, "writeBigInt64LE"));
	h.prototype.writeBigInt64BE = we(a(function(e, t = 0) {
		return Jn(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
	}, "writeBigInt64BE"));
	function Xn(r, e, t, n, i, s) {
		if (t + n > r.length) throw new RangeError("Index out of range");
		if (t < 0) throw new RangeError("Index out of range");
	}
	a(Xn, "checkIEEE754");
	function ei(r, e, t, n, i) {
		return e = +e, t = t >>> 0, i || Xn(r, e, t, 4, 34028234663852886e22, -34028234663852886e22), Pe.write(r, e, t, n, 23, 4), t + 4;
	}
	a(ei, "writeFloat");
	h.prototype.writeFloatLE = a(function(e, t, n) {
		return ei(this, e, t, !0, n);
	}, "writeFloatLE");
	h.prototype.writeFloatBE = a(function(e, t, n) {
		return ei(this, e, t, !1, n);
	}, "writeFloatBE");
	function ti(r, e, t, n, i) {
		return e = +e, t = t >>> 0, i || Xn(r, e, t, 8, 17976931348623157e292, -17976931348623157e292), Pe.write(r, e, t, n, 52, 8), t + 8;
	}
	a(ti, "writeDouble");
	h.prototype.writeDoubleLE = a(function(e, t, n) {
		return ti(this, e, t, !0, n);
	}, "writeDoubleLE");
	h.prototype.writeDoubleBE = a(function(e, t, n) {
		return ti(this, e, t, !1, n);
	}, "writeDoubleBE");
	h.prototype.copy = a(function(e, t, n, i) {
		if (!h.isBuffer(e)) throw new TypeError("argument should be a Buffer");
		if (n || (n = 0), !i && i !== 0 && (i = this.length), t >= e.length && (t = e.length), t || (t = 0), i > 0 && i < n && (i = n), i === n || e.length === 0 || this.length === 0) return 0;
		if (t < 0) throw new RangeError("targetStart out of bounds");
		if (n < 0 || n >= this.length) throw new RangeError("Index out of range");
		if (i < 0) throw new RangeError("sourceEnd out of bounds");
		i > this.length && (i = this.length), e.length - t < i - n && (i = e.length - t + n);
		let s = i - n;
		return this === e && typeof Uint8Array.prototype.copyWithin == "function" ? this.copyWithin(t, n, i) : Uint8Array.prototype.set.call(e, this.subarray(n, i), t), s;
	}, "copy");
	h.prototype.fill = a(function(e, t, n, i) {
		if (typeof e == "string") {
			if (typeof t == "string" ? (i = t, t = 0, n = this.length) : typeof n == "string" && (i = n, n = this.length), i !== void 0 && typeof i != "string") throw new TypeError("encoding must be a string");
			if (typeof i == "string" && !h.isEncoding(i)) throw new TypeError("Unknown encoding: " + i);
			if (e.length === 1) {
				let o = e.charCodeAt(0);
				(i === "utf8" && o < 128 || i === "latin1") && (e = o);
			}
		} else typeof e == "number" ? e = e & 255 : typeof e == "boolean" && (e = Number(e));
		if (t < 0 || this.length < t || this.length < n) throw new RangeError("Out of range index");
		if (n <= t) return this;
		t = t >>> 0, n = n === void 0 ? this.length : n >>> 0, e || (e = 0);
		let s;
		if (typeof e == "number") for (s = t; s < n; ++s) this[s] = e;
		else {
			let o = h.isBuffer(e) ? e : h.from(e, i), u = o.length;
			if (u === 0) throw new TypeError("The value \"" + e + "\" is invalid for argument \"value\"");
			for (s = 0; s < n - t; ++s) this[s + t] = o[s % u];
		}
		return this;
	}, "fill");
	var Te = {};
	function Vt(r, e, t) {
		var n;
		Te[r] = (n = class extends t {
			constructor() {
				super(), Object.defineProperty(this, "message", {
					value: e.apply(this, arguments),
					writable: !0,
					configurable: !0
				}), this.name = `${this.name} [${r}]`, this.stack, delete this.name;
			}
			get code() {
				return r;
			}
			set code(s) {
				Object.defineProperty(this, "code", {
					configurable: !0,
					enumerable: !0,
					value: s,
					writable: !0
				});
			}
			toString() {
				return `${this.name} [${r}\
]: ${this.message}`;
			}
		}, a(n, "NodeError"), n);
	}
	a(Vt, "E");
	Vt("ERR_BUFFER_OUT_OF_BOUNDS", function(r) {
		return r ? `${r} is outside of buffer bounds` : "Attempt to access memory outside buffer bounds";
	}, RangeError);
	Vt("ERR_INVALID_ARG_TYPE", function(r, e) {
		return `The "${r}" argument must be of type number. Received typ\
e ${typeof e}`;
	}, TypeError);
	Vt("ERR_OUT_OF_RANGE", function(r, e, t) {
		let n = `The value of "${r}" is out o\
f range.`, i = t;
		return Number.isInteger(t) && Math.abs(t) > 2 ** 32 ? i = $n(String(t)) : typeof t == "bigint" && (i = String(t), (t > BigInt(2) ** BigInt(32) || t < -(BigInt(2) ** BigInt(32))) && (i = $n(i)), i += "n"), n += ` It must be ${e}. Re\
ceived ${i}`, n;
	}, RangeError);
	function $n(r) {
		let e = "", t = r.length, n = r[0] === "-" ? 1 : 0;
		for (; t >= n + 4; t -= 3) e = `\
_${r.slice(t - 3, t)}${e}`;
		return `${r.slice(0, t)}${e}`;
	}
	a($n, "addNumericalSeparator");
	function Xo(r, e, t) {
		Re(e, "offset"), (r[e] === void 0 || r[e + t] === void 0) && je(e, r.length - (t + 1));
	}
	a(Xo, "checkBounds");
	function ri(r, e, t, n, i, s) {
		if (r > t || r < e) {
			let o = typeof e == "bigint" ? "n" : "", u;
			throw s > 3 ? e === 0 || e === BigInt(0) ? u = `>= 0${o} and < 2${o}\
 ** ${(s + 1) * 8}${o}` : u = `>= -(2${o} ** ${(s + 1) * 8 - 1}${o}) and < 2 ** ${(s + 1) * 8 - 1}${o}` : u = `>= ${e}${o} a\
nd <= ${t}${o}`, new Te.ERR_OUT_OF_RANGE("value", u, r);
		}
		Xo(n, i, s);
	}
	a(ri, "checkIntBI");
	function Re(r, e) {
		if (typeof r != "number") throw new Te.ERR_INVALID_ARG_TYPE(e, "number", r);
	}
	a(Re, "validateNumber");
	function je(r, e, t) {
		throw Math.floor(r) !== r ? (Re(r, t), new Te.ERR_OUT_OF_RANGE(t || "offset", "an integer", r)) : e < 0 ? new Te.ERR_BUFFER_OUT_OF_BOUNDS() : new Te.ERR_OUT_OF_RANGE(t || "offset", `>= ${t ? 1 : 0} and <= ${e}`, r);
	}
	a(je, "boundsError");
	var ea = /[^+/0-9A-Za-z-_]/g;
	function ta(r) {
		if (r = r.split("=")[0], r = r.trim().replace(ea, ""), r.length < 2) return "";
		for (; r.length % 4 !== 0;) r = r + "=";
		return r;
	}
	a(ta, "base64clean");
	function Ht(r, e) {
		e = e || 1 / 0;
		let t, n = r.length, i = null, s = [];
		for (let o = 0; o < n; ++o) {
			if (t = r.charCodeAt(o), t > 55295 && t < 57344) {
				if (!i) {
					if (t > 56319) {
						(e -= 3) > -1 && s.push(239, 191, 189);
						continue;
					} else if (o + 1 === n) {
						(e -= 3) > -1 && s.push(239, 191, 189);
						continue;
					}
					i = t;
					continue;
				}
				if (t < 56320) {
					(e -= 3) > -1 && s.push(239, 191, 189), i = t;
					continue;
				}
				t = (i - 55296 << 10 | t - 56320) + 65536;
			} else i && (e -= 3) > -1 && s.push(239, 191, 189);
			if (i = null, t < 128) {
				if ((e -= 1) < 0) break;
				s.push(t);
			} else if (t < 2048) {
				if ((e -= 2) < 0) break;
				s.push(t >> 6 | 192, t & 63 | 128);
			} else if (t < 65536) {
				if ((e -= 3) < 0) break;
				s.push(t >> 12 | 224, t >> 6 & 63 | 128, t & 63 | 128);
			} else if (t < 1114112) {
				if ((e -= 4) < 0) break;
				s.push(t >> 18 | 240, t >> 12 & 63 | 128, t >> 6 & 63 | 128, t & 63 | 128);
			} else throw new Error("Invalid code point");
		}
		return s;
	}
	a(Ht, "utf8ToBytes");
	function ra(r) {
		let e = [];
		for (let t = 0; t < r.length; ++t) e.push(r.charCodeAt(t) & 255);
		return e;
	}
	a(ra, "asciiToBytes");
	function na(r, e) {
		let t, n, i, s = [];
		for (let o = 0; o < r.length && !((e -= 2) < 0); ++o) t = r.charCodeAt(o), n = t >> 8, i = t % 256, s.push(i), s.push(n);
		return s;
	}
	a(na, "utf16leToBytes");
	function ni(r) {
		return Nt.toByteArray(ta(r));
	}
	a(ni, "base64ToBytes");
	function ht(r, e, t, n) {
		let i;
		for (i = 0; i < n && !(i + t >= e.length || i >= r.length); ++i) e[i + t] = r[i];
		return i;
	}
	a(ht, "blitBuffer");
	function ue(r, e) {
		return r instanceof e || r != null && r.constructor != null && r.constructor.name != null && r.constructor.name === e.name;
	}
	a(ue, "isInstance");
	function zt(r) {
		return r !== r;
	}
	a(zt, "numberIsNaN");
	var ia = function() {
		let r = "0123456789abcdef", e = new Array(256);
		for (let t = 0; t < 16; ++t) {
			let n = t * 16;
			for (let i = 0; i < 16; ++i) e[n + i] = r[t] + r[i];
		}
		return e;
	}();
	function we(r) {
		return typeof BigInt > "u" ? sa : r;
	}
	a(we, "defineBigIntMethod");
	function sa() {
		throw new Error("BigInt not supported");
	}
	a(sa, "BufferBigIntNotDefined");
});
var b;
var v;
var d;
var m;
var p = G(() => {
	"use strict";
	b = globalThis, v = globalThis.setImmediate ?? ((r) => setTimeout(r, 0)), globalThis.clearImmediate, d = typeof globalThis.Buffer == "function" && typeof globalThis.Buffer.allocUnsafe == "function" ? globalThis.Buffer : ii().Buffer, m = globalThis.process ?? {};
	m.env ?? (m.env = {});
	try {
		m.nextTick(() => {});
	} catch {
		let e = Promise.resolve();
		m.nextTick = e.then.bind(e);
	}
});
var ge = T((Bl, Kt) => {
	"use strict";
	p();
	var Le = typeof Reflect == "object" ? Reflect : null, si = Le && typeof Le.apply == "function" ? Le.apply : a(function(e, t, n) {
		return Function.prototype.apply.call(e, t, n);
	}, "ReflectApply"), pt;
	Le && typeof Le.ownKeys == "function" ? pt = Le.ownKeys : Object.getOwnPropertySymbols ? pt = a(function(e) {
		return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e));
	}, "ReflectOwnKeys") : pt = a(function(e) {
		return Object.getOwnPropertyNames(e);
	}, "ReflectOwnKeys");
	function oa(r) {
		console && console.warn && console.warn(r);
	}
	a(oa, "ProcessEmitWarning");
	var ai = Number.isNaN || a(function(e) {
		return e !== e;
	}, "NumberIsNaN");
	function R() {
		R.init.call(this);
	}
	a(R, "EventEmitter");
	Kt.exports = R;
	Kt.exports.once = la;
	R.EventEmitter = R;
	R.prototype._events = void 0;
	R.prototype._eventsCount = 0;
	R.prototype._maxListeners = void 0;
	var oi = 10;
	function dt(r) {
		if (typeof r != "function") throw new TypeError("The \"listener\" argument must be of type Function. Received type " + typeof r);
	}
	a(dt, "checkListener");
	Object.defineProperty(R, "defaultMaxListeners", {
		enumerable: !0,
		get: a(function() {
			return oi;
		}, "get"),
		set: a(function(r) {
			if (typeof r != "number" || r < 0 || ai(r)) throw new RangeError("The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received " + r + ".");
			oi = r;
		}, "set")
	});
	R.init = function() {
		(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
	};
	R.prototype.setMaxListeners = a(function(e) {
		if (typeof e != "number" || e < 0 || ai(e)) throw new RangeError("The value of \"n\" is out of range. It must be a non-negative number. Received " + e + ".");
		return this._maxListeners = e, this;
	}, "setMaxListeners");
	function ui(r) {
		return r._maxListeners === void 0 ? R.defaultMaxListeners : r._maxListeners;
	}
	a(ui, "_getMaxListeners");
	R.prototype.getMaxListeners = a(function() {
		return ui(this);
	}, "getMaxListeners");
	R.prototype.emit = a(function(e) {
		for (var t = [], n = 1; n < arguments.length; n++) t.push(arguments[n]);
		var i = e === "error", s = this._events;
		if (s !== void 0) i = i && s.error === void 0;
		else if (!i) return !1;
		if (i) {
			var o;
			if (t.length > 0 && (o = t[0]), o instanceof Error) throw o;
			var u = /* @__PURE__ */ new Error("Unhandled error." + (o ? " (" + o.message + ")" : ""));
			throw u.context = o, u;
		}
		var c = s[e];
		if (c === void 0) return !1;
		if (typeof c == "function") si(c, this, t);
		else for (var l = c.length, f = pi(c, l), n = 0; n < l; ++n) si(f[n], this, t);
		return !0;
	}, "emit");
	function ci(r, e, t, n) {
		var i, s, o;
		if (dt(t), s = r._events, s === void 0 ? (s = r._events = Object.create(null), r._eventsCount = 0) : (s.newListener !== void 0 && (r.emit("newListener", e, t.listener ? t.listener : t), s = r._events), o = s[e]), o === void 0) o = s[e] = t, ++r._eventsCount;
		else if (typeof o == "function" ? o = s[e] = n ? [t, o] : [o, t] : n ? o.unshift(t) : o.push(t), i = ui(r), i > 0 && o.length > i && !o.warned) {
			o.warned = !0;
			var u = /* @__PURE__ */ new Error("Possible EventEmitter memory leak detected. " + o.length + " " + String(e) + " listeners added. Use emitter.setMaxListeners() to increase limit");
			u.name = "MaxListenersExceededWarning", u.emitter = r, u.type = e, u.count = o.length, oa(u);
		}
		return r;
	}
	a(ci, "_addListener");
	R.prototype.addListener = a(function(e, t) {
		return ci(this, e, t, !1);
	}, "addListener");
	R.prototype.on = R.prototype.addListener;
	R.prototype.prependListener = a(function(e, t) {
		return ci(this, e, t, !0);
	}, "prependListener");
	function aa() {
		if (!this.fired) return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
	}
	a(aa, "onceWrapper");
	function li(r, e, t) {
		var n = {
			fired: !1,
			wrapFn: void 0,
			target: r,
			type: e,
			listener: t
		}, i = aa.bind(n);
		return i.listener = t, n.wrapFn = i, i;
	}
	a(li, "_onceWrap");
	R.prototype.once = a(function(e, t) {
		return dt(t), this.on(e, li(this, e, t)), this;
	}, "once");
	R.prototype.prependOnceListener = a(function(e, t) {
		return dt(t), this.prependListener(e, li(this, e, t)), this;
	}, "prependOnceListener");
	R.prototype.removeListener = a(function(e, t) {
		var n, i, s, o, u;
		if (dt(t), i = this._events, i === void 0) return this;
		if (n = i[e], n === void 0) return this;
		if (n === t || n.listener === t) --this._eventsCount === 0 ? this._events = Object.create(null) : (delete i[e], i.removeListener && this.emit("removeListener", e, n.listener || t));
		else if (typeof n != "function") {
			for (s = -1, o = n.length - 1; o >= 0; o--) if (n[o] === t || n[o].listener === t) {
				u = n[o].listener, s = o;
				break;
			}
			if (s < 0) return this;
			s === 0 ? n.shift() : ua(n, s), n.length === 1 && (i[e] = n[0]), i.removeListener !== void 0 && this.emit("removeListener", e, u || t);
		}
		return this;
	}, "removeListener");
	R.prototype.off = R.prototype.removeListener;
	R.prototype.removeAllListeners = a(function(e) {
		var t, n, i;
		if (n = this._events, n === void 0) return this;
		if (n.removeListener === void 0) return arguments.length === 0 ? (this._events = Object.create(null), this._eventsCount = 0) : n[e] !== void 0 && (--this._eventsCount === 0 ? this._events = Object.create(null) : delete n[e]), this;
		if (arguments.length === 0) {
			var s = Object.keys(n), o;
			for (i = 0; i < s.length; ++i) o = s[i], o !== "removeListener" && this.removeAllListeners(o);
			return this.removeAllListeners("removeListener"), this._events = Object.create(null), this._eventsCount = 0, this;
		}
		if (t = n[e], typeof t == "function") this.removeListener(e, t);
		else if (t !== void 0) for (i = t.length - 1; i >= 0; i--) this.removeListener(e, t[i]);
		return this;
	}, "removeAllListeners");
	function fi(r, e, t) {
		var n = r._events;
		if (n === void 0) return [];
		var i = n[e];
		return i === void 0 ? [] : typeof i == "function" ? t ? [i.listener || i] : [i] : t ? ca(i) : pi(i, i.length);
	}
	a(fi, "_listeners");
	R.prototype.listeners = a(function(e) {
		return fi(this, e, !0);
	}, "listeners");
	R.prototype.rawListeners = a(function(e) {
		return fi(this, e, !1);
	}, "rawListeners");
	R.listenerCount = function(r, e) {
		return typeof r.listenerCount == "function" ? r.listenerCount(e) : hi.call(r, e);
	};
	R.prototype.listenerCount = hi;
	function hi(r) {
		var e = this._events;
		if (e !== void 0) {
			var t = e[r];
			if (typeof t == "function") return 1;
			if (t !== void 0) return t.length;
		}
		return 0;
	}
	a(hi, "listenerCount");
	R.prototype.eventNames = a(function() {
		return this._eventsCount > 0 ? pt(this._events) : [];
	}, "eventNames");
	function pi(r, e) {
		for (var t = new Array(e), n = 0; n < e; ++n) t[n] = r[n];
		return t;
	}
	a(pi, "arrayClone");
	function ua(r, e) {
		for (; e + 1 < r.length; e++) r[e] = r[e + 1];
		r.pop();
	}
	a(ua, "spliceOne");
	function ca(r) {
		for (var e = new Array(r.length), t = 0; t < e.length; ++t) e[t] = r[t].listener || r[t];
		return e;
	}
	a(ca, "unwrapListeners");
	function la(r, e) {
		return new Promise(function(t, n) {
			function i(o) {
				r.removeListener(e, s), n(o);
			}
			a(i, "errorListener");
			function s() {
				typeof r.removeListener == "function" && r.removeListener("error", i), t([].slice.call(arguments));
			}
			a(s, "resolver"), di(r, e, s, { once: !0 }), e !== "error" && fa(r, i, { once: !0 });
		});
	}
	a(la, "once");
	function fa(r, e, t) {
		typeof r.on == "function" && di(r, "error", e, t);
	}
	a(fa, "addErrorHandlerIfEventEmitter");
	function di(r, e, t, n) {
		if (typeof r.on == "function") n.once ? r.once(e, t) : r.on(e, t);
		else if (typeof r.addEventListener == "function") r.addEventListener(e, a(function i(s) {
			n.once && r.removeEventListener(e, i), t(s);
		}, "wrapListener"));
		else throw new TypeError("The \"emitter\" argument must be of type EventEmitter. Received type " + typeof r);
	}
	a(di, "eventTargetAgnosticAddListener");
});
var wi = {};
ie(wi, {
	Socket: () => ce,
	isIP: () => ha
});
function ha(r) {
	return 0;
}
var mi;
var yi;
var S;
var ce;
var Fe = G(() => {
	"use s\
trict";
	p();
	mi = Se(ge(), 1);
	a(ha, "isIP");
	yi = /^[^.]+\./, S = class S extends mi.EventEmitter {
		constructor() {
			super(...arguments);
			E(this, "opts", {});
			E(this, "connecting", !1);
			E(this, "pending", !0);
			E(this, "writable", !0);
			E(this, "encrypted", !1);
			E(this, "authorized", !1);
			E(this, "destroyed", !1);
			E(this, "ws", null);
			E(this, "writeBuffer");
			E(this, "tlsState", 0);
			E(this, "tlsRead");
			E(this, "tlsWrite");
		}
		static get poolQueryViaFetch() {
			return S.opts.poolQueryViaFetch ?? S.defaults.poolQueryViaFetch;
		}
		static set poolQueryViaFetch(t) {
			S.opts.poolQueryViaFetch = t;
		}
		static get fetchEndpoint() {
			return S.opts.fetchEndpoint ?? S.defaults.fetchEndpoint;
		}
		static set fetchEndpoint(t) {
			S.opts.fetchEndpoint = t;
		}
		static get fetchConnectionCache() {
			return !0;
		}
		static set fetchConnectionCache(t) {
			console.warn("The `fetchConnectionCache` option is deprecated (now always `true`)");
		}
		static get fetchFunction() {
			return S.opts.fetchFunction ?? S.defaults.fetchFunction;
		}
		static set fetchFunction(t) {
			S.opts.fetchFunction = t;
		}
		static get webSocketConstructor() {
			return S.opts.webSocketConstructor ?? S.defaults.webSocketConstructor;
		}
		static set webSocketConstructor(t) {
			S.opts.webSocketConstructor = t;
		}
		get webSocketConstructor() {
			return this.opts.webSocketConstructor ?? S.webSocketConstructor;
		}
		set webSocketConstructor(t) {
			this.opts.webSocketConstructor = t;
		}
		static get wsProxy() {
			return S.opts.wsProxy ?? S.defaults.wsProxy;
		}
		static set wsProxy(t) {
			S.opts.wsProxy = t;
		}
		get wsProxy() {
			return this.opts.wsProxy ?? S.wsProxy;
		}
		set wsProxy(t) {
			this.opts.wsProxy = t;
		}
		static get coalesceWrites() {
			return S.opts.coalesceWrites ?? S.defaults.coalesceWrites;
		}
		static set coalesceWrites(t) {
			S.opts.coalesceWrites = t;
		}
		get coalesceWrites() {
			return this.opts.coalesceWrites ?? S.coalesceWrites;
		}
		set coalesceWrites(t) {
			this.opts.coalesceWrites = t;
		}
		static get useSecureWebSocket() {
			return S.opts.useSecureWebSocket ?? S.defaults.useSecureWebSocket;
		}
		static set useSecureWebSocket(t) {
			S.opts.useSecureWebSocket = t;
		}
		get useSecureWebSocket() {
			return this.opts.useSecureWebSocket ?? S.useSecureWebSocket;
		}
		set useSecureWebSocket(t) {
			this.opts.useSecureWebSocket = t;
		}
		static get forceDisablePgSSL() {
			return S.opts.forceDisablePgSSL ?? S.defaults.forceDisablePgSSL;
		}
		static set forceDisablePgSSL(t) {
			S.opts.forceDisablePgSSL = t;
		}
		get forceDisablePgSSL() {
			return this.opts.forceDisablePgSSL ?? S.forceDisablePgSSL;
		}
		set forceDisablePgSSL(t) {
			this.opts.forceDisablePgSSL = t;
		}
		static get disableSNI() {
			return S.opts.disableSNI ?? S.defaults.disableSNI;
		}
		static set disableSNI(t) {
			S.opts.disableSNI = t;
		}
		get disableSNI() {
			return this.opts.disableSNI ?? S.disableSNI;
		}
		set disableSNI(t) {
			this.opts.disableSNI = t;
		}
		static get disableWarningInBrowsers() {
			return S.opts.disableWarningInBrowsers ?? S.defaults.disableWarningInBrowsers;
		}
		static set disableWarningInBrowsers(t) {
			S.opts.disableWarningInBrowsers = t;
		}
		get disableWarningInBrowsers() {
			return this.opts.disableWarningInBrowsers ?? S.disableWarningInBrowsers;
		}
		set disableWarningInBrowsers(t) {
			this.opts.disableWarningInBrowsers = t;
		}
		static get pipelineConnect() {
			return S.opts.pipelineConnect ?? S.defaults.pipelineConnect;
		}
		static set pipelineConnect(t) {
			S.opts.pipelineConnect = t;
		}
		get pipelineConnect() {
			return this.opts.pipelineConnect ?? S.pipelineConnect;
		}
		set pipelineConnect(t) {
			this.opts.pipelineConnect = t;
		}
		static get subtls() {
			return S.opts.subtls ?? S.defaults.subtls;
		}
		static set subtls(t) {
			S.opts.subtls = t;
		}
		get subtls() {
			return this.opts.subtls ?? S.subtls;
		}
		set subtls(t) {
			this.opts.subtls = t;
		}
		static get pipelineTLS() {
			return S.opts.pipelineTLS ?? S.defaults.pipelineTLS;
		}
		static set pipelineTLS(t) {
			S.opts.pipelineTLS = t;
		}
		get pipelineTLS() {
			return this.opts.pipelineTLS ?? S.pipelineTLS;
		}
		set pipelineTLS(t) {
			this.opts.pipelineTLS = t;
		}
		static get rootCerts() {
			return S.opts.rootCerts ?? S.defaults.rootCerts;
		}
		static set rootCerts(t) {
			S.opts.rootCerts = t;
		}
		get rootCerts() {
			return this.opts.rootCerts ?? S.rootCerts;
		}
		set rootCerts(t) {
			this.opts.rootCerts = t;
		}
		wsProxyAddrForHost(t, n) {
			let i = this.wsProxy;
			if (i === void 0) throw new Error("No WebSocket proxy is configured. Please see https://github.com/neondatabase/serverless/blob/main/CONFIG.md#wsproxy-string--host-string-port-number--string--string");
			return typeof i == "function" ? i(t, n) : `${i}?address=${t}:${n}`;
		}
		setNoDelay() {
			return this;
		}
		setKeepAlive() {
			return this;
		}
		ref() {
			return this;
		}
		unref() {
			return this;
		}
		connect(t, n, i) {
			this.connecting = !0, i && this.once("connect", i);
			let s = a(() => {
				this.connecting = !1, this.pending = !1, this.emit("connect"), this.emit("ready");
			}, "handleWebSocketOpen"), o = a((c, l = !1) => {
				c.binaryType = "arraybuffer", c.addEventListener("error", (f) => {
					this.emit("error", f), this.emit("close");
				}), c.addEventListener("message", (f) => {
					if (this.tlsState === 0) {
						let y = d.from(f.data);
						this.emit("data", y);
					}
				}), c.addEventListener("close", () => {
					this.emit("close");
				}), l ? s() : c.addEventListener("open", s);
			}, "configureWebSocket"), u;
			try {
				u = this.wsProxyAddrForHost(n, typeof t == "string" ? parseInt(t, 10) : t);
			} catch (c) {
				this.emit("error", c), this.emit("close");
				return;
			}
			try {
				let l = (this.useSecureWebSocket ? "wss:" : "ws:") + "//" + u;
				if (this.webSocketConstructor !== void 0) this.ws = new this.webSocketConstructor(l), o(this.ws);
				else try {
					this.ws = new WebSocket(l), o(this.ws);
				} catch {
					this.ws = new __unstable_WebSocket(l), o(this.ws);
				}
			} catch (c) {
				let f = (this.useSecureWebSocket ? "https:" : "http:") + "//" + u;
				fetch(f, { headers: { Upgrade: "websocket" } }).then((y) => {
					if (this.ws = y.webSocket, this.ws == null) throw c;
					this.ws.accept(), o(this.ws, !0);
				}).catch((y) => {
					this.emit("error", /* @__PURE__ */ new Error(`All attempts to open a WebSocket to connect to the database failed. Please refer \
to https://github.com/neondatabase/serverless/blob/main/CONFIG.md#websocketconstructor-typeof-websoc\
ket--undefined. Details: ${y}`)), this.emit("close");
				});
			}
		}
		async startTls(t) {
			if (this.subtls === void 0) throw new Error("For Postgres SSL connections, you must set `neonConfig.subtls` to the subtls library. See https://github.com/neondatabase/serverless/blob/main/CONFIG.md for more information.");
			this.tlsState = 1;
			let n = await this.subtls.TrustedCert.databaseFromPEM(this.rootCerts), i = new this.subtls.WebSocketReadQueue(this.ws), s = i.read.bind(i), o = this.rawWrite.bind(this), { read: u, write: c } = await this.subtls.startTls(t, n, s, o, {
				useSNI: !this.disableSNI,
				expectPreData: this.pipelineTLS ? new Uint8Array([83]) : void 0
			});
			this.tlsRead = u, this.tlsWrite = c, this.tlsState = 2, this.encrypted = !0, this.authorized = !0, this.emit("secureConnection", this), this.tlsReadLoop();
		}
		async tlsReadLoop() {
			for (;;) {
				let t = await this.tlsRead();
				if (t === void 0) break;
				{
					let n = d.from(t);
					this.emit("data", n);
				}
			}
		}
		rawWrite(t) {
			if (!this.coalesceWrites) {
				this.ws && this.ws.send(t);
				return;
			}
			if (this.writeBuffer === void 0) this.writeBuffer = t, setTimeout(() => {
				this.ws && this.ws.send(this.writeBuffer), this.writeBuffer = void 0;
			}, 0);
			else {
				let n = new Uint8Array(this.writeBuffer.length + t.length);
				n.set(this.writeBuffer), n.set(t, this.writeBuffer.length), this.writeBuffer = n;
			}
		}
		write(t, n = "utf8", i = (s) => {}) {
			return t.length === 0 ? (i(), !0) : (typeof t == "string" && (t = d.from(t, n)), this.tlsState === 0 ? (this.rawWrite(t), i()) : this.tlsState === 1 ? this.once("secureConnection", () => {
				this.write(t, n, i);
			}) : (this.tlsWrite(t), i()), !0);
		}
		end(t = d.alloc(0), n = "utf8", i = () => {}) {
			return this.write(t, n, () => {
				this.ws.close(), i();
			}), this;
		}
		destroy() {
			return this.destroyed = !0, this.end();
		}
	};
	a(S, "Socket"), E(S, "defaults", {
		poolQueryViaFetch: !1,
		fetchEndpoint: a((t, n, i) => {
			let s;
			return i?.jwtAuth ? s = t.replace(yi, "apiauth.") : s = t.replace(yi, "api."), "https://" + s + "/sql";
		}, "fetchEndpoint"),
		fetchConnectionCache: !0,
		fetchFunction: void 0,
		webSocketConstructor: void 0,
		wsProxy: a((t) => t + "/v2", "wsProxy"),
		useSecureWebSocket: !0,
		forceDisablePgSSL: !0,
		coalesceWrites: !0,
		pipelineConnect: "password",
		subtls: void 0,
		rootCerts: "",
		pipelineTLS: !1,
		disableSNI: !1,
		disableWarningInBrowsers: !1
	}), E(S, "opts", {});
	ce = S;
});
var gi = {};
ie(gi, { parse: () => Yt });
function Yt(r, e = !1) {
	let { protocol: t } = new URL(r), n = "http:" + r.substring(t.length), { username: i, password: s, host: o, hostname: u, port: c, pathname: l, search: f, searchParams: y, hash: g } = new URL(n);
	s = decodeURIComponent(s), i = decodeURIComponent(i), l = decodeURIComponent(l);
	let A = i + ":" + s, C = e ? Object.fromEntries(y.entries()) : f;
	return {
		href: r,
		protocol: t,
		auth: A,
		username: i,
		password: s,
		host: o,
		hostname: u,
		port: c,
		pathname: l,
		search: f,
		query: C,
		hash: g
	};
}
var Zt = G(() => {
	"use strict";
	p();
	a(Yt, "parse");
});
var tr = T((Ai) => {
	"use strict";
	p();
	Ai.parse = function(r, e) {
		return new er(r, e).parse();
	};
	var vt = class vt {
		constructor(e, t) {
			this.source = e, this.transform = t || Ca, this.position = 0, this.entries = [], this.recorded = [], this.dimension = 0;
		}
		isEof() {
			return this.position >= this.source.length;
		}
		nextCharacter() {
			var e = this.source[this.position++];
			return e === "\\" ? {
				value: this.source[this.position++],
				escaped: !0
			} : {
				value: e,
				escaped: !1
			};
		}
		record(e) {
			this.recorded.push(e);
		}
		newEntry(e) {
			var t;
			(this.recorded.length > 0 || e) && (t = this.recorded.join(""), t === "NULL" && !e && (t = null), t !== null && (t = this.transform(t)), this.entries.push(t), this.recorded = []);
		}
		consumeDimensions() {
			if (this.source[0] === "[") {
				for (; !this.isEof();) if (this.nextCharacter().value === "=") break;
			}
		}
		parse(e) {
			var t, n, i;
			for (this.consumeDimensions(); !this.isEof();) if (t = this.nextCharacter(), t.value === "{" && !i) this.dimension++, this.dimension > 1 && (n = new vt(this.source.substr(this.position - 1), this.transform), this.entries.push(n.parse(!0)), this.position += n.position - 2);
			else if (t.value === "}" && !i) {
				if (this.dimension--, !this.dimension && (this.newEntry(), e)) return this.entries;
			} else t.value === "\"" && !t.escaped ? (i && this.newEntry(!0), i = !i) : t.value === "," && !i ? this.newEntry() : this.record(t.value);
			if (this.dimension !== 0) throw new Error("array dimension not balanced");
			return this.entries;
		}
	};
	a(vt, "ArrayParser");
	var er = vt;
	function Ca(r) {
		return r;
	}
	a(Ca, "identity");
});
var rr = T((Zl, Ci) => {
	p();
	var _a = tr();
	Ci.exports = { create: a(function(r, e) {
		return { parse: a(function() {
			return _a.parse(r, e);
		}, "parse") };
	}, "create") };
});
var Ti = T((ef, Ii) => {
	"use strict";
	p();
	var Ia = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?.*?( BC)?$/, Ta = /^(\d{1,})-(\d{2})-(\d{2})( BC)?$/, Pa = /([Z+-])(\d{2})?:?(\d{2})?:?(\d{2})?/, Ra = /^-?infinity$/;
	Ii.exports = a(function(e) {
		if (Ra.test(e)) return Number(e.replace("i", "I"));
		var t = Ia.exec(e);
		if (!t) return Ba(e) || null;
		var n = !!t[8], i = parseInt(t[1], 10);
		n && (i = _i(i));
		var s = parseInt(t[2], 10) - 1, o = t[3], u = parseInt(t[4], 10), c = parseInt(t[5], 10), l = parseInt(t[6], 10), f = t[7];
		f = f ? 1e3 * parseFloat(f) : 0;
		var y, g = La(e);
		return g != null ? (y = new Date(Date.UTC(i, s, o, u, c, l, f)), nr(i) && y.setUTCFullYear(i), g !== 0 && y.setTime(y.getTime() - g)) : (y = new Date(i, s, o, u, c, l, f), nr(i) && y.setFullYear(i)), y;
	}, "parseDate");
	function Ba(r) {
		var e = Ta.exec(r);
		if (e) {
			var t = parseInt(e[1], 10);
			e[4] && (t = _i(t));
			var i = parseInt(e[2], 10) - 1, s = e[3], o = new Date(t, i, s);
			return nr(t) && o.setFullYear(t), o;
		}
	}
	a(Ba, "getDate");
	function La(r) {
		if (r.endsWith("+00")) return 0;
		var e = Pa.exec(r.split(" ")[1]);
		if (e) {
			var t = e[1];
			if (t === "Z") return 0;
			var n = t === "-" ? -1 : 1;
			return (parseInt(e[2], 10) * 3600 + parseInt(e[3] || 0, 10) * 60 + parseInt(e[4] || 0, 10)) * n * 1e3;
		}
	}
	a(La, "timeZoneOffset");
	function _i(r) {
		return -(r - 1);
	}
	a(_i, "bcYearToNegativeYear");
	function nr(r) {
		return r >= 0 && r < 100;
	}
	a(nr, "is0To99");
});
var Ri = T((nf, Pi) => {
	p();
	Pi.exports = ka;
	var Fa = Object.prototype.hasOwnProperty;
	function ka(r) {
		for (var e = 1; e < arguments.length; e++) {
			var t = arguments[e];
			for (var n in t) Fa.call(t, n) && (r[n] = t[n]);
		}
		return r;
	}
	a(ka, "extend");
});
var Fi = T((af, Li) => {
	"use strict";
	p();
	var Ma = Ri();
	Li.exports = ke;
	function ke(r) {
		if (!(this instanceof ke)) return new ke(r);
		Ma(this, Va(r));
	}
	a(ke, "PostgresInterval");
	var Ua = [
		"seconds",
		"minutes",
		"hours",
		"days",
		"months",
		"years"
	];
	ke.prototype.toPostgres = function() {
		var r = Ua.filter(this.hasOwnProperty, this);
		return this.milliseconds && r.indexOf("seconds") < 0 && r.push("seconds"), r.length === 0 ? "0" : r.map(function(e) {
			var t = this[e] || 0;
			return e === "seconds" && this.milliseconds && (t = (t + this.milliseconds / 1e3).toFixed(6).replace(/\.?0+$/, "")), t + " " + e;
		}, this).join(" ");
	};
	var Da = {
		years: "Y",
		months: "M",
		days: "D",
		hours: "H",
		minutes: "M",
		seconds: "S"
	}, Oa = [
		"years",
		"months",
		"days"
	], qa = [
		"hours",
		"minutes",
		"seconds"
	];
	ke.prototype.toISOString = ke.prototype.toISO = function() {
		var r = Oa.map(t, this).join(""), e = qa.map(t, this).join("");
		return "P" + r + "T" + e;
		function t(n) {
			var i = this[n] || 0;
			return n === "seconds" && this.milliseconds && (i = (i + this.milliseconds / 1e3).toFixed(6).replace(/0+$/, "")), i + Da[n];
		}
	};
	var ir = "([+-]?\\d+)", Qa = ir + "\\s+years?", Na = ir + "\\s+mons?", Wa = ir + "\\s+days?", Ha = new RegExp([
		Qa,
		Na,
		Wa,
		"([+-])?([\\d]*):(\\d\\d):(\\d\\d)\\.?(\\d{1,6})?"
	].map(function(r) {
		return "(" + r + ")?";
	}).join("\\s*")), Bi = {
		years: 2,
		months: 4,
		days: 6,
		hours: 9,
		minutes: 10,
		seconds: 11,
		milliseconds: 12
	}, $a = [
		"hours",
		"minutes",
		"seconds",
		"milliseconds"
	];
	function Ga(r) {
		var e = r + "000000".slice(r.length);
		return parseInt(e, 10) / 1e3;
	}
	a(Ga, "parseMilliseconds");
	function Va(r) {
		if (!r) return {};
		var e = Ha.exec(r), t = e[8] === "-";
		return Object.keys(Bi).reduce(function(n, i) {
			var o = e[Bi[i]];
			return !o || (o = i === "milliseconds" ? Ga(o) : parseInt(o, 10), !o) || (t && ~$a.indexOf(i) && (o *= -1), n[i] = o), n;
		}, {});
	}
	a(Va, "parse");
});
var Mi = T((lf, ki) => {
	"use strict";
	p();
	ki.exports = a(function(e) {
		if (/^\\x/.test(e)) return new d(e.substr(2), "hex");
		for (var t = "", n = 0; n < e.length;) if (e[n] !== "\\") t += e[n], ++n;
		else if (/[0-7]{3}/.test(e.substr(n + 1, 3))) t += String.fromCharCode(parseInt(e.substr(n + 1, 3), 8)), n += 4;
		else {
			for (var i = 1; n + i < e.length && e[n + i] === "\\";) i++;
			for (var s = 0; s < Math.floor(i / 2); ++s) t += "\\";
			n += Math.floor(i / 2) * 2;
		}
		return new d(t, "binary");
	}, "parseBytea");
});
var Wi = T((pf, Ni) => {
	p();
	var Ve = tr(), ze = rr(), xt = Ti(), Di = Fi(), Oi = Mi();
	function St(r) {
		return a(function(t) {
			return t === null ? t : r(t);
		}, "nullAllowed");
	}
	a(St, "allowNull");
	function qi(r) {
		return r === null ? r : r === "TRUE" || r === "t" || r === "true" || r === "y" || r === "yes" || r === "on" || r === "1";
	}
	a(qi, "parseBool");
	function za(r) {
		return r ? Ve.parse(r, qi) : null;
	}
	a(za, "parseBoolArray");
	function Ka(r) {
		return parseInt(r, 10);
	}
	a(Ka, "parseBaseTenInt");
	function sr(r) {
		return r ? Ve.parse(r, St(Ka)) : null;
	}
	a(sr, "parseIntegerArray");
	function Ya(r) {
		return r ? Ve.parse(r, St(function(e) {
			return Qi(e).trim();
		})) : null;
	}
	a(Ya, "parseBigIntegerArray");
	var Za = a(function(r) {
		if (!r) return null;
		return ze.create(r, function(t) {
			return t !== null && (t = cr(t)), t;
		}).parse();
	}, "parsePointArray"), or = a(function(r) {
		if (!r) return null;
		return ze.create(r, function(t) {
			return t !== null && (t = parseFloat(t)), t;
		}).parse();
	}, "parseFloatArray"), re = a(function(r) {
		if (!r) return null;
		return ze.create(r).parse();
	}, "parseStringArray"), ar = a(function(r) {
		if (!r) return null;
		return ze.create(r, function(t) {
			return t !== null && (t = xt(t)), t;
		}).parse();
	}, "parseDateArray"), Ja = a(function(r) {
		if (!r) return null;
		return ze.create(r, function(t) {
			return t !== null && (t = Di(t)), t;
		}).parse();
	}, "parseIntervalArray"), Xa = a(function(r) {
		return r ? Ve.parse(r, St(Oi)) : null;
	}, "parseByteAArray"), ur = a(function(r) {
		return parseInt(r, 10);
	}, "parseInteger"), Qi = a(function(r) {
		var e = String(r);
		return /^\d+$/.test(e) ? e : r;
	}, "parseBigInteger"), Ui = a(function(r) {
		return r ? Ve.parse(r, St(JSON.parse)) : null;
	}, "parseJsonArray"), cr = a(function(r) {
		return r[0] !== "(" ? null : (r = r.substring(1, r.length - 1).split(","), {
			x: parseFloat(r[0]),
			y: parseFloat(r[1])
		});
	}, "parsePoint"), eu = a(function(r) {
		if (r[0] !== "<" && r[1] !== "(") return null;
		for (var e = "(", t = "", n = !1, i = 2; i < r.length - 1; i++) {
			if (n || (e += r[i]), r[i] === ")") {
				n = !0;
				continue;
			} else if (!n) continue;
			r[i] !== "," && (t += r[i]);
		}
		var s = cr(e);
		return s.radius = parseFloat(t), s;
	}, "parseCircle");
	Ni.exports = { init: a(function(r) {
		r(20, Qi), r(21, ur), r(23, ur), r(26, ur), r(700, parseFloat), r(701, parseFloat), r(16, qi), r(1082, xt), r(1114, xt), r(1184, xt), r(600, cr), r(651, re), r(718, eu), r(1e3, za), r(1001, Xa), r(1005, sr), r(1007, sr), r(1028, sr), r(1016, Ya), r(1017, Za), r(1021, or), r(1022, or), r(1231, or), r(1014, re), r(1015, re), r(1008, re), r(1009, re), r(1040, re), r(1041, re), r(1115, ar), r(1182, ar), r(1185, ar), r(1186, Di), r(1187, Ja), r(17, Oi), r(114, JSON.parse.bind(JSON)), r(3802, JSON.parse.bind(JSON)), r(199, Ui), r(3807, Ui), r(3907, re), r(2951, re), r(791, re), r(1183, re), r(1270, re);
	}, "init") };
});
var Hi = T((mf, ji) => {
	"use strict";
	p();
	var z = 1e6;
	function ru(r) {
		var e = r.readInt32BE(0), t = r.readUInt32BE(4), n = "";
		e < 0 && (e = ~e + (t === 0), t = ~t + 1 >>> 0, n = "-");
		var i = "", s, o, u, c, l, f;
		if (s = e % z, e = e / z >>> 0, o = 4294967296 * s + t, t = o / z >>> 0, u = "" + (o - z * t), t === 0 && e === 0) return n + u + i;
		for (c = "", l = 6 - u.length, f = 0; f < l; f++) c += "0";
		i = c + u + i;
		if (s = e % z, e = e / z >>> 0, o = 4294967296 * s + t, t = o / z >>> 0, u = "" + (o - z * t), t === 0 && e === 0) return n + u + i;
		for (c = "", l = 6 - u.length, f = 0; f < l; f++) c += "0";
		i = c + u + i;
		if (s = e % z, e = e / z >>> 0, o = 4294967296 * s + t, t = o / z >>> 0, u = "" + (o - z * t), t === 0 && e === 0) return n + u + i;
		for (c = "", l = 6 - u.length, f = 0; f < l; f++) c += "0";
		i = c + u + i;
		return s = e % z, o = 4294967296 * s + t, u = "" + o % z, n + u + i;
	}
	a(ru, "readInt8");
	ji.exports = ru;
});
var Ki = T((bf, zi) => {
	p();
	var nu = Hi(), L = a(function(r, e, t, n, i) {
		t = t || 0, n = n || !1, i = i || function(A, C, D) {
			return A * Math.pow(2, D) + C;
		};
		var s = t >> 3, o = a(function(A) {
			return n ? ~A & 255 : A;
		}, "inv"), u = 255, c = 8 - t % 8;
		e < c && (u = 255 << 8 - e & 255, c = e), t && (u = u >> t % 8);
		var l = 0;
		t % 8 + e >= 8 && (l = i(0, o(r[s]) & u, c));
		for (var f = e + t >> 3, y = s + 1; y < f; y++) l = i(l, o(r[y]), 8);
		var g = (e + t) % 8;
		return g > 0 && (l = i(l, o(r[f]) >> 8 - g, g)), l;
	}, "parseBits"), Vi = a(function(r, e, t) {
		var n = Math.pow(2, t - 1) - 1, i = L(r, 1), s = L(r, t, 1);
		if (s === 0) return 0;
		var o = 1, u = a(function(l, f, y) {
			l === 0 && (l = 1);
			for (var g = 1; g <= y; g++) o /= 2, (f & 1 << y - g) > 0 && (l += o);
			return l;
		}, "parsePrecisionBits"), c = L(r, e, t + 1, !1, u);
		return s == Math.pow(2, t + 1) - 1 ? c === 0 ? i === 0 ? 1 / 0 : -1 / 0 : NaN : (i === 0 ? 1 : -1) * Math.pow(2, s - n) * c;
	}, "parseFloatFromBits"), iu = a(function(r) {
		return L(r, 1) == 1 ? -1 * (L(r, 15, 1, !0) + 1) : L(r, 15, 1);
	}, "parseInt16"), $i = a(function(r) {
		return L(r, 1) == 1 ? -1 * (L(r, 31, 1, !0) + 1) : L(r, 31, 1);
	}, "parseInt32"), su = a(function(r) {
		return Vi(r, 23, 8);
	}, "parseFloat32"), ou = a(function(r) {
		return Vi(r, 52, 11);
	}, "parseFloat64"), au = a(function(r) {
		var e = L(r, 16, 32);
		if (e == 49152) return NaN;
		for (var t = Math.pow(1e4, L(r, 16, 16)), n = 0, s = L(r, 16), o = 0; o < s; o++) n += L(r, 16, 64 + 16 * o) * t, t /= 1e4;
		var u = Math.pow(10, L(r, 16, 48));
		return (e === 0 ? 1 : -1) * Math.round(n * u) / u;
	}, "parseNumeric"), Gi = a(function(r, e) {
		var t = L(e, 1), n = L(e, 63, 1), i = /* @__PURE__ */ new Date((t === 0 ? 1 : -1) * n / 1e3 + 9466848e5);
		return r || i.setTime(i.getTime() + i.getTimezoneOffset() * 6e4), i.usec = n % 1e3, i.getMicroSeconds = function() {
			return this.usec;
		}, i.setMicroSeconds = function(s) {
			this.usec = s;
		}, i.getUTCMicroSeconds = function() {
			return this.usec;
		}, i;
	}, "parseDate"), Ke = a(function(r) {
		for (var e = L(r, 32), t = L(r, 32, 32), n = L(r, 32, 64), i = 96, s = [], o = 0; o < e; o++) s[o] = L(r, 32, i), i += 32, i += 32;
		var u = a(function(l) {
			var f = L(r, 32, i);
			if (i += 32, f == 4294967295) return null;
			var y;
			if (l == 23 || l == 20) return y = L(r, f * 8, i), i += f * 8, y;
			if (l == 25) return y = r.toString(this.encoding, i >> 3, (i += f << 3) >> 3), y;
			console.log("ERROR: ElementType not implemented: " + l);
		}, "parseElement"), c = a(function(l, f) {
			var y = [], g;
			if (l.length > 1) {
				var A = l.shift();
				for (g = 0; g < A; g++) y[g] = c(l, f);
				l.unshift(A);
			} else for (g = 0; g < l[0]; g++) y[g] = u(f);
			return y;
		}, "parse");
		return c(s, n);
	}, "parseArray"), uu = a(function(r) {
		return r.toString("utf8");
	}, "parseText"), cu = a(function(r) {
		return r === null ? null : L(r, 8) > 0;
	}, "parseBool");
	zi.exports = { init: a(function(r) {
		r(20, nu), r(21, iu), r(23, $i), r(26, $i), r(1700, au), r(700, su), r(701, ou), r(16, cu), r(1114, Gi.bind(null, !1)), r(1184, Gi.bind(null, !0)), r(1e3, Ke), r(1007, Ke), r(1016, Ke), r(1008, Ke), r(1009, Ke), r(25, uu);
	}, "init") };
});
var Zi = T((Sf, Yi) => {
	p();
	Yi.exports = {
		BOOL: 16,
		BYTEA: 17,
		CHAR: 18,
		INT8: 20,
		INT2: 21,
		INT4: 23,
		REGPROC: 24,
		TEXT: 25,
		OID: 26,
		TID: 27,
		XID: 28,
		CID: 29,
		JSON: 114,
		XML: 142,
		PG_NODE_TREE: 194,
		SMGR: 210,
		PATH: 602,
		POLYGON: 604,
		CIDR: 650,
		FLOAT4: 700,
		FLOAT8: 701,
		ABSTIME: 702,
		RELTIME: 703,
		TINTERVAL: 704,
		CIRCLE: 718,
		MACADDR8: 774,
		MONEY: 790,
		MACADDR: 829,
		INET: 869,
		ACLITEM: 1033,
		BPCHAR: 1042,
		VARCHAR: 1043,
		DATE: 1082,
		TIME: 1083,
		TIMESTAMP: 1114,
		TIMESTAMPTZ: 1184,
		INTERVAL: 1186,
		TIMETZ: 1266,
		BIT: 1560,
		VARBIT: 1562,
		NUMERIC: 1700,
		REFCURSOR: 1790,
		REGPROCEDURE: 2202,
		REGOPER: 2203,
		REGOPERATOR: 2204,
		REGCLASS: 2205,
		REGTYPE: 2206,
		UUID: 2950,
		TXID_SNAPSHOT: 2970,
		PG_LSN: 3220,
		PG_NDISTINCT: 3361,
		PG_DEPENDENCIES: 3402,
		TSVECTOR: 3614,
		TSQUERY: 3615,
		GTSVECTOR: 3642,
		REGCONFIG: 3734,
		REGDICTIONARY: 3769,
		JSONB: 3802,
		REGNAMESPACE: 4089,
		REGROLE: 4096
	};
});
var Je = T((Ze) => {
	p();
	var fu = Wi(), hu = Ki(), pu = rr(), du = Zi();
	Ze.getTypeParser = yu;
	Ze.setTypeParser = mu;
	Ze.arrayParser = pu;
	Ze.builtins = du;
	var Ye = {
		text: {},
		binary: {}
	};
	function Ji(r) {
		return String(r);
	}
	a(Ji, "noParse");
	function yu(r, e) {
		return e = e || "text", Ye[e] && Ye[e][r] || Ji;
	}
	a(yu, "getTypeParser");
	function mu(r, e, t) {
		typeof e == "function" && (t = e, e = "text"), Ye[e][r] = t;
	}
	a(mu, "setTypeParser");
	fu.init(function(r, e) {
		Ye.text[r] = e;
	});
	hu.init(function(r, e) {
		Ye.binary[r] = e;
	});
});
var At = T((If, Xi) => {
	"use strict";
	p();
	var wu = Je();
	function Et(r) {
		this._types = r || wu, this.text = {}, this.binary = {};
	}
	a(Et, "TypeOverrides");
	Et.prototype.getOverrides = function(r) {
		switch (r) {
			case "text": return this.text;
			case "binary": return this.binary;
			default: return {};
		}
	};
	Et.prototype.setTypeParser = function(r, e, t) {
		typeof e == "function" && (t = e, e = "text"), this.getOverrides(e)[r] = t;
	};
	Et.prototype.getTypeParser = function(r, e) {
		return e = e || "text", this.getOverrides(e)[r] || this._types.getTypeParser(r, e);
	};
	Xi.exports = Et;
});
function Xe(r) {
	let e = 1779033703, t = 3144134277, n = 1013904242, i = 2773480762, s = 1359893119, o = 2600822924, u = 528734635, c = 1541459225, l = 0, f = 0, y = [
		1116352408,
		1899447441,
		3049323471,
		3921009573,
		961987163,
		1508970993,
		2453635748,
		2870763221,
		3624381080,
		310598401,
		607225278,
		1426881987,
		1925078388,
		2162078206,
		2614888103,
		3248222580,
		3835390401,
		4022224774,
		264347078,
		604807628,
		770255983,
		1249150122,
		1555081692,
		1996064986,
		2554220882,
		2821834349,
		2952996808,
		3210313671,
		3336571891,
		3584528711,
		113926993,
		338241895,
		666307205,
		773529912,
		1294757372,
		1396182291,
		1695183700,
		1986661051,
		2177026350,
		2456956037,
		2730485921,
		2820302411,
		3259730800,
		3345764771,
		3516065817,
		3600352804,
		4094571909,
		275423344,
		430227734,
		506948616,
		659060556,
		883997877,
		958139571,
		1322822218,
		1537002063,
		1747873779,
		1955562222,
		2024104815,
		2227730452,
		2361852424,
		2428436474,
		2756734187,
		3204031479,
		3329325298
	], g = a((I, w) => I >>> w | I << 32 - w, "rrot"), A = /* @__PURE__ */ new Uint32Array(64), C = /* @__PURE__ */ new Uint8Array(64), D = a(() => {
		for (let B = 0, j = 0; B < 16; B++, j += 4) A[B] = C[j] << 24 | C[j + 1] << 16 | C[j + 2] << 8 | C[j + 3];
		for (let B = 16; B < 64; B++) {
			let j = g(A[B - 15], 7) ^ g(A[B - 15], 18) ^ A[B - 15] >>> 3, le = g(A[B - 2], 17) ^ g(A[B - 2], 19) ^ A[B - 2] >>> 10;
			A[B] = A[B - 16] + j + A[B - 7] + le | 0;
		}
		let I = e, w = t, Z = n, W = i, J = s, X = o, se = u, oe = c;
		for (let B = 0; B < 64; B++) {
			let j = g(J, 6) ^ g(J, 11) ^ g(J, 25), le = J & X ^ ~J & se, de = oe + j + le + y[B] + A[B] | 0, _e = (g(I, 2) ^ g(I, 13) ^ g(I, 22)) + (I & w ^ I & Z ^ w & Z) | 0;
			oe = se, se = X, X = J, J = W + de | 0, W = Z, Z = w, w = I, I = de + _e | 0;
		}
		e = e + I | 0, t = t + w | 0, n = n + Z | 0, i = i + W | 0, s = s + J | 0, o = o + X | 0, u = u + se | 0, c = c + oe | 0, f = 0;
	}, "process"), Y = a((I) => {
		typeof I == "string" && (I = new TextEncoder().encode(I));
		for (let w = 0; w < I.length; w++) C[f++] = I[w], f === 64 && D();
		l += I.length;
	}, "add"), P = a(() => {
		if (C[f++] = 128, f == 64 && D(), f + 8 > 64) {
			for (; f < 64;) C[f++] = 0;
			D();
		}
		for (; f < 58;) C[f++] = 0;
		let I = l * 8;
		C[f++] = I / 1099511627776 & 255, C[f++] = I / 4294967296 & 255, C[f++] = I >>> 24, C[f++] = I >>> 16 & 255, C[f++] = I >>> 8 & 255, C[f++] = I & 255, D();
		let w = /* @__PURE__ */ new Uint8Array(32);
		return w[0] = e >>> 24, w[1] = e >>> 16 & 255, w[2] = e >>> 8 & 255, w[3] = e & 255, w[4] = t >>> 24, w[5] = t >>> 16 & 255, w[6] = t >>> 8 & 255, w[7] = t & 255, w[8] = n >>> 24, w[9] = n >>> 16 & 255, w[10] = n >>> 8 & 255, w[11] = n & 255, w[12] = i >>> 24, w[13] = i >>> 16 & 255, w[14] = i >>> 8 & 255, w[15] = i & 255, w[16] = s >>> 24, w[17] = s >>> 16 & 255, w[18] = s >>> 8 & 255, w[19] = s & 255, w[20] = o >>> 24, w[21] = o >>> 16 & 255, w[22] = o >>> 8 & 255, w[23] = o & 255, w[24] = u >>> 24, w[25] = u >>> 16 & 255, w[26] = u >>> 8 & 255, w[27] = u & 255, w[28] = c >>> 24, w[29] = c >>> 16 & 255, w[30] = c >>> 8 & 255, w[31] = c & 255, w;
	}, "digest");
	return r === void 0 ? {
		add: Y,
		digest: P
	} : (Y(r), P());
}
var es = G(() => {
	"use strict";
	p();
	a(Xe, "sha256");
});
var U;
var et;
var ts = G(() => {
	"use strict";
	p();
	U = class U {
		constructor() {
			E(this, "_dataLength", 0);
			E(this, "_bufferLength", 0);
			E(this, "_state", /* @__PURE__ */ new Int32Array(4));
			E(this, "_buffer", /* @__PURE__ */ new ArrayBuffer(68));
			E(this, "_buffer8");
			E(this, "_buffer32");
			this._buffer8 = new Uint8Array(this._buffer, 0, 68), this._buffer32 = new Uint32Array(this._buffer, 0, 17), this.start();
		}
		static hashByteArray(e, t = !1) {
			return this.onePassHasher.start().appendByteArray(e).end(t);
		}
		static hashStr(e, t = !1) {
			return this.onePassHasher.start().appendStr(e).end(t);
		}
		static hashAsciiStr(e, t = !1) {
			return this.onePassHasher.start().appendAsciiStr(e).end(t);
		}
		static _hex(e) {
			let t = U.hexChars, n = U.hexOut, i, s, o, u;
			for (u = 0; u < 4; u += 1) for (s = u * 8, i = e[u], o = 0; o < 8; o += 2) n[s + 1 + o] = t.charAt(i & 15), i >>>= 4, n[s + 0 + o] = t.charAt(i & 15), i >>>= 4;
			return n.join("");
		}
		static _md5cycle(e, t) {
			let n = e[0], i = e[1], s = e[2], o = e[3];
			n += (i & s | ~i & o) + t[0] - 680876936 | 0, n = (n << 7 | n >>> 25) + i | 0, o += (n & i | ~n & s) + t[1] - 389564586 | 0, o = (o << 12 | o >>> 20) + n | 0, s += (o & n | ~o & i) + t[2] + 606105819 | 0, s = (s << 17 | s >>> 15) + o | 0, i += (s & o | ~s & n) + t[3] - 1044525330 | 0, i = (i << 22 | i >>> 10) + s | 0, n += (i & s | ~i & o) + t[4] - 176418897 | 0, n = (n << 7 | n >>> 25) + i | 0, o += (n & i | ~n & s) + t[5] + 1200080426 | 0, o = (o << 12 | o >>> 20) + n | 0, s += (o & n | ~o & i) + t[6] - 1473231341 | 0, s = (s << 17 | s >>> 15) + o | 0, i += (s & o | ~s & n) + t[7] - 45705983 | 0, i = (i << 22 | i >>> 10) + s | 0, n += (i & s | ~i & o) + t[8] + 1770035416 | 0, n = (n << 7 | n >>> 25) + i | 0, o += (n & i | ~n & s) + t[9] - 1958414417 | 0, o = (o << 12 | o >>> 20) + n | 0, s += (o & n | ~o & i) + t[10] - 42063 | 0, s = (s << 17 | s >>> 15) + o | 0, i += (s & o | ~s & n) + t[11] - 1990404162 | 0, i = (i << 22 | i >>> 10) + s | 0, n += (i & s | ~i & o) + t[12] + 1804603682 | 0, n = (n << 7 | n >>> 25) + i | 0, o += (n & i | ~n & s) + t[13] - 40341101 | 0, o = (o << 12 | o >>> 20) + n | 0, s += (o & n | ~o & i) + t[14] - 1502002290 | 0, s = (s << 17 | s >>> 15) + o | 0, i += (s & o | ~s & n) + t[15] + 1236535329 | 0, i = (i << 22 | i >>> 10) + s | 0, n += (i & o | s & ~o) + t[1] - 165796510 | 0, n = (n << 5 | n >>> 27) + i | 0, o += (n & s | i & ~s) + t[6] - 1069501632 | 0, o = (o << 9 | o >>> 23) + n | 0, s += (o & i | n & ~i) + t[11] + 643717713 | 0, s = (s << 14 | s >>> 18) + o | 0, i += (s & n | o & ~n) + t[0] - 373897302 | 0, i = (i << 20 | i >>> 12) + s | 0, n += (i & o | s & ~o) + t[5] - 701558691 | 0, n = (n << 5 | n >>> 27) + i | 0, o += (n & s | i & ~s) + t[10] + 38016083 | 0, o = (o << 9 | o >>> 23) + n | 0, s += (o & i | n & ~i) + t[15] - 660478335 | 0, s = (s << 14 | s >>> 18) + o | 0, i += (s & n | o & ~n) + t[4] - 405537848 | 0, i = (i << 20 | i >>> 12) + s | 0, n += (i & o | s & ~o) + t[9] + 568446438 | 0, n = (n << 5 | n >>> 27) + i | 0, o += (n & s | i & ~s) + t[14] - 1019803690 | 0, o = (o << 9 | o >>> 23) + n | 0, s += (o & i | n & ~i) + t[3] - 187363961 | 0, s = (s << 14 | s >>> 18) + o | 0, i += (s & n | o & ~n) + t[8] + 1163531501 | 0, i = (i << 20 | i >>> 12) + s | 0, n += (i & o | s & ~o) + t[13] - 1444681467 | 0, n = (n << 5 | n >>> 27) + i | 0, o += (n & s | i & ~s) + t[2] - 51403784 | 0, o = (o << 9 | o >>> 23) + n | 0, s += (o & i | n & ~i) + t[7] + 1735328473 | 0, s = (s << 14 | s >>> 18) + o | 0, i += (s & n | o & ~n) + t[12] - 1926607734 | 0, i = (i << 20 | i >>> 12) + s | 0, n += (i ^ s ^ o) + t[5] - 378558 | 0, n = (n << 4 | n >>> 28) + i | 0, o += (n ^ i ^ s) + t[8] - 2022574463 | 0, o = (o << 11 | o >>> 21) + n | 0, s += (o ^ n ^ i) + t[11] + 1839030562 | 0, s = (s << 16 | s >>> 16) + o | 0, i += (s ^ o ^ n) + t[14] - 35309556 | 0, i = (i << 23 | i >>> 9) + s | 0, n += (i ^ s ^ o) + t[1] - 1530992060 | 0, n = (n << 4 | n >>> 28) + i | 0, o += (n ^ i ^ s) + t[4] + 1272893353 | 0, o = (o << 11 | o >>> 21) + n | 0, s += (o ^ n ^ i) + t[7] - 155497632 | 0, s = (s << 16 | s >>> 16) + o | 0, i += (s ^ o ^ n) + t[10] - 1094730640 | 0, i = (i << 23 | i >>> 9) + s | 0, n += (i ^ s ^ o) + t[13] + 681279174 | 0, n = (n << 4 | n >>> 28) + i | 0, o += (n ^ i ^ s) + t[0] - 358537222 | 0, o = (o << 11 | o >>> 21) + n | 0, s += (o ^ n ^ i) + t[3] - 722521979 | 0, s = (s << 16 | s >>> 16) + o | 0, i += (s ^ o ^ n) + t[6] + 76029189 | 0, i = (i << 23 | i >>> 9) + s | 0, n += (i ^ s ^ o) + t[9] - 640364487 | 0, n = (n << 4 | n >>> 28) + i | 0, o += (n ^ i ^ s) + t[12] - 421815835 | 0, o = (o << 11 | o >>> 21) + n | 0, s += (o ^ n ^ i) + t[15] + 530742520 | 0, s = (s << 16 | s >>> 16) + o | 0, i += (s ^ o ^ n) + t[2] - 995338651 | 0, i = (i << 23 | i >>> 9) + s | 0, n += (s ^ (i | ~o)) + t[0] - 198630844 | 0, n = (n << 6 | n >>> 26) + i | 0, o += (i ^ (n | ~s)) + t[7] + 1126891415 | 0, o = (o << 10 | o >>> 22) + n | 0, s += (n ^ (o | ~i)) + t[14] - 1416354905 | 0, s = (s << 15 | s >>> 17) + o | 0, i += (o ^ (s | ~n)) + t[5] - 57434055 | 0, i = (i << 21 | i >>> 11) + s | 0, n += (s ^ (i | ~o)) + t[12] + 1700485571 | 0, n = (n << 6 | n >>> 26) + i | 0, o += (i ^ (n | ~s)) + t[3] - 1894986606 | 0, o = (o << 10 | o >>> 22) + n | 0, s += (n ^ (o | ~i)) + t[10] - 1051523 | 0, s = (s << 15 | s >>> 17) + o | 0, i += (o ^ (s | ~n)) + t[1] - 2054922799 | 0, i = (i << 21 | i >>> 11) + s | 0, n += (s ^ (i | ~o)) + t[8] + 1873313359 | 0, n = (n << 6 | n >>> 26) + i | 0, o += (i ^ (n | ~s)) + t[15] - 30611744 | 0, o = (o << 10 | o >>> 22) + n | 0, s += (n ^ (o | ~i)) + t[6] - 1560198380 | 0, s = (s << 15 | s >>> 17) + o | 0, i += (o ^ (s | ~n)) + t[13] + 1309151649 | 0, i = (i << 21 | i >>> 11) + s | 0, n += (s ^ (i | ~o)) + t[4] - 145523070 | 0, n = (n << 6 | n >>> 26) + i | 0, o += (i ^ (n | ~s)) + t[11] - 1120210379 | 0, o = (o << 10 | o >>> 22) + n | 0, s += (n ^ (o | ~i)) + t[2] + 718787259 | 0, s = (s << 15 | s >>> 17) + o | 0, i += (o ^ (s | ~n)) + t[9] - 343485551 | 0, i = (i << 21 | i >>> 11) + s | 0, e[0] = n + e[0] | 0, e[1] = i + e[1] | 0, e[2] = s + e[2] | 0, e[3] = o + e[3] | 0;
		}
		start() {
			return this._dataLength = 0, this._bufferLength = 0, this._state.set(U.stateIdentity), this;
		}
		appendStr(e) {
			let t = this._buffer8, n = this._buffer32, i = this._bufferLength, s, o;
			for (o = 0; o < e.length; o += 1) {
				if (s = e.charCodeAt(o), s < 128) t[i++] = s;
				else if (s < 2048) t[i++] = (s >>> 6) + 192, t[i++] = s & 63 | 128;
				else if (s < 55296 || s > 56319) t[i++] = (s >>> 12) + 224, t[i++] = s >>> 6 & 63 | 128, t[i++] = s & 63 | 128;
				else {
					if (s = (s - 55296) * 1024 + (e.charCodeAt(++o) - 56320) + 65536, s > 1114111) throw new Error("Unicode standard supports code points up to U+10FFFF");
					t[i++] = (s >>> 18) + 240, t[i++] = s >>> 12 & 63 | 128, t[i++] = s >>> 6 & 63 | 128, t[i++] = s & 63 | 128;
				}
				i >= 64 && (this._dataLength += 64, U._md5cycle(this._state, n), i -= 64, n[0] = n[16]);
			}
			return this._bufferLength = i, this;
		}
		appendAsciiStr(e) {
			let t = this._buffer8, n = this._buffer32, i = this._bufferLength, s, o = 0;
			for (;;) {
				for (s = Math.min(e.length - o, 64 - i); s--;) t[i++] = e.charCodeAt(o++);
				if (i < 64) break;
				this._dataLength += 64, U._md5cycle(this._state, n), i = 0;
			}
			return this._bufferLength = i, this;
		}
		appendByteArray(e) {
			let t = this._buffer8, n = this._buffer32, i = this._bufferLength, s, o = 0;
			for (;;) {
				for (s = Math.min(e.length - o, 64 - i); s--;) t[i++] = e[o++];
				if (i < 64) break;
				this._dataLength += 64, U._md5cycle(this._state, n), i = 0;
			}
			return this._bufferLength = i, this;
		}
		getState() {
			let e = this._state;
			return {
				buffer: String.fromCharCode.apply(null, Array.from(this._buffer8)),
				buflen: this._bufferLength,
				length: this._dataLength,
				state: [
					e[0],
					e[1],
					e[2],
					e[3]
				]
			};
		}
		setState(e) {
			let t = e.buffer, n = e.state, i = this._state, s;
			for (this._dataLength = e.length, this._bufferLength = e.buflen, i[0] = n[0], i[1] = n[1], i[2] = n[2], i[3] = n[3], s = 0; s < t.length; s += 1) this._buffer8[s] = t.charCodeAt(s);
		}
		end(e = !1) {
			let t = this._bufferLength, n = this._buffer8, i = this._buffer32, s = (t >> 2) + 1;
			this._dataLength += t;
			let o = this._dataLength * 8;
			if (n[t] = 128, n[t + 1] = n[t + 2] = n[t + 3] = 0, i.set(U.buffer32Identity.subarray(s), s), t > 55 && (U._md5cycle(this._state, i), i.set(U.buffer32Identity)), o <= 4294967295) i[14] = o;
			else {
				let u = o.toString(16).match(/(.*?)(.{0,8})$/);
				if (u === null) return;
				let c = parseInt(u[2], 16), l = parseInt(u[1], 16) || 0;
				i[14] = c, i[15] = l;
			}
			return U._md5cycle(this._state, i), e ? this._state : U._hex(this._state);
		}
	};
	a(U, "Md5"), E(U, "stateIdentity", new Int32Array([
		1732584193,
		-271733879,
		-1732584194,
		271733878
	])), E(U, "buffer32Identity", new Int32Array([
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	])), E(U, "hexChars", "0123456789abcdef"), E(U, "hexOut", []), E(U, "onePassHasher", new U());
	et = U;
});
var lr = {};
ie(lr, {
	createHash: () => bu,
	createHmac: () => vu,
	randomBytes: () => gu
});
function gu(r) {
	return crypto.getRandomValues(d.alloc(r));
}
function bu(r) {
	if (r === "sha256") return { update: a(function(e) {
		return { digest: a(function() {
			return d.from(Xe(e));
		}, "digest") };
	}, "update") };
	if (r === "md5") return { update: a(function(e) {
		return { digest: a(function() {
			return typeof e == "string" ? et.hashStr(e) : et.hashByteArray(e);
		}, "digest") };
	}, "update") };
	throw new Error(`Hash type '${r}' not supported`);
}
function vu(r, e) {
	if (r !== "sha256") throw new Error(`\
Only sha256 is supported (requested: '${r}')`);
	return { update: a(function(t) {
		return { digest: a(function() {
			typeof e == "string" && (e = new TextEncoder().encode(e)), typeof t == "string" && (t = new TextEncoder().encode(t));
			let n = e.length;
			if (n > 64) e = Xe(e);
			else if (n < 64) {
				let c = /* @__PURE__ */ new Uint8Array(64);
				c.set(e), e = c;
			}
			let i = /* @__PURE__ */ new Uint8Array(64), s = /* @__PURE__ */ new Uint8Array(64);
			for (let c = 0; c < 64; c++) i[c] = 54 ^ e[c], s[c] = 92 ^ e[c];
			let o = new Uint8Array(t.length + 64);
			o.set(i, 0), o.set(t, 64);
			let u = /* @__PURE__ */ new Uint8Array(96);
			return u.set(s, 0), u.set(Xe(o), 64), d.from(Xe(u));
		}, "digest") };
	}, "update") };
}
var fr = G(() => {
	"use strict";
	p();
	es();
	ts();
	a(gu, "randomBytes");
	a(bu, "createHash");
	a(vu, "createHmac");
});
var tt = T((Qf, hr) => {
	"use strict";
	p();
	hr.exports = {
		host: "localhost",
		user: m.platform === "win32" ? m.env.USERNAME : m.env.USER,
		database: void 0,
		password: null,
		connectionString: void 0,
		port: 5432,
		rows: 0,
		binary: !1,
		max: 10,
		idleTimeoutMillis: 3e4,
		client_encoding: "",
		ssl: !1,
		application_name: void 0,
		fallback_application_name: void 0,
		options: void 0,
		parseInputDatesAsUTC: !1,
		statement_timeout: !1,
		lock_timeout: !1,
		idle_in_transaction_session_timeout: !1,
		query_timeout: !1,
		connect_timeout: 0,
		keepalives: 1,
		keepalives_idle: 0
	};
	var Me = Je(), xu = Me.getTypeParser(20, "text"), Su = Me.getTypeParser(1016, "text");
	hr.exports.__defineSetter__("parseInt8", function(r) {
		Me.setTypeParser(20, "text", r ? Me.getTypeParser(23, "text") : xu), Me.setTypeParser(1016, "text", r ? Me.getTypeParser(1007, "text") : Su);
	});
});
var rt = T((Wf, ns) => {
	"use strict";
	p();
	var Eu = (fr(), O(lr)), Au = tt();
	function Cu(r) {
		return "\"" + r.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"";
	}
	a(Cu, "escapeElement");
	function rs(r) {
		for (var e = "{", t = 0; t < r.length; t++) t > 0 && (e = e + ","), r[t] === null || typeof r[t] > "u" ? e = e + "NULL" : Array.isArray(r[t]) ? e = e + rs(r[t]) : r[t] instanceof d ? e += "\\\\x" + r[t].toString("hex") : e += Cu(Ct(r[t]));
		return e = e + "}", e;
	}
	a(rs, "arrayString");
	var Ct = a(function(r, e) {
		if (r == null) return null;
		if (r instanceof d) return r;
		if (ArrayBuffer.isView(r)) {
			var t = d.from(r.buffer, r.byteOffset, r.byteLength);
			return t.length === r.byteLength ? t : t.slice(r.byteOffset, r.byteOffset + r.byteLength);
		}
		return r instanceof Date ? Au.parseInputDatesAsUTC ? Tu(r) : Iu(r) : Array.isArray(r) ? rs(r) : typeof r == "object" ? _u(r, e) : r.toString();
	}, "prepareValue");
	function _u(r, e) {
		if (r && typeof r.toPostgres == "function") {
			if (e = e || [], e.indexOf(r) !== -1) throw new Error("circular reference detected while preparing \"" + r + "\" for query");
			return e.push(r), Ct(r.toPostgres(Ct), e);
		}
		return JSON.stringify(r);
	}
	a(_u, "prepareObject");
	function N(r, e) {
		for (r = "" + r; r.length < e;) r = "0" + r;
		return r;
	}
	a(N, "pad");
	function Iu(r) {
		var e = -r.getTimezoneOffset(), t = r.getFullYear(), n = t < 1;
		n && (t = Math.abs(t) + 1);
		var i = N(t, 4) + "-" + N(r.getMonth() + 1, 2) + "-" + N(r.getDate(), 2) + "T" + N(r.getHours(), 2) + ":" + N(r.getMinutes(), 2) + ":" + N(r.getSeconds(), 2) + "." + N(r.getMilliseconds(), 3);
		return e < 0 ? (i += "-", e *= -1) : i += "+", i += N(Math.floor(e / 60), 2) + ":" + N(e % 60, 2), n && (i += " BC"), i;
	}
	a(Iu, "dateToString");
	function Tu(r) {
		var e = r.getUTCFullYear(), t = e < 1;
		t && (e = Math.abs(e) + 1);
		var n = N(e, 4) + "-" + N(r.getUTCMonth() + 1, 2) + "-" + N(r.getUTCDate(), 2) + "T" + N(r.getUTCHours(), 2) + ":" + N(r.getUTCMinutes(), 2) + ":" + N(r.getUTCSeconds(), 2) + "." + N(r.getUTCMilliseconds(), 3);
		return n += "+00:00", t && (n += " BC"), n;
	}
	a(Tu, "dateToStringUTC");
	function Pu(r, e, t) {
		return r = typeof r == "string" ? { text: r } : r, e && (typeof e == "function" ? r.callback = e : r.values = e), t && (r.callback = t), r;
	}
	a(Pu, "normalizeQueryConfig");
	var pr = a(function(r) {
		return Eu.createHash("md5").update(r, "utf-8").digest("hex");
	}, "md5"), Ru = a(function(r, e, t) {
		var n = pr(e + r);
		return "md5" + pr(d.concat([d.from(n), t]));
	}, "postgresMd5PasswordHash");
	ns.exports = {
		prepareValue: a(function(e) {
			return Ct(e);
		}, "prepareValueWrapper"),
		normalizeQueryConfig: Pu,
		postgresMd5PasswordHash: Ru,
		md5: pr
	};
});
var nt = {};
ie(nt, { default: () => ku });
var ku;
var it = G(() => {
	"use strict";
	p();
	ku = {};
});
var ds = T((th, ps) => {
	"use strict";
	p();
	var yr = (fr(), O(lr));
	function Mu(r) {
		if (r.indexOf("SCRAM-SHA-256") === -1) throw new Error("SASL: Only mechanism SCRAM-SHA-256 is currently supported");
		let e = yr.randomBytes(18).toString("base64");
		return {
			mechanism: "SCRAM-SHA-256",
			clientNonce: e,
			response: "n,,n=*,r=" + e,
			message: "SASLInitialResponse"
		};
	}
	a(Mu, "startSession");
	function Uu(r, e, t) {
		if (r.message !== "SASLInitialResponse") throw new Error("SASL: Last message was not SASLInitialResponse");
		if (typeof e != "string") throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string");
		if (typeof t != "string") throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string");
		let n = qu(t);
		if (n.nonce.startsWith(r.clientNonce)) {
			if (n.nonce.length === r.clientNonce.length) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
		} else throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce does not start with client nonce");
		var s = Wu(e, d.from(n.salt, "base64"), n.iteration), o = Ue(s, "Client Key"), u = Nu(o), c = "n=*,r=" + r.clientNonce, l = "r=" + n.nonce + ",s=" + n.salt + ",i=" + n.iteration, f = "c=biws,r=" + n.nonce, y = c + "," + l + "," + f, C = hs(o, Ue(u, y)).toString("base64"), Y = Ue(Ue(s, "Server Key"), y);
		r.message = "SASLResponse", r.serverSignature = Y.toString("base64"), r.response = f + ",p=" + C;
	}
	a(Uu, "continueSession");
	function Du(r, e) {
		if (r.message !== "SASLResponse") throw new Error("SASL: Last message was not SASLResponse");
		if (typeof e != "string") throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: serverData must be a string");
		let { serverSignature: t } = Qu(e);
		if (t !== r.serverSignature) throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature does not match");
	}
	a(Du, "finalizeSession");
	function Ou(r) {
		if (typeof r != "string") throw new TypeError("SASL: text must be a string");
		return r.split("").map((e, t) => r.charCodeAt(t)).every((e) => e >= 33 && e <= 43 || e >= 45 && e <= 126);
	}
	a(Ou, "isPrintableChars");
	function ls(r) {
		return /^(?:[a-zA-Z0-9+/]{4})*(?:[a-zA-Z0-9+/]{2}==|[a-zA-Z0-9+/]{3}=)?$/.test(r);
	}
	a(ls, "isBase64");
	function fs(r) {
		if (typeof r != "string") throw new TypeError("SASL: attribute pairs text must be a string");
		return new Map(r.split(",").map((e) => {
			if (!/^.=/.test(e)) throw new Error("SASL: Invalid attribute pair entry");
			return [e[0], e.substring(2)];
		}));
	}
	a(fs, "parseAttributePairs");
	function qu(r) {
		let e = fs(r), t = e.get("r");
		if (t) {
			if (!Ou(t)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce must only contain printable characters");
		} else throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing");
		let n = e.get("s");
		if (n) {
			if (!ls(n)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: salt must be base64");
		} else throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing");
		let i = e.get("i");
		if (i) {
			if (!/^[1-9][0-9]*$/.test(i)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: invalid iteration count");
		} else throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: iteration missing");
		return {
			nonce: t,
			salt: n,
			iteration: parseInt(i, 10)
		};
	}
	a(qu, "parseServerFirstMessage");
	function Qu(r) {
		let t = fs(r).get("v");
		if (t) {
			if (!ls(t)) throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature must be base64");
		} else throw new Error("SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature is missing");
		return { serverSignature: t };
	}
	a(Qu, "parseServerFinalMessage");
	function hs(r, e) {
		if (!d.isBuffer(r)) throw new TypeError("first argument must be a Buffer");
		if (!d.isBuffer(e)) throw new TypeError("second argument must be a Buffer");
		if (r.length !== e.length) throw new Error("Buffer lengths must match");
		if (r.length === 0) throw new Error("Buffers cannot be empty");
		return d.from(r.map((t, n) => r[n] ^ e[n]));
	}
	a(hs, "xorBuffers");
	function Nu(r) {
		return yr.createHash("sha256").update(r).digest();
	}
	a(Nu, "sha256");
	function Ue(r, e) {
		return yr.createHmac("sha256", r).update(e).digest();
	}
	a(Ue, "hmacSha256");
	function Wu(r, e, t) {
		for (var n = Ue(r, d.concat([e, d.from([
			0,
			0,
			0,
			1
		])])), i = n, s = 0; s < t - 1; s++) n = Ue(r, n), i = hs(i, n);
		return i;
	}
	a(Wu, "Hi");
	ps.exports = {
		startSession: Mu,
		continueSession: Uu,
		finalizeSession: Du
	};
});
var mr = {};
ie(mr, { join: () => ju });
function ju(...r) {
	return r.join("/");
}
var wr = G(() => {
	"use strict";
	p();
	a(ju, "join");
});
var gr = {};
ie(gr, { stat: () => Hu });
function Hu(r, e) {
	e(/* @__PURE__ */ new Error("No filesystem"));
}
var br = G(() => {
	"use str\
ict";
	p();
	a(Hu, "stat");
});
var vr = {};
ie(vr, { default: () => $u });
var $u;
var xr = G(() => {
	"use strict";
	p();
	$u = {};
});
var ys = {};
ie(ys, { StringDecoder: () => Sr });
var Er;
var Sr;
var ms = G(() => {
	"use strict";
	p();
	Er = class Er {
		constructor(e) {
			E(this, "td");
			this.td = new TextDecoder(e);
		}
		write(e) {
			return this.td.decode(e, { stream: !0 });
		}
		end(e) {
			return this.td.decode(e);
		}
	};
	a(Er, "StringDecoder");
	Sr = Er;
});
var vs = T((fh, bs) => {
	"use strict";
	p();
	var { Transform: Gu } = (xr(), O(vr)), { StringDecoder: Vu } = (ms(), O(ys)), ve = Symbol("last"), It = Symbol("decoder");
	function zu(r, e, t) {
		let n;
		if (this.overflow) {
			if (n = this[It].write(r).split(this.matcher), n.length === 1) return t();
			n.shift(), this.overflow = !1;
		} else this[ve] += this[It].write(r), n = this[ve].split(this.matcher);
		this[ve] = n.pop();
		for (let i = 0; i < n.length; i++) try {
			gs(this, this.mapper(n[i]));
		} catch (s) {
			return t(s);
		}
		if (this.overflow = this[ve].length > this.maxLength, this.overflow && !this.skipOverflow) {
			t(/* @__PURE__ */ new Error("maximum buffer reached"));
			return;
		}
		t();
	}
	a(zu, "transform");
	function Ku(r) {
		if (this[ve] += this[It].end(), this[ve]) try {
			gs(this, this.mapper(this[ve]));
		} catch (e) {
			return r(e);
		}
		r();
	}
	a(Ku, "flush");
	function gs(r, e) {
		e !== void 0 && r.push(e);
	}
	a(gs, "push");
	function ws(r) {
		return r;
	}
	a(ws, "noop");
	function Yu(r, e, t) {
		switch (r = r || /\r?\n/, e = e || ws, t = t || {}, arguments.length) {
			case 1:
				typeof r == "function" ? (e = r, r = /\r?\n/) : typeof r == "object" && !(r instanceof RegExp) && !r[Symbol.split] && (t = r, r = /\r?\n/);
				break;
			case 2: typeof r == "function" ? (t = e, e = r, r = /\r?\n/) : typeof e == "object" && (t = e, e = ws);
		}
		t = Object.assign({}, t), t.autoDestroy = !0, t.transform = zu, t.flush = Ku, t.readableObjectMode = !0;
		let n = new Gu(t);
		return n[ve] = "", n[It] = new Vu("utf8"), n.matcher = r, n.mapper = e, n.maxLength = t.maxLength, n.skipOverflow = t.skipOverflow || !1, n.overflow = !1, n._destroy = function(i, s) {
			this._writableState.errorEmitted = !1, s(i);
		}, n;
	}
	a(Yu, "split");
	bs.exports = Yu;
});
var Es = T((dh, pe) => {
	"use strict";
	p();
	var xs = (wr(), O(mr)), Zu = (xr(), O(vr)).Stream, Ju = vs(), Ss = (it(), O(nt)), Xu = 5432, Tt = m.platform === "win32", st = m.stderr, ec = 56, tc = 7, rc = 61440, nc = 32768;
	function ic(r) {
		return (r & rc) == nc;
	}
	a(ic, "isRegFile");
	var De = [
		"host",
		"port",
		"database",
		"user",
		"password"
	], Ar = De.length, sc = De[Ar - 1];
	function Cr() {
		if (st instanceof Zu && st.writable === !0) {
			var e = Array.prototype.slice.call(arguments).concat(`
`);
			st.write(Ss.format.apply(Ss, e));
		}
	}
	a(Cr, "warn");
	Object.defineProperty(pe.exports, "isWin", {
		get: a(function() {
			return Tt;
		}, "get"),
		set: a(function(r) {
			Tt = r;
		}, "set")
	});
	pe.exports.warnTo = function(r) {
		var e = st;
		return st = r, e;
	};
	pe.exports.getFileName = function(r) {
		var e = r || m.env;
		return e.PGPASSFILE || (Tt ? xs.join(e.APPDATA || "./", "postgresql", "pgpass.conf") : xs.join(e.HOME || "./", ".pgpass"));
	};
	pe.exports.usePgPass = function(r, e) {
		return Object.prototype.hasOwnProperty.call(m.env, "PGPASSWORD") ? !1 : Tt ? !0 : (e = e || "<unkn>", ic(r.mode) ? r.mode & (ec | tc) ? (Cr("WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less", e), !1) : !0 : (Cr("WARNING: password file \"%s\" is not a plain file", e), !1));
	};
	var oc = pe.exports.match = function(r, e) {
		return De.slice(0, -1).reduce(function(t, n, i) {
			return i == 1 && Number(r[n] || Xu) === Number(e[n]) ? t && !0 : t && (e[n] === "*" || e[n] === r[n]);
		}, !0);
	};
	pe.exports.getPassword = function(r, e, t) {
		var n, i = e.pipe(Ju());
		function s(c) {
			var l = ac(c);
			l && uc(l) && oc(r, l) && (n = l[sc], i.end());
		}
		a(s, "onLine");
		var o = a(function() {
			e.destroy(), t(n);
		}, "onEnd"), u = a(function(c) {
			e.destroy(), Cr("WARNING: error on reading file: %s", c), t(void 0);
		}, "onErr");
		e.on("error", u), i.on("data", s).on("end", o).on("error", u);
	};
	var ac = pe.exports.parseLine = function(r) {
		if (r.length < 11 || r.match(/^\s+#/)) return null;
		for (var e = "", t = "", n = 0, i = 0, o = {}, u = !1, c = a(function(f, y, g) {
			var A = r.substring(y, g);
			Object.hasOwnProperty.call(m.env, "PGPASS_NO_DEESCAPE") || (A = A.replace(/\\([:\\])/g, "$1")), o[De[f]] = A;
		}, "addToObj"), l = 0; l < r.length - 1; l += 1) {
			if (e = r.charAt(l + 1), t = r.charAt(l), u = n == Ar - 1, u) {
				c(n, i);
				break;
			}
			l >= 0 && e == ":" && t !== "\\" && (c(n, i, l + 1), i = l + 2, n += 1);
		}
		return o = Object.keys(o).length === Ar ? o : null, o;
	}, uc = pe.exports.isValidEntry = function(r) {
		for (var e = {
			0: function(o) {
				return o.length > 0;
			},
			1: function(o) {
				return o === "*" ? !0 : (o = Number(o), isFinite(o) && o > 0 && o < 9007199254740992 && Math.floor(o) === o);
			},
			2: function(o) {
				return o.length > 0;
			},
			3: function(o) {
				return o.length > 0;
			},
			4: function(o) {
				return o.length > 0;
			}
		}, t = 0; t < De.length; t += 1) {
			var n = e[t];
			if (!n(r[De[t]] || "")) return !1;
		}
		return !0;
	};
});
var Cs = T((gh, _r) => {
	"use strict";
	p();
	wr(), O(mr);
	var As = (br(), O(gr)), Pt = Es();
	_r.exports = function(r, e) {
		var t = Pt.getFileName();
		As.stat(t, function(n, i) {
			if (n || !Pt.usePgPass(i, t)) return e(void 0);
			var s = As.createReadStream(t);
			Pt.getPassword(r, s, e);
		});
	};
	_r.exports.warnTo = Pt.warnTo;
});
var _s = {};
ie(_s, { default: () => cc });
var cc;
var Is = G(() => {
	"use strict";
	p();
	cc = {};
});
var Ps = T((xh, Ts) => {
	"use strict";
	p();
	var lc = (Zt(), O(gi)), Ir = (br(), O(gr));
	function Tr(r) {
		if (r.charAt(0) === "/") {
			var t = r.split(" ");
			return {
				host: t[0],
				database: t[1]
			};
		}
		var e = lc.parse(/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(r) ? encodeURI(r).replace(/\%25(\d\d)/g, "%$1") : r, !0), t = e.query;
		for (var n in t) Array.isArray(t[n]) && (t[n] = t[n][t[n].length - 1]);
		var i = (e.auth || ":").split(":");
		if (t.user = i[0], t.password = i.splice(1).join(":"), t.port = e.port, e.protocol == "socket:") return t.host = decodeURI(e.pathname), t.database = e.query.db, t.client_encoding = e.query.encoding, t;
		t.host || (t.host = e.hostname);
		var s = e.pathname;
		if (!t.host && s && /^%2f/i.test(s)) {
			var o = s.split("/");
			t.host = decodeURIComponent(o[0]), s = o.splice(1).join("/");
		}
		switch (s && s.charAt(0) === "/" && (s = s.slice(1) || null), t.database = s && decodeURI(s), (t.ssl === "true" || t.ssl === "1") && (t.ssl = !0), t.ssl === "0" && (t.ssl = !1), (t.sslcert || t.sslkey || t.sslrootcert || t.sslmode) && (t.ssl = {}), t.sslcert && (t.ssl.cert = Ir.readFileSync(t.sslcert).toString()), t.sslkey && (t.ssl.key = Ir.readFileSync(t.sslkey).toString()), t.sslrootcert && (t.ssl.ca = Ir.readFileSync(t.sslrootcert).toString()), t.sslmode) {
			case "disable":
				t.ssl = !1;
				break;
			case "prefer":
			case "require":
			case "verify-ca":
			case "verify-full": break;
			case "no-verify": t.ssl.rejectUnauthorized = !1;
		}
		return t;
	}
	a(Tr, "parse");
	Ts.exports = Tr;
	Tr.parse = Tr;
});
var Rt = T((Ah, Ls) => {
	"use strict";
	p();
	var fc = (Is(), O(_s)), Bs = tt(), Rs = Ps().parse, H = a(function(r, e, t) {
		return t === void 0 ? t = m.env["PG" + r.toUpperCase()] : t === !1 || (t = m.env[t]), e[r] || t || Bs[r];
	}, "val"), hc = a(function() {
		switch (m.env.PGSSLMODE) {
			case "disable": return !1;
			case "prefer":
			case "require":
			case "verify-ca":
			case "verify-full": return !0;
			case "no-verify": return { rejectUnauthorized: !1 };
		}
		return Bs.ssl;
	}, "readSSLConfigFromEnvironment"), Oe = a(function(r) {
		return "'" + ("" + r).replace(/\\/g, "\\\\").replace(/'/g, "\\'") + "'";
	}, "quoteParamValue"), ne = a(function(r, e, t) {
		var n = e[t];
		n != null && r.push(t + "=" + Oe(n));
	}, "add"), Rr = class Rr {
		constructor(e) {
			e = typeof e == "string" ? Rs(e) : e || {}, e.connectionString && (e = Object.assign({}, e, Rs(e.connectionString))), this.user = H("user", e), this.database = H("database", e), this.database === void 0 && (this.database = this.user), this.port = parseInt(H("port", e), 10), this.host = H("host", e), Object.defineProperty(this, "password", {
				configurable: !0,
				enumerable: !1,
				writable: !0,
				value: H("password", e)
			}), this.binary = H("binary", e), this.options = H("options", e), this.ssl = typeof e.ssl > "u" ? hc() : e.ssl, typeof this.ssl == "string" && this.ssl === "true" && (this.ssl = !0), this.ssl === "no-verify" && (this.ssl = { rejectUnauthorized: !1 }), this.ssl && this.ssl.key && Object.defineProperty(this.ssl, "key", { enumerable: !1 }), this.client_encoding = H("client_encoding", e), this.replication = H("replication", e), this.isDomainSocket = !(this.host || "").indexOf("/"), this.application_name = H("application_name", e, "PGAPPNAME"), this.fallback_application_name = H("fallback_application_name", e, !1), this.statement_timeout = H("statement_timeout", e, !1), this.lock_timeout = H("lock_timeout", e, !1), this.idle_in_transaction_session_timeout = H("idle_in_transaction_session_timeout", e, !1), this.query_timeout = H("query_timeout", e, !1), e.connectionTimeoutMillis === void 0 ? this.connect_timeout = m.env.PGCONNECT_TIMEOUT || 0 : this.connect_timeout = Math.floor(e.connectionTimeoutMillis / 1e3), e.keepAlive === !1 ? this.keepalives = 0 : e.keepAlive === !0 && (this.keepalives = 1), typeof e.keepAliveInitialDelayMillis == "number" && (this.keepalives_idle = Math.floor(e.keepAliveInitialDelayMillis / 1e3));
		}
		getLibpqConnectionString(e) {
			var t = [];
			ne(t, this, "user"), ne(t, this, "password"), ne(t, this, "port"), ne(t, this, "application_name"), ne(t, this, "fallback_application_name"), ne(t, this, "connect_timeout"), ne(t, this, "options");
			var n = typeof this.ssl == "object" ? this.ssl : this.ssl ? { sslmode: this.ssl } : {};
			if (ne(t, n, "sslmode"), ne(t, n, "sslca"), ne(t, n, "sslkey"), ne(t, n, "sslcert"), ne(t, n, "sslrootcert"), this.database && t.push("dbname=" + Oe(this.database)), this.replication && t.push("replication=" + Oe(this.replication)), this.host && t.push("host=" + Oe(this.host)), this.isDomainSocket) return e(null, t.join(" "));
			this.client_encoding && t.push("client_encoding=" + Oe(this.client_encoding)), fc.lookup(this.host, function(i, s) {
				return i ? e(i, null) : (t.push("hostaddr=" + Oe(s)), e(null, t.join(" ")));
			});
		}
	};
	a(Rr, "ConnectionParameters");
	Ls.exports = Rr;
});
var Ms = T((Ih, ks) => {
	"use strict";
	p();
	var pc = Je(), Fs = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/, Lr = class Lr {
		constructor(e, t) {
			this.command = null, this.rowCount = null, this.oid = null, this.rows = [], this.fields = [], this._parsers = void 0, this._types = t, this.RowCtor = null, this.rowAsArray = e === "array", this.rowAsArray && (this.parseRow = this._parseRowAsArray);
		}
		addCommandComplete(e) {
			var t;
			e.text ? t = Fs.exec(e.text) : t = Fs.exec(e.command), t && (this.command = t[1], t[3] ? (this.oid = parseInt(t[2], 10), this.rowCount = parseInt(t[3], 10)) : t[2] && (this.rowCount = parseInt(t[2], 10)));
		}
		_parseRowAsArray(e) {
			for (var t = new Array(e.length), n = 0, i = e.length; n < i; n++) {
				var s = e[n];
				s !== null ? t[n] = this._parsers[n](s) : t[n] = null;
			}
			return t;
		}
		parseRow(e) {
			for (var t = {}, n = 0, i = e.length; n < i; n++) {
				var s = e[n], o = this.fields[n].name;
				s !== null ? t[o] = this._parsers[n](s) : t[o] = null;
			}
			return t;
		}
		addRow(e) {
			this.rows.push(e);
		}
		addFields(e) {
			this.fields = e, this.fields.length && (this._parsers = new Array(e.length));
			for (var t = 0; t < e.length; t++) {
				var n = e[t];
				this._types ? this._parsers[t] = this._types.getTypeParser(n.dataTypeID, n.format || "text") : this._parsers[t] = pc.getTypeParser(n.dataTypeID, n.format || "text");
			}
		}
	};
	a(Lr, "Result");
	ks.exports = Lr;
});
var qs = T((Rh, Os) => {
	"use strict";
	p();
	var { EventEmitter: dc } = ge(), Us = Ms(), Ds = rt(), kr = class kr extends dc {
		constructor(e, t, n) {
			super(), e = Ds.normalizeQueryConfig(e, t, n), this.text = e.text, this.values = e.values, this.rows = e.rows, this.types = e.types, this.name = e.name, this.binary = e.binary, this.portal = e.portal || "", this.callback = e.callback, this._rowMode = e.rowMode, m.domain && e.callback && (this.callback = m.domain.bind(e.callback)), this._result = new Us(this._rowMode, this.types), this._results = this._result, this.isPreparedStatement = !1, this._canceledDueToError = !1, this._promise = null;
		}
		requiresPreparation() {
			return this.name || this.rows ? !0 : !this.text || !this.values ? !1 : this.values.length > 0;
		}
		_checkForMultirow() {
			this._result.command && (Array.isArray(this._results) || (this._results = [this._result]), this._result = new Us(this._rowMode, this.types), this._results.push(this._result));
		}
		handleRowDescription(e) {
			this._checkForMultirow(), this._result.addFields(e.fields), this._accumulateRows = this.callback || !this.listeners("row").length;
		}
		handleDataRow(e) {
			let t;
			if (!this._canceledDueToError) {
				try {
					t = this._result.parseRow(e.fields);
				} catch (n) {
					this._canceledDueToError = n;
					return;
				}
				this.emit("row", t, this._result), this._accumulateRows && this._result.addRow(t);
			}
		}
		handleCommandComplete(e, t) {
			this._checkForMultirow(), this._result.addCommandComplete(e), this.rows && t.sync();
		}
		handleEmptyQuery(e) {
			this.rows && e.sync();
		}
		handleError(e, t) {
			if (this._canceledDueToError && (e = this._canceledDueToError, this._canceledDueToError = !1), this.callback) return this.callback(e);
			this.emit("error", e);
		}
		handleReadyForQuery(e) {
			if (this._canceledDueToError) return this.handleError(this._canceledDueToError, e);
			if (this.callback) try {
				this.callback(null, this._results);
			} catch (t) {
				m.nextTick(() => {
					throw t;
				});
			}
			this.emit("end", this._results);
		}
		submit(e) {
			if (typeof this.text != "string" && typeof this.name != "string") return /* @__PURE__ */ new Error("A query must have either text or a name. Supplying neither is unsupported.");
			let t = e.parsedStatements[this.name];
			return this.text && t && this.text !== t ? /* @__PURE__ */ new Error(`Prepared statements must be unique - '${this.name}\
' was used for a different statement`) : this.values && !Array.isArray(this.values) ? /* @__PURE__ */ new Error("Query values must be an array") : (this.requiresPreparation() ? this.prepare(e) : e.query(this.text), null);
		}
		hasBeenParsed(e) {
			return this.name && e.parsedStatements[this.name];
		}
		handlePortalSuspended(e) {
			this._getRows(e, this.rows);
		}
		_getRows(e, t) {
			e.execute({
				portal: this.portal,
				rows: t
			}), t ? e.flush() : e.sync();
		}
		prepare(e) {
			this.isPreparedStatement = !0, this.hasBeenParsed(e) || e.parse({
				text: this.text,
				name: this.name,
				types: this.types
			});
			try {
				e.bind({
					portal: this.portal,
					statement: this.name,
					values: this.values,
					binary: this.binary,
					valueMapper: Ds.prepareValue
				});
			} catch (t) {
				this.handleError(t, e);
				return;
			}
			e.describe({
				type: "P",
				name: this.portal || ""
			}), this._getRows(e, this.rows);
		}
		handleCopyInResponse(e) {
			e.sendCopyFail("No source stream defined");
		}
		handleCopyData(e, t) {}
	};
	a(kr, "Query");
	Os.exports = kr;
});
var ln = T((_) => {
	"use strict";
	p();
	Object.defineProperty(_, "__esModule", { value: !0 });
	_.NoticeMessage = _.DataRowMessage = _.CommandCompleteMessage = _.ReadyForQueryMessage = _.NotificationResponseMessage = _.BackendKeyDataMessage = _.AuthenticationMD5Password = _.ParameterStatusMessage = _.ParameterDescriptionMessage = _.RowDescriptionMessage = _.Field = _.CopyResponse = _.CopyDataMessage = _.DatabaseError = _.copyDone = _.emptyQuery = _.replicationStart = _.portalSuspended = _.noData = _.closeComplete = _.bindComplete = _.parseComplete = void 0;
	_.parseComplete = {
		name: "parseComplete",
		length: 5
	};
	_.bindComplete = {
		name: "bindComplete",
		length: 5
	};
	_.closeComplete = {
		name: "closeComplete",
		length: 5
	};
	_.noData = {
		name: "noData",
		length: 5
	};
	_.portalSuspended = {
		name: "portalSuspended",
		length: 5
	};
	_.replicationStart = {
		name: "replicationStart",
		length: 4
	};
	_.emptyQuery = {
		name: "emptyQuery",
		length: 4
	};
	_.copyDone = {
		name: "copyDone",
		length: 4
	};
	var Kr = class Kr extends Error {
		constructor(e, t, n) {
			super(e), this.length = t, this.name = n;
		}
	};
	a(Kr, "DatabaseError");
	_.DatabaseError = Kr;
	var Yr = class Yr {
		constructor(e, t) {
			this.length = e, this.chunk = t, this.name = "copyData";
		}
	};
	a(Yr, "CopyDataMessage");
	_.CopyDataMessage = Yr;
	var Zr = class Zr {
		constructor(e, t, n, i) {
			this.length = e, this.name = t, this.binary = n, this.columnTypes = new Array(i);
		}
	};
	a(Zr, "CopyResponse");
	_.CopyResponse = Zr;
	var Jr = class Jr {
		constructor(e, t, n, i, s, o, u) {
			this.name = e, this.tableID = t, this.columnID = n, this.dataTypeID = i, this.dataTypeSize = s, this.dataTypeModifier = o, this.format = u;
		}
	};
	a(Jr, "Field");
	_.Field = Jr;
	var Xr = class Xr {
		constructor(e, t) {
			this.length = e, this.fieldCount = t, this.name = "rowDescription", this.fields = new Array(this.fieldCount);
		}
	};
	a(Xr, "RowDescriptionMessage");
	_.RowDescriptionMessage = Xr;
	var en = class en {
		constructor(e, t) {
			this.length = e, this.parameterCount = t, this.name = "parameterDescription", this.dataTypeIDs = new Array(this.parameterCount);
		}
	};
	a(en, "ParameterDescriptionMessage");
	_.ParameterDescriptionMessage = en;
	var tn = class tn {
		constructor(e, t, n) {
			this.length = e, this.parameterName = t, this.parameterValue = n, this.name = "parameterStatus";
		}
	};
	a(tn, "ParameterStatusMessage");
	_.ParameterStatusMessage = tn;
	var rn = class rn {
		constructor(e, t) {
			this.length = e, this.salt = t, this.name = "authenticationMD5Password";
		}
	};
	a(rn, "AuthenticationMD5Password");
	_.AuthenticationMD5Password = rn;
	var nn = class nn {
		constructor(e, t, n) {
			this.length = e, this.processID = t, this.secretKey = n, this.name = "backendKeyData";
		}
	};
	a(nn, "BackendKeyDataMessage");
	_.BackendKeyDataMessage = nn;
	var sn = class sn {
		constructor(e, t, n, i) {
			this.length = e, this.processId = t, this.channel = n, this.payload = i, this.name = "notification";
		}
	};
	a(sn, "NotificationResponseMessage");
	_.NotificationResponseMessage = sn;
	var on = class on {
		constructor(e, t) {
			this.length = e, this.status = t, this.name = "readyForQuery";
		}
	};
	a(on, "ReadyForQueryMessage");
	_.ReadyForQueryMessage = on;
	var an = class an {
		constructor(e, t) {
			this.length = e, this.text = t, this.name = "commandComplete";
		}
	};
	a(an, "CommandCompleteMessage");
	_.CommandCompleteMessage = an;
	var un = class un {
		constructor(e, t) {
			this.length = e, this.fields = t, this.name = "dataRow", this.fieldCount = t.length;
		}
	};
	a(un, "DataRowMessage");
	_.DataRowMessage = un;
	var cn = class cn {
		constructor(e, t) {
			this.length = e, this.message = t, this.name = "notice";
		}
	};
	a(cn, "NoticeMessage");
	_.NoticeMessage = cn;
});
var Qs = T((Bt) => {
	"use strict";
	p();
	Object.defineProperty(Bt, "__esModule", { value: !0 });
	Bt.Writer = void 0;
	var hn = class hn {
		constructor(e = 256) {
			this.size = e, this.offset = 5, this.headerPosition = 0, this.buffer = d.allocUnsafe(e);
		}
		ensure(e) {
			if (this.buffer.length - this.offset < e) {
				let n = this.buffer, i = n.length + (n.length >> 1) + e;
				this.buffer = d.allocUnsafe(i), n.copy(this.buffer);
			}
		}
		addInt32(e) {
			return this.ensure(4), this.buffer[this.offset++] = e >>> 24 & 255, this.buffer[this.offset++] = e >>> 16 & 255, this.buffer[this.offset++] = e >>> 8 & 255, this.buffer[this.offset++] = e >>> 0 & 255, this;
		}
		addInt16(e) {
			return this.ensure(2), this.buffer[this.offset++] = e >>> 8 & 255, this.buffer[this.offset++] = e >>> 0 & 255, this;
		}
		addCString(e) {
			if (!e) this.ensure(1);
			else {
				let t = d.byteLength(e);
				this.ensure(t + 1), this.buffer.write(e, this.offset, "utf-8"), this.offset += t;
			}
			return this.buffer[this.offset++] = 0, this;
		}
		addString(e = "") {
			let t = d.byteLength(e);
			return this.ensure(t), this.buffer.write(e, this.offset), this.offset += t, this;
		}
		add(e) {
			return this.ensure(e.length), e.copy(this.buffer, this.offset), this.offset += e.length, this;
		}
		join(e) {
			if (e) {
				this.buffer[this.headerPosition] = e;
				let t = this.offset - (this.headerPosition + 1);
				this.buffer.writeInt32BE(t, this.headerPosition + 1);
			}
			return this.buffer.slice(e ? 0 : 5, this.offset);
		}
		flush(e) {
			let t = this.join(e);
			return this.offset = 5, this.headerPosition = 0, this.buffer = d.allocUnsafe(this.size), t;
		}
	};
	a(hn, "Writer");
	Bt.Writer = hn;
});
var Ws = T((Ft) => {
	"use strict";
	p();
	Object.defineProperty(Ft, "__esModule", { value: !0 });
	Ft.serialize = void 0;
	var pn = Qs(), F = new pn.Writer(), yc = a((r) => {
		F.addInt16(3).addInt16(0);
		for (let n of Object.keys(r)) F.addCString(n).addCString(r[n]);
		F.addCString("client_encoding").addCString("UTF8");
		let e = F.addCString("").flush(), t = e.length + 4;
		return new pn.Writer().addInt32(t).add(e).flush();
	}, "startup"), mc = a(() => {
		let r = d.allocUnsafe(8);
		return r.writeInt32BE(8, 0), r.writeInt32BE(80877103, 4), r;
	}, "requestSsl"), wc = a((r) => F.addCString(r).flush(112), "password"), gc = a(function(r, e) {
		return F.addCString(r).addInt32(d.byteLength(e)).addString(e), F.flush(112);
	}, "sendSASLInitialResponseMessage"), bc = a(function(r) {
		return F.addString(r).flush(112);
	}, "sendSCRAMClientFinalMessage"), vc = a((r) => F.addCString(r).flush(81), "query"), Ns = [], xc = a((r) => {
		let e = r.name || "";
		e.length > 63 && (console.error("Warning! Postgres only supports 63 characters for query names."), console.error("You supplied %s (%s)", e, e.length), console.error("This can cause conflicts and silent errors executing queries"));
		let t = r.types || Ns, n = t.length, i = F.addCString(e).addCString(r.text).addInt16(n);
		for (let s = 0; s < n; s++) i.addInt32(t[s]);
		return F.flush(80);
	}, "parse"), qe = new pn.Writer(), Sc = a(function(r, e) {
		for (let t = 0; t < r.length; t++) {
			let n = e ? e(r[t], t) : r[t];
			n == null ? (F.addInt16(0), qe.addInt32(-1)) : n instanceof d ? (F.addInt16(1), qe.addInt32(n.length), qe.add(n)) : (F.addInt16(0), qe.addInt32(d.byteLength(n)), qe.addString(n));
		}
	}, "writeValues"), Ec = a((r = {}) => {
		let e = r.portal || "", t = r.statement || "", n = r.binary || !1, i = r.values || Ns, s = i.length;
		return F.addCString(e).addCString(t), F.addInt16(s), Sc(i, r.valueMapper), F.addInt16(s), F.add(qe.flush()), F.addInt16(n ? 1 : 0), F.flush(66);
	}, "bind"), Ac = d.from([
		69,
		0,
		0,
		0,
		9,
		0,
		0,
		0,
		0,
		0
	]), Cc = a((r) => {
		if (!r || !r.portal && !r.rows) return Ac;
		let e = r.portal || "", t = r.rows || 0, n = d.byteLength(e), i = 4 + n + 1 + 4, s = d.allocUnsafe(1 + i);
		return s[0] = 69, s.writeInt32BE(i, 1), s.write(e, 5, "utf-8"), s[n + 5] = 0, s.writeUInt32BE(t, s.length - 4), s;
	}, "execute"), _c = a((r, e) => {
		let t = d.allocUnsafe(16);
		return t.writeInt32BE(16, 0), t.writeInt16BE(1234, 4), t.writeInt16BE(5678, 6), t.writeInt32BE(r, 8), t.writeInt32BE(e, 12), t;
	}, "cancel"), dn = a((r, e) => {
		let n = 4 + d.byteLength(e) + 1, i = d.allocUnsafe(1 + n);
		return i[0] = r, i.writeInt32BE(n, 1), i.write(e, 5, "utf-8"), i[n] = 0, i;
	}, "cstringMessage"), Ic = F.addCString("P").flush(68), Tc = F.addCString("S").flush(68), Pc = a((r) => r.name ? dn(68, `${r.type}${r.name || ""}`) : r.type === "P" ? Ic : Tc, "describe"), Rc = a((r) => {
		return dn(67, `${r.type}${r.name || ""}`);
	}, "close"), Bc = a((r) => F.add(r).flush(100), "copyData"), Lc = a((r) => dn(102, r), "copyFail"), Lt = a((r) => d.from([
		r,
		0,
		0,
		0,
		4
	]), "codeOnlyBuffer"), Fc = Lt(72), kc = Lt(83), Mc = Lt(88), Uc = Lt(99);
	Ft.serialize = {
		startup: yc,
		password: wc,
		requestSsl: mc,
		sendSASLInitialResponseMessage: gc,
		sendSCRAMClientFinalMessage: bc,
		query: vc,
		parse: xc,
		bind: Ec,
		execute: Cc,
		describe: Pc,
		close: Rc,
		flush: a(() => Fc, "flush"),
		sync: a(() => kc, "sync"),
		end: a(() => Mc, "end"),
		copyData: Bc,
		copyDone: a(() => Uc, "copyDone"),
		copyFail: Lc,
		cancel: _c
	};
});
var js = T((kt) => {
	"use strict";
	p();
	Object.defineProperty(kt, "__esModule", { value: !0 });
	kt.BufferReader = void 0;
	var Oc = d.allocUnsafe(0), mn = class mn {
		constructor(e = 0) {
			this.offset = e, this.buffer = Oc, this.encoding = "utf-8";
		}
		setBuffer(e, t) {
			this.offset = e, this.buffer = t;
		}
		int16() {
			let e = this.buffer.readInt16BE(this.offset);
			return this.offset += 2, e;
		}
		byte() {
			let e = this.buffer[this.offset];
			return this.offset++, e;
		}
		int32() {
			let e = this.buffer.readInt32BE(this.offset);
			return this.offset += 4, e;
		}
		uint32() {
			let e = this.buffer.readUInt32BE(this.offset);
			return this.offset += 4, e;
		}
		string(e) {
			let t = this.buffer.toString(this.encoding, this.offset, this.offset + e);
			return this.offset += e, t;
		}
		cstring() {
			let e = this.offset, t = e;
			for (; this.buffer[t++] !== 0;);
			return this.offset = t, this.buffer.toString(this.encoding, e, t - 1);
		}
		bytes(e) {
			let t = this.buffer.slice(this.offset, this.offset + e);
			return this.offset += e, t;
		}
	};
	a(mn, "BufferReader");
	kt.BufferReader = mn;
});
var Gs = T((Mt) => {
	"use strict";
	p();
	Object.defineProperty(Mt, "__esModule", { value: !0 });
	Mt.Parser = void 0;
	var k = ln(), qc = js(), wn = 1, Hs = wn + 4, $s = d.allocUnsafe(0), bn = class bn {
		constructor(e) {
			if (this.buffer = $s, this.bufferLength = 0, this.bufferOffset = 0, this.reader = new qc.BufferReader(), e?.mode === "binary") throw new Error("Binary mode not supported yet");
			this.mode = e?.mode || "text";
		}
		parse(e, t) {
			this.mergeBuffer(e);
			let n = this.bufferOffset + this.bufferLength, i = this.bufferOffset;
			for (; i + Hs <= n;) {
				let s = this.buffer[i], o = this.buffer.readUInt32BE(i + wn), u = wn + o;
				if (u + i <= n) t(this.handlePacket(i + Hs, s, o, this.buffer)), i += u;
				else break;
			}
			i === n ? (this.buffer = $s, this.bufferLength = 0, this.bufferOffset = 0) : (this.bufferLength = n - i, this.bufferOffset = i);
		}
		mergeBuffer(e) {
			if (this.bufferLength > 0) {
				let t = this.bufferLength + e.byteLength;
				if (t + this.bufferOffset > this.buffer.byteLength) {
					let i;
					if (t <= this.buffer.byteLength && this.bufferOffset >= this.bufferLength) i = this.buffer;
					else {
						let s = this.buffer.byteLength * 2;
						for (; t >= s;) s *= 2;
						i = d.allocUnsafe(s);
					}
					this.buffer.copy(i, 0, this.bufferOffset, this.bufferOffset + this.bufferLength), this.buffer = i, this.bufferOffset = 0;
				}
				e.copy(this.buffer, this.bufferOffset + this.bufferLength), this.bufferLength = t;
			} else this.buffer = e, this.bufferOffset = 0, this.bufferLength = e.byteLength;
		}
		handlePacket(e, t, n, i) {
			switch (t) {
				case 50: return k.bindComplete;
				case 49: return k.parseComplete;
				case 51: return k.closeComplete;
				case 110: return k.noData;
				case 115: return k.portalSuspended;
				case 99: return k.copyDone;
				case 87: return k.replicationStart;
				case 73: return k.emptyQuery;
				case 68: return this.parseDataRowMessage(e, n, i);
				case 67: return this.parseCommandCompleteMessage(e, n, i);
				case 90: return this.parseReadyForQueryMessage(e, n, i);
				case 65: return this.parseNotificationMessage(e, n, i);
				case 82: return this.parseAuthenticationResponse(e, n, i);
				case 83: return this.parseParameterStatusMessage(e, n, i);
				case 75: return this.parseBackendKeyData(e, n, i);
				case 69: return this.parseErrorMessage(e, n, i, "error");
				case 78: return this.parseErrorMessage(e, n, i, "notice");
				case 84: return this.parseRowDescriptionMessage(e, n, i);
				case 116: return this.parseParameterDescriptionMessage(e, n, i);
				case 71: return this.parseCopyInMessage(e, n, i);
				case 72: return this.parseCopyOutMessage(e, n, i);
				case 100: return this.parseCopyData(e, n, i);
				default: return new k.DatabaseError("received invalid response: " + t.toString(16), n, "error");
			}
		}
		parseReadyForQueryMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.string(1);
			return new k.ReadyForQueryMessage(t, i);
		}
		parseCommandCompleteMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.cstring();
			return new k.CommandCompleteMessage(t, i);
		}
		parseCopyData(e, t, n) {
			let i = n.slice(e, e + (t - 4));
			return new k.CopyDataMessage(t, i);
		}
		parseCopyInMessage(e, t, n) {
			return this.parseCopyMessage(e, t, n, "copyInResponse");
		}
		parseCopyOutMessage(e, t, n) {
			return this.parseCopyMessage(e, t, n, "copyOutResponse");
		}
		parseCopyMessage(e, t, n, i) {
			this.reader.setBuffer(e, n);
			let s = this.reader.byte() !== 0, o = this.reader.int16(), u = new k.CopyResponse(t, i, s, o);
			for (let c = 0; c < o; c++) u.columnTypes[c] = this.reader.int16();
			return u;
		}
		parseNotificationMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.int32(), s = this.reader.cstring(), o = this.reader.cstring();
			return new k.NotificationResponseMessage(t, i, s, o);
		}
		parseRowDescriptionMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.int16(), s = new k.RowDescriptionMessage(t, i);
			for (let o = 0; o < i; o++) s.fields[o] = this.parseField();
			return s;
		}
		parseField() {
			let e = this.reader.cstring(), t = this.reader.uint32(), n = this.reader.int16(), i = this.reader.uint32(), s = this.reader.int16(), o = this.reader.int32(), u = this.reader.int16() === 0 ? "text" : "binary";
			return new k.Field(e, t, n, i, s, o, u);
		}
		parseParameterDescriptionMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.int16(), s = new k.ParameterDescriptionMessage(t, i);
			for (let o = 0; o < i; o++) s.dataTypeIDs[o] = this.reader.int32();
			return s;
		}
		parseDataRowMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.int16(), s = new Array(i);
			for (let o = 0; o < i; o++) {
				let u = this.reader.int32();
				s[o] = u === -1 ? null : this.reader.string(u);
			}
			return new k.DataRowMessage(t, s);
		}
		parseParameterStatusMessage(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.cstring(), s = this.reader.cstring();
			return new k.ParameterStatusMessage(t, i, s);
		}
		parseBackendKeyData(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.int32(), s = this.reader.int32();
			return new k.BackendKeyDataMessage(t, i, s);
		}
		parseAuthenticationResponse(e, t, n) {
			this.reader.setBuffer(e, n);
			let i = this.reader.int32(), s = {
				name: "authenticationOk",
				length: t
			};
			switch (i) {
				case 0: break;
				case 3:
					s.length === 8 && (s.name = "authenticationCleartextPassword");
					break;
				case 5:
					if (s.length === 12) {
						s.name = "authenticationMD5Password";
						let o = this.reader.bytes(4);
						return new k.AuthenticationMD5Password(t, o);
					}
					break;
				case 10:
					{
						s.name = "authenticationSASL", s.mechanisms = [];
						let o;
						do
							o = this.reader.cstring(), o && s.mechanisms.push(o);
						while (o);
					}
					break;
				case 11:
					s.name = "authenticationSASLContinue", s.data = this.reader.string(t - 8);
					break;
				case 12:
					s.name = "authenticationSASLFinal", s.data = this.reader.string(t - 8);
					break;
				default: throw new Error("Unknown authenticationOk message type " + i);
			}
			return s;
		}
		parseErrorMessage(e, t, n, i) {
			this.reader.setBuffer(e, n);
			let s = {}, o = this.reader.string(1);
			for (; o !== "\0";) s[o] = this.reader.cstring(), o = this.reader.string(1);
			let u = s.M, c = i === "notice" ? new k.NoticeMessage(t, u) : new k.DatabaseError(u, t, i);
			return c.severity = s.S, c.code = s.C, c.detail = s.D, c.hint = s.H, c.position = s.P, c.internalPosition = s.p, c.internalQuery = s.q, c.where = s.W, c.schema = s.s, c.table = s.t, c.column = s.c, c.dataType = s.d, c.constraint = s.n, c.file = s.F, c.line = s.L, c.routine = s.R, c;
		}
	};
	a(bn, "Parser");
	Mt.Parser = bn;
});
var vn = T((xe) => {
	"use strict";
	p();
	Object.defineProperty(xe, "__esModule", { value: !0 });
	xe.DatabaseError = xe.serialize = xe.parse = void 0;
	var Nc = ln();
	Object.defineProperty(xe, "DatabaseError", {
		enumerable: !0,
		get: a(function() {
			return Nc.DatabaseError;
		}, "get")
	});
	var Wc = Ws();
	Object.defineProperty(xe, "serialize", {
		enumerable: !0,
		get: a(function() {
			return Wc.serialize;
		}, "get")
	});
	var jc = Gs();
	function Hc(r, e) {
		let t = new jc.Parser();
		return r.on("data", (n) => t.parse(n, e)), new Promise((n) => r.on("end", () => n()));
	}
	a(Hc, "parse");
	xe.parse = Hc;
});
var Vs = {};
ie(Vs, { connect: () => $c });
function $c({ socket: r, servername: e }) {
	return r.startTls(e), r;
}
var zs = G(() => {
	"use strict";
	p();
	a($c, "connect");
});
var En = T((Xh, Zs) => {
	"use strict";
	p();
	var Ks = (Fe(), O(wi)), Gc = ge().EventEmitter, { parse: Vc, serialize: Q } = vn(), Ys = Q.flush(), zc = Q.sync(), Kc = Q.end(), Sn = class Sn extends Gc {
		constructor(e) {
			super(), e = e || {}, this.stream = e.stream || new Ks.Socket(), this._keepAlive = e.keepAlive, this._keepAliveInitialDelayMillis = e.keepAliveInitialDelayMillis, this.lastBuffer = !1, this.parsedStatements = {}, this.ssl = e.ssl || !1, this._ending = !1, this._emitMessage = !1;
			var t = this;
			this.on("newListener", function(n) {
				n === "message" && (t._emitMessage = !0);
			});
		}
		connect(e, t) {
			var n = this;
			this._connecting = !0, this.stream.setNoDelay(!0), this.stream.connect(e, t), this.stream.once("connect", function() {
				n._keepAlive && n.stream.setKeepAlive(!0, n._keepAliveInitialDelayMillis), n.emit("connect");
			});
			let i = a(function(s) {
				n._ending && (s.code === "ECONNRESET" || s.code === "EPIPE") || n.emit("error", s);
			}, "reportStreamError");
			if (this.stream.on("error", i), this.stream.on("close", function() {
				n.emit("end");
			}), !this.ssl) return this.attachListeners(this.stream);
			this.stream.once("data", function(s) {
				switch (s.toString("utf8")) {
					case "S": break;
					case "N": return n.stream.end(), n.emit("error", /* @__PURE__ */ new Error("The server does not support SSL connections"));
					default: return n.stream.end(), n.emit("error", /* @__PURE__ */ new Error("There was an error establishing an SSL connection"));
				}
				var u = (zs(), O(Vs));
				let c = { socket: n.stream };
				n.ssl !== !0 && (Object.assign(c, n.ssl), "key" in n.ssl && (c.key = n.ssl.key)), Ks.isIP(t) === 0 && (c.servername = t);
				try {
					n.stream = u.connect(c);
				} catch (l) {
					return n.emit("error", l);
				}
				n.attachListeners(n.stream), n.stream.on("error", i), n.emit("sslconnect");
			});
		}
		attachListeners(e) {
			e.on("end", () => {
				this.emit("end");
			}), Vc(e, (t) => {
				var n = t.name === "error" ? "errorMessage" : t.name;
				this._emitMessage && this.emit("message", t), this.emit(n, t);
			});
		}
		requestSsl() {
			this.stream.write(Q.requestSsl());
		}
		startup(e) {
			this.stream.write(Q.startup(e));
		}
		cancel(e, t) {
			this._send(Q.cancel(e, t));
		}
		password(e) {
			this._send(Q.password(e));
		}
		sendSASLInitialResponseMessage(e, t) {
			this._send(Q.sendSASLInitialResponseMessage(e, t));
		}
		sendSCRAMClientFinalMessage(e) {
			this._send(Q.sendSCRAMClientFinalMessage(e));
		}
		_send(e) {
			return this.stream.writable ? this.stream.write(e) : !1;
		}
		query(e) {
			this._send(Q.query(e));
		}
		parse(e) {
			this._send(Q.parse(e));
		}
		bind(e) {
			this._send(Q.bind(e));
		}
		execute(e) {
			this._send(Q.execute(e));
		}
		flush() {
			this.stream.writable && this.stream.write(Ys);
		}
		sync() {
			this._ending = !0, this._send(Ys), this._send(zc);
		}
		ref() {
			this.stream.ref();
		}
		unref() {
			this.stream.unref();
		}
		end() {
			if (this._ending = !0, !this._connecting || !this.stream.writable) {
				this.stream.end();
				return;
			}
			return this.stream.write(Kc, () => {
				this.stream.end();
			});
		}
		close(e) {
			this._send(Q.close(e));
		}
		describe(e) {
			this._send(Q.describe(e));
		}
		sendCopyFromChunk(e) {
			this._send(Q.copyData(e));
		}
		endCopyFrom() {
			this._send(Q.copyDone());
		}
		sendCopyFail(e) {
			this._send(Q.copyFail(e));
		}
	};
	a(Sn, "Connection");
	Zs.exports = Sn;
});
var eo = T((np, Xs) => {
	"use strict";
	p();
	var Yc = ge().EventEmitter;
	it(), O(nt);
	var Zc = rt(), An = ds(), Jc = Cs(), Xc = At(), el = Rt(), Js = qs(), tl = tt(), rl = En(), Cn = class Cn extends Yc {
		constructor(e) {
			super(), this.connectionParameters = new el(e), this.user = this.connectionParameters.user, this.database = this.connectionParameters.database, this.port = this.connectionParameters.port, this.host = this.connectionParameters.host, Object.defineProperty(this, "password", {
				configurable: !0,
				enumerable: !1,
				writable: !0,
				value: this.connectionParameters.password
			}), this.replication = this.connectionParameters.replication;
			var t = e || {};
			this._Promise = t.Promise || b.Promise, this._types = new Xc(t.types), this._ending = !1, this._connecting = !1, this._connected = !1, this._connectionError = !1, this._queryable = !0, this.connection = t.connection || new rl({
				stream: t.stream,
				ssl: this.connectionParameters.ssl,
				keepAlive: t.keepAlive || !1,
				keepAliveInitialDelayMillis: t.keepAliveInitialDelayMillis || 0,
				encoding: this.connectionParameters.client_encoding || "utf8"
			}), this.queryQueue = [], this.binary = t.binary || tl.binary, this.processID = null, this.secretKey = null, this.ssl = this.connectionParameters.ssl || !1, this.ssl && this.ssl.key && Object.defineProperty(this.ssl, "key", { enumerable: !1 }), this._connectionTimeoutMillis = t.connectionTimeoutMillis || 0;
		}
		_errorAllQueries(e) {
			let t = a((n) => {
				m.nextTick(() => {
					n.handleError(e, this.connection);
				});
			}, "enqueueError");
			this.activeQuery && (t(this.activeQuery), this.activeQuery = null), this.queryQueue.forEach(t), this.queryQueue.length = 0;
		}
		_connect(e) {
			var t = this, n = this.connection;
			if (this._connectionCallback = e, this._connecting || this._connected) {
				let i = /* @__PURE__ */ new Error("Client has already been connected. You cannot reuse a client.");
				m.nextTick(() => {
					e(i);
				});
				return;
			}
			this._connecting = !0, this.connectionTimeoutHandle, this._connectionTimeoutMillis > 0 && (this.connectionTimeoutHandle = setTimeout(() => {
				n._ending = !0, n.stream.destroy(/* @__PURE__ */ new Error("timeout expired"));
			}, this._connectionTimeoutMillis)), this.host && this.host.indexOf("/") === 0 ? n.connect(this.host + "/.s.PGSQL." + this.port) : n.connect(this.port, this.host), n.on("connect", function() {
				t.ssl ? n.requestSsl() : n.startup(t.getStartupConf());
			}), n.on("sslconnect", function() {
				n.startup(t.getStartupConf());
			}), this._attachListeners(n), n.once("end", () => {
				let i = this._ending ? /* @__PURE__ */ new Error("Connection terminated") : /* @__PURE__ */ new Error("Connection terminated unexpectedly");
				clearTimeout(this.connectionTimeoutHandle), this._errorAllQueries(i), this._ending || (this._connecting && !this._connectionError ? this._connectionCallback ? this._connectionCallback(i) : this._handleErrorEvent(i) : this._connectionError || this._handleErrorEvent(i)), m.nextTick(() => {
					this.emit("end");
				});
			});
		}
		connect(e) {
			if (e) {
				this._connect(e);
				return;
			}
			return new this._Promise((t, n) => {
				this._connect((i) => {
					i ? n(i) : t();
				});
			});
		}
		_attachListeners(e) {
			e.on("authenticationCleartextPassword", this._handleAuthCleartextPassword.bind(this)), e.on("authenticationMD5Password", this._handleAuthMD5Password.bind(this)), e.on("authenticationSASL", this._handleAuthSASL.bind(this)), e.on("authenticationSASLContinue", this._handleAuthSASLContinue.bind(this)), e.on("authenticationSASLFinal", this._handleAuthSASLFinal.bind(this)), e.on("backendKeyData", this._handleBackendKeyData.bind(this)), e.on("error", this._handleErrorEvent.bind(this)), e.on("errorMessage", this._handleErrorMessage.bind(this)), e.on("readyForQuery", this._handleReadyForQuery.bind(this)), e.on("notice", this._handleNotice.bind(this)), e.on("rowDescription", this._handleRowDescription.bind(this)), e.on("dataRow", this._handleDataRow.bind(this)), e.on("portalSuspended", this._handlePortalSuspended.bind(this)), e.on("emptyQuery", this._handleEmptyQuery.bind(this)), e.on("commandComplete", this._handleCommandComplete.bind(this)), e.on("parseComplete", this._handleParseComplete.bind(this)), e.on("copyInResponse", this._handleCopyInResponse.bind(this)), e.on("copyData", this._handleCopyData.bind(this)), e.on("notification", this._handleNotification.bind(this));
		}
		_checkPgPass(e) {
			let t = this.connection;
			typeof this.password == "function" ? this._Promise.resolve().then(() => this.password()).then((n) => {
				if (n !== void 0) {
					if (typeof n != "string") {
						t.emit("error", /* @__PURE__ */ new TypeError("Password must be a string"));
						return;
					}
					this.connectionParameters.password = this.password = n;
				} else this.connectionParameters.password = this.password = null;
				e();
			}).catch((n) => {
				t.emit("error", n);
			}) : this.password !== null ? e() : Jc(this.connectionParameters, (n) => {
				n !== void 0 && (this.connectionParameters.password = this.password = n), e();
			});
		}
		_handleAuthCleartextPassword(e) {
			this._checkPgPass(() => {
				this.connection.password(this.password);
			});
		}
		_handleAuthMD5Password(e) {
			this._checkPgPass(() => {
				let t = Zc.postgresMd5PasswordHash(this.user, this.password, e.salt);
				this.connection.password(t);
			});
		}
		_handleAuthSASL(e) {
			this._checkPgPass(() => {
				this.saslSession = An.startSession(e.mechanisms), this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
			});
		}
		_handleAuthSASLContinue(e) {
			An.continueSession(this.saslSession, this.password, e.data), this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
		}
		_handleAuthSASLFinal(e) {
			An.finalizeSession(this.saslSession, e.data), this.saslSession = null;
		}
		_handleBackendKeyData(e) {
			this.processID = e.processID, this.secretKey = e.secretKey;
		}
		_handleReadyForQuery(e) {
			this._connecting && (this._connecting = !1, this._connected = !0, clearTimeout(this.connectionTimeoutHandle), this._connectionCallback && (this._connectionCallback(null, this), this._connectionCallback = null), this.emit("connect"));
			let { activeQuery: t } = this;
			this.activeQuery = null, this.readyForQuery = !0, t && t.handleReadyForQuery(this.connection), this._pulseQueryQueue();
		}
		_handleErrorWhileConnecting(e) {
			if (!this._connectionError) {
				if (this._connectionError = !0, clearTimeout(this.connectionTimeoutHandle), this._connectionCallback) return this._connectionCallback(e);
				this.emit("error", e);
			}
		}
		_handleErrorEvent(e) {
			if (this._connecting) return this._handleErrorWhileConnecting(e);
			this._queryable = !1, this._errorAllQueries(e), this.emit("error", e);
		}
		_handleErrorMessage(e) {
			if (this._connecting) return this._handleErrorWhileConnecting(e);
			let t = this.activeQuery;
			if (!t) {
				this._handleErrorEvent(e);
				return;
			}
			this.activeQuery = null, t.handleError(e, this.connection);
		}
		_handleRowDescription(e) {
			this.activeQuery.handleRowDescription(e);
		}
		_handleDataRow(e) {
			this.activeQuery.handleDataRow(e);
		}
		_handlePortalSuspended(e) {
			this.activeQuery.handlePortalSuspended(this.connection);
		}
		_handleEmptyQuery(e) {
			this.activeQuery.handleEmptyQuery(this.connection);
		}
		_handleCommandComplete(e) {
			this.activeQuery.handleCommandComplete(e, this.connection);
		}
		_handleParseComplete(e) {
			this.activeQuery.name && (this.connection.parsedStatements[this.activeQuery.name] = this.activeQuery.text);
		}
		_handleCopyInResponse(e) {
			this.activeQuery.handleCopyInResponse(this.connection);
		}
		_handleCopyData(e) {
			this.activeQuery.handleCopyData(e, this.connection);
		}
		_handleNotification(e) {
			this.emit("notification", e);
		}
		_handleNotice(e) {
			this.emit("notice", e);
		}
		getStartupConf() {
			var e = this.connectionParameters, t = {
				user: e.user,
				database: e.database
			}, n = e.application_name || e.fallback_application_name;
			return n && (t.application_name = n), e.replication && (t.replication = "" + e.replication), e.statement_timeout && (t.statement_timeout = String(parseInt(e.statement_timeout, 10))), e.lock_timeout && (t.lock_timeout = String(parseInt(e.lock_timeout, 10))), e.idle_in_transaction_session_timeout && (t.idle_in_transaction_session_timeout = String(parseInt(e.idle_in_transaction_session_timeout, 10))), e.options && (t.options = e.options), t;
		}
		cancel(e, t) {
			if (e.activeQuery === t) {
				var n = this.connection;
				this.host && this.host.indexOf("/") === 0 ? n.connect(this.host + "/.s.PGSQL." + this.port) : n.connect(this.port, this.host), n.on("connect", function() {
					n.cancel(e.processID, e.secretKey);
				});
			} else e.queryQueue.indexOf(t) !== -1 && e.queryQueue.splice(e.queryQueue.indexOf(t), 1);
		}
		setTypeParser(e, t, n) {
			return this._types.setTypeParser(e, t, n);
		}
		getTypeParser(e, t) {
			return this._types.getTypeParser(e, t);
		}
		escapeIdentifier(e) {
			return "\"" + e.replace(/"/g, "\"\"") + "\"";
		}
		escapeLiteral(e) {
			for (var t = !1, n = "'", i = 0; i < e.length; i++) {
				var s = e[i];
				s === "'" ? n += s + s : s === "\\" ? (n += s + s, t = !0) : n += s;
			}
			return n += "'", t === !0 && (n = " E" + n), n;
		}
		_pulseQueryQueue() {
			if (this.readyForQuery === !0) if (this.activeQuery = this.queryQueue.shift(), this.activeQuery) {
				this.readyForQuery = !1, this.hasExecuted = !0;
				let e = this.activeQuery.submit(this.connection);
				e && m.nextTick(() => {
					this.activeQuery.handleError(e, this.connection), this.readyForQuery = !0, this._pulseQueryQueue();
				});
			} else this.hasExecuted && (this.activeQuery = null, this.emit("drain"));
		}
		query(e, t, n) {
			var i, s, o, u, c;
			if (e == null) throw new TypeError("Client was passed a null or undefined query");
			return typeof e.submit == "function" ? (o = e.query_timeout || this.connectionParameters.query_timeout, s = i = e, typeof t == "function" && (i.callback = i.callback || t)) : (o = this.connectionParameters.query_timeout, i = new Js(e, t, n), i.callback || (s = new this._Promise((l, f) => {
				i.callback = (y, g) => y ? f(y) : l(g);
			}))), o && (c = i.callback, u = setTimeout(() => {
				var l = /* @__PURE__ */ new Error("Query read timeout");
				m.nextTick(() => {
					i.handleError(l, this.connection);
				}), c(l), i.callback = () => {};
				var f = this.queryQueue.indexOf(i);
				f > -1 && this.queryQueue.splice(f, 1), this._pulseQueryQueue();
			}, o), i.callback = (l, f) => {
				clearTimeout(u), c(l, f);
			}), this.binary && !i.binary && (i.binary = !0), i._result && !i._result._types && (i._result._types = this._types), this._queryable ? this._ending ? (m.nextTick(() => {
				i.handleError(/* @__PURE__ */ new Error("Client was closed and is not queryable"), this.connection);
			}), s) : (this.queryQueue.push(i), this._pulseQueryQueue(), s) : (m.nextTick(() => {
				i.handleError(/* @__PURE__ */ new Error("Client has encountered a connection error and is not queryable"), this.connection);
			}), s);
		}
		ref() {
			this.connection.ref();
		}
		unref() {
			this.connection.unref();
		}
		end(e) {
			if (this._ending = !0, !this.connection._connecting) if (e) e();
			else return this._Promise.resolve();
			if (this.activeQuery || !this._queryable ? this.connection.stream.destroy() : this.connection.end(), e) this.connection.once("end", e);
			else return new this._Promise((t) => {
				this.connection.once("end", t);
			});
		}
	};
	a(Cn, "Client");
	var Ut = Cn;
	Ut.Query = Js;
	Xs.exports = Ut;
});
var io = T((op, no) => {
	"use strict";
	p();
	var nl = ge().EventEmitter, to = a(function() {}, "NOOP"), ro = a((r, e) => {
		let t = r.findIndex(e);
		return t === -1 ? void 0 : r.splice(t, 1)[0];
	}, "removeWhere"), Tn = class Tn {
		constructor(e, t, n) {
			this.client = e, this.idleListener = t, this.timeoutId = n;
		}
	};
	a(Tn, "IdleItem");
	var _n = Tn, Pn = class Pn {
		constructor(e) {
			this.callback = e;
		}
	};
	a(Pn, "PendingItem");
	var Qe = Pn;
	function il() {
		throw new Error("Release called on client which has already been released to the pool.");
	}
	a(il, "throwOnDoubleRelease");
	function Dt(r, e) {
		if (e) return {
			callback: e,
			result: void 0
		};
		let t, n;
		return {
			callback: a(function(o, u) {
				o ? t(o) : n(u);
			}, "cb"),
			result: new r(function(o, u) {
				n = o, t = u;
			}).catch((o) => {
				throw Error.captureStackTrace(o), o;
			})
		};
	}
	a(Dt, "promisify");
	function sl(r, e) {
		return a(function t(n) {
			n.client = e, e.removeListener("error", t), e.on("error", () => {
				r.log("additional client error after disconnection due to error", n);
			}), r._remove(e), r.emit("error", n, e);
		}, "idleListener");
	}
	a(sl, "makeIdleListener");
	var Rn = class Rn extends nl {
		constructor(e, t) {
			super(), this.options = Object.assign({}, e), e != null && "password" in e && Object.defineProperty(this.options, "password", {
				configurable: !0,
				enumerable: !1,
				writable: !0,
				value: e.password
			}), e != null && e.ssl && e.ssl.key && Object.defineProperty(this.options.ssl, "key", { enumerable: !1 }), this.options.max = this.options.max || this.options.poolSize || 10, this.options.min = this.options.min || 0, this.options.maxUses = this.options.maxUses || 1 / 0, this.options.allowExitOnIdle = this.options.allowExitOnIdle || !1, this.options.maxLifetimeSeconds = this.options.maxLifetimeSeconds || 0, this.log = this.options.log || function() {}, this.Client = this.options.Client || t || ot().Client, this.Promise = this.options.Promise || b.Promise, typeof this.options.idleTimeoutMillis > "u" && (this.options.idleTimeoutMillis = 1e4), this._clients = [], this._idle = [], this._expired = /* @__PURE__ */ new WeakSet(), this._pendingQueue = [], this._endCallback = void 0, this.ending = !1, this.ended = !1;
		}
		_isFull() {
			return this._clients.length >= this.options.max;
		}
		_isAboveMin() {
			return this._clients.length > this.options.min;
		}
		_pulseQueue() {
			if (this.log("pulse queue"), this.ended) {
				this.log("pulse queue ended");
				return;
			}
			if (this.ending) {
				this.log("pulse queue on ending"), this._idle.length && this._idle.slice().map((t) => {
					this._remove(t.client);
				}), this._clients.length || (this.ended = !0, this._endCallback());
				return;
			}
			if (!this._pendingQueue.length) {
				this.log("no queued requests");
				return;
			}
			if (!this._idle.length && this._isFull()) return;
			let e = this._pendingQueue.shift();
			if (this._idle.length) {
				let t = this._idle.pop();
				clearTimeout(t.timeoutId);
				let n = t.client;
				n.ref && n.ref();
				let i = t.idleListener;
				return this._acquireClient(n, e, i, !1);
			}
			if (!this._isFull()) return this.newClient(e);
			throw new Error("unexpected condition");
		}
		_remove(e) {
			let t = ro(this._idle, (n) => n.client === e);
			t !== void 0 && clearTimeout(t.timeoutId), this._clients = this._clients.filter((n) => n !== e), e.end(), this.emit("remove", e);
		}
		connect(e) {
			if (this.ending) {
				let i = /* @__PURE__ */ new Error("Cannot use a pool after calling end on the pool");
				return e ? e(i) : this.Promise.reject(i);
			}
			let t = Dt(this.Promise, e), n = t.result;
			if (this._isFull() || this._idle.length) {
				if (this._idle.length && m.nextTick(() => this._pulseQueue()), !this.options.connectionTimeoutMillis) return this._pendingQueue.push(new Qe(t.callback)), n;
				let i = a((u, c, l) => {
					clearTimeout(o), t.callback(u, c, l);
				}, "queueCallback"), s = new Qe(i), o = setTimeout(() => {
					ro(this._pendingQueue, (u) => u.callback === i), s.timedOut = !0, t.callback(/* @__PURE__ */ new Error("timeout exceeded when trying to connect"));
				}, this.options.connectionTimeoutMillis);
				return o.unref && o.unref(), this._pendingQueue.push(s), n;
			}
			return this.newClient(new Qe(t.callback)), n;
		}
		newClient(e) {
			let t = new this.Client(this.options);
			this._clients.push(t);
			let n = sl(this, t);
			this.log("checking client timeout");
			let i, s = !1;
			this.options.connectionTimeoutMillis && (i = setTimeout(() => {
				this.log("ending client due to timeout"), s = !0, t.connection ? t.connection.stream.destroy() : t.end();
			}, this.options.connectionTimeoutMillis)), this.log("connecting new client"), t.connect((o) => {
				if (i && clearTimeout(i), t.on("error", n), o) this.log("client failed to connect", o), this._clients = this._clients.filter((u) => u !== t), s && (o = new Error("Connection terminated due to connection timeout", { cause: o })), this._pulseQueue(), e.timedOut || e.callback(o, void 0, to);
				else {
					if (this.log("new client connected"), this.options.maxLifetimeSeconds !== 0) {
						let u = setTimeout(() => {
							this.log("ending client due to expired lifetime"), this._expired.add(t), this._idle.findIndex((l) => l.client === t) !== -1 && this._acquireClient(t, new Qe((l, f, y) => y()), n, !1);
						}, this.options.maxLifetimeSeconds * 1e3);
						u.unref(), t.once("end", () => clearTimeout(u));
					}
					return this._acquireClient(t, e, n, !0);
				}
			});
		}
		_acquireClient(e, t, n, i) {
			i && this.emit("connect", e), this.emit("acquire", e), e.release = this._releaseOnce(e, n), e.removeListener("error", n), t.timedOut ? i && this.options.verify ? this.options.verify(e, e.release) : e.release() : i && this.options.verify ? this.options.verify(e, (s) => {
				if (s) return e.release(s), t.callback(s, void 0, to);
				t.callback(void 0, e, e.release);
			}) : t.callback(void 0, e, e.release);
		}
		_releaseOnce(e, t) {
			let n = !1;
			return (i) => {
				n && il(), n = !0, this._release(e, t, i);
			};
		}
		_release(e, t, n) {
			if (e.on("error", t), e._poolUseCount = (e._poolUseCount || 0) + 1, this.emit("release", n, e), n || this.ending || !e._queryable || e._ending || e._poolUseCount >= this.options.maxUses) {
				e._poolUseCount >= this.options.maxUses && this.log("remove expended client"), this._remove(e), this._pulseQueue();
				return;
			}
			if (this._expired.has(e)) {
				this.log("remove expired client"), this._expired.delete(e), this._remove(e), this._pulseQueue();
				return;
			}
			let s;
			this.options.idleTimeoutMillis && this._isAboveMin() && (s = setTimeout(() => {
				this.log("remove idle client"), this._remove(e);
			}, this.options.idleTimeoutMillis), this.options.allowExitOnIdle && s.unref()), this.options.allowExitOnIdle && e.unref(), this._idle.push(new _n(e, t, s)), this._pulseQueue();
		}
		query(e, t, n) {
			if (typeof e == "function") {
				let s = Dt(this.Promise, e);
				return v(function() {
					return s.callback(/* @__PURE__ */ new Error("Passing a function as the first parameter to pool.query is not supported"));
				}), s.result;
			}
			typeof t == "function" && (n = t, t = void 0);
			let i = Dt(this.Promise, n);
			return n = i.callback, this.connect((s, o) => {
				if (s) return n(s);
				let u = !1, c = a((l) => {
					u || (u = !0, o.release(l), n(l));
				}, "onError");
				o.once("error", c), this.log("dispatching query");
				try {
					o.query(e, t, (l, f) => {
						if (this.log("query dispatched"), o.removeListener("error", c), !u) return u = !0, o.release(l), l ? n(l) : n(void 0, f);
					});
				} catch (l) {
					return o.release(l), n(l);
				}
			}), i.result;
		}
		end(e) {
			if (this.log("ending"), this.ending) {
				let n = /* @__PURE__ */ new Error("Called end on pool more than once");
				return e ? e(n) : this.Promise.reject(n);
			}
			this.ending = !0;
			let t = Dt(this.Promise, e);
			return this._endCallback = t.callback, this._pulseQueue(), t.result;
		}
		get waitingCount() {
			return this._pendingQueue.length;
		}
		get idleCount() {
			return this._idle.length;
		}
		get expiredCount() {
			return this._clients.reduce((e, t) => e + (this._expired.has(t) ? 1 : 0), 0);
		}
		get totalCount() {
			return this._clients.length;
		}
	};
	a(Rn, "Pool");
	no.exports = Rn;
});
var so = {};
ie(so, { default: () => ol });
var ol;
var oo = G(() => {
	"use strict";
	p();
	ol = {};
});
var ao = T((lp, al) => {
	al.exports = {
		name: "pg",
		version: "8.8.0",
		description: "PostgreSQL client - pure javascript & libpq with the same API",
		keywords: [
			"database",
			"libpq",
			"pg",
			"postgre",
			"postgres",
			"postgresql",
			"rdbms"
		],
		homepage: "https://github.com/brianc/node-postgres",
		repository: {
			type: "git",
			url: "git://github.com/brianc/node-postgres.git",
			directory: "packages/pg"
		},
		author: "Brian Carlson <brian.m.carlson@gmail.com>",
		main: "./lib",
		dependencies: {
			"buffer-writer": "2.0.0",
			"packet-reader": "1.0.0",
			"pg-connection-string": "^2.5.0",
			"pg-pool": "^3.5.2",
			"pg-protocol": "^1.5.0",
			"pg-types": "^2.1.0",
			pgpass: "1.x"
		},
		devDependencies: {
			async: "2.6.4",
			bluebird: "3.5.2",
			co: "4.6.0",
			"pg-copy-streams": "0.3.0"
		},
		peerDependencies: { "pg-native": ">=3.0.1" },
		peerDependenciesMeta: { "pg-native": { optional: !0 } },
		scripts: { test: "make test-all" },
		files: ["lib", "SPONSORS.md"],
		license: "MIT",
		engines: { node: ">= 8.0.0" },
		gitHead: "c99fb2c127ddf8d712500db2c7b9a5491a178655"
	};
});
var lo = T((fp, co) => {
	"use strict";
	p();
	var uo = ge().EventEmitter, ul = (it(), O(nt)), Bn = rt(), Ne = co.exports = function(r, e, t) {
		uo.call(this), r = Bn.normalizeQueryConfig(r, e, t), this.text = r.text, this.values = r.values, this.name = r.name, this.callback = r.callback, this.state = "new", this._arrayMode = r.rowMode === "array", this._emitRowEvents = !1, this.on("newListener", function(n) {
			n === "row" && (this._emitRowEvents = !0);
		}.bind(this));
	};
	ul.inherits(Ne, uo);
	var cl = {
		sqlState: "code",
		statementPosition: "position",
		messagePrimary: "message",
		context: "where",
		schemaName: "schema",
		tableName: "table",
		columnName: "column",
		dataTypeName: "dataType",
		constraintName: "constraint",
		sourceFile: "file",
		sourceLine: "line",
		sourceFunction: "routine"
	};
	Ne.prototype.handleError = function(r) {
		var e = this.native.pq.resultErrorFields();
		if (e) for (var t in e) {
			var n = cl[t] || t;
			r[n] = e[t];
		}
		this.callback ? this.callback(r) : this.emit("error", r), this.state = "error";
	};
	Ne.prototype.then = function(r, e) {
		return this._getPromise().then(r, e);
	};
	Ne.prototype.catch = function(r) {
		return this._getPromise().catch(r);
	};
	Ne.prototype._getPromise = function() {
		return this._promise ? this._promise : (this._promise = new Promise(function(r, e) {
			this._once("end", r), this._once("error", e);
		}.bind(this)), this._promise);
	};
	Ne.prototype.submit = function(r) {
		this.state = "running";
		var e = this;
		this.native = r.native, r.native.arrayMode = this._arrayMode;
		var t = a(function(s, o, u) {
			if (r.native.arrayMode = !1, v(function() {
				e.emit("_done");
			}), s) return e.handleError(s);
			e._emitRowEvents && (u.length > 1 ? o.forEach((c, l) => {
				c.forEach((f) => {
					e.emit("row", f, u[l]);
				});
			}) : o.forEach(function(c) {
				e.emit("row", c, u);
			})), e.state = "end", e.emit("end", u), e.callback && e.callback(null, u);
		}, "after");
		if (m.domain && (t = m.domain.bind(t)), this.name) {
			this.name.length > 63 && (console.error("Warning! Postgres only supports 63 characters for query names."), console.error("You supplied %s (%s)", this.name, this.name.length), console.error("This can cause conflicts and silent errors executing queries"));
			var n = (this.values || []).map(Bn.prepareValue);
			if (r.namedQueries[this.name]) {
				if (this.text && r.namedQueries[this.name] !== this.text) {
					let s = /* @__PURE__ */ new Error(`Prepa\
red statements must be unique - '${this.name}' was used for a different statement`);
					return t(s);
				}
				return r.native.execute(this.name, n, t);
			}
			return r.native.prepare(this.name, this.text, n.length, function(s) {
				return s ? t(s) : (r.namedQueries[e.name] = e.text, e.native.execute(e.name, n, t));
			});
		} else if (this.values) {
			if (!Array.isArray(this.values)) return t(/* @__PURE__ */ new Error("Query values must be an array"));
			var i = this.values.map(Bn.prepareValue);
			r.native.query(this.text, i, t);
		} else r.native.query(this.text, t);
	};
});
var yo = T((yp, po) => {
	"use strict";
	p();
	var ll = (oo(), O(so)), fl = At();
	ao();
	var fo = ge().EventEmitter, hl = (it(), O(nt)), pl = Rt(), ho = lo(), K = po.exports = function(r) {
		fo.call(this), r = r || {}, this._Promise = r.Promise || b.Promise, this._types = new fl(r.types), this.native = new ll({ types: this._types }), this._queryQueue = [], this._ending = !1, this._connecting = !1, this._connected = !1, this._queryable = !0;
		var e = this.connectionParameters = new pl(r);
		this.user = e.user, Object.defineProperty(this, "password", {
			configurable: !0,
			enumerable: !1,
			writable: !0,
			value: e.password
		}), this.database = e.database, this.host = e.host, this.port = e.port, this.namedQueries = {};
	};
	K.Query = ho;
	hl.inherits(K, fo);
	K.prototype._errorAllQueries = function(r) {
		let e = a((t) => {
			m.nextTick(() => {
				t.native = this.native, t.handleError(r);
			});
		}, "enqueueError");
		this._hasActiveQuery() && (e(this._activeQuery), this._activeQuery = null), this._queryQueue.forEach(e), this._queryQueue.length = 0;
	};
	K.prototype._connect = function(r) {
		var e = this;
		if (this._connecting) {
			m.nextTick(() => r(/* @__PURE__ */ new Error("Client has already been connected. You cannot reuse a client.")));
			return;
		}
		this._connecting = !0, this.connectionParameters.getLibpqConnectionString(function(t, n) {
			if (t) return r(t);
			e.native.connect(n, function(i) {
				if (i) return e.native.end(), r(i);
				e._connected = !0, e.native.on("error", function(s) {
					e._queryable = !1, e._errorAllQueries(s), e.emit("error", s);
				}), e.native.on("notification", function(s) {
					e.emit("notification", {
						channel: s.relname,
						payload: s.extra
					});
				}), e.emit("connect"), e._pulseQueryQueue(!0), r();
			});
		});
	};
	K.prototype.connect = function(r) {
		if (r) {
			this._connect(r);
			return;
		}
		return new this._Promise((e, t) => {
			this._connect((n) => {
				n ? t(n) : e();
			});
		});
	};
	K.prototype.query = function(r, e, t) {
		var n, i, s, o, u;
		if (r == null) throw new TypeError("Client was passed a null or undefined query");
		if (typeof r.submit == "function") s = r.query_timeout || this.connectionParameters.query_timeout, i = n = r, typeof e == "function" && (r.callback = e);
		else if (s = this.connectionParameters.query_timeout, n = new ho(r, e, t), !n.callback) {
			let c, l;
			i = new this._Promise((f, y) => {
				c = f, l = y;
			}), n.callback = (f, y) => f ? l(f) : c(y);
		}
		return s && (u = n.callback, o = setTimeout(() => {
			var c = /* @__PURE__ */ new Error("Query read timeout");
			m.nextTick(() => {
				n.handleError(c, this.connection);
			}), u(c), n.callback = () => {};
			var l = this._queryQueue.indexOf(n);
			l > -1 && this._queryQueue.splice(l, 1), this._pulseQueryQueue();
		}, s), n.callback = (c, l) => {
			clearTimeout(o), u(c, l);
		}), this._queryable ? this._ending ? (n.native = this.native, m.nextTick(() => {
			n.handleError(/* @__PURE__ */ new Error("Client was closed and is not queryable"));
		}), i) : (this._queryQueue.push(n), this._pulseQueryQueue(), i) : (n.native = this.native, m.nextTick(() => {
			n.handleError(/* @__PURE__ */ new Error("Client has encountered a connection error and is not queryable"));
		}), i);
	};
	K.prototype.end = function(r) {
		var e = this;
		this._ending = !0, this._connected || this.once("connect", this.end.bind(this, r));
		var t;
		return r || (t = new this._Promise(function(n, i) {
			r = a((s) => s ? i(s) : n(), "cb");
		})), this.native.end(function() {
			e._errorAllQueries(/* @__PURE__ */ new Error("Connection terminated")), m.nextTick(() => {
				e.emit("end"), r && r();
			});
		}), t;
	};
	K.prototype._hasActiveQuery = function() {
		return this._activeQuery && this._activeQuery.state !== "error" && this._activeQuery.state !== "end";
	};
	K.prototype._pulseQueryQueue = function(r) {
		if (this._connected && !this._hasActiveQuery()) {
			var e = this._queryQueue.shift();
			if (!e) {
				r || this.emit("drain");
				return;
			}
			this._activeQuery = e, e.submit(this);
			var t = this;
			e.once("_done", function() {
				t._pulseQueryQueue();
			});
		}
	};
	K.prototype.cancel = function(r) {
		this._activeQuery === r ? this.native.cancel(function() {}) : this._queryQueue.indexOf(r) !== -1 && this._queryQueue.splice(this._queryQueue.indexOf(r), 1);
	};
	K.prototype.ref = function() {};
	K.prototype.unref = function() {};
	K.prototype.setTypeParser = function(r, e, t) {
		return this._types.setTypeParser(r, e, t);
	};
	K.prototype.getTypeParser = function(r, e) {
		return this._types.getTypeParser(r, e);
	};
});
var Ln = T((gp, mo) => {
	"use strict";
	p();
	mo.exports = yo();
});
var ot = T((vp, at) => {
	"use strict";
	p();
	var dl = eo(), yl = tt(), ml = En(), wl = io(), { DatabaseError: gl } = vn(), bl = a((r) => {
		var e;
		return e = class extends wl {
			constructor(n) {
				super(n, r);
			}
		}, a(e, "BoundPool"), e;
	}, "poolFactory"), Fn = a(function(r) {
		this.defaults = yl, this.Client = r, this.Query = this.Client.Query, this.Pool = bl(this.Client), this._pools = [], this.Connection = ml, this.types = Je(), this.DatabaseError = gl;
	}, "PG");
	typeof m.env.NODE_PG_FORCE_NATIVE < "u" ? at.exports = new Fn(Ln()) : (at.exports = new Fn(dl), Object.defineProperty(at.exports, "native", {
		configurable: !0,
		enumerable: !1,
		get() {
			var r = null;
			try {
				r = new Fn(Ln());
			} catch (e) {
				if (e.code !== "MODULE_NOT_FOUND") throw e;
			}
			return Object.defineProperty(at.exports, "native", { value: r }), r;
		}
	}));
});
p();
p();
Fe();
Zt();
p();
var pa = Object.defineProperty;
var da = Object.defineProperties;
var ya = Object.getOwnPropertyDescriptors;
var bi = Object.getOwnPropertySymbols;
var ma = Object.prototype.hasOwnProperty;
var wa = Object.prototype.propertyIsEnumerable;
var vi = a((r, e, t) => e in r ? pa(r, e, {
	enumerable: !0,
	configurable: !0,
	writable: !0,
	value: t
}) : r[e] = t, "__defNormalProp");
var ga = a((r, e) => {
	for (var t in e || (e = {})) ma.call(e, t) && vi(r, t, e[t]);
	if (bi) for (var t of bi(e)) wa.call(e, t) && vi(r, t, e[t]);
	return r;
}, "__spreadValues");
var ba = a((r, e) => da(r, ya(e)), "__spreadProps");
var va = 1008e3;
var xi = new Uint8Array(new Uint16Array([258]).buffer)[0] === 2;
var xa = new TextDecoder();
var Jt = new TextEncoder();
var yt = Jt.encode("0123456789abcdef");
var mt = Jt.encode("0123456789ABCDEF");
var Si = Jt.encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").slice();
Si[62] = 45;
Si[63] = 95;
var He;
var wt;
function Ea(r, { alphabet: e, scratchArr: t } = {}) {
	if (!He) if (He = /* @__PURE__ */ new Uint16Array(256), wt = /* @__PURE__ */ new Uint16Array(256), xi) for (let C = 0; C < 256; C++) He[C] = yt[C & 15] << 8 | yt[C >>> 4], wt[C] = mt[C & 15] << 8 | mt[C >>> 4];
	else for (let C = 0; C < 256; C++) He[C] = yt[C & 15] | yt[C >>> 4] << 8, wt[C] = mt[C & 15] | mt[C >>> 4] << 8;
	r.byteOffset % 4 !== 0 && (r = new Uint8Array(r));
	let n = r.length, i = n >>> 1, s = n >>> 2, o = t || new Uint16Array(n), u = new Uint32Array(r.buffer, r.byteOffset, s), c = new Uint32Array(o.buffer, o.byteOffset, i), l = e === "upper" ? wt : He, f = 0, y = 0, g;
	if (xi) for (; f < s;) g = u[f++], c[y++] = l[g >>> 8 & 255] << 16 | l[g & 255], c[y++] = l[g >>> 24] << 16 | l[g >>> 16 & 255];
	else for (; f < s;) g = u[f++], c[y++] = l[g >>> 24] << 16 | l[g >>> 16 & 255], c[y++] = l[g >>> 8 & 255] << 16 | l[g & 255];
	for (f <<= 2; f < n;) o[f] = l[r[f++]];
	return xa.decode(o.subarray(0, n));
}
a(Ea, "_toHex");
function Aa(r, e = {}) {
	let t = "", n = r.length, i = va >>> 1, s = Math.ceil(n / i), o = new Uint16Array(s > 1 ? i : n);
	for (let u = 0; u < s; u++) {
		let c = u * i, l = c + i;
		t += Ea(r.subarray(c, l), ba(ga({}, e), { scratchArr: o }));
	}
	return t;
}
a(Aa, "_toHexChunked");
function Ei(r, e = {}) {
	return e.alphabet !== "upper" && typeof r.toHex == "function" ? r.toHex() : Aa(r, e);
}
a(Ei, "toHex");
p();
var gt = class gt {
	constructor(e, t) {
		this.strings = e;
		this.values = t;
	}
	toParameterizedQuery(e = {
		query: "",
		params: []
	}) {
		let { strings: t, values: n } = this;
		for (let i = 0, s = t.length; i < s; i++) if (e.query += t[i], i < n.length) {
			let o = n[i];
			if (o instanceof Ge) e.query += o.sql;
			else if (o instanceof Ce) if (o.queryData instanceof gt) o.queryData.toParameterizedQuery(e);
			else {
				if (o.queryData.params?.length) throw new Error("This query is not composable");
				e.query += o.queryData.query;
			}
			else {
				let { params: u } = e;
				u.push(o), e.query += "$" + u.length, (o instanceof d || ArrayBuffer.isView(o)) && (e.query += "::bytea");
			}
		}
		return e;
	}
};
a(gt, "SqlTemplate");
var $e = gt;
var Xt = class Xt {
	constructor(e) {
		this.sql = e;
	}
};
a(Xt, "UnsafeRawSql");
var Ge = Xt;
p();
function bt() {
	typeof window < "u" && typeof document < "u" && typeof console < "u" && typeof console.warn == "function" && console.warn(`          
        ************************************************************
        *                                                          *
        *  WARNING: Running SQL directly from the browser can have *
        *  security implications. Even if your database is         *
        *  protected by Row-Level Security (RLS), use it at your   *
        *  own risk. This approach is great for fast prototyping,  *
        *  but ensure proper safeguards are in place to prevent    *
        *  misuse or execution of expensive SQL queries by your    *
        *  end users.                                              *
        *                                                          *
        *  If you've assessed the risks, suppress this message     *
        *  using the disableWarningInBrowsers configuration        *
        *  parameter.                                              *
        *                                                          *
        ************************************************************`);
}
a(bt, "warnIfBrowser");
Fe();
var as = Se(At());
var us = Se(rt());
var _t = class _t extends Error {
	constructor(t) {
		super(t);
		E(this, "name", "NeonDbError");
		E(this, "severity");
		E(this, "code");
		E(this, "detail");
		E(this, "hint");
		E(this, "position");
		E(this, "internalPosition");
		E(this, "internalQuery");
		E(this, "where");
		E(this, "schema");
		E(this, "table");
		E(this, "column");
		E(this, "dataType");
		E(this, "constraint");
		E(this, "file");
		E(this, "line");
		E(this, "routine");
		E(this, "sourceError");
		"captureStackTrace" in Error && typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, _t);
	}
};
a(_t, "NeonDbError");
var be = _t;
var is = "transaction() expects an array of queries, or a function returning an array of queries";
var Bu = [
	"severity",
	"code",
	"detail",
	"hint",
	"position",
	"internalPosition",
	"internalQuery",
	"where",
	"schema",
	"table",
	"column",
	"dataType",
	"constraint",
	"file",
	"line",
	"routine"
];
function Lu(r) {
	return r instanceof d ? "\\x" + Ei(r) : r;
}
a(Lu, "encodeBuffersAsBytea");
function ss(r) {
	let { query: e, params: t } = r instanceof $e ? r.toParameterizedQuery() : r;
	return {
		query: e,
		params: t.map((n) => Lu((0, us.prepareValue)(n)))
	};
}
a(ss, "prepareQuery");
function cs(r, { arrayMode: e, fullResults: t, fetchOptions: n, isolationLevel: i, readOnly: s, deferrable: o, authToken: u, disableWarningInBrowsers: c } = {}) {
	if (!r) throw new Error("No database connection string was provided to `neon()`. Perhaps an environment variable has not been set?");
	let l;
	try {
		l = Yt(r);
	} catch {
		throw new Error("Database connection string provided to `neon()` is not a valid URL. Connection string: " + String(r));
	}
	let { protocol: f, username: y, hostname: g, port: A, pathname: C } = l;
	if (f !== "postgres:" && f !== "postgresql:" || !y || !g || !C) throw new Error("Database connection string format for `neon()` should be: postgresql://user:password@host.tld/dbname?option=value");
	function D(P, ...I) {
		if (!(Array.isArray(P) && Array.isArray(P.raw) && Array.isArray(I))) throw new Error("This function can now be called only as a tagged-template function: sql`SELECT ${value}`, not sql(\"SELECT $1\", [value], options). For a conventional function call with value placeholders ($1, $2, etc.), use sql.query(\"SELECT $1\", [value], options).");
		return new Ce(Y, new $e(P, I));
	}
	a(D, "templateFn"), D.query = (P, I, w) => new Ce(Y, {
		query: P,
		params: I ?? []
	}, w), D.unsafe = (P) => new Ge(P), D.transaction = async (P, I) => {
		if (typeof P == "function" && (P = P(D)), !Array.isArray(P)) throw new Error(is);
		P.forEach((W) => {
			if (!(W instanceof Ce)) throw new Error(is);
		});
		return Y(P.map((W) => W.queryData), P.map((W) => W.opts ?? {}), I);
	};
	async function Y(P, I, w) {
		let { fetchEndpoint: Z, fetchFunction: W } = ce, J = Array.isArray(P) ? { queries: P.map((ee) => ss(ee)) } : ss(P), X = n ?? {}, se = e ?? !1, oe = t ?? !1, B = i, j = s, le = o;
		w !== void 0 && (w.fetchOptions !== void 0 && (X = {
			...X,
			...w.fetchOptions
		}), w.arrayMode !== void 0 && (se = w.arrayMode), w.fullResults !== void 0 && (oe = w.fullResults), w.isolationLevel !== void 0 && (B = w.isolationLevel), w.readOnly !== void 0 && (j = w.readOnly), w.deferrable !== void 0 && (le = w.deferrable)), I !== void 0 && !Array.isArray(I) && I.fetchOptions !== void 0 && (X = {
			...X,
			...I.fetchOptions
		});
		let de = u;
		!Array.isArray(I) && I?.authToken !== void 0 && (de = I.authToken);
		let We = typeof Z == "function" ? Z(g, A, { jwtAuth: de !== void 0 }) : Z, fe = {
			"Neon-Connection-String": r,
			"Neon-Raw-Text-Output": "true",
			"Neon-Array-Mode": "true"
		}, _e = await Fu(de);
		_e && (fe.Authorization = `Bearer ${_e}`), Array.isArray(P) && (B !== void 0 && (fe["Neon-Batch-Isolation-Level"] = B), j !== void 0 && (fe["Neon-Batch-Read-Only"] = String(j)), le !== void 0 && (fe["Neon-Batch-Deferrable"] = String(le))), c || ce.disableWarningInBrowsers || bt();
		let ye;
		try {
			ye = await (W ?? fetch)(We, {
				method: "POST",
				body: JSON.stringify(J),
				headers: fe,
				...X
			});
		} catch (ee) {
			let M = new be(`Error connecting to database: ${ee}`);
			throw M.sourceError = ee, M;
		}
		if (ye.ok) {
			let ee = await ye.json();
			if (Array.isArray(P)) {
				let M = ee.results;
				if (!Array.isArray(M)) throw new be("Neon internal error: unexpected result format");
				return M.map(($, me) => {
					let Ot = I[me] ?? {};
					return os($, {
						arrayMode: Ot.arrayMode ?? se,
						fullResults: Ot.fullResults ?? oe,
						types: Ot.types
					});
				});
			} else {
				let M = I ?? {};
				return os(ee, {
					arrayMode: M.arrayMode ?? se,
					fullResults: M.fullResults ?? oe,
					types: M.types
				});
			}
		} else {
			let { status: ee } = ye;
			if (ee === 400) {
				let M = await ye.json(), $ = new be(M.message);
				for (let me of Bu) $[me] = M[me] ?? void 0;
				throw $;
			} else throw new be(`Server error (HTTP status ${ee}): ${await ye.text()}`);
		}
	}
	return a(Y, "execute"), D;
}
a(cs, "neon");
var dr = class dr {
	constructor(e, t, n) {
		this.execute = e;
		this.queryData = t;
		this.opts = n;
	}
	then(e, t) {
		return this.execute(this.queryData, this.opts).then(e, t);
	}
	catch(e) {
		return this.execute(this.queryData, this.opts).catch(e);
	}
	finally(e) {
		return this.execute(this.queryData, this.opts).finally(e);
	}
};
a(dr, "NeonQueryPromise");
var Ce = dr;
function os(r, { arrayMode: e, fullResults: t, types: n }) {
	let i = new as.default(n), s = r.fields.map((c) => c.name), o = r.fields.map((c) => i.getTypeParser(c.dataTypeID)), u = e === !0 ? r.rows.map((c) => c.map((l, f) => l === null ? null : o[f](l))) : r.rows.map((c) => Object.fromEntries(c.map((l, f) => [s[f], l === null ? null : o[f](l)])));
	return t ? (r.viaNeonFetch = !0, r.rowAsArray = e, r.rows = u, r._parsers = o, r._types = i, r) : u;
}
a(os, "processQueryResult");
async function Fu(r) {
	if (typeof r == "string") return r;
	if (typeof r == "function") try {
		return await Promise.resolve(r());
	} catch (e) {
		let t = new be("Error getting auth token.");
		throw e instanceof Error && (t = new be(`Error getting auth token: ${e.message}`)), t;
	}
}
a(Fu, "getAuthToken");
p();
var go = Se(ot());
p();
var wo = Se(ot());
var kn = class kn extends wo.Client {
	constructor(t) {
		super(t);
		this.config = t;
	}
	get neonConfig() {
		return this.connection.stream;
	}
	connect(t) {
		let { neonConfig: n } = this;
		n.forceDisablePgSSL && (this.ssl = this.connection.ssl = !1), this.ssl && n.useSecureWebSocket && console.warn("SSL is enabled for both Postgres (e.g. ?sslmode=require in the connection string + forceDisablePgSSL = false) and the WebSocket tunnel (useSecureWebSocket = true). Double encryption will increase latency and CPU usage. It may be appropriate to disable SSL in the Postgres connection parameters or set forceDisablePgSSL = true.");
		let i = typeof this.config != "string" && this.config?.host !== void 0 || typeof this.config != "string" && this.config?.connectionString !== void 0 || m.env.PGHOST !== void 0, s = m.env.USER ?? m.env.USERNAME;
		if (!i && this.host === "localhost" && this.user === s && this.database === s && this.password === null) throw new Error(`No database host or connection string wa\
s set, and key parameters have default values (host: localhost, user: ${s}, db: ${s}, password: null\
). Is an environment variable missing? Alternatively, if you intended to connect with these paramete\
rs, please set the host to 'localhost' explicitly.`);
		let o = super.connect(t), u = n.pipelineTLS && this.ssl, c = n.pipelineConnect === "password";
		if (!u && !n.pipelineConnect) return o;
		let l = this.connection;
		if (u && l.on("connect", () => l.stream.emit("data", "S")), c) {
			l.removeAllListeners("authenticationCleartextPassword"), l.removeAllListeners("readyForQuery"), l.once("readyForQuery", () => l.on("readyForQuery", this._handleReadyForQuery.bind(this)));
			let f = this.ssl ? "sslconnect" : "connect";
			l.on(f, () => {
				this.neonConfig.disableWarningInBrowsers || bt(), this._handleAuthCleartextPassword(), this._handleReadyForQuery();
			});
		}
		return o;
	}
	async _handleAuthSASLContinue(t) {
		if (typeof crypto > "u" || crypto.subtle === void 0 || crypto.subtle.importKey === void 0) throw new Error("Cannot use SASL auth when `crypto.subtle` is not defined");
		let n = crypto.subtle, i = this.saslSession, s = this.password, o = t.data;
		if (i.message !== "SASLInitialResponse" || typeof s != "string" || typeof o != "string") throw new Error("SASL: protocol error");
		let u = Object.fromEntries(o.split(",").map((M) => {
			if (!/^.=/.test(M)) throw new Error("SASL: Invalid attribute pair entry");
			return [M[0], M.substring(2)];
		})), c = u.r, l = u.s, f = u.i;
		if (!c || !/^[!-+--~]+$/.test(c)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing/unprintable");
		if (!l || !/^(?:[a-zA-Z0-9+/]{4})*(?:[a-zA-Z0-9+/]{2}==|[a-zA-Z0-9+/]{3}=)?$/.test(l)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: salt missing/not base64");
		if (!f || !/^[1-9][0-9]*$/.test(f)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: missing/invalid iteration count");
		if (!c.startsWith(i.clientNonce)) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce does not start with client nonce");
		if (c.length === i.clientNonce.length) throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
		let y = parseInt(f, 10), g = d.from(l, "base64"), A = new TextEncoder(), C = A.encode(s), D = await n.importKey("raw", C, {
			name: "HMAC",
			hash: { name: "SHA-256" }
		}, !1, ["sign"]), Y = new Uint8Array(await n.sign("HMAC", D, d.concat([g, d.from([
			0,
			0,
			0,
			1
		])]))), P = Y;
		for (var I = 0; I < y - 1; I++) Y = new Uint8Array(await n.sign("HMAC", D, Y)), P = d.from(P.map((M, $) => P[$] ^ Y[$]));
		let w = P, Z = await n.importKey("raw", w, {
			name: "HMAC",
			hash: { name: "SHA-256" }
		}, !1, ["sign"]), W = new Uint8Array(await n.sign("HMAC", Z, A.encode("Client Key"))), J = await n.digest("SHA-256", W), X = "n=*,r=" + i.clientNonce, se = "r=" + c + ",s=" + l + ",i=" + y, oe = "c=biws,r=" + c, B = X + "," + se + "," + oe, j = await n.importKey("raw", J, {
			name: "HMAC",
			hash: { name: "SHA-256" }
		}, !1, ["sign"]);
		var le = new Uint8Array(await n.sign("HMAC", j, A.encode(B))), We = d.from(W.map((M, $) => W[$] ^ le[$])).toString("base64");
		let fe = await n.importKey("raw", w, {
			name: "HMAC",
			hash: { name: "SHA-256" }
		}, !1, ["sign"]), _e = await n.sign("HMAC", fe, A.encode("Server Key")), ye = await n.importKey("raw", _e, {
			name: "HMAC",
			hash: { name: "SHA-256" }
		}, !1, ["sign"]);
		var ee = d.from(await n.sign("HMAC", ye, A.encode(B)));
		i.message = "SASLResponse", i.serverSignature = ee.toString("base64"), i.response = oe + ",p=" + We, this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
	}
};
a(kn, "NeonClient");
var ut = kn;
Fe();
var bo = Se(Rt());
function vl(r, e) {
	if (e) return {
		callback: e,
		result: void 0
	};
	let t, n;
	return {
		callback: a(function(o, u) {
			o ? t(o) : n(u);
		}, "cb"),
		result: new r(function(o, u) {
			n = o, t = u;
		})
	};
}
a(vl, "promisify");
var Un = class Un extends go.Pool {
	constructor() {
		super(...arguments);
		E(this, "Client", ut);
		E(this, "hasFetchUnsupportedListeners", !1);
		E(this, "addListener", this.on);
	}
	on(t, n) {
		return t !== "error" && (this.hasFetchUnsupportedListeners = !0), super.on(t, n);
	}
	query(t, n, i) {
		if (!ce.poolQueryViaFetch || this.hasFetchUnsupportedListeners || typeof t == "function") return super.query(t, n, i);
		typeof n == "function" && (i = n, n = void 0);
		let s = vl(this.Promise, i);
		i = s.callback;
		try {
			let o = new bo.default(this.options), u = encodeURIComponent, c = encodeURI, l = `postgresql://${u(o.user)}:${u(o.password)}@${u(o.host)}\
/${c(o.database)}`, f = typeof t == "string" ? t : t.text, y = n ?? t.values ?? [];
			cs(l, {
				fullResults: !0,
				arrayMode: t.rowMode === "array"
			}).query(f, y, { types: t.types ?? this.options?.types }).then((A) => i(void 0, A)).catch((A) => i(A));
		} catch (o) {
			i(o);
		}
		return s.result;
	}
};
a(Un, "NeonPool");
var Mn = Un;
Fe();
var ct = Se(ot());
ct.DatabaseError;
ct.defaults;
ct.escapeIdentifier;
ct.escapeLiteral;
var export_types = ct.types;
/*! Bundled license information:

ieee754/index.js:
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)

buffer/index.js:
(*!
* The buffer module from node.js, for the browser.
*
* @author   Feross Aboukhadijeh <https://feross.org>
* @license  MIT
*)
*/
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/neon-http/session.js
var rawQueryConfig = {
	arrayMode: false,
	fullResults: true
};
var queryConfig = {
	arrayMode: true,
	fullResults: true
};
var NeonHttpPreparedQuery = class extends PgPreparedQuery {
	constructor(client, query, logger, cache, queryMetadata, cacheConfig, fields, _isResponseInArrayMode, customResultMapper) {
		super(query, cache, queryMetadata, cacheConfig);
		this.client = client;
		this.logger = logger;
		this.fields = fields;
		this._isResponseInArrayMode = _isResponseInArrayMode;
		this.customResultMapper = customResultMapper;
		this.clientQuery = client.query ?? client;
	}
	static [entityKind] = "NeonHttpPreparedQuery";
	clientQuery;
	/** @internal */
	async execute(placeholderValues = {}, token = this.authToken) {
		const params = fillPlaceholders(this.query.params, placeholderValues);
		this.logger.logQuery(this.query.sql, params);
		const { fields, clientQuery, query, customResultMapper } = this;
		if (!fields && !customResultMapper) return this.queryWithCache(query.sql, params, async () => {
			return clientQuery(query.sql, params, token === void 0 ? rawQueryConfig : {
				...rawQueryConfig,
				authToken: token
			});
		});
		const result = await this.queryWithCache(query.sql, params, async () => {
			return await clientQuery(query.sql, params, token === void 0 ? queryConfig : {
				...queryConfig,
				authToken: token
			});
		});
		return this.mapResult(result);
	}
	mapResult(result) {
		if (!this.fields && !this.customResultMapper) return result;
		const rows = result.rows;
		if (this.customResultMapper) return this.customResultMapper(rows);
		return rows.map((row) => mapResultRow(this.fields, row, this.joinsNotNullableMap));
	}
	all(placeholderValues = {}) {
		const params = fillPlaceholders(this.query.params, placeholderValues);
		this.logger.logQuery(this.query.sql, params);
		return this.clientQuery(this.query.sql, params, this.authToken === void 0 ? rawQueryConfig : {
			...rawQueryConfig,
			authToken: this.authToken
		}).then((result) => result.rows);
	}
	/** @internal */
	values(placeholderValues = {}, token) {
		const params = fillPlaceholders(this.query.params, placeholderValues);
		this.logger.logQuery(this.query.sql, params);
		return this.clientQuery(this.query.sql, params, {
			arrayMode: true,
			fullResults: true,
			authToken: token
		}).then((result) => result.rows);
	}
	/** @internal */
	isResponseInArrayMode() {
		return this._isResponseInArrayMode;
	}
};
var NeonHttpSession = class extends PgSession {
	constructor(client, dialect, schema, options = {}) {
		super(dialect);
		this.client = client;
		this.schema = schema;
		this.options = options;
		this.clientQuery = client.query ?? client;
		this.logger = options.logger ?? new NoopLogger();
		this.cache = options.cache ?? new NoopCache();
	}
	static [entityKind] = "NeonHttpSession";
	clientQuery;
	logger;
	cache;
	prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
		return new NeonHttpPreparedQuery(this.client, query, this.logger, this.cache, queryMetadata, cacheConfig, fields, isResponseInArrayMode, customResultMapper);
	}
	async batch(queries) {
		const preparedQueries = [];
		const builtQueries = [];
		for (const query of queries) {
			const preparedQuery = query._prepare();
			const builtQuery = preparedQuery.getQuery();
			preparedQueries.push(preparedQuery);
			builtQueries.push(this.clientQuery(builtQuery.sql, builtQuery.params, {
				fullResults: true,
				arrayMode: preparedQuery.isResponseInArrayMode()
			}));
		}
		return (await this.client.transaction(builtQueries, queryConfig)).map((result, i) => preparedQueries[i].mapResult(result, true));
	}
	async query(query, params) {
		this.logger.logQuery(query, params);
		return await this.clientQuery(query, params, {
			arrayMode: true,
			fullResults: true
		});
	}
	async queryObjects(query, params) {
		return this.clientQuery(query, params, {
			arrayMode: false,
			fullResults: true
		});
	}
	/** @internal */
	async count(sql, token) {
		const res = await this.execute(sql, token);
		return Number(res["rows"][0]["count"]);
	}
	async transaction(_transaction, _config = {}) {
		throw new Error("No transactions support in neon-http driver");
	}
};
//#endregion
//#region ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260820.1_@electric-sql+pglite@0.5.5_@n_569a67503b62783334b79944c9135f48/node_modules/drizzle-orm/neon-http/driver.js
var NeonHttpDriver = class {
	constructor(client, dialect, options = {}) {
		this.client = client;
		this.dialect = dialect;
		this.options = options;
		this.initMappers();
	}
	static [entityKind] = "NeonHttpDriver";
	createSession(schema) {
		return new NeonHttpSession(this.client, this.dialect, schema, {
			logger: this.options.logger,
			cache: this.options.cache
		});
	}
	initMappers() {
		export_types.setTypeParser(export_types.builtins.TIMESTAMPTZ, (val) => val);
		export_types.setTypeParser(export_types.builtins.TIMESTAMP, (val) => val);
		export_types.setTypeParser(export_types.builtins.DATE, (val) => val);
		export_types.setTypeParser(export_types.builtins.INTERVAL, (val) => val);
		export_types.setTypeParser(1231, (val) => val);
		export_types.setTypeParser(1115, (val) => val);
		export_types.setTypeParser(1185, (val) => val);
		export_types.setTypeParser(1187, (val) => val);
		export_types.setTypeParser(1182, (val) => val);
	}
};
function wrap(target, token, cb, deep) {
	return new Proxy(target, { get(target2, p) {
		const element = target2[p];
		if (typeof element !== "function" && (typeof element !== "object" || element === null)) return element;
		if (deep) return wrap(element, token, cb);
		if (p === "query") return wrap(element, token, cb, true);
		return new Proxy(element, { apply(target3, thisArg, argArray) {
			const res = target3.call(thisArg, ...argArray);
			if (typeof res === "object" && res !== null && "setToken" in res && typeof res.setToken === "function") res.setToken(token);
			return cb(target3, p, res);
		} });
	} });
}
var NeonHttpDatabase = class extends PgDatabase {
	static [entityKind] = "NeonHttpDatabase";
	$withAuth(token) {
		this.authToken = token;
		return wrap(this, token, (target, p, res) => {
			if (p === "with") return wrap(res, token, (_, __, res2) => res2);
			return res;
		});
	}
	async batch(batch) {
		return this.session.batch(batch);
	}
};
function construct(client, config = {}) {
	const dialect = new PgDialect({ casing: config.casing });
	let logger;
	if (config.logger === true) logger = new DefaultLogger();
	else if (config.logger !== false) logger = config.logger;
	let schema;
	if (config.schema) {
		const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
		schema = {
			fullSchema: config.schema,
			schema: tablesConfig.tables,
			tableNamesMap: tablesConfig.tableNamesMap
		};
	}
	const db = new NeonHttpDatabase(dialect, new NeonHttpDriver(client, dialect, {
		logger,
		cache: config.cache
	}).createSession(schema), schema);
	db.$client = client;
	db.$cache = config.cache;
	if (db.$cache) db.$cache["invalidate"] = config.cache?.onMutate;
	return db;
}
function drizzle(...params) {
	if (typeof params[0] === "string") return construct(cs(params[0]), params[1]);
	if (isConfig(params[0])) {
		const { connection, client, ...drizzleConfig } = params[0];
		if (client) return construct(client, drizzleConfig);
		if (typeof connection === "object") {
			const { connectionString, ...options } = connection;
			return construct(cs(connectionString, options), drizzleConfig);
		}
		return construct(cs(connection), drizzleConfig);
	}
	return construct(params[0], params[1]);
}
((drizzle2) => {
	function mock(config) {
		return construct({}, config);
	}
	drizzle2.mock = mock;
})(drizzle || (drizzle = {}));
//#endregion
//#region ../../packages/db/dist/postgres/neon-http.js
function createNeonHttpClient(opts) {
	const sql = cs(opts.connectionString);
	return drizzle(sql, { schema: opts.schema });
}
//#endregion
//#region ../../packages/util/dist/crypto.js
/**
* `@platform-modules/util/crypto` — AES-GCM secrets, SHA-256 hex, portable timing-safe compare.
*
* `timingSafeEqual` is safe only for equal-expected-length comparands (hashes, tokens).
* The length guard returns early — do not use for variable-length secrets.
*/
/** Coerce Uint8Array to BufferSource when DOM + @types/node widen ArrayBufferLike. */
function asBufferSource(bytes) {
	return bytes;
}
/**
* Portable constant-time string comparison (NOT `crypto.subtle.timingSafeEqual` — CF-only).
* Safe only when `a` and `b` are expected to be the same length (e.g. hex hashes).
*/
function timingSafeEqual(a, b) {
	const encoder = new TextEncoder();
	const bufA = encoder.encode(a);
	const bufB = encoder.encode(b);
	if (bufA.byteLength !== bufB.byteLength) return false;
	let diff = 0;
	for (let i = 0; i < bufA.byteLength; i++) diff |= bufA[i] ^ bufB[i];
	return diff === 0;
}
/** URL-safe base64 without padding (`+`→`-`, `/`→`_`). */
function base64url(bytes) {
	const arr = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
	let binary = "";
	for (const b of arr) binary += String.fromCharCode(b);
	return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}
async function importHmacKey(secret, usages) {
	return crypto.subtle.importKey("raw", asBufferSource(new TextEncoder().encode(secret)), {
		name: "HMAC",
		hash: "SHA-256"
	}, false, usages);
}
/**
* HMAC-SHA-256 of `message` under `secret`, returned as URL-safe base64 (no padding).
* Fail-closed on minting: throws on an empty `secret` rather than signing under a weak key.
*/
async function hmacSign(message, secret) {
	if (!secret) throw new Error("hmacSign: secret must be non-empty");
	const key = await importHmacKey(secret, ["sign"]);
	return base64url(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(message)));
}
/**
* Constant-time verify of an `hmacSign` signature over `message` under `secret`.
* Fail-closed: returns false on an empty `secret` or any mismatch — never throws.
* Comparison is timing-safe (recompute-and-compare via {@link timingSafeEqual}).
*/
async function hmacVerify(message, secret, signature) {
	if (!secret) return false;
	return timingSafeEqual(await hmacSign(message, secret), signature);
}
//#endregion
export { PgSession as $, getById as A, trash as B, parseMaintenance as C, exportContent as D, settingsSchema as E, readFlatContentEntries as F, assertActiveContentTransaction as G, visibilityPredicate as H, remove as I, contentEntries as J, assertCanModify as K, restore as L, list as M, publish as N, importContent as O, put as P, PgPreparedQuery as Q, schedule as R, parseHomepage as S, setSetting as T, ContentAuthzError as U, unpublish as V, ContentValidationError as W, listTerms as X, contentSchema as Y, termsForEntry as Z, isValidLogoUrl as _, Mn as a, parseDiscussionConfig as b, isEntityId as c, mapContentError as d, PgTransaction as et, parseIdBody as f, getSetting as g, getAllSettings as h, createNeonHttpClient as i, getBySlug as j, ContentNotFoundError as k, jsonError as l, SETTINGS_KEYS as m, hmacVerify as n, PgDialect as nt, ce as o, DEFAULT_SITE_NAME as p, authorizeContentAction as q, timingSafeEqual as r, count as rt, export_types as s, hmacSign as t, PgDatabase as tt, jsonOk as u, parseBlocklistInput as v, parseSiteIdentity as w, parseHideModeToggle as x, parseConsentConfig as y, setVisibility as z };
