@rebasepro/client 0.14.0 → 0.14.1-canary.g7e666eb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +37 -26
- package/dist/index.es.js.map +1 -1
- package/dist/offline-query.d.ts +3 -3
- package/dist/sdk_query_builder.d.ts +5 -0
- package/package.json +4 -4
- package/src/collection.ts +6 -3
- package/src/offline-query.ts +45 -27
- package/src/sdk_query_builder.ts +9 -1
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_STORAGE_SOURCE_KEY, EntityReference, EntityRelation, GeoPoint, PUBLIC_STORAGE_PREFIX, RebaseApiError, RebaseApiError as RebaseApiError$1, RebaseClientError, RebaseClientError as RebaseClientError$1, Vector, isPublicStoragePath, toCanonicalOp } from "@rebasepro/types";
|
|
2
|
-
import { COMPOSITE_ID_SEPARATOR, QueryBuilder, RebasePaginationError, and, buildCompositeId, collectAllPages, cond, or, paginateFind, resolveFindWindow, serializeFilter, serializeLogicalCondition, serializeOrderBy } from "@rebasepro/common";
|
|
2
|
+
import { COMPOSITE_ID_SEPARATOR, QueryBuilder, RebasePaginationError, and, buildCompositeId, collectAllPages, cond, normalizeOrderBy, or, paginateFind, resolveFindWindow, serializeFilter, serializeLogicalCondition, serializeOrderBy } from "@rebasepro/common";
|
|
3
3
|
import { toSnakeCase } from "@rebasepro/utils";
|
|
4
4
|
//#region src/reviver.ts
|
|
5
5
|
function rebaseReviver(_key, value) {
|
|
@@ -1277,9 +1277,15 @@ var SDKQueryBuilder = class {
|
|
|
1277
1277
|
}
|
|
1278
1278
|
/**
|
|
1279
1279
|
* Order the results by a specific column.
|
|
1280
|
+
*
|
|
1281
|
+
* Call it again to add a tie-breaker rather than replace the sort: keys
|
|
1282
|
+
* apply in the order they were added, so
|
|
1283
|
+
* `.orderBy("roles").orderBy("created_at", "desc")` sorts by role and
|
|
1284
|
+
* shows the newest first within each one.
|
|
1280
1285
|
*/
|
|
1281
1286
|
orderBy(column, direction = "asc") {
|
|
1282
|
-
this.params.orderBy
|
|
1287
|
+
const existing = normalizeOrderBy(this.params.orderBy) ?? [];
|
|
1288
|
+
this.params.orderBy = [...existing, [column, direction]];
|
|
1283
1289
|
return this;
|
|
1284
1290
|
}
|
|
1285
1291
|
/**
|
|
@@ -1596,8 +1602,7 @@ function createCollectionClient(transport, slug, ws) {
|
|
|
1596
1602
|
logical: params?.logical,
|
|
1597
1603
|
limit: params?.limit,
|
|
1598
1604
|
offset: window.driverOffset,
|
|
1599
|
-
orderBy: params?.orderBy
|
|
1600
|
-
order: params?.orderBy?.[1],
|
|
1605
|
+
orderBy: normalizeOrderBy(params?.orderBy),
|
|
1601
1606
|
searchString: params?.searchString,
|
|
1602
1607
|
searchExplain: params?.searchExplain
|
|
1603
1608
|
}, (incomingRows) => {
|
|
@@ -4101,23 +4106,30 @@ function matchesParams(row, params) {
|
|
|
4101
4106
|
* not shuffle rows between pages.
|
|
4102
4107
|
*/
|
|
4103
4108
|
function sortRows(rows, orderBy) {
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
const sign = direction === "desc" ? -1 : 1;
|
|
4109
|
+
const keys = normalizeOrderBy(orderBy);
|
|
4110
|
+
if (!keys) return rows;
|
|
4107
4111
|
return rows.sort((a, b) => {
|
|
4108
|
-
const
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
const bNull = isNullish(toComparable(bv));
|
|
4112
|
-
if (aNull || bNull) {
|
|
4113
|
-
if (aNull && bNull) return tiebreak(a, b);
|
|
4114
|
-
return (aNull ? 1 : -1) * (direction === "desc" ? -1 : 1);
|
|
4112
|
+
for (const [field, direction = "asc"] of keys) {
|
|
4113
|
+
const cmp = compareOnKey(a, b, field, direction);
|
|
4114
|
+
if (cmp !== 0) return cmp;
|
|
4115
4115
|
}
|
|
4116
|
-
|
|
4117
|
-
if (cmp === void 0 || cmp === 0) return tiebreak(a, b);
|
|
4118
|
-
return cmp * sign;
|
|
4116
|
+
return tiebreak(a, b);
|
|
4119
4117
|
});
|
|
4120
4118
|
}
|
|
4119
|
+
/** One key's verdict: negative, positive, or 0 for "these two are equal here". */
|
|
4120
|
+
function compareOnKey(a, b, field, direction) {
|
|
4121
|
+
const av = a[field];
|
|
4122
|
+
const bv = b[field];
|
|
4123
|
+
const aNull = isNullish(toComparable(av));
|
|
4124
|
+
const bNull = isNullish(toComparable(bv));
|
|
4125
|
+
if (aNull || bNull) {
|
|
4126
|
+
if (aNull && bNull) return 0;
|
|
4127
|
+
return (aNull ? 1 : -1) * (direction === "desc" ? -1 : 1);
|
|
4128
|
+
}
|
|
4129
|
+
const cmp = compareValues(av, bv);
|
|
4130
|
+
if (cmp === void 0 || cmp === 0) return 0;
|
|
4131
|
+
return cmp * (direction === "desc" ? -1 : 1);
|
|
4132
|
+
}
|
|
4121
4133
|
function tiebreak(a, b) {
|
|
4122
4134
|
return compareValues(a.id, b.id) ?? 0;
|
|
4123
4135
|
}
|
|
@@ -4214,17 +4226,16 @@ function isExactlyEvaluable(params) {
|
|
|
4214
4226
|
* comparator.
|
|
4215
4227
|
*/
|
|
4216
4228
|
function isLocallySortable(rows, orderBy) {
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4229
|
+
const keys = normalizeOrderBy(orderBy);
|
|
4230
|
+
if (!keys) return true;
|
|
4231
|
+
return keys.every(([field]) => rows.every((row) => {
|
|
4220
4232
|
const value = toComparable(row[field]);
|
|
4221
|
-
if (isNullish(value))
|
|
4222
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
4223
|
-
if (typeof value === "bigint")
|
|
4224
|
-
if (typeof value === "string" && value.trim() !== "" && !Number.isNaN(Number(value)))
|
|
4233
|
+
if (isNullish(value)) return true;
|
|
4234
|
+
if (typeof value === "number" || typeof value === "boolean") return true;
|
|
4235
|
+
if (typeof value === "bigint") return true;
|
|
4236
|
+
if (typeof value === "string" && value.trim() !== "" && !Number.isNaN(Number(value))) return true;
|
|
4225
4237
|
return false;
|
|
4226
|
-
}
|
|
4227
|
-
return true;
|
|
4238
|
+
}));
|
|
4228
4239
|
}
|
|
4229
4240
|
/** Run a full query — filter, sort, paginate — over a set of rows. */
|
|
4230
4241
|
function runLocalQuery(rows, params) {
|