@neetru/sdk 3.2.3 → 3.4.0
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/CHANGELOG.md +45 -0
- package/dist/ai.cjs +229 -7
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +229 -7
- package/dist/ai.mjs.map +1 -1
- package/dist/auth.cjs +581 -18
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +581 -18
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.cjs +19 -3
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +19 -3
- package/dist/catalog.mjs.map +1 -1
- package/dist/checkout.cjs +19 -3
- package/dist/checkout.cjs.map +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +19 -3
- package/dist/checkout.mjs.map +1 -1
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +193 -8
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +193 -9
- package/dist/db.mjs.map +1 -1
- package/dist/entitlements.cjs +19 -3
- package/dist/entitlements.cjs.map +1 -1
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +19 -3
- package/dist/entitlements.mjs.map +1 -1
- package/dist/errors.cjs +11 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +10 -1
- package/dist/errors.d.ts +10 -1
- package/dist/errors.mjs +11 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +582 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +582 -19
- package/dist/index.mjs.map +1 -1
- package/dist/mocks.cjs +87 -4
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +19 -1
- package/dist/mocks.d.ts +19 -1
- package/dist/mocks.mjs +87 -4
- package/dist/mocks.mjs.map +1 -1
- package/dist/notifications.cjs +19 -3
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +19 -3
- package/dist/notifications.mjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/support.cjs +117 -4
- package/dist/support.cjs.map +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs +117 -4
- package/dist/support.mjs.map +1 -1
- package/dist/telemetry.cjs +19 -3
- package/dist/telemetry.cjs.map +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +19 -3
- package/dist/telemetry.mjs.map +1 -1
- package/dist/{types-PzHvWMbV.d.cts → types-BoFSCHF_.d.cts} +185 -6
- package/dist/{types-iLDjiqqk.d.ts → types-DdJyqBy-.d.ts} +185 -6
- package/dist/usage.cjs +19 -3
- package/dist/usage.cjs.map +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +19 -3
- package/dist/usage.mjs.map +1 -1
- package/dist/webhooks.cjs +19 -3
- package/dist/webhooks.cjs.map +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +19 -3
- package/dist/webhooks.mjs.map +1 -1
- package/package.json +1 -1
package/dist/db.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { w as ConflictRecord, x as CreateOfflineDocumentsOptions, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, K as DbQuery, L as DbSqlLease, N as DbWhereFilter, P as FieldSentinel, Q as IncrementSentinel, V as NEETRU_SENTINEL_KEY, Y as NeetruDb, Z as NeetruDbDocuments, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a4 as NeetruSqlClient, ad as RealtimeTransport, ai as ServerTimestampSentinel, ak as SqlOptions, ap as SyncState, aG as WithFieldSentinels, aH as __resetDbIdWarningForTests, aK as createNeetruDb, aM as createRestSyncTransport, aO as getWebSocketRealtimeClient, aP as increment, aQ as isFieldSentinel, aR as isIncrementSentinel, aS as isServerTimestampSentinel, aT as serverTimestamp } from './types-BoFSCHF_.cjs';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.cjs';
|
package/dist/db.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { w as ConflictRecord, x as CreateOfflineDocumentsOptions, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, K as DbQuery, L as DbSqlLease, N as DbWhereFilter, P as FieldSentinel, Q as IncrementSentinel, V as NEETRU_SENTINEL_KEY, Y as NeetruDb, Z as NeetruDbDocuments, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a4 as NeetruSqlClient, ad as RealtimeTransport, ai as ServerTimestampSentinel, ak as SqlOptions, ap as SyncState, aG as WithFieldSentinels, aH as __resetDbIdWarningForTests, aK as createNeetruDb, aM as createRestSyncTransport, aO as getWebSocketRealtimeClient, aP as increment, aQ as isFieldSentinel, aR as isIncrementSentinel, aS as isServerTimestampSentinel, aT as serverTimestamp } from './types-DdJyqBy-.js';
|
|
2
2
|
import 'drizzle-orm/node-postgres';
|
|
3
3
|
import './errors.js';
|
package/dist/db.mjs
CHANGED
|
@@ -18,12 +18,22 @@ var init_errors = __esm({
|
|
|
18
18
|
code;
|
|
19
19
|
status;
|
|
20
20
|
requestId;
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Motivo semântico opcional propagado pelo Core no corpo do erro (campo
|
|
23
|
+
* `reason` no TOPO do body, fora de `error`). Usado principalmente pelo 503
|
|
24
|
+
* de lease de DB, onde `reason` discrimina o estado do ambiente
|
|
25
|
+
* (`suspended` | `archived` | `revoked` | `provisioning` | `degraded` |
|
|
26
|
+
* `no_route` | `expired`). Camadas superiores (ex.: `db/sql`) mapeiam isso
|
|
27
|
+
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
28
|
+
*/
|
|
29
|
+
reason;
|
|
30
|
+
constructor(code, message, status, requestId, reason) {
|
|
22
31
|
super(message);
|
|
23
32
|
this.name = "NeetruError";
|
|
24
33
|
this.code = code;
|
|
25
34
|
this.status = status;
|
|
26
35
|
this.requestId = requestId;
|
|
36
|
+
this.reason = reason;
|
|
27
37
|
Object.setPrototypeOf(this, _NeetruError.prototype);
|
|
28
38
|
}
|
|
29
39
|
};
|
|
@@ -229,16 +239,22 @@ async function httpRequest(config, opts) {
|
|
|
229
239
|
const body = await safeJson(res);
|
|
230
240
|
let code = statusToCode(res.status);
|
|
231
241
|
let message = `HTTP ${res.status}`;
|
|
232
|
-
|
|
242
|
+
let reason;
|
|
243
|
+
if (body && typeof body === "object") {
|
|
233
244
|
const errField = body.error;
|
|
234
245
|
if (typeof errField === "string") {
|
|
235
246
|
message = errField;
|
|
236
247
|
} else if (errField && typeof errField === "object") {
|
|
237
248
|
if (typeof errField.code === "string") code = errField.code;
|
|
238
249
|
if (typeof errField.message === "string") message = errField.message;
|
|
250
|
+
if (typeof errField.reason === "string") reason = errField.reason;
|
|
251
|
+
} else {
|
|
252
|
+
if (typeof body.code === "string") code = body.code;
|
|
253
|
+
if (typeof body.message === "string") message = body.message;
|
|
239
254
|
}
|
|
255
|
+
if (typeof body.reason === "string") reason = body.reason;
|
|
240
256
|
}
|
|
241
|
-
const err = new NeetruError(code, message, res.status, requestId);
|
|
257
|
+
const err = new NeetruError(code, message, res.status, requestId, reason);
|
|
242
258
|
lastError = err;
|
|
243
259
|
const isRetryable = RETRYABLE_CODES2.has(code);
|
|
244
260
|
if (isRetryable && attempt < maxRetries) {
|
|
@@ -365,6 +381,7 @@ var init_resilient_pool = __esm({
|
|
|
365
381
|
|
|
366
382
|
// src/db/sql/lease.ts
|
|
367
383
|
function hasConnectionChanged(oldLease, newLease) {
|
|
384
|
+
if (!oldLease) return true;
|
|
368
385
|
return oldLease.leaseId !== newLease.leaseId || oldLease.credentialVersion !== newLease.credentialVersion || oldLease.host !== newLease.host || oldLease.port !== newLease.port || oldLease.dbName !== newLease.dbName || oldLease.user !== newLease.user || oldLease.password !== newLease.password || oldLease.sslca !== newLease.sslca || oldLease.clientCert !== newLease.clientCert || oldLease.clientKey !== newLease.clientKey;
|
|
369
386
|
}
|
|
370
387
|
function mapPoolError(err) {
|
|
@@ -396,6 +413,10 @@ var init_lease = __esm({
|
|
|
396
413
|
RENEWAL_THRESHOLD = 0.8;
|
|
397
414
|
MIN_RENEWAL_DELAY_MS = 3e4;
|
|
398
415
|
SqlLeaseManager = class {
|
|
416
|
+
/**
|
|
417
|
+
* Lease atual. `null` no modo LAZY antes da 1ª query (o 1º lease é adiado —
|
|
418
|
+
* ver `_ensureInitialLease`). Após a 1ª aquisição, sempre não-nulo.
|
|
419
|
+
*/
|
|
399
420
|
_lease;
|
|
400
421
|
_pool;
|
|
401
422
|
_orm;
|
|
@@ -407,6 +428,12 @@ var init_lease = __esm({
|
|
|
407
428
|
* `_reactiveReLease`.
|
|
408
429
|
*/
|
|
409
430
|
_reLeaseInFlight = null;
|
|
431
|
+
/**
|
|
432
|
+
* Promessa da aquisição do LEASE INICIAL em voo (modo lazy) — coalesce as
|
|
433
|
+
* N primeiras queries concorrentes num único fetch. `null` quando não há
|
|
434
|
+
* aquisição inicial pendente. Ver `_ensureInitialLease`.
|
|
435
|
+
*/
|
|
436
|
+
_initInFlight = null;
|
|
410
437
|
_deps;
|
|
411
438
|
constructor(lease, pool, orm, deps) {
|
|
412
439
|
this._lease = lease;
|
|
@@ -416,7 +443,7 @@ var init_lease = __esm({
|
|
|
416
443
|
...deps,
|
|
417
444
|
now: deps.now ?? (() => Date.now())
|
|
418
445
|
};
|
|
419
|
-
this._scheduleRenewal();
|
|
446
|
+
if (this._lease) this._scheduleRenewal();
|
|
420
447
|
}
|
|
421
448
|
// ─── Superfície pública (NeetruSqlClient) ──────────────────────────────────
|
|
422
449
|
get orm() {
|
|
@@ -454,6 +481,7 @@ var init_lease = __esm({
|
|
|
454
481
|
* usa `MIN_RENEWAL_DELAY_MS` como fallback seguro.
|
|
455
482
|
*/
|
|
456
483
|
_calcRenewalDelayMs() {
|
|
484
|
+
if (!this._lease) return MIN_RENEWAL_DELAY_MS;
|
|
457
485
|
const expiresAtMs = Date.parse(this._lease.expiresAt);
|
|
458
486
|
if (!Number.isFinite(expiresAtMs)) return MIN_RENEWAL_DELAY_MS;
|
|
459
487
|
const now = this._deps.now();
|
|
@@ -477,6 +505,8 @@ var init_lease = __esm({
|
|
|
477
505
|
}
|
|
478
506
|
async _doRenew() {
|
|
479
507
|
if (this._closed) return;
|
|
508
|
+
const currentLease = this._lease;
|
|
509
|
+
if (!currentLease) return;
|
|
480
510
|
try {
|
|
481
511
|
const withDb = (o) => {
|
|
482
512
|
if (this._deps.database !== void 0) o.database = this._deps.database;
|
|
@@ -484,7 +514,7 @@ var init_lease = __esm({
|
|
|
484
514
|
};
|
|
485
515
|
let newLease;
|
|
486
516
|
try {
|
|
487
|
-
newLease = await this._deps.fetchLease(withDb({ leaseId:
|
|
517
|
+
newLease = await this._deps.fetchLease(withDb({ leaseId: currentLease.leaseId }));
|
|
488
518
|
} catch (renewErr) {
|
|
489
519
|
newLease = await this._deps.fetchLease(withDb({}));
|
|
490
520
|
}
|
|
@@ -544,6 +574,71 @@ var init_lease = __esm({
|
|
|
544
574
|
this._reLeaseInFlight = null;
|
|
545
575
|
}
|
|
546
576
|
}
|
|
577
|
+
// ─── Lease INICIAL lazy (motor de ambientes suspenso) ──────────────────────
|
|
578
|
+
/**
|
|
579
|
+
* Adquire o LEASE INICIAL sob demanda (modo lazy). Chamado pelo pool "adiado"
|
|
580
|
+
* (`createDeferredPool`) na 1ª query/transação — nunca no boot do módulo.
|
|
581
|
+
*
|
|
582
|
+
* Fluxo:
|
|
583
|
+
* 1. Se já há lease (`_lease != null`), devolve o pool REAL interno vigente
|
|
584
|
+
* (idempotente — chamadas após a 1ª aquisição são no-op de fetch).
|
|
585
|
+
* 2. Busca o 1º lease no Core (com `database` se houver — contrato C-H).
|
|
586
|
+
* 3. Cria o pool REAL e faz o swap no wrapper resiliente (`__neetruSwapInner`)
|
|
587
|
+
* pra que as queries seguintes passem direto pelo pool real.
|
|
588
|
+
* 4. Agenda a renovação proativa (só a partir daqui — antes não havia lease).
|
|
589
|
+
*
|
|
590
|
+
* Coalesce concorrência: N primeiras queries compartilham UM único fetch
|
|
591
|
+
* (`_initInFlight`). Se a aquisição FALHA (ex.: ambiente suspenso →
|
|
592
|
+
* `db_suspended`, ou Core fora → `db_unavailable`), o erro propaga pra query
|
|
593
|
+
* que a disparou e `_initInFlight` é limpo — a PRÓXIMA query re-tenta (o
|
|
594
|
+
* ambiente pode ter voltado). NÃO derruba o processo nem o import do módulo.
|
|
595
|
+
*/
|
|
596
|
+
async _ensureInitialLease() {
|
|
597
|
+
if (this._closed) {
|
|
598
|
+
throw new NeetruDbError(
|
|
599
|
+
"db_unavailable",
|
|
600
|
+
"SqlLeaseManager foi fechado \u2014 aquisi\xE7\xE3o de lease inicial abortada."
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
if (this._lease) {
|
|
604
|
+
return isResilientPool(this._pool) ? this._pool.__neetruGetInner() : this._pool;
|
|
605
|
+
}
|
|
606
|
+
if (this._initInFlight !== null) return this._initInFlight;
|
|
607
|
+
const run = (async () => {
|
|
608
|
+
let lease;
|
|
609
|
+
try {
|
|
610
|
+
lease = this._deps.database !== void 0 ? await this._deps.fetchLease({ database: this._deps.database }) : await this._deps.fetchLease();
|
|
611
|
+
} catch (err) {
|
|
612
|
+
if (err instanceof NeetruDbError) throw err;
|
|
613
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
614
|
+
throw new NeetruDbError("db_unavailable", `Falha ao obter lease inicial: ${msg}`);
|
|
615
|
+
}
|
|
616
|
+
let realPool;
|
|
617
|
+
try {
|
|
618
|
+
realPool = this._deps.createPool(lease);
|
|
619
|
+
} catch (err) {
|
|
620
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
621
|
+
throw new NeetruDbError("db_unavailable", `Falha ao abrir pool: ${msg}`);
|
|
622
|
+
}
|
|
623
|
+
if (isResilientPool(this._pool)) {
|
|
624
|
+
const old = this._pool.__neetruSwapInner(realPool);
|
|
625
|
+
void old.end().catch(() => {
|
|
626
|
+
});
|
|
627
|
+
} else {
|
|
628
|
+
this._pool = realPool;
|
|
629
|
+
}
|
|
630
|
+
this._lease = lease;
|
|
631
|
+
this._scheduleRenewal();
|
|
632
|
+
return realPool;
|
|
633
|
+
})();
|
|
634
|
+
this._initInFlight = run;
|
|
635
|
+
try {
|
|
636
|
+
return await run;
|
|
637
|
+
} catch (err) {
|
|
638
|
+
this._initInFlight = null;
|
|
639
|
+
throw err;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
547
642
|
/**
|
|
548
643
|
* Hot-swap do pool: cria pool novo, atualiza ponteiros, drena pool antigo.
|
|
549
644
|
*
|
|
@@ -627,10 +722,19 @@ function createHttpLeaseFetcher(config) {
|
|
|
627
722
|
retries: 2
|
|
628
723
|
});
|
|
629
724
|
} catch (err) {
|
|
725
|
+
const verb = isRenewal ? "renovar" : "obter";
|
|
630
726
|
const msg = err instanceof Error ? err.message : String(err);
|
|
727
|
+
const reason = err instanceof NeetruError ? err.reason : void 0;
|
|
728
|
+
if (reason === "suspended" || reason === "archived" || reason === "revoked") {
|
|
729
|
+
const human = reason === "suspended" ? "ambiente suspenso \u2014 a m\xE1quina que o servia parou; ser\xE1 religado quando o ambiente voltar" : reason === "archived" ? "ambiente arquivado \u2014 este banco foi arquivado e n\xE3o aceita mais conex\xF5es" : "lease revogado \u2014 as credenciais deste ambiente foram revogadas pelo Core";
|
|
730
|
+
throw new NeetruDbError(
|
|
731
|
+
"db_suspended",
|
|
732
|
+
`Falha ao ${verb} lease SQL: ${human} (reason=${reason}).`
|
|
733
|
+
);
|
|
734
|
+
}
|
|
631
735
|
throw new NeetruDbError(
|
|
632
736
|
"db_unavailable",
|
|
633
|
-
`Falha ao ${
|
|
737
|
+
`Falha ao ${verb} lease SQL: ${msg}`
|
|
634
738
|
);
|
|
635
739
|
}
|
|
636
740
|
return parseLease(raw);
|
|
@@ -702,8 +806,64 @@ async function createDrizzleHandle(pool, schema) {
|
|
|
702
806
|
);
|
|
703
807
|
return drizzle(pool, { schema });
|
|
704
808
|
}
|
|
809
|
+
function createDeferredPool(poolPrototype, ensureRealPool) {
|
|
810
|
+
let real = null;
|
|
811
|
+
let inflight = null;
|
|
812
|
+
const getReal = () => {
|
|
813
|
+
if (real) return Promise.resolve(real);
|
|
814
|
+
if (!inflight) {
|
|
815
|
+
inflight = ensureRealPool().then((p) => {
|
|
816
|
+
real = p;
|
|
817
|
+
inflight = null;
|
|
818
|
+
return p;
|
|
819
|
+
}).catch((e) => {
|
|
820
|
+
inflight = null;
|
|
821
|
+
throw e;
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
return inflight;
|
|
825
|
+
};
|
|
826
|
+
const deferred = {
|
|
827
|
+
async query(...args) {
|
|
828
|
+
const p = await getReal();
|
|
829
|
+
return p.query(...args);
|
|
830
|
+
},
|
|
831
|
+
async connect(...args) {
|
|
832
|
+
const p = await getReal();
|
|
833
|
+
return p.connect(...args);
|
|
834
|
+
},
|
|
835
|
+
async end() {
|
|
836
|
+
if (real) await real.end();
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
if (poolPrototype) {
|
|
840
|
+
Object.setPrototypeOf(deferred, poolPrototype);
|
|
841
|
+
}
|
|
842
|
+
return deferred;
|
|
843
|
+
}
|
|
705
844
|
async function createSqlClientWithDeps(deps, options) {
|
|
706
845
|
const depsWithDb = options?.database !== void 0 ? { ...deps, database: options.database } : deps;
|
|
846
|
+
if (depsWithDb.lazy) {
|
|
847
|
+
let managerRef = null;
|
|
848
|
+
const deferred = createDeferredPool(depsWithDb.poolPrototype ?? null, () => {
|
|
849
|
+
if (!managerRef) {
|
|
850
|
+
throw new NeetruDbError("db_unavailable", "SQL client n\xE3o inicializado (manager ausente).");
|
|
851
|
+
}
|
|
852
|
+
return managerRef._ensureInitialLease();
|
|
853
|
+
});
|
|
854
|
+
const pool2 = createResilientPool(deferred);
|
|
855
|
+
let orm2;
|
|
856
|
+
try {
|
|
857
|
+
orm2 = depsWithDb.createDrizzle(pool2, depsWithDb.schema);
|
|
858
|
+
} catch (err) {
|
|
859
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
860
|
+
throw new NeetruDbError("db_unavailable", `Falha ao criar handle Drizzle: ${msg}`);
|
|
861
|
+
}
|
|
862
|
+
const manager2 = new SqlLeaseManager(null, pool2, orm2, depsWithDb);
|
|
863
|
+
managerRef = manager2;
|
|
864
|
+
pool2.__neetruSetReLease(() => manager2._reactiveReLease());
|
|
865
|
+
return manager2;
|
|
866
|
+
}
|
|
707
867
|
let lease;
|
|
708
868
|
try {
|
|
709
869
|
if (options?.database !== void 0) {
|
|
@@ -756,8 +916,8 @@ async function createSqlClientFromConfig(config, schema, options) {
|
|
|
756
916
|
`[client.db.sql] requer pg + drizzle-orm como peerDependencies do servidor. Instale: npm install pg drizzle-orm. (${err.message})`
|
|
757
917
|
);
|
|
758
918
|
}
|
|
919
|
+
const Pool = pgMod.Pool ?? pgMod.default?.Pool;
|
|
759
920
|
const createPool = (lease) => {
|
|
760
|
-
const Pool = pgMod.Pool ?? pgMod.default?.Pool;
|
|
761
921
|
const ssl = lease.sslca ? {
|
|
762
922
|
ca: lease.sslca,
|
|
763
923
|
cert: lease.clientCert ?? void 0,
|
|
@@ -784,7 +944,14 @@ async function createSqlClientFromConfig(config, schema, options) {
|
|
|
784
944
|
fetchLease,
|
|
785
945
|
createPool,
|
|
786
946
|
createDrizzle,
|
|
787
|
-
schema
|
|
947
|
+
schema,
|
|
948
|
+
// Lease inicial LAZY (motor de ambientes suspenso): `client.db.sql()` não
|
|
949
|
+
// pode explodir o `import` do módulo do produto quando o ambiente está
|
|
950
|
+
// suspenso/arquivado no boot. O 1º lease é adiado pra 1ª query.
|
|
951
|
+
lazy: true,
|
|
952
|
+
// Placeholder pré-1ª-query herda `pg.Pool.prototype` pra `instanceof Pool`
|
|
953
|
+
// valer no wrapper resiliente (transações Drizzle PASS-THROUGH seguras).
|
|
954
|
+
poolPrototype: Pool?.prototype ?? null
|
|
788
955
|
},
|
|
789
956
|
options
|
|
790
957
|
);
|
|
@@ -793,6 +960,7 @@ var LEASE_ENDPOINT, LEASE_RENEW_ENDPOINT;
|
|
|
793
960
|
var init_sql_client = __esm({
|
|
794
961
|
"src/db/sql/sql-client.ts"() {
|
|
795
962
|
init_db_errors();
|
|
963
|
+
init_errors();
|
|
796
964
|
init_lease();
|
|
797
965
|
init_resilient_pool();
|
|
798
966
|
LEASE_ENDPOINT = "/api/sdk/v1/db/lease";
|
|
@@ -4231,7 +4399,23 @@ function buildTicketProvider(config, opts) {
|
|
|
4231
4399
|
function getWebSocketRealtimeClient(gatewayUrl, ticketProvider, dbId, wsFactory) {
|
|
4232
4400
|
return new NeetruRealtimeClient({ gatewayUrl, ticketProvider, dbId, webSocketFactory: wsFactory });
|
|
4233
4401
|
}
|
|
4402
|
+
var _hasWarnedMissingDbId = false;
|
|
4403
|
+
function __resetDbIdWarningForTests() {
|
|
4404
|
+
_hasWarnedMissingDbId = false;
|
|
4405
|
+
}
|
|
4406
|
+
function warnMissingDbIdOnce(config, dbOpts) {
|
|
4407
|
+
if (_hasWarnedMissingDbId) return;
|
|
4408
|
+
if (dbOpts.dbId) return;
|
|
4409
|
+
if (config.env === "prod") return;
|
|
4410
|
+
if (typeof window === "undefined") return;
|
|
4411
|
+
if (typeof console === "undefined" || typeof console.warn !== "function") return;
|
|
4412
|
+
_hasWarnedMissingDbId = true;
|
|
4413
|
+
console.warn(
|
|
4414
|
+
"[neetru/sdk] client.db sem `dbId` expl\xEDcito: escritas client-side (add/set/update/remove/list) caem no datastore gen\xE9rico do Core, escopado por tenant/produto (header x-neetru-tenant) \u2014 `dbId` s\xF3 nomeia o cache offline LOCAL (IndexedDB), n\xE3o roteia nem escopa nada no servidor. Veja o JSDoc de NeetruDbOptions.dbId."
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4234
4417
|
function createNeetruDb(config, dbOpts = {}) {
|
|
4418
|
+
warnMissingDbIdOnce(config, dbOpts);
|
|
4235
4419
|
let resolvedTransport;
|
|
4236
4420
|
if (dbOpts.transport !== void 0) {
|
|
4237
4421
|
resolvedTransport = dbOpts.transport;
|
|
@@ -4406,6 +4590,6 @@ function createLazyCollectionRef(name, getDocsPromise) {
|
|
|
4406
4590
|
};
|
|
4407
4591
|
}
|
|
4408
4592
|
|
|
4409
|
-
export { NEETRU_SENTINEL_KEY, NeetruDbError, createNeetruDb, createRestSyncTransport, getWebSocketRealtimeClient, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp };
|
|
4593
|
+
export { NEETRU_SENTINEL_KEY, NeetruDbError, __resetDbIdWarningForTests, createNeetruDb, createRestSyncTransport, getWebSocketRealtimeClient, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp };
|
|
4410
4594
|
//# sourceMappingURL=db.mjs.map
|
|
4411
4595
|
//# sourceMappingURL=db.mjs.map
|