{"version":3,"sources":["../src/base.ts","../src/errors.ts"],"sourcesContent":["import { query as queryTemplate } from './templating.js'\nimport { parseDescribeStatementResults, parseResults } from './parse.js'\nimport {\n  type Serializer,\n  type Parser,\n  serializers,\n  parsers,\n  arraySerializer,\n  arrayParser,\n} from './types.js'\nimport type {\n  DebugLevel,\n  PGliteInterface,\n  Results,\n  Transaction,\n  QueryOptions,\n  ExecProtocolOptions,\n  ExecProtocolResult,\n  DescribeQueryResult,\n  ExecProtocolOptionsStream,\n} from './interface.js'\n\nimport { serialize as serializeProtocol } from '@electric-sql/pg-protocol'\nimport {\n  RowDescriptionMessage,\n  ParameterDescriptionMessage,\n  DatabaseError,\n  BackendMessage,\n} from '@electric-sql/pg-protocol/messages'\nimport { makePGliteError } from './errors.js'\n\nexport abstract class BasePGlite\n  implements Pick<PGliteInterface, 'query' | 'sql' | 'exec' | 'transaction'>\n{\n  serializers: Record<number | string, Serializer> = { ...serializers }\n  parsers: Record<number | string, Parser> = { ...parsers }\n  #arrayTypesInitialized = false\n\n  // # Abstract properties:\n  abstract debug: DebugLevel\n\n  // # Private properties:\n  #inTransaction = false\n\n  // # Abstract methods:\n\n  /**\n   * Execute a postgres wire protocol message\n   * @param message The postgres wire protocol message to execute\n   * @returns The result of the query\n   */\n  abstract execProtocol(\n    message: Uint8Array,\n    { syncToFs, onNotice }: ExecProtocolOptions,\n  ): Promise<ExecProtocolResult>\n\n  /**\n   * Execute a postgres wire protocol message\n   * @param message The postgres wire protocol message to execute\n   * @returns The parsed results of the query\n   */\n  abstract execProtocolStream(\n    message: Uint8Array,\n    { syncToFs, onNotice }: ExecProtocolOptions,\n  ): Promise<BackendMessage[]>\n\n  /**\n   * Execute a postgres wire protocol message directly without wrapping the response.\n   * Only use if `execProtocol()` doesn't suite your needs.\n   *\n   * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,\n   * transactions, and notification listeners. Only use if you need to bypass these wrappers and\n   * don't intend to use the above features.\n   *\n   * @param message The postgres wire protocol message to execute\n   * @returns The direct message data response produced by Postgres\n   */\n  abstract execProtocolRaw(\n    message: Uint8Array,\n    { syncToFs }: ExecProtocolOptions,\n  ): Promise<Uint8Array>\n\n  /**\n   * Execute a postgres wire protocol message directly without wrapping the response.\n   * Only use if `execProtocol()` doesn't suite your needs.\n   *\n   * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,\n   * transactions, and notification listeners. Only use if you need to bypass these wrappers and\n   * don't intend to use the above features.\n   *\n   * @param message The postgres wire protocol message to execute\n   * @param options.onRawData Callback to receive streaming data\n   */\n  abstract execProtocolRawStream(\n    message: Uint8Array,\n    { syncToFs, onRawData }: ExecProtocolOptionsStream,\n  ): Promise<void>\n\n  /**\n   * Sync the database to the filesystem\n   * @returns Promise that resolves when the database is synced to the filesystem\n   */\n  abstract syncToFs(): Promise<void>\n\n  /**\n   * Handle a file attached to the current query\n   * @param file The file to handle\n   */\n  abstract _handleBlob(blob?: File | Blob): Promise<void>\n\n  /**\n   * Get the written file\n   */\n  abstract _getWrittenBlob(): Promise<File | Blob | undefined>\n\n  /**\n   * Cleanup the current file\n   */\n  abstract _cleanupBlob(): Promise<void>\n\n  abstract _checkReady(): Promise<void>\n  abstract _runExclusiveQuery<T>(fn: () => Promise<T>): Promise<T>\n  abstract _runExclusiveTransaction<T>(fn: () => Promise<T>): Promise<T>\n\n  /**\n   * Listen for notifications on a channel\n   */\n  abstract listen(\n    channel: string,\n    callback: (payload: string) => void,\n    tx?: Transaction,\n  ): Promise<(tx?: Transaction) => Promise<void>>\n\n  // # Concrete implementations:\n\n  /**\n   * Initialize the array types\n   * The oid if the type of an element and the typarray is the oid of the type of the\n   * array.\n   * We extract these from the database then create the serializers/parsers for\n   * each type.\n   * This should be called at the end of #init() in the implementing class.\n   */\n  async _initArrayTypes({ force = false } = {}) {\n    if (this.#arrayTypesInitialized && !force) return\n    this.#arrayTypesInitialized = true\n\n    const types = await this.query<{ oid: number; typarray: number }>(`\n      SELECT b.oid, b.typarray\n      FROM pg_catalog.pg_type a\n      LEFT JOIN pg_catalog.pg_type b ON b.oid = a.typelem\n      WHERE a.typcategory = 'A'\n      GROUP BY b.oid, b.typarray\n      ORDER BY b.oid\n    `)\n\n    for (const type of types.rows) {\n      this.serializers[type.typarray] = (x) =>\n        arraySerializer(x, this.serializers[type.oid], type.typarray)\n      this.parsers[type.typarray] = (x) =>\n        arrayParser(x, this.parsers[type.oid], type.typarray)\n    }\n  }\n\n  async #execProtocolNoSync(\n    message: Uint8Array,\n    options: ExecProtocolOptions = {},\n  ): Promise<BackendMessage[]> {\n    const results = await this.execProtocolStream(message, {\n      ...options,\n      syncToFs: false,\n    })\n\n    return results\n  }\n\n  /**\n   * Re-syncs the array types from the database\n   * This is useful if you add a new type to the database and want to use it, otherwise pglite won't recognize it.\n   */\n  async refreshArrayTypes() {\n    await this._initArrayTypes({ force: true })\n  }\n\n  /**\n   * Execute a single SQL statement\n   * This uses the \"Extended Query\" postgres wire protocol message.\n   * @param query The query to execute\n   * @param params Optional parameters for the query\n   * @returns The result of the query\n   */\n  async query<T>(\n    query: string,\n    params?: any[],\n    options?: QueryOptions,\n  ): Promise<Results<T>> {\n    await this._checkReady()\n    // We wrap the public query method in the transaction mutex to ensure that\n    // only one query can be executed at a time and not concurrently with a\n    // transaction.\n    return await this._runExclusiveTransaction(async () => {\n      return await this.#runQuery<T>(query, params, options)\n    })\n  }\n\n  /**\n   * Execute a single SQL statement like with {@link PGlite.query}, but with a\n   * templated statement where template values will be treated as parameters.\n   *\n   * You can use helpers from `/template` to further format the query with\n   * identifiers, raw SQL, and nested statements.\n   *\n   * This uses the \"Extended Query\" postgres wire protocol message.\n   *\n   * @param query The query to execute with parameters as template values\n   * @returns The result of the query\n   *\n   * @example\n   * ```ts\n   * const results = await db.sql`SELECT * FROM ${identifier`foo`} WHERE id = ${id}`\n   * ```\n   */\n  async sql<T>(\n    sqlStrings: TemplateStringsArray,\n    ...params: any[]\n  ): Promise<Results<T>> {\n    const { query, params: actualParams } = queryTemplate(sqlStrings, ...params)\n    return await this.query(query, actualParams)\n  }\n\n  /**\n   * Execute a SQL query, this can have multiple statements.\n   * This uses the \"Simple Query\" postgres wire protocol message.\n   * @param query The query to execute\n   * @returns The result of the query\n   */\n  async exec(query: string, options?: QueryOptions): Promise<Array<Results>> {\n    await this._checkReady()\n    // We wrap the public exec method in the transaction mutex to ensure that\n    // only one query can be executed at a time and not concurrently with a\n    // transaction.\n    return await this._runExclusiveTransaction(async () => {\n      return await this.#runExec(query, options)\n    })\n  }\n\n  /**\n   * Internal method to execute a query\n   * Not protected by the transaction mutex, so it can be used inside a transaction\n   * @param query The query to execute\n   * @param params Optional parameters for the query\n   * @returns The result of the query\n   */\n  async #runQuery<T>(\n    query: string,\n    params: any[] = [],\n    options?: QueryOptions,\n  ): Promise<Results<T>> {\n    return await this._runExclusiveQuery(async () => {\n      // We need to parse, bind and execute a query with parameters\n      this.#log('runQuery', query, params, options)\n      await this._handleBlob(options?.blob)\n\n      let results = []\n\n      try {\n        const parseResults = await this.#execProtocolNoSync(\n          serializeProtocol.parse({ text: query, types: options?.paramTypes }),\n          options,\n        )\n\n        const dataTypeIDs = parseDescribeStatementResults(\n          await this.#execProtocolNoSync(\n            serializeProtocol.describe({ type: 'S' }),\n            options,\n          ),\n        )\n\n        const values = params.map((param, i) => {\n          const oid = dataTypeIDs[i]\n          if (param === null || param === undefined) {\n            return null\n          }\n          const serialize = options?.serializers?.[oid] ?? this.serializers[oid]\n          if (serialize) {\n            return serialize(param)\n          } else {\n            return param.toString()\n          }\n        })\n\n        results = [\n          ...parseResults,\n          ...(await this.#execProtocolNoSync(\n            serializeProtocol.bind({\n              values,\n            }),\n            options,\n          )),\n          ...(await this.#execProtocolNoSync(\n            serializeProtocol.describe({ type: 'P' }),\n            options,\n          )),\n          ...(await this.#execProtocolNoSync(\n            serializeProtocol.execute({}),\n            options,\n          )),\n        ]\n      } catch (e) {\n        if (e instanceof DatabaseError) {\n          const pgError = makePGliteError({ e, options, params, query })\n          throw pgError\n        }\n        throw e\n      } finally {\n        results.push(\n          ...(await this.#execProtocolNoSync(\n            serializeProtocol.sync(),\n            options,\n          )),\n        )\n      }\n\n      await this._cleanupBlob()\n      if (!this.#inTransaction) {\n        await this.syncToFs()\n      }\n      const blob = await this._getWrittenBlob()\n      return parseResults(results, this.parsers, options, blob)[0] as Results<T>\n    })\n  }\n\n  /**\n   * Internal method to execute a query\n   * Not protected by the transaction mutex, so it can be used inside a transaction\n   * @param query The query to execute\n   * @param params Optional parameters for the query\n   * @returns The result of the query\n   */\n  async #runExec(\n    query: string,\n    options?: QueryOptions,\n  ): Promise<Array<Results>> {\n    return await this._runExclusiveQuery(async () => {\n      // No params so we can just send the query\n      this.#log('runExec', query, options)\n      await this._handleBlob(options?.blob)\n      let results = []\n      try {\n        results = await this.#execProtocolNoSync(\n          serializeProtocol.query(query),\n          options,\n        )\n      } catch (e) {\n        if (e instanceof DatabaseError) {\n          const pgError = makePGliteError({\n            e,\n            options,\n            params: undefined,\n            query,\n          })\n          throw pgError\n        }\n        throw e\n      } finally {\n        results.push(\n          ...(await this.#execProtocolNoSync(\n            serializeProtocol.sync(),\n            options,\n          )),\n        )\n      }\n      this._cleanupBlob()\n      if (!this.#inTransaction) {\n        await this.syncToFs()\n      }\n      const blob = await this._getWrittenBlob()\n      return parseResults(\n        results,\n        this.parsers,\n        options,\n        blob,\n      ) as Array<Results>\n    })\n  }\n\n  /**\n   * Describe a query\n   * @param query The query to describe\n   * @returns A description of the result types for the query\n   */\n  async describeQuery(\n    query: string,\n    options?: QueryOptions,\n  ): Promise<DescribeQueryResult> {\n    let messages = []\n    try {\n      await this.#execProtocolNoSync(\n        serializeProtocol.parse({ text: query, types: options?.paramTypes }),\n        options,\n      )\n\n      messages = await this.#execProtocolNoSync(\n        serializeProtocol.describe({ type: 'S' }),\n        options,\n      )\n    } catch (e) {\n      if (e instanceof DatabaseError) {\n        const pgError = makePGliteError({\n          e,\n          options,\n          params: undefined,\n          query,\n        })\n        throw pgError\n      }\n      throw e\n    } finally {\n      messages.push(\n        ...(await this.#execProtocolNoSync(serializeProtocol.sync(), options)),\n      )\n    }\n\n    const paramDescription = messages.find(\n      (msg): msg is ParameterDescriptionMessage =>\n        msg.name === 'parameterDescription',\n    )\n    const resultDescription = messages.find(\n      (msg): msg is RowDescriptionMessage => msg.name === 'rowDescription',\n    )\n\n    const queryParams =\n      paramDescription?.dataTypeIDs.map((dataTypeID) => ({\n        dataTypeID,\n        serializer: this.serializers[dataTypeID],\n      })) ?? []\n\n    const resultFields =\n      resultDescription?.fields.map((field) => ({\n        name: field.name,\n        dataTypeID: field.dataTypeID,\n        parser: this.parsers[field.dataTypeID],\n      })) ?? []\n\n    return { queryParams, resultFields }\n  }\n\n  /**\n   * Execute a transaction\n   * @param callback A callback function that takes a transaction object\n   * @returns The result of the transaction\n   */\n  async transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T> {\n    await this._checkReady()\n    return await this._runExclusiveTransaction(async () => {\n      await this.#runExec('BEGIN')\n      this.#inTransaction = true\n\n      // Once a transaction is closed, we throw an error if it's used again\n      let closed = false\n      const checkClosed = () => {\n        if (closed) {\n          throw new Error('Transaction is closed')\n        }\n      }\n\n      const tx: Transaction = {\n        query: async <T>(\n          query: string,\n          params?: any[],\n          options?: QueryOptions,\n        ): Promise<Results<T>> => {\n          checkClosed()\n          return await this.#runQuery(query, params, options)\n        },\n        sql: async <T>(\n          sqlStrings: TemplateStringsArray,\n          ...params: any[]\n        ): Promise<Results<T>> => {\n          checkClosed()\n          const { query, params: actualParams } = queryTemplate(\n            sqlStrings,\n            ...params,\n          )\n          return await this.#runQuery(query, actualParams)\n        },\n        exec: async (\n          query: string,\n          options?: QueryOptions,\n        ): Promise<Array<Results>> => {\n          checkClosed()\n          return await this.#runExec(query, options)\n        },\n        rollback: async () => {\n          checkClosed()\n          // Rollback and set the closed flag to prevent further use of this\n          // transaction\n          await this.#runExec('ROLLBACK')\n          closed = true\n        },\n        listen: async (\n          channel: string,\n          callback: (payload: string) => void,\n        ) => {\n          checkClosed()\n          return await this.listen(channel, callback, tx)\n        },\n        get closed() {\n          return closed\n        },\n      }\n\n      try {\n        const result = await callback(tx)\n        if (!closed) {\n          closed = true\n          await this.#runExec('COMMIT')\n        }\n        this.#inTransaction = false\n        return result\n      } catch (e) {\n        if (!closed) {\n          closed = true\n          await this.#runExec('ROLLBACK')\n        }\n        this.#inTransaction = false\n        throw e\n      }\n    })\n  }\n\n  /**\n   * Run a function exclusively, no other transactions or queries will be allowed\n   * while the function is running.\n   * This is useful when working with the execProtocol methods as they are not blocked,\n   * and do not block the locks used by transactions and queries.\n   * @param fn The function to run\n   * @returns The result of the function\n   */\n  async runExclusive<T>(fn: () => Promise<T>): Promise<T> {\n    return await this._runExclusiveQuery(fn)\n  }\n\n  /**\n   * Internal log function\n   */\n  #log(...args: any[]) {\n    if (this.debug > 0) {\n      console.log(...args)\n    }\n  }\n}\n","import { DatabaseError } from '@electric-sql/pg-protocol/messages'\nimport { QueryOptions } from './interface'\n\nexport interface PGliteError extends DatabaseError {\n  query: string | undefined\n  params: any[] | undefined\n  queryOptions: QueryOptions | undefined\n}\n\nexport function makePGliteError(data: {\n  e: DatabaseError\n  query: string\n  params: any[] | undefined\n  options: QueryOptions | undefined\n}) {\n  const pgError = data.e as PGliteError\n  pgError.query = data.query\n  pgError.params = data.params\n  pgError.queryOptions = data.options\n  return pgError\n}\n"],"mappings":"qMAAAA,ICAAC,IASO,SAASC,EAAgBC,EAK7B,CACD,IAAMC,EAAUD,EAAK,EACrB,OAAAC,EAAQ,MAAQD,EAAK,MACrBC,EAAQ,OAASD,EAAK,OACtBC,EAAQ,aAAeD,EAAK,QACrBC,CACT,CDpBA,IAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EA+BsBC,EAAf,KAEP,CAFO,cAAAC,EAAA,KAAAN,GAGL,iBAAmD,CAAE,GAAGO,CAAY,EACpE,aAA2C,CAAE,GAAGC,CAAQ,EACxDF,EAAA,KAAA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AAQ,eACZc,EACAE,EACyB,CACzB,OAAO,MAAM,KAAK,mBAAmB,SAAY,CAE/CC,EAAA,KAAKpB,EAAAI,GAAL,UAAU,UAAWa,EAAOE,GAC5B,MAAM,KAAK,YAAYA,GAAS,IAAI,EACpC,IAAIwB,EAAU,CAAC,EACf,GAAI,CACFA,EAAU,MAAMvB,EAAA,KAAKpB,EAAAC,GAAL,UACduB,EAAkB,MAAMP,CAAK,EAC7BE,EAEJ,OAASM,EAAG,CACV,MAAIA,aAAaC,EACCC,EAAgB,CAC9B,EAAAF,EACA,QAAAN,EACA,OAAQ,OACR,MAAAF,CACF,CAAC,EAGGQ,CACR,QAAE,CACAkB,EAAQ,KACN,GAAI,MAAMvB,EAAA,KAAKpB,EAAAC,GAAL,UACRuB,EAAkB,KAAK,EACvBL,EAEJ,CACF,CACA,KAAK,aAAa,EACbT,EAAA,KAAKX,IACR,MAAM,KAAK,SAAS,EAEtB,IAAMoD,EAAO,MAAM,KAAK,gBAAgB,EACxC,OAAOP,EACLD,EACA,KAAK,QACLxB,EACAgC,CACF,CACF,CAAC,CACH,EAkKA/C,EAAI,YAAIgD,EAAa,CACf,KAAK,MAAQ,GACf,QAAQ,IAAI,GAAGA,CAAI,CAEvB","names":["init_esm_shims","init_esm_shims","makePGliteError","data","pgError","_arrayTypesInitialized","_inTransaction","_BasePGlite_instances","execProtocolNoSync_fn","runQuery_fn","runExec_fn","log_fn","BasePGlite","__privateAdd","serializers","parsers","force","__privateGet","__privateSet","types","type","x","arraySerializer","arrayParser","query","params","options","__privateMethod","sqlStrings","actualParams","messages","serialize","e","DatabaseError","makePGliteError","paramDescription","msg","resultDescription","queryParams","dataTypeID","resultFields","field","callback","closed","checkClosed","tx","channel","result","fn","message","results","parseResults","dataTypeIDs","parseDescribeStatementResults","values","param","i","oid","blob","args"]}