@noormdev/cli 1.0.0-alpha.1 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-RBOB52ZJ.js → chunk-CFWFYGBB.js} +2 -1
- package/dist/{chunk-MQJKW43U.js → chunk-ERDQ5FIO.js} +2 -1
- package/dist/chunk-GGT3S2QA.js +5 -0
- package/dist/{chunk-TGNLDSZU.js → chunk-JNBY3ZU6.js} +3 -2
- package/dist/chunk-KVY4JR2A.js +2 -0
- package/dist/{chunk-O7NFFKRC.js → chunk-QI5B3GSQ.js} +1 -0
- package/dist/{chunk-DGJUBN33.js → chunk-UR6MHSHU.js} +1 -0
- package/dist/{devtools-RJP7TZE6.js → devtools-YYBWFXMQ.js} +2 -1
- package/dist/engine-UAXTESN4.js +2 -0
- package/dist/{esm-FK2ZKTD7.js → esm-74GQLDJV.js} +2 -1
- package/dist/index.js +4 -3
- package/dist/{mssql-2XQG4WUZ.js → mssql-Y7W7F4UH.js} +2 -1
- package/dist/{mysql-XWGAH4UX.js → mysql-EEPNIS5Q.js} +2 -1
- package/dist/{mysql2-KRZWXZIF.js → mysql2-GYI2HTEE.js} +2 -1
- package/dist/{open-QFL643MX.js → open-NGBTRDPN.js} +2 -1
- package/dist/{postgres-KQB7PRSJ.js → postgres-7E352BHM.js} +2 -1
- package/dist/{sqlite-SK4I3XQS.js → sqlite-KSGG7IKM.js} +2 -1
- package/dist/{tarn-E5JKU5EV.js → tarn-LSH7NLRE.js} +2 -1
- package/dist/{tedious-R2TVM4UU.js → tedious-7M6OXIVA.js} +3 -2
- package/package.json +1 -1
- package/dist/chunk-4MUZ22JB.js +0 -4
- package/dist/chunk-BX5KFQ6D.js +0 -1
- package/dist/engine-E7UBRVEC.js +0 -1
|
@@ -1 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
1
2
|
function M(r){return typeof r>"u"||r===void 0}function p(r){return typeof r=="string"}function pe(r){return typeof r=="number"}function ze(r){return typeof r=="boolean"}function Ie(r){return r===null}function ko(r){return r instanceof Date}function Ue(r){return typeof r=="bigint"}function Co(r){return typeof Buffer<"u"&&Buffer.isBuffer(r)}function x(r){return typeof r=="function"}function X(r){return typeof r=="object"&&r!==null}function o(r){return Object.freeze(r)}function Re(r){return C(r)?r:[r]}function C(r){return Array.isArray(r)}function Eo(r){return r}var nt=new Set;function le(r){nt.has(r)||(nt.add(r),console.log(r))}var it=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function st(r){let e="";for(let t=0;t<r;++t)e+=Xt();return e}function Xt(){return it[~~(Math.random()*it.length)]}function w(){return new Wr}var Wr=class{#e;get queryId(){return this.#e===void 0&&(this.#e=st(8)),this.#e}};var g=o({is(r){return r.kind==="AliasNode"},create(r,e){return o({kind:"AliasNode",node:r,alias:e})}});var u=o({is(r){return r.kind==="IdentifierNode"},create(r){return o({kind:"IdentifierNode",name:r})}});var T=o({is(r){return r.kind==="AndNode"},create(r,e){return o({kind:"AndNode",left:r,right:e})}});var P=o({is(r){return r.kind==="OrNode"},create(r,e){return o({kind:"OrNode",left:r,right:e})}});var Ve=o({is(r){return r.kind==="OnNode"},create(r){return o({kind:"OnNode",on:r})},cloneWithOperation(r,e,t){return o({...r,on:e==="And"?T.create(r.on,t):P.create(r.on,t)})}});var Q=o({is(r){return r.kind==="JoinNode"},create(r,e){return o({kind:"JoinNode",joinType:r,table:e,on:void 0})},createWithOn(r,e,t){return o({kind:"JoinNode",joinType:r,table:e,on:Ve.create(t)})},cloneWithOn(r,e){return o({...r,on:r.on?Ve.cloneWithOperation(r.on,"And",e):Ve.create(e)})}});var Je=o({is(r){return r.kind==="ListNode"},create(r){return o({kind:"ListNode",items:o(r)})}});var $e=class{nodeStack=[];#e=o({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let n=this.transformNodeImpl(e,t);return this.nodeStack.pop(),o(n)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){return e&&o(e.map(n=>this.transformNode(n,t)))}transformSelectQuery(e,t){return{kind:"SelectQueryNode",from:this.transformNode(e.from,t),selections:this.transformNodeList(e.selections,t),distinctOn:this.transformNodeList(e.distinctOn,t),joins:this.transformNodeList(e.joins,t),groupBy:this.transformNode(e.groupBy,t),orderBy:this.transformNode(e.orderBy,t),where:this.transformNode(e.where,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),limit:this.transformNode(e.limit,t),offset:this.transformNode(e.offset,t),with:this.transformNode(e.with,t),having:this.transformNode(e.having,t),explain:this.transformNode(e.explain,t),setOperations:this.transformNodeList(e.setOperations,t),fetch:this.transformNode(e.fetch,t),top:this.transformNode(e.top,t)}}transformSelection(e,t){return{kind:"SelectionNode",selection:this.transformNode(e.selection,t)}}transformColumn(e,t){return{kind:"ColumnNode",column:this.transformNode(e.column,t)}}transformAlias(e,t){return{kind:"AliasNode",node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)}}transformTable(e,t){return{kind:"TableNode",table:this.transformNode(e.table,t)}}transformFrom(e,t){return{kind:"FromNode",froms:this.transformNodeList(e.froms,t)}}transformReference(e,t){return{kind:"ReferenceNode",column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)}}transformAnd(e,t){return{kind:"AndNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformOr(e,t){return{kind:"OrNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformValueList(e,t){return{kind:"ValueListNode",values:this.transformNodeList(e.values,t)}}transformParens(e,t){return{kind:"ParensNode",node:this.transformNode(e.node,t)}}transformJoin(e,t){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)}}transformRaw(e,t){return{kind:"RawNode",sqlFragments:o([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)}}transformWhere(e,t){return{kind:"WhereNode",where:this.transformNode(e.where,t)}}transformInsertQuery(e,t){return{kind:"InsertQueryNode",into:this.transformNode(e.into,t),columns:this.transformNodeList(e.columns,t),values:this.transformNode(e.values,t),returning:this.transformNode(e.returning,t),onConflict:this.transformNode(e.onConflict,t),onDuplicateKey:this.transformNode(e.onDuplicateKey,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),ignore:e.ignore,orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformValues(e,t){return{kind:"ValuesNode",values:this.transformNodeList(e.values,t)}}transformDeleteQuery(e,t){return{kind:"DeleteQueryNode",from:this.transformNode(e.from,t),using:this.transformNode(e.using,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orderBy:this.transformNode(e.orderBy,t),limit:this.transformNode(e.limit,t),explain:this.transformNode(e.explain,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformReturning(e,t){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections,t)}}transformCreateTable(e,t){return{kind:"CreateTableNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),selectQuery:this.transformNode(e.selectQuery,t)}}transformColumnDefinition(e,t){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),references:this.transformNode(e.references,t),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,t),check:this.transformNode(e.check,t),generated:this.transformNode(e.generated,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e,t){return{kind:"AddColumnNode",column:this.transformNode(e.column,t)}}transformDropTable(e,t){return{kind:"DropTableNode",table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e,t){return{kind:"OrderByNode",items:this.transformNodeList(e.items,t)}}transformOrderByItem(e,t){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,t),direction:this.transformNode(e.direction,t),collation:this.transformNode(e.collation,t),nulls:e.nulls}}transformGroupBy(e,t){return{kind:"GroupByNode",items:this.transformNodeList(e.items,t)}}transformGroupByItem(e,t){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,t)}}transformUpdateQuery(e,t){return{kind:"UpdateQueryNode",table:this.transformNode(e.table,t),from:this.transformNode(e.from,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),updates:this.transformNodeList(e.updates,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),explain:this.transformNode(e.explain,t),limit:this.transformNode(e.limit,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t),orderBy:this.transformNode(e.orderBy,t)}}transformColumnUpdate(e,t){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)}}transformLimit(e,t){return{kind:"LimitNode",limit:this.transformNode(e.limit,t)}}transformOffset(e,t){return{kind:"OffsetNode",offset:this.transformNode(e.offset,t)}}transformOnConflict(e,t){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns,t),constraint:this.transformNode(e.constraint,t),indexExpression:this.transformNode(e.indexExpression,t),indexWhere:this.transformNode(e.indexWhere,t),updates:this.transformNodeList(e.updates,t),updateWhere:this.transformNode(e.updateWhere,t),doNothing:e.doNothing}}transformOnDuplicateKey(e,t){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,t)}}transformCreateIndex(e,t){return{kind:"CreateIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,t),nullsNotDistinct:e.nullsNotDistinct}}transformList(e,t){return{kind:"ListNode",items:this.transformNodeList(e.items,t)}}transformDropIndex(e,t){return{kind:"DropIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e,t){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformUniqueConstraint(e,t){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformForeignKeyConstraint(e,t){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,t),references:this.transformNode(e.references,t),name:this.transformNode(e.name,t),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformSetOperation(e,t){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all}}transformReferences(e,t){return{kind:"ReferencesNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e,t){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)}}transformWith(e,t){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive}}transformCommonTableExpression(e,t){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)}}transformCommonTableExpressionName(e,t){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)}}transformHaving(e,t){return{kind:"HavingNode",having:this.transformNode(e.having,t)}}transformCreateSchema(e,t){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists}}transformDropSchema(e,t){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e,t){return{kind:"AlterTableNode",table:this.transformNode(e.table,t),renameTo:this.transformNode(e.renameTo,t),setSchema:this.transformNode(e.setSchema,t),columnAlterations:this.transformNodeList(e.columnAlterations,t),addConstraint:this.transformNode(e.addConstraint,t),dropConstraint:this.transformNode(e.dropConstraint,t),renameConstraint:this.transformNode(e.renameConstraint,t),addIndex:this.transformNode(e.addIndex,t),dropIndex:this.transformNode(e.dropIndex,t)}}transformDropColumn(e,t){return{kind:"DropColumnNode",column:this.transformNode(e.column,t)}}transformRenameColumn(e,t){return{kind:"RenameColumnNode",column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)}}transformAlterColumn(e,t){return{kind:"AlterColumnNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),dataTypeExpression:this.transformNode(e.dataTypeExpression,t),setDefault:this.transformNode(e.setDefault,t),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e,t){return{kind:"ModifyColumnNode",column:this.transformNode(e.column,t)}}transformAddConstraint(e,t){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,t)}}transformDropConstraint(e,t){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier}}transformRenameConstraint(e,t){return{kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)}}transformCreateView(e,t){return{kind:"CreateViewNode",name:this.transformNode(e.name,t),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,t),as:this.transformNode(e.as,t)}}transformRefreshMaterializedView(e,t){return{kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData}}transformDropView(e,t){return{kind:"DropViewNode",name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e,t){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)}}transformDefaultValue(e,t){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,t)}}transformOn(e,t){return{kind:"OnNode",on:this.transformNode(e.on,t)}}transformSelectModifier(e,t){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)}}transformCreateType(e,t){return{kind:"CreateTypeNode",name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)}}transformDropType(e,t){return{kind:"DropTypeNode",name:this.transformNode(e.name,t),ifExists:e.ifExists}}transformExplain(e,t){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,t)}}transformSchemableIdentifier(e,t){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)}}transformAggregateFunction(e,t){return{kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,t),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,t),withinGroup:this.transformNode(e.withinGroup,t),filter:this.transformNode(e.filter,t),over:this.transformNode(e.over,t)}}transformOver(e,t){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)}}transformPartitionBy(e,t){return{kind:"PartitionByNode",items:this.transformNodeList(e.items,t)}}transformPartitionByItem(e,t){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,t)}}transformBinaryOperation(e,t){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)}}transformUnaryOperation(e,t){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)}}transformUsing(e,t){return{kind:"UsingNode",tables:this.transformNodeList(e.tables,t)}}transformFunction(e,t){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,t)}}transformCase(e,t){return{kind:"CaseNode",value:this.transformNode(e.value,t),when:this.transformNodeList(e.when,t),else:this.transformNode(e.else,t),isStatement:e.isStatement}}transformWhen(e,t){return{kind:"WhenNode",condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)}}transformJSONReference(e,t){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)}}transformJSONPath(e,t){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)}}transformJSONPathLeg(e,t){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e,t){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)}}transformTuple(e,t){return{kind:"TupleNode",values:this.transformNodeList(e.values,t)}}transformMergeQuery(e,t){return{kind:"MergeQueryNode",into:this.transformNode(e.into,t),using:this.transformNode(e.using,t),whens:this.transformNodeList(e.whens,t),with:this.transformNode(e.with,t),top:this.transformNode(e.top,t),endModifiers:this.transformNodeList(e.endModifiers,t),output:this.transformNode(e.output,t),returning:this.transformNode(e.returning,t)}}transformMatched(e,t){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e,t){return{kind:"AddIndexNode",name:this.transformNode(e.name,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists}}transformCast(e,t){return{kind:"CastNode",expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)}}transformFetch(e,t){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier}}transformTop(e,t){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e,t){return{kind:"OutputNode",selections:this.transformNodeList(e.selections,t)}}transformDataType(e,t){return e}transformSelectAll(e,t){return e}transformIdentifier(e,t){return e}transformValue(e,t){return e}transformPrimitiveValueList(e,t){return e}transformOperator(e,t){return e}transformDefaultInsertValue(e,t){return e}transformOrAction(e,t){return e}transformCollate(e,t){return e}};var Ae=o({is(r){return r.kind==="SchemableIdentifierNode"},create(r){return o({kind:"SchemableIdentifierNode",identifier:u.create(r)})},createWithSchema(r,e){return o({kind:"SchemableIdentifierNode",schema:u.create(r),identifier:u.create(e)})}});var B=o({is(r){return r.kind==="TableNode"},create(r){return o({kind:"TableNode",table:Ae.create(r)})},createWithSchema(r,e){return o({kind:"TableNode",table:Ae.createWithSchema(r,e)})}});var Te=o({is(r){return r.kind==="UsingNode"},create(r){return o({kind:"UsingNode",tables:o(r)})},cloneWithTables(r,e){return o({...r,tables:o([...r.tables,...e])})}});var Zt=o({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),_t={json_agg:!0,to_json:!0},Ge=class extends $e{#e;#r=new Set;#t=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,t){if(!this.#s(e))return super.transformNodeImpl(e,t);let n=this.#u(e);for(let A of n)this.#t.add(A);let i=this.#a(e);for(let A of i)this.#r.add(A);let m=super.transformNodeImpl(e,t);for(let A of i)this.#r.delete(A);for(let A of n)this.#t.delete(A);return m}transformSchemableIdentifier(e,t){let n=super.transformSchemableIdentifier(e,t);return n.schema||!this.#r.has(e.identifier.name)?n:{...n,schema:u.create(this.#e)}}transformReferences(e,t){let n=super.transformReferences(e,t);return n.table.table.schema?n:{...n,table:B.createWithSchema(this.#e,n.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#n(e,t,"aggregated")}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#n(e,t,"arguments")}}transformSelectModifier(e,t){return{...super.transformSelectModifier({...e,of:void 0},t),of:e.of?.map(n=>B.is(n)&&!n.table.schema?{...n,table:this.transformIdentifier(n.table.identifier,t)}:this.transformNode(n,t))}}#n(e,t,n){return _t[e.func]?e[n].map(i=>!B.is(i)||i.table.schema?this.transformNode(i,t):{...i,table:this.transformIdentifier(i.table.identifier,t)}):this.transformNodeList(e[n],t)}#s(e){return e.kind in Zt}#a(e){let t=new Set;if("name"in e&&e.name&&Ae.is(e.name)&&this.#i(e.name,t),"from"in e&&e.from)for(let n of e.from.froms)this.#o(n,t);if("into"in e&&e.into&&this.#o(e.into,t),"table"in e&&e.table&&this.#o(e.table,t),"joins"in e&&e.joins)for(let n of e.joins)this.#o(n.table,t);return"using"in e&&e.using&&(Q.is(e.using)?this.#o(e.using.table,t):this.#o(e.using,t)),t}#u(e){let t=new Set;return"with"in e&&e.with&&this.#d(e.with,t),t}#o(e,t){if(B.is(e))return this.#i(e.table,t);if(g.is(e)&&B.is(e.node))return this.#i(e.node.table,t);if(Je.is(e)){for(let n of e.items)this.#o(n,t);return}if(Te.is(e)){for(let n of e.tables)this.#o(n,t);return}}#i(e,t){let n=e.identifier.name;!this.#r.has(n)&&!this.#t.has(n)&&t.add(n)}#d(e,t){for(let n of e.expressions){let i=n.name.table.table.identifier.name;this.#t.has(i)||t.add(i)}}};var Ne=class{#e;constructor(e){this.#e=new Ge(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};var Be=class{#e;#r;#t;constructor(){this.#e=new Promise((e,t)=>{this.#t=t,this.#r=e})}get promise(){return this.#e}resolve=e=>{this.#r&&this.#r(e)};reject=e=>{this.#t&&this.#t(e)}};async function at(r){let e=new Be,t=new Be;return r.provideConnection(async n=>(e.resolve(n),await t.promise)).catch(n=>e.reject(n)),o({connection:await e.promise,release:t.resolve})}var G=o({is(r){return r.kind==="SelectModifierNode"},create(r,e){return o({kind:"SelectModifierNode",modifier:r,of:e})},createWithExpression(r){return o({kind:"SelectModifierNode",rawModifier:r})}});var oe=o({is(r){return r.kind==="BinaryOperationNode"},create(r,e,t){return o({kind:"BinaryOperationNode",leftOperand:r,operator:e,rightOperand:t})}});function f(r){return X(r)&&x(r.toOperationNode)}var eo=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],ro=["+","-","*","/","%","^","&","|","#","<<",">>"],ut=["->","->>"],to=[...eo,...ro,"&&","||"],oo=["exists","not exists"],no=["not","-",...oo],dt=[...to,...ut,...no,"between","between symmetric"],v=o({is(r){return r.kind==="OperatorNode"},create(r){return o({kind:"OperatorNode",operator:r})}});function Sr(r){return p(r)&&ut.includes(r)}var E=o({is(r){return r.kind==="ColumnNode"},create(r){return o({kind:"ColumnNode",column:u.create(r)})}});var je=o({is(r){return r.kind==="SelectAllNode"},create(){return o({kind:"SelectAllNode"})}});var ye=o({is(r){return r.kind==="ReferenceNode"},create(r,e){return o({kind:"ReferenceNode",table:e,column:r})},createSelectAll(r){return o({kind:"ReferenceNode",table:r,column:je.create()})}});function Ke(r){return X(r)&&"expressionType"in r&&f(r)}function mt(r){return X(r)&&"expression"in r&&p(r.alias)&&f(r)}var me=o({is(r){return r.kind==="FromNode"},create(r){return o({kind:"FromNode",froms:o(r)})},cloneWithFroms(r,e){return o({...r,froms:o([...r.froms,...e])})}});var br=o({is(r){return r.kind==="GroupByNode"},create(r){return o({kind:"GroupByNode",items:o(r)})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var kr=o({is(r){return r.kind==="HavingNode"},create(r){return o({kind:"HavingNode",having:r})},cloneWithOperation(r,e,t){return o({...r,having:e==="And"?T.create(r.having,t):P.create(r.having,t)})}});var l=o({is(r){return r.kind==="InsertQueryNode"},create(r,e,t){return o({kind:"InsertQueryNode",into:r,...e&&{with:e},replace:t})},createWithoutInto(){return o({kind:"InsertQueryNode"})},cloneWith(r,e){return o({...r,...e})}});var j=o({is(r){return r.kind==="UpdateQueryNode"},create(r,e){return o({kind:"UpdateQueryNode",table:r.length===1?r[0]:Je.create(r),...e&&{with:e}})},createWithoutTable(){return o({kind:"UpdateQueryNode"})},cloneWithFromItems(r,e){return o({...r,from:r.from?me.cloneWithFroms(r.from,e):me.create(e)})},cloneWithUpdates(r,e){return o({...r,updates:r.updates?o([...r.updates,...e]):e})},cloneWithLimit(r,e){return o({...r,limit:e})}});var ne=o({is(r){return r.kind==="DeleteQueryNode"},create(r,e){return o({kind:"DeleteQueryNode",from:me.create(r),...e&&{with:e}})},cloneWithOrderByItems:(r,e)=>s.cloneWithOrderByItems(r,e),cloneWithoutOrderBy:r=>s.cloneWithoutOrderBy(r),cloneWithLimit(r,e){return o({...r,limit:e})},cloneWithoutLimit(r){return o({...r,limit:void 0})},cloneWithUsing(r,e){return o({...r,using:r.using!==void 0?Te.cloneWithTables(r.using,e):Te.create(e)})}});var b=o({is(r){return r.kind==="WhereNode"},create(r){return o({kind:"WhereNode",where:r})},cloneWithOperation(r,e,t){return o({...r,where:e==="And"?T.create(r.where,t):P.create(r.where,t)})}});var Cr=o({is(r){return r.kind==="ReturningNode"},create(r){return o({kind:"ReturningNode",selections:o(r)})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})}});var ct=o({is(r){return r.kind==="ExplainNode"},create(r,e){return o({kind:"ExplainNode",format:r,options:e})}});var Z=o({is(r){return r.kind==="WhenNode"},create(r){return o({kind:"WhenNode",condition:r})},cloneWithResult(r,e){return o({...r,result:e})}});var q=o({is(r){return r.kind==="MergeQueryNode"},create(r,e){return o({kind:"MergeQueryNode",into:r,...e&&{with:e}})},cloneWithUsing(r,e){return o({...r,using:e})},cloneWithWhen(r,e){return o({...r,whens:r.whens?o([...r.whens,e]):o([e])})},cloneWithThen(r,e){return o({...r,whens:r.whens?o([...r.whens.slice(0,-1),Z.cloneWithResult(r.whens[r.whens.length-1],e)]):void 0})}});var Er=o({is(r){return r.kind==="OutputNode"},create(r){return o({kind:"OutputNode",selections:o(r)})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})}});var _=o({is(r){return r.kind==="OrderByNode"},create(r){return o({kind:"OrderByNode",items:o([...r])})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var s=o({is(r){return d.is(r)||l.is(r)||j.is(r)||ne.is(r)||q.is(r)},cloneWithEndModifier(r,e){return o({...r,endModifiers:r.endModifiers?o([...r.endModifiers,e]):o([e])})},cloneWithWhere(r,e){return o({...r,where:r.where?b.cloneWithOperation(r.where,"And",e):b.create(e)})},cloneWithJoin(r,e){return o({...r,joins:r.joins?o([...r.joins,e]):o([e])})},cloneWithReturning(r,e){return o({...r,returning:r.returning?Cr.cloneWithSelections(r.returning,e):Cr.create(e)})},cloneWithoutReturning(r){return o({...r,returning:void 0})},cloneWithoutWhere(r){return o({...r,where:void 0})},cloneWithExplain(r,e,t){return o({...r,explain:ct.create(e,t?.toOperationNode())})},cloneWithTop(r,e){return o({...r,top:e})},cloneWithOutput(r,e){return o({...r,output:r.output?Er.cloneWithSelections(r.output,e):Er.create(e)})},cloneWithOrderByItems(r,e){return o({...r,orderBy:r.orderBy?_.cloneWithItems(r.orderBy,e):_.create(e)})},cloneWithoutOrderBy(r){return o({...r,orderBy:void 0})}});var d=o({is(r){return r.kind==="SelectQueryNode"},create(r){return o({kind:"SelectQueryNode",...r&&{with:r}})},createFrom(r,e){return o({kind:"SelectQueryNode",from:me.create(r),...e&&{with:e}})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})},cloneWithDistinctOn(r,e){return o({...r,distinctOn:r.distinctOn?o([...r.distinctOn,...e]):o(e)})},cloneWithFrontModifier(r,e){return o({...r,frontModifiers:r.frontModifiers?o([...r.frontModifiers,e]):o([e])})},cloneWithOrderByItems:(r,e)=>s.cloneWithOrderByItems(r,e),cloneWithGroupByItems(r,e){return o({...r,groupBy:r.groupBy?br.cloneWithItems(r.groupBy,e):br.create(e)})},cloneWithLimit(r,e){return o({...r,limit:e})},cloneWithOffset(r,e){return o({...r,offset:e})},cloneWithFetch(r,e){return o({...r,fetch:e})},cloneWithHaving(r,e){return o({...r,having:r.having?kr.cloneWithOperation(r.having,"And",e):kr.create(e)})},cloneWithSetOperations(r,e){return o({...r,setOperations:r.setOperations?o([...r.setOperations,...e]):o([...e])})},cloneWithoutSelections(r){return o({...r,selections:[]})},cloneWithoutLimit(r){return o({...r,limit:void 0})},cloneWithoutOffset(r){return o({...r,offset:void 0})},cloneWithoutOrderBy:r=>s.cloneWithoutOrderBy(r),cloneWithoutGroupBy(r){return o({...r,groupBy:void 0})}});var ht=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Rr(this.#e,e)}},Rr=class{#e;#r;get table(){return this.#e}get alias(){return this.#r}constructor(e,t){this.#e=e,this.#r=t}toOperationNode(){return g.create(N(this.#e),u.create(this.#r))}};function ft(r){return X(r)&&f(r)&&p(r.table)&&p(r.alias)}function z(r){return C(r)?r.map(e=>ce(e)):[ce(r)]}function ce(r){return p(r)?Ar(r):ft(r)?r.toOperationNode():He(r)}function Ar(r){let e=" as ";if(r.includes(e)){let[t,n]=r.split(e).map(pt);return g.create(N(t),u.create(n))}else return N(r)}function N(r){if(r.includes(".")){let[t,n]=r.split(".").map(pt);return B.createWithSchema(t,n)}else return B.create(r)}function pt(r){return r.trim()}var ie=o({is(r){return r.kind==="ParensNode"},create(r){return o({kind:"ParensNode",node:r})}});var a=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new qe(this,e)}or(...e){return new Tr(P.create(this.#e,h(e)))}and(...e){return new Br(T.create(this.#e,h(e)))}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},qe=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return g.create(this.#e.toOperationNode(),f(this.#r)?this.#r.toOperationNode():u.create(this.#r))}},Tr=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new qe(this,e)}or(...e){return new r(P.create(this.#e,h(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return ie.create(this.#e)}},Br=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new qe(this,e)}and(...e){return new r(T.create(this.#e,h(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return ie.create(this.#e)}};var K=o({is(r){return r.kind==="AggregateFunctionNode"},create(r,e=[]){return o({kind:"AggregateFunctionNode",func:r,aggregated:e})},cloneWithDistinct(r){return o({...r,distinct:!0})},cloneWithOrderBy(r,e,t=!1){let n=t?"withinGroup":"orderBy";return o({...r,[n]:r[n]?_.cloneWithItems(r[n],e):_.create(e)})},cloneWithFilter(r,e){return o({...r,filter:r.filter?b.cloneWithOperation(r.filter,"And",e):b.create(e)})},cloneWithOrFilter(r,e){return o({...r,filter:r.filter?b.cloneWithOperation(r.filter,"Or",e):b.create(e)})},cloneWithOver(r,e){return o({...r,over:e})}});var qr=o({is(r){return r.kind==="FunctionNode"},create(r,e){return o({kind:"FunctionNode",func:r,arguments:e})}});var we=o({is(r){return r.kind==="SelectionNode"},create(r){return o({kind:"SelectionNode",selection:r})},createSelectAll(){return o({kind:"SelectionNode",selection:je.create()})},createSelectAllFromTable(r){return o({kind:"SelectionNode",selection:ye.createSelectAll(r)})}});var lt=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Lr(this.#e)}};function Ye(r){return X(r)&&f(r)&&p(r.dynamicReference)}function O(r){return x(r)?O(r(I())):C(r)?r.map(e=>Nt(e)):[Nt(r)]}function Nt(r){return p(r)?we.create(wt(r)):Ye(r)?we.create(r.toOperationNode()):we.create(He(r))}function W(r){return r?Array.isArray(r)?r.map(yt):[yt(r)]:[we.createSelectAll()]}function yt(r){if(p(r))return we.createSelectAllFromTable(N(r));throw new Error(`invalid value selectAll expression: ${JSON.stringify(r)}`)}var Fr=o({is(r){return r.kind==="PartitionByNode"},create(r){return o({kind:"PartitionByNode",items:o(r)})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var Le=o({is(r){return r.kind==="OverNode"},create(){return o({kind:"OverNode"})},cloneWithOrderByItems(r,e){return o({...r,orderBy:r.orderBy?_.cloneWithItems(r.orderBy,e):_.create(e)})},cloneWithPartitionByItems(r,e){return o({...r,partitionBy:r.partitionBy?Fr.cloneWithItems(r.partitionBy,e):Fr.create(e)})}});var y=o({is(r){return r.kind==="RawNode"},create(r,e){return o({kind:"RawNode",sqlFragments:o(r),parameters:o(e)})},createWithSql(r){return y.create([r],[])},createWithChild(r){return y.create(["",""],[r])},createWithChildren(r){return y.create(new Array(r.length+1).fill(""),r)}});var Xe=class r{#e;constructor(e){this.#e=o(e)}on(...e){return new r({...this.#e,joinNode:Q.cloneWithOn(this.#e.joinNode,h(e))})}onRef(e,t,n){return new r({...this.#e,joinNode:Q.cloneWithOn(this.#e.joinNode,S(e,t,n))})}onTrue(){return new r({...this.#e,joinNode:Q.cloneWithOn(this.#e.joinNode,y.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};var U=o({is(r){return r.kind==="OrderByItemNode"},create(r,e){return o({kind:"OrderByItemNode",orderBy:r,direction:e})},cloneWith(r,e){return o({...r,...e})}});var Ot=o({is(r){return r.kind==="CollateNode"},create(r){return o({kind:"CollateNode",collation:u.create(r)})}});var Ze=class r{#e;constructor(e){this.#e=o(e)}desc(){return new r({node:U.cloneWith(this.#e.node,{direction:y.createWithSql("desc")})})}asc(){return new r({node:U.cloneWith(this.#e.node,{direction:y.createWithSql("asc")})})}nullsLast(){return new r({node:U.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new r({node:U.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new r({node:U.cloneWith(this.#e.node,{collation:Ot.create(e)})})}toOperationNode(){return this.#e.node}};function Mr(r){return r==="asc"||r==="desc"}function L(r){if(r.length===2)return[Dr(r[0],r[1])];if(r.length===1){let[e]=r;return Array.isArray(e)?(le("orderBy(array) is deprecated, use multiple orderBy calls instead."),e.map(t=>Dr(t))):[Dr(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${r.length}`)}function Dr(r,e){let t=io(r);if(U.is(t)){if(e)throw new Error("Cannot specify direction twice!");return t}return xt(t,e)}function io(r){if(ee(r))return H(r);if(Ye(r))return r.toOperationNode();let[e,t]=r.split(" ");return t?(le("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),xt(V(e),t)):V(r)}function xt(r,e){if(typeof e=="string"){if(!Mr(e))throw new Error(`Invalid order by direction: ${e}`);return U.create(r,y.createWithSql(e))}if(Ke(e))return le("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),U.create(r,e.toOperationNode());let t=U.create(r);return e?e(new Ze({node:t})).toOperationNode():t}var gt=o({is(r){return r.kind==="PartitionByItemNode"},create(r){return o({kind:"PartitionByItemNode",partitionBy:r})}});function Wt(r){return re(r).map(gt.create)}var _e=class r{#e;constructor(e){this.#e=o(e)}orderBy(...e){return new r({overNode:Le.cloneWithOrderByItems(this.#e.overNode,L(e))})}clearOrderBy(){return new r({overNode:s.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new r({overNode:Le.cloneWithPartitionByItems(this.#e.overNode,Wt(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};var so=o([]),er=class{#e;constructor(e=so){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let n of this.#e){let i=n.transformQuery({node:e,queryId:t});if(i.kind===e.kind)e=i;else throw new Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${i.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async t=>{let n=await t.executeQuery(e);return"numUpdatedOrDeletedRows"in n&&le("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#r(n,e.queryId)})}async*stream(e,t){let{connection:n,release:i}=await at(this);try{for await(let m of n.streamQuery(e,t))yield await this.#r(m,e.queryId)}finally{i()}}async#r(e,t){for(let n of this.#e)e=await n.transformResult({result:e,queryId:t});return e}};var Pr=class r extends er{get adapter(){throw new Error("this query cannot be compiled to SQL")}compileQuery(){throw new Error("this query cannot be compiled to SQL")}provideConnection(){throw new Error("this query cannot be executed")}withConnectionProvider(){throw new Error("this query cannot have a connection provider")}withPlugin(e){return new r([...this.plugins,e])}withPlugins(e){return new r([...this.plugins,...e])}withPluginAtFront(e){return new r([e,...this.plugins])}withoutPlugins(){return new r([])}},se=new Pr;function St(){return new rr({executor:se})}function bt(r,e){return new Xe({joinNode:Q.create(r,ce(e))})}function kt(){return new _e({overNode:Le.create()})}var Oe=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}as(e){return new Qr(this,e)}distinct(){return new r({...this.#e,aggregateFunctionNode:K.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new r({...this.#e,aggregateFunctionNode:s.cloneWithOrderByItems(this.#e.aggregateFunctionNode,L(e))})}clearOrderBy(){return new r({...this.#e,aggregateFunctionNode:s.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new r({...this.#e,aggregateFunctionNode:K.cloneWithOrderBy(this.#e.aggregateFunctionNode,L(e),!0)})}filterWhere(...e){return new r({...this.#e,aggregateFunctionNode:K.cloneWithFilter(this.#e.aggregateFunctionNode,h(e))})}filterWhereRef(e,t,n){return new r({...this.#e,aggregateFunctionNode:K.cloneWithFilter(this.#e.aggregateFunctionNode,S(e,t,n))})}over(e){let t=kt();return new r({...this.#e,aggregateFunctionNode:K.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(t):t).toOperationNode())})}$call(e){return e(this)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}},Qr=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return g.create(this.#e.toOperationNode(),u.create(this.#r))}};function Ct(){let r=(t,n)=>new a(qr.create(t,re(n??[]))),e=(t,n)=>new Oe({aggregateFunctionNode:K.create(t,n?re(n):void 0)});return Object.assign(r,{agg:e,avg(t){return e("avg",[t])},coalesce(...t){return r("coalesce",t)},count(t){return e("count",[t])},countAll(t){return new Oe({aggregateFunctionNode:K.create("count",W(t))})},max(t){return e("max",[t])},min(t){return e("min",[t])},sum(t){return e("sum",[t])},any(t){return r("any",[t])},jsonAgg(t){return new Oe({aggregateFunctionNode:K.create("json_agg",[p(t)?N(t):t.toOperationNode()])})},toJson(t){return new a(qr.create("to_json",[p(t)?N(t):t.toOperationNode()]))}})}var Et=o({is(r){return r.kind==="UnaryOperationNode"},create(r,e){return o({kind:"UnaryOperationNode",operator:r,operand:e})}});function Rt(r,e){return Et.create(v.create(r),k(e))}var tr=o({is(r){return r.kind==="PrimitiveValueListNode"},create(r){return o({kind:"PrimitiveValueListNode",values:o([...r])})}});var or=o({is(r){return r.kind==="ValueListNode"},create(r){return o({kind:"ValueListNode",values:o(r)})}});var F=o({is(r){return r.kind==="ValueNode"},create(r){return o({kind:"ValueNode",value:r})},createImmediate(r){return o({kind:"ValueNode",value:r,immediate:!0})}});function At(r){return C(r)?ao(r):c(r)}function c(r){return ee(r)?H(r):F.create(r)}function nr(r){return pe(r)||ze(r)||Ie(r)}function Fe(r){if(!nr(r))throw new Error(`unsafe immediate value ${JSON.stringify(r)}`);return F.createImmediate(r)}function ao(r){return r.some(ee)?or.create(r.map(e=>c(e))):tr.create(r)}var J=o({is(r){return r.kind==="CaseNode"},create(r){return o({kind:"CaseNode",value:r})},cloneWithWhen(r,e){return o({...r,when:o(r.when?[...r.when,e]:[e])})},cloneWithThen(r,e){return o({...r,when:r.when?o([...r.when.slice(0,-1),Z.cloneWithResult(r.when[r.when.length-1],e)]):void 0})},cloneWith(r,e){return o({...r,...e})}});var ir=class{#e;constructor(e){this.#e=o(e)}when(...e){return new sr({...this.#e,node:J.cloneWithWhen(this.#e.node,Z.create(h(e)))})}},sr=class{#e;constructor(e){this.#e=o(e)}then(e){return new vr({...this.#e,node:J.cloneWithThen(this.#e.node,nr(e)?Fe(e):c(e))})}},vr=class{#e;constructor(e){this.#e=o(e)}when(...e){return new sr({...this.#e,node:J.cloneWithWhen(this.#e.node,Z.create(h(e)))})}else(e){return new zr({...this.#e,node:J.cloneWith(this.#e.node,{else:nr(e)?Fe(e):c(e)})})}end(){return new a(J.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(J.cloneWith(this.#e.node,{isStatement:!0}))}},zr=class{#e;constructor(e){this.#e=o(e)}end(){return new a(J.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(J.cloneWith(this.#e.node,{isStatement:!0}))}};var ar=o({is(r){return r.kind==="JSONOperatorChainNode"},create(r){return o({kind:"JSONOperatorChainNode",operator:r,values:o([])})},cloneWithValue(r,e){return o({...r,values:o([...r.values,e])})}});var Ir=o({is(r){return r.kind==="JSONPathLegNode"},create(r,e){return o({kind:"JSONPathLegNode",type:r,value:e})}});var ae=o({is(r){return r.kind==="JSONPathNode"},create(r){return o({kind:"JSONPathNode",inOperator:r,pathLegs:o([])})},cloneWithLeg(r,e){return o({...r,pathLegs:o([...r.pathLegs,e])})}});var xe=o({is(r){return r.kind==="JSONReferenceNode"},create(r,e){return o({kind:"JSONReferenceNode",reference:r,traversal:e})},cloneWithTraversal(r,e){return o({...r,traversal:e})}});var ge=class{#e;constructor(e){this.#e=e}at(e){return this.#r("ArrayLocation",e)}key(e){return this.#r("Member",e)}#r(e,t){return xe.is(this.#e)?new ur(xe.cloneWithTraversal(this.#e,ae.is(this.#e.traversal)?ae.cloneWithLeg(this.#e.traversal,Ir.create(e,t)):ar.cloneWithValue(this.#e.traversal,F.createImmediate(t)))):new ur(ae.cloneWithLeg(this.#e,Ir.create(e,t)))}},ur=class r extends ge{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new Ur(this,e)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},Ur=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return g.create(this.#e.toOperationNode(),f(this.#r)?this.#r.toOperationNode():u.create(this.#r))}};var Vr=o({is(r){return r.kind==="TupleNode"},create(r){return o({kind:"TupleNode",values:o(r)})}});var uo=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],mo=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],Tt=o({is(r){return r.kind==="DataTypeNode"},create(r){return o({kind:"DataTypeNode",dataType:r})}});function Bt(r){return!!(uo.includes(r)||mo.some(e=>e.test(r)))}function qt(r){if(f(r))return r.toOperationNode();if(Bt(r))return Tt.create(r);throw new Error(`invalid column data type ${JSON.stringify(r)}`)}var Lt=o({is(r){return r.kind==="CastNode"},create(r,e){return o({kind:"CastNode",expression:r,dataType:e})}});function mr(r=se){function e(i,m,A){return new a(dr(i,m,A))}function t(i,m){return new a(Rt(i,m))}let n=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(i){return De({queryId:w(),executor:r,queryNode:d.createFrom(z(i))})},case(i){return new ir({node:J.create(M(i)?void 0:k(i))})},ref(i,m){return M(m)?new a(V(i)):new ge(Ft(i,m))},jsonPath(){return new ge(ae.create())},table(i){return new a(N(i))},val(i){return new a(c(i))},refTuple(...i){return new a(Vr.create(i.map(k)))},tuple(...i){return new a(Vr.create(i.map(c)))},lit(i){return new a(Fe(i))},unary:t,not(i){return t("not",i)},exists(i){return t("exists",i)},neg(i){return t("-",i)},between(i,m,A){return new a(oe.create(k(i),v.create("between"),T.create(c(m),c(A))))},betweenSymmetric(i,m,A){return new a(oe.create(k(i),v.create("between symmetric"),T.create(c(m),c(A))))},and(i){return C(i)?new a(We(i,"and")):new a(Jr(i,"and"))},or(i){return C(i)?new a(We(i,"or")):new a(Jr(i,"or"))},parens(...i){let m=h(i);return ie.is(m)?new a(m):new a(ie.create(m))},cast(i,m){return new a(Lt.create(k(i),qt(m)))},withSchema(i){return mr(r.withPluginAtFront(new Ne(i)))}});return n.fn=Ct(),n.eb=n,n}function I(r){return mr()}function H(r){if(f(r))return r.toOperationNode();if(x(r))return r(I()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(r)}`)}function He(r){if(f(r))return r.toOperationNode();if(x(r))return r(I()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(r)}`)}function ee(r){return Ke(r)||mt(r)||x(r)}function Lr(r){return p(r)?V(r):r.toOperationNode()}function re(r){return C(r)?r.map(e=>k(e)):[k(r)]}function k(r){return ee(r)?H(r):Lr(r)}function Ft(r,e){let t=V(r);if(Sr(e))return xe.create(t,ar.create(v.create(e)));let n=e.slice(0,-1);if(Sr(n))return xe.create(t,ae.create(v.create(n)));throw new Error(`Invalid JSON operator: ${e}`)}function V(r){if(!r.includes("."))return ye.create(E.create(r));let t=r.split(".").map($r);if(t.length===3)return ho(t);if(t.length===2)return fo(t);throw new Error(`invalid column reference ${r}`)}function wt(r){let e=" as ";if(r.includes(e)){let[t,n]=r.split(e).map($r);return g.create(V(t),u.create(n))}else return V(r)}function co(r){return E.create(r)}function Ud(r){if(r.includes(" ")){let[t,n]=r.split(" ").map($r);if(!Mr(n))throw new Error(`invalid order direction "${n}" next to "${t}"`);return L([t,n])[0]}else return co(r)}function ho(r){let[e,t,n]=r;return ye.create(E.create(n),B.createWithSchema(e,t))}function fo(r){let[e,t]=r;return ye.create(E.create(t),B.create(e))}function $r(r){return r.trim()}function h(r){if(r.length===3)return dr(r[0],r[1],r[2]);if(r.length===1)return c(r[0]);throw new Error(`invalid arguments: ${JSON.stringify(r)}`)}function dr(r,e,t){return po(e)&&Mt(t)?oe.create(k(r),Gr(e),F.createImmediate(t)):oe.create(k(r),Gr(e),At(t))}function S(r,e,t){return oe.create(k(r),Gr(e),k(t))}function Jr(r,e){return We(Object.entries(r).filter(([,t])=>!M(t)).map(([t,n])=>dr(t,Mt(n)?"is":"=",n)),e)}function We(r,e,t=!0){let n=e==="and"?T.create:P.create;if(r.length===0)return oe.create(F.createImmediate(1),v.create("="),F.createImmediate(e==="and"?1:0));let i=Dt(r[0]);for(let m=1;m<r.length;++m)i=n(i,Dt(r[m]));return r.length>1&&t?ie.create(i):i}function po(r){return r==="is"||r==="is not"}function Mt(r){return Ie(r)||ze(r)}function Gr(r){if(p(r)&&dt.includes(r))return v.create(r);if(f(r))return r.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(r)}`)}function Dt(r){return f(r)?r.toOperationNode():r}function ue(r,e){if(e.length===3)return No(r,e[0],e[1],e[2]);if(e.length===2)return lo(r,e[0],e[1]);if(e.length===1)return yo(r,e[0]);throw new Error("not implemented")}function lo(r,e,t){return t(bt(r,e)).toOperationNode()}function No(r,e,t,n){return Q.createWithOn(r,ce(e),S(t,"=",n))}function yo(r,e){return Q.create(r,ce(e))}var Se=o({is(r){return r.kind==="LimitNode"},create(r){return o({kind:"LimitNode",limit:r})}});var Pt=o({is(r){return r.kind==="OffsetNode"},create(r){return o({kind:"OffsetNode",offset:r})}});var Qt=o({is(r){return r.kind==="GroupByItemNode"},create(r){return o({kind:"GroupByItemNode",groupBy:r})}});function vt(r){return r=x(r)?r(I()):r,re(r).map(Qt.create)}var D=class extends Error{node;constructor(e){super("no result"),this.node=e}};function Y(r){return Object.prototype.hasOwnProperty.call(r,"prototype")}var zt=o({is(r){return r.kind==="SetOperationNode"},create(r,e,t){return o({kind:"SetOperationNode",operator:r,expression:e,all:t})}});function he(r,e,t){return x(e)&&(e=e(mr())),C(e)||(e=[e]),e.map(n=>zt.create(r,H(n),t))}var It=o({is(r){return r.kind==="FetchNode"},create(r,e){return{kind:"FetchNode",rowCount:F.create(r),modifier:e}}});function Ut(r,e){if(!pe(r)&&!Ue(r))throw new Error(`Invalid fetch row count: ${r}`);if(!wo(e))throw new Error(`Invalid fetch modifier: ${e}`);return It.create(r,e)}function wo(r){return r==="only"||r==="with ties"}var Vt=o({is(r){return r.kind==="TopNode"},create(r,e){return o({kind:"TopNode",expression:r,modifiers:e})}});function $(r,e){if(!pe(r)&&!Ue(r))throw new Error(`Invalid top expression: ${r}`);if(!M(e)&&!Oo(e))throw new Error(`Invalid top modifiers: ${e}`);return Vt.create(r,e)}function Oo(r){return r==="percent"||r==="with ties"||r==="percent with ties"}var jr=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,S(e,t,n))})}having(...e){return new r({...this.#e,queryNode:d.cloneWithHaving(this.#e.queryNode,h(e))})}havingRef(e,t,n){return new r({...this.#e,queryNode:d.cloneWithHaving(this.#e.queryNode,S(e,t,n))})}select(e){return new r({...this.#e,queryNode:d.cloneWithSelections(this.#e.queryNode,O(e))})}distinctOn(e){return new r({...this.#e,queryNode:d.cloneWithDistinctOn(this.#e.queryNode,re(e))})}modifyFront(e){return new r({...this.#e,queryNode:d.cloneWithFrontModifier(this.#e.queryNode,G.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.createWithExpression(e.toOperationNode()))})}distinct(){return new r({...this.#e,queryNode:d.cloneWithFrontModifier(this.#e.queryNode,G.create("Distinct"))})}forUpdate(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForUpdate",e?Re(e).map(N):void 0))})}forShare(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForShare",e?Re(e).map(N):void 0))})}forKeyShare(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForKeyShare",e?Re(e).map(N):void 0))})}forNoKeyUpdate(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForNoKeyUpdate",e?Re(e).map(N):void 0))})}skipLocked(){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("SkipLocked"))})}noWait(){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("NoWait"))})}selectAll(e){return new r({...this.#e,queryNode:d.cloneWithSelections(this.#e.queryNode,W(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}crossJoin(...e){return this.#r("CrossJoin",e)}innerJoinLateral(...e){return this.#r("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#r("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#r("LateralCrossJoin",e)}crossApply(...e){return this.#r("CrossApply",e)}outerApply(...e){return this.#r("OuterApply",e)}#r(e,t){return new r({...this.#e,queryNode:s.cloneWithJoin(this.#e.queryNode,ue(e,t))})}orderBy(...e){return new r({...this.#e,queryNode:s.cloneWithOrderByItems(this.#e.queryNode,L(e))})}groupBy(e){return new r({...this.#e,queryNode:d.cloneWithGroupByItems(this.#e.queryNode,vt(e))})}limit(e){return new r({...this.#e,queryNode:d.cloneWithLimit(this.#e.queryNode,Se.create(c(e)))})}offset(e){return new r({...this.#e,queryNode:d.cloneWithOffset(this.#e.queryNode,Pt.create(c(e)))})}fetch(e,t="only"){return new r({...this.#e,queryNode:d.cloneWithFetch(this.#e.queryNode,Ut(e,t))})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}union(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("union",e,!1))})}unionAll(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("union",e,!0))})}intersect(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("intersect",e,!1))})}intersectAll(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("intersect",e,!0))})}except(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("except",e,!1))})}exceptAll(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("except",e,!0))})}as(e){return new Kr(this,e)}clearSelect(){return new r({...this.#e,queryNode:d.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new r({...this.#e,queryNode:s.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:d.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new r({...this.#e,queryNode:d.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new r({...this.#e,queryNode:s.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new r({...this.#e,queryNode:d.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}$asTuple(){return new a(this.toOperationNode())}$asScalar(){return new a(this.toOperationNode())}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};function De(r){return new jr(r)}var Kr=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return g.create(this.#e.toOperationNode(),u.create(this.#r))}};var Jt=o({is(r){return r.kind==="ValuesNode"},create(r){return o({kind:"ValuesNode",values:o(r)})}});var $t=o({is(r){return r.kind==="DefaultInsertValueNode"},create(){return o({kind:"DefaultInsertValueNode"})}});function cr(r){let e=x(r)?r(I()):r,t=C(e)?e:o([e]);return xo(t)}function xo(r){let e=go(r);return[o([...e.keys()].map(E.create)),Jt.create(r.map(t=>Wo(t,e)))]}function go(r){let e=new Map;for(let t of r){let n=Object.keys(t);for(let i of n)!e.has(i)&&t[i]!==void 0&&e.set(i,e.size)}return e}function Wo(r,e){let t=Object.keys(r),n=Array.from({length:e.size}),i=!1,m=t.length;for(let ve of t){let Ee=e.get(ve);if(M(Ee)){m--;continue}let gr=r[ve];(M(gr)||ee(gr))&&(i=!0),n[Ee]=gr}if(m<e.size||i){let ve=$t.create();return or.create(n.map(Ee=>M(Ee)?ve:c(Ee)))}return tr.create(n)}var Hr=o({is(r){return r.kind==="ColumnUpdateNode"},create(r,e){return o({kind:"ColumnUpdateNode",column:r,value:e})}});function Gt(...r){return r.length===2?[Hr.create(k(r[0]),c(r[1]))]:Me(r[0])}function Me(r){let e=x(r)?r(I()):r;return Object.entries(e).filter(([t,n])=>n!==void 0).map(([t,n])=>Hr.create(E.create(t),c(n)))}var jt=o({is(r){return r.kind==="OnDuplicateKeyNode"},create(r){return o({kind:"OnDuplicateKeyNode",updates:r})}});var hr=class{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}};var R=o({is(r){return r.kind==="OnConflictNode"},create(){return o({kind:"OnConflictNode"})},cloneWith(r,e){return o({...r,...e})},cloneWithIndexWhere(r,e){return o({...r,indexWhere:r.indexWhere?b.cloneWithOperation(r.indexWhere,"And",e):b.create(e)})},cloneWithIndexOrWhere(r,e){return o({...r,indexWhere:r.indexWhere?b.cloneWithOperation(r.indexWhere,"Or",e):b.create(e)})},cloneWithUpdateWhere(r,e){return o({...r,updateWhere:r.updateWhere?b.cloneWithOperation(r.updateWhere,"And",e):b.create(e)})},cloneWithUpdateOrWhere(r,e){return o({...r,updateWhere:r.updateWhere?b.cloneWithOperation(r.updateWhere,"Or",e):b.create(e)})},cloneWithoutIndexWhere(r){return o({...r,indexWhere:void 0})},cloneWithoutUpdateWhere(r){return o({...r,updateWhere:void 0})}});var fr=class r{#e;constructor(e){this.#e=o(e)}column(e){let t=E.create(e);return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?o([...this.#e.onConflictNode.columns,t]):o([t])})})}columns(e){let t=e.map(E.create);return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?o([...this.#e.onConflictNode.columns,...t]):o(t)})})}constraint(e){return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{constraint:u.create(e)})})}expression(e){return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new r({...this.#e,onConflictNode:R.cloneWithIndexWhere(this.#e.onConflictNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,onConflictNode:R.cloneWithIndexWhere(this.#e.onConflictNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,onConflictNode:R.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Yr({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Xr({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{updates:Me(e)})})}$call(e){return e(this)}},Yr=class{#e;constructor(e){this.#e=o(e)}toOperationNode(){return this.#e.onConflictNode}},Xr=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,onConflictNode:R.cloneWithUpdateWhere(this.#e.onConflictNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,onConflictNode:R.cloneWithUpdateWhere(this.#e.onConflictNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,onConflictNode:R.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};var fe=o({is(r){return r.kind==="OrActionNode"},create(r){return o({kind:"OrActionNode",action:r})}});var Pe=class r{#e;constructor(e){this.#e=o(e)}values(e){let[t,n]=cr(e);return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{columns:t,values:n})})}columns(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{columns:o(e.map(E.create))})})}expression(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{values:H(e)})})}defaultValues(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("ignore")})})}orIgnore(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("ignore")})})}orAbort(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("abort")})})}orFail(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("fail")})})}orReplace(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("replace")})})}orRollback(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("rollback")})})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}onConflict(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{onConflict:e(new fr({onConflictNode:R.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{onDuplicateKey:jt.create(Me(e))})})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W())})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}clearReturning(){return new r({...this.#e,queryNode:s.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new hr(t.insertId,t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var pr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var lr=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,queryNode:s.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}using(e){return new r({...this.#e,queryNode:ne.cloneWithUsing(this.#e.queryNode,z(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}#r(e,t){return new r({...this.#e,queryNode:s.cloneWithJoin(this.#e.queryNode,ue(e,t))})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}clearReturning(){return new r({...this.#e,queryNode:s.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:ne.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new r({...this.#e,queryNode:s.cloneWithOrderByItems(this.#e.queryNode,L(e))})}clearOrderBy(){return new r({...this.#e,queryNode:s.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new r({...this.#e,queryNode:ne.cloneWithLimit(this.#e.queryNode,Se.create(c(e)))})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new pr(t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var Nr=class{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}};var be=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,queryNode:s.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}from(e){return new r({...this.#e,queryNode:j.cloneWithFromItems(this.#e.queryNode,z(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}#r(e,t){return new r({...this.#e,queryNode:s.cloneWithJoin(this.#e.queryNode,ue(e,t))})}orderBy(...e){return new r({...this.#e,queryNode:s.cloneWithOrderByItems(this.#e.queryNode,L(e))})}clearOrderBy(){return new r({...this.#e,queryNode:s.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new r({...this.#e,queryNode:j.cloneWithLimit(this.#e.queryNode,Se.create(c(e)))})}set(...e){return new r({...this.#e,queryNode:j.cloneWithUpdates(this.#e.queryNode,Gt(...e))})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new r({...this.#e,queryNode:s.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new Nr(t.numAffectedRows??BigInt(0),t.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var Zr=o({is(r){return r.kind==="CommonTableExpressionNameNode"},create(r,e){return o({kind:"CommonTableExpressionNameNode",table:B.create(r),columns:e?o(e.map(E.create)):void 0})}});var ke=o({is(r){return r.kind==="CommonTableExpressionNode"},create(r,e){return o({kind:"CommonTableExpressionNode",name:r,expression:e})},cloneWith(r,e){return o({...r,...e})}});var yr=class r{#e;constructor(e){this.#e=o(e)}materialized(){return new r({...this.#e,node:ke.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new r({...this.#e,node:ke.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function _r(r,e){let t=e(St()).toOperationNode();return x(r)?r(So(t)).toOperationNode():ke.create(Kt(r),t)}function So(r){return e=>new yr({node:ke.create(Kt(e),r)})}function Kt(r){if(r.includes("(")){let e=r.split(/[\(\)]/),t=e[0],n=e[1].split(",").map(i=>i.trim());return Zr.create(t,n)}else return Zr.create(r)}var Qe=o({is(r){return r.kind==="WithNode"},create(r,e){return o({kind:"WithNode",expressions:o([r]),...e})},cloneWithExpression(r,e){return o({...r,expressions:o([...r.expressions,e])})}});var Ht=o({is(r){return r.kind==="MatchedNode"},create(r,e=!1){return o({kind:"MatchedNode",not:r,bySource:e})}});function et(r,e,t){return Z.create(We([Ht.create(!r.isMatched,r.bySource),...e&&e.length>0?[e.length===3&&t?S(e[0],e[1],e[2]):h(e)]:[]],"and",!1))}function Ce(r){return p(r)?y.create([r],[]):f(r)?r.toOperationNode():r}var wr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var Or=class r{#e;constructor(e){this.#e=o(e)}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}using(...e){return new de({...this.#e,queryNode:q.cloneWithUsing(this.#e.queryNode,ue("Using",e))})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}},de=class r{#e;constructor(e){this.#e=o(e)}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}whenMatched(){return this.#r([])}whenMatchedAnd(...e){return this.#r(e)}whenMatchedAndRef(e,t,n){return this.#r([e,t,n],!0)}#r(e,t){return new xr({...this.#e,queryNode:q.cloneWithWhen(this.#e.queryNode,et({isMatched:!0},e,t))})}whenNotMatched(){return this.#t([])}whenNotMatchedAnd(...e){return this.#t(e)}whenNotMatchedAndRef(e,t,n){return this.#t([e,t,n],!0)}whenNotMatchedBySource(){return this.#t([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#t(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,n){return this.#t([e,t,n],!0,!0)}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}#t(e,t=!1,n=!1){let i={...this.#e,queryNode:q.cloneWithWhen(this.#e.queryNode,et({isMatched:!1,bySource:n},e,t))},m=n?xr:rt;return new m(i)}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new wr(t.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}},xr=class{#e;constructor(e){this.#e=o(e)}thenDelete(){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce("delete"))})}thenDoNothing(){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce("do nothing"))})}thenUpdate(e){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce(e(new be({queryId:this.#e.queryId,executor:se,queryNode:j.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(t=>t.set(...e))}},rt=class{#e;constructor(e){this.#e=o(e)}thenDoNothing(){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce("do nothing"))})}thenInsertValues(e){let[t,n]=cr(e);return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce(l.cloneWith(l.createWithoutInto(),{columns:t,values:n})))})}};var rr=class r{#e;constructor(e){this.#e=o(e)}selectFrom(e){return De({queryId:w(),executor:this.#e.executor,queryNode:d.createFrom(z(e),this.#e.withNode)})}selectNoFrom(e){return De({queryId:w(),executor:this.#e.executor,queryNode:d.cloneWithSelections(d.create(this.#e.withNode),O(e))})}insertInto(e){return new Pe({queryId:w(),executor:this.#e.executor,queryNode:l.create(N(e),this.#e.withNode)})}replaceInto(e){return new Pe({queryId:w(),executor:this.#e.executor,queryNode:l.create(N(e),this.#e.withNode,!0)})}deleteFrom(e){return new lr({queryId:w(),executor:this.#e.executor,queryNode:ne.create(z(e),this.#e.withNode)})}updateTable(e){return new be({queryId:w(),executor:this.#e.executor,queryNode:j.create(z(e),this.#e.withNode)})}mergeInto(e){return new Or({queryId:w(),executor:this.#e.executor,queryNode:q.create(Ar(e),this.#e.withNode)})}with(e,t){let n=_r(e,t);return new r({...this.#e,withNode:this.#e.withNode?Qe.cloneWithExpression(this.#e.withNode,n):Qe.create(n)})}withRecursive(e,t){let n=_r(e,t);return new r({...this.#e,withNode:this.#e.withNode?Qe.cloneWithExpression(this.#e.withNode,n):Qe.create(n,{recursive:!0})})}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ne(e))})}};var tt=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new ot(this,e)}$castTo(){return new r({...this.#e})}$notNull(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,plugins:this.#e.plugins!==void 0?o([...this.#e.plugins,e]):o([e])})}toOperationNode(){return this.#t(this.#r())}compile(e){return this.#n(this.#r(e))}async execute(e){let t=this.#r(e);return t.executeQuery(this.#n(t))}#r(e){let t=e!==void 0?e.getExecutor():se;return this.#e.plugins!==void 0?t.withPlugins(this.#e.plugins):t}#t(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#n(e){return e.compileQuery(this.#t(e),this.#e.queryId)}};function te(r){return new tt(r)}var ot=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}get rawBuilder(){return this.#e}toOperationNode(){return g.create(this.#e.toOperationNode(),f(this.#r)?this.#r.toOperationNode():u.create(this.#r))}};var bo=Object.assign((r,...e)=>te({queryId:w(),rawNode:y.create(r,e?.map(Yt)??[])}),{ref(r){return te({queryId:w(),rawNode:y.createWithChild(V(r))})},val(r){return te({queryId:w(),rawNode:y.createWithChild(c(r))})},value(r){return this.val(r)},table(r){return te({queryId:w(),rawNode:y.createWithChild(N(r))})},id(...r){let e=new Array(r.length+1).fill(".");return e[0]="",e[e.length-1]="",te({queryId:w(),rawNode:y.create(e,r.map(u.create))})},lit(r){return te({queryId:w(),rawNode:y.createWithChild(F.createImmediate(r))})},literal(r){return this.lit(r)},raw(r){return te({queryId:w(),rawNode:y.createWithSql(r)})},join(r,e=bo`, `){let t=new Array(Math.max(2*r.length-1,0)),n=e.toOperationNode();for(let i=0;i<r.length;++i)t[2*i]=Yt(r[i]),i!==r.length-1&&(t[2*i+1]=n);return te({queryId:w(),rawNode:y.createWithChildren(t)})}});function Yt(r){return f(r)?r.toOperationNode():c(r)}export{M as a,p as b,pe as c,ze as d,Ie as e,ko as f,Ue as g,Co as h,x as i,X as j,o as k,Eo as l,u as m,Ae as n,f as o,v as p,E as q,je as r,lt as s,y as t,le as u,V as v,co as w,Ud as x,or as y,F as z,ie as A,h as B,l as C,Z as D,s as E,d as F,st as G,w as H,$e as I,Ne as J,Be as K,at as L,er as M,rr as N,zt as O,Ct as P,J as Q,ir as R,qt as S,H as T,ht as U,N as V,bo as W};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
1
2
|
var h=Object.create;var e=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var m=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var n=(a,b)=>()=>(a&&(b=a(a=0)),b);var o=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports),p=(a,b)=>{for(var c in b)e(a,c,{get:b[c],enumerable:!0})},g=(a,b,c,f)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of j(b))!l.call(a,d)&&d!==c&&e(a,d,{get:()=>b[d],enumerable:!(f=i(b,d))||f.enumerable});return a};var q=(a,b,c)=>(c=a!=null?h(k(a)):{},g(b||!a||!a.__esModule?e(c,"default",{value:a,enumerable:!0}):c,a)),r=a=>g(e({},"__esModule",{value:!0}),a);export{m as a,n as b,o as c,p as d,q as e,r as f};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import{a as m,c as x,e as Y}from"./chunk-DGJUBN33.js";var T=x((Sr,je)=>{"use strict";var Ve=["nodebuffer","arraybuffer","fragments"],$e=typeof Blob<"u";$e&&Ve.push("blob");je.exports={BINARY_TYPES:Ve,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:$e,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var K=x((xr,re)=>{"use strict";var{EMPTY_BUFFER:Zt}=T(),Se=Buffer[Symbol.species];function Qt(t,e){if(t.length===0)return Zt;if(t.length===1)return t[0];let s=Buffer.allocUnsafe(e),r=0;for(let i=0;i<t.length;i++){let n=t[i];s.set(n,r),r+=n.length}return r<e?new Se(s.buffer,s.byteOffset,r):s}function ze(t,e,s,r,i){for(let n=0;n<i;n++)s[r+n]=t[n]^e[n&3]}function He(t,e){for(let s=0;s<t.length;s++)t[s]^=e[s&3]}function Jt(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function xe(t){if(xe.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Se(t):ArrayBuffer.isView(t)?e=new Se(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),xe.readOnly=!1),e}re.exports={concat:Qt,mask:ze,toArrayBuffer:Jt,toBuffer:xe,unmask:He};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=m("bufferutil");re.exports.mask=function(e,s,r,i,n){n<48?ze(e,s,r,i,n):t.mask(e,s,r,i,n)},re.exports.unmask=function(e,s){e.length<32?He(e,s):t.unmask(e,s)}}catch{}});var Xe=x((Er,Ke)=>{"use strict";var Ye=Symbol("kDone"),Ee=Symbol("kRun"),ve=class{constructor(e){this[Ye]=()=>{this.pending--,this[Ee]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Ee]()}[Ee](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Ye])}}};Ke.exports=ve});var Z=x((vr,et)=>{"use strict";var X=m("zlib"),Ze=K(),es=Xe(),{kStatusCode:Qe}=T(),ts=Buffer[Symbol.species],ss=Buffer.from([0,0,255,255]),ne=Symbol("permessage-deflate"),k=Symbol("total-length"),W=Symbol("callback"),N=Symbol("buffers"),F=Symbol("error"),ie,be=class{constructor(e,s,r){if(this._maxPayload=r|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!s,this._deflate=null,this._inflate=null,this.params=null,!ie){let i=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ie=new es(i)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[W];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let s=this._options,r=e.find(i=>!(s.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(s.serverMaxWindowBits===!1||typeof s.serverMaxWindowBits=="number"&&s.serverMaxWindowBits>i.server_max_window_bits)||typeof s.clientMaxWindowBits=="number"&&!i.client_max_window_bits));if(!r)throw new Error("None of the extension offers can be accepted");return s.serverNoContextTakeover&&(r.server_no_context_takeover=!0),s.clientNoContextTakeover&&(r.client_no_context_takeover=!0),typeof s.serverMaxWindowBits=="number"&&(r.server_max_window_bits=s.serverMaxWindowBits),typeof s.clientMaxWindowBits=="number"?r.client_max_window_bits=s.clientMaxWindowBits:(r.client_max_window_bits===!0||s.clientMaxWindowBits===!1)&&delete r.client_max_window_bits,r}acceptAsClient(e){let s=e[0];if(this._options.clientNoContextTakeover===!1&&s.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!s.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(s.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&s.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return s}normalizeParams(e){return e.forEach(s=>{Object.keys(s).forEach(r=>{let i=s[r];if(i.length>1)throw new Error(`Parameter "${r}" must have only a single value`);if(i=i[0],r==="client_max_window_bits"){if(i!==!0){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else if(r==="server_max_window_bits"){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else throw new Error(`Unknown parameter "${r}"`);s[r]=i})}),e}decompress(e,s,r){ie.add(i=>{this._decompress(e,s,(n,o)=>{i(),r(n,o)})})}compress(e,s,r){ie.add(i=>{this._compress(e,s,(n,o)=>{i(),r(n,o)})})}_decompress(e,s,r){let i=this._isServer?"client":"server";if(!this._inflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?X.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=X.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[ne]=this,this._inflate[k]=0,this._inflate[N]=[],this._inflate.on("error",is),this._inflate.on("data",Je)}this._inflate[W]=r,this._inflate.write(e),s&&this._inflate.write(ss),this._inflate.flush(()=>{let n=this._inflate[F];if(n){this._inflate.close(),this._inflate=null,r(n);return}let o=Ze.concat(this._inflate[N],this._inflate[k]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[k]=0,this._inflate[N]=[],s&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),r(null,o)})}_compress(e,s,r){let i=this._isServer?"server":"client";if(!this._deflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?X.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=X.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[k]=0,this._deflate[N]=[],this._deflate.on("data",rs)}this._deflate[W]=r,this._deflate.write(e),this._deflate.flush(X.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Ze.concat(this._deflate[N],this._deflate[k]);s&&(n=new ts(n.buffer,n.byteOffset,n.length-4)),this._deflate[W]=null,this._deflate[k]=0,this._deflate[N]=[],s&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),r(null,n)})}};et.exports=be;function rs(t){this[N].push(t),this[k]+=t.length}function Je(t){if(this[k]+=t.length,this[ne]._maxPayload<1||this[k]<=this[ne]._maxPayload){this[N].push(t);return}this[F]=new RangeError("Max payload size exceeded"),this[F].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[F][Qe]=1009,this.removeListener("data",Je),this.reset()}function is(t){if(this[ne]._inflate=null,this[F]){this[W](this[F]);return}t[Qe]=1007,this[W](t)}});var q=x((br,oe)=>{"use strict";var{isUtf8:tt}=m("buffer"),{hasBlob:ns}=T(),os=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function as(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function we(t){let e=t.length,s=0;for(;s<e;)if((t[s]&128)===0)s++;else if((t[s]&224)===192){if(s+1===e||(t[s+1]&192)!==128||(t[s]&254)===192)return!1;s+=2}else if((t[s]&240)===224){if(s+2>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||t[s]===224&&(t[s+1]&224)===128||t[s]===237&&(t[s+1]&224)===160)return!1;s+=3}else if((t[s]&248)===240){if(s+3>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||(t[s+3]&192)!==128||t[s]===240&&(t[s+1]&240)===128||t[s]===244&&t[s+1]>143||t[s]>244)return!1;s+=4}else return!1;return!0}function ls(t){return ns&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}oe.exports={isBlob:ls,isValidStatusCode:as,isValidUTF8:we,tokenChars:os};if(tt)oe.exports.isValidUTF8=function(t){return t.length<24?we(t):tt(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=m("utf-8-validate");oe.exports.isValidUTF8=function(e){return e.length<32?we(e):t(e)}}catch{}});var Le=x((wr,lt)=>{"use strict";var{Writable:fs}=m("stream"),st=Z(),{BINARY_TYPES:hs,EMPTY_BUFFER:rt,kStatusCode:cs,kWebSocket:us}=T(),{concat:Oe,toArrayBuffer:ds,unmask:_s}=K(),{isValidStatusCode:ps,isValidUTF8:it}=q(),ae=Buffer[Symbol.species],v=0,nt=1,ot=2,at=3,Te=4,ke=5,le=6,Ce=class extends fs{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hs[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[us]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=v}_write(e,s,r){if(this._opcode===8&&this._state==v)return r();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e),new ae(r.buffer,r.byteOffset,e)}let s=Buffer.allocUnsafe(e);do{let r=this._buffers[0],i=s.length-e;e>=r.length?s.set(this._buffers.shift(),i):(s.set(new Uint8Array(r.buffer,r.byteOffset,e),i),this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return s}startLoop(e){this._loop=!0;do switch(this._state){case v:this.getInfo(e);break;case nt:this.getPayloadLength16(e);break;case ot:this.getPayloadLength64(e);break;case at:this.getMask();break;case Te:this.getData(e);break;case ke:case le:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let s=this.consume(2);if((s[0]&48)!==0){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(i);return}let r=(s[0]&64)===64;if(r&&!this._extensions[st.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._fin=(s[0]&128)===128,this._opcode=s[0]&15,this._payloadLength=s[1]&127,this._opcode===0){if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(i);return}if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(s[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(i);return}this._payloadLength===126?this._state=nt:this._payloadLength===127?this._state=ot:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let s=this.consume(8),r=s.readUInt32BE(0);if(r>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(i);return}this._payloadLength=r*Math.pow(2,32)+s.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let s=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(s);return}this._masked?this._state=at:this._state=Te}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Te}getData(e){let s=rt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}s=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&_s(s,this._mask)}if(this._opcode>7){this.controlMessage(s,e);return}if(this._compressed){this._state=ke,this.decompress(s,e);return}s.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(s)),this.dataMessage(e)}decompress(e,s){this._extensions[st.extensionName].decompress(e,this._fin,(i,n)=>{if(i)return s(i);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");s(o);return}this._fragments.push(n)}this.dataMessage(s),this._state===v&&this.startLoop(s)})}dataMessage(e){if(!this._fin){this._state=v;return}let s=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=Oe(r,s):this._binaryType==="arraybuffer"?i=ds(Oe(r,s)):this._binaryType==="blob"?i=new Blob(r):i=r,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=v):(this._state=le,setImmediate(()=>{this.emit("message",i,!0),this._state=v,this.startLoop(e)}))}else{let i=Oe(r,s);if(!this._skipUTF8Validation&&!it(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===ke||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=v):(this._state=le,setImmediate(()=>{this.emit("message",i,!1),this._state=v,this.startLoop(e)}))}}controlMessage(e,s){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,rt),this.end();else{let r=e.readUInt16BE(0);if(!ps(r)){let n=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");s(n);return}let i=new ae(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!it(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");s(n);return}this._loop=!1,this.emit("conclude",r,i),this.end()}this._state=v;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=v):(this._state=le,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=v,this.startLoop(s)}))}createError(e,s,r,i,n){this._loop=!1,this._errored=!0;let o=new e(r?`Invalid WebSocket frame: ${s}`:s);return Error.captureStackTrace(o,this.createError),o.code=n,o[cs]=i,o}};lt.exports=Ce});var Be=x((Tr,ct)=>{"use strict";var{Duplex:Or}=m("stream"),{randomFillSync:ms}=m("crypto"),ft=Z(),{EMPTY_BUFFER:gs,kWebSocket:ys,NOOP:Ss}=T(),{isBlob:G,isValidStatusCode:xs}=q(),{mask:ht,toBuffer:B}=K(),b=Symbol("kByteLength"),Es=Buffer.alloc(4),fe=8*1024,R,V=fe,w=0,vs=1,bs=2,Ne=class t{constructor(e,s,r){this._extensions=s||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=w,this.onerror=Ss,this[ys]=void 0}static frame(e,s){let r,i=!1,n=2,o=!1;s.mask&&(r=s.maskBuffer||Es,s.generateMask?s.generateMask(r):(V===fe&&(R===void 0&&(R=Buffer.alloc(fe)),ms(R,0,fe),V=0),r[0]=R[V++],r[1]=R[V++],r[2]=R[V++],r[3]=R[V++]),o=(r[0]|r[1]|r[2]|r[3])===0,n=6);let l;typeof e=="string"?(!s.mask||o)&&s[b]!==void 0?l=s[b]:(e=Buffer.from(e),l=e.length):(l=e.length,i=s.mask&&s.readOnly&&!o);let f=l;l>=65536?(n+=8,f=127):l>125&&(n+=2,f=126);let a=Buffer.allocUnsafe(i?l+n:n);return a[0]=s.fin?s.opcode|128:s.opcode,s.rsv1&&(a[0]|=64),a[1]=f,f===126?a.writeUInt16BE(l,2):f===127&&(a[2]=a[3]=0,a.writeUIntBE(l,4,6)),s.mask?(a[1]|=128,a[n-4]=r[0],a[n-3]=r[1],a[n-2]=r[2],a[n-1]=r[3],o?[a,e]:i?(ht(e,r,a,n,l),[a]):(ht(e,r,e,0,l),[a,e])):[a,e]}close(e,s,r,i){let n;if(e===void 0)n=gs;else{if(typeof e!="number"||!xs(e))throw new TypeError("First argument must be a valid error code number");if(s===void 0||!s.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let l=Buffer.byteLength(s);if(l>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+l),n.writeUInt16BE(e,0),typeof s=="string"?n.write(s,2):n.set(s,2)}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==w?this.enqueue([this.dispatch,n,!1,o,i]):this.sendFrame(t.frame(n,o),i)}ping(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):G(e)?(i=e.size,n=!1):(e=B(e),i=e.length,n=B.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};G(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}pong(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):G(e)?(i=e.size,n=!1):(e=B(e),i=e.length,n=B.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};G(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}send(e,s,r){let i=this._extensions[ft.extensionName],n=s.binary?2:1,o=s.compress,l,f;typeof e=="string"?(l=Buffer.byteLength(e),f=!1):G(e)?(l=e.size,f=!1):(e=B(e),l=e.length,f=B.readOnly),this._firstFragment?(this._firstFragment=!1,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=l>=i._threshold),this._compress=o):(o=!1,n=0),s.fin&&(this._firstFragment=!0);let a={[b]:l,fin:s.fin,generateMask:this._generateMask,mask:s.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:f,rsv1:o};G(e)?this._state!==w?this.enqueue([this.getBlobData,e,this._compress,a,r]):this.getBlobData(e,this._compress,a,r):this._state!==w?this.enqueue([this.dispatch,e,this._compress,a,r]):this.dispatch(e,this._compress,a,r)}getBlobData(e,s,r,i){this._bufferedBytes+=r[b],this._state=bs,e.arrayBuffer().then(n=>{if(this._socket.destroyed){let l=new Error("The socket was closed while the blob was being read");process.nextTick(Pe,this,l,i);return}this._bufferedBytes-=r[b];let o=B(n);s?this.dispatch(o,s,r,i):(this._state=w,this.sendFrame(t.frame(o,r),i),this.dequeue())}).catch(n=>{process.nextTick(ws,this,n,i)})}dispatch(e,s,r,i){if(!s){this.sendFrame(t.frame(e,r),i);return}let n=this._extensions[ft.extensionName];this._bufferedBytes+=r[b],this._state=vs,n.compress(e,r.fin,(o,l)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");Pe(this,f,i);return}this._bufferedBytes-=r[b],this._state=w,r.readOnly=!1,this.sendFrame(t.frame(l,r),i),this.dequeue()})}dequeue(){for(;this._state===w&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,s){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],s),this._socket.uncork()):this._socket.write(e[0],s)}};ct.exports=Ne;function Pe(t,e,s){typeof s=="function"&&s(e);for(let r=0;r<t._queue.length;r++){let i=t._queue[r],n=i[i.length-1];typeof n=="function"&&n(e)}}function ws(t,e,s){Pe(t,e,s),t.onerror(e)}});var xt=x((kr,St)=>{"use strict";var{kForOnEventAttribute:Q,kListener:Re}=T(),ut=Symbol("kCode"),dt=Symbol("kData"),_t=Symbol("kError"),pt=Symbol("kMessage"),mt=Symbol("kReason"),$=Symbol("kTarget"),gt=Symbol("kType"),yt=Symbol("kWasClean"),C=class{constructor(e){this[$]=null,this[gt]=e}get target(){return this[$]}get type(){return this[gt]}};Object.defineProperty(C.prototype,"target",{enumerable:!0});Object.defineProperty(C.prototype,"type",{enumerable:!0});var I=class extends C{constructor(e,s={}){super(e),this[ut]=s.code===void 0?0:s.code,this[mt]=s.reason===void 0?"":s.reason,this[yt]=s.wasClean===void 0?!1:s.wasClean}get code(){return this[ut]}get reason(){return this[mt]}get wasClean(){return this[yt]}};Object.defineProperty(I.prototype,"code",{enumerable:!0});Object.defineProperty(I.prototype,"reason",{enumerable:!0});Object.defineProperty(I.prototype,"wasClean",{enumerable:!0});var j=class extends C{constructor(e,s={}){super(e),this[_t]=s.error===void 0?null:s.error,this[pt]=s.message===void 0?"":s.message}get error(){return this[_t]}get message(){return this[pt]}};Object.defineProperty(j.prototype,"error",{enumerable:!0});Object.defineProperty(j.prototype,"message",{enumerable:!0});var J=class extends C{constructor(e,s={}){super(e),this[dt]=s.data===void 0?null:s.data}get data(){return this[dt]}};Object.defineProperty(J.prototype,"data",{enumerable:!0});var Os={addEventListener(t,e,s={}){for(let i of this.listeners(t))if(!s[Q]&&i[Re]===e&&!i[Q])return;let r;if(t==="message")r=function(n,o){let l=new J("message",{data:o?n:n.toString()});l[$]=this,he(e,this,l)};else if(t==="close")r=function(n,o){let l=new I("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});l[$]=this,he(e,this,l)};else if(t==="error")r=function(n){let o=new j("error",{error:n,message:n.message});o[$]=this,he(e,this,o)};else if(t==="open")r=function(){let n=new C("open");n[$]=this,he(e,this,n)};else return;r[Q]=!!s[Q],r[Re]=e,s.once?this.once(t,r):this.on(t,r)},removeEventListener(t,e){for(let s of this.listeners(t))if(s[Re]===e&&!s[Q]){this.removeListener(t,s);break}}};St.exports={CloseEvent:I,ErrorEvent:j,Event:C,EventTarget:Os,MessageEvent:J};function he(t,e,s){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,s):t.call(e,s)}});var Ie=x((Cr,Et)=>{"use strict";var{tokenChars:ee}=q();function O(t,e,s){t[e]===void 0?t[e]=[s]:t[e].push(s)}function Ts(t){let e=Object.create(null),s=Object.create(null),r=!1,i=!1,n=!1,o,l,f=-1,a=-1,h=-1,c=0;for(;c<t.length;c++)if(a=t.charCodeAt(c),o===void 0)if(h===-1&&ee[a]===1)f===-1&&(f=c);else if(c!==0&&(a===32||a===9))h===-1&&f!==-1&&(h=c);else if(a===59||a===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(f,h);a===44?(O(e,g,s),s=Object.create(null)):o=g,f=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(l===void 0)if(h===-1&&ee[a]===1)f===-1&&(f=c);else if(a===32||a===9)h===-1&&f!==-1&&(h=c);else if(a===59||a===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),O(s,t.slice(f,h),!0),a===44&&(O(e,o,s),s=Object.create(null),o=void 0),f=h=-1}else if(a===61&&f!==-1&&h===-1)l=t.slice(f,c),f=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(i){if(ee[a]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);f===-1?f=c:r||(r=!0),i=!1}else if(n)if(ee[a]===1)f===-1&&(f=c);else if(a===34&&f!==-1)n=!1,h=c;else if(a===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&ee[a]===1)f===-1&&(f=c);else if(f!==-1&&(a===32||a===9))h===-1&&(h=c);else if(a===59||a===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(f,h);r&&(g=g.replace(/\\/g,""),r=!1),O(s,l,g),a===44&&(O(e,o,s),s=Object.create(null),o=void 0),l=void 0,f=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(f===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let _=t.slice(f,h);return o===void 0?O(e,_,s):(l===void 0?O(s,_,!0):r?O(s,l,_.replace(/\\/g,"")):O(s,l,_),O(e,o,s)),e}function ks(t){return Object.keys(t).map(e=>{let s=t[e];return Array.isArray(s)||(s=[s]),s.map(r=>[e].concat(Object.keys(r).map(i=>{let n=r[i];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Et.exports={format:ks,parse:Ts}});var _e=x((Pr,Rt)=>{"use strict";var Cs=m("events"),Ls=m("https"),Ns=m("http"),wt=m("net"),Ps=m("tls"),{randomBytes:Bs,createHash:Rs}=m("crypto"),{Duplex:Lr,Readable:Nr}=m("stream"),{URL:Ue}=m("url"),P=Z(),Is=Le(),Us=Be(),{isBlob:Ds}=q(),{BINARY_TYPES:vt,EMPTY_BUFFER:ce,GUID:Ms,kForOnEventAttribute:De,kListener:As,kStatusCode:Ws,kWebSocket:y,NOOP:Ot}=T(),{EventTarget:{addEventListener:Fs,removeEventListener:qs}}=xt(),{format:Gs,parse:Vs}=Ie(),{toBuffer:$s}=K(),js=30*1e3,Tt=Symbol("kAborted"),Me=[8,13],L=["CONNECTING","OPEN","CLOSING","CLOSED"],zs=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends Cs{constructor(e,s,r){super(),this._binaryType=vt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ce,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,s===void 0?s=[]:Array.isArray(s)||(typeof s=="object"&&s!==null?(r=s,s=[]):s=[s]),kt(this,e,s,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){vt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,s,r){let i=new Is({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),n=new Us(e,this._extensions,r.generateMask);this._receiver=i,this._sender=n,this._socket=e,i[y]=this,n[y]=this,e[y]=this,i.on("conclude",Ks),i.on("drain",Xs),i.on("error",Zs),i.on("message",Qs),i.on("ping",Js),i.on("pong",er),n.onerror=tr,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),s.length>0&&e.unshift(s),e.on("close",Nt),e.on("data",de),e.on("end",Pt),e.on("error",Bt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[P.extensionName]&&this._extensions[P.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,s){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,s,!this._isServer,r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Lt(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.ping(e||ce,s,r)}pong(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.pong(e||ce,s,r)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof s=="function"&&(r=s,s={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}let i={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...s};this._extensions[P.extensionName]||(i.compress=!1),this._sender.send(e||ce,i,r)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[De])return e[As];return null},set(e){for(let s of this.listeners(t))if(s[De]){this.removeListener(t,s);break}typeof e=="function"&&this.addEventListener(t,e,{[De]:!0})}})});d.prototype.addEventListener=Fs;d.prototype.removeEventListener=qs;Rt.exports=d;function kt(t,e,s,r){let i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Me[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=i.autoPong,!Me.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Me.join(", ")})`);let n;if(e instanceof Ue)n=e;else try{n=new Ue(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",l=n.protocol==="ws+unix:",f;if(n.protocol!=="ws:"&&!o&&!l?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:l&&!n.pathname?f="The URL's pathname is empty":n.hash&&(f="The URL contains a fragment identifier"),f){let u=new SyntaxError(f);if(t._redirects===0)throw u;ue(t,u);return}let a=o?443:80,h=Bs(16).toString("base64"),c=o?Ls.request:Ns.request,_=new Set,g;if(i.createConnection=i.createConnection||(o?Ys:Hs),i.defaultPort=i.defaultPort||a,i.port=n.port||a,i.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},i.path=n.pathname+n.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(g=new P(i.perMessageDeflate!==!0?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=Gs({[P.extensionName]:g.offer()})),s.length){for(let u of s){if(typeof u!="string"||!zs.test(u)||_.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");_.add(u)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(n.username||n.password)&&(i.auth=`${n.username}:${n.password}`),l){let u=i.path.split(":");i.socketPath=u[0],i.path=u[1]}let p;if(i.followRedirects){if(t._redirects===0){t._originalIpc=l,t._originalSecure=o,t._originalHostOrSocketPath=l?i.socketPath:n.host;let u=r&&r.headers;if(r={...r,headers:{}},u)for(let[S,M]of Object.entries(u))r.headers[S.toLowerCase()]=M}else if(t.listenerCount("redirect")===0){let u=l?t._originalIpc?i.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,u||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),p=t._req=c(i),t._redirects&&t.emit("redirect",t.url,p)}else p=t._req=c(i);i.timeout&&p.on("timeout",()=>{E(t,p,"Opening handshake has timed out")}),p.on("error",u=>{p===null||p[Tt]||(p=t._req=null,ue(t,u))}),p.on("response",u=>{let S=u.headers.location,M=u.statusCode;if(S&&i.followRedirects&&M>=300&&M<400){if(++t._redirects>i.maxRedirects){E(t,p,"Maximum redirects exceeded");return}p.abort();let z;try{z=new Ue(S,e)}catch{let A=new SyntaxError(`Invalid URL: ${S}`);ue(t,A);return}kt(t,z,s,r)}else t.emit("unexpected-response",p,u)||E(t,p,`Unexpected server response: ${u.statusCode}`)}),p.on("upgrade",(u,S,M)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;p=t._req=null;let z=u.headers.upgrade;if(z===void 0||z.toLowerCase()!=="websocket"){E(t,S,"Invalid Upgrade header");return}let Fe=Rs("sha1").update(h+Ms).digest("base64");if(u.headers["sec-websocket-accept"]!==Fe){E(t,S,"Invalid Sec-WebSocket-Accept header");return}let A=u.headers["sec-websocket-protocol"],H;if(A!==void 0?_.size?_.has(A)||(H="Server sent an invalid subprotocol"):H="Server sent a subprotocol but none was requested":_.size&&(H="Server sent no subprotocol"),H){E(t,S,H);return}A&&(t._protocol=A);let qe=u.headers["sec-websocket-extensions"];if(qe!==void 0){if(!g){E(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let ge;try{ge=Vs(qe)}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}let Ge=Object.keys(ge);if(Ge.length!==1||Ge[0]!==P.extensionName){E(t,S,"Server indicated an extension that was not requested");return}try{g.accept(ge[P.extensionName])}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[P.extensionName]=g}t.setSocket(S,M,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(p,t):p.end()}function ue(t,e){t._readyState=d.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Hs(t){return t.path=t.socketPath,wt.connect(t)}function Ys(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=wt.isIP(t.host)?"":t.host),Ps.connect(t)}function E(t,e,s){t._readyState=d.CLOSING;let r=new Error(s);Error.captureStackTrace(r,E),e.setHeader?(e[Tt]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(ue,t,r)):(e.destroy(r),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Ae(t,e,s){if(e){let r=Ds(e)?e.size:$s(e).length;t._socket?t._sender._bufferedBytes+=r:t._bufferedAmount+=r}if(s){let r=new Error(`WebSocket is not open: readyState ${t.readyState} (${L[t.readyState]})`);process.nextTick(s,r)}}function Ks(t,e){let s=this[y];s._closeFrameReceived=!0,s._closeMessage=e,s._closeCode=t,s._socket[y]!==void 0&&(s._socket.removeListener("data",de),process.nextTick(Ct,s._socket),t===1005?s.close():s.close(t,e))}function Xs(){let t=this[y];t.isPaused||t._socket.resume()}function Zs(t){let e=this[y];e._socket[y]!==void 0&&(e._socket.removeListener("data",de),process.nextTick(Ct,e._socket),e.close(t[Ws])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function bt(){this[y].emitClose()}function Qs(t,e){this[y].emit("message",t,e)}function Js(t){let e=this[y];e._autoPong&&e.pong(t,!this._isServer,Ot),e.emit("ping",t)}function er(t){this[y].emit("pong",t)}function Ct(t){t.resume()}function tr(t){let e=this[y];e.readyState!==d.CLOSED&&(e.readyState===d.OPEN&&(e._readyState=d.CLOSING,Lt(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Lt(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),js)}function Nt(){let t=this[y];this.removeListener("close",Nt),this.removeListener("data",de),this.removeListener("end",Pt),t._readyState=d.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[y]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",bt),t._receiver.on("finish",bt))}function de(t){this[y]._receiver.write(t)||this.pause()}function Pt(){let t=this[y];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Bt(){let t=this[y];this.removeListener("error",Bt),this.on("error",Ot),t&&(t._readyState=d.CLOSING,this.destroy())}});var Mt=x((Rr,Dt)=>{"use strict";var Br=_e(),{Duplex:sr}=m("stream");function It(t){t.emit("close")}function rr(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Ut(t){this.removeListener("error",Ut),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function ir(t,e){let s=!0,r=new sr({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let l=!o&&r._readableState.objectMode?n.toString():n;r.push(l)||t.pause()}),t.once("error",function(n){r.destroyed||(s=!1,r.destroy(n))}),t.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(i,n){if(t.readyState===t.CLOSED){n(i),process.nextTick(It,r);return}let o=!1;t.once("error",function(f){o=!0,n(f)}),t.once("close",function(){o||n(i),process.nextTick(It,r)}),s&&t.terminate()},r._final=function(i){if(t.readyState===t.CONNECTING){t.once("open",function(){r._final(i)});return}t._socket!==null&&(t._socket._writableState.finished?(i(),r._readableState.endEmitted&&r.destroy()):(t._socket.once("finish",function(){i()}),t.close()))},r._read=function(){t.isPaused&&t.resume()},r._write=function(i,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){r._write(i,n,o)});return}t.send(i,o)},r.on("end",rr),r.on("error",Ut),r}Dt.exports=ir});var Wt=x((Ir,At)=>{"use strict";var{tokenChars:nr}=q();function or(t){let e=new Set,s=-1,r=-1,i=0;for(i;i<t.length;i++){let o=t.charCodeAt(i);if(r===-1&&nr[o]===1)s===-1&&(s=i);else if(i!==0&&(o===32||o===9))r===-1&&s!==-1&&(r=i);else if(o===44){if(s===-1)throw new SyntaxError(`Unexpected character at index ${i}`);r===-1&&(r=i);let l=t.slice(s,r);if(e.has(l))throw new SyntaxError(`The "${l}" subprotocol is duplicated`);e.add(l),s=r=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(s===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(s,i);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}At.exports={parse:or}});var zt=x((Dr,jt)=>{"use strict";var ar=m("events"),pe=m("http"),{Duplex:Ur}=m("stream"),{createHash:lr}=m("crypto"),Ft=Ie(),U=Z(),fr=Wt(),hr=_e(),{GUID:cr,kWebSocket:ur}=T(),dr=/^[+/0-9A-Za-z]{22}==$/,qt=0,Gt=1,$t=2,We=class extends ar{constructor(e,s){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:hr,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=pe.createServer((r,i)=>{let n=pe.STATUS_CODES[426];i.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),i.end(n)}),this._server.listen(e.port,e.host,e.backlog,s)):e.server&&(this._server=e.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=_r(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,n,o)=>{this.handleUpgrade(i,n,o,r)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=qt}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===$t){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(te,this);return}if(e&&this.once("close",e),this._state!==Gt)if(this._state=Gt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(te,this):process.nextTick(te,this);else{let s=this._server;this._removeListeners(),this._removeListeners=this._server=null,s.close(()=>{te(this)})}}shouldHandle(e){if(this.options.path){let s=e.url.indexOf("?");if((s!==-1?e.url.slice(0,s):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,s,r,i){s.on("error",Vt);let n=e.headers["sec-websocket-key"],o=e.headers.upgrade,l=+e.headers["sec-websocket-version"];if(e.method!=="GET"){D(this,e,s,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){D(this,e,s,400,"Invalid Upgrade header");return}if(n===void 0||!dr.test(n)){D(this,e,s,400,"Missing or invalid Sec-WebSocket-Key header");return}if(l!==13&&l!==8){D(this,e,s,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){se(s,400);return}let f=e.headers["sec-websocket-protocol"],a=new Set;if(f!==void 0)try{a=fr.parse(f)}catch{D(this,e,s,400,"Invalid Sec-WebSocket-Protocol header");return}let h=e.headers["sec-websocket-extensions"],c={};if(this.options.perMessageDeflate&&h!==void 0){let _=new U(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let g=Ft.parse(h);g[U.extensionName]&&(_.accept(g[U.extensionName]),c[U.extensionName]=_)}catch{D(this,e,s,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let _={origin:e.headers[`${l===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(_,(g,p,u,S)=>{if(!g)return se(s,p||401,u,S);this.completeUpgrade(c,n,a,e,s,r,i)});return}if(!this.options.verifyClient(_))return se(s,401)}this.completeUpgrade(c,n,a,e,s,r,i)}completeUpgrade(e,s,r,i,n,o,l){if(!n.readable||!n.writable)return n.destroy();if(n[ur])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>qt)return se(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${lr("sha1").update(s+cr).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(r.size){let c=this.options.handleProtocols?this.options.handleProtocols(r,i):r.values().next().value;c&&(a.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[U.extensionName]){let c=e[U.extensionName].params,_=Ft.format({[U.extensionName]:[c]});a.push(`Sec-WebSocket-Extensions: ${_}`),h._extensions=e}this.emit("headers",a,i),n.write(a.concat(`\r
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as m,c as x,e as Y}from"./chunk-UR6MHSHU.js";var T=x((Sr,je)=>{"use strict";var Ve=["nodebuffer","arraybuffer","fragments"],$e=typeof Blob<"u";$e&&Ve.push("blob");je.exports={BINARY_TYPES:Ve,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:$e,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var K=x((xr,re)=>{"use strict";var{EMPTY_BUFFER:Zt}=T(),Se=Buffer[Symbol.species];function Qt(t,e){if(t.length===0)return Zt;if(t.length===1)return t[0];let s=Buffer.allocUnsafe(e),r=0;for(let i=0;i<t.length;i++){let n=t[i];s.set(n,r),r+=n.length}return r<e?new Se(s.buffer,s.byteOffset,r):s}function ze(t,e,s,r,i){for(let n=0;n<i;n++)s[r+n]=t[n]^e[n&3]}function He(t,e){for(let s=0;s<t.length;s++)t[s]^=e[s&3]}function Jt(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function xe(t){if(xe.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Se(t):ArrayBuffer.isView(t)?e=new Se(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),xe.readOnly=!1),e}re.exports={concat:Qt,mask:ze,toArrayBuffer:Jt,toBuffer:xe,unmask:He};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=m("bufferutil");re.exports.mask=function(e,s,r,i,n){n<48?ze(e,s,r,i,n):t.mask(e,s,r,i,n)},re.exports.unmask=function(e,s){e.length<32?He(e,s):t.unmask(e,s)}}catch{}});var Xe=x((Er,Ke)=>{"use strict";var Ye=Symbol("kDone"),Ee=Symbol("kRun"),ve=class{constructor(e){this[Ye]=()=>{this.pending--,this[Ee]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Ee]()}[Ee](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Ye])}}};Ke.exports=ve});var Z=x((vr,et)=>{"use strict";var X=m("zlib"),Ze=K(),es=Xe(),{kStatusCode:Qe}=T(),ts=Buffer[Symbol.species],ss=Buffer.from([0,0,255,255]),ne=Symbol("permessage-deflate"),k=Symbol("total-length"),W=Symbol("callback"),N=Symbol("buffers"),F=Symbol("error"),ie,be=class{constructor(e,s,r){if(this._maxPayload=r|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!s,this._deflate=null,this._inflate=null,this.params=null,!ie){let i=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ie=new es(i)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[W];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let s=this._options,r=e.find(i=>!(s.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(s.serverMaxWindowBits===!1||typeof s.serverMaxWindowBits=="number"&&s.serverMaxWindowBits>i.server_max_window_bits)||typeof s.clientMaxWindowBits=="number"&&!i.client_max_window_bits));if(!r)throw new Error("None of the extension offers can be accepted");return s.serverNoContextTakeover&&(r.server_no_context_takeover=!0),s.clientNoContextTakeover&&(r.client_no_context_takeover=!0),typeof s.serverMaxWindowBits=="number"&&(r.server_max_window_bits=s.serverMaxWindowBits),typeof s.clientMaxWindowBits=="number"?r.client_max_window_bits=s.clientMaxWindowBits:(r.client_max_window_bits===!0||s.clientMaxWindowBits===!1)&&delete r.client_max_window_bits,r}acceptAsClient(e){let s=e[0];if(this._options.clientNoContextTakeover===!1&&s.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!s.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(s.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&s.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return s}normalizeParams(e){return e.forEach(s=>{Object.keys(s).forEach(r=>{let i=s[r];if(i.length>1)throw new Error(`Parameter "${r}" must have only a single value`);if(i=i[0],r==="client_max_window_bits"){if(i!==!0){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else if(r==="server_max_window_bits"){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else throw new Error(`Unknown parameter "${r}"`);s[r]=i})}),e}decompress(e,s,r){ie.add(i=>{this._decompress(e,s,(n,o)=>{i(),r(n,o)})})}compress(e,s,r){ie.add(i=>{this._compress(e,s,(n,o)=>{i(),r(n,o)})})}_decompress(e,s,r){let i=this._isServer?"client":"server";if(!this._inflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?X.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=X.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[ne]=this,this._inflate[k]=0,this._inflate[N]=[],this._inflate.on("error",is),this._inflate.on("data",Je)}this._inflate[W]=r,this._inflate.write(e),s&&this._inflate.write(ss),this._inflate.flush(()=>{let n=this._inflate[F];if(n){this._inflate.close(),this._inflate=null,r(n);return}let o=Ze.concat(this._inflate[N],this._inflate[k]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[k]=0,this._inflate[N]=[],s&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),r(null,o)})}_compress(e,s,r){let i=this._isServer?"server":"client";if(!this._deflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?X.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=X.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[k]=0,this._deflate[N]=[],this._deflate.on("data",rs)}this._deflate[W]=r,this._deflate.write(e),this._deflate.flush(X.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Ze.concat(this._deflate[N],this._deflate[k]);s&&(n=new ts(n.buffer,n.byteOffset,n.length-4)),this._deflate[W]=null,this._deflate[k]=0,this._deflate[N]=[],s&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),r(null,n)})}};et.exports=be;function rs(t){this[N].push(t),this[k]+=t.length}function Je(t){if(this[k]+=t.length,this[ne]._maxPayload<1||this[k]<=this[ne]._maxPayload){this[N].push(t);return}this[F]=new RangeError("Max payload size exceeded"),this[F].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[F][Qe]=1009,this.removeListener("data",Je),this.reset()}function is(t){if(this[ne]._inflate=null,this[F]){this[W](this[F]);return}t[Qe]=1007,this[W](t)}});var q=x((br,oe)=>{"use strict";var{isUtf8:tt}=m("buffer"),{hasBlob:ns}=T(),os=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function as(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function we(t){let e=t.length,s=0;for(;s<e;)if((t[s]&128)===0)s++;else if((t[s]&224)===192){if(s+1===e||(t[s+1]&192)!==128||(t[s]&254)===192)return!1;s+=2}else if((t[s]&240)===224){if(s+2>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||t[s]===224&&(t[s+1]&224)===128||t[s]===237&&(t[s+1]&224)===160)return!1;s+=3}else if((t[s]&248)===240){if(s+3>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||(t[s+3]&192)!==128||t[s]===240&&(t[s+1]&240)===128||t[s]===244&&t[s+1]>143||t[s]>244)return!1;s+=4}else return!1;return!0}function ls(t){return ns&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}oe.exports={isBlob:ls,isValidStatusCode:as,isValidUTF8:we,tokenChars:os};if(tt)oe.exports.isValidUTF8=function(t){return t.length<24?we(t):tt(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=m("utf-8-validate");oe.exports.isValidUTF8=function(e){return e.length<32?we(e):t(e)}}catch{}});var Le=x((wr,lt)=>{"use strict";var{Writable:fs}=m("stream"),st=Z(),{BINARY_TYPES:hs,EMPTY_BUFFER:rt,kStatusCode:cs,kWebSocket:us}=T(),{concat:Oe,toArrayBuffer:ds,unmask:_s}=K(),{isValidStatusCode:ps,isValidUTF8:it}=q(),ae=Buffer[Symbol.species],v=0,nt=1,ot=2,at=3,Te=4,ke=5,le=6,Ce=class extends fs{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hs[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[us]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=v}_write(e,s,r){if(this._opcode===8&&this._state==v)return r();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e),new ae(r.buffer,r.byteOffset,e)}let s=Buffer.allocUnsafe(e);do{let r=this._buffers[0],i=s.length-e;e>=r.length?s.set(this._buffers.shift(),i):(s.set(new Uint8Array(r.buffer,r.byteOffset,e),i),this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return s}startLoop(e){this._loop=!0;do switch(this._state){case v:this.getInfo(e);break;case nt:this.getPayloadLength16(e);break;case ot:this.getPayloadLength64(e);break;case at:this.getMask();break;case Te:this.getData(e);break;case ke:case le:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let s=this.consume(2);if((s[0]&48)!==0){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(i);return}let r=(s[0]&64)===64;if(r&&!this._extensions[st.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._fin=(s[0]&128)===128,this._opcode=s[0]&15,this._payloadLength=s[1]&127,this._opcode===0){if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(i);return}if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(s[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(i);return}this._payloadLength===126?this._state=nt:this._payloadLength===127?this._state=ot:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let s=this.consume(8),r=s.readUInt32BE(0);if(r>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(i);return}this._payloadLength=r*Math.pow(2,32)+s.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let s=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(s);return}this._masked?this._state=at:this._state=Te}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Te}getData(e){let s=rt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}s=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&_s(s,this._mask)}if(this._opcode>7){this.controlMessage(s,e);return}if(this._compressed){this._state=ke,this.decompress(s,e);return}s.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(s)),this.dataMessage(e)}decompress(e,s){this._extensions[st.extensionName].decompress(e,this._fin,(i,n)=>{if(i)return s(i);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");s(o);return}this._fragments.push(n)}this.dataMessage(s),this._state===v&&this.startLoop(s)})}dataMessage(e){if(!this._fin){this._state=v;return}let s=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=Oe(r,s):this._binaryType==="arraybuffer"?i=ds(Oe(r,s)):this._binaryType==="blob"?i=new Blob(r):i=r,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=v):(this._state=le,setImmediate(()=>{this.emit("message",i,!0),this._state=v,this.startLoop(e)}))}else{let i=Oe(r,s);if(!this._skipUTF8Validation&&!it(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===ke||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=v):(this._state=le,setImmediate(()=>{this.emit("message",i,!1),this._state=v,this.startLoop(e)}))}}controlMessage(e,s){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,rt),this.end();else{let r=e.readUInt16BE(0);if(!ps(r)){let n=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");s(n);return}let i=new ae(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!it(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");s(n);return}this._loop=!1,this.emit("conclude",r,i),this.end()}this._state=v;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=v):(this._state=le,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=v,this.startLoop(s)}))}createError(e,s,r,i,n){this._loop=!1,this._errored=!0;let o=new e(r?`Invalid WebSocket frame: ${s}`:s);return Error.captureStackTrace(o,this.createError),o.code=n,o[cs]=i,o}};lt.exports=Ce});var Be=x((Tr,ct)=>{"use strict";var{Duplex:Or}=m("stream"),{randomFillSync:ms}=m("crypto"),ft=Z(),{EMPTY_BUFFER:gs,kWebSocket:ys,NOOP:Ss}=T(),{isBlob:G,isValidStatusCode:xs}=q(),{mask:ht,toBuffer:B}=K(),b=Symbol("kByteLength"),Es=Buffer.alloc(4),fe=8*1024,R,V=fe,w=0,vs=1,bs=2,Ne=class t{constructor(e,s,r){this._extensions=s||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=w,this.onerror=Ss,this[ys]=void 0}static frame(e,s){let r,i=!1,n=2,o=!1;s.mask&&(r=s.maskBuffer||Es,s.generateMask?s.generateMask(r):(V===fe&&(R===void 0&&(R=Buffer.alloc(fe)),ms(R,0,fe),V=0),r[0]=R[V++],r[1]=R[V++],r[2]=R[V++],r[3]=R[V++]),o=(r[0]|r[1]|r[2]|r[3])===0,n=6);let l;typeof e=="string"?(!s.mask||o)&&s[b]!==void 0?l=s[b]:(e=Buffer.from(e),l=e.length):(l=e.length,i=s.mask&&s.readOnly&&!o);let f=l;l>=65536?(n+=8,f=127):l>125&&(n+=2,f=126);let a=Buffer.allocUnsafe(i?l+n:n);return a[0]=s.fin?s.opcode|128:s.opcode,s.rsv1&&(a[0]|=64),a[1]=f,f===126?a.writeUInt16BE(l,2):f===127&&(a[2]=a[3]=0,a.writeUIntBE(l,4,6)),s.mask?(a[1]|=128,a[n-4]=r[0],a[n-3]=r[1],a[n-2]=r[2],a[n-1]=r[3],o?[a,e]:i?(ht(e,r,a,n,l),[a]):(ht(e,r,e,0,l),[a,e])):[a,e]}close(e,s,r,i){let n;if(e===void 0)n=gs;else{if(typeof e!="number"||!xs(e))throw new TypeError("First argument must be a valid error code number");if(s===void 0||!s.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let l=Buffer.byteLength(s);if(l>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+l),n.writeUInt16BE(e,0),typeof s=="string"?n.write(s,2):n.set(s,2)}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==w?this.enqueue([this.dispatch,n,!1,o,i]):this.sendFrame(t.frame(n,o),i)}ping(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):G(e)?(i=e.size,n=!1):(e=B(e),i=e.length,n=B.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};G(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}pong(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):G(e)?(i=e.size,n=!1):(e=B(e),i=e.length,n=B.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};G(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}send(e,s,r){let i=this._extensions[ft.extensionName],n=s.binary?2:1,o=s.compress,l,f;typeof e=="string"?(l=Buffer.byteLength(e),f=!1):G(e)?(l=e.size,f=!1):(e=B(e),l=e.length,f=B.readOnly),this._firstFragment?(this._firstFragment=!1,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=l>=i._threshold),this._compress=o):(o=!1,n=0),s.fin&&(this._firstFragment=!0);let a={[b]:l,fin:s.fin,generateMask:this._generateMask,mask:s.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:f,rsv1:o};G(e)?this._state!==w?this.enqueue([this.getBlobData,e,this._compress,a,r]):this.getBlobData(e,this._compress,a,r):this._state!==w?this.enqueue([this.dispatch,e,this._compress,a,r]):this.dispatch(e,this._compress,a,r)}getBlobData(e,s,r,i){this._bufferedBytes+=r[b],this._state=bs,e.arrayBuffer().then(n=>{if(this._socket.destroyed){let l=new Error("The socket was closed while the blob was being read");process.nextTick(Pe,this,l,i);return}this._bufferedBytes-=r[b];let o=B(n);s?this.dispatch(o,s,r,i):(this._state=w,this.sendFrame(t.frame(o,r),i),this.dequeue())}).catch(n=>{process.nextTick(ws,this,n,i)})}dispatch(e,s,r,i){if(!s){this.sendFrame(t.frame(e,r),i);return}let n=this._extensions[ft.extensionName];this._bufferedBytes+=r[b],this._state=vs,n.compress(e,r.fin,(o,l)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");Pe(this,f,i);return}this._bufferedBytes-=r[b],this._state=w,r.readOnly=!1,this.sendFrame(t.frame(l,r),i),this.dequeue()})}dequeue(){for(;this._state===w&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,s){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],s),this._socket.uncork()):this._socket.write(e[0],s)}};ct.exports=Ne;function Pe(t,e,s){typeof s=="function"&&s(e);for(let r=0;r<t._queue.length;r++){let i=t._queue[r],n=i[i.length-1];typeof n=="function"&&n(e)}}function ws(t,e,s){Pe(t,e,s),t.onerror(e)}});var xt=x((kr,St)=>{"use strict";var{kForOnEventAttribute:Q,kListener:Re}=T(),ut=Symbol("kCode"),dt=Symbol("kData"),_t=Symbol("kError"),pt=Symbol("kMessage"),mt=Symbol("kReason"),$=Symbol("kTarget"),gt=Symbol("kType"),yt=Symbol("kWasClean"),C=class{constructor(e){this[$]=null,this[gt]=e}get target(){return this[$]}get type(){return this[gt]}};Object.defineProperty(C.prototype,"target",{enumerable:!0});Object.defineProperty(C.prototype,"type",{enumerable:!0});var I=class extends C{constructor(e,s={}){super(e),this[ut]=s.code===void 0?0:s.code,this[mt]=s.reason===void 0?"":s.reason,this[yt]=s.wasClean===void 0?!1:s.wasClean}get code(){return this[ut]}get reason(){return this[mt]}get wasClean(){return this[yt]}};Object.defineProperty(I.prototype,"code",{enumerable:!0});Object.defineProperty(I.prototype,"reason",{enumerable:!0});Object.defineProperty(I.prototype,"wasClean",{enumerable:!0});var j=class extends C{constructor(e,s={}){super(e),this[_t]=s.error===void 0?null:s.error,this[pt]=s.message===void 0?"":s.message}get error(){return this[_t]}get message(){return this[pt]}};Object.defineProperty(j.prototype,"error",{enumerable:!0});Object.defineProperty(j.prototype,"message",{enumerable:!0});var J=class extends C{constructor(e,s={}){super(e),this[dt]=s.data===void 0?null:s.data}get data(){return this[dt]}};Object.defineProperty(J.prototype,"data",{enumerable:!0});var Os={addEventListener(t,e,s={}){for(let i of this.listeners(t))if(!s[Q]&&i[Re]===e&&!i[Q])return;let r;if(t==="message")r=function(n,o){let l=new J("message",{data:o?n:n.toString()});l[$]=this,he(e,this,l)};else if(t==="close")r=function(n,o){let l=new I("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});l[$]=this,he(e,this,l)};else if(t==="error")r=function(n){let o=new j("error",{error:n,message:n.message});o[$]=this,he(e,this,o)};else if(t==="open")r=function(){let n=new C("open");n[$]=this,he(e,this,n)};else return;r[Q]=!!s[Q],r[Re]=e,s.once?this.once(t,r):this.on(t,r)},removeEventListener(t,e){for(let s of this.listeners(t))if(s[Re]===e&&!s[Q]){this.removeListener(t,s);break}}};St.exports={CloseEvent:I,ErrorEvent:j,Event:C,EventTarget:Os,MessageEvent:J};function he(t,e,s){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,s):t.call(e,s)}});var Ie=x((Cr,Et)=>{"use strict";var{tokenChars:ee}=q();function O(t,e,s){t[e]===void 0?t[e]=[s]:t[e].push(s)}function Ts(t){let e=Object.create(null),s=Object.create(null),r=!1,i=!1,n=!1,o,l,f=-1,a=-1,h=-1,c=0;for(;c<t.length;c++)if(a=t.charCodeAt(c),o===void 0)if(h===-1&&ee[a]===1)f===-1&&(f=c);else if(c!==0&&(a===32||a===9))h===-1&&f!==-1&&(h=c);else if(a===59||a===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(f,h);a===44?(O(e,g,s),s=Object.create(null)):o=g,f=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(l===void 0)if(h===-1&&ee[a]===1)f===-1&&(f=c);else if(a===32||a===9)h===-1&&f!==-1&&(h=c);else if(a===59||a===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),O(s,t.slice(f,h),!0),a===44&&(O(e,o,s),s=Object.create(null),o=void 0),f=h=-1}else if(a===61&&f!==-1&&h===-1)l=t.slice(f,c),f=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(i){if(ee[a]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);f===-1?f=c:r||(r=!0),i=!1}else if(n)if(ee[a]===1)f===-1&&(f=c);else if(a===34&&f!==-1)n=!1,h=c;else if(a===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&ee[a]===1)f===-1&&(f=c);else if(f!==-1&&(a===32||a===9))h===-1&&(h=c);else if(a===59||a===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(f,h);r&&(g=g.replace(/\\/g,""),r=!1),O(s,l,g),a===44&&(O(e,o,s),s=Object.create(null),o=void 0),l=void 0,f=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(f===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let _=t.slice(f,h);return o===void 0?O(e,_,s):(l===void 0?O(s,_,!0):r?O(s,l,_.replace(/\\/g,"")):O(s,l,_),O(e,o,s)),e}function ks(t){return Object.keys(t).map(e=>{let s=t[e];return Array.isArray(s)||(s=[s]),s.map(r=>[e].concat(Object.keys(r).map(i=>{let n=r[i];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Et.exports={format:ks,parse:Ts}});var _e=x((Pr,Rt)=>{"use strict";var Cs=m("events"),Ls=m("https"),Ns=m("http"),wt=m("net"),Ps=m("tls"),{randomBytes:Bs,createHash:Rs}=m("crypto"),{Duplex:Lr,Readable:Nr}=m("stream"),{URL:Ue}=m("url"),P=Z(),Is=Le(),Us=Be(),{isBlob:Ds}=q(),{BINARY_TYPES:vt,EMPTY_BUFFER:ce,GUID:Ms,kForOnEventAttribute:De,kListener:As,kStatusCode:Ws,kWebSocket:y,NOOP:Ot}=T(),{EventTarget:{addEventListener:Fs,removeEventListener:qs}}=xt(),{format:Gs,parse:Vs}=Ie(),{toBuffer:$s}=K(),js=30*1e3,Tt=Symbol("kAborted"),Me=[8,13],L=["CONNECTING","OPEN","CLOSING","CLOSED"],zs=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends Cs{constructor(e,s,r){super(),this._binaryType=vt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ce,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,s===void 0?s=[]:Array.isArray(s)||(typeof s=="object"&&s!==null?(r=s,s=[]):s=[s]),kt(this,e,s,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){vt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,s,r){let i=new Is({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),n=new Us(e,this._extensions,r.generateMask);this._receiver=i,this._sender=n,this._socket=e,i[y]=this,n[y]=this,e[y]=this,i.on("conclude",Ks),i.on("drain",Xs),i.on("error",Zs),i.on("message",Qs),i.on("ping",Js),i.on("pong",er),n.onerror=tr,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),s.length>0&&e.unshift(s),e.on("close",Nt),e.on("data",de),e.on("end",Pt),e.on("error",Bt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[P.extensionName]&&this._extensions[P.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,s){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,s,!this._isServer,r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Lt(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.ping(e||ce,s,r)}pong(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.pong(e||ce,s,r)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof s=="function"&&(r=s,s={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}let i={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...s};this._extensions[P.extensionName]||(i.compress=!1),this._sender.send(e||ce,i,r)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[De])return e[As];return null},set(e){for(let s of this.listeners(t))if(s[De]){this.removeListener(t,s);break}typeof e=="function"&&this.addEventListener(t,e,{[De]:!0})}})});d.prototype.addEventListener=Fs;d.prototype.removeEventListener=qs;Rt.exports=d;function kt(t,e,s,r){let i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Me[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=i.autoPong,!Me.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Me.join(", ")})`);let n;if(e instanceof Ue)n=e;else try{n=new Ue(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",l=n.protocol==="ws+unix:",f;if(n.protocol!=="ws:"&&!o&&!l?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:l&&!n.pathname?f="The URL's pathname is empty":n.hash&&(f="The URL contains a fragment identifier"),f){let u=new SyntaxError(f);if(t._redirects===0)throw u;ue(t,u);return}let a=o?443:80,h=Bs(16).toString("base64"),c=o?Ls.request:Ns.request,_=new Set,g;if(i.createConnection=i.createConnection||(o?Ys:Hs),i.defaultPort=i.defaultPort||a,i.port=n.port||a,i.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},i.path=n.pathname+n.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(g=new P(i.perMessageDeflate!==!0?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=Gs({[P.extensionName]:g.offer()})),s.length){for(let u of s){if(typeof u!="string"||!zs.test(u)||_.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");_.add(u)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(n.username||n.password)&&(i.auth=`${n.username}:${n.password}`),l){let u=i.path.split(":");i.socketPath=u[0],i.path=u[1]}let p;if(i.followRedirects){if(t._redirects===0){t._originalIpc=l,t._originalSecure=o,t._originalHostOrSocketPath=l?i.socketPath:n.host;let u=r&&r.headers;if(r={...r,headers:{}},u)for(let[S,M]of Object.entries(u))r.headers[S.toLowerCase()]=M}else if(t.listenerCount("redirect")===0){let u=l?t._originalIpc?i.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,u||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),p=t._req=c(i),t._redirects&&t.emit("redirect",t.url,p)}else p=t._req=c(i);i.timeout&&p.on("timeout",()=>{E(t,p,"Opening handshake has timed out")}),p.on("error",u=>{p===null||p[Tt]||(p=t._req=null,ue(t,u))}),p.on("response",u=>{let S=u.headers.location,M=u.statusCode;if(S&&i.followRedirects&&M>=300&&M<400){if(++t._redirects>i.maxRedirects){E(t,p,"Maximum redirects exceeded");return}p.abort();let z;try{z=new Ue(S,e)}catch{let A=new SyntaxError(`Invalid URL: ${S}`);ue(t,A);return}kt(t,z,s,r)}else t.emit("unexpected-response",p,u)||E(t,p,`Unexpected server response: ${u.statusCode}`)}),p.on("upgrade",(u,S,M)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;p=t._req=null;let z=u.headers.upgrade;if(z===void 0||z.toLowerCase()!=="websocket"){E(t,S,"Invalid Upgrade header");return}let Fe=Rs("sha1").update(h+Ms).digest("base64");if(u.headers["sec-websocket-accept"]!==Fe){E(t,S,"Invalid Sec-WebSocket-Accept header");return}let A=u.headers["sec-websocket-protocol"],H;if(A!==void 0?_.size?_.has(A)||(H="Server sent an invalid subprotocol"):H="Server sent a subprotocol but none was requested":_.size&&(H="Server sent no subprotocol"),H){E(t,S,H);return}A&&(t._protocol=A);let qe=u.headers["sec-websocket-extensions"];if(qe!==void 0){if(!g){E(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let ge;try{ge=Vs(qe)}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}let Ge=Object.keys(ge);if(Ge.length!==1||Ge[0]!==P.extensionName){E(t,S,"Server indicated an extension that was not requested");return}try{g.accept(ge[P.extensionName])}catch{E(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[P.extensionName]=g}t.setSocket(S,M,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(p,t):p.end()}function ue(t,e){t._readyState=d.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Hs(t){return t.path=t.socketPath,wt.connect(t)}function Ys(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=wt.isIP(t.host)?"":t.host),Ps.connect(t)}function E(t,e,s){t._readyState=d.CLOSING;let r=new Error(s);Error.captureStackTrace(r,E),e.setHeader?(e[Tt]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(ue,t,r)):(e.destroy(r),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Ae(t,e,s){if(e){let r=Ds(e)?e.size:$s(e).length;t._socket?t._sender._bufferedBytes+=r:t._bufferedAmount+=r}if(s){let r=new Error(`WebSocket is not open: readyState ${t.readyState} (${L[t.readyState]})`);process.nextTick(s,r)}}function Ks(t,e){let s=this[y];s._closeFrameReceived=!0,s._closeMessage=e,s._closeCode=t,s._socket[y]!==void 0&&(s._socket.removeListener("data",de),process.nextTick(Ct,s._socket),t===1005?s.close():s.close(t,e))}function Xs(){let t=this[y];t.isPaused||t._socket.resume()}function Zs(t){let e=this[y];e._socket[y]!==void 0&&(e._socket.removeListener("data",de),process.nextTick(Ct,e._socket),e.close(t[Ws])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function bt(){this[y].emitClose()}function Qs(t,e){this[y].emit("message",t,e)}function Js(t){let e=this[y];e._autoPong&&e.pong(t,!this._isServer,Ot),e.emit("ping",t)}function er(t){this[y].emit("pong",t)}function Ct(t){t.resume()}function tr(t){let e=this[y];e.readyState!==d.CLOSED&&(e.readyState===d.OPEN&&(e._readyState=d.CLOSING,Lt(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Lt(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),js)}function Nt(){let t=this[y];this.removeListener("close",Nt),this.removeListener("data",de),this.removeListener("end",Pt),t._readyState=d.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[y]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",bt),t._receiver.on("finish",bt))}function de(t){this[y]._receiver.write(t)||this.pause()}function Pt(){let t=this[y];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Bt(){let t=this[y];this.removeListener("error",Bt),this.on("error",Ot),t&&(t._readyState=d.CLOSING,this.destroy())}});var Mt=x((Rr,Dt)=>{"use strict";var Br=_e(),{Duplex:sr}=m("stream");function It(t){t.emit("close")}function rr(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Ut(t){this.removeListener("error",Ut),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function ir(t,e){let s=!0,r=new sr({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let l=!o&&r._readableState.objectMode?n.toString():n;r.push(l)||t.pause()}),t.once("error",function(n){r.destroyed||(s=!1,r.destroy(n))}),t.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(i,n){if(t.readyState===t.CLOSED){n(i),process.nextTick(It,r);return}let o=!1;t.once("error",function(f){o=!0,n(f)}),t.once("close",function(){o||n(i),process.nextTick(It,r)}),s&&t.terminate()},r._final=function(i){if(t.readyState===t.CONNECTING){t.once("open",function(){r._final(i)});return}t._socket!==null&&(t._socket._writableState.finished?(i(),r._readableState.endEmitted&&r.destroy()):(t._socket.once("finish",function(){i()}),t.close()))},r._read=function(){t.isPaused&&t.resume()},r._write=function(i,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){r._write(i,n,o)});return}t.send(i,o)},r.on("end",rr),r.on("error",Ut),r}Dt.exports=ir});var Wt=x((Ir,At)=>{"use strict";var{tokenChars:nr}=q();function or(t){let e=new Set,s=-1,r=-1,i=0;for(i;i<t.length;i++){let o=t.charCodeAt(i);if(r===-1&&nr[o]===1)s===-1&&(s=i);else if(i!==0&&(o===32||o===9))r===-1&&s!==-1&&(r=i);else if(o===44){if(s===-1)throw new SyntaxError(`Unexpected character at index ${i}`);r===-1&&(r=i);let l=t.slice(s,r);if(e.has(l))throw new SyntaxError(`The "${l}" subprotocol is duplicated`);e.add(l),s=r=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(s===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(s,i);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}At.exports={parse:or}});var zt=x((Dr,jt)=>{"use strict";var ar=m("events"),pe=m("http"),{Duplex:Ur}=m("stream"),{createHash:lr}=m("crypto"),Ft=Ie(),U=Z(),fr=Wt(),hr=_e(),{GUID:cr,kWebSocket:ur}=T(),dr=/^[+/0-9A-Za-z]{22}==$/,qt=0,Gt=1,$t=2,We=class extends ar{constructor(e,s){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:hr,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=pe.createServer((r,i)=>{let n=pe.STATUS_CODES[426];i.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),i.end(n)}),this._server.listen(e.port,e.host,e.backlog,s)):e.server&&(this._server=e.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=_r(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,n,o)=>{this.handleUpgrade(i,n,o,r)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=qt}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===$t){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(te,this);return}if(e&&this.once("close",e),this._state!==Gt)if(this._state=Gt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(te,this):process.nextTick(te,this);else{let s=this._server;this._removeListeners(),this._removeListeners=this._server=null,s.close(()=>{te(this)})}}shouldHandle(e){if(this.options.path){let s=e.url.indexOf("?");if((s!==-1?e.url.slice(0,s):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,s,r,i){s.on("error",Vt);let n=e.headers["sec-websocket-key"],o=e.headers.upgrade,l=+e.headers["sec-websocket-version"];if(e.method!=="GET"){D(this,e,s,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){D(this,e,s,400,"Invalid Upgrade header");return}if(n===void 0||!dr.test(n)){D(this,e,s,400,"Missing or invalid Sec-WebSocket-Key header");return}if(l!==13&&l!==8){D(this,e,s,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){se(s,400);return}let f=e.headers["sec-websocket-protocol"],a=new Set;if(f!==void 0)try{a=fr.parse(f)}catch{D(this,e,s,400,"Invalid Sec-WebSocket-Protocol header");return}let h=e.headers["sec-websocket-extensions"],c={};if(this.options.perMessageDeflate&&h!==void 0){let _=new U(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let g=Ft.parse(h);g[U.extensionName]&&(_.accept(g[U.extensionName]),c[U.extensionName]=_)}catch{D(this,e,s,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let _={origin:e.headers[`${l===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(_,(g,p,u,S)=>{if(!g)return se(s,p||401,u,S);this.completeUpgrade(c,n,a,e,s,r,i)});return}if(!this.options.verifyClient(_))return se(s,401)}this.completeUpgrade(c,n,a,e,s,r,i)}completeUpgrade(e,s,r,i,n,o,l){if(!n.readable||!n.writable)return n.destroy();if(n[ur])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>qt)return se(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${lr("sha1").update(s+cr).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(r.size){let c=this.options.handleProtocols?this.options.handleProtocols(r,i):r.values().next().value;c&&(a.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[U.extensionName]){let c=e[U.extensionName].params,_=Ft.format({[U.extensionName]:[c]});a.push(`Sec-WebSocket-Extensions: ${_}`),h._extensions=e}this.emit("headers",a,i),n.write(a.concat(`\r
|
|
2
3
|
`).join(`\r
|
|
3
4
|
`)),n.removeListener("error",Vt),h.setSocket(n,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(h),h.on("close",()=>{this.clients.delete(h),this._shouldEmitClose&&!this.clients.size&&process.nextTick(te,this)})),l(h,i)}};jt.exports=We;function _r(t,e){for(let s of Object.keys(e))t.on(s,e[s]);return function(){for(let r of Object.keys(e))t.removeListener(r,e[r])}}function te(t){t._state=$t,t.emit("close")}function Vt(){this.destroy()}function se(t,e,s,r){s=s||pe.STATUS_CODES[e],r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(s),...r},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${pe.STATUS_CODES[e]}\r
|
|
4
5
|
`+Object.keys(r).map(i=>`${i}: ${r[i]}`).join(`\r
|