Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tanstack/query-core

Package Overview
Dependencies
Maintainers
2
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/query-core - npm Package Compare versions

Comparing version 5.0.0-alpha.49 to 5.0.0-alpha.50

46

build/lib/focusManager.js
'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var subscribable = require('./subscribable.js');
var utils = require('./utils.js');
var _focused = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("focused");
var _cleanup = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("cleanup");
var _setup = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setup");
class FocusManager extends subscribable.Subscribable {
#focused;
#cleanup;
#setup;
constructor() {
super();
Object.defineProperty(this, _focused, {
writable: true,
value: void 0
});
Object.defineProperty(this, _cleanup, {
writable: true,
value: void 0
});
Object.defineProperty(this, _setup, {
writable: true,
value: void 0
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setup)[_setup] = onFocus => {
this.#setup = onFocus => {
// addEventListener does not exist in React Native, but window does

@@ -41,4 +28,4 @@ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

onSubscribe() {
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup)[_cleanup]) {
this.setEventListener(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setup)[_setup]);
if (!this.#cleanup) {
this.setEventListener(this.#setup);
}

@@ -48,12 +35,10 @@ }

if (!this.hasListeners()) {
var _classPrivateFieldLoo, _classPrivateFieldLoo2;
(_classPrivateFieldLoo = (_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup))[_cleanup]) == null ? void 0 : _classPrivateFieldLoo.call(_classPrivateFieldLoo2);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup)[_cleanup] = undefined;
this.#cleanup?.();
this.#cleanup = undefined;
}
}
setEventListener(setup) {
var _classPrivateFieldLoo3, _classPrivateFieldLoo4;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setup)[_setup] = setup;
(_classPrivateFieldLoo3 = (_classPrivateFieldLoo4 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup))[_cleanup]) == null ? void 0 : _classPrivateFieldLoo3.call(_classPrivateFieldLoo4);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup)[_cleanup] = setup(focused => {
this.#setup = setup;
this.#cleanup?.();
this.#cleanup = setup(focused => {
if (typeof focused === 'boolean') {

@@ -67,3 +52,3 @@ this.setFocused(focused);

setFocused(focused) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _focused)[_focused] = focused;
this.#focused = focused;
if (focused) {

@@ -79,5 +64,4 @@ this.onFocus();

isFocused() {
var _globalThis$document;
if (typeof _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _focused)[_focused] === 'boolean') {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _focused)[_focused];
if (typeof this.#focused === 'boolean') {
return this.#focused;
}

@@ -87,3 +71,3 @@

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return ((_globalThis$document = globalThis.document) == null ? void 0 : _globalThis$document.visibilityState) !== 'hidden';
return globalThis.document?.visibilityState !== 'hidden';
}

@@ -90,0 +74,0 @@ }

@@ -32,6 +32,5 @@ 'use strict';

function dehydrate(client, options = {}) {
var _options$shouldDehydr, _options$shouldDehydr2;
const filterMutation = (_options$shouldDehydr = options.shouldDehydrateMutation) != null ? _options$shouldDehydr : defaultShouldDehydrateMutation;
const filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
const filterQuery = (_options$shouldDehydr2 = options.shouldDehydrateQuery) != null ? _options$shouldDehydr2 : defaultShouldDehydrateQuery;
const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);

@@ -55,5 +54,4 @@ return {

mutations.forEach(dehydratedMutation => {
var _options$defaultOptio;
mutationCache.build(client, {
...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),
...options?.defaultOptions?.mutations,
mutationKey: dehydratedMutation.mutationKey

@@ -63,3 +61,2 @@ }, dehydratedMutation.state);

queries.forEach(dehydratedQuery => {
var _options$defaultOptio2;
const query = queryCache.get(dehydratedQuery.queryHash);

@@ -84,3 +81,3 @@

queryCache.build(client, {
...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
...options?.defaultOptions?.queries,
queryKey: dehydratedQuery.queryKey,

@@ -87,0 +84,0 @@ queryHash: dehydratedQuery.queryHash

@@ -9,7 +9,6 @@ 'use strict';

context.fetchFn = async () => {
var _context$fetchOptions, _context$fetchOptions2, _context$fetchOptions3, _context$state$data, _context$state$data2;
const options = context.options;
const direction = (_context$fetchOptions = context.fetchOptions) == null ? void 0 : (_context$fetchOptions2 = _context$fetchOptions.meta) == null ? void 0 : (_context$fetchOptions3 = _context$fetchOptions2.fetchMore) == null ? void 0 : _context$fetchOptions3.direction;
const oldPages = ((_context$state$data = context.state.data) == null ? void 0 : _context$state$data.pages) || [];
const oldPageParams = ((_context$state$data2 = context.state.data) == null ? void 0 : _context$state$data2.pageParams) || [];
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
const oldPages = context.state.data?.pages || [];
const oldPageParams = context.state.data?.pageParams || [];
const empty = {

@@ -110,3 +109,3 @@ pages: [],

}) {
return options.getPreviousPageParam == null ? void 0 : options.getPreviousPageParam(pages[0], pages, pageParams[0], pageParams);
return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
}

@@ -113,0 +112,0 @@

@@ -53,3 +53,2 @@ 'use strict';

createResult(query, options) {
var _state$fetchMeta, _state$fetchMeta$fetc, _state$fetchMeta2, _state$fetchMeta2$fet;
const {

@@ -63,4 +62,4 @@ state

} = result;
const isFetchingNextPage = isFetching && ((_state$fetchMeta = state.fetchMeta) == null ? void 0 : (_state$fetchMeta$fetc = _state$fetchMeta.fetchMore) == null ? void 0 : _state$fetchMeta$fetc.direction) === 'forward';
const isFetchingPreviousPage = isFetching && ((_state$fetchMeta2 = state.fetchMeta) == null ? void 0 : (_state$fetchMeta2$fet = _state$fetchMeta2.fetchMore) == null ? void 0 : _state$fetchMeta2$fet.direction) === 'backward';
const isFetchingNextPage = isFetching && state.fetchMeta?.fetchMore?.direction === 'forward';
const isFetchingPreviousPage = isFetching && state.fetchMeta?.fetchMore?.direction === 'backward';
return {

@@ -67,0 +66,0 @@ ...result,

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var notifyManager = require('./notifyManager.js');

@@ -9,35 +8,16 @@ var removable = require('./removable.js');

// TYPES
var _observers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("observers");
var _defaultOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("defaultOptions");
var _mutationCache = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutationCache");
var _retryer = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("retryer");
var _dispatch = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("dispatch");
// CLASS
class Mutation extends removable.Removable {
#observers;
#defaultOptions;
#mutationCache;
#retryer;
constructor(config) {
super();
Object.defineProperty(this, _dispatch, {
value: _dispatch2
});
Object.defineProperty(this, _observers, {
writable: true,
value: void 0
});
Object.defineProperty(this, _defaultOptions, {
writable: true,
value: void 0
});
Object.defineProperty(this, _mutationCache, {
writable: true,
value: void 0
});
Object.defineProperty(this, _retryer, {
writable: true,
value: void 0
});
this.mutationId = config.mutationId;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions] = config.defaultOptions;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache] = config.mutationCache;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = [];
this.#defaultOptions = config.defaultOptions;
this.#mutationCache = config.mutationCache;
this.#observers = [];
this.state = config.state || getDefaultState();

@@ -49,3 +29,3 @@ this.setOptions(config.options);

this.options = {
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions],
...this.#defaultOptions,
...options

@@ -59,8 +39,8 @@ };

addObserver(observer) {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].indexOf(observer) === -1) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].push(observer);
if (this.#observers.indexOf(observer) === -1) {
this.#observers.push(observer);
// Stop the mutation from being garbage collected
this.clearGcTimeout();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].notify({
this.#mutationCache.notify({
type: 'observerAdded',

@@ -73,5 +53,5 @@ mutation: this,

removeObserver(observer) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].filter(x => x !== observer);
this.#observers = this.#observers.filter(x => x !== observer);
this.scheduleGc();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].notify({
this.#mutationCache.notify({
type: 'observerRemoved',

@@ -83,7 +63,7 @@ mutation: this,

optionalRemove() {
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length) {
if (!this.#observers.length) {
if (this.state.status === 'pending') {
this.scheduleGc();
} else {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].remove(this);
this.#mutationCache.remove(this);
}

@@ -93,4 +73,3 @@ }

continue() {
var _classPrivateFieldLoo, _classPrivateFieldLoo2;
return (_classPrivateFieldLoo = (_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo2.continue()) != null ? _classPrivateFieldLoo :
return this.#retryer?.continue() ??
// continuing a mutation assumes that variables are set, mutation must have been dehydrated before

@@ -101,4 +80,3 @@ this.execute(this.state.variables);

const executeMutation = () => {
var _this$options$retry;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer] = retryer.createRetryer({
this.#retryer = retryer.createRetryer({
fn: () => {

@@ -111,3 +89,3 @@ if (!this.options.mutationFn) {

onFail: (failureCount, error) => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'failed',

@@ -119,3 +97,3 @@ failureCount,

onPause: () => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'pause'

@@ -125,18 +103,16 @@ });

onContinue: () => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'continue'
});
},
retry: (_this$options$retry = this.options.retry) != null ? _this$options$retry : 0,
retry: this.options.retry ?? 0,
retryDelay: this.options.retryDelay,
networkMode: this.options.networkMode
});
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].promise;
return this.#retryer.promise;
};
const restored = this.state.status === 'pending';
try {
var _classPrivateFieldLoo5, _classPrivateFieldLoo6, _this$options$onSucce, _this$options2, _classPrivateFieldLoo7, _classPrivateFieldLoo8, _this$options$onSettl, _this$options3;
if (!restored) {
var _classPrivateFieldLoo3, _classPrivateFieldLoo4, _this$options$onMutat, _this$options;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'pending',

@@ -146,6 +122,6 @@ variables

// Notify cache callback
await ((_classPrivateFieldLoo3 = (_classPrivateFieldLoo4 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].config).onMutate) == null ? void 0 : _classPrivateFieldLoo3.call(_classPrivateFieldLoo4, variables, this));
const context = await ((_this$options$onMutat = (_this$options = this.options).onMutate) == null ? void 0 : _this$options$onMutat.call(_this$options, variables));
await this.#mutationCache.config.onMutate?.(variables, this);
const context = await this.options.onMutate?.(variables);
if (context !== this.state.context) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'pending',

@@ -160,9 +136,9 @@ context,

// Notify cache callback
await ((_classPrivateFieldLoo5 = (_classPrivateFieldLoo6 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].config).onSuccess) == null ? void 0 : _classPrivateFieldLoo5.call(_classPrivateFieldLoo6, data, variables, this.state.context, this));
await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, variables, this.state.context));
await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
await this.options.onSuccess?.(data, variables, this.state.context);
// Notify cache callback
await ((_classPrivateFieldLoo7 = (_classPrivateFieldLoo8 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].config).onSettled) == null ? void 0 : _classPrivateFieldLoo7.call(_classPrivateFieldLoo8, data, null, this.state.variables, this.state.context, this));
await ((_this$options$onSettl = (_this$options3 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options3, data, null, variables, this.state.context));
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
await this.options.onSettled?.(data, null, variables, this.state.context);
this.#dispatch({
type: 'success',

@@ -174,13 +150,12 @@ data

try {
var _classPrivateFieldLoo9, _classPrivateFieldLoo10, _this$options$onError, _this$options4, _classPrivateFieldLoo11, _classPrivateFieldLoo12, _this$options$onSettl2, _this$options5;
// Notify cache callback
await ((_classPrivateFieldLoo9 = (_classPrivateFieldLoo10 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].config).onError) == null ? void 0 : _classPrivateFieldLoo9.call(_classPrivateFieldLoo10, error, variables, this.state.context, this));
await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, variables, this.state.context));
await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
await this.options.onError?.(error, variables, this.state.context);
// Notify cache callback
await ((_classPrivateFieldLoo11 = (_classPrivateFieldLoo12 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].config).onSettled) == null ? void 0 : _classPrivateFieldLoo11.call(_classPrivateFieldLoo12, undefined, error, this.state.variables, this.state.context, this));
await ((_this$options$onSettl2 = (_this$options5 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options5, undefined, error, variables, this.state.context));
await this.#mutationCache.config.onSettled?.(undefined, error, this.state.variables, this.state.context, this);
await this.options.onSettled?.(undefined, error, variables, this.state.context);
throw error;
} finally {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'error',

@@ -192,68 +167,68 @@ error: error

}
}
function _dispatch2(action) {
const reducer = state => {
switch (action.type) {
case 'failed':
return {
...state,
failureCount: action.failureCount,
failureReason: action.error
};
case 'pause':
return {
...state,
isPaused: true
};
case 'continue':
return {
...state,
isPaused: false
};
case 'pending':
return {
...state,
context: action.context,
data: undefined,
failureCount: 0,
failureReason: null,
error: null,
isPaused: !retryer.canFetch(this.options.networkMode),
status: 'pending',
variables: action.variables,
submittedAt: Date.now()
};
case 'success':
return {
...state,
data: action.data,
failureCount: 0,
failureReason: null,
error: null,
status: 'success',
isPaused: false
};
case 'error':
return {
...state,
data: undefined,
error: action.error,
failureCount: state.failureCount + 1,
failureReason: action.error,
isPaused: false,
status: 'error'
};
}
};
this.state = reducer(this.state);
notifyManager.notifyManager.batch(() => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].forEach(observer => {
observer.onMutationUpdate(action);
#dispatch(action) {
const reducer = state => {
switch (action.type) {
case 'failed':
return {
...state,
failureCount: action.failureCount,
failureReason: action.error
};
case 'pause':
return {
...state,
isPaused: true
};
case 'continue':
return {
...state,
isPaused: false
};
case 'pending':
return {
...state,
context: action.context,
data: undefined,
failureCount: 0,
failureReason: null,
error: null,
isPaused: !retryer.canFetch(this.options.networkMode),
status: 'pending',
variables: action.variables,
submittedAt: Date.now()
};
case 'success':
return {
...state,
data: action.data,
failureCount: 0,
failureReason: null,
error: null,
status: 'success',
isPaused: false
};
case 'error':
return {
...state,
data: undefined,
error: action.error,
failureCount: state.failureCount + 1,
failureReason: action.error,
isPaused: false,
status: 'error'
};
}
};
this.state = reducer(this.state);
notifyManager.notifyManager.batch(() => {
this.#observers.forEach(observer => {
observer.onMutationUpdate(action);
});
this.#mutationCache.notify({
mutation: this,
type: 'updated',
action
});
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].notify({
mutation: this,
type: 'updated',
action
});
});
}
}

@@ -260,0 +235,0 @@ function getDefaultState() {

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var notifyManager = require('./notifyManager.js');

@@ -10,25 +9,14 @@ var mutation = require('./mutation.js');

// TYPES
var _mutations = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutations");
var _mutationId = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutationId");
var _resuming = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("resuming");
// CLASS
class MutationCache extends subscribable.Subscribable {
#mutations;
#mutationId;
#resuming;
constructor(config = {}) {
super();
Object.defineProperty(this, _mutations, {
writable: true,
value: void 0
});
Object.defineProperty(this, _mutationId, {
writable: true,
value: void 0
});
Object.defineProperty(this, _resuming, {
writable: true,
value: void 0
});
this.config = config;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations] = [];
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationId)[_mutationId] = 0;
this.#mutations = [];
this.#mutationId = 0;
}

@@ -38,3 +26,3 @@ build(client, options, state) {

mutationCache: this,
mutationId: ++_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationId)[_mutationId],
mutationId: ++this.#mutationId,
options: client.defaultMutationOptions(options),

@@ -47,3 +35,3 @@ state

add(mutation) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].push(mutation);
this.#mutations.push(mutation);
this.notify({

@@ -55,3 +43,3 @@ type: 'added',

remove(mutation) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].filter(x => x !== mutation);
this.#mutations = this.#mutations.filter(x => x !== mutation);
this.notify({

@@ -64,3 +52,3 @@ type: 'removed',

notifyManager.notifyManager.batch(() => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].forEach(mutation => {
this.#mutations.forEach(mutation => {
this.remove(mutation);

@@ -71,3 +59,3 @@ });

getAll() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations];
return this.#mutations;
}

@@ -79,6 +67,6 @@ find(filters) {

};
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].find(mutation => utils.matchMutation(defaultedFilters, mutation));
return this.#mutations.find(mutation => utils.matchMutation(defaultedFilters, mutation));
}
findAll(filters = {}) {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].filter(mutation => utils.matchMutation(filters, mutation));
return this.#mutations.filter(mutation => utils.matchMutation(filters, mutation));
}

@@ -93,10 +81,9 @@ notify(event) {

resumePausedMutations() {
var _classPrivateFieldLoo;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming] = ((_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming]) != null ? _classPrivateFieldLoo : Promise.resolve()).then(() => {
const pausedMutations = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].filter(x => x.state.isPaused);
this.#resuming = (this.#resuming ?? Promise.resolve()).then(() => {
const pausedMutations = this.#mutations.filter(x => x.state.isPaused);
return notifyManager.notifyManager.batch(() => pausedMutations.reduce((promise, mutation) => promise.then(() => mutation.continue().catch(utils.noop)), Promise.resolve()));
}).then(() => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming] = undefined;
this.#resuming = undefined;
});
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming];
return this.#resuming;
}

@@ -103,0 +90,0 @@ }

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var mutation = require('./mutation.js');

@@ -10,39 +9,16 @@ var notifyManager = require('./notifyManager.js');

// TYPES
var _client = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("client");
var _currentResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentResult");
var _currentMutation = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentMutation");
var _mutateOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutateOptions");
var _updateResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateResult");
var _notify = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("notify");
// CLASS
class MutationObserver extends subscribable.Subscribable {
#client;
#currentResult = undefined;
#currentMutation;
#mutateOptions;
constructor(client, options) {
super();
Object.defineProperty(this, _notify, {
value: _notify2
});
Object.defineProperty(this, _updateResult, {
value: _updateResult2
});
Object.defineProperty(this, _client, {
writable: true,
value: void 0
});
Object.defineProperty(this, _currentResult, {
writable: true,
value: undefined
});
Object.defineProperty(this, _currentMutation, {
writable: true,
value: void 0
});
Object.defineProperty(this, _mutateOptions, {
writable: true,
value: void 0
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = client;
this.#client = client;
this.setOptions(options);
this.bindMethods();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
this.#updateResult();
}

@@ -54,74 +30,68 @@ bindMethods() {

setOptions(options) {
var _classPrivateFieldLoo;
const prevOptions = this.options;
this.options = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].defaultMutationOptions(options);
this.options = this.#client.defaultMutationOptions(options);
if (!utils.shallowEqualObjects(prevOptions, this.options)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getMutationCache().notify({
this.#client.getMutationCache().notify({
type: 'observerOptionsUpdated',
mutation: _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation],
mutation: this.#currentMutation,
observer: this
});
}
(_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo.setOptions(this.options);
this.#currentMutation?.setOptions(this.options);
}
onUnsubscribe() {
if (!this.hasListeners()) {
var _classPrivateFieldLoo2;
(_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo2.removeObserver(this);
this.#currentMutation?.removeObserver(this);
}
}
onMutationUpdate(action) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify](action);
this.#updateResult();
this.#notify(action);
}
getCurrentResult() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
return this.#currentResult;
}
reset() {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation] = undefined;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify]();
this.#currentMutation = undefined;
this.#updateResult();
this.#notify();
}
mutate(variables, options) {
var _classPrivateFieldLoo3;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions] = options;
(_classPrivateFieldLoo3 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo3.removeObserver(this);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getMutationCache().build(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], this.options);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation].addObserver(this);
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation].execute(variables);
this.#mutateOptions = options;
this.#currentMutation?.removeObserver(this);
this.#currentMutation = this.#client.getMutationCache().build(this.#client, this.options);
this.#currentMutation.addObserver(this);
return this.#currentMutation.execute(variables);
}
}
function _updateResult2() {
var _classPrivateFieldLoo4, _classPrivateFieldLoo5;
const state = (_classPrivateFieldLoo4 = (_classPrivateFieldLoo5 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo5.state) != null ? _classPrivateFieldLoo4 : mutation.getDefaultState();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult] = {
...state,
isPending: state.status === 'pending',
isSuccess: state.status === 'success',
isError: state.status === 'error',
isIdle: state.status === 'idle',
mutate: this.mutate,
reset: this.reset
};
}
function _notify2(action) {
notifyManager.notifyManager.batch(() => {
// First trigger the mutate callbacks
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions] && this.hasListeners()) {
if ((action == null ? void 0 : action.type) === 'success') {
var _classPrivateFieldLoo6, _classPrivateFieldLoo7, _classPrivateFieldLoo8, _classPrivateFieldLoo9;
(_classPrivateFieldLoo6 = (_classPrivateFieldLoo7 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSuccess) == null ? void 0 : _classPrivateFieldLoo6.call(_classPrivateFieldLoo7, action.data, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
(_classPrivateFieldLoo8 = (_classPrivateFieldLoo9 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSettled) == null ? void 0 : _classPrivateFieldLoo8.call(_classPrivateFieldLoo9, action.data, null, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
} else if ((action == null ? void 0 : action.type) === 'error') {
var _classPrivateFieldLoo10, _classPrivateFieldLoo11, _classPrivateFieldLoo12, _classPrivateFieldLoo13;
(_classPrivateFieldLoo10 = (_classPrivateFieldLoo11 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onError) == null ? void 0 : _classPrivateFieldLoo10.call(_classPrivateFieldLoo11, action.error, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
(_classPrivateFieldLoo12 = (_classPrivateFieldLoo13 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSettled) == null ? void 0 : _classPrivateFieldLoo12.call(_classPrivateFieldLoo13, undefined, action.error, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
#updateResult() {
const state = this.#currentMutation?.state ?? mutation.getDefaultState();
this.#currentResult = {
...state,
isPending: state.status === 'pending',
isSuccess: state.status === 'success',
isError: state.status === 'error',
isIdle: state.status === 'idle',
mutate: this.mutate,
reset: this.reset
};
}
#notify(action) {
notifyManager.notifyManager.batch(() => {
// First trigger the mutate callbacks
if (this.#mutateOptions && this.hasListeners()) {
if (action?.type === 'success') {
this.#mutateOptions.onSuccess?.(action.data, this.#currentResult.variables, this.#currentResult.context);
this.#mutateOptions.onSettled?.(action.data, null, this.#currentResult.variables, this.#currentResult.context);
} else if (action?.type === 'error') {
this.#mutateOptions.onError?.(action.error, this.#currentResult.variables, this.#currentResult.context);
this.#mutateOptions.onSettled?.(undefined, action.error, this.#currentResult.variables, this.#currentResult.context);
}
}
}
// Then trigger the listeners
this.listeners.forEach(listener => {
listener(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult]);
// Then trigger the listeners
this.listeners.forEach(listener => {
listener(this.#currentResult);
});
});
});
}
}

@@ -128,0 +98,0 @@

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var subscribable = require('./subscribable.js');
var utils = require('./utils.js');
var _online = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("online");
var _cleanup = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("cleanup");
var _setup = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setup");
class OnlineManager extends subscribable.Subscribable {
#online;
#cleanup;
#setup;
constructor() {
super();
Object.defineProperty(this, _online, {
writable: true,
value: void 0
});
Object.defineProperty(this, _cleanup, {
writable: true,
value: void 0
});
Object.defineProperty(this, _setup, {
writable: true,
value: void 0
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setup)[_setup] = onOnline => {
this.#setup = onOnline => {
// addEventListener does not exist in React Native, but window does

@@ -43,4 +30,4 @@ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

onSubscribe() {
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup)[_cleanup]) {
this.setEventListener(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setup)[_setup]);
if (!this.#cleanup) {
this.setEventListener(this.#setup);
}

@@ -50,12 +37,10 @@ }

if (!this.hasListeners()) {
var _classPrivateFieldLoo, _classPrivateFieldLoo2;
(_classPrivateFieldLoo = (_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup))[_cleanup]) == null ? void 0 : _classPrivateFieldLoo.call(_classPrivateFieldLoo2);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup)[_cleanup] = undefined;
this.#cleanup?.();
this.#cleanup = undefined;
}
}
setEventListener(setup) {
var _classPrivateFieldLoo3, _classPrivateFieldLoo4;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setup)[_setup] = setup;
(_classPrivateFieldLoo3 = (_classPrivateFieldLoo4 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup))[_cleanup]) == null ? void 0 : _classPrivateFieldLoo3.call(_classPrivateFieldLoo4);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cleanup)[_cleanup] = setup(online => {
this.#setup = setup;
this.#cleanup?.();
this.#cleanup = setup(online => {
if (typeof online === 'boolean') {

@@ -69,3 +54,3 @@ this.setOnline(online);

setOnline(online) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _online)[_online] = online;
this.#online = online;
if (online) {

@@ -81,4 +66,4 @@ this.onOnline();

isOnline() {
if (typeof _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _online)[_online] === 'boolean') {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _online)[_online];
if (typeof this.#online === 'boolean') {
return this.#online;
}

@@ -85,0 +70,0 @@ if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var notifyManager = require('./notifyManager.js');

@@ -17,66 +16,26 @@ var queryObserver = require('./queryObserver.js');

}
var _client = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("client");
var _result = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("result");
var _queries = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("queries");
var _observers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("observers");
var _options = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("options");
var _combinedResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("combinedResult");
var _setResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setResult");
var _combineResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("combineResult");
var _findMatchingObservers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("findMatchingObservers");
var _onUpdate = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("onUpdate");
var _notify = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("notify");
class QueriesObserver extends subscribable.Subscribable {
constructor(client, _queries2, _options2) {
#client;
#result;
#queries;
#observers;
#options;
#combinedResult;
constructor(client, queries, options) {
super();
Object.defineProperty(this, _notify, {
value: _notify2
});
Object.defineProperty(this, _onUpdate, {
value: _onUpdate2
});
Object.defineProperty(this, _findMatchingObservers, {
value: _findMatchingObservers2
});
Object.defineProperty(this, _combineResult, {
value: _combineResult2
});
Object.defineProperty(this, _setResult, {
value: _setResult2
});
Object.defineProperty(this, _client, {
writable: true,
value: void 0
});
Object.defineProperty(this, _result, {
writable: true,
value: void 0
});
Object.defineProperty(this, _queries, {
writable: true,
value: void 0
});
Object.defineProperty(this, _observers, {
writable: true,
value: void 0
});
Object.defineProperty(this, _options, {
writable: true,
value: void 0
});
Object.defineProperty(this, _combinedResult, {
writable: true,
value: void 0
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = client;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries] = [];
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = [];
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setResult)[_setResult]([]);
this.setQueries(_queries2, _options2);
this.#client = client;
this.#queries = [];
this.#observers = [];
this.#setResult([]);
this.setQueries(queries, options);
}
#setResult(value) {
this.#result = value;
this.#combinedResult = this.#combineResult(value);
}
onSubscribe() {
if (this.listeners.size === 1) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].forEach(observer => {
this.#observers.forEach(observer => {
observer.subscribe(result => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _onUpdate)[_onUpdate](observer, result);
this.#onUpdate(observer, result);
});

@@ -93,3 +52,3 @@ });

this.listeners = new Set();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].forEach(observer => {
this.#observers.forEach(observer => {
observer.destroy();

@@ -99,7 +58,7 @@ });

setQueries(queries, options, notifyOptions) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries] = queries;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _options)[_options] = options;
this.#queries = queries;
this.#options = options;
notifyManager.notifyManager.batch(() => {
const prevObservers = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers];
const newObserverMatches = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _findMatchingObservers)[_findMatchingObservers](_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries]);
const prevObservers = this.#observers;
const newObserverMatches = this.#findMatchingObservers(this.#queries);

@@ -114,4 +73,4 @@ // set options for the new observers to notify of changes

}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = newObservers;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setResult)[_setResult](newResult);
this.#observers = newObservers;
this.#setResult(newResult);
if (!this.hasListeners()) {

@@ -125,22 +84,22 @@ return;

observer.subscribe(result => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _onUpdate)[_onUpdate](observer, result);
this.#onUpdate(observer, result);
});
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify]();
this.#notify();
});
}
getCurrentResult() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult];
return this.#combinedResult;
}
getQueries() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].map(observer => observer.getCurrentQuery());
return this.#observers.map(observer => observer.getCurrentQuery());
}
getObservers() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers];
return this.#observers;
}
getOptimisticResult(queries) {
const matches = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _findMatchingObservers)[_findMatchingObservers](queries);
const matches = this.#findMatchingObservers(queries);
const result = matches.map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions));
return [result, r => {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combineResult)[_combineResult](r != null ? r : result);
return this.#combineResult(r ?? result);
}, () => {

@@ -153,58 +112,53 @@ return matches.map((match, index) => {

}
}
function _setResult2(value) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result] = value;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combineResult)[_combineResult](value);
}
function _combineResult2(input) {
var _classPrivateFieldLoo;
const combine = (_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _options)[_options]) == null ? void 0 : _classPrivateFieldLoo.combine;
if (combine) {
return utils.replaceEqualDeep(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult], combine(input));
#combineResult(input) {
const combine = this.#options?.combine;
if (combine) {
return utils.replaceEqualDeep(this.#combinedResult, combine(input));
}
return input;
}
return input;
}
function _findMatchingObservers2(queries) {
const prevObservers = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers];
const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
const defaultedQueryOptions = queries.map(options => _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].defaultQueryOptions(options));
const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
const match = prevObserversMap.get(defaultedOptions.queryHash);
if (match != null) {
return [{
defaultedQueryOptions: defaultedOptions,
observer: match
}];
}
return [];
});
const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
const getObserver = options => {
const defaultedOptions = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].defaultQueryOptions(options);
const currentObserver = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(o => o.options.queryHash === defaultedOptions.queryHash);
return currentObserver != null ? currentObserver : new queryObserver.QueryObserver(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], defaultedOptions);
};
const newOrReusedObservers = unmatchedQueries.map(options => {
return {
defaultedQueryOptions: options,
observer: getObserver(options)
#findMatchingObservers(queries) {
const prevObservers = this.#observers;
const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
const defaultedQueryOptions = queries.map(options => this.#client.defaultQueryOptions(options));
const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
const match = prevObserversMap.get(defaultedOptions.queryHash);
if (match != null) {
return [{
defaultedQueryOptions: defaultedOptions,
observer: match
}];
}
return [];
});
const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
const getObserver = options => {
const defaultedOptions = this.#client.defaultQueryOptions(options);
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
return currentObserver ?? new queryObserver.QueryObserver(this.#client, defaultedOptions);
};
});
const sortMatchesByOrderOfQueries = (a, b) => defaultedQueryOptions.indexOf(a.defaultedQueryOptions) - defaultedQueryOptions.indexOf(b.defaultedQueryOptions);
return matchingObservers.concat(newOrReusedObservers).sort(sortMatchesByOrderOfQueries);
}
function _onUpdate2(observer, result) {
const index = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].indexOf(observer);
if (index !== -1) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setResult)[_setResult](replaceAt(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result], index, result));
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify]();
const newOrReusedObservers = unmatchedQueries.map(options => {
return {
defaultedQueryOptions: options,
observer: getObserver(options)
};
});
const sortMatchesByOrderOfQueries = (a, b) => defaultedQueryOptions.indexOf(a.defaultedQueryOptions) - defaultedQueryOptions.indexOf(b.defaultedQueryOptions);
return matchingObservers.concat(newOrReusedObservers).sort(sortMatchesByOrderOfQueries);
}
}
function _notify2() {
notifyManager.notifyManager.batch(() => {
this.listeners.forEach(listener => {
listener(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result]);
#onUpdate(observer, result) {
const index = this.#observers.indexOf(observer);
if (index !== -1) {
this.#setResult(replaceAt(this.#result, index, result));
this.#notify();
}
}
#notify() {
notifyManager.notifyManager.batch(() => {
this.listeners.forEach(listener => {
listener(this.#result);
});
});
});
}
}

@@ -211,0 +165,0 @@

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var utils = require('./utils.js');

@@ -10,64 +9,25 @@ var notifyManager = require('./notifyManager.js');

// TYPES
var _initialState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("initialState");
var _revertState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("revertState");
var _cache = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("cache");
var _promise = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("promise");
var _retryer = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("retryer");
var _observers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("observers");
var _defaultOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("defaultOptions");
var _abortSignalConsumed = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("abortSignalConsumed");
var _setOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setOptions");
var _dispatch = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("dispatch");
// CLASS
class Query extends removable.Removable {
#initialState;
#revertState;
#cache;
#promise;
#retryer;
#observers;
#defaultOptions;
#abortSignalConsumed;
constructor(config) {
super();
Object.defineProperty(this, _dispatch, {
value: _dispatch2
});
Object.defineProperty(this, _setOptions, {
value: _setOptions2
});
Object.defineProperty(this, _initialState, {
writable: true,
value: void 0
});
Object.defineProperty(this, _revertState, {
writable: true,
value: void 0
});
Object.defineProperty(this, _cache, {
writable: true,
value: void 0
});
Object.defineProperty(this, _promise, {
writable: true,
value: void 0
});
Object.defineProperty(this, _retryer, {
writable: true,
value: void 0
});
Object.defineProperty(this, _observers, {
writable: true,
value: void 0
});
Object.defineProperty(this, _defaultOptions, {
writable: true,
value: void 0
});
Object.defineProperty(this, _abortSignalConsumed, {
writable: true,
value: void 0
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = false;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions] = config.defaultOptions;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](config.options);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = [];
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache] = config.cache;
this.#abortSignalConsumed = false;
this.#defaultOptions = config.defaultOptions;
this.#setOptions(config.options);
this.#observers = [];
this.#cache = config.cache;
this.queryKey = config.queryKey;
this.queryHash = config.queryHash;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _initialState)[_initialState] = config.state || getDefaultState(this.options);
this.state = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _initialState)[_initialState];
this.#initialState = config.state || getDefaultState(this.options);
this.state = this.#initialState;
this.scheduleGc();

@@ -78,5 +38,12 @@ }

}
#setOptions(options) {
this.options = {
...this.#defaultOptions,
...options
};
this.updateGcTime(this.options.gcTime);
}
optionalRemove() {
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length && this.state.fetchStatus === 'idle') {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].remove(this);
if (!this.#observers.length && this.state.fetchStatus === 'idle') {
this.#cache.remove(this);
}

@@ -88,7 +55,7 @@ }

// Set data and mark it as cached
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
data,
type: 'success',
dataUpdatedAt: options == null ? void 0 : options.updatedAt,
manual: options == null ? void 0 : options.manual
dataUpdatedAt: options?.updatedAt,
manual: options?.manual
});

@@ -98,3 +65,3 @@ return data;

setState(state, setStateOptions) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'setState',

@@ -106,5 +73,4 @@ state,

cancel(options) {
var _classPrivateFieldLoo;
const promise = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise];
(_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo.cancel(options);
const promise = this.#promise;
this.#retryer?.cancel(options);
return promise ? promise.then(utils.noop).catch(utils.noop) : Promise.resolve();

@@ -120,6 +86,6 @@ }

this.destroy();
this.setState(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _initialState)[_initialState]);
this.setState(this.#initialState);
}
isActive() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].some(observer => observer.options.enabled !== false);
return this.#observers.some(observer => observer.options.enabled !== false);
}

@@ -130,3 +96,3 @@ isDisabled() {

isStale() {
return this.state.isInvalidated || !this.state.dataUpdatedAt || _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].some(observer => observer.getCurrentResult().isStale);
return this.state.isInvalidated || !this.state.dataUpdatedAt || this.#observers.some(observer => observer.getCurrentResult().isStale);
}

@@ -137,5 +103,4 @@ isStaleByTime(staleTime = 0) {

onFocus() {
var _classPrivateFieldLoo2;
const observer = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(x => x.shouldFetchOnWindowFocus());
observer == null ? void 0 : observer.refetch({
const observer = this.#observers.find(x => x.shouldFetchOnWindowFocus());
observer?.refetch({
cancelRefetch: false

@@ -145,8 +110,7 @@ });

// Continue fetch if currently paused
(_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo2.continue();
this.#retryer?.continue();
}
onOnline() {
var _classPrivateFieldLoo3;
const observer = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(x => x.shouldFetchOnReconnect());
observer == null ? void 0 : observer.refetch({
const observer = this.#observers.find(x => x.shouldFetchOnReconnect());
observer?.refetch({
cancelRefetch: false

@@ -156,11 +120,11 @@ });

// Continue fetch if currently paused
(_classPrivateFieldLoo3 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo3.continue();
this.#retryer?.continue();
}
addObserver(observer) {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].indexOf(observer) === -1) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].push(observer);
if (this.#observers.indexOf(observer) === -1) {
this.#observers.push(observer);
// Stop the query from being garbage collected
this.clearGcTimeout();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
this.#cache.notify({
type: 'observerAdded',

@@ -173,14 +137,14 @@ query: this,

removeObserver(observer) {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].indexOf(observer) !== -1) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].filter(x => x !== observer);
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length) {
if (this.#observers.indexOf(observer) !== -1) {
this.#observers = this.#observers.filter(x => x !== observer);
if (!this.#observers.length) {
// If the transport layer does not support cancellation
// we'll let the query continue so the result can be cached
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed]) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].cancel({
if (this.#retryer) {
if (this.#abortSignalConsumed) {
this.#retryer.cancel({
revert: true
});
} else {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].cancelRetry();
this.#retryer.cancelRetry();
}

@@ -190,3 +154,3 @@ }

}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
this.#cache.notify({
type: 'observerRemoved',

@@ -199,7 +163,7 @@ query: this,

getObserversCount() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length;
return this.#observers.length;
}
invalidate() {
if (!this.state.isInvalidated) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'invalidate'

@@ -210,5 +174,4 @@ });

fetch(options, fetchOptions) {
var _this$options$behavio, _context$fetchOptions;
if (this.state.fetchStatus !== 'idle') {
if (this.state.dataUpdatedAt && fetchOptions != null && fetchOptions.cancelRefetch) {
if (this.state.dataUpdatedAt && fetchOptions?.cancelRefetch) {
// Silently cancel current fetch if the user wants to cancel refetches

@@ -218,8 +181,7 @@ this.cancel({

});
} else if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise]) {
var _classPrivateFieldLoo4;
} else if (this.#promise) {
// make sure that retries that were potentially cancelled due to unmounts can continue
(_classPrivateFieldLoo4 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo4.continueRetry();
this.#retryer?.continueRetry();
// Return current promise if we are already fetching
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise];
return this.#promise;
}

@@ -230,3 +192,3 @@ }

if (options) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](options);
this.#setOptions(options);
}

@@ -237,5 +199,5 @@

if (!this.options.queryFn) {
const observer = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(x => x.options.queryFn);
const observer = this.#observers.find(x => x.options.queryFn);
if (observer) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](observer.options);
this.#setOptions(observer.options);
}

@@ -263,3 +225,3 @@ }

get: () => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = true;
this.#abortSignalConsumed = true;
return abortController.signal;

@@ -276,3 +238,3 @@ }

}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = false;
this.#abortSignalConsumed = false;
return this.options.queryFn(queryFnContext);

@@ -290,13 +252,12 @@ };

addSignalProperty(context);
(_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch(context);
this.options.behavior?.onFetch(context);
// Store state in case the current fetch needs to be reverted
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState] = this.state;
this.#revertState = this.state;
// Set to fetching state if not already in it
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) == null ? void 0 : _context$fetchOptions.meta)) {
var _context$fetchOptions2;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== context.fetchOptions?.meta) {
this.#dispatch({
type: 'fetch',
meta: (_context$fetchOptions2 = context.fetchOptions) == null ? void 0 : _context$fetchOptions2.meta
meta: context.fetchOptions?.meta
});

@@ -307,3 +268,3 @@ }

if (!(retryer.isCancelledError(error) && error.silent)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'error',

@@ -314,6 +275,5 @@ error: error

if (!retryer.isCancelledError(error)) {
var _classPrivateFieldLoo5, _classPrivateFieldLoo6, _classPrivateFieldLoo7, _classPrivateFieldLoo8;
// Notify cache callback
(_classPrivateFieldLoo5 = (_classPrivateFieldLoo6 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onError) == null ? void 0 : _classPrivateFieldLoo5.call(_classPrivateFieldLoo6, error, this);
(_classPrivateFieldLoo7 = (_classPrivateFieldLoo8 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onSettled) == null ? void 0 : _classPrivateFieldLoo7.call(_classPrivateFieldLoo8, this.state.data, error, this);
this.#cache.config.onError?.(error, this);
this.#cache.config.onSettled?.(this.state.data, error, this);
}

@@ -328,7 +288,6 @@ if (!this.isFetchingOptimistic) {

// Try to fetch the data
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer] = retryer.createRetryer({
this.#retryer = retryer.createRetryer({
fn: context.fetchFn,
abort: abortController.abort.bind(abortController),
onSuccess: data => {
var _classPrivateFieldLoo9, _classPrivateFieldLoo10, _classPrivateFieldLoo11, _classPrivateFieldLoo12;
if (typeof data === 'undefined') {

@@ -344,4 +303,4 @@ if (process.env.NODE_ENV !== 'production') {

// Notify cache callback
(_classPrivateFieldLoo9 = (_classPrivateFieldLoo10 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onSuccess) == null ? void 0 : _classPrivateFieldLoo9.call(_classPrivateFieldLoo10, data, this);
(_classPrivateFieldLoo11 = (_classPrivateFieldLoo12 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onSettled) == null ? void 0 : _classPrivateFieldLoo11.call(_classPrivateFieldLoo12, data, this.state.error, this);
this.#cache.config.onSuccess?.(data, this);
this.#cache.config.onSettled?.(data, this.state.error, this);
if (!this.isFetchingOptimistic) {

@@ -355,3 +314,3 @@ // Schedule query gc after fetching

onFail: (failureCount, error) => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'failed',

@@ -363,3 +322,3 @@ failureCount,

onPause: () => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'pause'

@@ -369,3 +328,3 @@ });

onContinue: () => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
this.#dispatch({
type: 'continue'

@@ -378,100 +337,92 @@ });

});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].promise;
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise];
this.#promise = this.#retryer.promise;
return this.#promise;
}
}
function _setOptions2(options) {
this.options = {
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions],
...options
};
this.updateGcTime(this.options.gcTime);
}
function _dispatch2(action) {
const reducer = state => {
var _action$meta, _action$dataUpdatedAt;
switch (action.type) {
case 'failed':
return {
...state,
fetchFailureCount: action.failureCount,
fetchFailureReason: action.error
};
case 'pause':
return {
...state,
fetchStatus: 'paused'
};
case 'continue':
return {
...state,
fetchStatus: 'fetching'
};
case 'fetch':
return {
...state,
fetchFailureCount: 0,
fetchFailureReason: null,
fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
fetchStatus: retryer.canFetch(this.options.networkMode) ? 'fetching' : 'paused',
...(!state.dataUpdatedAt && {
#dispatch(action) {
const reducer = state => {
switch (action.type) {
case 'failed':
return {
...state,
fetchFailureCount: action.failureCount,
fetchFailureReason: action.error
};
case 'pause':
return {
...state,
fetchStatus: 'paused'
};
case 'continue':
return {
...state,
fetchStatus: 'fetching'
};
case 'fetch':
return {
...state,
fetchFailureCount: 0,
fetchFailureReason: null,
fetchMeta: action.meta ?? null,
fetchStatus: retryer.canFetch(this.options.networkMode) ? 'fetching' : 'paused',
...(!state.dataUpdatedAt && {
error: null,
status: 'pending'
})
};
case 'success':
return {
...state,
data: action.data,
dataUpdateCount: state.dataUpdateCount + 1,
dataUpdatedAt: action.dataUpdatedAt ?? Date.now(),
error: null,
status: 'pending'
})
};
case 'success':
return {
...state,
data: action.data,
dataUpdateCount: state.dataUpdateCount + 1,
dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
error: null,
isInvalidated: false,
status: 'success',
...(!action.manual && {
isInvalidated: false,
status: 'success',
...(!action.manual && {
fetchStatus: 'idle',
fetchFailureCount: 0,
fetchFailureReason: null
})
};
case 'error':
const error = action.error;
if (retryer.isCancelledError(error) && error.revert && this.#revertState) {
return {
...this.#revertState
};
}
return {
...state,
error: error,
errorUpdateCount: state.errorUpdateCount + 1,
errorUpdatedAt: Date.now(),
fetchFailureCount: state.fetchFailureCount + 1,
fetchFailureReason: error,
fetchStatus: 'idle',
fetchFailureCount: 0,
fetchFailureReason: null
})
};
case 'error':
const error = action.error;
if (retryer.isCancelledError(error) && error.revert && _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState]) {
status: 'error'
};
case 'invalidate':
return {
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState]
...state,
isInvalidated: true
};
}
return {
...state,
error: error,
errorUpdateCount: state.errorUpdateCount + 1,
errorUpdatedAt: Date.now(),
fetchFailureCount: state.fetchFailureCount + 1,
fetchFailureReason: error,
fetchStatus: 'idle',
status: 'error'
};
case 'invalidate':
return {
...state,
isInvalidated: true
};
case 'setState':
return {
...state,
...action.state
};
}
};
this.state = reducer(this.state);
notifyManager.notifyManager.batch(() => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].forEach(observer => {
observer.onQueryUpdate();
case 'setState':
return {
...state,
...action.state
};
}
};
this.state = reducer(this.state);
notifyManager.notifyManager.batch(() => {
this.#observers.forEach(observer => {
observer.onQueryUpdate();
});
this.#cache.notify({
query: this,
type: 'updated',
action
});
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
query: this,
type: 'updated',
action
});
});
}
}

@@ -485,3 +436,3 @@ function getDefaultState(options) {

dataUpdateCount: 0,
dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
error: null,

@@ -488,0 +439,0 @@ errorUpdateCount: 0,

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var utils = require('./utils.js');

@@ -10,19 +9,15 @@ var query = require('./query.js');

// TYPES
var _queries = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("queries");
// CLASS
class QueryCache extends subscribable.Subscribable {
#queries;
constructor(config = {}) {
super();
Object.defineProperty(this, _queries, {
writable: true,
value: void 0
});
this.config = config;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries] = new Map();
this.#queries = new Map();
}
build(client, options, state) {
var _options$queryHash;
const queryKey = options.queryKey;
const queryHash = (_options$queryHash = options.queryHash) != null ? _options$queryHash : utils.hashQueryKeyByOptions(queryKey, options);
const queryHash = options.queryHash ?? utils.hashQueryKeyByOptions(queryKey, options);
let query$1 = this.get(queryHash);

@@ -43,4 +38,4 @@ if (!query$1) {

add(query) {
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries].has(query.queryHash)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries].set(query.queryHash, query);
if (!this.#queries.has(query.queryHash)) {
this.#queries.set(query.queryHash, query);
this.notify({

@@ -53,7 +48,7 @@ type: 'added',

remove(query) {
const queryInMap = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries].get(query.queryHash);
const queryInMap = this.#queries.get(query.queryHash);
if (queryInMap) {
query.destroy();
if (queryInMap === query) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries].delete(query.queryHash);
this.#queries.delete(query.queryHash);
}

@@ -74,6 +69,6 @@ this.notify({

get(queryHash) {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries].get(queryHash);
return this.#queries.get(queryHash);
}
getAll() {
return [..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries].values()];
return [...this.#queries.values()];
}

@@ -80,0 +75,0 @@ find(filters) {

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var utils = require('./utils.js');

@@ -13,66 +12,35 @@ var queryCache = require('./queryCache.js');

// TYPES
var _queryCache = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("queryCache");
var _mutationCache = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutationCache");
var _defaultOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("defaultOptions");
var _queryDefaults = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("queryDefaults");
var _mutationDefaults = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutationDefaults");
var _mountCount = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mountCount");
var _unsubscribeFocus = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("unsubscribeFocus");
var _unsubscribeOnline = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("unsubscribeOnline");
// CLASS
class QueryClient {
#queryCache;
#mutationCache;
#defaultOptions;
#queryDefaults;
#mutationDefaults;
#mountCount;
#unsubscribeFocus;
#unsubscribeOnline;
constructor(config = {}) {
Object.defineProperty(this, _queryCache, {
writable: true,
value: void 0
});
Object.defineProperty(this, _mutationCache, {
writable: true,
value: void 0
});
Object.defineProperty(this, _defaultOptions, {
writable: true,
value: void 0
});
Object.defineProperty(this, _queryDefaults, {
writable: true,
value: void 0
});
Object.defineProperty(this, _mutationDefaults, {
writable: true,
value: void 0
});
Object.defineProperty(this, _mountCount, {
writable: true,
value: void 0
});
Object.defineProperty(this, _unsubscribeFocus, {
writable: true,
value: void 0
});
Object.defineProperty(this, _unsubscribeOnline, {
writable: true,
value: void 0
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache] = config.queryCache || new queryCache.QueryCache();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache] = config.mutationCache || new mutationCache.MutationCache();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions] = config.defaultOptions || {};
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryDefaults)[_queryDefaults] = new Map();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationDefaults)[_mutationDefaults] = new Map();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mountCount)[_mountCount] = 0;
this.#queryCache = config.queryCache || new queryCache.QueryCache();
this.#mutationCache = config.mutationCache || new mutationCache.MutationCache();
this.#defaultOptions = config.defaultOptions || {};
this.#queryDefaults = new Map();
this.#mutationDefaults = new Map();
this.#mountCount = 0;
}
mount() {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mountCount)[_mountCount]++;
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mountCount)[_mountCount] !== 1) return;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _unsubscribeFocus)[_unsubscribeFocus] = focusManager.focusManager.subscribe(() => {
this.#mountCount++;
if (this.#mountCount !== 1) return;
this.#unsubscribeFocus = focusManager.focusManager.subscribe(() => {
if (focusManager.focusManager.isFocused()) {
this.resumePausedMutations();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].onFocus();
this.#queryCache.onFocus();
}
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _unsubscribeOnline)[_unsubscribeOnline] = onlineManager.onlineManager.subscribe(() => {
this.#unsubscribeOnline = onlineManager.onlineManager.subscribe(() => {
if (onlineManager.onlineManager.isOnline()) {
this.resumePausedMutations();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].onOnline();
this.#queryCache.onOnline();
}

@@ -82,12 +50,11 @@ });

unmount() {
var _classPrivateFieldLoo, _classPrivateFieldLoo2, _classPrivateFieldLoo3, _classPrivateFieldLoo4;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mountCount)[_mountCount]--;
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mountCount)[_mountCount] !== 0) return;
(_classPrivateFieldLoo = (_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _unsubscribeFocus))[_unsubscribeFocus]) == null ? void 0 : _classPrivateFieldLoo.call(_classPrivateFieldLoo2);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _unsubscribeFocus)[_unsubscribeFocus] = undefined;
(_classPrivateFieldLoo3 = (_classPrivateFieldLoo4 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _unsubscribeOnline))[_unsubscribeOnline]) == null ? void 0 : _classPrivateFieldLoo3.call(_classPrivateFieldLoo4);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _unsubscribeOnline)[_unsubscribeOnline] = undefined;
this.#mountCount--;
if (this.#mountCount !== 0) return;
this.#unsubscribeFocus?.();
this.#unsubscribeFocus = undefined;
this.#unsubscribeOnline?.();
this.#unsubscribeOnline = undefined;
}
isFetching(filters) {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].findAll({
return this.#queryCache.findAll({
...filters,

@@ -98,3 +65,3 @@ fetchStatus: 'fetching'

isMutating(filters) {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].findAll({
return this.#mutationCache.findAll({
...filters,

@@ -105,6 +72,5 @@ status: 'pending'

getQueryData(queryKey) {
var _classPrivateFieldLoo5;
return (_classPrivateFieldLoo5 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].find({
return this.#queryCache.find({
queryKey
})) == null ? void 0 : _classPrivateFieldLoo5.state.data;
})?.state.data;
}

@@ -125,6 +91,6 @@ ensureQueryData(options) {

setQueryData(queryKey, updater, options) {
const query = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].find({
const query = this.#queryCache.find({
queryKey
});
const prevData = query == null ? void 0 : query.state.data;
const prevData = query?.state.data;
const data = utils.functionalUpdate(updater, prevData);

@@ -137,3 +103,3 @@ if (typeof data === 'undefined') {

});
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].build(this, defaultedOptions).setData(data, {
return this.#queryCache.build(this, defaultedOptions).setData(data, {
...options,

@@ -149,9 +115,8 @@ manual: true

getQueryState(queryKey) {
var _classPrivateFieldLoo6;
return (_classPrivateFieldLoo6 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].find({
return this.#queryCache.find({
queryKey
})) == null ? void 0 : _classPrivateFieldLoo6.state;
})?.state;
}
removeQueries(filters) {
const queryCache = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache];
const queryCache = this.#queryCache;
notifyManager.notifyManager.batch(() => {

@@ -164,3 +129,3 @@ queryCache.findAll(filters).forEach(query => {

resetQueries(filters, options) {
const queryCache = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache];
const queryCache = this.#queryCache;
const refetchFilters = {

@@ -182,3 +147,3 @@ type: 'active',

};
const promises = notifyManager.notifyManager.batch(() => _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].findAll(filters).map(query => query.cancel(defaultedCancelOptions)));
const promises = notifyManager.notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(defaultedCancelOptions)));
return Promise.all(promises).then(utils.noop).catch(utils.noop);

@@ -188,4 +153,3 @@ }

return notifyManager.notifyManager.batch(() => {
var _ref, _filters$refetchType;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].findAll(filters).forEach(query => {
this.#queryCache.findAll(filters).forEach(query => {
query.invalidate();

@@ -198,3 +162,3 @@ });

...filters,
type: (_ref = (_filters$refetchType = filters.refetchType) != null ? _filters$refetchType : filters.type) != null ? _ref : 'active'
type: filters.refetchType ?? filters.type ?? 'active'
};

@@ -205,8 +169,7 @@ return this.refetchQueries(refetchFilters, options);

refetchQueries(filters = {}, options) {
var _options$cancelRefetc;
const fetchOptions = {
...options,
cancelRefetch: (_options$cancelRefetc = options == null ? void 0 : options.cancelRefetch) != null ? _options$cancelRefetc : true
cancelRefetch: options?.cancelRefetch ?? true
};
const promises = notifyManager.notifyManager.batch(() => _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].findAll(filters).filter(query => !query.isDisabled()).map(query => {
const promises = notifyManager.notifyManager.batch(() => this.#queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => {
let promise = query.fetch(undefined, fetchOptions);

@@ -227,3 +190,3 @@ if (!fetchOptions.throwOnError) {

}
const query = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].build(this, defaultedOptions);
const query = this.#queryCache.build(this, defaultedOptions);
return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);

@@ -242,18 +205,18 @@ }

resumePausedMutations() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].resumePausedMutations();
return this.#mutationCache.resumePausedMutations();
}
getQueryCache() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache];
return this.#queryCache;
}
getMutationCache() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache];
return this.#mutationCache;
}
getDefaultOptions() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions];
return this.#defaultOptions;
}
setDefaultOptions(options) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions] = options;
this.#defaultOptions = options;
}
setQueryDefaults(queryKey, options) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryDefaults)[_queryDefaults].set(utils.hashKey(queryKey), {
this.#queryDefaults.set(utils.hashKey(queryKey), {
queryKey,

@@ -264,3 +227,3 @@ defaultOptions: options

getQueryDefaults(queryKey) {
const defaults = [..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryDefaults)[_queryDefaults].values()];
const defaults = [...this.#queryDefaults.values()];
let result = {};

@@ -278,3 +241,3 @@ defaults.forEach(queryDefault => {

setMutationDefaults(mutationKey, options) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationDefaults)[_mutationDefaults].set(utils.hashKey(mutationKey), {
this.#mutationDefaults.set(utils.hashKey(mutationKey), {
mutationKey,

@@ -285,3 +248,3 @@ defaultOptions: options

getMutationDefaults(mutationKey) {
const defaults = [..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationDefaults)[_mutationDefaults].values()];
const defaults = [...this.#mutationDefaults.values()];
let result = {};

@@ -299,8 +262,8 @@ defaults.forEach(queryDefault => {

defaultQueryOptions(options) {
if (options != null && options._defaulted) {
if (options?._defaulted) {
return options;
}
const defaultedOptions = {
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions].queries,
...((options == null ? void 0 : options.queryKey) && this.getQueryDefaults(options.queryKey)),
...this.#defaultOptions.queries,
...(options?.queryKey && this.getQueryDefaults(options.queryKey)),
...options,

@@ -323,8 +286,8 @@ _defaulted: true

defaultMutationOptions(options) {
if (options != null && options._defaulted) {
if (options?._defaulted) {
return options;
}
return {
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions].mutations,
...((options == null ? void 0 : options.mutationKey) && this.getMutationDefaults(options.mutationKey)),
...this.#defaultOptions.mutations,
...(options?.mutationKey && this.getMutationDefaults(options.mutationKey)),
...options,

@@ -335,4 +298,4 @@ _defaulted: true

clear() {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queryCache)[_queryCache].clear();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationCache)[_mutationCache].clear();
this.#queryCache.clear();
this.#mutationCache.clear();
}

@@ -339,0 +302,0 @@ }

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var utils = require('./utils.js');

@@ -10,120 +9,24 @@ var notifyManager = require('./notifyManager.js');

var _client = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("client");
var _currentQuery = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentQuery");
var _currentQueryInitialState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentQueryInitialState");
var _currentResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentResult");
var _currentResultState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentResultState");
var _currentResultOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentResultOptions");
var _selectError = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("selectError");
var _selectFn = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("selectFn");
var _selectResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("selectResult");
var _lastQueryWithDefinedData = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("lastQueryWithDefinedData");
var _staleTimeoutId = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("staleTimeoutId");
var _refetchIntervalId = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("refetchIntervalId");
var _currentRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentRefetchInterval");
var _trackedProps = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("trackedProps");
var _executeFetch = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("executeFetch");
var _updateStaleTimeout = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateStaleTimeout");
var _computeRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("computeRefetchInterval");
var _updateRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateRefetchInterval");
var _updateTimers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateTimers");
var _clearStaleTimeout = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("clearStaleTimeout");
var _clearRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("clearRefetchInterval");
var _updateResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateResult");
var _updateQuery = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateQuery");
var _notify = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("notify");
class QueryObserver extends subscribable.Subscribable {
#client;
#currentQuery = undefined;
#currentQueryInitialState = undefined;
#currentResult = undefined;
#currentResultState;
#currentResultOptions;
#selectError;
#selectFn;
#selectResult;
// This property keeps track of the last query with defined data.
// It will be used to pass the previous data and query to the placeholder function between renders.
#lastQueryWithDefinedData;
#staleTimeoutId;
#refetchIntervalId;
#currentRefetchInterval;
#trackedProps = new Set();
constructor(client, options) {
super();
Object.defineProperty(this, _notify, {
value: _notify2
});
Object.defineProperty(this, _updateQuery, {
value: _updateQuery2
});
Object.defineProperty(this, _updateResult, {
value: _updateResult2
});
Object.defineProperty(this, _clearRefetchInterval, {
value: _clearRefetchInterval2
});
Object.defineProperty(this, _clearStaleTimeout, {
value: _clearStaleTimeout2
});
Object.defineProperty(this, _updateTimers, {
value: _updateTimers2
});
Object.defineProperty(this, _updateRefetchInterval, {
value: _updateRefetchInterval2
});
Object.defineProperty(this, _computeRefetchInterval, {
value: _computeRefetchInterval2
});
Object.defineProperty(this, _updateStaleTimeout, {
value: _updateStaleTimeout2
});
Object.defineProperty(this, _executeFetch, {
value: _executeFetch2
});
Object.defineProperty(this, _client, {
writable: true,
value: void 0
});
Object.defineProperty(this, _currentQuery, {
writable: true,
value: undefined
});
Object.defineProperty(this, _currentQueryInitialState, {
writable: true,
value: undefined
});
Object.defineProperty(this, _currentResult, {
writable: true,
value: undefined
});
Object.defineProperty(this, _currentResultState, {
writable: true,
value: void 0
});
Object.defineProperty(this, _currentResultOptions, {
writable: true,
value: void 0
});
Object.defineProperty(this, _selectError, {
writable: true,
value: void 0
});
Object.defineProperty(this, _selectFn, {
writable: true,
value: void 0
});
Object.defineProperty(this, _selectResult, {
writable: true,
value: void 0
});
// This property keeps track of the last query with defined data.
// It will be used to pass the previous data and query to the placeholder function between renders.
Object.defineProperty(this, _lastQueryWithDefinedData, {
writable: true,
value: void 0
});
Object.defineProperty(this, _staleTimeoutId, {
writable: true,
value: void 0
});
Object.defineProperty(this, _refetchIntervalId, {
writable: true,
value: void 0
});
Object.defineProperty(this, _currentRefetchInterval, {
writable: true,
value: void 0
});
Object.defineProperty(this, _trackedProps, {
writable: true,
value: new Set()
});
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = client;
this.#client = client;
this.options = options;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError] = null;
this.#selectError = null;
this.bindMethods();

@@ -137,7 +40,7 @@ this.setOptions(options);

if (this.listeners.size === 1) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].addObserver(this);
if (shouldFetchOnMount(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
this.#currentQuery.addObserver(this);
if (shouldFetchOnMount(this.#currentQuery, this.options)) {
this.#executeFetch();
}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateTimers)[_updateTimers]();
this.#updateTimers();
}

@@ -151,21 +54,21 @@ }

shouldFetchOnReconnect() {
return shouldFetchOn(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options, this.options.refetchOnReconnect);
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
}
shouldFetchOnWindowFocus() {
return shouldFetchOn(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options, this.options.refetchOnWindowFocus);
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
}
destroy() {
this.listeners = new Set();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _clearStaleTimeout)[_clearStaleTimeout]();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _clearRefetchInterval)[_clearRefetchInterval]();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].removeObserver(this);
this.#clearStaleTimeout();
this.#clearRefetchInterval();
this.#currentQuery.removeObserver(this);
}
setOptions(options, notifyOptions) {
const prevOptions = this.options;
const prevQuery = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
this.options = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].defaultQueryOptions(options);
const prevQuery = this.#currentQuery;
this.options = this.#client.defaultQueryOptions(options);
if (!utils.shallowEqualObjects(prevOptions, this.options)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().notify({
this.#client.getQueryCache().notify({
type: 'observerOptionsUpdated',
query: _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery],
query: this.#currentQuery,
observer: this

@@ -182,30 +85,30 @@ });

}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateQuery)[_updateQuery]();
this.#updateQuery();
const mounted = this.hasListeners();
// Fetch if there are subscribers
if (mounted && shouldFetchOptionally(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], prevQuery, this.options, prevOptions)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) {
this.#executeFetch();
}
// Update result
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult](notifyOptions);
this.#updateResult(notifyOptions);
// Update stale interval if needed
if (mounted && (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery] !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateStaleTimeout)[_updateStaleTimeout]();
if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
this.#updateStaleTimeout();
}
const nextRefetchInterval = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _computeRefetchInterval)[_computeRefetchInterval]();
const nextRefetchInterval = this.#computeRefetchInterval();
// Update refetch interval if needed
if (mounted && (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery] !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval])) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateRefetchInterval)[_updateRefetchInterval](nextRefetchInterval);
if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.#currentRefetchInterval)) {
this.#updateRefetchInterval(nextRefetchInterval);
}
}
getOptimisticResult(options) {
const query = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], options);
const query = this.#client.getQueryCache().build(this.#client, options);
return this.createResult(query, options);
}
getCurrentResult() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
return this.#currentResult;
}

@@ -219,3 +122,3 @@ trackResult(result) {

get: () => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _trackedProps)[_trackedProps].add(key);
this.#trackedProps.add(key);
return result[key];

@@ -228,3 +131,3 @@ }

getCurrentQuery() {
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
return this.#currentQuery;
}

@@ -239,4 +142,4 @@ refetch({

fetchOptimistic(options) {
const defaultedOptions = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].defaultQueryOptions(options);
const query = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], defaultedOptions);
const defaultedOptions = this.#client.defaultQueryOptions(options);
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
query.isFetchingOptimistic = true;

@@ -246,19 +149,76 @@ return query.fetch().then(() => this.createResult(query, defaultedOptions));

fetch(fetchOptions) {
var _fetchOptions$cancelR;
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]({
return this.#executeFetch({
...fetchOptions,
cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
cancelRefetch: fetchOptions.cancelRefetch ?? true
}).then(() => {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
this.#updateResult();
return this.#currentResult;
});
}
#executeFetch(fetchOptions) {
// Make sure we reference the latest query as the current one might have been removed
this.#updateQuery();
// Fetch
let promise = this.#currentQuery.fetch(this.options, fetchOptions);
if (!fetchOptions?.throwOnError) {
promise = promise.catch(utils.noop);
}
return promise;
}
#updateStaleTimeout() {
this.#clearStaleTimeout();
if (utils.isServer || this.#currentResult.isStale || !utils.isValidTimeout(this.options.staleTime)) {
return;
}
const time = utils.timeUntilStale(this.#currentResult.dataUpdatedAt, this.options.staleTime);
// The timeout is sometimes triggered 1 ms before the stale time expiration.
// To mitigate this issue we always add 1 ms to the timeout.
const timeout = time + 1;
this.#staleTimeoutId = setTimeout(() => {
if (!this.#currentResult.isStale) {
this.#updateResult();
}
}, timeout);
}
#computeRefetchInterval() {
return (typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval) ?? false;
}
#updateRefetchInterval(nextInterval) {
this.#clearRefetchInterval();
this.#currentRefetchInterval = nextInterval;
if (utils.isServer || this.options.enabled === false || !utils.isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
return;
}
this.#refetchIntervalId = setInterval(() => {
if (this.options.refetchIntervalInBackground || focusManager.focusManager.isFocused()) {
this.#executeFetch();
}
}, this.#currentRefetchInterval);
}
#updateTimers() {
this.#updateStaleTimeout();
this.#updateRefetchInterval(this.#computeRefetchInterval());
}
#clearStaleTimeout() {
if (this.#staleTimeoutId) {
clearTimeout(this.#staleTimeoutId);
this.#staleTimeoutId = undefined;
}
}
#clearRefetchInterval() {
if (this.#refetchIntervalId) {
clearInterval(this.#refetchIntervalId);
this.#refetchIntervalId = undefined;
}
}
createResult(query, options) {
const prevQuery = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
const prevQuery = this.#currentQuery;
const prevOptions = this.options;
const prevResult = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
const prevResultState = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultState)[_currentResultState];
const prevResultOptions = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultOptions)[_currentResultOptions];
const prevResult = this.#currentResult;
const prevResultState = this.#currentResultState;
const prevResultOptions = this.#currentResultOptions;
const queryChange = query !== prevQuery;
const queryInitialState = queryChange ? query.state : _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQueryInitialState)[_currentQueryInitialState];
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
const {

@@ -295,13 +255,13 @@ state

// Memoize select result
if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectFn)[_selectFn]) {
data = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectResult)[_selectResult];
if (prevResult && state.data === prevResultState?.data && options.select === this.#selectFn) {
data = this.#selectResult;
} else {
try {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectFn)[_selectFn] = options.select;
this.#selectFn = options.select;
data = options.select(state.data);
data = utils.replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectResult)[_selectResult] = data;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError] = null;
data = utils.replaceData(prevResult?.data, data, options);
this.#selectResult = data;
this.#selectError = null;
} catch (selectError) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError] = selectError;
this.#selectError = selectError;
}

@@ -320,13 +280,12 @@ }

// Memoize placeholder data
if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
placeholderData = prevResult.data;
} else {
var _classPrivateFieldLoo;
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData((_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _lastQueryWithDefinedData)[_lastQueryWithDefinedData]) == null ? void 0 : _classPrivateFieldLoo.state.data, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _lastQueryWithDefinedData)[_lastQueryWithDefinedData]) : options.placeholderData;
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
if (options.select && typeof placeholderData !== 'undefined') {
try {
placeholderData = options.select(placeholderData);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError] = null;
this.#selectError = null;
} catch (selectError) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError] = selectError;
this.#selectError = selectError;
}

@@ -337,9 +296,9 @@ }

status = 'success';
data = utils.replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
data = utils.replaceData(prevResult?.data, placeholderData, options);
isPlaceholderData = true;
}
}
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError]) {
error = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectError)[_selectError];
data = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _selectResult)[_selectResult];
if (this.#selectError) {
error = this.#selectError;
data = this.#selectResult;
errorUpdatedAt = Date.now();

@@ -380,141 +339,82 @@ status = 'error';

}
onQueryUpdate() {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
if (this.hasListeners()) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateTimers)[_updateTimers]();
}
}
}
function _executeFetch2(fetchOptions) {
// Make sure we reference the latest query as the current one might have been removed
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateQuery)[_updateQuery]();
#updateResult(notifyOptions) {
const prevResult = this.#currentResult;
const nextResult = this.createResult(this.#currentQuery, this.options);
this.#currentResultState = this.#currentQuery.state;
this.#currentResultOptions = this.options;
// Fetch
let promise = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].fetch(this.options, fetchOptions);
if (!(fetchOptions != null && fetchOptions.throwOnError)) {
promise = promise.catch(utils.noop);
}
return promise;
}
function _updateStaleTimeout2() {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _clearStaleTimeout)[_clearStaleTimeout]();
if (utils.isServer || _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].isStale || !utils.isValidTimeout(this.options.staleTime)) {
return;
}
const time = utils.timeUntilStale(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].dataUpdatedAt, this.options.staleTime);
// The timeout is sometimes triggered 1 ms before the stale time expiration.
// To mitigate this issue we always add 1 ms to the timeout.
const timeout = time + 1;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId] = setTimeout(() => {
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].isStale) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
// Only notify and update result if something has changed
if (utils.shallowEqualObjects(nextResult, prevResult)) {
return;
}
}, timeout);
}
function _computeRefetchInterval2() {
var _ref;
return (_ref = typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery]) : this.options.refetchInterval) != null ? _ref : false;
}
function _updateRefetchInterval2(nextInterval) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _clearRefetchInterval)[_clearRefetchInterval]();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval] = nextInterval;
if (utils.isServer || this.options.enabled === false || !utils.isValidTimeout(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval]) || _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval] === 0) {
return;
}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId] = setInterval(() => {
if (this.options.refetchIntervalInBackground || focusManager.focusManager.isFocused()) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
if (this.#currentResultState.data !== undefined) {
this.#lastQueryWithDefinedData = this.#currentQuery;
}
}, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval]);
}
function _updateTimers2() {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateStaleTimeout)[_updateStaleTimeout]();
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateRefetchInterval)[_updateRefetchInterval](_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _computeRefetchInterval)[_computeRefetchInterval]());
}
function _clearStaleTimeout2() {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId]) {
clearTimeout(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId]);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId] = undefined;
}
}
function _clearRefetchInterval2() {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId]) {
clearInterval(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId]);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId] = undefined;
}
}
function _updateResult2(notifyOptions) {
const prevResult = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
const nextResult = this.createResult(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultState)[_currentResultState] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].state;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultOptions)[_currentResultOptions] = this.options;
this.#currentResult = nextResult;
// Only notify and update result if something has changed
if (utils.shallowEqualObjects(nextResult, prevResult)) {
return;
// Determine which callbacks to trigger
const defaultNotifyOptions = {};
const shouldNotifyListeners = () => {
if (!prevResult) {
return true;
}
const {
notifyOnChangeProps
} = this.options;
if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.#trackedProps.size) {
return true;
}
const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
if (this.options.throwOnError) {
includedProps.add('error');
}
return Object.keys(this.#currentResult).some(key => {
const typedKey = key;
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
return changed && includedProps.has(typedKey);
});
};
if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
defaultNotifyOptions.listeners = true;
}
this.#notify({
...defaultNotifyOptions,
...notifyOptions
});
}
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultState)[_currentResultState].data !== undefined) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _lastQueryWithDefinedData)[_lastQueryWithDefinedData] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult] = nextResult;
// Determine which callbacks to trigger
const defaultNotifyOptions = {};
const shouldNotifyListeners = () => {
if (!prevResult) {
return true;
#updateQuery() {
const query = this.#client.getQueryCache().build(this.#client, this.options);
if (query === this.#currentQuery) {
return;
}
const {
notifyOnChangeProps
} = this.options;
if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _trackedProps)[_trackedProps].size) {
return true;
const prevQuery = this.#currentQuery;
this.#currentQuery = query;
this.#currentQueryInitialState = query.state;
if (this.hasListeners()) {
prevQuery?.removeObserver(this);
query.addObserver(this);
}
const includedProps = new Set(notifyOnChangeProps != null ? notifyOnChangeProps : _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _trackedProps)[_trackedProps]);
if (this.options.throwOnError) {
includedProps.add('error');
}
onQueryUpdate() {
this.#updateResult();
if (this.hasListeners()) {
this.#updateTimers();
}
return Object.keys(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult]).some(key => {
const typedKey = key;
const changed = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult][typedKey] !== prevResult[typedKey];
return changed && includedProps.has(typedKey);
});
};
if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
defaultNotifyOptions.listeners = true;
}
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify]({
...defaultNotifyOptions,
...notifyOptions
});
}
function _updateQuery2() {
const query = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], this.options);
if (query === _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery]) {
return;
}
const prevQuery = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery] = query;
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQueryInitialState)[_currentQueryInitialState] = query.state;
if (this.hasListeners()) {
prevQuery == null ? void 0 : prevQuery.removeObserver(this);
query.addObserver(this);
}
}
function _notify2(notifyOptions) {
notifyManager.notifyManager.batch(() => {
// First, trigger the listeners
if (notifyOptions.listeners) {
this.listeners.forEach(listener => {
listener(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult]);
#notify(notifyOptions) {
notifyManager.notifyManager.batch(() => {
// First, trigger the listeners
if (notifyOptions.listeners) {
this.listeners.forEach(listener => {
listener(this.#currentResult);
});
}
// Then the cache listeners
this.#client.getQueryCache().notify({
query: this.#currentQuery,
type: 'observerResultsUpdated'
});
}
// Then the cache listeners
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().notify({
query: _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery],
type: 'observerResultsUpdated'
});
});
}
}

@@ -521,0 +421,0 @@ function shouldLoadOnMount(query, options) {

'use strict';
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var utils = require('./utils.js');
var _gcTimeout = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("gcTimeout");
class Removable {
constructor() {
Object.defineProperty(this, _gcTimeout, {
writable: true,
value: void 0
});
}
#gcTimeout;
destroy() {

@@ -20,3 +13,3 @@ this.clearGcTimeout();

if (utils.isValidTimeout(this.gcTime)) {
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _gcTimeout)[_gcTimeout] = setTimeout(() => {
this.#gcTimeout = setTimeout(() => {
this.optionalRemove();

@@ -28,8 +21,8 @@ }, this.gcTime);

// Default to 5 minutes (Infinity for server-side) if no gcTime is set
this.gcTime = Math.max(this.gcTime || 0, newGcTime != null ? newGcTime : utils.isServer ? Infinity : 5 * 60 * 1000);
this.gcTime = Math.max(this.gcTime || 0, newGcTime ?? (utils.isServer ? Infinity : 5 * 60 * 1000));
}
clearGcTimeout() {
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _gcTimeout)[_gcTimeout]) {
clearTimeout(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _gcTimeout)[_gcTimeout]);
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _gcTimeout)[_gcTimeout] = undefined;
if (this.#gcTimeout) {
clearTimeout(this.#gcTimeout);
this.#gcTimeout = undefined;
}

@@ -36,0 +29,0 @@ }

@@ -13,8 +13,8 @@ 'use strict';

function canFetch(networkMode) {
return (networkMode != null ? networkMode : 'online') === 'online' ? onlineManager.onlineManager.isOnline() : true;
return (networkMode ?? 'online') === 'online' ? onlineManager.onlineManager.isOnline() : true;
}
class CancelledError {
constructor(options) {
this.revert = options == null ? void 0 : options.revert;
this.silent = options == null ? void 0 : options.silent;
this.revert = options?.revert;
this.silent = options?.silent;
}

@@ -39,3 +39,3 @@ }

reject(new CancelledError(cancelOptions));
config.abort == null ? void 0 : config.abort();
config.abort?.();
}

@@ -53,4 +53,4 @@ };

isResolved = true;
config.onSuccess == null ? void 0 : config.onSuccess(value);
continueFn == null ? void 0 : continueFn();
config.onSuccess?.(value);
continueFn?.();
promiseResolve(value);

@@ -62,4 +62,4 @@ }

isResolved = true;
config.onError == null ? void 0 : config.onError(value);
continueFn == null ? void 0 : continueFn();
config.onError?.(value);
continueFn?.();
promiseReject(value);

@@ -77,7 +77,7 @@ }

};
config.onPause == null ? void 0 : config.onPause();
config.onPause?.();
}).then(() => {
continueFn = undefined;
if (!isResolved) {
config.onContinue == null ? void 0 : config.onContinue();
config.onContinue?.();
}

@@ -102,3 +102,2 @@ });

Promise.resolve(promiseOrValue).then(resolve).catch(error => {
var _config$retry, _config$retryDelay;
// Stop if the fetch is already resolved

@@ -110,4 +109,4 @@ if (isResolved) {

// Do we need to retry the request?
const retry = (_config$retry = config.retry) != null ? _config$retry : 3;
const retryDelay = (_config$retryDelay = config.retryDelay) != null ? _config$retryDelay : defaultRetryDelay;
const retry = config.retry ?? 3;
const retryDelay = config.retryDelay ?? defaultRetryDelay;
const delay = typeof retryDelay === 'function' ? retryDelay(failureCount, error) : retryDelay;

@@ -123,3 +122,3 @@ const shouldRetry = retry === true || typeof retry === 'number' && failureCount < retry || typeof retry === 'function' && retry(failureCount, error);

// Notify on fail
config.onFail == null ? void 0 : config.onFail(failureCount, error);
config.onFail?.(failureCount, error);

@@ -154,3 +153,3 @@ // Delay

continue: () => {
const didContinue = continueFn == null ? void 0 : continueFn();
const didContinue = continueFn?.();
return didContinue ? promise : Promise.resolve();

@@ -157,0 +156,0 @@ },

@@ -86,3 +86,3 @@ 'use strict';

function hashQueryKeyByOptions(queryKey, options) {
const hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashKey;
const hashFn = options?.queryKeyHashFn || hashKey;
return hashFn(queryKey);

@@ -89,0 +89,0 @@ }

{
"name": "@tanstack/query-core",
"version": "5.0.0-alpha.49",
"version": "5.0.0-alpha.50",
"description": "The framework agnostic core that powers TanStack Query",

@@ -28,3 +28,2 @@ "author": "tannerlinsley",

"build/lib/*",
"build/umd/*",
"src"

@@ -31,0 +30,0 @@ ],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc