// src/index.ts
import { decode } from "@reifydb/core";
import { decode as decode2 } from "@reifydb/core";
function transform_to_value_instances(result) {
  if (result === null || result === void 0) return result;
  if (typeof result !== "object") return result;
  if (Array.isArray(result)) {
    return result.map(transform_to_value_instances);
  }
  const obj = result;
  if ("type" in obj && "value" in obj && Object.keys(obj).length === 2) {
    return decode(obj);
  }
  const transformed = {};
  for (const [key, value] of Object.entries(obj)) {
    transformed[key] = transform_to_value_instances(value);
  }
  return transformed;
}
var WasmDB = class {
  db;
  constructor(db) {
    this.db = db;
  }
  admin(rql) {
    return transform_to_value_instances(this.db.admin(rql));
  }
  admin_with_params(rql, params) {
    return transform_to_value_instances(this.db.adminWithParams(rql, params));
  }
  command(rql) {
    return transform_to_value_instances(this.db.command(rql));
  }
  command_with_params(rql, params) {
    return transform_to_value_instances(this.db.commandWithParams(rql, params));
  }
  query(rql) {
    return transform_to_value_instances(this.db.query(rql));
  }
  query_with_params(rql, params) {
    return transform_to_value_instances(this.db.queryWithParams(rql, params));
  }
  login_with_password(identifier, password) {
    const raw = this.db.loginWithPassword(identifier, password);
    const result = { token: raw.token, identity: raw.identity };
    raw.free();
    return result;
  }
  login_with_token(token) {
    const raw = this.db.loginWithToken(token);
    const result = { token: raw.token, identity: raw.identity };
    raw.free();
    return result;
  }
  logout() {
    this.db.logout();
  }
  free() {
    this.db.free();
  }
};
async function create_wasm_db() {
  const mod = await import("../wasm/reifydb_webassembly.js");
  return new WasmDB(new mod.WasmDB());
}
export {
  WasmDB,
  create_wasm_db,
  decode2 as decode,
  transform_to_value_instances
};
//# sourceMappingURL=index.js.map