UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

58 lines (57 loc) • 1.95 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const errors = require("./errors.cjs"); const SYNC_PERSISTENCE_PROTOCOL = `@tanstack/db/sync-persistence`; const SYNC_PERSISTENCE_VERSION = 1; function isRecord(value) { return typeof value === `object` && value !== null; } function requireFunction(value, key, path = key) { if (typeof value[key] !== `function`) { throw new errors.InvalidSyncPersistenceCapabilityError( `${path} must be a function` ); } } function validateSyncPersistenceCapability(value) { if (value === null) return null; if (!isRecord(value)) { throw new errors.InvalidSyncPersistenceCapabilityError( `expected null or a complete capability object` ); } if (value.protocol !== SYNC_PERSISTENCE_PROTOCOL) { throw new errors.InvalidSyncPersistenceCapabilityError( `protocol must be "${SYNC_PERSISTENCE_PROTOCOL}"` ); } if (value.version !== SYNC_PERSISTENCE_VERSION) { throw new errors.InvalidSyncPersistenceCapabilityError( `version must be ${SYNC_PERSISTENCE_VERSION}` ); } requireFunction(value, `hydrateBaseline`); requireFunction(value, `scanPersistedRows`); const resumeSnapshot = value.resumeSnapshot; if (!isRecord(resumeSnapshot)) { throw new errors.InvalidSyncPersistenceCapabilityError( `resumeSnapshot must be an object` ); } requireFunction(resumeSnapshot, `certify`, `resumeSnapshot.certify`); requireFunction( resumeSnapshot, `getKeySetEvidence`, `resumeSnapshot.getKeySetEvidence` ); requireFunction( resumeSnapshot, `expectCurrentCommit`, `resumeSnapshot.expectCurrentCommit` ); return value; } exports.SYNC_PERSISTENCE_PROTOCOL = SYNC_PERSISTENCE_PROTOCOL; exports.SYNC_PERSISTENCE_VERSION = SYNC_PERSISTENCE_VERSION; exports.validateSyncPersistenceCapability = validateSyncPersistenceCapability; //# sourceMappingURL=sync-persistence.cjs.map