@neetru/sdk 3.0.2 → 3.1.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 +554 -530
- package/dist/auth.cjs +60 -39
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -2
- package/dist/auth.d.ts +1 -2
- package/dist/auth.mjs +60 -39
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.d.cts +1 -2
- package/dist/catalog.d.ts +1 -2
- package/dist/checkout.d.cts +1 -2
- package/dist/checkout.d.ts +1 -2
- package/dist/db-react.cjs +15 -5
- package/dist/db-react.cjs.map +1 -1
- package/dist/db-react.d.cts +35 -13
- package/dist/db-react.d.ts +35 -13
- package/dist/db-react.mjs +15 -5
- package/dist/db-react.mjs.map +1 -1
- package/dist/db.cjs +71 -50
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +1 -2
- package/dist/db.d.ts +1 -2
- package/dist/db.mjs +71 -50
- package/dist/db.mjs.map +1 -1
- package/dist/entitlements.d.cts +1 -2
- package/dist/entitlements.d.ts +1 -2
- package/dist/firestore-compat.cjs +399 -0
- package/dist/firestore-compat.cjs.map +1 -0
- package/dist/firestore-compat.d.cts +294 -0
- package/dist/firestore-compat.d.ts +294 -0
- package/dist/firestore-compat.mjs +371 -0
- package/dist/firestore-compat.mjs.map +1 -0
- package/dist/index.cjs +72 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +72 -51
- package/dist/index.mjs.map +1 -1
- package/dist/mocks.d.cts +1 -2
- package/dist/mocks.d.ts +1 -2
- package/dist/notifications.d.cts +1 -2
- package/dist/notifications.d.ts +1 -2
- package/dist/react.cjs +267 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +117 -3
- package/dist/react.d.ts +117 -3
- package/dist/react.mjs +265 -1
- package/dist/react.mjs.map +1 -1
- package/dist/support.d.cts +1 -2
- package/dist/support.d.ts +1 -2
- package/dist/telemetry.d.cts +1 -2
- package/dist/telemetry.d.ts +1 -2
- package/dist/{types-D7zVkO3n.d.ts → types-BRv8wBxX.d.ts} +581 -2
- package/dist/{types-Dc4bjrrt.d.cts → types-nwErcRX8.d.cts} +581 -2
- package/dist/usage.d.cts +1 -2
- package/dist/usage.d.ts +1 -2
- package/dist/webhooks.d.cts +1 -2
- package/dist/webhooks.d.ts +1 -2
- package/package.json +156 -151
- package/dist/collection-ref-BDdfD87k.d.cts +0 -581
- package/dist/collection-ref-BDdfD87k.d.ts +0 -581
package/dist/db.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, K as SqlOptions, a7 as createNeetruDb, a9 as createRestSyncTransport, ab as getWebSocketRealtimeClient } from './types-Dc4bjrrt.cjs';
|
|
1
|
+
export { i as ConflictRecord, j as CreateOfflineDocumentsOptions, l as DbBatchOp, m as DbChangeType, n as DbCollectionRef, o as DbDoc, p as DbDocRef, q as DbGetResult, r as DbListResult, t as DbQuery, u as DbSqlLease, w as DbWhereFilter, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, G as NeetruDb, H as NeetruDbDocuments, J as NeetruDbEngine, K as NeetruDbError, O as NeetruDbErrorCode, P as NeetruDbOptions, Q as NeetruDbTransport, S as NeetruSqlClient, $ as RealtimeTransport, a3 as ServerTimestampSentinel, a5 as SqlOptions, aa as SyncState, ap as WithFieldSentinels, ar as createNeetruDb, at as createRestSyncTransport, av as getWebSocketRealtimeClient, aw as increment, ax as isFieldSentinel, ay as isIncrementSentinel, az as isServerTimestampSentinel, aA as serverTimestamp } from './types-nwErcRX8.cjs';
|
|
3
2
|
import 'drizzle-orm/node-postgres';
|
|
4
3
|
import './errors.cjs';
|
package/dist/db.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, K as SqlOptions, a7 as createNeetruDb, a9 as createRestSyncTransport, ab as getWebSocketRealtimeClient } from './types-D7zVkO3n.js';
|
|
1
|
+
export { i as ConflictRecord, j as CreateOfflineDocumentsOptions, l as DbBatchOp, m as DbChangeType, n as DbCollectionRef, o as DbDoc, p as DbDocRef, q as DbGetResult, r as DbListResult, t as DbQuery, u as DbSqlLease, w as DbWhereFilter, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, G as NeetruDb, H as NeetruDbDocuments, J as NeetruDbEngine, K as NeetruDbError, O as NeetruDbErrorCode, P as NeetruDbOptions, Q as NeetruDbTransport, S as NeetruSqlClient, $ as RealtimeTransport, a3 as ServerTimestampSentinel, a5 as SqlOptions, aa as SyncState, ap as WithFieldSentinels, ar as createNeetruDb, at as createRestSyncTransport, av as getWebSocketRealtimeClient, aw as increment, ax as isFieldSentinel, ay as isIncrementSentinel, az as isServerTimestampSentinel, aA as serverTimestamp } from './types-BRv8wBxX.js';
|
|
3
2
|
import 'drizzle-orm/node-postgres';
|
|
4
3
|
import './errors.js';
|
package/dist/db.mjs
CHANGED
|
@@ -1350,7 +1350,71 @@ var MutationQueue = class {
|
|
|
1350
1350
|
}
|
|
1351
1351
|
};
|
|
1352
1352
|
|
|
1353
|
+
// src/db/field-value.ts
|
|
1354
|
+
var NEETRU_SENTINEL_KEY = "__neetru__";
|
|
1355
|
+
function serverTimestamp() {
|
|
1356
|
+
return { __neetru__: "serverTimestamp" };
|
|
1357
|
+
}
|
|
1358
|
+
function increment(n) {
|
|
1359
|
+
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
1360
|
+
throw new TypeError(
|
|
1361
|
+
`increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
return { __neetru__: "increment", operand: n };
|
|
1365
|
+
}
|
|
1366
|
+
function isFieldSentinel(v) {
|
|
1367
|
+
return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
|
|
1368
|
+
}
|
|
1369
|
+
function isServerTimestampSentinel(v) {
|
|
1370
|
+
return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
|
|
1371
|
+
}
|
|
1372
|
+
function isIncrementSentinel(v) {
|
|
1373
|
+
return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
|
|
1374
|
+
}
|
|
1375
|
+
function resolveSentinelLocally(value, baseValue) {
|
|
1376
|
+
if (isServerTimestampSentinel(value)) {
|
|
1377
|
+
return Date.now();
|
|
1378
|
+
}
|
|
1379
|
+
if (isIncrementSentinel(value)) {
|
|
1380
|
+
const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
|
|
1381
|
+
return base + value.operand;
|
|
1382
|
+
}
|
|
1383
|
+
return value;
|
|
1384
|
+
}
|
|
1385
|
+
function resolveSentinelsLocally(data, existing) {
|
|
1386
|
+
let touched = false;
|
|
1387
|
+
const out = {};
|
|
1388
|
+
for (const [k, v] of Object.entries(data)) {
|
|
1389
|
+
if (isFieldSentinel(v)) {
|
|
1390
|
+
touched = true;
|
|
1391
|
+
out[k] = resolveSentinelLocally(v, existing?.[k]);
|
|
1392
|
+
} else {
|
|
1393
|
+
out[k] = v;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return touched ? out : data;
|
|
1397
|
+
}
|
|
1398
|
+
function hasFieldSentinel(data) {
|
|
1399
|
+
for (const v of Object.values(data)) {
|
|
1400
|
+
if (isFieldSentinel(v)) return true;
|
|
1401
|
+
}
|
|
1402
|
+
return false;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1353
1405
|
// src/db/offline/sync-engine.ts
|
|
1406
|
+
function hasSentinels(payload) {
|
|
1407
|
+
return payload !== null && hasFieldSentinel(payload);
|
|
1408
|
+
}
|
|
1409
|
+
function sanitizeSentinelPayload(payload) {
|
|
1410
|
+
if (payload === null) return null;
|
|
1411
|
+
if (!hasFieldSentinel(payload)) return payload;
|
|
1412
|
+
const out = {};
|
|
1413
|
+
for (const [k, v] of Object.entries(payload)) {
|
|
1414
|
+
if (!isFieldSentinel(v)) out[k] = v;
|
|
1415
|
+
}
|
|
1416
|
+
return out;
|
|
1417
|
+
}
|
|
1354
1418
|
var SyncEngine = class {
|
|
1355
1419
|
_store;
|
|
1356
1420
|
_queue;
|
|
@@ -1558,11 +1622,16 @@ var SyncEngine = class {
|
|
|
1558
1622
|
}
|
|
1559
1623
|
return;
|
|
1560
1624
|
}
|
|
1561
|
-
const
|
|
1625
|
+
const literalPayload = sanitizeSentinelPayload(mut.payload);
|
|
1626
|
+
const newData = literalPayload ?? (existing?.data ?? {});
|
|
1562
1627
|
const updatedDoc = {
|
|
1563
1628
|
collection,
|
|
1564
1629
|
id: docId,
|
|
1565
|
-
data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } :
|
|
1630
|
+
data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : (
|
|
1631
|
+
// add/set: se o payload tinha sentinels, o cache otimista (existing.data)
|
|
1632
|
+
// é a fonte de verdade até o pull; senão usa o payload literal.
|
|
1633
|
+
hasSentinels(mut.payload) ? { ...existing?.data ?? {}, ...newData } : newData
|
|
1634
|
+
),
|
|
1566
1635
|
meta: {
|
|
1567
1636
|
serverVersion,
|
|
1568
1637
|
updatedAtServer: serverTimestamp2,
|
|
@@ -2644,54 +2713,6 @@ var TabCoordinator = class {
|
|
|
2644
2713
|
|
|
2645
2714
|
// src/db/collection-ref.ts
|
|
2646
2715
|
init_db_errors();
|
|
2647
|
-
|
|
2648
|
-
// src/db/field-value.ts
|
|
2649
|
-
var NEETRU_SENTINEL_KEY = "__neetru__";
|
|
2650
|
-
function serverTimestamp() {
|
|
2651
|
-
return { __neetru__: "serverTimestamp" };
|
|
2652
|
-
}
|
|
2653
|
-
function increment(n) {
|
|
2654
|
-
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
2655
|
-
throw new TypeError(
|
|
2656
|
-
`increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
|
|
2657
|
-
);
|
|
2658
|
-
}
|
|
2659
|
-
return { __neetru__: "increment", operand: n };
|
|
2660
|
-
}
|
|
2661
|
-
function isFieldSentinel(v) {
|
|
2662
|
-
return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
|
|
2663
|
-
}
|
|
2664
|
-
function isServerTimestampSentinel(v) {
|
|
2665
|
-
return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
|
|
2666
|
-
}
|
|
2667
|
-
function isIncrementSentinel(v) {
|
|
2668
|
-
return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
|
|
2669
|
-
}
|
|
2670
|
-
function resolveSentinelLocally(value, baseValue) {
|
|
2671
|
-
if (isServerTimestampSentinel(value)) {
|
|
2672
|
-
return Date.now();
|
|
2673
|
-
}
|
|
2674
|
-
if (isIncrementSentinel(value)) {
|
|
2675
|
-
const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
|
|
2676
|
-
return base + value.operand;
|
|
2677
|
-
}
|
|
2678
|
-
return value;
|
|
2679
|
-
}
|
|
2680
|
-
function resolveSentinelsLocally(data, existing) {
|
|
2681
|
-
let touched = false;
|
|
2682
|
-
const out = {};
|
|
2683
|
-
for (const [k, v] of Object.entries(data)) {
|
|
2684
|
-
if (isFieldSentinel(v)) {
|
|
2685
|
-
touched = true;
|
|
2686
|
-
out[k] = resolveSentinelLocally(v, existing?.[k]);
|
|
2687
|
-
} else {
|
|
2688
|
-
out[k] = v;
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
return touched ? out : data;
|
|
2692
|
-
}
|
|
2693
|
-
|
|
2694
|
-
// src/db/collection-ref.ts
|
|
2695
2716
|
function isIndexedDBUnavailable() {
|
|
2696
2717
|
return typeof indexedDB === "undefined" || typeof window === "undefined";
|
|
2697
2718
|
}
|