@tanstack/db
Version:
A reactive client store for building super fast apps on sync
70 lines (69 loc) • 3.27 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const errors = require("./errors.cjs");
const liveQueryPrimitives = require("./live-query-primitives.cjs");
const liveQueryOptions = require("./live-query-options.cjs");
function getLiveQueryKey(input) {
const queryKey = input && typeof input === `object` && !liveQueryPrimitives.isCollection(input) ? input.queryKey : void 0;
return Array.isArray(queryKey) && queryKey.length > 0 ? queryKey : void 0;
}
const sourceObjectTokens = /* @__PURE__ */ new WeakMap();
let nextSourceObjectToken = 0;
function getSourceObjectToken(source) {
let token = sourceObjectTokens.get(source);
if (token === void 0) {
token = ++nextSourceObjectToken;
sourceObjectTokens.set(source, token);
}
return token;
}
const unscopedClaims = {};
function createLiveQuerySourceIdClaims() {
return /* @__PURE__ */ new WeakMap();
}
function claimLiveQuerySourceIds(claims, sources, client, bindingName) {
const scope = client ?? unscopedClaims;
const prior = claims.get(scope);
const seen = /* @__PURE__ */ new Map();
for (const source of sources) {
const token = getSourceObjectToken(source);
const previous = seen.get(source.id) ?? prior?.get(source.id);
if (previous !== void 0 && previous !== token) {
throw new errors.SourceCollectionIdReuseError(bindingName, source.id);
}
seen.set(source.id, token);
}
const claimed = prior ?? /* @__PURE__ */ new Map();
for (const [id, token] of seen) claimed.set(id, token);
claims.set(scope, claimed);
}
function identifyLiveQuery(preparedValue, scope, identify = liveQueryOptions.getPreparedLiveQueryIdentity) {
const identity = identify(preparedValue);
claimLiveQuerySourceIds(
scope.claims,
liveQueryOptions.getPreparedLiveQuerySources(preparedValue, scope.onUnboundDescriptor),
scope.client,
scope.bindingName
);
return identity;
}
exports.getLiveQueryStatusFlags = liveQueryPrimitives.getLiveQueryStatusFlags;
exports.getPublicCollection = liveQueryPrimitives.getPublicCollection;
exports.isCollection = liveQueryPrimitives.isCollection;
exports.isFailedStatus = liveQueryPrimitives.isFailedStatus;
exports.isSingleResultCollection = liveQueryPrimitives.isSingleResultCollection;
exports.configPool = liveQueryOptions.configPool;
exports.getLiveQueryHash = liveQueryOptions.getLiveQueryHash;
exports.getPreparedLiveQueryIdentity = liveQueryOptions.getPreparedLiveQueryIdentity;
exports.getPreparedLiveQuerySources = liveQueryOptions.getPreparedLiveQuerySources;
exports.prepareLiveQueryValue = liveQueryOptions.prepareLiveQueryValue;
exports.rejectLiveQueryInput = liveQueryOptions.rejectLiveQueryInput;
exports.releaseDeferredOnReclaim = liveQueryOptions.releaseDeferredOnReclaim;
exports.resolveLiveQueryValue = liveQueryOptions.resolveLiveQueryValue;
exports.resumeDeferredLiveQueryCollections = liveQueryOptions.resumeDeferredLiveQueryCollections;
exports.claimLiveQuerySourceIds = claimLiveQuerySourceIds;
exports.createLiveQuerySourceIdClaims = createLiveQuerySourceIdClaims;
exports.getLiveQueryKey = getLiveQueryKey;
exports.getSourceObjectToken = getSourceObjectToken;
exports.identifyLiveQuery = identifyLiveQuery;
//# sourceMappingURL=live-query-adapter.cjs.map