@rdlabo/workers-hono-kit 0.9.1 → 0.9.2
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/offline/index.d.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { fromTinyIntFlag, replicaTimestampMs, toReplicaDateOnly, toReplicaIsoDat
|
|
|
10
10
|
export { replicaNowIso } from './clock.js';
|
|
11
11
|
export { defineRestDbMethodConverter } from './rest-db-method-converter.js';
|
|
12
12
|
export type { RestDbMethodConverter } from './rest-db-method-converter.js';
|
|
13
|
+
export { decodeOfflineSnapshotCursor, encodeOfflineSnapshotCursor } from './snapshot-cursor.js';
|
|
14
|
+
export type { OfflineSnapshotCursor } from './snapshot-cursor.js';
|
package/dist/offline/index.js
CHANGED
|
@@ -9,3 +9,4 @@
|
|
|
9
9
|
export { fromTinyIntFlag, replicaTimestampMs, toReplicaDateOnly, toReplicaIsoDatetime, toTinyIntFlag } from './wire.js';
|
|
10
10
|
export { replicaNowIso } from './clock.js';
|
|
11
11
|
export { defineRestDbMethodConverter } from './rest-db-method-converter.js';
|
|
12
|
+
export { decodeOfflineSnapshotCursor, encodeOfflineSnapshotCursor } from './snapshot-cursor.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Position of a keyset-paginated initial snapshot at a captured journal watermark. */
|
|
2
|
+
export interface OfflineSnapshotCursor {
|
|
3
|
+
/** Highest journal revision captured before the snapshot scan starts. */
|
|
4
|
+
watermark: number;
|
|
5
|
+
/** Zero-based product-defined snapshot source index. */
|
|
6
|
+
sourceIndex: number;
|
|
7
|
+
/** Last server-side numeric ID emitted from the current source. */
|
|
8
|
+
afterId: number;
|
|
9
|
+
}
|
|
10
|
+
/** Encodes an initial-snapshot position as a stable versioned cursor. */
|
|
11
|
+
export declare function encodeOfflineSnapshotCursor(cursor: OfflineSnapshotCursor): string;
|
|
12
|
+
/** Decodes a versioned initial-snapshot cursor, returning null for malformed input. */
|
|
13
|
+
export declare function decodeOfflineSnapshotCursor(value: string): OfflineSnapshotCursor | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const SNAPSHOT_CURSOR_PREFIX = 'snapshot:v1';
|
|
2
|
+
const CANONICAL_NON_NEGATIVE_INTEGER = /^(0|[1-9]\d*)$/;
|
|
3
|
+
/** Encodes an initial-snapshot position as a stable versioned cursor. */
|
|
4
|
+
export function encodeOfflineSnapshotCursor(cursor) {
|
|
5
|
+
assertNonNegativeSafeInteger(cursor.watermark, 'watermark');
|
|
6
|
+
assertNonNegativeSafeInteger(cursor.sourceIndex, 'sourceIndex');
|
|
7
|
+
assertNonNegativeSafeInteger(cursor.afterId, 'afterId');
|
|
8
|
+
return `${SNAPSHOT_CURSOR_PREFIX}:${cursor.watermark}:${cursor.sourceIndex}:${cursor.afterId}`;
|
|
9
|
+
}
|
|
10
|
+
/** Decodes a versioned initial-snapshot cursor, returning null for malformed input. */
|
|
11
|
+
export function decodeOfflineSnapshotCursor(value) {
|
|
12
|
+
const parts = value.split(':');
|
|
13
|
+
if (parts.length !== 5 || `${parts[0]}:${parts[1]}` !== SNAPSHOT_CURSOR_PREFIX) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const [, , watermarkValue, sourceIndexValue, afterIdValue] = parts;
|
|
17
|
+
if (!CANONICAL_NON_NEGATIVE_INTEGER.test(watermarkValue) ||
|
|
18
|
+
!CANONICAL_NON_NEGATIVE_INTEGER.test(sourceIndexValue) ||
|
|
19
|
+
!CANONICAL_NON_NEGATIVE_INTEGER.test(afterIdValue)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const watermark = Number(watermarkValue);
|
|
23
|
+
const sourceIndex = Number(sourceIndexValue);
|
|
24
|
+
const afterId = Number(afterIdValue);
|
|
25
|
+
if (!isNonNegativeSafeInteger(watermark) ||
|
|
26
|
+
!isNonNegativeSafeInteger(sourceIndex) ||
|
|
27
|
+
!isNonNegativeSafeInteger(afterId)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return { watermark, sourceIndex, afterId };
|
|
31
|
+
}
|
|
32
|
+
function isNonNegativeSafeInteger(value) {
|
|
33
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
34
|
+
}
|
|
35
|
+
function assertNonNegativeSafeInteger(value, field) {
|
|
36
|
+
if (!isNonNegativeSafeInteger(value)) {
|
|
37
|
+
throw new RangeError(`Offline snapshot cursor ${field} must be a non-negative safe integer.`);
|
|
38
|
+
}
|
|
39
|
+
}
|