@codeleap/query 7.0.2 → 7.1.1
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/factors/createQueryManager.d.ts +17 -14
- package/dist/factors/createQueryManager.d.ts.map +1 -1
- package/dist/factors/createQueryManager.js +18 -19
- package/dist/factors/createQueryManager.js.map +1 -1
- package/dist/factors/createQueryOperations.js +3 -6
- package/dist/factors/createQueryOperations.js.map +1 -1
- package/dist/factors/index.js +2 -18
- package/dist/factors/index.js.map +1 -1
- package/dist/index.js +3 -19
- package/dist/index.js.map +1 -1
- package/dist/lib/Mutations.js +39 -50
- package/dist/lib/Mutations.js.map +1 -1
- package/dist/lib/QueryClientEnhanced/index.js +45 -51
- package/dist/lib/QueryClientEnhanced/index.js.map +1 -1
- package/dist/lib/QueryClientEnhanced/types.js +1 -2
- package/dist/lib/QueryKeys.js +80 -91
- package/dist/lib/QueryKeys.js.map +1 -1
- package/dist/lib/QueryManager.d.ts +26 -10
- package/dist/lib/QueryManager.d.ts.map +1 -1
- package/dist/lib/QueryManager.js +173 -121
- package/dist/lib/QueryManager.js.map +1 -1
- package/dist/lib/QueryOperations/index.d.ts +2 -2
- package/dist/lib/QueryOperations/index.d.ts.map +1 -1
- package/dist/lib/QueryOperations/index.js +33 -33
- package/dist/lib/QueryOperations/index.js.map +1 -1
- package/dist/lib/QueryOperations/types.js +1 -2
- package/dist/lib/index.js +5 -21
- package/dist/lib/index.js.map +1 -1
- package/dist/types/core.d.ts +17 -3
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js +1 -2
- package/dist/types/create.js +1 -2
- package/dist/types/delete.js +1 -2
- package/dist/types/index.js +7 -23
- package/dist/types/index.js.map +1 -1
- package/dist/types/list.d.ts +6 -4
- package/dist/types/list.d.ts.map +1 -1
- package/dist/types/list.js +1 -2
- package/dist/types/retrieve.js +1 -2
- package/dist/types/update.js +1 -2
- package/dist/types/utility.js +1 -2
- package/dist/utils/index.js +1 -17
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/misc.js +3 -7
- package/dist/utils/misc.js.map +1 -1
- package/package.json +5 -5
- package/src/factors/createQueryManager.ts +19 -16
- package/src/lib/QueryManager.ts +55 -15
- package/src/types/core.ts +22 -3
- package/src/types/list.ts +7 -5
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.QueryOperations = void 0;
|
|
13
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
-
const QueryClientEnhanced_1 = require("../QueryClientEnhanced");
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { QueryClientEnhanced } from '../QueryClientEnhanced';
|
|
15
3
|
/**
|
|
16
4
|
* Builder class for creating type-safe query and mutation operations
|
|
17
5
|
* @template TMutations - Record type containing all registered mutation functions
|
|
@@ -28,7 +16,10 @@ const QueryClientEnhanced_1 = require("../QueryClientEnhanced");
|
|
|
28
16
|
* - Type-safe React hooks generation
|
|
29
17
|
* - Immutable operation registration (returns new instances)
|
|
30
18
|
*/
|
|
31
|
-
class QueryOperations {
|
|
19
|
+
export class QueryOperations {
|
|
20
|
+
_options;
|
|
21
|
+
_mutations;
|
|
22
|
+
_queries;
|
|
32
23
|
/**
|
|
33
24
|
* Creates a new QueryOperations instance
|
|
34
25
|
* @param _options - Configuration options including QueryClient
|
|
@@ -48,7 +39,7 @@ class QueryOperations {
|
|
|
48
39
|
return this._mutations;
|
|
49
40
|
}
|
|
50
41
|
get queryClient() {
|
|
51
|
-
if (this._options.queryClient instanceof
|
|
42
|
+
if (this._options.queryClient instanceof QueryClientEnhanced) {
|
|
52
43
|
return this._options.queryClient.client;
|
|
53
44
|
}
|
|
54
45
|
return this._options.queryClient;
|
|
@@ -81,7 +72,7 @@ class QueryOperations {
|
|
|
81
72
|
* ```
|
|
82
73
|
*/
|
|
83
74
|
mutation(name, fn) {
|
|
84
|
-
return new QueryOperations(this._options,
|
|
75
|
+
return new QueryOperations(this._options, { ...this._mutations, [name]: fn }, this._queries);
|
|
85
76
|
}
|
|
86
77
|
/**
|
|
87
78
|
* Registers a new query function
|
|
@@ -104,7 +95,7 @@ class QueryOperations {
|
|
|
104
95
|
* ```
|
|
105
96
|
*/
|
|
106
97
|
query(name, fn) {
|
|
107
|
-
return new QueryOperations(this._options, this._mutations,
|
|
98
|
+
return new QueryOperations(this._options, this._mutations, { ...this._queries, [name]: fn });
|
|
108
99
|
}
|
|
109
100
|
/**
|
|
110
101
|
* React hook for executing mutations with full type safety
|
|
@@ -133,12 +124,16 @@ class QueryOperations {
|
|
|
133
124
|
*/
|
|
134
125
|
useMutation(mutationKey, options) {
|
|
135
126
|
const mutationFn = this._mutations[mutationKey];
|
|
136
|
-
return
|
|
127
|
+
return useMutation({
|
|
128
|
+
mutationKey: this.getMutationKey(mutationKey),
|
|
129
|
+
mutationFn: async (data) => {
|
|
137
130
|
if (!mutationFn) {
|
|
138
131
|
throw new Error(`Mutation "${String(mutationKey)}" not found`);
|
|
139
132
|
}
|
|
140
133
|
return mutationFn(data);
|
|
141
|
-
}
|
|
134
|
+
},
|
|
135
|
+
...options
|
|
136
|
+
});
|
|
142
137
|
}
|
|
143
138
|
/**
|
|
144
139
|
* React hook for executing queries with full type safety
|
|
@@ -171,12 +166,16 @@ class QueryOperations {
|
|
|
171
166
|
*/
|
|
172
167
|
useQuery(queryKey, params, options) {
|
|
173
168
|
const queryFn = this._queries[queryKey];
|
|
174
|
-
return
|
|
169
|
+
return useQuery({
|
|
170
|
+
queryKey: this.getQueryKey(queryKey, params),
|
|
171
|
+
queryFn: async () => {
|
|
175
172
|
if (!queryFn) {
|
|
176
173
|
throw new Error(`Query "${String(queryKey)}" not found`);
|
|
177
174
|
}
|
|
178
175
|
return queryFn(params);
|
|
179
|
-
}
|
|
176
|
+
},
|
|
177
|
+
...options
|
|
178
|
+
});
|
|
180
179
|
}
|
|
181
180
|
/**
|
|
182
181
|
* Generates a properly typed query key for React Query
|
|
@@ -242,7 +241,11 @@ class QueryOperations {
|
|
|
242
241
|
prefetchQuery(queryKey, params, options) {
|
|
243
242
|
const prefetchQueryKey = this.getQueryKey(queryKey, params);
|
|
244
243
|
const queryFn = this._queries[queryKey];
|
|
245
|
-
return this.queryClient.prefetchQuery(
|
|
244
|
+
return this.queryClient.prefetchQuery({
|
|
245
|
+
queryKey: prefetchQueryKey,
|
|
246
|
+
queryFn: queryFn,
|
|
247
|
+
...options,
|
|
248
|
+
});
|
|
246
249
|
}
|
|
247
250
|
/**
|
|
248
251
|
* Retrieves cached query data if it exists
|
|
@@ -273,16 +276,13 @@ class QueryOperations {
|
|
|
273
276
|
* }
|
|
274
277
|
* ```
|
|
275
278
|
*/
|
|
276
|
-
getQueryData(queryKey, params, options) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return this.queryClient.getQueryData(prefetchQueryKey);
|
|
284
|
-
});
|
|
279
|
+
async getQueryData(queryKey, params, options) {
|
|
280
|
+
const prefetchQueryKey = this.getQueryKey(queryKey, params);
|
|
281
|
+
const cachedData = this.queryClient.getQueryData(prefetchQueryKey);
|
|
282
|
+
if (!cachedData) {
|
|
283
|
+
await this.prefetchQuery(queryKey, params, options);
|
|
284
|
+
}
|
|
285
|
+
return this.queryClient.getQueryData(prefetchQueryKey);
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
|
-
exports.QueryOperations = QueryOperations;
|
|
288
288
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/QueryOperations/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/QueryOperations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAoE,MAAM,uBAAuB,CAAA;AAE/H,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,eAAe;IAWhB;IACA;IACA;IATV;;;;;OAKG;IACH,YACU,QAAgC,EAChC,aAAyB,EAAgB,EACzC,WAAqB,EAAc;QAFnC,aAAQ,GAAR,QAAQ,CAAwB;QAChC,eAAU,GAAV,UAAU,CAA+B;QACzC,aAAQ,GAAR,QAAQ,CAA2B;IACzC,CAAC;IAEL;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED,IAAI,WAAW;QACb,IAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,YAAY,mBAAmB,EAAE,CAAC;YAC5D,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAA;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAA;IAClC,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,CACN,IAAO,EACP,EAAoB;QAEpB,OAAO,IAAI,eAAe,CACxB,IAAI,CAAC,QAAQ,EACb,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAA8C,EAC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,CAAC,CAAA;IACrE,CAAC;CACF"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./QueryClientEnhanced"), exports);
|
|
18
|
-
__exportStar(require("./QueryKeys"), exports);
|
|
19
|
-
__exportStar(require("./Mutations"), exports);
|
|
20
|
-
__exportStar(require("./QueryManager"), exports);
|
|
21
|
-
__exportStar(require("./QueryOperations"), exports);
|
|
1
|
+
export * from './QueryClientEnhanced';
|
|
2
|
+
export * from './QueryKeys';
|
|
3
|
+
export * from './Mutations';
|
|
4
|
+
export * from './QueryManager';
|
|
5
|
+
export * from './QueryOperations';
|
|
22
6
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
|
package/dist/types/core.d.ts
CHANGED
|
@@ -8,11 +8,24 @@ export type QueryItem = {
|
|
|
8
8
|
export type PageParam = number;
|
|
9
9
|
/** Raw page payload returned by `listFn` — a flat array of items for one page. */
|
|
10
10
|
export type ListPaginationResponse<T extends QueryItem> = T[];
|
|
11
|
-
/**
|
|
12
|
-
export type
|
|
11
|
+
/** Extra metadata from a paginated API response (everything except the items array). */
|
|
12
|
+
export type ListResponseMeta = Record<string, unknown>;
|
|
13
|
+
/** Envelope returned by `listFn` when it includes metadata beyond the items array. `listItems` holds the page items; all other fields are treated as metadata. */
|
|
14
|
+
export type ListPaginationEnvelope<T extends QueryItem, M extends ListResponseMeta = ListResponseMeta> = {
|
|
15
|
+
listItems: T[];
|
|
16
|
+
} & M;
|
|
17
|
+
/** What `listFn` is allowed to return: a flat array (backward compat) or an envelope with metadata. */
|
|
18
|
+
export type ListFnResponse<T extends QueryItem, M extends ListResponseMeta = ListResponseMeta> = T[] | ListPaginationEnvelope<T, M>;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor options for `QueryManager`. All `*Fn` fields are optional; omitting one disables the corresponding operation and its generated hooks.
|
|
21
|
+
* @template T - The query item type that extends QueryItem
|
|
22
|
+
* @template F - The filter type used for list queries
|
|
23
|
+
* @template M - Optional metadata shape returned alongside list items (e.g. `{ count: number }`). Defaults to `Record<string, unknown>`.
|
|
24
|
+
*/
|
|
25
|
+
export type QueryManagerOptions<T extends QueryItem, F, M extends ListResponseMeta = ListResponseMeta> = {
|
|
13
26
|
name: string;
|
|
14
27
|
queryClient: ReturnType<typeof useQueryClient> | QueryClientEnhanced;
|
|
15
|
-
listFn?: (limit: number, offset: number, filters: F) => Promise<
|
|
28
|
+
listFn?: (limit: number, offset: number, filters: F) => Promise<ListFnResponse<T, M>>;
|
|
16
29
|
/** Page size sent to `listFn`. Defaults to 10 when omitted. */
|
|
17
30
|
listLimit?: number;
|
|
18
31
|
/** Side-effect hook called on every render with the current infinite-list query result. Useful for syncing list state into external stores. */
|
|
@@ -20,6 +33,7 @@ export type QueryManagerOptions<T extends QueryItem, F> = {
|
|
|
20
33
|
pageParams: number[];
|
|
21
34
|
pages: ListPaginationResponse<T>[];
|
|
22
35
|
allItems: T[];
|
|
36
|
+
meta: M | null;
|
|
23
37
|
}, Error>) => void;
|
|
24
38
|
retrieveFn?: (id: T['id']) => Promise<T>;
|
|
25
39
|
createFn?: (data: Partial<T>) => Promise<T>;
|
package/dist/types/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAE5C,qEAAqE;AACrE,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CACpB,CAAA;AAED,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,EAAE,CAAA;AAE7D,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAE5C,qEAAqE;AACrE,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CACpB,CAAA;AAED,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,EAAE,CAAA;AAE7D,wFAAwF;AACxF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MA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AI,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;IAE3C,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;IAE3C,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;CAC7C,CAAA"}
|
package/dist/types/core.js
CHANGED
package/dist/types/create.js
CHANGED
package/dist/types/delete.js
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./core"), exports);
|
|
18
|
-
__exportStar(require("./list"), exports);
|
|
19
|
-
__exportStar(require("./utility"), exports);
|
|
20
|
-
__exportStar(require("./retrieve"), exports);
|
|
21
|
-
__exportStar(require("./create"), exports);
|
|
22
|
-
__exportStar(require("./update"), exports);
|
|
23
|
-
__exportStar(require("./delete"), exports);
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './list';
|
|
3
|
+
export * from './utility';
|
|
4
|
+
export * from './retrieve';
|
|
5
|
+
export * from './create';
|
|
6
|
+
export * from './update';
|
|
7
|
+
export * from './delete';
|
|
24
8
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
|
package/dist/types/list.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { QueryKey, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
2
|
-
import { ListPaginationResponse, PageParam, QueryItem } from './core';
|
|
2
|
+
import { ListPaginationResponse, ListResponseMeta, PageParam, QueryItem } from './core';
|
|
3
3
|
/**
|
|
4
4
|
* Normalised shape of the infinite-query cache entry.
|
|
5
5
|
* `allItems` is a convenience flat-merge of every page's items — use it for rendering; use `pages` when you need per-page boundaries.
|
|
6
|
+
* `meta` holds extra data from the most recent `listFn` response (e.g. total count), or `null` when `listFn` returns a plain array.
|
|
6
7
|
*/
|
|
7
|
-
export type ListSelector<T extends QueryItem> = {
|
|
8
|
+
export type ListSelector<T extends QueryItem, M extends ListResponseMeta = ListResponseMeta> = {
|
|
8
9
|
pageParams: PageParam[];
|
|
9
10
|
pages: ListPaginationResponse<T>[];
|
|
10
11
|
allItems: T[];
|
|
12
|
+
meta: M | null;
|
|
11
13
|
};
|
|
12
|
-
type InfiniteQueryOptions<T extends QueryItem> = UseInfiniteQueryOptions<ListPaginationResponse<T>, Error, ListSelector<T>, QueryKey, PageParam>;
|
|
14
|
+
type InfiniteQueryOptions<T extends QueryItem, M extends ListResponseMeta = ListResponseMeta> = UseInfiniteQueryOptions<ListPaginationResponse<T>, Error, ListSelector<T, M>, QueryKey, PageParam>;
|
|
13
15
|
/** Options accepted by the generated `useList` hook. Extends React Query's infinite-query options; `limit` and `filters` are forwarded to `listFn`. */
|
|
14
|
-
export type ListQueryOptions<T extends QueryItem, F> = Partial<InfiniteQueryOptions<T>> & {
|
|
16
|
+
export type ListQueryOptions<T extends QueryItem, F, M extends ListResponseMeta = ListResponseMeta> = Partial<InfiniteQueryOptions<T, M>> & {
|
|
15
17
|
limit?: number;
|
|
16
18
|
filters?: F;
|
|
17
19
|
};
|
package/dist/types/list.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/types/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/types/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAEvF;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,IAAI;IAC7F,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAA;IAClC,QAAQ,EAAE,CAAC,EAAE,CAAA;IACb,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;CACf,CAAA;AAED,KAAK,oBAAoB,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,IAAI,uBAAuB,CACrH,sBAAsB,CAAC,CAAC,CAAC,EACzB,KAAK,EACL,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAClB,QAAQ,EACR,SAAS,CACV,CAAA;AAED,uJAAuJ;AACvJ,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,EAAE,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG;IAC1I,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,CAAC,CAAA;CACZ,CAAA"}
|
package/dist/types/list.js
CHANGED
package/dist/types/retrieve.js
CHANGED
package/dist/types/update.js
CHANGED
package/dist/types/utility.js
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./misc"), exports);
|
|
1
|
+
export * from './misc';
|
|
18
2
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
package/dist/utils/misc.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateTempId = exports.tempIdPrefix = void 0;
|
|
4
1
|
function uuidV4() {
|
|
5
2
|
function randomHex() {
|
|
6
3
|
return Math.floor(Math.random() * 16).toString(16);
|
|
@@ -30,10 +27,9 @@ function uuidV4() {
|
|
|
30
27
|
return uuid;
|
|
31
28
|
}
|
|
32
29
|
/** Prefix used on every optimistically-created item id. Check `id.startsWith(tempIdPrefix)` to distinguish placeholder items from server-assigned ids. */
|
|
33
|
-
|
|
30
|
+
export const tempIdPrefix = 'temp-id';
|
|
34
31
|
/** Returns a unique placeholder id for optimistic creates. The format is `temp-id-<uuidv4>` and is guaranteed never to collide with server-assigned ids. */
|
|
35
|
-
const generateTempId = () => {
|
|
36
|
-
return
|
|
32
|
+
export const generateTempId = () => {
|
|
33
|
+
return tempIdPrefix + '-' + uuidV4();
|
|
37
34
|
};
|
|
38
|
-
exports.generateTempId = generateTempId;
|
|
39
35
|
//# sourceMappingURL=misc.js.map
|
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"AAAA,SAAS,MAAM;IACb,SAAS,SAAS;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,IAAI,GAAG,EAAE,CAAA;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/query",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"directory": "packages/query"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@codeleap/config": "7.0.
|
|
26
|
-
"@codeleap/types": "7.0.
|
|
27
|
-
"@codeleap/utils": "7.0.
|
|
25
|
+
"@codeleap/config": "7.0.2",
|
|
26
|
+
"@codeleap/types": "7.0.2",
|
|
27
|
+
"@codeleap/utils": "7.0.2",
|
|
28
28
|
"ts-node-dev": "1.1.8"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"typecheck": "bun tsc --noEmit -p ./tsconfig.json"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@codeleap/types": "7.0.
|
|
35
|
+
"@codeleap/types": "7.0.2",
|
|
36
36
|
"typescript": "6.0.3",
|
|
37
37
|
"@tanstack/react-query": "5.100.9"
|
|
38
38
|
},
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { QueryManager } from '../lib'
|
|
2
|
-
import { QueryItem, QueryManagerOptions } from '../types'
|
|
2
|
+
import { ListResponseMeta, QueryItem, QueryManagerOptions } from '../types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Factory function to create a new QueryManager instance
|
|
6
6
|
* @template T - The query item type that extends QueryItem
|
|
7
7
|
* @template F - The filter type used for list queries
|
|
8
|
+
* @template M - Optional metadata shape returned alongside list items (e.g. `{ count: number }`). Defaults to `Record<string, unknown>`.
|
|
8
9
|
* @param options - Configuration options for the query manager
|
|
9
10
|
* @returns New QueryManager instance
|
|
10
|
-
*
|
|
11
|
+
*
|
|
11
12
|
* @example
|
|
12
13
|
* ```typescript
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* email: string
|
|
16
|
-
* status: 'active' | 'inactive'
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* interface UserFilters {
|
|
20
|
-
* status?: 'active' | 'inactive'
|
|
21
|
-
* search?: string
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* const userQueryManager = createQueryManager<User, UserFilters>({
|
|
14
|
+
* // Without list metadata (backward compatible)
|
|
15
|
+
* const userManager = createQueryManager<User, UserFilters>({
|
|
25
16
|
* name: 'users',
|
|
26
17
|
* queryClient,
|
|
27
18
|
* listFn: (limit, offset, filters) => api.getUsers({ limit, offset, ...filters }),
|
|
@@ -31,8 +22,20 @@ import { QueryItem, QueryManagerOptions } from '../types'
|
|
|
31
22
|
* deleteFn: (id) => api.deleteUser(id),
|
|
32
23
|
* listLimit: 20
|
|
33
24
|
* })
|
|
25
|
+
*
|
|
26
|
+
* // With list metadata
|
|
27
|
+
* const postManager = createQueryManager<Post, PostFilters, { count: number }>({
|
|
28
|
+
* name: 'posts',
|
|
29
|
+
* queryClient,
|
|
30
|
+
* listFn: async (limit, offset, filters) => {
|
|
31
|
+
* const { data } = await api.get('/posts/', { limit, offset, ...filters })
|
|
32
|
+
* return { listItems: data.results, count: data.count }
|
|
33
|
+
* },
|
|
34
|
+
* })
|
|
35
|
+
* // In a component: const { items, meta } = postManager.useList({ filters })
|
|
36
|
+
* // meta?.count is typed as number
|
|
34
37
|
* ```
|
|
35
38
|
*/
|
|
36
|
-
export const createQueryManager = <T extends QueryItem, F = {}>(options: QueryManagerOptions<T, F>) => {
|
|
37
|
-
return new QueryManager<T, F>(options)
|
|
39
|
+
export const createQueryManager = <T extends QueryItem, F = {}, M extends ListResponseMeta = ListResponseMeta>(options: QueryManagerOptions<T, F, M>) => {
|
|
40
|
+
return new QueryManager<T, F, M>(options)
|
|
38
41
|
}
|