Skip to content

Commit 08b9a5e

Browse files
committed
Support direct params format in fetchCollection
Allow both calling styles for fetchCollection: - col('tasks', { params: { status: 'active' } }) // explicit params key - col('tasks', { status: 'active' }) // direct params format When opts.params is undefined but opts has keys other than 'force' and 'params', the opts object (minus force) is treated as params directly. This provides a more intuitive API while maintaining backward compatibility.
1 parent 500e253 commit 08b9a5e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

verity/shared/static/lib/core.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,10 +1720,30 @@ function planFetchLevels(T, levelsSet) {
17201720
function fetchCollection(name, opts = {}) {
17211721
const C = G.collections.get(name);
17221722
if (!C) throw new Error(`Unknown collection '${name}'`);
1723-
const { ref } = ensureCollectionRefEntry(name, opts.params);
1723+
1724+
// Support both { params: {...} } and direct params format
1725+
// If opts.params is explicitly provided, use it
1726+
// Otherwise, if opts has keys other than 'force' and 'params', treat opts as params directly
1727+
let effectiveParams = opts.params;
1728+
let effectiveForce = opts.force;
1729+
1730+
if (effectiveParams === undefined) {
1731+
const optsKeys = Object.keys(opts);
1732+
const hasNonMetaKeys = optsKeys.some(k => k !== 'force' && k !== 'params');
1733+
if (hasNonMetaKeys) {
1734+
// Treat opts as params directly (excluding force)
1735+
const { force, params, ...rest } = opts;
1736+
effectiveParams = rest;
1737+
effectiveForce = force;
1738+
}
1739+
}
1740+
1741+
const normalizedOpts = { params: effectiveParams, force: effectiveForce };
1742+
1743+
const { ref } = ensureCollectionRefEntry(name, effectiveParams);
17241744
ref.meta.lastUsedAt = nowISO();
17251745
scheduleMemorySweep();
1726-
_startCollectionFetch(name, opts);
1746+
_startCollectionFetch(name, normalizedOpts);
17271747

17281748
// Set isLoading based on actual in-flight state (source of truth)
17291749
// DO NOT sync here - it creates a race condition where isLoading=true but activeQueryId=null

0 commit comments

Comments
 (0)