@codeleap/query 6.8.0 → 7.0.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.js +37 -0
- package/dist/factors/createQueryManager.js.map +1 -0
- package/dist/factors/createQueryOperations.js +36 -0
- package/dist/factors/createQueryOperations.js.map +1 -0
- package/dist/factors/index.js +3 -0
- package/dist/factors/index.js.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/Mutations.js +235 -0
- package/dist/lib/Mutations.js.map +1 -0
- package/dist/lib/QueryClientEnhanced/index.js +195 -0
- package/dist/lib/QueryClientEnhanced/index.js.map +1 -0
- package/dist/lib/QueryClientEnhanced/types.js +2 -0
- package/dist/lib/QueryClientEnhanced/types.js.map +1 -0
- package/dist/lib/QueryKeys.js +313 -0
- package/dist/lib/QueryKeys.js.map +1 -0
- package/dist/lib/QueryManager.js +400 -0
- package/dist/lib/QueryManager.js.map +1 -0
- package/dist/lib/QueryOperations/index.js +284 -0
- package/dist/lib/QueryOperations/index.js.map +1 -0
- package/dist/lib/QueryOperations/types.js +2 -0
- package/dist/lib/QueryOperations/types.js.map +1 -0
- package/dist/lib/index.js +6 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/types/core.js +2 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/create.js +2 -0
- package/dist/types/create.js.map +1 -0
- package/dist/types/delete.js +2 -0
- package/dist/types/delete.js.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/list.js +2 -0
- package/dist/types/list.js.map +1 -0
- package/dist/types/retrieve.js +2 -0
- package/dist/types/retrieve.js.map +1 -0
- package/dist/types/update.js +2 -0
- package/dist/types/update.js.map +1 -0
- package/dist/types/utility.js +2 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/misc.js +35 -0
- package/dist/utils/misc.js.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
11
|
+
import { QueryClientEnhanced } from '../QueryClientEnhanced';
|
|
12
|
+
/**
|
|
13
|
+
* Builder class for creating type-safe query and mutation operations
|
|
14
|
+
* @template TMutations - Record type containing all registered mutation functions
|
|
15
|
+
* @template TQueries - Record type containing all registered query functions
|
|
16
|
+
*
|
|
17
|
+
* @description
|
|
18
|
+
* QueryOperations provides a fluent interface for building collections of queries and mutations
|
|
19
|
+
* with full type safety. It acts as a centralized registry for all data operations and provides
|
|
20
|
+
* corresponding React hooks that are automatically typed based on the registered functions.
|
|
21
|
+
*
|
|
22
|
+
* Key features:
|
|
23
|
+
* - Fluent builder pattern for registering operations
|
|
24
|
+
* - Automatic type inference for parameters and return types
|
|
25
|
+
* - Type-safe React hooks generation
|
|
26
|
+
* - Immutable operation registration (returns new instances)
|
|
27
|
+
*/
|
|
28
|
+
export class QueryOperations {
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new QueryOperations instance
|
|
31
|
+
* @param _options - Configuration options including QueryClient
|
|
32
|
+
* @param _mutations - Record of registered mutation functions (internal)
|
|
33
|
+
* @param _queries - Record of registered query functions (internal)
|
|
34
|
+
*/
|
|
35
|
+
constructor(_options, _mutations = {}, _queries = {}) {
|
|
36
|
+
this._options = _options;
|
|
37
|
+
this._mutations = _mutations;
|
|
38
|
+
this._queries = _queries;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets all registered mutation functions
|
|
42
|
+
* @returns Readonly record of mutation functions
|
|
43
|
+
*/
|
|
44
|
+
get mutations() {
|
|
45
|
+
return this._mutations;
|
|
46
|
+
}
|
|
47
|
+
get queryClient() {
|
|
48
|
+
if (this._options.queryClient instanceof QueryClientEnhanced) {
|
|
49
|
+
return this._options.queryClient.client;
|
|
50
|
+
}
|
|
51
|
+
return this._options.queryClient;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets all registered query functions
|
|
55
|
+
* @returns Readonly record of query functions
|
|
56
|
+
*/
|
|
57
|
+
get queries() {
|
|
58
|
+
return this._queries;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Registers a new mutation function
|
|
62
|
+
* @template K - The name/key for the mutation
|
|
63
|
+
* @template T - The input data type for the mutation
|
|
64
|
+
* @template R - The return data type for the mutation
|
|
65
|
+
* @param name - Unique name identifier for the mutation
|
|
66
|
+
* @param fn - The mutation function that performs the operation
|
|
67
|
+
* @returns New QueryOperations instance with the mutation added
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const operations = createQueryOperations({ queryClient })
|
|
72
|
+
* .mutation('createUser', async (userData: CreateUserData) => {
|
|
73
|
+
* return api.post('/users', userData)
|
|
74
|
+
* })
|
|
75
|
+
* .mutation('updateUser', async (userData: UpdateUserData) => {
|
|
76
|
+
* return api.put(`/users/${userData.id}`, userData)
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
mutation(name, fn) {
|
|
81
|
+
return new QueryOperations(this._options, Object.assign(Object.assign({}, this._mutations), { [name]: fn }), this._queries);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Registers a new query function
|
|
85
|
+
* @template K - The name/key for the query
|
|
86
|
+
* @template T - The parameters type for the query
|
|
87
|
+
* @template R - The return data type for the query
|
|
88
|
+
* @param name - Unique name identifier for the query
|
|
89
|
+
* @param fn - The query function that fetches the data
|
|
90
|
+
* @returns New QueryOperations instance with the query added
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const operations = createQueryOperations({ queryClient })
|
|
95
|
+
* .query('getUser', async (userId: string) => {
|
|
96
|
+
* return api.get(`/users/${userId}`)
|
|
97
|
+
* })
|
|
98
|
+
* .query('getUsers', async (filters?: UserFilters) => {
|
|
99
|
+
* return api.get('/users', { params: filters })
|
|
100
|
+
* })
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
query(name, fn) {
|
|
104
|
+
return new QueryOperations(this._options, this._mutations, Object.assign(Object.assign({}, this._queries), { [name]: fn }));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* React hook for executing mutations with full type safety
|
|
108
|
+
* @template K - The mutation key type
|
|
109
|
+
* @param mutationKey - The name of the registered mutation to use
|
|
110
|
+
* @param options - React Query mutation options (excluding mutationFn and mutationKey)
|
|
111
|
+
* @returns React Query mutation object with inferred types
|
|
112
|
+
*
|
|
113
|
+
* @description
|
|
114
|
+
* This hook automatically provides type-safe parameters and return types based on the
|
|
115
|
+
* registered mutation function. It handles error cases and provides proper TypeScript
|
|
116
|
+
* inference for the mutation data and variables.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const createUserMutation = operations.useMutation('createUser', {
|
|
121
|
+
* onSuccess: (user) => {
|
|
122
|
+
* // 'user' is automatically typed as the return type of createUser
|
|
123
|
+
* console.log('Created user:', user.id)
|
|
124
|
+
* }
|
|
125
|
+
* })
|
|
126
|
+
*
|
|
127
|
+
* // Usage - parameters are type-checked
|
|
128
|
+
* createUserMutation.mutate({ name: 'John', email: 'john@example.com' })
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
useMutation(mutationKey, options) {
|
|
132
|
+
const mutationFn = this._mutations[mutationKey];
|
|
133
|
+
return useMutation(Object.assign({ mutationKey: this.getMutationKey(mutationKey), mutationFn: (data) => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (!mutationFn) {
|
|
135
|
+
throw new Error(`Mutation "${String(mutationKey)}" not found`);
|
|
136
|
+
}
|
|
137
|
+
return mutationFn(data);
|
|
138
|
+
}) }, options));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* React hook for executing queries with full type safety
|
|
142
|
+
* @template K - The query key type
|
|
143
|
+
* @param queryKey - The name of the registered query to use
|
|
144
|
+
* @param params - Parameters to pass to the query function (optional if query doesn't require params)
|
|
145
|
+
* @param options - React Query options (excluding queryKey and queryFn)
|
|
146
|
+
* @returns React Query query object with inferred types
|
|
147
|
+
*
|
|
148
|
+
* @description
|
|
149
|
+
* This hook automatically provides type-safe parameters and return types based on the
|
|
150
|
+
* registered query function. It generates appropriate query keys and handles parameter
|
|
151
|
+
* validation.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Query with parameters
|
|
156
|
+
* const userQuery = operations.useQuery('getUser', 'user-123', {
|
|
157
|
+
* enabled: !!userId
|
|
158
|
+
* })
|
|
159
|
+
*
|
|
160
|
+
* // Query without parameters
|
|
161
|
+
* const usersQuery = operations.useQuery('getUsers', undefined, {
|
|
162
|
+
* refetchInterval: 30000
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* // Query with optional parameters
|
|
166
|
+
* const filteredUsersQuery = operations.useQuery('getUsers', { status: 'active' })
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
useQuery(queryKey, params, options) {
|
|
170
|
+
const queryFn = this._queries[queryKey];
|
|
171
|
+
return useQuery(Object.assign({ queryKey: this.getQueryKey(queryKey, params), queryFn: () => __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
if (!queryFn) {
|
|
173
|
+
throw new Error(`Query "${String(queryKey)}" not found`);
|
|
174
|
+
}
|
|
175
|
+
return queryFn(params);
|
|
176
|
+
}) }, options));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Generates a properly typed query key for React Query
|
|
180
|
+
* @template K - The query key type
|
|
181
|
+
* @param queryKey - The name of the query
|
|
182
|
+
* @param params - Optional parameters for the query
|
|
183
|
+
* @returns Query key array, with params included only when necessary
|
|
184
|
+
*
|
|
185
|
+
* @description
|
|
186
|
+
* This method creates React Query compatible keys that include parameters when present.
|
|
187
|
+
* The return type is conditionally typed based on whether the query requires parameters.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Returns ['getUser', 'user-123']
|
|
192
|
+
* const keyWithParams = operations.getQueryKey('getUser', 'user-123')
|
|
193
|
+
*
|
|
194
|
+
* // Returns ['getUsers']
|
|
195
|
+
* const keyWithoutParams = operations.getQueryKey('getUsers')
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
getQueryKey(queryKey, params) {
|
|
199
|
+
return (params !== undefined ? [queryKey, params] : [queryKey]);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Generates a mutation key for React Query
|
|
203
|
+
* @template K - The mutation key type
|
|
204
|
+
* @param mutationKey - The name of the mutation
|
|
205
|
+
* @returns Mutation key array containing only the mutation name
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* // Returns ['createUser']
|
|
210
|
+
* const mutationKey = operations.getMutationKey('createUser')
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
getMutationKey(mutationKey) {
|
|
214
|
+
return [mutationKey];
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Prefetches a query to populate the cache ahead of time
|
|
218
|
+
* @template K - The query key type
|
|
219
|
+
* @param queryKey - The name of the registered query to prefetch
|
|
220
|
+
* @param params - Parameters to pass to the query function (optional if query doesn't require params)
|
|
221
|
+
* @param options - React Query prefetch options
|
|
222
|
+
* @returns Promise that resolves when the prefetch is complete
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* // Prefetch user data when hovering over a user link
|
|
227
|
+
* const handleUserHover = async (userId: string) => {
|
|
228
|
+
* await operations.prefetchQuery('getUser', userId, {
|
|
229
|
+
* staleTime: 5 * 60 * 1000 // 5 minutes
|
|
230
|
+
* })
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* // Prefetch data on route change
|
|
234
|
+
* useEffect(() => {
|
|
235
|
+
* operations.prefetchQuery('getUsers', { status: 'active' })
|
|
236
|
+
* }, [])
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
prefetchQuery(queryKey, params, options) {
|
|
240
|
+
const prefetchQueryKey = this.getQueryKey(queryKey, params);
|
|
241
|
+
const queryFn = this._queries[queryKey];
|
|
242
|
+
return this.queryClient.prefetchQuery(Object.assign({ queryKey: prefetchQueryKey, queryFn: queryFn }, options));
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Retrieves cached query data if it exists
|
|
246
|
+
* @template K - The query key type
|
|
247
|
+
* @template T - The expected return type (defaults to inferred query return type)
|
|
248
|
+
* @param queryKey - The name of the registered query
|
|
249
|
+
* @param params - Parameters used when the query was cached (optional if query doesn't require params)
|
|
250
|
+
* @returns The cached data if it exists, undefined otherwise
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* // Get cached user data
|
|
255
|
+
* const cachedUser = operations.getQueryData('getUser', 'user-123')
|
|
256
|
+
* if (cachedUser) {
|
|
257
|
+
* console.log('User already in cache:', cachedUser.name)
|
|
258
|
+
* }
|
|
259
|
+
*
|
|
260
|
+
* // Check if users list is cached before showing loading state
|
|
261
|
+
* const cachedUsers = operations.getQueryData('getUsers')
|
|
262
|
+
* const showSkeleton = !cachedUsers
|
|
263
|
+
*
|
|
264
|
+
* // Access cached data in event handlers
|
|
265
|
+
* const handleUserAction = () => {
|
|
266
|
+
* const currentUser = operations.getQueryData('getCurrentUser')
|
|
267
|
+
* if (currentUser?.role === 'admin') {
|
|
268
|
+
* // Perform admin action
|
|
269
|
+
* }
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
getQueryData(queryKey, params, options) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
const prefetchQueryKey = this.getQueryKey(queryKey, params);
|
|
276
|
+
const cachedData = this.queryClient.getQueryData(prefetchQueryKey);
|
|
277
|
+
if (!cachedData) {
|
|
278
|
+
yield this.prefetchQuery(queryKey, params, options);
|
|
279
|
+
}
|
|
280
|
+
return this.queryClient.getQueryData(prefetchQueryKey);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;IAI1B;;;;;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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qF;;YAErF,MAAM,gBAAgB,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAE3D,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAc,gBAAgB,CAAC,CAAA;YAE/E,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;YACrD,CAAC;YAED,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAc,gBAAgB,CAAC,CAAA;QACrE,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/QueryOperations/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/types/core.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/types/create.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/types/delete.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/types/list.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieve.js","sourceRoot":"","sources":["../../src/types/retrieve.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/types/update.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.js","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function uuidV4() {
|
|
2
|
+
function randomHex() {
|
|
3
|
+
return Math.floor(Math.random() * 16).toString(16);
|
|
4
|
+
}
|
|
5
|
+
let uuid = '';
|
|
6
|
+
for (let i = 0; i < 8; i++) {
|
|
7
|
+
uuid += randomHex();
|
|
8
|
+
}
|
|
9
|
+
uuid += '-';
|
|
10
|
+
for (let i = 0; i < 4; i++) {
|
|
11
|
+
uuid += randomHex();
|
|
12
|
+
}
|
|
13
|
+
uuid += '-';
|
|
14
|
+
uuid += '4';
|
|
15
|
+
for (let i = 0; i < 3; i++) {
|
|
16
|
+
uuid += randomHex();
|
|
17
|
+
}
|
|
18
|
+
uuid += '-';
|
|
19
|
+
uuid += ['8', '9', 'a', 'b'][Math.floor(Math.random() * 4)];
|
|
20
|
+
for (let i = 0; i < 3; i++) {
|
|
21
|
+
uuid += randomHex();
|
|
22
|
+
}
|
|
23
|
+
uuid += '-';
|
|
24
|
+
for (let i = 0; i < 12; i++) {
|
|
25
|
+
uuid += randomHex();
|
|
26
|
+
}
|
|
27
|
+
return uuid;
|
|
28
|
+
}
|
|
29
|
+
/** Prefix used on every optimistically-created item id. Check `id.startsWith(tempIdPrefix)` to distinguish placeholder items from server-assigned ids. */
|
|
30
|
+
export const tempIdPrefix = 'temp-id';
|
|
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. */
|
|
32
|
+
export const generateTempId = () => {
|
|
33
|
+
return tempIdPrefix + '-' + uuidV4();
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=misc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,IAAI,SAAS,EAAE,CAAA;IACrB,CAAC;IAED,IAAI,IAAI,GAAG,CAAA;IAEX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,IAAI,SAAS,EAAE,CAAA;IACrB,CAAC;IAED,IAAI,IAAI,GAAG,CAAA;IAEX,IAAI,IAAI,GAAG,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,IAAI,SAAS,EAAE,CAAA;IACrB,CAAC;IACD,IAAI,IAAI,GAAG,CAAA;IAEX,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,IAAI,SAAS,EAAE,CAAA;IACrB,CAAC;IACD,IAAI,IAAI,GAAG,CAAA;IAEX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,IAAI,IAAI,SAAS,EAAE,CAAA;IACrB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,0JAA0J;AAC1J,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAA;AAErC,4JAA4J;AAC5J,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,YAAY,GAAG,GAAG,GAAG,MAAM,EAAE,CAAA;AACtC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/query",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"directory": "packages/query"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@codeleap/config": "
|
|
26
|
-
"@codeleap/types": "
|
|
27
|
-
"@codeleap/utils": "
|
|
25
|
+
"@codeleap/config": "7.0.1",
|
|
26
|
+
"@codeleap/types": "7.0.1",
|
|
27
|
+
"@codeleap/utils": "7.0.1",
|
|
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": "
|
|
35
|
+
"@codeleap/types": "7.0.1",
|
|
36
36
|
"typescript": "6.0.3",
|
|
37
37
|
"@tanstack/react-query": "5.100.9"
|
|
38
38
|
},
|