qortex-core 0.1.4 → 0.1.5
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/index.d.ts +23 -3
- package/index.js +34 -1
- package/index.mjs +34 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* Using readonly to prevent accidental mutations
|
|
4
4
|
*/
|
|
5
5
|
type QueryKey = string | readonly (string | number)[];
|
|
6
|
-
/** Valid query key values - only strings and numbers are allowed */
|
|
7
|
-
type QueryKeyValue = string | number;
|
|
8
6
|
/** Function that fetches data, can be async or sync */
|
|
9
7
|
type Fetcher<T = any> = () => Promise<T> | T;
|
|
10
8
|
/** Function that compares two values for equality */
|
|
@@ -88,6 +86,28 @@ declare class QueryManager {
|
|
|
88
86
|
private lastReturnedState;
|
|
89
87
|
private defaultConfig;
|
|
90
88
|
private throttleTime;
|
|
89
|
+
/**
|
|
90
|
+
* ⚠️ DANGER: Clear all cached data and subscriptions
|
|
91
|
+
*
|
|
92
|
+
* This method completely wipes all internal state including:
|
|
93
|
+
* - All cached query data
|
|
94
|
+
* - All active subscriptions
|
|
95
|
+
* - All state references
|
|
96
|
+
*
|
|
97
|
+
* @warning This should ONLY be used in testing environments or when you need to completely reset the query manager state. Using this in production will cause all active queries to lose their data and subscriptions to break.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // ✅ Safe usage in tests
|
|
102
|
+
* beforeEach(() => {
|
|
103
|
+
* queryManager.dangerClearCache();
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // ❌ Dangerous usage in production
|
|
107
|
+
* // queryManager.dangerClearCache(); // Don't do this!
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
dangerClearCache(): void;
|
|
91
111
|
/**
|
|
92
112
|
* Set default configuration for all queries
|
|
93
113
|
*/
|
|
@@ -168,4 +188,4 @@ declare const queryManager: QueryManager;
|
|
|
168
188
|
*/
|
|
169
189
|
declare function serializeKey(key: QueryKey): string;
|
|
170
190
|
|
|
171
|
-
export { DefaultConfig, EqualityFn, Fetcher, InferFetcherResult, QueryKey,
|
|
191
|
+
export { DefaultConfig, EqualityFn, Fetcher, InferFetcherResult, QueryKey, QueryManager, QueryOptions, QueryState, QueryStatus, queryManager, serializeKey };
|
package/index.js
CHANGED
|
@@ -114,6 +114,11 @@ function createPublicState(state) {
|
|
|
114
114
|
refetch: state.refetch
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
+
function warnNoFetcherOrData(key) {
|
|
118
|
+
console.warn(
|
|
119
|
+
`[qortex] No fetcher or data for key "${serializeKey(key)}". Register a fetcher or set initial data.`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
117
122
|
|
|
118
123
|
// src/queryManager.ts
|
|
119
124
|
var QueryManager = class {
|
|
@@ -124,6 +129,32 @@ var QueryManager = class {
|
|
|
124
129
|
this.defaultConfig = {};
|
|
125
130
|
this.throttleTime = THROTTLE_TIME;
|
|
126
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* ⚠️ DANGER: Clear all cached data and subscriptions
|
|
134
|
+
*
|
|
135
|
+
* This method completely wipes all internal state including:
|
|
136
|
+
* - All cached query data
|
|
137
|
+
* - All active subscriptions
|
|
138
|
+
* - All state references
|
|
139
|
+
*
|
|
140
|
+
* @warning This should ONLY be used in testing environments or when you need to completely reset the query manager state. Using this in production will cause all active queries to lose their data and subscriptions to break.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* // ✅ Safe usage in tests
|
|
145
|
+
* beforeEach(() => {
|
|
146
|
+
* queryManager.dangerClearCache();
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* // ❌ Dangerous usage in production
|
|
150
|
+
* // queryManager.dangerClearCache(); // Don't do this!
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
dangerClearCache() {
|
|
154
|
+
this.cache.clear();
|
|
155
|
+
this.subs.clear();
|
|
156
|
+
this.lastReturnedState.clear();
|
|
157
|
+
}
|
|
127
158
|
/**
|
|
128
159
|
* Set default configuration for all queries
|
|
129
160
|
*/
|
|
@@ -179,7 +210,9 @@ var QueryManager = class {
|
|
|
179
210
|
return state.fetchPromise;
|
|
180
211
|
const fetcher = state.fetcher;
|
|
181
212
|
if (!fetcher) {
|
|
182
|
-
|
|
213
|
+
if (state.updatedAt === void 0) {
|
|
214
|
+
warnNoFetcherOrData(key);
|
|
215
|
+
}
|
|
183
216
|
return Promise.resolve(state.data);
|
|
184
217
|
}
|
|
185
218
|
;
|
package/index.mjs
CHANGED
|
@@ -86,6 +86,11 @@ function createPublicState(state) {
|
|
|
86
86
|
refetch: state.refetch
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
+
function warnNoFetcherOrData(key) {
|
|
90
|
+
console.warn(
|
|
91
|
+
`[qortex] No fetcher or data for key "${serializeKey(key)}". Register a fetcher or set initial data.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
89
94
|
|
|
90
95
|
// src/queryManager.ts
|
|
91
96
|
var QueryManager = class {
|
|
@@ -96,6 +101,32 @@ var QueryManager = class {
|
|
|
96
101
|
this.defaultConfig = {};
|
|
97
102
|
this.throttleTime = THROTTLE_TIME;
|
|
98
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* ⚠️ DANGER: Clear all cached data and subscriptions
|
|
106
|
+
*
|
|
107
|
+
* This method completely wipes all internal state including:
|
|
108
|
+
* - All cached query data
|
|
109
|
+
* - All active subscriptions
|
|
110
|
+
* - All state references
|
|
111
|
+
*
|
|
112
|
+
* @warning This should ONLY be used in testing environments or when you need to completely reset the query manager state. Using this in production will cause all active queries to lose their data and subscriptions to break.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // ✅ Safe usage in tests
|
|
117
|
+
* beforeEach(() => {
|
|
118
|
+
* queryManager.dangerClearCache();
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* // ❌ Dangerous usage in production
|
|
122
|
+
* // queryManager.dangerClearCache(); // Don't do this!
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
dangerClearCache() {
|
|
126
|
+
this.cache.clear();
|
|
127
|
+
this.subs.clear();
|
|
128
|
+
this.lastReturnedState.clear();
|
|
129
|
+
}
|
|
99
130
|
/**
|
|
100
131
|
* Set default configuration for all queries
|
|
101
132
|
*/
|
|
@@ -151,7 +182,9 @@ var QueryManager = class {
|
|
|
151
182
|
return state.fetchPromise;
|
|
152
183
|
const fetcher = state.fetcher;
|
|
153
184
|
if (!fetcher) {
|
|
154
|
-
|
|
185
|
+
if (state.updatedAt === void 0) {
|
|
186
|
+
warnNoFetcherOrData(key);
|
|
187
|
+
}
|
|
155
188
|
return Promise.resolve(state.data);
|
|
156
189
|
}
|
|
157
190
|
;
|