@braine/quantum-query 1.2.8 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -55,6 +55,9 @@ function createSignal(initialValue, options) {
55
55
  set: (newValue) => {
56
56
  s.value = newValue;
57
57
  },
58
+ update: (fn) => {
59
+ s.value = fn(s.value);
60
+ },
58
61
  subscribe: (fn) => {
59
62
  if (subscriberCount === 0) {
60
63
  options?.onActive?.();
@@ -82,6 +85,9 @@ function computed(fn) {
82
85
  set: () => {
83
86
  throw new Error("[Quantum] Cannot set a computed signal directly.");
84
87
  },
88
+ update: () => {
89
+ throw new Error("[Quantum] Cannot update a computed signal directly.");
90
+ },
85
91
  subscribe: (fn2) => {
86
92
  subscriberCount++;
87
93
  const dispose = (0, import_signals_core.effect)(() => {
@@ -591,7 +597,7 @@ function isDeepEqual(a, b) {
591
597
  var QueryStorage = class {
592
598
  // Tracks access order (least to most recent)
593
599
  // Default configuration
594
- constructor(defaultStaleTime = 0, defaultCacheTime = 5 * 60 * 1e3, maxSize = 100) {
600
+ constructor(defaultStaleTime = 5 * 60 * 1e3, defaultCacheTime = 5 * 60 * 1e3, maxSize = 100) {
595
601
  this.defaultStaleTime = defaultStaleTime;
596
602
  this.defaultCacheTime = defaultCacheTime;
597
603
  this.maxSize = maxSize;
@@ -944,7 +950,7 @@ var QueryClient = class {
944
950
  defaultCacheTime;
945
951
  defaultSchema;
946
952
  constructor(config) {
947
- this.defaultStaleTime = config?.defaultStaleTime ?? 0;
953
+ this.defaultStaleTime = config?.defaultStaleTime ?? 5 * 60 * 1e3;
948
954
  this.defaultCacheTime = config?.defaultCacheTime ?? 5 * 60 * 1e3;
949
955
  this.defaultSchema = config?.defaultSchema;
950
956
  this.storage = new QueryStorage(
@@ -1126,6 +1132,14 @@ var QueryClient = class {
1126
1132
  return Date.now() - entry.timestamp > entry.staleTime;
1127
1133
  };
1128
1134
  getAll = () => this.storage.getAll();
1135
+ /**
1136
+ * Check if a query key exists in the cache
1137
+ */
1138
+ has = (queryKey) => {
1139
+ const key = this.storage.generateKey(queryKey);
1140
+ const signal2 = this.storage.get(key, false);
1141
+ return signal2 !== void 0 && signal2.get() !== void 0;
1142
+ };
1129
1143
  snapshot = () => this.storage.getSnapshot();
1130
1144
  clear = () => this.storage.clear();
1131
1145
  remove = (key) => this.storage.delete(this.storage.generateKey(key));
package/dist/index.d.cts CHANGED
@@ -10,6 +10,7 @@ import React$1, { ReactNode } from 'react';
10
10
  interface Signal<T> {
11
11
  get: () => T;
12
12
  set: (value: T) => void;
13
+ update: (fn: (current: T) => T) => void;
13
14
  subscribe: (fn: (value: T) => void) => () => void;
14
15
  isWatched: () => boolean;
15
16
  }
@@ -244,6 +245,10 @@ declare class QueryClient {
244
245
  use: (plugin: QueryPlugin) => this;
245
246
  isStale: (queryKey: QueryKeyInput) => boolean;
246
247
  getAll: () => Map<string, CacheEntry<unknown>>;
248
+ /**
249
+ * Check if a query key exists in the cache
250
+ */
251
+ has: (queryKey: QueryKeyInput) => boolean;
247
252
  snapshot: () => Map<string, CacheEntry<unknown>>;
248
253
  clear: () => void;
249
254
  remove: (key: QueryKeyInput) => void;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ import React$1, { ReactNode } from 'react';
10
10
  interface Signal<T> {
11
11
  get: () => T;
12
12
  set: (value: T) => void;
13
+ update: (fn: (current: T) => T) => void;
13
14
  subscribe: (fn: (value: T) => void) => () => void;
14
15
  isWatched: () => boolean;
15
16
  }
@@ -244,6 +245,10 @@ declare class QueryClient {
244
245
  use: (plugin: QueryPlugin) => this;
245
246
  isStale: (queryKey: QueryKeyInput) => boolean;
246
247
  getAll: () => Map<string, CacheEntry<unknown>>;
248
+ /**
249
+ * Check if a query key exists in the cache
250
+ */
251
+ has: (queryKey: QueryKeyInput) => boolean;
247
252
  snapshot: () => Map<string, CacheEntry<unknown>>;
248
253
  clear: () => void;
249
254
  remove: (key: QueryKeyInput) => void;
package/dist/index.js CHANGED
@@ -14,6 +14,9 @@ function createSignal(initialValue, options) {
14
14
  set: (newValue) => {
15
15
  s.value = newValue;
16
16
  },
17
+ update: (fn) => {
18
+ s.value = fn(s.value);
19
+ },
17
20
  subscribe: (fn) => {
18
21
  if (subscriberCount === 0) {
19
22
  options?.onActive?.();
@@ -41,6 +44,9 @@ function computed(fn) {
41
44
  set: () => {
42
45
  throw new Error("[Quantum] Cannot set a computed signal directly.");
43
46
  },
47
+ update: () => {
48
+ throw new Error("[Quantum] Cannot update a computed signal directly.");
49
+ },
44
50
  subscribe: (fn2) => {
45
51
  subscriberCount++;
46
52
  const dispose = preactEffect(() => {
@@ -550,7 +556,7 @@ function isDeepEqual(a, b) {
550
556
  var QueryStorage = class {
551
557
  // Tracks access order (least to most recent)
552
558
  // Default configuration
553
- constructor(defaultStaleTime = 0, defaultCacheTime = 5 * 60 * 1e3, maxSize = 100) {
559
+ constructor(defaultStaleTime = 5 * 60 * 1e3, defaultCacheTime = 5 * 60 * 1e3, maxSize = 100) {
554
560
  this.defaultStaleTime = defaultStaleTime;
555
561
  this.defaultCacheTime = defaultCacheTime;
556
562
  this.maxSize = maxSize;
@@ -903,7 +909,7 @@ var QueryClient = class {
903
909
  defaultCacheTime;
904
910
  defaultSchema;
905
911
  constructor(config) {
906
- this.defaultStaleTime = config?.defaultStaleTime ?? 0;
912
+ this.defaultStaleTime = config?.defaultStaleTime ?? 5 * 60 * 1e3;
907
913
  this.defaultCacheTime = config?.defaultCacheTime ?? 5 * 60 * 1e3;
908
914
  this.defaultSchema = config?.defaultSchema;
909
915
  this.storage = new QueryStorage(
@@ -1085,6 +1091,14 @@ var QueryClient = class {
1085
1091
  return Date.now() - entry.timestamp > entry.staleTime;
1086
1092
  };
1087
1093
  getAll = () => this.storage.getAll();
1094
+ /**
1095
+ * Check if a query key exists in the cache
1096
+ */
1097
+ has = (queryKey) => {
1098
+ const key = this.storage.generateKey(queryKey);
1099
+ const signal2 = this.storage.get(key, false);
1100
+ return signal2 !== void 0 && signal2.get() !== void 0;
1101
+ };
1088
1102
  snapshot = () => this.storage.getSnapshot();
1089
1103
  clear = () => this.storage.clear();
1090
1104
  remove = (key) => this.storage.delete(this.storage.generateKey(key));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braine/quantum-query",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "scripts": {