@rebasepro/client 0.29.1 → 0.29.3
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/auth.d.ts +1 -1
- package/dist/client-contract.types.d.ts +57 -0
- package/dist/collection.d.ts +9 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +42 -30
- package/dist/index.es.js.map +1 -1
- package/dist/{offline-Cy6woFyt.js → offline-B6J1YUWF.js} +69 -9
- package/dist/offline-B6J1YUWF.js.map +1 -0
- package/dist/offline-connectivity.d.ts +8 -2
- package/dist/{offline-store-C2Sy3Kwl.js → offline-store-B7F5mimt.js} +51 -6
- package/dist/offline-store-B7F5mimt.js.map +1 -0
- package/dist/offline.d.ts +9 -0
- package/dist/transport.d.ts +15 -1
- package/dist/websocket.d.ts +34 -1
- package/package.json +4 -4
- package/dist/offline-Cy6woFyt.js.map +0 -1
- package/dist/offline-store-C2Sy3Kwl.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as byIdRead, c as invalidBulkBody, d as RebaseApiError$1, f as buildQueryString, g as rebaseReviver, l as SDKQueryBuilder, n as MemoryOfflineStore, r as createMutationId, s as etagOf, t as IndexedDBOfflineStore, u as RebaseClientError$1 } from "./offline-store-
|
|
2
|
-
import { EntityReference, EntityRelation, GeoPoint, Vector, hasFieldOperation, isUnsupported, parseRelationAggregateSort, toCanonicalOp } from "@rebasepro/types";
|
|
1
|
+
import { a as byIdRead, c as invalidBulkBody, d as RebaseApiError$1, f as buildQueryString, g as rebaseReviver, l as SDKQueryBuilder, n as MemoryOfflineStore, r as createMutationId, s as etagOf, t as IndexedDBOfflineStore, u as RebaseClientError$1 } from "./offline-store-B7F5mimt.js";
|
|
2
|
+
import { EntityReference, EntityRelation, GeoPoint, Vector, hasFieldOperation, isUnsupported, parseCaseFoldedFieldPath, parseRelationAggregateSort, toCanonicalOp } from "@rebasepro/types";
|
|
3
3
|
import { collectAllPages, normalizeOrderBy, paginateFind, resolveFindWindow, withETag } from "@rebasepro/common";
|
|
4
4
|
import { splitSearchTerms, unref } from "@rebasepro/utils";
|
|
5
5
|
//#region src/offline-codec.ts
|
|
@@ -539,6 +539,10 @@ function matchesOperator(rowValue, op, filterValue) {
|
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
function isTuple(value) {
|
|
542
|
+
if (Array.isArray(value) && value.length === 1 && typeof value[0] === "string") {
|
|
543
|
+
const op = toCanonicalOp(value[0]);
|
|
544
|
+
return op === "is-null" || op === "is-not-null";
|
|
545
|
+
}
|
|
542
546
|
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && toCanonicalOp(value[0]) !== void 0;
|
|
543
547
|
}
|
|
544
548
|
/**
|
|
@@ -574,6 +578,19 @@ function conditionTuples(condition) {
|
|
|
574
578
|
unreadable: tuples.length !== condition.length || tuples.length === 0
|
|
575
579
|
};
|
|
576
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* The value a filter key reads off a row: the field itself, or — for
|
|
583
|
+
* `lower(field)` / `upper(field)` — the field's text folded to that case.
|
|
584
|
+
* JavaScript's folding is not the database's for every script, so a query that
|
|
585
|
+
* folds is never called exact ({@link isExactlyEvaluable}).
|
|
586
|
+
*/
|
|
587
|
+
function filterValueOf(row, field) {
|
|
588
|
+
const folded = parseCaseFoldedFieldPath(field);
|
|
589
|
+
if (!folded) return row[field];
|
|
590
|
+
const value = row[folded.field];
|
|
591
|
+
if (value === null || value === void 0) return value;
|
|
592
|
+
return folded.fn === "lower" ? String(value).toLowerCase() : String(value).toUpperCase();
|
|
593
|
+
}
|
|
577
594
|
/** Evaluate a `where` clause: every field, and every tuple on a field, AND-ed. */
|
|
578
595
|
function matchesWhere(row, where) {
|
|
579
596
|
if (!where) return true;
|
|
@@ -581,7 +598,7 @@ function matchesWhere(row, where) {
|
|
|
581
598
|
const { tuples } = conditionTuples(condition);
|
|
582
599
|
for (const [rawOp, value] of tuples) {
|
|
583
600
|
const op = toCanonicalOp(rawOp) ?? rawOp;
|
|
584
|
-
if (!matchesOperator(row
|
|
601
|
+
if (!matchesOperator(filterValueOf(row, field), op, value)) return false;
|
|
585
602
|
}
|
|
586
603
|
}
|
|
587
604
|
return true;
|
|
@@ -595,7 +612,7 @@ function matchesLogical(row, condition) {
|
|
|
595
612
|
return condition.type === "or" ? children.some((c) => matchesLogical(row, c)) : children.every((c) => matchesLogical(row, c));
|
|
596
613
|
}
|
|
597
614
|
const op = toCanonicalOp(condition.operator) ?? condition.operator;
|
|
598
|
-
return matchesOperator(row
|
|
615
|
+
return matchesOperator(filterValueOf(row, condition.column), op, condition.value);
|
|
599
616
|
}
|
|
600
617
|
/**
|
|
601
618
|
* Approximate the server's full-text search with a case-insensitive substring
|
|
@@ -766,15 +783,18 @@ function isExactlyEvaluable(params) {
|
|
|
766
783
|
if (logicalReachesThroughRelation(params.logical)) return false;
|
|
767
784
|
return true;
|
|
768
785
|
}
|
|
769
|
-
/**
|
|
786
|
+
/**
|
|
787
|
+
* Does any filter key reach outside this row — `applications.status` — or fold
|
|
788
|
+
* a field's case, which the database does by its own rules?
|
|
789
|
+
*/
|
|
770
790
|
function whereReachesThroughRelation(where) {
|
|
771
|
-
return where ? Object.keys(where).some((field) => field.includes(".")) : false;
|
|
791
|
+
return where ? Object.keys(where).some((field) => field.includes(".") || parseCaseFoldedFieldPath(field) !== void 0) : false;
|
|
772
792
|
}
|
|
773
793
|
/** The same question, through an `and(...)`/`or(...)` tree. */
|
|
774
794
|
function logicalReachesThroughRelation(condition, depth = 0) {
|
|
775
795
|
if (!condition || depth > 32) return false;
|
|
776
796
|
if ("type" in condition) return (condition.conditions ?? []).some((c) => logicalReachesThroughRelation(c, depth + 1));
|
|
777
|
-
return typeof condition.column === "string" && condition.column.includes(".");
|
|
797
|
+
return typeof condition.column === "string" && (condition.column.includes(".") || parseCaseFoldedFieldPath(condition.column) !== void 0);
|
|
778
798
|
}
|
|
779
799
|
/**
|
|
780
800
|
* Would sorting `rows` locally reproduce the order the server would have sent?
|
|
@@ -1378,6 +1398,16 @@ var OfflineManager = class {
|
|
|
1378
1398
|
* user's, unconfirmed: it would go out with no credentials, as nobody. It
|
|
1379
1399
|
* queues for its author instead, as it does offline.
|
|
1380
1400
|
*/
|
|
1401
|
+
/**
|
|
1402
|
+
* A filtered write runs on the server or not at all: refused while writes
|
|
1403
|
+
* are being queued, and while this collection has queued writes the
|
|
1404
|
+
* server has not seen — the filter would be judged against rows they are
|
|
1405
|
+
* about to change.
|
|
1406
|
+
*/
|
|
1407
|
+
assertOnlineForFilteredWrite(slug, method) {
|
|
1408
|
+
if (this.sendsWrites() && !this.hasPendingIn(slug)) return;
|
|
1409
|
+
throw new RebaseClientError$1(`${method}() on "${slug}" needs the server: which rows a filter matches is the server's answer, so a filtered write is not queued offline, nor sent ahead of writes this collection still has queued.`, { code: "OFFLINE_FILTERED_WRITE_UNSUPPORTED" });
|
|
1410
|
+
}
|
|
1381
1411
|
sendsWrites() {
|
|
1382
1412
|
return this.connectivity.shouldAttempt() && !this.unverified;
|
|
1383
1413
|
}
|
|
@@ -1625,7 +1655,7 @@ var OfflineManager = class {
|
|
|
1625
1655
|
if (this.sendsWrites()) try {
|
|
1626
1656
|
const row = await inner.upsert(data, options);
|
|
1627
1657
|
this.connectivity.markSuccess();
|
|
1628
|
-
await this.ingest(slug, [row], ticket);
|
|
1658
|
+
if (row) await this.ingest(slug, [row], ticket);
|
|
1629
1659
|
this.notifyCollection(slug);
|
|
1630
1660
|
this.scheduleRefresh(slug);
|
|
1631
1661
|
return row;
|
|
@@ -1634,6 +1664,7 @@ var OfflineManager = class {
|
|
|
1634
1664
|
this.connectivity.markFailure();
|
|
1635
1665
|
}
|
|
1636
1666
|
const rowId = data.id;
|
|
1667
|
+
if (options?.where || options?.ignoreDuplicates) throw new RebaseClientError$1(`Cannot upsert into "${slug}" with \`where\` or \`ignoreDuplicates\` while offline: whether the stored row is kept is decided by the server, on the row it holds.`, { code: "OFFLINE_UPSERT_UNSUPPORTED" });
|
|
1637
1668
|
if (options?.onConflict?.length || rowId === void 0) throw new RebaseClientError$1(`Cannot upsert into "${slug}" while offline: the row it would replace can only be found by the server. Upserting on the primary key, with the key in the row, is queued; upserting on a natural key is not.`, { code: "OFFLINE_UPSERT_UNSUPPORTED" });
|
|
1638
1669
|
const row = optimisticRow(data, rowId);
|
|
1639
1670
|
await this.enqueue({
|
|
@@ -1686,6 +1717,31 @@ var OfflineManager = class {
|
|
|
1686
1717
|
this.notifyCollection(slug);
|
|
1687
1718
|
return optimistic;
|
|
1688
1719
|
},
|
|
1720
|
+
/**
|
|
1721
|
+
* Online only. Which rows a filter matches is the server's answer —
|
|
1722
|
+
* the local store holds a subset of them — so a filtered write is
|
|
1723
|
+
* never applied locally or queued. The rows it updated are folded
|
|
1724
|
+
* into the store; a filtered delete refreshes the collection.
|
|
1725
|
+
*/
|
|
1726
|
+
updateWhere: async (query, data, options) => {
|
|
1727
|
+
const ticket = this.ticket() ?? await this.nextTicket();
|
|
1728
|
+
await this.ensureCollection(slug);
|
|
1729
|
+
this.assertOnlineForFilteredWrite(slug, "updateWhere");
|
|
1730
|
+
const rows = await inner.updateWhere(query, data, options);
|
|
1731
|
+
this.connectivity.markSuccess();
|
|
1732
|
+
await this.ingest(slug, rows, ticket);
|
|
1733
|
+
this.notifyCollection(slug);
|
|
1734
|
+
this.scheduleRefresh(slug);
|
|
1735
|
+
return rows;
|
|
1736
|
+
},
|
|
1737
|
+
deleteWhere: async (query, options) => {
|
|
1738
|
+
await this.ensureCollection(slug);
|
|
1739
|
+
this.assertOnlineForFilteredWrite(slug, "deleteWhere");
|
|
1740
|
+
const deleted = await inner.deleteWhere(query, options);
|
|
1741
|
+
this.connectivity.markSuccess();
|
|
1742
|
+
this.scheduleRefresh(slug);
|
|
1743
|
+
return deleted;
|
|
1744
|
+
},
|
|
1689
1745
|
deleteMany: async (ids, options) => {
|
|
1690
1746
|
const ticket = this.ticket() ?? await this.nextTicket();
|
|
1691
1747
|
await this.ensureCollection(slug);
|
|
@@ -2732,6 +2788,10 @@ var OfflineManager = class {
|
|
|
2732
2788
|
hasPending(slug, id) {
|
|
2733
2789
|
return this.pendingIds(slug)?.writes.has(String(id)) ?? false;
|
|
2734
2790
|
}
|
|
2791
|
+
/** Does this collection have any write the server has not seen? */
|
|
2792
|
+
hasPendingIn(slug) {
|
|
2793
|
+
return (this.pendingIds(slug)?.writes.size ?? 0) > 0;
|
|
2794
|
+
}
|
|
2735
2795
|
/** Is this row one the server has never been told about? */
|
|
2736
2796
|
isLocallyCreated(slug, idKey) {
|
|
2737
2797
|
return this.pendingIds(slug)?.creates.has(idKey) ?? false;
|
|
@@ -3427,4 +3487,4 @@ var OfflineManager = class {
|
|
|
3427
3487
|
//#endregion
|
|
3428
3488
|
export { OfflineManager };
|
|
3429
3489
|
|
|
3430
|
-
//# sourceMappingURL=offline-
|
|
3490
|
+
//# sourceMappingURL=offline-B6J1YUWF.js.map
|