@neetru/sdk 2.3.2 → 2.3.4

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/index.mjs CHANGED
@@ -5368,21 +5368,46 @@ var MockDb = class {
5368
5368
  return ref;
5369
5369
  }
5370
5370
  /**
5371
- * Implementa SQL in-memory via `pg-mem` + `drizzle-orm/node-postgres`.
5371
+ * Implementa SQL in-memory para testes preferência: `@electric-sql/pglite`
5372
+ * + `drizzle-orm/pglite`; fallback: `pg-mem` + `drizzle-orm/node-postgres`
5373
+ * com strip interceptor.
5372
5374
  *
5373
- * bug_a7f2ae25fda54129b52b6dd55aaa6050 (HIGH 26/05): antes lançava
5374
- * `db_unavailable` sempre, bloqueando vitest server-side dos consumers
5375
- * que refatoraram pra `client.db.sql()`. Agora carrega `pg-mem` lazy +
5376
- * cria `NodePgDatabase` Drizzle apontando pra DB in-memory.
5375
+ * bug_6bae8674461f4600809e2f9de13c6043 (HIGH 26/05): fix anterior (2.3.3)
5376
+ * teve efeito INVERSO. Injetar `pool.types.getTypeParser` fez drizzle-orm
5377
+ * passar `query.types.getTypeParser` pro pg-mem, que tem guard interno
5378
+ * `if (query.types?.getTypeParser) throw NotSupported`. Ou seja: presença
5379
+ * de getTypeParser é o gatilho do erro — não ausência.
5377
5380
  *
5378
- * Requer `pg-mem`, `drizzle-orm` e `pg` como devDependencies do consumer
5379
- * (instale com `npm install -D pg-mem drizzle-orm pg`). Se ausentes, joga
5380
- * `db_unavailable` com mensagem clara.
5381
+ * Solução A (pglite, preferida): `@electric-sql/pglite` é WASM-Postgres
5382
+ * nativo sem adapter pg-mem, sem esse conflito de tipos.
5383
+ * Solução B (fallback pg-mem): strip interceptor no pool.query que deleta
5384
+ * `types.getTypeParser` do objeto de query ANTES do pg-mem ver. Compat com
5385
+ * consumers que só têm pg-mem nas devDeps.
5381
5386
  *
5382
- * Use `options.initSql` pra criar tabelas no test setup sem isso o orm
5383
- * funciona mas qualquer SELECT/INSERT em tabela inexistente vai falhar.
5387
+ * Use `options.initSql` pra rodar DDL no setup (CREATE TABLE etc).
5384
5388
  */
5385
5389
  async sql(schema, options) {
5390
+ const ddls = options?.initSql ? Array.isArray(options.initSql) ? options.initSql : [options.initSql] : [];
5391
+ try {
5392
+ const pglitePkg = await import('@electric-sql/pglite');
5393
+ const drizzlePglitePkg = await import('drizzle-orm/pglite');
5394
+ const pglite = await pglitePkg.PGlite.create();
5395
+ for (const ddl of ddls) {
5396
+ await pglite.query(ddl);
5397
+ }
5398
+ const pgliteOrm = drizzlePglitePkg.drizzle(pglite, { schema });
5399
+ const ormAsNode = pgliteOrm;
5400
+ return {
5401
+ orm: ormAsNode,
5402
+ async transaction(fn, _opts) {
5403
+ return await pgliteOrm.transaction(fn);
5404
+ },
5405
+ async close() {
5406
+ if (!pglite.closed) await pglite.close();
5407
+ }
5408
+ };
5409
+ } catch (_pgliteErr) {
5410
+ }
5386
5411
  let pgMemMod;
5387
5412
  let drizzlePg;
5388
5413
  try {
@@ -5391,12 +5416,11 @@ var MockDb = class {
5391
5416
  } catch {
5392
5417
  throw new NeetruDbError(
5393
5418
  "db_unavailable",
5394
- "[MockDb] sql() requer pg-mem + drizzle-orm + pg como devDependencies do consumer. Rode: npm install -D pg-mem drizzle-orm pg."
5419
+ "[MockDb] sql() requer @electric-sql/pglite OU pg-mem + drizzle-orm + pg como devDependencies. Preferido: npm install -D @electric-sql/pglite drizzle-orm. Alternativo: npm install -D pg-mem drizzle-orm pg."
5395
5420
  );
5396
5421
  }
5397
5422
  const memDb = pgMemMod.newDb({ noAstCoverageCheck: true });
5398
- if (options?.initSql) {
5399
- const ddls = Array.isArray(options.initSql) ? options.initSql : [options.initSql];
5423
+ if (ddls.length > 0) {
5400
5424
  for (const ddl of ddls) {
5401
5425
  memDb.public.none(ddl);
5402
5426
  }
@@ -5404,6 +5428,17 @@ var MockDb = class {
5404
5428
  const adapters = memDb.adapters.createPg();
5405
5429
  const PoolCtor = adapters.Pool;
5406
5430
  const pool = new PoolCtor();
5431
+ const origQuery = pool.query.bind(pool);
5432
+ pool.query = (q, ...rest) => {
5433
+ if (q !== null && typeof q === "object") {
5434
+ const queryObj = q;
5435
+ const types = queryObj["types"];
5436
+ if (types !== null && typeof types === "object" && "getTypeParser" in types) {
5437
+ delete types["getTypeParser"];
5438
+ }
5439
+ }
5440
+ return origQuery(q, ...rest);
5441
+ };
5407
5442
  const orm = drizzlePg.drizzle(pool, { schema });
5408
5443
  return {
5409
5444
  orm,