@spacelr/sdk 0.10.5 → 0.10.7
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.d.mts +47 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.js +69 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -310,18 +310,27 @@ var HttpClient = class {
|
|
|
310
310
|
}
|
|
311
311
|
throwHttpError(statusCode, body) {
|
|
312
312
|
const apiBody = body;
|
|
313
|
-
const message = apiBody.error?.message ?? `HTTP ${statusCode}`;
|
|
314
|
-
const code = apiBody.error?.code ?? `HTTP_${statusCode}`;
|
|
315
|
-
const details = apiBody.error?.details;
|
|
316
313
|
const flatBody = body;
|
|
314
|
+
const flatMessage = (() => {
|
|
315
|
+
const m = flatBody["message"];
|
|
316
|
+
if (typeof m === "string" && m.length > 0) return m;
|
|
317
|
+
if (Array.isArray(m)) {
|
|
318
|
+
const parts = m.filter((x) => typeof x === "string");
|
|
319
|
+
if (parts.length > 0) return parts.join("; ");
|
|
320
|
+
}
|
|
321
|
+
return void 0;
|
|
322
|
+
})();
|
|
323
|
+
const message = apiBody.error?.message ?? flatMessage ?? `HTTP ${statusCode}`;
|
|
324
|
+
const code = apiBody.error?.code ?? `HTTP_${statusCode}`;
|
|
325
|
+
const details = apiBody.error?.details ?? (flatMessage !== void 0 ? flatBody : void 0);
|
|
317
326
|
if (statusCode === 400 && flatBody["errorCode"] === "SEARCH_FILTER_REQUIRED") {
|
|
318
|
-
const
|
|
327
|
+
const flatMessage2 = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
|
|
319
328
|
const missingFields = Array.isArray(flatBody["missingFields"]) ? flatBody["missingFields"] : [];
|
|
320
|
-
throw new SpacelrSearchFilterRequiredError(
|
|
329
|
+
throw new SpacelrSearchFilterRequiredError(flatMessage2, { missingFields });
|
|
321
330
|
}
|
|
322
331
|
if (statusCode === 400 && flatBody["errorCode"] === "SCAN_LIMIT_EXCEEDED") {
|
|
323
|
-
const
|
|
324
|
-
throw new SpacelrScanLimitExceededError(
|
|
332
|
+
const flatMessage2 = typeof flatBody["message"] === "string" ? flatBody["message"] : message;
|
|
333
|
+
throw new SpacelrScanLimitExceededError(flatMessage2);
|
|
325
334
|
}
|
|
326
335
|
if (statusCode === 401 || statusCode === 403) {
|
|
327
336
|
throw new SpacelrAuthError(message, statusCode, details);
|
|
@@ -2268,6 +2277,9 @@ function isTimelineSourceStats(value) {
|
|
|
2268
2277
|
}
|
|
2269
2278
|
|
|
2270
2279
|
// libs/sdk/src/modules/database.module.ts
|
|
2280
|
+
var DEFAULT_CATCHUP_MAX_PAGES = 1e3;
|
|
2281
|
+
var DEFAULT_CATCHUP_MAX_DOCS = 5e4;
|
|
2282
|
+
var DEFAULT_CATCHUP_PAGE_SIZE = 100;
|
|
2271
2283
|
var Paginator = class {
|
|
2272
2284
|
constructor(http, basePath, opts) {
|
|
2273
2285
|
this.http = http;
|
|
@@ -2705,6 +2717,54 @@ var CollectionRef = class {
|
|
|
2705
2717
|
* aborts the request and silences the AbortError. Gap-recovery state
|
|
2706
2718
|
* machine lands in Task 6.
|
|
2707
2719
|
*/
|
|
2720
|
+
/**
|
|
2721
|
+
* #699 P1 — resolve the snapshot documents for `subscribeWithSnapshot`.
|
|
2722
|
+
* Without `catchUp`, one bounded page honoring `limit`/`sort` (unchanged
|
|
2723
|
+
* behavior). With `catchUp`, keyset-drain ALL matching pages (`_id`
|
|
2724
|
+
* ascending) up to `maxPages`/`maxDocs` and return the union. All pages are
|
|
2725
|
+
* gathered before the caller delivers `onSnapshot`, so the existing
|
|
2726
|
+
* snapshot-ordering buffer only unblocks live `onChange` after the full
|
|
2727
|
+
* drain. A thrown error (e.g. `SCAN_LIMIT_EXCEEDED`, abort) propagates to the
|
|
2728
|
+
* caller's existing snapshot try/catch.
|
|
2729
|
+
*/
|
|
2730
|
+
async resolveSnapshotDocs(opts, signal) {
|
|
2731
|
+
if (!opts.catchUp) {
|
|
2732
|
+
const builder = this.find(opts.where);
|
|
2733
|
+
if (opts.sort) builder.sort(opts.sort);
|
|
2734
|
+
if (opts.limit !== void 0) builder.limit(opts.limit);
|
|
2735
|
+
if (opts.select) builder.select(opts.select);
|
|
2736
|
+
const result = await builder.execute(signal);
|
|
2737
|
+
return result.documents;
|
|
2738
|
+
}
|
|
2739
|
+
const asCap = (v, def) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.floor(v) : def;
|
|
2740
|
+
const asPageSize = (v, def) => typeof v === "number" && Number.isFinite(v) && v >= 1 ? Math.floor(v) : def;
|
|
2741
|
+
const maxPages = asCap(opts.catchUp.maxPages, DEFAULT_CATCHUP_MAX_PAGES);
|
|
2742
|
+
const maxDocs = asCap(opts.catchUp.maxDocs, DEFAULT_CATCHUP_MAX_DOCS);
|
|
2743
|
+
const pageSize = asPageSize(opts.limit, DEFAULT_CATCHUP_PAGE_SIZE);
|
|
2744
|
+
const all = [];
|
|
2745
|
+
let cursor;
|
|
2746
|
+
for (let page = 0; page < maxPages && all.length < maxDocs; page++) {
|
|
2747
|
+
const builder = this.find(opts.where).sort({ _id: 1 }).limit(pageSize);
|
|
2748
|
+
if (opts.select) builder.select(opts.select);
|
|
2749
|
+
const result = cursor === void 0 ? await builder.execute(signal) : await builder.after(cursor).execute(signal);
|
|
2750
|
+
const docs = result.documents;
|
|
2751
|
+
if (docs.length === 0) break;
|
|
2752
|
+
const room = maxDocs - all.length;
|
|
2753
|
+
if (docs.length >= room) {
|
|
2754
|
+
all.push(...docs.slice(0, room));
|
|
2755
|
+
break;
|
|
2756
|
+
}
|
|
2757
|
+
all.push(...docs);
|
|
2758
|
+
const more = result.mode === "cursor" ? result.hasMore : result.hasMore ?? docs.length >= pageSize;
|
|
2759
|
+
if (!more) break;
|
|
2760
|
+
const nextCursor = docs[docs.length - 1]._id;
|
|
2761
|
+
if (nextCursor === void 0 || nextCursor === null || cursor !== void 0 && nextCursor <= cursor) {
|
|
2762
|
+
break;
|
|
2763
|
+
}
|
|
2764
|
+
cursor = nextCursor;
|
|
2765
|
+
}
|
|
2766
|
+
return all;
|
|
2767
|
+
}
|
|
2708
2768
|
async subscribeWithSnapshot(opts) {
|
|
2709
2769
|
if (!this.realtime) {
|
|
2710
2770
|
throw new Error("Realtime not available: no RealtimeClient configured");
|
|
@@ -2776,12 +2836,7 @@ var CollectionRef = class {
|
|
|
2776
2836
|
snapshotAbort = new AbortController();
|
|
2777
2837
|
let recoveryDocs;
|
|
2778
2838
|
try {
|
|
2779
|
-
|
|
2780
|
-
if (opts.sort) builder.sort(opts.sort);
|
|
2781
|
-
if (opts.limit !== void 0) builder.limit(opts.limit);
|
|
2782
|
-
if (opts.select) builder.select(opts.select);
|
|
2783
|
-
const result = await builder.execute(snapshotAbort.signal);
|
|
2784
|
-
recoveryDocs = result.documents;
|
|
2839
|
+
recoveryDocs = await this.resolveSnapshotDocs(opts, snapshotAbort.signal);
|
|
2785
2840
|
} catch (err) {
|
|
2786
2841
|
if (!isActive) return;
|
|
2787
2842
|
if (err instanceof DOMException && err.name === "AbortError") return;
|
|
@@ -2924,12 +2979,7 @@ var CollectionRef = class {
|
|
|
2924
2979
|
currentUnsubscribe = initial.unsubscribe;
|
|
2925
2980
|
let snapshotDocs;
|
|
2926
2981
|
try {
|
|
2927
|
-
|
|
2928
|
-
if (opts.sort) builder.sort(opts.sort);
|
|
2929
|
-
if (opts.limit !== void 0) builder.limit(opts.limit);
|
|
2930
|
-
if (opts.select) builder.select(opts.select);
|
|
2931
|
-
const result = await builder.execute(snapshotAbort.signal);
|
|
2932
|
-
snapshotDocs = result.documents;
|
|
2982
|
+
snapshotDocs = await this.resolveSnapshotDocs(opts, snapshotAbort.signal);
|
|
2933
2983
|
} catch (err) {
|
|
2934
2984
|
currentUnsubscribe?.();
|
|
2935
2985
|
isActive = false;
|