@neetru/sdk 3.8.0 → 3.8.1
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 +20 -0
- package/dist/ai.cjs +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/auth.cjs +708 -688
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +705 -685
- package/dist/catalog.cjs +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/checkout.cjs +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +1 -1
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +242 -222
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +263 -243
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +730 -710
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +874 -854
- package/dist/mobile.d.cts +1 -1
- package/dist/mobile.d.ts +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/notifications.cjs +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/support.cjs +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs +1 -1
- package/dist/telemetry.cjs +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +1 -1
- package/dist/{types-bVztFQTI.d.ts → types-BYPk_3HR.d.ts} +56 -16
- package/dist/{types-D-9bjlM0.d.cts → types-yv3EDKg2.d.cts} +56 -16
- package/dist/usage.cjs +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +1 -1
- package/dist/webhooks.cjs +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +1 -1
- package/package.json +1 -1
package/dist/db.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { openDB } from 'idb';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var Ye = Object.defineProperty;
|
|
4
4
|
var S = (r, e) => () => (r && (e = r(r = 0)), e);
|
|
5
5
|
var me = (r, e) => {
|
|
6
6
|
for (var t in e)
|
|
7
|
-
|
|
7
|
+
Ye(r, t, { get: e[t], enumerable: true });
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
// src/errors.ts
|
|
11
|
-
var
|
|
12
|
-
|
|
11
|
+
var b, x = S(() => {
|
|
12
|
+
b = class r extends Error {
|
|
13
13
|
code;
|
|
14
14
|
status;
|
|
15
15
|
requestId;
|
|
@@ -36,13 +36,13 @@ var g, x = S(() => {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// src/db-errors.ts
|
|
39
|
-
var
|
|
39
|
+
var Ze, f, I = S(() => {
|
|
40
40
|
x();
|
|
41
|
-
|
|
41
|
+
Ze = /* @__PURE__ */ new Set([
|
|
42
42
|
"db_unavailable",
|
|
43
43
|
"db_conflict",
|
|
44
44
|
"db_timeout"
|
|
45
|
-
]),
|
|
45
|
+
]), f = class r extends b {
|
|
46
46
|
/** Código de erro fechado — específico de DB. */
|
|
47
47
|
code;
|
|
48
48
|
/**
|
|
@@ -56,7 +56,7 @@ var Ye, p, I = S(() => {
|
|
|
56
56
|
*/
|
|
57
57
|
dbId;
|
|
58
58
|
constructor(e, t, n) {
|
|
59
|
-
super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable =
|
|
59
|
+
super(e, t), this.name = "NeetruDbError", this.code = e, this.retryable = Ze.has(e), this.dbId = n, Object.setPrototypeOf(this, r.prototype);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
});
|
|
@@ -66,7 +66,7 @@ function Te() {
|
|
|
66
66
|
let r = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
67
67
|
if (r && typeof r.randomUUID == "function")
|
|
68
68
|
return r.randomUUID();
|
|
69
|
-
throw new
|
|
69
|
+
throw new b(
|
|
70
70
|
"runtime_unsupported",
|
|
71
71
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
72
72
|
);
|
|
@@ -77,9 +77,9 @@ var Re = S(() => {
|
|
|
77
77
|
|
|
78
78
|
// src/correlation.ts
|
|
79
79
|
function ke(r) {
|
|
80
|
-
return typeof r == "string" && r.length > 0 && r.length <= 128 &&
|
|
80
|
+
return typeof r == "string" && r.length > 0 && r.length <= 128 && wt.test(r);
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function St() {
|
|
83
83
|
let r = globalThis.crypto;
|
|
84
84
|
try {
|
|
85
85
|
if (r && typeof r.randomUUID == "function") return r.randomUUID();
|
|
@@ -106,11 +106,11 @@ function Ce(r, e) {
|
|
|
106
106
|
}
|
|
107
107
|
n[i] = s;
|
|
108
108
|
}
|
|
109
|
-
let o = t ?? (ke(e) ? e : void 0) ??
|
|
109
|
+
let o = t ?? (ke(e) ? e : void 0) ?? St();
|
|
110
110
|
return n[De] = o, { headers: n, correlationId: o };
|
|
111
111
|
}
|
|
112
|
-
var De,
|
|
113
|
-
De = "x-correlation-id",
|
|
112
|
+
var De, wt, Ie = S(() => {
|
|
113
|
+
De = "x-correlation-id", wt = /^[A-Za-z0-9._:\-]+$/;
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
// src/server-only-key.ts
|
|
@@ -134,13 +134,13 @@ var Ee = S(() => {
|
|
|
134
134
|
var U = {};
|
|
135
135
|
me(U, {
|
|
136
136
|
checkCoreVersionCompat: () => qe,
|
|
137
|
-
httpRequest: () =>
|
|
137
|
+
httpRequest: () => Ot,
|
|
138
138
|
statusToCode: () => Fe
|
|
139
139
|
});
|
|
140
140
|
function se(r) {
|
|
141
141
|
return r.split("+")[0] ?? r;
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function Rt(r, e) {
|
|
144
144
|
let t = se(r).split(".").map(Number), n = se(e).split(".").map(Number), o = Math.max(t.length, n.length);
|
|
145
145
|
for (let i = 0; i < o; i++) {
|
|
146
146
|
let s = t[i] ?? 0, a = n[i] ?? 0;
|
|
@@ -150,28 +150,28 @@ function Tt(r, e) {
|
|
|
150
150
|
}
|
|
151
151
|
function Ne() {
|
|
152
152
|
try {
|
|
153
|
-
return "3.8.
|
|
153
|
+
return "3.8.1";
|
|
154
154
|
} catch {
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
function
|
|
158
|
+
function Dt() {
|
|
159
159
|
let r = Ne();
|
|
160
160
|
return r ? parseInt(r.split(".")[0] ?? "3", 10) : 3;
|
|
161
161
|
}
|
|
162
162
|
function qe(r) {
|
|
163
163
|
if (!r) return;
|
|
164
|
-
let e =
|
|
164
|
+
let e = Dt(), t = Tt[e];
|
|
165
165
|
if (!t) return;
|
|
166
166
|
let n = se(r);
|
|
167
|
-
if (
|
|
167
|
+
if (Rt(n, t) < 0) {
|
|
168
168
|
let o = `${e}:${n}`;
|
|
169
169
|
Le.has(o) || (Le.add(o), console.warn(
|
|
170
170
|
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${r}" \xE9 anterior ao m\xEDnimo recomendado "${t}" para SDK major ${e}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
171
171
|
));
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function kt() {
|
|
175
175
|
let r = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
176
176
|
return Pe() ? "Esta opera\xE7\xE3o exige a credencial nrt_ do produto, que \xE9 S\xD3 DE SERVIDOR. No navegador/app, chame a API do seu produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio \u2014 o backend do produto faz esta chamada com o SDK e a chave. (" + r + ")" : r;
|
|
177
177
|
}
|
|
@@ -179,7 +179,7 @@ function Me(r) {
|
|
|
179
179
|
let e = 200 * Math.pow(4, r), t = e * 0.2 * (Math.random() * 2 - 1);
|
|
180
180
|
return Math.max(50, Math.round(e + t));
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function Lt(r) {
|
|
183
183
|
if (!r) return null;
|
|
184
184
|
let e = Number(r);
|
|
185
185
|
if (Number.isFinite(e) && e >= 0) return Math.min(Math.round(e * 1e3), Oe);
|
|
@@ -196,7 +196,7 @@ function xe(r) {
|
|
|
196
196
|
function Fe(r) {
|
|
197
197
|
return r === 401 ? "unauthorized" : r === 403 ? "forbidden" : r === 404 ? "not_found" : r === 409 ? "conflict" : r === 410 ? "gone" : r === 422 || r === 400 ? "validation_failed" : r === 429 ? "rate_limited" : r >= 500 ? "server_error" : "unknown";
|
|
198
198
|
}
|
|
199
|
-
function
|
|
199
|
+
function Mt(r, e, t) {
|
|
200
200
|
let n = r.replace(/\/+$/, ""), o = e.startsWith("/") ? e : `/${e}`, i = new URL(`${n}${o}`);
|
|
201
201
|
if (t)
|
|
202
202
|
for (let [s, a] of Object.entries(t))
|
|
@@ -212,26 +212,26 @@ async function Ae(r) {
|
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
async function
|
|
216
|
-
let t = e.method ?? "GET", n =
|
|
215
|
+
async function Ot(r, e) {
|
|
216
|
+
let t = e.method ?? "GET", n = Mt(r.baseUrl, e.path, e.query), o = Pt.has(t) ? Ct : It, i = e.retries ?? o, { headers: s, correlationId: a } = Ce(
|
|
217
217
|
{ accept: "application/json", ...e.headers },
|
|
218
218
|
e.correlationId
|
|
219
219
|
), c = Ne();
|
|
220
220
|
if (c && (s["x-neetru-sdk-version"] = c), e.requireAuth) {
|
|
221
221
|
if (!r.apiKey)
|
|
222
|
-
throw new
|
|
222
|
+
throw new b("missing_api_key", kt());
|
|
223
223
|
s.authorization = `Bearer ${r.apiKey}`;
|
|
224
224
|
}
|
|
225
225
|
if (e.idempotencyKey) {
|
|
226
|
-
let
|
|
227
|
-
s["idempotency-key"] =
|
|
226
|
+
let p = typeof e.idempotencyKey == "string" ? e.idempotencyKey : Te();
|
|
227
|
+
s["idempotency-key"] = p;
|
|
228
228
|
}
|
|
229
229
|
let l = e.body !== void 0 && t !== "GET" && t !== "DELETE" ? JSON.stringify(e.body) : void 0;
|
|
230
230
|
l !== void 0 && (s["content-type"] = "application/json");
|
|
231
231
|
let d = null, u = e.deadlineMs != null ? Date.now() + e.deadlineMs : null;
|
|
232
|
-
for (let
|
|
232
|
+
for (let p = 0; p <= i; p++) {
|
|
233
233
|
if (u != null && Date.now() >= u)
|
|
234
|
-
throw d ?? new
|
|
234
|
+
throw d ?? new b(
|
|
235
235
|
"network_error",
|
|
236
236
|
"Deadline excedido antes de completar a request",
|
|
237
237
|
void 0,
|
|
@@ -241,15 +241,15 @@ async function Mt(r, e) {
|
|
|
241
241
|
);
|
|
242
242
|
let h = { method: t, headers: s };
|
|
243
243
|
l !== void 0 && (h.body = l);
|
|
244
|
-
let
|
|
245
|
-
h.signal = AbortSignal.timeout(
|
|
246
|
-
let
|
|
244
|
+
let _ = u != null ? Math.max(1, Math.min(3e4, u - Date.now())) : 3e4;
|
|
245
|
+
h.signal = AbortSignal.timeout(_);
|
|
246
|
+
let y;
|
|
247
247
|
try {
|
|
248
|
-
|
|
248
|
+
y = await r.fetch(n, h);
|
|
249
249
|
} catch (m) {
|
|
250
250
|
let O = m instanceof DOMException && m.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${m instanceof Error ? m.message : "fetch failed"}`;
|
|
251
|
-
if (d = new
|
|
252
|
-
let he = Me(
|
|
251
|
+
if (d = new b("network_error", O, void 0, void 0, void 0, a), p < i) {
|
|
252
|
+
let he = Me(p);
|
|
253
253
|
if (u == null || Date.now() + he < u) {
|
|
254
254
|
await xe(he);
|
|
255
255
|
continue;
|
|
@@ -257,23 +257,23 @@ async function Mt(r, e) {
|
|
|
257
257
|
}
|
|
258
258
|
throw d;
|
|
259
259
|
}
|
|
260
|
-
let B =
|
|
261
|
-
if (
|
|
262
|
-
let m =
|
|
263
|
-
return m && qe(m), await Ae(
|
|
260
|
+
let B = y.headers.get("x-request-id") ?? y.headers.get("x-correlation-id") ?? void 0;
|
|
261
|
+
if (y.ok) {
|
|
262
|
+
let m = y.headers.get("x-neetru-version");
|
|
263
|
+
return m && qe(m), await Ae(y);
|
|
264
264
|
}
|
|
265
|
-
let
|
|
266
|
-
if (
|
|
267
|
-
let m =
|
|
268
|
-
typeof m == "string" ? w = m : m && typeof m == "object" ? (typeof m.code == "string" && (
|
|
265
|
+
let g = await Ae(y), v = Fe(y.status), w = `HTTP ${y.status}`, C;
|
|
266
|
+
if (g && typeof g == "object") {
|
|
267
|
+
let m = g.error;
|
|
268
|
+
typeof m == "string" ? w = m : m && typeof m == "object" ? (typeof m.code == "string" && (v = m.code), typeof m.message == "string" && (w = m.message), typeof m.reason == "string" && (C = m.reason)) : (typeof g.code == "string" && (v = g.code), typeof g.message == "string" && (w = g.message)), typeof g.reason == "string" && (C = g.reason);
|
|
269
269
|
}
|
|
270
|
-
if (
|
|
271
|
-
let m =
|
|
272
|
-
w === `HTTP ${
|
|
270
|
+
if (y.status === 410) {
|
|
271
|
+
let m = y.headers.get("x-neetru-replacement");
|
|
272
|
+
w === `HTTP ${y.status}` && (w = `Endpoint ${e.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), m && !w.includes(m) && (w += ` Substituto: ${m}.`);
|
|
273
273
|
}
|
|
274
|
-
let fe = new
|
|
275
|
-
if (d = fe,
|
|
276
|
-
let O =
|
|
274
|
+
let fe = new b(v, w, y.status, B, C, a);
|
|
275
|
+
if (d = fe, Et.has(v) && p < i) {
|
|
276
|
+
let O = Lt(y.headers.get("retry-after")) ?? Me(p);
|
|
277
277
|
if (u == null || Date.now() + O < u) {
|
|
278
278
|
await xe(O);
|
|
279
279
|
continue;
|
|
@@ -281,20 +281,20 @@ async function Mt(r, e) {
|
|
|
281
281
|
}
|
|
282
282
|
throw fe;
|
|
283
283
|
}
|
|
284
|
-
throw d ?? new
|
|
284
|
+
throw d ?? new b("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, a);
|
|
285
285
|
}
|
|
286
|
-
var
|
|
286
|
+
var Tt, Le, Ct, It, Pt, Et, Oe, W = S(() => {
|
|
287
287
|
x();
|
|
288
288
|
Re();
|
|
289
289
|
Ie();
|
|
290
290
|
Ee();
|
|
291
|
-
|
|
291
|
+
Tt = {
|
|
292
292
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
293
293
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
294
294
|
3: "2026.05.1"
|
|
295
295
|
};
|
|
296
296
|
Le = /* @__PURE__ */ new Set();
|
|
297
|
-
|
|
297
|
+
Ct = 2, It = 0, Pt = /* @__PURE__ */ new Set(["GET", "HEAD"]), Et = /* @__PURE__ */ new Set([
|
|
298
298
|
"rate_limited",
|
|
299
299
|
"server_error",
|
|
300
300
|
"network_error"
|
|
@@ -306,7 +306,7 @@ var St, Le, kt, Ct, It, Pt, Oe, W = S(() => {
|
|
|
306
306
|
function J(r) {
|
|
307
307
|
return typeof r == "object" && r !== null && r[ae] === true;
|
|
308
308
|
}
|
|
309
|
-
function
|
|
309
|
+
function xt(r) {
|
|
310
310
|
let e = r && typeof r == "object" && "code" in r ? r.code : void 0;
|
|
311
311
|
if (e === "ECONNREFUSED" || e === "ETIMEDOUT" || e === "ENOTFOUND" || e === "EHOSTUNREACH" || e === "EAI_AGAIN")
|
|
312
312
|
return true;
|
|
@@ -318,67 +318,84 @@ function Ot(r) {
|
|
|
318
318
|
let n = (r instanceof Error ? r.message : typeof r == "string" ? r : "").toLowerCase();
|
|
319
319
|
return n.length === 0 ? false : !!(n.includes("certificate expired") || n.includes("certificate has expired") || n.includes("cert_has_expired") || n.includes("alert certificate expired") || n.includes("err_ssl") || n.includes("sslv3 alert") || n.includes("tlsv1 alert") || n.includes("econnrefused") || n.includes("etimedout") || n.includes("enotfound") || n.includes("ehostunreach") || n.includes("getaddrinfo"));
|
|
320
320
|
}
|
|
321
|
+
function Ue(r) {
|
|
322
|
+
let e = r && typeof r == "object" && "code" in r ? r.code : void 0;
|
|
323
|
+
if (typeof e == "string" && At.has(e.toUpperCase()))
|
|
324
|
+
return true;
|
|
325
|
+
let n = (r instanceof Error ? r.message : typeof r == "string" ? r : "").toLowerCase();
|
|
326
|
+
return n.length === 0 ? false : n.includes("password authentication failed") || n.includes("sasl authentication failed");
|
|
327
|
+
}
|
|
328
|
+
function Nt(r) {
|
|
329
|
+
return xt(r) || Ue(r);
|
|
330
|
+
}
|
|
321
331
|
function ce(r) {
|
|
322
332
|
let e = { current: r }, t = null, n = {
|
|
323
|
-
__neetruSwapInner(
|
|
324
|
-
let
|
|
325
|
-
return e.current =
|
|
333
|
+
__neetruSwapInner(d) {
|
|
334
|
+
let u = e.current;
|
|
335
|
+
return e.current = d, u;
|
|
326
336
|
},
|
|
327
337
|
__neetruGetInner() {
|
|
328
338
|
return e.current;
|
|
329
339
|
},
|
|
330
|
-
__neetruSetReLease(
|
|
331
|
-
t =
|
|
340
|
+
__neetruSetReLease(d) {
|
|
341
|
+
t = d;
|
|
332
342
|
}
|
|
333
|
-
}, o = (
|
|
343
|
+
}, o = (d, u, p) => u[d](
|
|
344
|
+
...p
|
|
345
|
+
), i = (d, u) => (...p) => p.length > 0 && typeof p[p.length - 1] == "function" ? o(d, e.current, p) : (async () => {
|
|
334
346
|
try {
|
|
335
|
-
return await o(e.current,
|
|
336
|
-
} catch (
|
|
337
|
-
let
|
|
338
|
-
if (
|
|
339
|
-
throw
|
|
347
|
+
return await o(d, e.current, p);
|
|
348
|
+
} catch (h) {
|
|
349
|
+
let _ = t;
|
|
350
|
+
if (_ === null || !u(h))
|
|
351
|
+
throw h;
|
|
340
352
|
try {
|
|
341
|
-
await
|
|
353
|
+
await _();
|
|
342
354
|
} catch {
|
|
343
|
-
throw
|
|
355
|
+
throw h;
|
|
344
356
|
}
|
|
345
|
-
return await o(e.current,
|
|
357
|
+
return await o(d, e.current, p);
|
|
346
358
|
}
|
|
347
|
-
})(), s = Object.create(Object.getPrototypeOf(r));
|
|
348
|
-
return new Proxy(
|
|
349
|
-
get(
|
|
350
|
-
if (
|
|
351
|
-
if (
|
|
352
|
-
if (
|
|
353
|
-
if (
|
|
354
|
-
if (
|
|
355
|
-
if (
|
|
359
|
+
})(), s = i("query", Nt), a = i("connect", Ue), c = Object.create(Object.getPrototypeOf(r));
|
|
360
|
+
return new Proxy(c, {
|
|
361
|
+
get(d, u) {
|
|
362
|
+
if (u === ae) return true;
|
|
363
|
+
if (u === "__neetruSwapInner") return n.__neetruSwapInner;
|
|
364
|
+
if (u === "__neetruGetInner") return n.__neetruGetInner;
|
|
365
|
+
if (u === "__neetruSetReLease") return n.__neetruSetReLease;
|
|
366
|
+
if (u === "query") return s;
|
|
367
|
+
if (u === "connect") {
|
|
368
|
+
let _ = e.current;
|
|
369
|
+
return typeof _.connect == "function" ? a : _.connect;
|
|
370
|
+
}
|
|
371
|
+
if (u === "constructor")
|
|
356
372
|
return e.current.constructor;
|
|
357
|
-
let
|
|
358
|
-
return typeof
|
|
373
|
+
let p = e.current, h = Reflect.get(p, u, p);
|
|
374
|
+
return typeof h == "function" ? h.bind(p) : h;
|
|
359
375
|
}
|
|
360
376
|
});
|
|
361
377
|
}
|
|
362
|
-
var ae, le = S(() => {
|
|
378
|
+
var ae, At, le = S(() => {
|
|
363
379
|
ae = /* @__PURE__ */ Symbol.for("neetru.sdk.resilientPool");
|
|
380
|
+
At = /* @__PURE__ */ new Set(["28P01", "28000"]);
|
|
364
381
|
});
|
|
365
382
|
|
|
366
383
|
// src/db/sql/lease.ts
|
|
367
|
-
function
|
|
384
|
+
function Ft(r, e) {
|
|
368
385
|
return r ? r.leaseId !== e.leaseId || r.credentialVersion !== e.credentialVersion || r.host !== e.host || r.port !== e.port || r.dbName !== e.dbName || r.user !== e.user || r.password !== e.password || r.sslca !== e.sslca || r.clientCert !== e.clientCert || r.clientKey !== e.clientKey : true;
|
|
369
386
|
}
|
|
370
|
-
function
|
|
371
|
-
if (r instanceof
|
|
387
|
+
function Ut(r) {
|
|
388
|
+
if (r instanceof f) return r;
|
|
372
389
|
let e = r instanceof Error ? r.message : String(r), t = r instanceof Error ? r.code : void 0;
|
|
373
|
-
return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new
|
|
390
|
+
return typeof t == "string" && (t === "ECONNREFUSED" || t === "ENOTFOUND" || t === "ETIMEDOUT") ? new f(
|
|
374
391
|
"db_unavailable",
|
|
375
392
|
`Pool connection failed (${t}): ${e}`
|
|
376
|
-
) : e.includes("statement timeout") || e.includes("lock timeout") ? new
|
|
393
|
+
) : e.includes("statement timeout") || e.includes("lock timeout") ? new f("db_timeout", `Query timeout: ${e}`) : e.includes("40001") || e.includes("40P01") || e.includes("deadlock") ? new f("db_conflict", `Transaction conflict: ${e}`) : e.includes("42501") || e.toLowerCase().includes("permission denied") ? new f("db_permission_denied", `Permission denied: ${e}`) : new f("db_unavailable", `Database error: ${e}`);
|
|
377
394
|
}
|
|
378
|
-
var
|
|
395
|
+
var qt, M, $, We = S(() => {
|
|
379
396
|
I();
|
|
380
397
|
le();
|
|
381
|
-
|
|
398
|
+
qt = 0.8, M = 3e4, $ = class {
|
|
382
399
|
/**
|
|
383
400
|
* Lease atual. `null` no modo LAZY antes da 1ª query (o 1º lease é adiado —
|
|
384
401
|
* ver `_ensureInitialLease`). Após a 1ª aquisição, sempre não-nulo.
|
|
@@ -418,7 +435,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
418
435
|
isolationLevel: t.isolationLevel
|
|
419
436
|
}) : await this._orm.transaction(e);
|
|
420
437
|
} catch (n) {
|
|
421
|
-
throw
|
|
438
|
+
throw Ut(n);
|
|
422
439
|
}
|
|
423
440
|
}
|
|
424
441
|
async close() {
|
|
@@ -441,7 +458,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
441
458
|
if (!Number.isFinite(e)) return M;
|
|
442
459
|
let t = this._deps.now(), n = e - t;
|
|
443
460
|
if (n <= 0) return M;
|
|
444
|
-
let o = n * (1 -
|
|
461
|
+
let o = n * (1 - qt);
|
|
445
462
|
return Math.max(M, Math.round(o));
|
|
446
463
|
}
|
|
447
464
|
_scheduleRenewal() {
|
|
@@ -470,7 +487,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
470
487
|
this._renewalTimer = setTimeout(() => {
|
|
471
488
|
this._doRenew();
|
|
472
489
|
}, M), console.warn(
|
|
473
|
-
`[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${M}ms (cert
|
|
490
|
+
`[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${M}ms (o cert de cliente mTLS do lease expira ~15min ap\xF3s o \xFAltimo swap):`,
|
|
474
491
|
t instanceof Error ? t.message : t
|
|
475
492
|
);
|
|
476
493
|
return;
|
|
@@ -482,10 +499,13 @@ var xt, M, $, Ue = S(() => {
|
|
|
482
499
|
/**
|
|
483
500
|
* Recuperação REATIVA: chamado pelo wrapper resiliente (`resilient-pool.ts`)
|
|
484
501
|
* quando uma query plana falha num erro de ESTABELECIMENTO de conexão (cert
|
|
485
|
-
* TLS
|
|
486
|
-
* renovação que não disparou)
|
|
487
|
-
* do
|
|
488
|
-
*
|
|
502
|
+
* TLS de cliente mTLS do lease expirado no meio de uma request, ou timer de
|
|
503
|
+
* renovação que não disparou) ou de AUTENTICAÇÃO (senha rotacionada por
|
|
504
|
+
* `rotate-credentials` antes do próximo renew — SQLSTATE 28P01/28000, ou o
|
|
505
|
+
* 08P01+SASL do PgBouncer; também no `connect()` de uma transação). Emite um
|
|
506
|
+
* lease NOVO e faz o swap do pool interno do wrapper com a credencial e o
|
|
507
|
+
* certificado frescos (o pool velho é drenado com `end()`); o wrapper então
|
|
508
|
+
* re-tenta a operação 1x no pool novo.
|
|
489
509
|
*
|
|
490
510
|
* Vai DIRETO ao lease novo (sem `leaseId`) — a conexão falhou porque o
|
|
491
511
|
* certificado do lease atual está ruim, então `renew` (que depende do lease
|
|
@@ -501,7 +521,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
501
521
|
*/
|
|
502
522
|
async _reactiveReLease() {
|
|
503
523
|
if (this._closed)
|
|
504
|
-
throw new
|
|
524
|
+
throw new f(
|
|
505
525
|
"db_unavailable",
|
|
506
526
|
"SqlLeaseManager foi fechado \u2014 re-lease reativo abortado."
|
|
507
527
|
);
|
|
@@ -538,7 +558,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
538
558
|
*/
|
|
539
559
|
async _ensureInitialLease() {
|
|
540
560
|
if (this._closed)
|
|
541
|
-
throw new
|
|
561
|
+
throw new f(
|
|
542
562
|
"db_unavailable",
|
|
543
563
|
"SqlLeaseManager foi fechado \u2014 aquisi\xE7\xE3o de lease inicial abortada."
|
|
544
564
|
);
|
|
@@ -550,16 +570,16 @@ var xt, M, $, Ue = S(() => {
|
|
|
550
570
|
try {
|
|
551
571
|
t = this._deps.database !== void 0 ? await this._deps.fetchLease({ database: this._deps.database }) : await this._deps.fetchLease();
|
|
552
572
|
} catch (o) {
|
|
553
|
-
if (o instanceof
|
|
573
|
+
if (o instanceof f) throw o;
|
|
554
574
|
let i = o instanceof Error ? o.message : String(o);
|
|
555
|
-
throw new
|
|
575
|
+
throw new f("db_unavailable", `Falha ao obter lease inicial: ${i}`);
|
|
556
576
|
}
|
|
557
577
|
let n;
|
|
558
578
|
try {
|
|
559
579
|
n = this._deps.createPool(t);
|
|
560
580
|
} catch (o) {
|
|
561
581
|
let i = o instanceof Error ? o.message : String(o);
|
|
562
|
-
throw new
|
|
582
|
+
throw new f("db_unavailable", `Falha ao abrir pool: ${i}`);
|
|
563
583
|
}
|
|
564
584
|
return J(this._pool) ? this._pool.__neetruSwapInner(n).end().catch(() => {
|
|
565
585
|
}) : this._pool = n, this._lease = t, this._scheduleRenewal(), n;
|
|
@@ -577,7 +597,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
577
597
|
* Exposto como método protegido para testes.
|
|
578
598
|
*/
|
|
579
599
|
async _swapPool(e) {
|
|
580
|
-
if (!
|
|
600
|
+
if (!Ft(this._lease, e)) {
|
|
581
601
|
this._lease = e;
|
|
582
602
|
return;
|
|
583
603
|
}
|
|
@@ -595,7 +615,7 @@ var xt, M, $, Ue = S(() => {
|
|
|
595
615
|
// ─── Helpers ───────────────────────────────────────────────────────────────
|
|
596
616
|
_assertOpen() {
|
|
597
617
|
if (this._closed)
|
|
598
|
-
throw new
|
|
618
|
+
throw new f(
|
|
599
619
|
"db_unavailable",
|
|
600
620
|
"SqlLeaseManager foi fechado \u2014 chame close() apenas no shutdown."
|
|
601
621
|
);
|
|
@@ -604,29 +624,29 @@ var xt, M, $, Ue = S(() => {
|
|
|
604
624
|
});
|
|
605
625
|
|
|
606
626
|
// src/db/sql/sql-client.ts
|
|
607
|
-
var
|
|
608
|
-
me(
|
|
609
|
-
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () =>
|
|
610
|
-
DEFAULT_POOL_IDLE_MS: () =>
|
|
627
|
+
var He = {};
|
|
628
|
+
me(He, {
|
|
629
|
+
DEFAULT_POOL_CONNECT_TIMEOUT_MS: () => ze,
|
|
630
|
+
DEFAULT_POOL_IDLE_MS: () => Qe,
|
|
611
631
|
DEFAULT_POOL_MAX: () => Ve,
|
|
612
|
-
LEASE_ENDPOINT: () =>
|
|
613
|
-
LEASE_RENEW_ENDPOINT: () =>
|
|
614
|
-
createDrizzleHandle: () =>
|
|
615
|
-
createHttpLeaseFetcher: () =>
|
|
616
|
-
createPgPool: () =>
|
|
617
|
-
createSqlClientFromConfig: () =>
|
|
618
|
-
createSqlClientWithDeps: () =>
|
|
632
|
+
LEASE_ENDPOINT: () => $e,
|
|
633
|
+
LEASE_RENEW_ENDPOINT: () => Be,
|
|
634
|
+
createDrizzleHandle: () => jt,
|
|
635
|
+
createHttpLeaseFetcher: () => je,
|
|
636
|
+
createPgPool: () => Bt,
|
|
637
|
+
createSqlClientFromConfig: () => Qt,
|
|
638
|
+
createSqlClientWithDeps: () => Ke,
|
|
619
639
|
resolvePoolTuning: () => ue
|
|
620
640
|
});
|
|
621
|
-
function
|
|
641
|
+
function Wt(r) {
|
|
622
642
|
return r === "workspace" ? "staging" : r === "prod" ? "production" : "dev-local";
|
|
623
643
|
}
|
|
624
|
-
function
|
|
644
|
+
function je(r) {
|
|
625
645
|
return async (e) => {
|
|
626
|
-
let { httpRequest: t } = await Promise.resolve().then(() => (W(), U)), n = !!e?.leaseId, o = n ?
|
|
646
|
+
let { httpRequest: t } = await Promise.resolve().then(() => (W(), U)), n = !!e?.leaseId, o = n ? Be : $e, i;
|
|
627
647
|
n ? i = { leaseId: e.leaseId } : (i = {
|
|
628
648
|
productId: r.productId ?? "",
|
|
629
|
-
environment:
|
|
649
|
+
environment: Wt(r.env ?? "prod")
|
|
630
650
|
}, e?.database !== void 0 && (i.database = e.database));
|
|
631
651
|
let s;
|
|
632
652
|
try {
|
|
@@ -639,35 +659,35 @@ function Be(r) {
|
|
|
639
659
|
retries: 2
|
|
640
660
|
});
|
|
641
661
|
} catch (a) {
|
|
642
|
-
let c = n ? "renovar" : "obter", l = a instanceof Error ? a.message : String(a), d = a instanceof
|
|
662
|
+
let c = n ? "renovar" : "obter", l = a instanceof Error ? a.message : String(a), d = a instanceof b ? a.reason : void 0;
|
|
643
663
|
if (d === "suspended" || d === "archived" || d === "revoked") {
|
|
644
664
|
let u = d === "suspended" ? "ambiente suspenso \u2014 a m\xE1quina que o servia parou; ser\xE1 religado quando o ambiente voltar" : d === "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";
|
|
645
|
-
throw new
|
|
665
|
+
throw new f(
|
|
646
666
|
"db_suspended",
|
|
647
667
|
`Falha ao ${c} lease SQL: ${u} (reason=${d}).`
|
|
648
668
|
);
|
|
649
669
|
}
|
|
650
|
-
throw new
|
|
670
|
+
throw new f(
|
|
651
671
|
"db_unavailable",
|
|
652
672
|
`Falha ao ${c} lease SQL: ${l}`
|
|
653
673
|
);
|
|
654
674
|
}
|
|
655
|
-
return
|
|
675
|
+
return $t(s);
|
|
656
676
|
};
|
|
657
677
|
}
|
|
658
|
-
function
|
|
678
|
+
function $t(r) {
|
|
659
679
|
if (!r || typeof r != "object")
|
|
660
|
-
throw new
|
|
680
|
+
throw new f("db_unavailable", "Resposta de lease inv\xE1lida (n\xE3o \xE9 objeto).");
|
|
661
681
|
let t = r.lease;
|
|
662
682
|
if (!t || typeof t != "object")
|
|
663
|
-
throw new
|
|
683
|
+
throw new f(
|
|
664
684
|
"db_unavailable",
|
|
665
685
|
'Resposta de lease inv\xE1lida: campo "lease" ausente ou n\xE3o \xE9 objeto. O Core retorna { kind, lease: { leaseId, host, ... } }.'
|
|
666
686
|
);
|
|
667
687
|
let n = t;
|
|
668
688
|
function o(i, s) {
|
|
669
689
|
if (typeof n[i] !== s)
|
|
670
|
-
throw new
|
|
690
|
+
throw new f(
|
|
671
691
|
"db_unavailable",
|
|
672
692
|
`Campo obrigat\xF3rio "${i}" ausente ou tipo inv\xE1lido na resposta de lease.`
|
|
673
693
|
);
|
|
@@ -699,10 +719,10 @@ function ue() {
|
|
|
699
719
|
// para múltiplas instâncias do app dividirem o mesmo front-door.
|
|
700
720
|
max: de("NEETRU_DB_POOL_MAX", Ve, 1, 100),
|
|
701
721
|
// Teto 15min = janela do cert; piso 1s.
|
|
702
|
-
idleTimeoutMillis: de("NEETRU_DB_POOL_IDLE_MS",
|
|
722
|
+
idleTimeoutMillis: de("NEETRU_DB_POOL_IDLE_MS", Qe, 1e3, 9e5),
|
|
703
723
|
connectionTimeoutMillis: de(
|
|
704
724
|
"NEETRU_DB_POOL_CONNECT_TIMEOUT_MS",
|
|
705
|
-
|
|
725
|
+
ze,
|
|
706
726
|
1e3,
|
|
707
727
|
12e4
|
|
708
728
|
),
|
|
@@ -710,7 +730,7 @@ function ue() {
|
|
|
710
730
|
keepAliveInitialDelayMillis: 1e4
|
|
711
731
|
};
|
|
712
732
|
}
|
|
713
|
-
async function
|
|
733
|
+
async function Bt(r) {
|
|
714
734
|
let { Pool: e } = await import(
|
|
715
735
|
/* webpackIgnore: true */
|
|
716
736
|
'pg'
|
|
@@ -730,14 +750,14 @@ async function Ut(r) {
|
|
|
730
750
|
...ue()
|
|
731
751
|
});
|
|
732
752
|
}
|
|
733
|
-
async function
|
|
753
|
+
async function jt(r, e) {
|
|
734
754
|
let { drizzle: t } = await import(
|
|
735
755
|
/* webpackIgnore: true */
|
|
736
756
|
'drizzle-orm/node-postgres'
|
|
737
757
|
);
|
|
738
758
|
return t(r, { schema: e });
|
|
739
759
|
}
|
|
740
|
-
function
|
|
760
|
+
function Vt(r, e) {
|
|
741
761
|
let t = null, n = null, o = () => t ? Promise.resolve(t) : (n || (n = e().then((s) => (t = s, n = null, s)).catch((s) => {
|
|
742
762
|
throw n = null, s;
|
|
743
763
|
})), n), i = {
|
|
@@ -753,37 +773,37 @@ function $t(r, e) {
|
|
|
753
773
|
};
|
|
754
774
|
return r && Object.setPrototypeOf(i, r), i;
|
|
755
775
|
}
|
|
756
|
-
async function
|
|
776
|
+
async function Ke(r, e) {
|
|
757
777
|
let t = e?.database !== void 0 ? { ...r, database: e.database } : r;
|
|
758
778
|
if (t.lazy) {
|
|
759
|
-
let c = null, l =
|
|
779
|
+
let c = null, l = Vt(t.poolPrototype ?? null, () => {
|
|
760
780
|
if (!c)
|
|
761
|
-
throw new
|
|
781
|
+
throw new f("db_unavailable", "SQL client n\xE3o inicializado (manager ausente).");
|
|
762
782
|
return c._ensureInitialLease();
|
|
763
783
|
}), d = ce(l), u;
|
|
764
784
|
try {
|
|
765
785
|
u = t.createDrizzle(d, t.schema);
|
|
766
786
|
} catch (h) {
|
|
767
|
-
let
|
|
768
|
-
throw new
|
|
787
|
+
let _ = h instanceof Error ? h.message : String(h);
|
|
788
|
+
throw new f("db_unavailable", `Falha ao criar handle Drizzle: ${_}`);
|
|
769
789
|
}
|
|
770
|
-
let
|
|
771
|
-
return c =
|
|
790
|
+
let p = new $(null, d, u, t);
|
|
791
|
+
return c = p, d.__neetruSetReLease(() => p._reactiveReLease()), p;
|
|
772
792
|
}
|
|
773
793
|
let n;
|
|
774
794
|
try {
|
|
775
795
|
e?.database !== void 0 ? n = await t.fetchLease({ database: e.database }) : n = await t.fetchLease();
|
|
776
796
|
} catch (c) {
|
|
777
|
-
if (c instanceof
|
|
797
|
+
if (c instanceof f) throw c;
|
|
778
798
|
let l = c instanceof Error ? c.message : String(c);
|
|
779
|
-
throw new
|
|
799
|
+
throw new f("db_unavailable", `Falha ao obter lease inicial: ${l}`);
|
|
780
800
|
}
|
|
781
801
|
let o;
|
|
782
802
|
try {
|
|
783
803
|
o = t.createPool(n);
|
|
784
804
|
} catch (c) {
|
|
785
805
|
let l = c instanceof Error ? c.message : String(c);
|
|
786
|
-
throw new
|
|
806
|
+
throw new f("db_unavailable", `Falha ao abrir pool: ${l}`);
|
|
787
807
|
}
|
|
788
808
|
let i = ce(o), s;
|
|
789
809
|
try {
|
|
@@ -792,13 +812,13 @@ async function ze(r, e) {
|
|
|
792
812
|
await o.end().catch(() => {
|
|
793
813
|
});
|
|
794
814
|
let l = c instanceof Error ? c.message : String(c);
|
|
795
|
-
throw new
|
|
815
|
+
throw new f("db_unavailable", `Falha ao criar handle Drizzle: ${l}`);
|
|
796
816
|
}
|
|
797
817
|
let a = new $(n, i, s, t);
|
|
798
818
|
return i.__neetruSetReLease(() => a._reactiveReLease()), a;
|
|
799
819
|
}
|
|
800
|
-
async function
|
|
801
|
-
let n =
|
|
820
|
+
async function Qt(r, e, t) {
|
|
821
|
+
let n = je(r), o, i;
|
|
802
822
|
try {
|
|
803
823
|
o = await import(
|
|
804
824
|
/* webpackIgnore: true */
|
|
@@ -808,13 +828,13 @@ async function Bt(r, e, t) {
|
|
|
808
828
|
'drizzle-orm/node-postgres'
|
|
809
829
|
);
|
|
810
830
|
} catch (l) {
|
|
811
|
-
throw new
|
|
831
|
+
throw new f(
|
|
812
832
|
"db_unavailable",
|
|
813
833
|
`[client.db.sql] requer pg + drizzle-orm como peerDependencies do servidor. Instale: npm install pg drizzle-orm. (${l.message})`
|
|
814
834
|
);
|
|
815
835
|
}
|
|
816
836
|
let s = o.Pool ?? o.default?.Pool;
|
|
817
|
-
return
|
|
837
|
+
return Ke(
|
|
818
838
|
{
|
|
819
839
|
fetchLease: n,
|
|
820
840
|
createPool: (l) => {
|
|
@@ -849,13 +869,13 @@ async function Bt(r, e, t) {
|
|
|
849
869
|
t
|
|
850
870
|
);
|
|
851
871
|
}
|
|
852
|
-
var
|
|
872
|
+
var $e, Be, Ve, Qe, ze, Ge = S(() => {
|
|
853
873
|
I();
|
|
854
874
|
x();
|
|
855
|
-
|
|
875
|
+
We();
|
|
856
876
|
le();
|
|
857
|
-
|
|
858
|
-
Ve = 10,
|
|
877
|
+
$e = "/api/sdk/v1/db/lease", Be = "/api/sdk/v1/db/lease/renew";
|
|
878
|
+
Ve = 10, Qe = 6e4, ze = 1e4;
|
|
859
879
|
});
|
|
860
880
|
|
|
861
881
|
// src/db/client-db.ts
|
|
@@ -884,7 +904,7 @@ function Z(r, e) {
|
|
|
884
904
|
}
|
|
885
905
|
return n;
|
|
886
906
|
}
|
|
887
|
-
function
|
|
907
|
+
function et(r, e) {
|
|
888
908
|
let t = Z(r, e.field);
|
|
889
909
|
if (t === void 0) return false;
|
|
890
910
|
let { op: n, value: o } = e;
|
|
@@ -915,10 +935,10 @@ function Ze(r, e) {
|
|
|
915
935
|
);
|
|
916
936
|
}
|
|
917
937
|
}
|
|
918
|
-
function
|
|
919
|
-
return e.every((t) =>
|
|
938
|
+
function tt(r, e) {
|
|
939
|
+
return e.every((t) => et(r, t));
|
|
920
940
|
}
|
|
921
|
-
function
|
|
941
|
+
function nt(r) {
|
|
922
942
|
return (e, t) => {
|
|
923
943
|
if (r) {
|
|
924
944
|
let n = Z(e.data, r.field), o = Z(t.data, r.field), i = A(n, o);
|
|
@@ -928,7 +948,7 @@ function tt(r) {
|
|
|
928
948
|
return e.id < t.id ? -1 : e.id > t.id ? 1 : 0;
|
|
929
949
|
};
|
|
930
950
|
}
|
|
931
|
-
function
|
|
951
|
+
function rt(r, e) {
|
|
932
952
|
let t = r.findIndex((n) => n.id === e.docId);
|
|
933
953
|
return t === -1 ? r : e.type === "startAfter" ? r.slice(t + 1) : r.slice(0, t);
|
|
934
954
|
}
|
|
@@ -946,9 +966,9 @@ var P = class r {
|
|
|
946
966
|
evaluate(e, t) {
|
|
947
967
|
let n = e.filter((d) => !d.meta.deleted), o = t.where ?? [];
|
|
948
968
|
o.length > 0 && (n = n.filter(
|
|
949
|
-
(d) =>
|
|
969
|
+
(d) => tt(d.data, o)
|
|
950
970
|
));
|
|
951
|
-
let i =
|
|
971
|
+
let i = nt(t.orderBy), s = [...n].sort(i), a = t.cursor ? rt(s, t.cursor) : s, c = Math.min(t.limit ?? 20, 500);
|
|
952
972
|
return {
|
|
953
973
|
docs: a.slice(0, c).map((d) => ({ id: d.id, data: d.data })),
|
|
954
974
|
// `incomplete` é sempre true aqui — o QueryEngine não sabe se o cache
|
|
@@ -968,7 +988,7 @@ var P = class r {
|
|
|
968
988
|
};
|
|
969
989
|
|
|
970
990
|
// src/db/offline/local-store.ts
|
|
971
|
-
var
|
|
991
|
+
var it = 1, T = "documents", R = "mutations", N = "query_cache", j = "sync_meta", E = "conflict_log", V = class {
|
|
972
992
|
db = null;
|
|
973
993
|
dbName;
|
|
974
994
|
constructor(e) {
|
|
@@ -980,7 +1000,7 @@ var ot = 1, T = "documents", R = "mutations", N = "query_cache", V = "sync_meta"
|
|
|
980
1000
|
* Idempotente — chamadas subsequentes são no-ops se o banco já está aberto.
|
|
981
1001
|
*/
|
|
982
1002
|
async open() {
|
|
983
|
-
this.db === null && (this.db = await openDB(this.dbName,
|
|
1003
|
+
this.db === null && (this.db = await openDB(this.dbName, it, {
|
|
984
1004
|
upgrade(e) {
|
|
985
1005
|
if (!e.objectStoreNames.contains(T)) {
|
|
986
1006
|
let t = e.createObjectStore(T, {
|
|
@@ -994,7 +1014,7 @@ var ot = 1, T = "documents", R = "mutations", N = "query_cache", V = "sync_meta"
|
|
|
994
1014
|
});
|
|
995
1015
|
t.createIndex("by_seq", "seq"), t.createIndex("by_status", "status"), t.createIndex("by_doc", ["collection", "docId"]), t.createIndex("by_batch", "batchId");
|
|
996
1016
|
}
|
|
997
|
-
if (e.objectStoreNames.contains(N) || e.createObjectStore(N, { keyPath: "queryHash" }), e.objectStoreNames.contains(
|
|
1017
|
+
if (e.objectStoreNames.contains(N) || e.createObjectStore(N, { keyPath: "queryHash" }), e.objectStoreNames.contains(j) || e.createObjectStore(j, { keyPath: "key" }), !e.objectStoreNames.contains(E)) {
|
|
998
1018
|
let t = e.createObjectStore(E, {
|
|
999
1019
|
keyPath: "id",
|
|
1000
1020
|
autoIncrement: true
|
|
@@ -1081,14 +1101,14 @@ var ot = 1, T = "documents", R = "mutations", N = "query_cache", V = "sync_meta"
|
|
|
1081
1101
|
* 'lastFullResyncAt', 'leaderTabId'.
|
|
1082
1102
|
*/
|
|
1083
1103
|
async getMeta(e) {
|
|
1084
|
-
let n = await this.assertOpen().get(
|
|
1104
|
+
let n = await this.assertOpen().get(j, e);
|
|
1085
1105
|
return n ? n.value : null;
|
|
1086
1106
|
}
|
|
1087
1107
|
/**
|
|
1088
1108
|
* Armazena ou atualiza um valor na store `sync_meta`.
|
|
1089
1109
|
*/
|
|
1090
1110
|
async setMeta(e, t) {
|
|
1091
|
-
await this.assertOpen().put(
|
|
1111
|
+
await this.assertOpen().put(j, { key: e, value: t });
|
|
1092
1112
|
}
|
|
1093
1113
|
// ─── Conflict log ───────────────────────────────────────────────────────────
|
|
1094
1114
|
/**
|
|
@@ -1390,7 +1410,7 @@ var z = class {
|
|
|
1390
1410
|
async enqueue(e) {
|
|
1391
1411
|
let { collection: t, op: n, payload: o, baseVersion: i, batchId: s, upsert: a } = e, c = e.docId ?? (n === "add" ? ee() : "");
|
|
1392
1412
|
await this.syncSeq();
|
|
1393
|
-
let d = (await this.store.listMutations({ collection: t, docId: c })).filter((h) => h.status === "queued").sort((h,
|
|
1413
|
+
let d = (await this.store.listMutations({ collection: t, docId: c })).filter((h) => h.status === "queued").sort((h, _) => _.seq - h.seq)[0];
|
|
1394
1414
|
if (d !== void 0) {
|
|
1395
1415
|
let h = this.tryCoalesce(d, n, o, s, a);
|
|
1396
1416
|
if (h !== null) {
|
|
@@ -1409,11 +1429,11 @@ var z = class {
|
|
|
1409
1429
|
status: "queued",
|
|
1410
1430
|
batchId: s
|
|
1411
1431
|
};
|
|
1412
|
-
let { coalesced:
|
|
1413
|
-
return await this.store.putMutation(
|
|
1432
|
+
let { coalesced: _ } = h;
|
|
1433
|
+
return await this.store.putMutation(_), _;
|
|
1414
1434
|
}
|
|
1415
1435
|
}
|
|
1416
|
-
let
|
|
1436
|
+
let p = {
|
|
1417
1437
|
seq: this.nextSeq(),
|
|
1418
1438
|
mutationId: ee(),
|
|
1419
1439
|
collection: t,
|
|
@@ -1429,7 +1449,7 @@ var z = class {
|
|
|
1429
1449
|
// bug_0273e4dd: só persiste o flag quando verdadeiro (mantém o doc limpo).
|
|
1430
1450
|
...a ? { upsert: true } : {}
|
|
1431
1451
|
};
|
|
1432
|
-
return await this.store.putMutation(
|
|
1452
|
+
return await this.store.putMutation(p), p;
|
|
1433
1453
|
}
|
|
1434
1454
|
// ─── Leitura da fila ─────────────────────────────────────────────────────────
|
|
1435
1455
|
/**
|
|
@@ -1529,10 +1549,10 @@ var z = class {
|
|
|
1529
1549
|
|
|
1530
1550
|
// src/db/field-value.ts
|
|
1531
1551
|
var te = "__neetru__";
|
|
1532
|
-
function
|
|
1552
|
+
function st() {
|
|
1533
1553
|
return { __neetru__: "serverTimestamp" };
|
|
1534
1554
|
}
|
|
1535
|
-
function
|
|
1555
|
+
function at(r) {
|
|
1536
1556
|
if (typeof r != "number" || !Number.isFinite(r))
|
|
1537
1557
|
throw new TypeError(
|
|
1538
1558
|
`increment(n): n deve ser um n\xFAmero finito (recebido: ${String(r)}).`
|
|
@@ -1548,13 +1568,13 @@ function ye(r) {
|
|
|
1548
1568
|
function ge(r) {
|
|
1549
1569
|
return D(r) && r.__neetru__ === "increment" && typeof r.operand == "number" && Number.isFinite(r.operand);
|
|
1550
1570
|
}
|
|
1551
|
-
function
|
|
1571
|
+
function ct(r, e) {
|
|
1552
1572
|
return ye(r) ? Date.now() : ge(r) ? (typeof e == "number" && Number.isFinite(e) ? e : 0) + r.operand : r;
|
|
1553
1573
|
}
|
|
1554
1574
|
function k(r, e) {
|
|
1555
1575
|
let t = false, n = {};
|
|
1556
1576
|
for (let [o, i] of Object.entries(r))
|
|
1557
|
-
D(i) ? (t = true, n[o] =
|
|
1577
|
+
D(i) ? (t = true, n[o] = ct(i, e?.[o])) : n[o] = i;
|
|
1558
1578
|
return t ? n : r;
|
|
1559
1579
|
}
|
|
1560
1580
|
function ne(r) {
|
|
@@ -1564,11 +1584,11 @@ function ne(r) {
|
|
|
1564
1584
|
}
|
|
1565
1585
|
|
|
1566
1586
|
// src/db/offline/sync-engine.ts
|
|
1567
|
-
var
|
|
1568
|
-
function
|
|
1587
|
+
var lt = 8, dt = 1e3, ut = 300 * 1e3, re = "truncatedCollections";
|
|
1588
|
+
function pt(r) {
|
|
1569
1589
|
return r !== null && ne(r);
|
|
1570
1590
|
}
|
|
1571
|
-
function
|
|
1591
|
+
function ft(r) {
|
|
1572
1592
|
if (r === null) return null;
|
|
1573
1593
|
if (!ne(r)) return r;
|
|
1574
1594
|
let e = {};
|
|
@@ -1770,13 +1790,13 @@ var K = class {
|
|
|
1770
1790
|
}), s.push({ type: "removed", collection: e, doc: { id: t, data: a.data } }));
|
|
1771
1791
|
return;
|
|
1772
1792
|
}
|
|
1773
|
-
let l =
|
|
1793
|
+
let l = ft(i.payload) ?? a?.data ?? {}, d = {
|
|
1774
1794
|
collection: e,
|
|
1775
1795
|
id: t,
|
|
1776
1796
|
data: i.op === "update" ? { ...a?.data ?? {}, ...l } : (
|
|
1777
1797
|
// add/set: se o payload tinha sentinels, o cache otimista (existing.data)
|
|
1778
1798
|
// é a fonte de verdade até o pull; senão usa o payload literal.
|
|
1779
|
-
|
|
1799
|
+
pt(i.payload) ? { ...a?.data ?? {}, ...l } : l
|
|
1780
1800
|
),
|
|
1781
1801
|
meta: {
|
|
1782
1802
|
serverVersion: n,
|
|
@@ -1929,7 +1949,7 @@ var K = class {
|
|
|
1929
1949
|
* pending do doc no cache + registra `lastError`/dispara `onError`.
|
|
1930
1950
|
*/
|
|
1931
1951
|
async _retryOrDeadLetter(e, t, n) {
|
|
1932
|
-
if (e.attempts + 1 <
|
|
1952
|
+
if (e.attempts + 1 < lt) {
|
|
1933
1953
|
await this._queue.markRetry(e.mutationId, t);
|
|
1934
1954
|
return;
|
|
1935
1955
|
}
|
|
@@ -1970,7 +1990,7 @@ var K = class {
|
|
|
1970
1990
|
}
|
|
1971
1991
|
/** Backoff exponencial keyed em `attempts`, com teto `BACKOFF_CAP_MS`. */
|
|
1972
1992
|
_backoffDelayMs(e) {
|
|
1973
|
-
return Math.min(
|
|
1993
|
+
return Math.min(dt * 2 ** (e - 1), ut);
|
|
1974
1994
|
}
|
|
1975
1995
|
// ─── FASE 2 — pull (reconciliar o cache) ─────────────────────────────────────
|
|
1976
1996
|
/**
|
|
@@ -2384,7 +2404,7 @@ var H = class r {
|
|
|
2384
2404
|
};
|
|
2385
2405
|
|
|
2386
2406
|
// src/db/offline/change-bus.ts
|
|
2387
|
-
function
|
|
2407
|
+
function ht(r) {
|
|
2388
2408
|
return `${r.collection}::${r.doc.id}`;
|
|
2389
2409
|
}
|
|
2390
2410
|
var G = class {
|
|
@@ -2432,7 +2452,7 @@ var G = class {
|
|
|
2432
2452
|
if (e.length === 0) return;
|
|
2433
2453
|
let t = /* @__PURE__ */ new Map();
|
|
2434
2454
|
for (let i of e)
|
|
2435
|
-
t.set(
|
|
2455
|
+
t.set(ht(i), i);
|
|
2436
2456
|
let n = Array.from(t.values()), o = /* @__PURE__ */ new Map();
|
|
2437
2457
|
for (let i of n)
|
|
2438
2458
|
o.has(i.collection) || o.set(i.collection, []), o.get(i.collection).push(i);
|
|
@@ -2751,25 +2771,25 @@ var q = class {
|
|
|
2751
2771
|
|
|
2752
2772
|
// src/db/collection-ref.ts
|
|
2753
2773
|
I();
|
|
2754
|
-
function
|
|
2774
|
+
function mt() {
|
|
2755
2775
|
return typeof indexedDB > "u" || typeof window > "u";
|
|
2756
2776
|
}
|
|
2757
2777
|
var ve = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
2758
|
-
function
|
|
2778
|
+
function _t(r) {
|
|
2759
2779
|
if (!ve.test(r))
|
|
2760
|
-
throw new
|
|
2780
|
+
throw new f(
|
|
2761
2781
|
"db_invalid_query",
|
|
2762
2782
|
`Nome de cole\xE7\xE3o inv\xE1lido: "${r}". Deve seguir o padr\xE3o ${ve}.`
|
|
2763
2783
|
);
|
|
2764
2784
|
}
|
|
2765
2785
|
function L(r, e = "id") {
|
|
2766
2786
|
if (!r || typeof r != "string" || r.trim() === "")
|
|
2767
|
-
throw new
|
|
2787
|
+
throw new f(
|
|
2768
2788
|
"db_invalid_query",
|
|
2769
2789
|
`${e} \xE9 obrigat\xF3rio e deve ser uma string n\xE3o-vazia.`
|
|
2770
2790
|
);
|
|
2771
2791
|
}
|
|
2772
|
-
function
|
|
2792
|
+
function yt(r) {
|
|
2773
2793
|
let e = {};
|
|
2774
2794
|
if (r?.where && (e.where = r.where.map((t) => ({
|
|
2775
2795
|
field: t.field,
|
|
@@ -2786,7 +2806,7 @@ function _t(r) {
|
|
|
2786
2806
|
}
|
|
2787
2807
|
return e;
|
|
2788
2808
|
}
|
|
2789
|
-
function
|
|
2809
|
+
function gt(r, e) {
|
|
2790
2810
|
if (r.length < e) return null;
|
|
2791
2811
|
let t = r[r.length - 1];
|
|
2792
2812
|
return t ? btoa(JSON.stringify({ type: "startAfter", docId: t.id })) : null;
|
|
@@ -2833,11 +2853,11 @@ var oe = class {
|
|
|
2833
2853
|
}
|
|
2834
2854
|
/** Constrói um DbListResult para a coleção com query opcional. */
|
|
2835
2855
|
async _buildListResult(e) {
|
|
2836
|
-
let t =
|
|
2856
|
+
let t = yt(e), n = t.limit ?? 20, o = await this._store.listDocs(this._collection, t), i = await this._hasPendingWrites(), s = this._isOnline(), a = this._engine.getSyncState(), c = gt(o.docs, n), l = await this._store.getMeta(re), d = Array.isArray(l) && l.includes(this._collection), u = !s || a.status === "offline" || d, p = i || a.lastSyncedAt === null || u;
|
|
2837
2857
|
return {
|
|
2838
2858
|
docs: o.docs.map((h) => ({ id: h.id, data: h.data })),
|
|
2839
2859
|
nextCursor: c,
|
|
2840
|
-
fromCache:
|
|
2860
|
+
fromCache: p,
|
|
2841
2861
|
stale: u,
|
|
2842
2862
|
hasPendingWrites: i,
|
|
2843
2863
|
changes: [],
|
|
@@ -3011,7 +3031,7 @@ var oe = class {
|
|
|
3011
3031
|
doc: { id: s, data: l }
|
|
3012
3032
|
});
|
|
3013
3033
|
} else if (o.kind === "update") {
|
|
3014
|
-
let s = o.id, a = o.data, c = await this._store.getDoc(i, s), l = c?.meta.deleted ? void 0 : c?.data, d = k(a, l), u = { ...c?.data ?? {}, ...d },
|
|
3034
|
+
let s = o.id, a = o.data, c = await this._store.getDoc(i, s), l = c?.meta.deleted ? void 0 : c?.data, d = k(a, l), u = { ...c?.data ?? {}, ...d }, p = await this._queue.enqueue({
|
|
3015
3035
|
collection: i,
|
|
3016
3036
|
docId: s,
|
|
3017
3037
|
op: "update",
|
|
@@ -3032,7 +3052,7 @@ var oe = class {
|
|
|
3032
3052
|
state: "pending",
|
|
3033
3053
|
pendingMutationIds: [
|
|
3034
3054
|
...c?.meta.pendingMutationIds ?? [],
|
|
3035
|
-
|
|
3055
|
+
p.mutationId
|
|
3036
3056
|
],
|
|
3037
3057
|
deleted: false,
|
|
3038
3058
|
ownerId: c?.meta.ownerId ?? null
|
|
@@ -3176,7 +3196,7 @@ var oe = class {
|
|
|
3176
3196
|
this._store = e.store, this._queue = e.queue, this._bus = e.bus, this._engine = e.engine, this._connectivity = e.connectivity;
|
|
3177
3197
|
}
|
|
3178
3198
|
collection(e) {
|
|
3179
|
-
return
|
|
3199
|
+
return _t(e), new oe(
|
|
3180
3200
|
e,
|
|
3181
3201
|
this._store,
|
|
3182
3202
|
this._queue,
|
|
@@ -3206,7 +3226,7 @@ var oe = class {
|
|
|
3206
3226
|
}
|
|
3207
3227
|
};
|
|
3208
3228
|
async function we(r) {
|
|
3209
|
-
let e =
|
|
3229
|
+
let e = mt() ? new Q() : new V(r.dbName);
|
|
3210
3230
|
await e.open();
|
|
3211
3231
|
let t = new z(e), n = new H(), o = new G(), i = new X({
|
|
3212
3232
|
// Se startOnline=false, injeta um navigator falso
|
|
@@ -3241,9 +3261,9 @@ async function we(r) {
|
|
|
3241
3261
|
}
|
|
3242
3262
|
|
|
3243
3263
|
// src/db/realtime/realtime-client.ts
|
|
3244
|
-
var
|
|
3264
|
+
var bt = 0;
|
|
3245
3265
|
function Se() {
|
|
3246
|
-
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++
|
|
3266
|
+
return typeof globalThis.crypto?.randomUUID == "function" ? globalThis.crypto.randomUUID() : `nrt-sub-${Date.now()}-${++bt}-${Math.random().toString(36).slice(2)}`;
|
|
3247
3267
|
}
|
|
3248
3268
|
var F = class {
|
|
3249
3269
|
// ── configuração ──────────────────────────────────────────────────────────
|
|
@@ -3283,7 +3303,7 @@ var F = class {
|
|
|
3283
3303
|
_pendingFrames = [];
|
|
3284
3304
|
// ── construtor ────────────────────────────────────────────────────────────
|
|
3285
3305
|
constructor(e) {
|
|
3286
|
-
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ??
|
|
3306
|
+
this._gatewayUrl = e.gatewayUrl, this._wsFactory = e.webSocketFactory ?? vt, this._setTimeout = e.setTimeoutFn ?? globalThis.setTimeout.bind(globalThis), this._clearTimeout = e.clearTimeoutFn ?? globalThis.clearTimeout.bind(globalThis), this._backoffBaseMs = e.backoffBaseMs ?? 1e3, this._backoffMaxMs = e.backoffMaxMs ?? 3e4, this._heartbeatIntervalMs = e.heartbeatIntervalMs ?? 25e3, this._ticketProvider = e.ticketProvider, this._dbId = e.dbId, this._connect();
|
|
3287
3307
|
}
|
|
3288
3308
|
// ── API pública ───────────────────────────────────────────────────────────
|
|
3289
3309
|
/**
|
|
@@ -3562,7 +3582,7 @@ var F = class {
|
|
|
3562
3582
|
_detachHandlers(e) {
|
|
3563
3583
|
e.onopen = null, e.onmessage = null, e.onclose = null, e.onerror = null;
|
|
3564
3584
|
}
|
|
3565
|
-
},
|
|
3585
|
+
}, vt = (r) => {
|
|
3566
3586
|
if (typeof WebSocket > "u")
|
|
3567
3587
|
throw new Error(
|
|
3568
3588
|
"[NeetruRealtimeClient] WebSocket n\xE3o dispon\xEDvel neste ambiente. Injete uma implementa\xE7\xE3o via `webSocketFactory` nas op\xE7\xF5es."
|
|
@@ -3572,15 +3592,15 @@ var F = class {
|
|
|
3572
3592
|
|
|
3573
3593
|
// src/db/client-db.ts
|
|
3574
3594
|
I();
|
|
3575
|
-
var
|
|
3576
|
-
function
|
|
3577
|
-
return e._transport ? e._transport : r === "firestore" && e.firestoreTransport ? e.firestoreTransport : r === "nosql-vm" && e.realtimeGatewayUrl ?
|
|
3595
|
+
var zt = (r) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}`, Y = (r, e) => `/api/sdk/v1/datastore/${encodeURIComponent(r)}/${encodeURIComponent(e)}`, Xe = 200;
|
|
3596
|
+
function Kt(r, e, t) {
|
|
3597
|
+
return e._transport ? e._transport : r === "firestore" && e.firestoreTransport ? e.firestoreTransport : r === "nosql-vm" && e.realtimeGatewayUrl ? Ht(e.realtimeGatewayUrl, t, e) : Je(t);
|
|
3578
3598
|
}
|
|
3579
|
-
function
|
|
3599
|
+
function Je(r) {
|
|
3580
3600
|
return {
|
|
3581
3601
|
async pushMutations(e) {
|
|
3582
3602
|
if (!r)
|
|
3583
|
-
throw new
|
|
3603
|
+
throw new f(
|
|
3584
3604
|
"db_unavailable",
|
|
3585
3605
|
"[RestSyncTransport] config n\xE3o dispon\xEDvel \u2014 n\xE3o \xE9 poss\xEDvel enviar ao Core. Inicialize o transporte via createNeetruDb."
|
|
3586
3606
|
);
|
|
@@ -3626,18 +3646,18 @@ function Xe(r) {
|
|
|
3626
3646
|
} catch (a) {
|
|
3627
3647
|
let c = a instanceof Error ? a.message : String(a), l = a?.code, d = a?.status;
|
|
3628
3648
|
if (l === "forbidden" || l === "unauthorized" || l === "not_found" || l === "conflict" || l === "validation_failed" || typeof d == "number" && d >= 400 && d < 500 && d !== 408 && d !== 429) {
|
|
3629
|
-
let
|
|
3649
|
+
let p = l === "forbidden" || l === "unauthorized" ? "rejected_permission" : "rejected_validation";
|
|
3630
3650
|
n.push({
|
|
3631
3651
|
mutationId: s.mutationId,
|
|
3632
3652
|
outcome: "rejected",
|
|
3633
|
-
reason:
|
|
3653
|
+
reason: p,
|
|
3634
3654
|
serverVersion: null,
|
|
3635
3655
|
serverData: null
|
|
3636
3656
|
});
|
|
3637
3657
|
continue;
|
|
3638
3658
|
}
|
|
3639
3659
|
if (n.length === 0)
|
|
3640
|
-
throw new
|
|
3660
|
+
throw new f("db_unavailable", `pushMutations falhou: ${c}`);
|
|
3641
3661
|
break;
|
|
3642
3662
|
}
|
|
3643
3663
|
return { results: n };
|
|
@@ -3654,7 +3674,7 @@ function Xe(r) {
|
|
|
3654
3674
|
try {
|
|
3655
3675
|
l = await t(r, {
|
|
3656
3676
|
method: "GET",
|
|
3657
|
-
path:
|
|
3677
|
+
path: zt(c),
|
|
3658
3678
|
requireAuth: !0,
|
|
3659
3679
|
retries: 2,
|
|
3660
3680
|
headers: o,
|
|
@@ -3662,37 +3682,37 @@ function Xe(r) {
|
|
|
3662
3682
|
// TRUNCADAS — reportadas em `truncatedCollections` p/ o SyncEngine
|
|
3663
3683
|
// (a) NÃO rodar deleção-por-ausência e (b) sinalizar
|
|
3664
3684
|
// `DbListResult.truncated`. Paginação por cursor é tarefa Core (gated).
|
|
3665
|
-
query: { limit:
|
|
3685
|
+
query: { limit: Xe }
|
|
3666
3686
|
});
|
|
3667
|
-
} catch (
|
|
3668
|
-
let h =
|
|
3669
|
-
throw new
|
|
3687
|
+
} catch (p) {
|
|
3688
|
+
let h = p instanceof Error ? p.message : String(p);
|
|
3689
|
+
throw new f(
|
|
3670
3690
|
"db_unavailable",
|
|
3671
3691
|
`[RestSyncTransport] fullResync falhou na cole\xE7\xE3o "${c}": ${h}`
|
|
3672
3692
|
);
|
|
3673
3693
|
}
|
|
3674
3694
|
let d = l, u = Array.isArray(d?.items) ? d.items : [];
|
|
3675
|
-
u.length >=
|
|
3676
|
-
for (let
|
|
3677
|
-
if (!
|
|
3678
|
-
let h =
|
|
3679
|
-
if (!
|
|
3680
|
-
let { id:
|
|
3681
|
-
if (typeof
|
|
3682
|
-
|
|
3683
|
-
else if (
|
|
3684
|
-
|
|
3685
|
-
else if (typeof
|
|
3686
|
-
let C = Date.parse(
|
|
3687
|
-
Number.isNaN(C) || (
|
|
3695
|
+
u.length >= Xe && a.push(c);
|
|
3696
|
+
for (let p of u) {
|
|
3697
|
+
if (!p || typeof p != "object") continue;
|
|
3698
|
+
let h = p, _ = typeof h.id == "string" ? h.id : null;
|
|
3699
|
+
if (!_) continue;
|
|
3700
|
+
let { id: y, ...B } = h, g = i, v = B._updatedAt;
|
|
3701
|
+
if (typeof v == "number")
|
|
3702
|
+
g = v;
|
|
3703
|
+
else if (v !== null && typeof v == "object" && typeof v._seconds == "number")
|
|
3704
|
+
g = v._seconds * 1e3;
|
|
3705
|
+
else if (typeof v == "string") {
|
|
3706
|
+
let C = Date.parse(v);
|
|
3707
|
+
Number.isNaN(C) || (g = C);
|
|
3688
3708
|
}
|
|
3689
|
-
let w = `rest_${
|
|
3709
|
+
let w = `rest_${_}_${g}`;
|
|
3690
3710
|
s.push({
|
|
3691
3711
|
collection: c,
|
|
3692
|
-
id:
|
|
3712
|
+
id: _,
|
|
3693
3713
|
data: B,
|
|
3694
3714
|
serverVersion: w,
|
|
3695
|
-
serverTimestamp:
|
|
3715
|
+
serverTimestamp: g,
|
|
3696
3716
|
deleted: false
|
|
3697
3717
|
});
|
|
3698
3718
|
}
|
|
@@ -3701,10 +3721,10 @@ function Xe(r) {
|
|
|
3701
3721
|
}
|
|
3702
3722
|
};
|
|
3703
3723
|
}
|
|
3704
|
-
function
|
|
3705
|
-
let n =
|
|
3724
|
+
function Ht(r, e, t) {
|
|
3725
|
+
let n = Je(e), o = new F({
|
|
3706
3726
|
gatewayUrl: r,
|
|
3707
|
-
ticketProvider:
|
|
3727
|
+
ticketProvider: Gt(e, t),
|
|
3708
3728
|
dbId: t.dbId,
|
|
3709
3729
|
webSocketFactory: t._wsFactory
|
|
3710
3730
|
});
|
|
@@ -3740,7 +3760,7 @@ function Qt(r, e, t) {
|
|
|
3740
3760
|
}
|
|
3741
3761
|
};
|
|
3742
3762
|
}
|
|
3743
|
-
function
|
|
3763
|
+
function Gt(r, e) {
|
|
3744
3764
|
return async () => {
|
|
3745
3765
|
let { httpRequest: t } = await Promise.resolve().then(() => (W(), U));
|
|
3746
3766
|
return await t(r, {
|
|
@@ -3755,25 +3775,25 @@ function zt(r, e) {
|
|
|
3755
3775
|
});
|
|
3756
3776
|
};
|
|
3757
3777
|
}
|
|
3758
|
-
function
|
|
3778
|
+
function Gn(r, e, t, n) {
|
|
3759
3779
|
return new F({ gatewayUrl: r, ticketProvider: e, dbId: t, webSocketFactory: n });
|
|
3760
3780
|
}
|
|
3761
3781
|
var pe = false;
|
|
3762
|
-
function
|
|
3782
|
+
function Xn() {
|
|
3763
3783
|
pe = false;
|
|
3764
3784
|
}
|
|
3765
|
-
function
|
|
3785
|
+
function Xt(r, e) {
|
|
3766
3786
|
pe || e.dbId && r.env !== "prod" && (typeof window > "u" || typeof console > "u" || typeof console.warn != "function" || (pe = true, console.warn(
|
|
3767
3787
|
'[neetru/sdk] client.db recebeu `dbId` ("' + e.dbId + '") mas ele N\xC3O roteia nem escopa nada no servidor: as escritas do mundo Documentos (add/set/update/remove/list) SEMPRE caem no datastore gen\xE9rico do Core, escopado s\xF3 por tenant/produto (header x-neetru-tenant). `dbId` apenas nomeia o cache offline LOCAL (IndexedDB). ATEN\xC7\xC3O: usar dbIds distintos no MESMO tenant/produto N\xC3O isola os dados no servidor \u2014 eles se misturam (co-mingling). Veja o JSDoc de NeetruDbOptions.dbId.'
|
|
3768
3788
|
)));
|
|
3769
3789
|
}
|
|
3770
|
-
function
|
|
3771
|
-
|
|
3790
|
+
function Jn(r, e = {}) {
|
|
3791
|
+
Xt(r, e);
|
|
3772
3792
|
let t;
|
|
3773
3793
|
e.transport !== void 0 ? t = e.transport : e.engine !== void 0 ? (console.warn(
|
|
3774
3794
|
'[neetru/sdk] NeetruDbOptions.engine est\xE1 depreciado e ser\xE1 removido em v3.0. Use NeetruDbOptions.transport em vez de engine. Valores v\xE1lidos: "rest" | "firestore" | "nosql-vm". Nota: "engine" no SDK configura o TRANSPORTE (REST/Firestore/WebSocket), n\xE3o o storage engine do admin database (firestore-instance, cloud-sql-postgres, \u2026).'
|
|
3775
3795
|
), t = e.engine) : t = "rest";
|
|
3776
|
-
let n =
|
|
3796
|
+
let n = Kt(t, e, r), o = e.dbId ?? "default", i = e.dbName ?? `neetru-db__${r.productId ?? "sdk"}__${o}__${r.env}`, s = null, a = null;
|
|
3777
3797
|
function c() {
|
|
3778
3798
|
return s || (s = we({
|
|
3779
3799
|
dbName: i,
|
|
@@ -3783,15 +3803,15 @@ function Hn(r, e = {}) {
|
|
|
3783
3803
|
}
|
|
3784
3804
|
return {
|
|
3785
3805
|
collection(l) {
|
|
3786
|
-
return a ? a.collection(l) :
|
|
3806
|
+
return a ? a.collection(l) : Jt(l, c);
|
|
3787
3807
|
},
|
|
3788
3808
|
async sql(l, d) {
|
|
3789
3809
|
if (r.env === "dev")
|
|
3790
|
-
throw new
|
|
3810
|
+
throw new f(
|
|
3791
3811
|
"db_unavailable",
|
|
3792
3812
|
"[SDK] db.sql() n\xE3o dispon\xEDvel em NEETRU_ENV=dev. Use `neetru dev` para subir o container Postgres local."
|
|
3793
3813
|
);
|
|
3794
|
-
return (await Promise.resolve().then(() => (
|
|
3814
|
+
return (await Promise.resolve().then(() => (Ge(), He))).createSqlClientFromConfig(r, l, d);
|
|
3795
3815
|
},
|
|
3796
3816
|
get syncState() {
|
|
3797
3817
|
return a?.syncState ?? {
|
|
@@ -3804,8 +3824,8 @@ function Hn(r, e = {}) {
|
|
|
3804
3824
|
onSyncStateChanged(l) {
|
|
3805
3825
|
if (a) return a.onSyncStateChanged(l);
|
|
3806
3826
|
let d = null, u = false;
|
|
3807
|
-
return c().then((
|
|
3808
|
-
u || (d =
|
|
3827
|
+
return c().then((p) => {
|
|
3828
|
+
u || (d = p.onSyncStateChanged(l));
|
|
3809
3829
|
}), () => {
|
|
3810
3830
|
u = true, d?.();
|
|
3811
3831
|
};
|
|
@@ -3822,15 +3842,15 @@ function Hn(r, e = {}) {
|
|
|
3822
3842
|
onError(l) {
|
|
3823
3843
|
if (a) return a.onError(l);
|
|
3824
3844
|
let d = null, u = false;
|
|
3825
|
-
return c().then((
|
|
3826
|
-
u || (d =
|
|
3845
|
+
return c().then((p) => {
|
|
3846
|
+
u || (d = p.onError(l));
|
|
3827
3847
|
}), () => {
|
|
3828
3848
|
u = true, d?.();
|
|
3829
3849
|
};
|
|
3830
3850
|
}
|
|
3831
3851
|
};
|
|
3832
3852
|
}
|
|
3833
|
-
function
|
|
3853
|
+
function Jt(r, e) {
|
|
3834
3854
|
async function t() {
|
|
3835
3855
|
return (await e()).collection(r);
|
|
3836
3856
|
}
|
|
@@ -3908,4 +3928,4 @@ function Ht(r, e) {
|
|
|
3908
3928
|
};
|
|
3909
3929
|
}
|
|
3910
3930
|
|
|
3911
|
-
export { te as NEETRU_SENTINEL_KEY,
|
|
3931
|
+
export { te as NEETRU_SENTINEL_KEY, f as NeetruDbError, Xn as __resetDbIdWarningForTests, Jn as createNeetruDb, Je as createRestSyncTransport, Gn as getWebSocketRealtimeClient, at as increment, D as isFieldSentinel, ge as isIncrementSentinel, ye as isServerTimestampSentinel, st as serverTimestamp };
|