{"version":3,"file":"session.cjs","names":["MySqlAsyncSession","entityKind","NoopLogger","NoopCache","MySqlAsyncPreparedQuery"],"sources":["../../src/mysql-proxy/session.ts"],"sourcesContent":["import type { FieldPacket, ResultSetHeader } from 'mysql2/promise';\nimport { type Cache, NoopCache } from '~/cache/core/index.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport { MySqlAsyncPreparedQuery, MySqlAsyncSession, type MySqlAsyncTransaction } from '~/mysql-core/async/session.ts';\nimport type { MySqlDialect } from '~/mysql-core/dialect.ts';\nimport type {\n\tAnyMySqlMapper,\n\tMySqlPreparedQueryConfig,\n\tMySqlQueryResultHKT,\n\tMySqlTransactionConfig,\n} from '~/mysql-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport type { Query } from '~/sql/sql.ts';\nimport type { RemoteCallback } from './driver.ts';\n\nexport type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];\n\nexport interface MySqlRemoteSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport class MySqlRemoteSession<\n\tTRelations extends AnyRelations,\n> extends MySqlAsyncSession<\n\tMySqlRemoteQueryResultHKT,\n\tTRelations\n> {\n\tstatic override readonly [entityKind]: string = 'MySqlRemoteSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: RemoteCallback,\n\t\tdialect: MySqlDialect,\n\t\tprivate relations: TRelations,\n\t\tprivate options: MySqlRemoteSessionOptions,\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache ?? new NoopCache();\n\t}\n\n\tprepareQuery<T extends MySqlPreparedQueryConfig>(\n\t\tquery: Query,\n\t\tmode: 'arrays' | 'objects' | 'raw',\n\t\tmapper?: AnyMySqlMapper,\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): MySqlAsyncPreparedQuery<T> {\n\t\tconst executor = async (params: any[] = []) => {\n\t\t\tconst raw = this.client(query.sql, params, mode === 'arrays' ? 'all' : 'execute');\n\n\t\t\tif (mode === 'objects') return raw.then(({ rows }) => rows[0]);\n\t\t\tif (mode === 'arrays' || !mapper) return raw.then(({ rows }) => rows);\n\t\t\treturn raw.then(({ rows, insertId, affectedRows }) => ({\n\t\t\t\t// Backwards compat with old implementation (types remain unaffected)\n\t\t\t\tinsertId: insertId ?? rows[0]?.insertId,\n\t\t\t\taffectedRows: affectedRows ?? rows[0]?.affectedRows,\n\t\t\t}));\n\t\t};\n\n\t\treturn new MySqlAsyncPreparedQuery(\n\t\t\texecutor,\n\t\t\tundefined,\n\t\t\tquery,\n\t\t\tmapper,\n\t\t\tmode,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\t_transaction: (tx: MySqlAsyncTransaction<MySqlRemoteQueryResultHKT, TRelations>) => Promise<T>,\n\t\t_config?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\tthrow new Error('Transactions are not supported by the MySql Proxy driver');\n\t}\n}\n\nexport interface MySqlRemoteQueryResultHKT extends MySqlQueryResultHKT {\n\ttype: MySqlRawQueryResult;\n}\n"],"mappings":";;;;;;;;AAyBA,IAAa,qBAAb,cAEUA,gDAGR;CACD,QAA0BC,0BAAsB;CAEhD,AAAQ;CACR,AAAQ;CAER,YACC,AAAQ,QACR,SACA,AAAQ,WACR,AAAQ,SACP;AACD,QAAM,QAAQ;EALN;EAEA;EACA;AAGR,OAAK,SAAS,QAAQ,UAAU,IAAIC,wBAAY;AAChD,OAAK,QAAQ,QAAQ,SAAS,IAAIC,iCAAW;;CAG9C,aACC,OACA,MACA,QACA,eAIA,aAC6B;EAC7B,MAAM,WAAW,OAAO,SAAgB,EAAE,KAAK;GAC9C,MAAM,MAAM,KAAK,OAAO,MAAM,KAAK,QAAQ,SAAS,WAAW,QAAQ,UAAU;AAEjF,OAAI,SAAS,UAAW,QAAO,IAAI,MAAM,EAAE,WAAW,KAAK,GAAG;AAC9D,OAAI,SAAS,YAAY,CAAC,OAAQ,QAAO,IAAI,MAAM,EAAE,WAAW,KAAK;AACrE,UAAO,IAAI,MAAM,EAAE,MAAM,UAAU,oBAAoB;IAEtD,UAAU,YAAY,KAAK,IAAI;IAC/B,cAAc,gBAAgB,KAAK,IAAI;IACvC,EAAE;;AAGJ,SAAO,IAAIC,sDACV,UACA,QACA,OACA,QACA,MACA,KAAK,QACL,KAAK,OACL,eACA,YACA;;CAGF,MAAe,YACd,cACA,SACa;AACb,QAAM,IAAI,MAAM,2DAA2D"}