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